@mastra/core 0.24.0 → 1.0.0-beta.1
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 +484 -139
- package/README.md +2 -3
- package/agent/message-list.d.ts +1 -0
- package/dist/action/index.d.ts +0 -2
- package/dist/action/index.d.ts.map +1 -1
- package/dist/agent/__tests__/mock-model.d.ts +3 -1
- package/dist/agent/__tests__/mock-model.d.ts.map +1 -1
- package/dist/agent/agent-legacy.d.ts +176 -0
- package/dist/agent/agent-legacy.d.ts.map +1 -0
- package/dist/agent/agent.d.ts +83 -229
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +10 -25
- package/dist/agent/agent.types.d.ts.map +1 -1
- package/dist/agent/index.cjs +10 -26
- package/dist/agent/index.d.ts +1 -2
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/index.cjs +16 -0
- package/dist/agent/message-list/index.d.ts +77 -87
- package/dist/agent/message-list/index.d.ts.map +1 -1
- package/dist/agent/message-list/index.js +3 -0
- package/dist/agent/message-list/prompt/attachments-to-parts.d.ts +2 -2
- package/dist/agent/message-list/prompt/attachments-to-parts.d.ts.map +1 -1
- package/dist/agent/message-list/prompt/convert-to-mastra-v1.d.ts +2 -2
- package/dist/agent/message-list/prompt/download-assets.d.ts.map +1 -1
- package/dist/agent/message-list/prompt/invalid-content-error.d.ts +1 -1
- package/dist/agent/message-list/prompt/invalid-content-error.d.ts.map +1 -1
- package/dist/agent/message-list/types.d.ts +2 -1
- package/dist/agent/message-list/types.d.ts.map +1 -1
- package/dist/agent/message-list/utils/ai-v4-v5/core-model-message.d.ts +3 -2
- package/dist/agent/message-list/utils/ai-v4-v5/core-model-message.d.ts.map +1 -1
- package/dist/agent/message-list/utils/ai-v4-v5/ui-message.d.ts +3 -2
- package/dist/agent/message-list/utils/ai-v4-v5/ui-message.d.ts.map +1 -1
- package/dist/agent/message-list/utils/ai-v5/gemini-compatibility.d.ts +1 -1
- package/dist/agent/message-list/utils/ai-v5/gemini-compatibility.d.ts.map +1 -1
- package/dist/agent/message-list/utils/convert-messages.d.ts +4 -4
- package/dist/agent/message-list/utils/convert-messages.d.ts.map +1 -1
- package/dist/agent/test-utils.d.ts +2 -79
- package/dist/agent/test-utils.d.ts.map +1 -1
- package/dist/agent/trip-wire.d.ts +1 -1
- package/dist/agent/trip-wire.d.ts.map +1 -1
- package/dist/agent/types.d.ts +23 -37
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/utils.d.ts +15 -64
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +16 -20
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts +5 -7
- 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 +14 -18
- 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 +6 -6
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/schema.d.ts +10 -12
- package/dist/agent/workflows/prepare-stream/schema.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts +3 -7
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
- package/dist/ai-sdk.types.d.ts +4705 -0
- package/dist/base.cjs +2 -2
- package/dist/base.d.ts +0 -16
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +1 -1
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.d.ts +2 -1
- package/dist/bundler/index.d.ts.map +1 -1
- package/dist/bundler/index.js +1 -1
- package/dist/cache/index.cjs +3 -3
- package/dist/cache/index.js +1 -1
- package/dist/{chunk-7J3XX4AO.cjs → chunk-2ZVKF4HP.cjs} +199 -66
- package/dist/chunk-2ZVKF4HP.cjs.map +1 -0
- package/dist/chunk-4CDL2QJT.js +649 -0
- package/dist/chunk-4CDL2QJT.js.map +1 -0
- package/dist/chunk-5WRI5ZAA.js +29 -0
- package/dist/{chunk-3HXBPDKN.js.map → chunk-5WRI5ZAA.js.map} +1 -1
- package/dist/{chunk-KAEQISOW.js → chunk-76K3IYWM.js} +5 -5
- package/dist/chunk-76K3IYWM.js.map +1 -0
- package/dist/chunk-7AHYOMHJ.js +149 -0
- package/dist/chunk-7AHYOMHJ.js.map +1 -0
- package/dist/{chunk-UZKIGB7M.cjs → chunk-BMAFVZ2D.cjs} +5 -5
- package/dist/chunk-BMAFVZ2D.cjs.map +1 -0
- package/dist/chunk-CB575O6L.cjs +12432 -0
- package/dist/chunk-CB575O6L.cjs.map +1 -0
- package/dist/{chunk-6TEQIYXV.cjs → chunk-CBAB7GOD.cjs} +15 -15
- package/dist/chunk-CBAB7GOD.cjs.map +1 -0
- package/dist/{chunk-ROS5CMJS.cjs → chunk-CD56CXVE.cjs} +63 -50
- package/dist/chunk-CD56CXVE.cjs.map +1 -0
- package/dist/{chunk-Z4RIRDU3.js → chunk-CINNK34N.js} +45 -32
- package/dist/chunk-CINNK34N.js.map +1 -0
- package/dist/{chunk-77JHIM4E.cjs → chunk-DNEURYF3.cjs} +348 -424
- package/dist/chunk-DNEURYF3.cjs.map +1 -0
- package/dist/{chunk-A5KDVZDL.cjs → chunk-DSNPWVIG.cjs} +9 -9
- package/dist/chunk-DSNPWVIG.cjs.map +1 -0
- package/dist/chunk-DZUJEN5N.cjs +32 -0
- package/dist/{chunk-EBVYYC2Q.cjs.map → chunk-DZUJEN5N.cjs.map} +1 -1
- package/dist/chunk-E7K4FTLN.cjs +273 -0
- package/dist/chunk-E7K4FTLN.cjs.map +1 -0
- package/dist/{chunk-MJMID7LX.cjs → chunk-ECFXGXWO.cjs} +609 -644
- package/dist/chunk-ECFXGXWO.cjs.map +1 -0
- package/dist/chunk-ET6UOTTU.cjs +154 -0
- package/dist/chunk-ET6UOTTU.cjs.map +1 -0
- package/dist/chunk-GGYKYORQ.cjs +2060 -0
- package/dist/chunk-GGYKYORQ.cjs.map +1 -0
- package/dist/{chunk-HLRWYUFN.js → chunk-GRBGQ2GE.js} +5 -5
- package/dist/{chunk-HLRWYUFN.js.map → chunk-GRBGQ2GE.js.map} +1 -1
- package/dist/{chunk-3VXXCPKX.js → chunk-H6CZGPZD.js} +334 -410
- package/dist/chunk-H6CZGPZD.js.map +1 -0
- package/dist/chunk-HDJFSJCK.js +2237 -0
- package/dist/chunk-HDJFSJCK.js.map +1 -0
- package/dist/{chunk-34ZCWSUA.js → chunk-I4CXL4SR.js} +6 -9
- package/dist/chunk-I4CXL4SR.js.map +1 -0
- package/dist/{chunk-3JX2Y3WH.cjs → chunk-IQO7ANVS.cjs} +18 -21
- package/dist/chunk-IQO7ANVS.cjs.map +1 -0
- package/dist/{chunk-GPWMM745.cjs → chunk-J7O6WENZ.cjs} +5 -5
- package/dist/{chunk-GPWMM745.cjs.map → chunk-J7O6WENZ.cjs.map} +1 -1
- package/dist/{chunk-PZUZNPFM.js → chunk-JJ5O45LH.js} +3 -4
- package/dist/chunk-JJ5O45LH.js.map +1 -0
- package/dist/chunk-JPGVRWWL.js +12385 -0
- package/dist/chunk-JPGVRWWL.js.map +1 -0
- package/dist/chunk-JUBFO5J3.js +15761 -0
- package/dist/chunk-JUBFO5J3.js.map +1 -0
- package/dist/{chunk-E3PG7G6E.js → chunk-JV2KH24V.js} +599 -633
- package/dist/chunk-JV2KH24V.js.map +1 -0
- package/dist/chunk-KEXGB7FK.cjs +29 -0
- package/dist/chunk-KEXGB7FK.cjs.map +1 -0
- package/dist/chunk-KIZIOFZC.js +265 -0
- package/dist/chunk-KIZIOFZC.js.map +1 -0
- package/dist/{chunk-UXG7PYML.js → chunk-KJ2SW6VA.js} +9 -9
- package/dist/chunk-KJ2SW6VA.js.map +1 -0
- package/dist/{chunk-TTELJD4F.js → chunk-L54GIUCB.js} +2 -2
- package/dist/chunk-L54GIUCB.js.map +1 -0
- package/dist/chunk-LWBQ4P4N.cjs +2240 -0
- package/dist/chunk-LWBQ4P4N.cjs.map +1 -0
- package/dist/{chunk-ABZOBBLL.cjs → chunk-MA7TEM62.cjs} +735 -562
- package/dist/chunk-MA7TEM62.cjs.map +1 -0
- package/dist/{chunk-TSNDVBUU.cjs → chunk-MR7ZWBL6.cjs} +2 -2
- package/dist/chunk-MR7ZWBL6.cjs.map +1 -0
- package/dist/chunk-MSWTA73A.cjs +15825 -0
- package/dist/chunk-MSWTA73A.cjs.map +1 -0
- package/dist/chunk-MV7KHWUT.js +2031 -0
- package/dist/chunk-MV7KHWUT.js.map +1 -0
- package/dist/{chunk-3NTOFNIU.js → chunk-OJNJA5ZI.js} +3 -3
- package/dist/{chunk-3NTOFNIU.js.map → chunk-OJNJA5ZI.js.map} +1 -1
- package/dist/chunk-QM5SRDJX.js +9022 -0
- package/dist/chunk-QM5SRDJX.js.map +1 -0
- package/dist/{chunk-WBAXXG34.cjs → chunk-QUKUN6NR.cjs} +32 -66
- package/dist/chunk-QUKUN6NR.cjs.map +1 -0
- package/dist/chunk-S6URFGCZ.js +27 -0
- package/dist/chunk-S6URFGCZ.js.map +1 -0
- package/dist/chunk-SVLMF4UZ.cjs +9033 -0
- package/dist/chunk-SVLMF4UZ.cjs.map +1 -0
- package/dist/{chunk-ZMELUU72.js → chunk-TQTAMPSC.js} +3 -3
- package/dist/chunk-TQTAMPSC.js.map +1 -0
- package/dist/{chunk-5NTO7S5I.cjs → chunk-TWH4PTDG.cjs} +2 -4
- package/dist/chunk-TWH4PTDG.cjs.map +1 -0
- package/dist/{chunk-WCHE6FJ7.js → chunk-UIZSWUKP.js} +15 -50
- package/dist/chunk-UIZSWUKP.js.map +1 -0
- package/dist/{chunk-BWGXM3D4.js → chunk-VOQ3ULMT.js} +712 -541
- package/dist/chunk-VOQ3ULMT.js.map +1 -0
- package/dist/{chunk-MCASUJWY.cjs → chunk-VOY2RXOC.cjs} +36 -59
- package/dist/chunk-VOY2RXOC.cjs.map +1 -0
- package/dist/{chunk-FHVFGVIO.js → chunk-W7UH2PWL.js} +189 -56
- package/dist/chunk-W7UH2PWL.js.map +1 -0
- package/dist/chunk-WM6CK2F3.cjs +674 -0
- package/dist/chunk-WM6CK2F3.cjs.map +1 -0
- package/dist/{chunk-PFXXH2RP.js → chunk-X7JMA3IY.js} +15 -15
- package/dist/chunk-X7JMA3IY.js.map +1 -0
- package/dist/{chunk-NR77P3TK.js → chunk-XEVG546F.js} +14 -37
- package/dist/chunk-XEVG546F.js.map +1 -0
- package/dist/{chunk-QFF5JUKT.cjs → chunk-Y63IFHEZ.cjs} +4 -4
- package/dist/chunk-Y63IFHEZ.cjs.map +1 -0
- package/dist/{chunk-B7V6NYWH.cjs → chunk-Y6ROD72V.cjs} +4 -4
- package/dist/{chunk-B7V6NYWH.cjs.map → chunk-Y6ROD72V.cjs.map} +1 -1
- package/dist/deployer/index.cjs +8 -6
- package/dist/deployer/index.cjs.map +1 -1
- package/dist/deployer/index.js +10 -1
- package/dist/deployer/index.js.map +1 -1
- package/dist/di/index.cjs +3 -3
- package/dist/di/index.d.ts +1 -1
- package/dist/di/index.js +1 -1
- package/dist/error/index.cjs +6 -6
- package/dist/error/index.d.ts +0 -1
- package/dist/error/index.d.ts.map +1 -1
- package/dist/error/index.js +1 -1
- package/dist/{scores → evals}/base.d.ts +20 -18
- package/dist/evals/base.d.ts.map +1 -0
- package/dist/{scores → evals}/base.test-utils.d.ts +25 -25
- package/dist/evals/base.test-utils.d.ts.map +1 -0
- package/dist/{scores → evals}/hooks.d.ts +3 -3
- package/dist/evals/hooks.d.ts.map +1 -0
- package/dist/evals/index.cjs +37 -0
- package/dist/evals/index.d.ts +4 -0
- package/dist/evals/index.d.ts.map +1 -0
- package/dist/evals/index.js +4 -0
- package/dist/{scores/run-experiment → evals/run}/index.d.ts +18 -18
- package/dist/evals/run/index.d.ts.map +1 -0
- package/dist/evals/run/scorerAccumulator.d.ts.map +1 -0
- package/dist/{scores → evals}/scoreTraces/index.cjs +79 -99
- package/dist/evals/scoreTraces/index.cjs.map +1 -0
- package/dist/evals/scoreTraces/index.d.ts.map +1 -0
- package/dist/{scores → evals}/scoreTraces/index.js +72 -92
- package/dist/evals/scoreTraces/index.js.map +1 -0
- package/dist/{scores → evals}/scoreTraces/scoreTraces.d.ts +2 -2
- package/dist/evals/scoreTraces/scoreTraces.d.ts.map +1 -0
- package/dist/{scores → evals}/scoreTraces/scoreTracesWorkflow.d.ts +11 -11
- package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -0
- package/dist/{scores → evals}/scoreTraces/utils.d.ts +7 -7
- package/dist/evals/scoreTraces/utils.d.ts.map +1 -0
- package/dist/{scores → evals}/types.d.ts +22 -22
- package/dist/evals/types.d.ts.map +1 -0
- package/dist/features/index.cjs +8 -0
- package/dist/features/index.cjs.map +1 -0
- package/dist/features/index.d.ts +17 -0
- package/dist/features/index.d.ts.map +1 -0
- package/dist/features/index.js +6 -0
- package/dist/features/index.js.map +1 -0
- package/dist/hooks/index.cjs +4 -4
- package/dist/hooks/index.d.ts +1 -27
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/index.cjs +2 -340
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -113
- package/dist/index.js.map +1 -1
- package/dist/integration/index.cjs +87 -10
- package/dist/integration/index.cjs.map +1 -1
- package/dist/integration/index.js +88 -1
- package/dist/integration/index.js.map +1 -1
- package/dist/integration/integration.d.ts +3 -3
- package/dist/integration/integration.d.ts.map +1 -1
- package/dist/llm/index.cjs +7 -7
- package/dist/llm/index.d.ts +5 -6
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +1 -1
- package/dist/llm/model/base.types.d.ts +6 -7
- package/dist/llm/model/base.types.d.ts.map +1 -1
- package/dist/llm/model/gateways/constants.d.ts.map +1 -1
- package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
- package/dist/llm/model/model.d.ts +7 -7
- package/dist/llm/model/model.d.ts.map +1 -1
- package/dist/llm/model/model.loop.d.ts +1 -1
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/model.loop.types.d.ts +3 -3
- package/dist/llm/model/model.loop.types.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +80 -17
- package/dist/llm/model/resolve-model.d.ts +8 -8
- package/dist/llm/model/shared.types.d.ts +2 -2
- package/dist/llm/model/shared.types.d.ts.map +1 -1
- package/dist/logger/constants.d.ts +1 -1
- package/dist/logger/default-logger.d.ts +2 -2
- package/dist/logger/default-logger.d.ts.map +1 -1
- package/dist/logger/index.cjs +11 -11
- package/dist/logger/index.js +2 -2
- package/dist/logger/logger.d.ts +4 -4
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/multi-logger.d.ts +2 -2
- package/dist/logger/multi-logger.d.ts.map +1 -1
- package/dist/logger/transport.d.ts +3 -3
- 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 +1 -1
- package/dist/loop/loop.d.ts.map +1 -1
- package/dist/loop/network/index.d.ts +15 -15
- package/dist/loop/network/index.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/types.d.ts +4 -7
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +55 -55
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +38 -38
- 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 -20
- 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 -2
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +55 -55
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/loop/workflows/schema.d.ts +19 -20
- 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/hooks.d.ts +2 -2
- package/dist/mastra/hooks.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +389 -180
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/mcp/index.cjs +41 -4
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.ts +6 -4
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +39 -2
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/types.d.ts +0 -15
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/memory/index.cjs +327 -13
- package/dist/memory/index.cjs.map +1 -1
- package/dist/memory/index.d.ts +1 -0
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +327 -1
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/memory.d.ts +33 -57
- package/dist/memory/memory.d.ts.map +1 -1
- package/dist/memory/mock.d.ts +61 -0
- package/dist/memory/mock.d.ts.map +1 -0
- package/dist/memory/types.d.ts +48 -45
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/models-dev-DNBKXHT4.js +3 -0
- package/dist/{models-dev-4VGIWYS3.js.map → models-dev-DNBKXHT4.js.map} +1 -1
- package/dist/models-dev-YBEEQIX6.cjs +12 -0
- package/dist/{models-dev-AXZASLL2.cjs.map → models-dev-YBEEQIX6.cjs.map} +1 -1
- package/dist/netlify-7G2L5VSH.js +3 -0
- package/dist/{netlify-VJXBII33.js.map → netlify-7G2L5VSH.js.map} +1 -1
- package/dist/netlify-GWNGSIRZ.cjs +12 -0
- package/dist/{netlify-TX6V7SJJ.cjs.map → netlify-GWNGSIRZ.cjs.map} +1 -1
- package/dist/{ai-tracing → observability}/context.d.ts +5 -5
- package/dist/observability/context.d.ts.map +1 -0
- package/dist/observability/index.cjs +36 -0
- package/dist/observability/index.d.ts +11 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +3 -0
- package/dist/observability/no-op.d.ts +22 -0
- package/dist/observability/no-op.d.ts.map +1 -0
- package/dist/observability/types/index.d.ts +2 -0
- package/dist/observability/types/index.d.ts.map +1 -0
- package/dist/{ai-tracing/types.d.ts → observability/types/tracing.d.ts} +161 -107
- package/dist/observability/types/tracing.d.ts.map +1 -0
- package/dist/observability/utils.d.ts +12 -0
- package/dist/observability/utils.d.ts.map +1 -0
- package/dist/processors/index.cjs +11 -11
- package/dist/processors/index.d.ts +10 -9
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/processors/batch-parts.d.ts +2 -1
- package/dist/processors/processors/batch-parts.d.ts.map +1 -1
- package/dist/processors/processors/language-detector.d.ts +6 -5
- package/dist/processors/processors/language-detector.d.ts.map +1 -1
- package/dist/processors/processors/moderation.d.ts +8 -7
- package/dist/processors/processors/moderation.d.ts.map +1 -1
- package/dist/processors/processors/pii-detector.d.ts +8 -7
- package/dist/processors/processors/pii-detector.d.ts.map +1 -1
- package/dist/processors/processors/prompt-injection-detector.d.ts +6 -5
- package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
- package/dist/processors/processors/structured-output.d.ts +3 -2
- package/dist/processors/processors/structured-output.d.ts.map +1 -1
- package/dist/processors/processors/system-prompt-scrubber.d.ts +6 -5
- package/dist/processors/processors/system-prompt-scrubber.d.ts.map +1 -1
- package/dist/processors/processors/token-limiter.d.ts +5 -4
- package/dist/processors/processors/token-limiter.d.ts.map +1 -1
- package/dist/processors/processors/unicode-normalizer.d.ts +5 -4
- package/dist/processors/processors/unicode-normalizer.d.ts.map +1 -1
- package/dist/processors/runner.d.ts +5 -5
- package/dist/processors/runner.d.ts.map +1 -1
- package/dist/provider-registry.json +175 -42
- package/dist/{registry-generator-DXRSYYYT.js → registry-generator-H4YNODDH.js} +2 -2
- package/dist/{registry-generator-DXRSYYYT.js.map → registry-generator-H4YNODDH.js.map} +1 -1
- package/dist/{registry-generator-6WVOHM2L.cjs → registry-generator-MK63POJO.cjs} +2 -2
- package/dist/{registry-generator-6WVOHM2L.cjs.map → registry-generator-MK63POJO.cjs.map} +1 -1
- package/dist/relevance/index.cjs +47 -13
- package/dist/relevance/index.cjs.map +1 -1
- package/dist/relevance/index.d.ts +0 -1
- package/dist/relevance/index.d.ts.map +1 -1
- package/dist/relevance/index.js +49 -1
- package/dist/relevance/index.js.map +1 -1
- package/dist/relevance/mastra-agent/index.d.ts.map +1 -1
- package/dist/request-context/index.cjs +12 -0
- package/dist/{runtime-context → request-context}/index.d.ts +1 -1
- package/dist/{runtime-context → request-context}/index.d.ts.map +1 -1
- package/dist/request-context/index.js +3 -0
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/index.cjs +9 -25
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.js +4 -21
- package/dist/server/index.js.map +1 -1
- package/dist/server/types.d.ts +3 -3
- package/dist/server/types.d.ts.map +1 -1
- package/dist/storage/base.d.ts +75 -143
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/constants.d.ts +3 -4
- package/dist/storage/constants.d.ts.map +1 -1
- package/dist/storage/domains/index.d.ts +0 -2
- package/dist/storage/domains/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/base.d.ts +19 -56
- package/dist/storage/domains/memory/base.d.ts.map +1 -1
- package/dist/storage/domains/memory/inmemory.d.ts +15 -35
- package/dist/storage/domains/memory/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/observability/base.d.ts +24 -24
- package/dist/storage/domains/observability/base.d.ts.map +1 -1
- package/dist/storage/domains/observability/inmemory.d.ts +18 -18
- package/dist/storage/domains/observability/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 +5 -5
- package/dist/storage/domains/scores/base.d.ts.map +1 -1
- package/dist/storage/domains/scores/inmemory.d.ts +5 -5
- package/dist/storage/domains/scores/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/workflows/base.d.ts +4 -11
- package/dist/storage/domains/workflows/base.d.ts.map +1 -1
- package/dist/storage/domains/workflows/inmemory.d.ts +4 -11
- package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +74 -1775
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.js +1 -1744
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/mock.d.ts +35 -92
- package/dist/storage/mock.d.ts.map +1 -1
- package/dist/storage/types.d.ts +77 -75
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts +4 -2
- package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
- package/dist/stream/RunOutput.d.ts +1 -0
- package/dist/stream/RunOutput.d.ts.map +1 -1
- package/dist/stream/aisdk/v4/input.d.ts +1 -1
- package/dist/stream/aisdk/v4/input.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/execute.d.ts +4 -11
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output.d.ts +1 -1
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts +1 -1
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +11 -11
- package/dist/stream/index.d.ts +1 -1
- package/dist/stream/index.d.ts.map +1 -1
- package/dist/stream/index.js +2 -2
- package/dist/stream/types.d.ts +2 -6
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.cjs +8 -8
- package/dist/test-utils/llm-mock.cjs.map +1 -1
- package/dist/test-utils/llm-mock.d.ts +1 -1
- package/dist/test-utils/llm-mock.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.js +3 -3
- package/dist/test-utils/llm-mock.js.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 +3 -71
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/tool.d.ts +25 -25
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/tools/types.d.ts +102 -11
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/validation.d.ts +4 -3
- package/dist/tools/validation.d.ts.map +1 -1
- package/dist/tts/index.cjs +12 -6
- package/dist/tts/index.cjs.map +1 -1
- package/dist/tts/index.d.ts +0 -1
- package/dist/tts/index.d.ts.map +1 -1
- package/dist/tts/index.js +14 -1
- package/dist/tts/index.js.map +1 -1
- package/dist/types/dynamic-argument.d.ts +3 -3
- package/dist/utils/fetchWithRetry.d.ts +9 -0
- package/dist/utils/fetchWithRetry.d.ts.map +1 -0
- package/dist/utils.cjs +33 -17
- package/dist/utils.d.ts +39 -6
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/vector/embed.d.ts +1 -1
- package/dist/vector/embed.d.ts.map +1 -1
- package/dist/vector/index.cjs +80 -8
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.js +80 -1
- package/dist/vector/index.js.map +1 -1
- package/dist/vector/vector.d.ts +5 -2
- package/dist/vector/vector.d.ts.map +1 -1
- package/dist/voice/composite-voice.d.ts +1 -7
- package/dist/voice/composite-voice.d.ts.map +1 -1
- package/dist/voice/index.cjs +4 -4
- package/dist/voice/index.js +1 -1
- package/dist/voice/voice.d.ts +0 -1
- package/dist/voice/voice.d.ts.map +1 -1
- package/dist/workflows/default.d.ts +35 -43
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/execution-engine.d.ts +5 -3
- 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 +15 -13
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts +5 -5
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts +3 -3
- 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/sleep.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/utils.d.ts +2 -7
- package/dist/workflows/evented/workflow-event-processor/utils.d.ts.map +1 -1
- package/dist/workflows/evented/workflow.d.ts +11 -14
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/execution-engine.d.ts +6 -6
- package/dist/workflows/execution-engine.d.ts.map +1 -1
- package/dist/workflows/index.cjs +22 -14
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts +5 -5
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +21 -44
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/utils.d.ts +14 -0
- package/dist/workflows/utils.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +74 -64
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/evals/scoreTraces.d.ts +1 -0
- package/evals.d.ts +1 -0
- package/features.d.ts +1 -0
- package/observability.d.ts +1 -0
- package/package.json +49 -64
- package/request-context.d.ts +1 -0
- package/src/_types/ai-sdk.types.d.ts +4705 -0
- package/src/llm/model/provider-types.generated.d.ts +80 -17
- package/agent/input-processor/processors.d.ts +0 -1
- package/ai-tracing.d.ts +0 -1
- package/dist/agent/index.warning.d.ts +0 -13
- package/dist/agent/index.warning.d.ts.map +0 -1
- package/dist/agent/input-processor/index.cjs +0 -28
- package/dist/agent/input-processor/index.d.ts +0 -10
- package/dist/agent/input-processor/index.d.ts.map +0 -1
- package/dist/agent/input-processor/index.js +0 -3
- package/dist/agent/input-processor/processors/index.d.ts +0 -6
- package/dist/agent/input-processor/processors/index.d.ts.map +0 -1
- package/dist/agent/input-processor/processors/language-detector.d.ts +0 -18
- package/dist/agent/input-processor/processors/language-detector.d.ts.map +0 -1
- package/dist/agent/input-processor/processors/moderation.d.ts +0 -18
- package/dist/agent/input-processor/processors/moderation.d.ts.map +0 -1
- package/dist/agent/input-processor/processors/pii-detector.d.ts +0 -18
- package/dist/agent/input-processor/processors/pii-detector.d.ts.map +0 -1
- package/dist/agent/input-processor/processors/prompt-injection-detector.d.ts +0 -18
- package/dist/agent/input-processor/processors/prompt-injection-detector.d.ts.map +0 -1
- package/dist/agent/input-processor/processors/unicode-normalizer.d.ts +0 -18
- package/dist/agent/input-processor/processors/unicode-normalizer.d.ts.map +0 -1
- package/dist/ai-tracing/context.d.ts.map +0 -1
- package/dist/ai-tracing/exporters/base.d.ts +0 -111
- package/dist/ai-tracing/exporters/base.d.ts.map +0 -1
- package/dist/ai-tracing/exporters/cloud.d.ts +0 -30
- package/dist/ai-tracing/exporters/cloud.d.ts.map +0 -1
- package/dist/ai-tracing/exporters/console.d.ts +0 -10
- package/dist/ai-tracing/exporters/console.d.ts.map +0 -1
- package/dist/ai-tracing/exporters/default.d.ts +0 -98
- package/dist/ai-tracing/exporters/default.d.ts.map +0 -1
- package/dist/ai-tracing/exporters/index.d.ts +0 -9
- package/dist/ai-tracing/exporters/index.d.ts.map +0 -1
- package/dist/ai-tracing/index.cjs +0 -148
- package/dist/ai-tracing/index.d.ts +0 -13
- package/dist/ai-tracing/index.d.ts.map +0 -1
- package/dist/ai-tracing/index.js +0 -3
- package/dist/ai-tracing/model-tracing.d.ts +0 -63
- package/dist/ai-tracing/model-tracing.d.ts.map +0 -1
- package/dist/ai-tracing/registry.d.ts +0 -51
- package/dist/ai-tracing/registry.d.ts.map +0 -1
- package/dist/ai-tracing/span_processors/index.d.ts +0 -5
- package/dist/ai-tracing/span_processors/index.d.ts.map +0 -1
- package/dist/ai-tracing/span_processors/sensitive-data-filter.d.ts +0 -85
- package/dist/ai-tracing/span_processors/sensitive-data-filter.d.ts.map +0 -1
- package/dist/ai-tracing/spans/base.d.ts +0 -65
- package/dist/ai-tracing/spans/base.d.ts.map +0 -1
- package/dist/ai-tracing/spans/default.d.ts +0 -13
- package/dist/ai-tracing/spans/default.d.ts.map +0 -1
- package/dist/ai-tracing/spans/index.d.ts +0 -7
- package/dist/ai-tracing/spans/index.d.ts.map +0 -1
- package/dist/ai-tracing/spans/no-op.d.ts +0 -15
- package/dist/ai-tracing/spans/no-op.d.ts.map +0 -1
- package/dist/ai-tracing/tracers/base.d.ts +0 -105
- package/dist/ai-tracing/tracers/base.d.ts.map +0 -1
- package/dist/ai-tracing/tracers/default.d.ts +0 -7
- package/dist/ai-tracing/tracers/default.d.ts.map +0 -1
- package/dist/ai-tracing/tracers/index.d.ts +0 -6
- package/dist/ai-tracing/tracers/index.d.ts.map +0 -1
- package/dist/ai-tracing/types.d.ts.map +0 -1
- package/dist/ai-tracing/utils.d.ts +0 -68
- package/dist/ai-tracing/utils.d.ts.map +0 -1
- package/dist/base.warning.d.ts +0 -9
- package/dist/base.warning.d.ts.map +0 -1
- package/dist/bundler/index.warning.d.ts +0 -9
- package/dist/bundler/index.warning.d.ts.map +0 -1
- package/dist/chunk-253FBVD4.cjs +0 -1303
- package/dist/chunk-253FBVD4.cjs.map +0 -1
- package/dist/chunk-2B3VLGTH.js +0 -87
- package/dist/chunk-2B3VLGTH.js.map +0 -1
- package/dist/chunk-34ZCWSUA.js.map +0 -1
- package/dist/chunk-3HXBPDKN.js +0 -105
- package/dist/chunk-3JX2Y3WH.cjs.map +0 -1
- package/dist/chunk-3VXXCPKX.js.map +0 -1
- package/dist/chunk-4R2TBRS7.cjs +0 -191
- package/dist/chunk-4R2TBRS7.cjs.map +0 -1
- package/dist/chunk-5NTO7S5I.cjs.map +0 -1
- package/dist/chunk-6C7VGVK4.js +0 -267
- package/dist/chunk-6C7VGVK4.js.map +0 -1
- package/dist/chunk-6KOL2B3A.cjs +0 -75
- package/dist/chunk-6KOL2B3A.cjs.map +0 -1
- package/dist/chunk-6TEQIYXV.cjs.map +0 -1
- package/dist/chunk-6VOPKVYH.cjs +0 -57
- package/dist/chunk-6VOPKVYH.cjs.map +0 -1
- package/dist/chunk-77JHIM4E.cjs.map +0 -1
- package/dist/chunk-7J3XX4AO.cjs.map +0 -1
- package/dist/chunk-A5KDVZDL.cjs.map +0 -1
- package/dist/chunk-ABZOBBLL.cjs.map +0 -1
- package/dist/chunk-AQGLVU53.cjs +0 -603
- package/dist/chunk-AQGLVU53.cjs.map +0 -1
- package/dist/chunk-BLUDYAPI.js +0 -596
- package/dist/chunk-BLUDYAPI.js.map +0 -1
- package/dist/chunk-BWGXM3D4.js.map +0 -1
- package/dist/chunk-C7OVZMPW.cjs +0 -91
- package/dist/chunk-C7OVZMPW.cjs.map +0 -1
- package/dist/chunk-DMBN72QF.cjs +0 -39
- package/dist/chunk-DMBN72QF.cjs.map +0 -1
- package/dist/chunk-DTTOVV72.js +0 -2880
- package/dist/chunk-DTTOVV72.js.map +0 -1
- package/dist/chunk-E3PG7G6E.js.map +0 -1
- package/dist/chunk-EBVYYC2Q.cjs +0 -111
- package/dist/chunk-FHVFGVIO.js.map +0 -1
- package/dist/chunk-GB5BIA4V.js +0 -167
- package/dist/chunk-GB5BIA4V.js.map +0 -1
- package/dist/chunk-HEQTUMUA.cjs +0 -271
- package/dist/chunk-HEQTUMUA.cjs.map +0 -1
- package/dist/chunk-HF3GZRFP.cjs +0 -9
- package/dist/chunk-HF3GZRFP.cjs.map +0 -1
- package/dist/chunk-JVV5LREI.js +0 -431
- package/dist/chunk-JVV5LREI.js.map +0 -1
- package/dist/chunk-KAEQISOW.js.map +0 -1
- package/dist/chunk-KDX3ZMQ2.js +0 -12
- package/dist/chunk-KDX3ZMQ2.js.map +0 -1
- package/dist/chunk-LG5B3KIW.js +0 -1215
- package/dist/chunk-LG5B3KIW.js.map +0 -1
- package/dist/chunk-LZUSZT7R.cjs +0 -170
- package/dist/chunk-LZUSZT7R.cjs.map +0 -1
- package/dist/chunk-MCASUJWY.cjs.map +0 -1
- package/dist/chunk-MJMID7LX.cjs.map +0 -1
- package/dist/chunk-MKCC5K77.js +0 -90
- package/dist/chunk-MKCC5K77.js.map +0 -1
- package/dist/chunk-NPNGPMT2.js +0 -39
- package/dist/chunk-NPNGPMT2.js.map +0 -1
- package/dist/chunk-NR77P3TK.js.map +0 -1
- package/dist/chunk-NUAURT4I.cjs +0 -82
- package/dist/chunk-NUAURT4I.cjs.map +0 -1
- package/dist/chunk-OIT3PCWA.js +0 -72
- package/dist/chunk-OIT3PCWA.js.map +0 -1
- package/dist/chunk-P35FNLTQ.cjs +0 -2936
- package/dist/chunk-P35FNLTQ.cjs.map +0 -1
- package/dist/chunk-PFXXH2RP.js.map +0 -1
- package/dist/chunk-PZUZNPFM.js.map +0 -1
- package/dist/chunk-QFF5JUKT.cjs.map +0 -1
- package/dist/chunk-RKXWLG33.js +0 -7
- package/dist/chunk-RKXWLG33.js.map +0 -1
- package/dist/chunk-ROS5CMJS.cjs.map +0 -1
- package/dist/chunk-SJMKDSRF.js +0 -179
- package/dist/chunk-SJMKDSRF.js.map +0 -1
- package/dist/chunk-SSULK22X.cjs +0 -14
- package/dist/chunk-SSULK22X.cjs.map +0 -1
- package/dist/chunk-TSNDVBUU.cjs.map +0 -1
- package/dist/chunk-TTELJD4F.js.map +0 -1
- package/dist/chunk-TX4TTPYJ.cjs +0 -436
- package/dist/chunk-TX4TTPYJ.cjs.map +0 -1
- package/dist/chunk-UXG7PYML.js.map +0 -1
- package/dist/chunk-UZKIGB7M.cjs.map +0 -1
- package/dist/chunk-VF676YCO.cjs +0 -150
- package/dist/chunk-VF676YCO.cjs.map +0 -1
- package/dist/chunk-VQASQG5D.js +0 -55
- package/dist/chunk-VQASQG5D.js.map +0 -1
- package/dist/chunk-WBAXXG34.cjs.map +0 -1
- package/dist/chunk-WCHE6FJ7.js.map +0 -1
- package/dist/chunk-WM4RO23J.js +0 -145
- package/dist/chunk-WM4RO23J.js.map +0 -1
- package/dist/chunk-Z4RIRDU3.js.map +0 -1
- package/dist/chunk-ZABG3SZ2.cjs +0 -93
- package/dist/chunk-ZABG3SZ2.cjs.map +0 -1
- package/dist/chunk-ZISECZZO.js +0 -72
- package/dist/chunk-ZISECZZO.js.map +0 -1
- package/dist/chunk-ZMELUU72.js.map +0 -1
- package/dist/deployer/index.warning.d.ts +0 -9
- package/dist/deployer/index.warning.d.ts.map +0 -1
- package/dist/eval/evaluation.d.ts +0 -14
- package/dist/eval/evaluation.d.ts.map +0 -1
- package/dist/eval/index.cjs +0 -16
- package/dist/eval/index.d.ts +0 -4
- package/dist/eval/index.d.ts.map +0 -1
- package/dist/eval/index.js +0 -3
- package/dist/eval/metric.d.ts +0 -8
- package/dist/eval/metric.d.ts.map +0 -1
- package/dist/eval/types.d.ts +0 -9
- package/dist/eval/types.d.ts.map +0 -1
- package/dist/integration/index.warning.d.ts +0 -3
- package/dist/integration/index.warning.d.ts.map +0 -1
- package/dist/integration/integration.warning.d.ts +0 -5
- package/dist/integration/integration.warning.d.ts.map +0 -1
- package/dist/integration/openapi-toolset.warning.d.ts +0 -5
- package/dist/integration/openapi-toolset.warning.d.ts.map +0 -1
- package/dist/loop/telemetry/index.d.ts +0 -36
- package/dist/loop/telemetry/index.d.ts.map +0 -1
- package/dist/loop/telemetry/noop.d.ts +0 -3
- package/dist/loop/telemetry/noop.d.ts.map +0 -1
- package/dist/loop/test-utils/mockTracer.d.ts +0 -47
- package/dist/loop/test-utils/mockTracer.d.ts.map +0 -1
- package/dist/loop/test-utils/telemetry.d.ts +0 -6
- package/dist/loop/test-utils/telemetry.d.ts.map +0 -1
- package/dist/memory/index.warning.d.ts +0 -6
- package/dist/memory/index.warning.d.ts.map +0 -1
- package/dist/models-dev-4VGIWYS3.js +0 -3
- package/dist/models-dev-AXZASLL2.cjs +0 -12
- package/dist/netlify-TX6V7SJJ.cjs +0 -12
- package/dist/netlify-VJXBII33.js +0 -3
- package/dist/relevance/cohere/index.d.ts +0 -9
- package/dist/relevance/cohere/index.d.ts.map +0 -1
- package/dist/runtime-context/index.cjs +0 -12
- package/dist/runtime-context/index.js +0 -3
- package/dist/scores/base.d.ts.map +0 -1
- package/dist/scores/base.test-utils.d.ts.map +0 -1
- package/dist/scores/hooks.d.ts.map +0 -1
- package/dist/scores/index.cjs +0 -37
- package/dist/scores/index.cjs.map +0 -1
- package/dist/scores/index.d.ts +0 -4
- package/dist/scores/index.d.ts.map +0 -1
- package/dist/scores/index.js +0 -4
- package/dist/scores/index.js.map +0 -1
- package/dist/scores/run-experiment/index.d.ts.map +0 -1
- package/dist/scores/run-experiment/scorerAccumulator.d.ts.map +0 -1
- package/dist/scores/scoreTraces/index.cjs.map +0 -1
- package/dist/scores/scoreTraces/index.d.ts.map +0 -1
- package/dist/scores/scoreTraces/index.js.map +0 -1
- package/dist/scores/scoreTraces/scoreTraces.d.ts.map +0 -1
- package/dist/scores/scoreTraces/scoreTracesWorkflow.d.ts.map +0 -1
- package/dist/scores/scoreTraces/utils.d.ts.map +0 -1
- package/dist/scores/types.d.ts.map +0 -1
- package/dist/storage/base.warning.d.ts +0 -8
- package/dist/storage/base.warning.d.ts.map +0 -1
- package/dist/storage/domains/legacy-evals/base.d.ts +0 -13
- package/dist/storage/domains/legacy-evals/base.d.ts.map +0 -1
- package/dist/storage/domains/legacy-evals/index.d.ts +0 -2
- package/dist/storage/domains/legacy-evals/index.d.ts.map +0 -1
- package/dist/storage/domains/legacy-evals/inmemory.d.ts +0 -17
- package/dist/storage/domains/legacy-evals/inmemory.d.ts.map +0 -1
- package/dist/storage/domains/traces/base.d.ts +0 -14
- package/dist/storage/domains/traces/base.d.ts.map +0 -1
- package/dist/storage/domains/traces/index.d.ts +0 -3
- package/dist/storage/domains/traces/index.d.ts.map +0 -1
- package/dist/storage/domains/traces/inmemory.d.ts +0 -22
- package/dist/storage/domains/traces/inmemory.d.ts.map +0 -1
- package/dist/storage/index.warning.d.ts +0 -3
- package/dist/storage/index.warning.d.ts.map +0 -1
- package/dist/telemetry/composite-exporter.d.ts +0 -10
- package/dist/telemetry/composite-exporter.d.ts.map +0 -1
- package/dist/telemetry/index.cjs +0 -32
- package/dist/telemetry/index.cjs.map +0 -1
- package/dist/telemetry/index.d.ts +0 -6
- package/dist/telemetry/index.d.ts.map +0 -1
- package/dist/telemetry/index.js +0 -3
- package/dist/telemetry/index.js.map +0 -1
- package/dist/telemetry/otel-vendor.cjs +0 -105
- package/dist/telemetry/otel-vendor.cjs.map +0 -1
- package/dist/telemetry/otel-vendor.d.ts +0 -11
- package/dist/telemetry/otel-vendor.d.ts.map +0 -1
- package/dist/telemetry/otel-vendor.js +0 -59
- package/dist/telemetry/otel-vendor.js.map +0 -1
- package/dist/telemetry/storage-exporter.d.ts +0 -21
- package/dist/telemetry/storage-exporter.d.ts.map +0 -1
- package/dist/telemetry/telemetry.d.ts +0 -59
- package/dist/telemetry/telemetry.d.ts.map +0 -1
- package/dist/telemetry/telemetry.decorators.d.ts +0 -15
- package/dist/telemetry/telemetry.decorators.d.ts.map +0 -1
- package/dist/telemetry/types.d.ts +0 -74
- package/dist/telemetry/types.d.ts.map +0 -1
- package/dist/telemetry/utility.d.ts +0 -15
- package/dist/telemetry/utility.d.ts.map +0 -1
- package/dist/tools/index.warning.d.ts +0 -8
- package/dist/tools/index.warning.d.ts.map +0 -1
- package/dist/tts/index.warning.d.ts +0 -7
- package/dist/tts/index.warning.d.ts.map +0 -1
- package/dist/vector/index.warning.d.ts +0 -6
- package/dist/vector/index.warning.d.ts.map +0 -1
- package/dist/workflows/index.warning.d.ts +0 -6
- package/dist/workflows/index.warning.d.ts.map +0 -1
- package/dist/workflows/legacy/index.cjs +0 -92
- package/dist/workflows/legacy/index.cjs.map +0 -1
- package/dist/workflows/legacy/index.d.ts +0 -5
- package/dist/workflows/legacy/index.d.ts.map +0 -1
- package/dist/workflows/legacy/index.js +0 -3
- package/dist/workflows/legacy/index.js.map +0 -1
- package/dist/workflows/legacy/machine.d.ts +0 -386
- package/dist/workflows/legacy/machine.d.ts.map +0 -1
- package/dist/workflows/legacy/step.d.ts +0 -15
- package/dist/workflows/legacy/step.d.ts.map +0 -1
- package/dist/workflows/legacy/types.d.ts +0 -397
- package/dist/workflows/legacy/types.d.ts.map +0 -1
- package/dist/workflows/legacy/utils.d.ts +0 -68
- package/dist/workflows/legacy/utils.d.ts.map +0 -1
- package/dist/workflows/legacy/workflow-instance.d.ts +0 -97
- package/dist/workflows/legacy/workflow-instance.d.ts.map +0 -1
- package/dist/workflows/legacy/workflow.d.ts +0 -109
- package/dist/workflows/legacy/workflow.d.ts.map +0 -1
- package/dist/workflows/workflow.warning.d.ts +0 -9
- package/dist/workflows/workflow.warning.d.ts.map +0 -1
- package/eval.d.ts +0 -1
- package/runtime-context.d.ts +0 -1
- package/scores/scoreTraces.d.ts +0 -1
- package/scores.d.ts +0 -1
- package/telemetry/otel-vendor.d.ts +0 -1
- package/telemetry.d.ts +0 -1
- package/workflows/legacy.d.ts +0 -1
- /package/dist/agent/{input-processor → message-list}/index.cjs.map +0 -0
- /package/dist/agent/{input-processor → message-list}/index.js.map +0 -0
- /package/dist/{ai-tracing → evals}/index.cjs.map +0 -0
- /package/dist/{ai-tracing → evals}/index.js.map +0 -0
- /package/dist/{scores/run-experiment → evals/run}/scorerAccumulator.d.ts +0 -0
- /package/dist/{scores → evals}/scoreTraces/index.d.ts +0 -0
- /package/dist/{eval → observability}/index.cjs.map +0 -0
- /package/dist/{eval → observability}/index.js.map +0 -0
- /package/dist/{runtime-context → request-context}/index.cjs.map +0 -0
- /package/dist/{runtime-context → request-context}/index.js.map +0 -0
|
@@ -0,0 +1,2031 @@
|
|
|
1
|
+
import { MessageList } from './chunk-JV2KH24V.js';
|
|
2
|
+
import { MastraError } from './chunk-JJ5O45LH.js';
|
|
3
|
+
import { MastraBase } from './chunk-S6URFGCZ.js';
|
|
4
|
+
|
|
5
|
+
// src/storage/constants.ts
|
|
6
|
+
var TABLE_WORKFLOW_SNAPSHOT = "mastra_workflow_snapshot";
|
|
7
|
+
var TABLE_MESSAGES = "mastra_messages";
|
|
8
|
+
var TABLE_THREADS = "mastra_threads";
|
|
9
|
+
var TABLE_TRACES = "mastra_traces";
|
|
10
|
+
var TABLE_RESOURCES = "mastra_resources";
|
|
11
|
+
var TABLE_SCORERS = "mastra_scorers";
|
|
12
|
+
var TABLE_SPANS = "mastra_ai_spans";
|
|
13
|
+
var SCORERS_SCHEMA = {
|
|
14
|
+
id: { type: "text", nullable: false, primaryKey: true },
|
|
15
|
+
scorerId: { type: "text" },
|
|
16
|
+
traceId: { type: "text", nullable: true },
|
|
17
|
+
spanId: { type: "text", nullable: true },
|
|
18
|
+
runId: { type: "text" },
|
|
19
|
+
scorer: { type: "jsonb" },
|
|
20
|
+
preprocessStepResult: { type: "jsonb", nullable: true },
|
|
21
|
+
extractStepResult: { type: "jsonb", nullable: true },
|
|
22
|
+
analyzeStepResult: { type: "jsonb", nullable: true },
|
|
23
|
+
score: { type: "float" },
|
|
24
|
+
reason: { type: "text", nullable: true },
|
|
25
|
+
metadata: { type: "jsonb", nullable: true },
|
|
26
|
+
preprocessPrompt: { type: "text", nullable: true },
|
|
27
|
+
extractPrompt: { type: "text", nullable: true },
|
|
28
|
+
generateScorePrompt: { type: "text", nullable: true },
|
|
29
|
+
generateReasonPrompt: { type: "text", nullable: true },
|
|
30
|
+
analyzePrompt: { type: "text", nullable: true },
|
|
31
|
+
// Deprecated
|
|
32
|
+
reasonPrompt: { type: "text", nullable: true },
|
|
33
|
+
input: { type: "jsonb" },
|
|
34
|
+
output: { type: "jsonb" },
|
|
35
|
+
// MESSAGE OUTPUT
|
|
36
|
+
additionalContext: { type: "jsonb", nullable: true },
|
|
37
|
+
// DATA FROM THE CONTEXT PARAM ON AN AGENT
|
|
38
|
+
requestContext: { type: "jsonb", nullable: true },
|
|
39
|
+
// THE EVALUATE Request Context FOR THE RUN
|
|
40
|
+
/**
|
|
41
|
+
* Things you can evaluate
|
|
42
|
+
*/
|
|
43
|
+
entityType: { type: "text", nullable: true },
|
|
44
|
+
// WORKFLOW, AGENT, TOOL, STEP, NETWORK
|
|
45
|
+
entity: { type: "jsonb", nullable: true },
|
|
46
|
+
// MINIMAL JSON DATA ABOUT WORKFLOW, AGENT, TOOL, STEP, NETWORK
|
|
47
|
+
entityId: { type: "text", nullable: true },
|
|
48
|
+
source: { type: "text" },
|
|
49
|
+
resourceId: { type: "text", nullable: true },
|
|
50
|
+
threadId: { type: "text", nullable: true },
|
|
51
|
+
createdAt: { type: "timestamp" },
|
|
52
|
+
updatedAt: { type: "timestamp" }
|
|
53
|
+
};
|
|
54
|
+
var SPAN_SCHEMA = {
|
|
55
|
+
// Composite primary key of traceId and spanId
|
|
56
|
+
traceId: { type: "text", nullable: false },
|
|
57
|
+
spanId: { type: "text", nullable: false },
|
|
58
|
+
parentSpanId: { type: "text", nullable: true },
|
|
59
|
+
name: { type: "text", nullable: false },
|
|
60
|
+
scope: { type: "jsonb", nullable: true },
|
|
61
|
+
// Mastra package info {"core-version": "0.1.0"}
|
|
62
|
+
spanType: { type: "text", nullable: false },
|
|
63
|
+
// WORKFLOW_RUN, WORKFLOW_STEP, AGENT_RUN, AGENT_STEP, TOOL_RUN, TOOL_STEP, etc.
|
|
64
|
+
attributes: { type: "jsonb", nullable: true },
|
|
65
|
+
metadata: { type: "jsonb", nullable: true },
|
|
66
|
+
links: { type: "jsonb", nullable: true },
|
|
67
|
+
input: { type: "jsonb", nullable: true },
|
|
68
|
+
output: { type: "jsonb", nullable: true },
|
|
69
|
+
error: { type: "jsonb", nullable: true },
|
|
70
|
+
startedAt: { type: "timestamp", nullable: false },
|
|
71
|
+
// When the span started
|
|
72
|
+
endedAt: { type: "timestamp", nullable: true },
|
|
73
|
+
// When the span ended
|
|
74
|
+
createdAt: { type: "timestamp", nullable: false },
|
|
75
|
+
// The time the database record was created
|
|
76
|
+
updatedAt: { type: "timestamp", nullable: true },
|
|
77
|
+
// The time the database record was last updated
|
|
78
|
+
isEvent: { type: "boolean", nullable: false }
|
|
79
|
+
};
|
|
80
|
+
var TABLE_SCHEMAS = {
|
|
81
|
+
[TABLE_WORKFLOW_SNAPSHOT]: {
|
|
82
|
+
workflow_name: {
|
|
83
|
+
type: "text"
|
|
84
|
+
},
|
|
85
|
+
run_id: {
|
|
86
|
+
type: "text"
|
|
87
|
+
},
|
|
88
|
+
resourceId: { type: "text", nullable: true },
|
|
89
|
+
snapshot: {
|
|
90
|
+
type: "text"
|
|
91
|
+
},
|
|
92
|
+
createdAt: {
|
|
93
|
+
type: "timestamp"
|
|
94
|
+
},
|
|
95
|
+
updatedAt: {
|
|
96
|
+
type: "timestamp"
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
[TABLE_SCORERS]: SCORERS_SCHEMA,
|
|
100
|
+
[TABLE_THREADS]: {
|
|
101
|
+
id: { type: "text", nullable: false, primaryKey: true },
|
|
102
|
+
resourceId: { type: "text", nullable: false },
|
|
103
|
+
title: { type: "text", nullable: false },
|
|
104
|
+
metadata: { type: "text", nullable: true },
|
|
105
|
+
createdAt: { type: "timestamp", nullable: false },
|
|
106
|
+
updatedAt: { type: "timestamp", nullable: false }
|
|
107
|
+
},
|
|
108
|
+
[TABLE_MESSAGES]: {
|
|
109
|
+
id: { type: "text", nullable: false, primaryKey: true },
|
|
110
|
+
thread_id: { type: "text", nullable: false },
|
|
111
|
+
content: { type: "text", nullable: false },
|
|
112
|
+
role: { type: "text", nullable: false },
|
|
113
|
+
type: { type: "text", nullable: false },
|
|
114
|
+
createdAt: { type: "timestamp", nullable: false },
|
|
115
|
+
resourceId: { type: "text", nullable: true }
|
|
116
|
+
},
|
|
117
|
+
[TABLE_SPANS]: SPAN_SCHEMA,
|
|
118
|
+
[TABLE_TRACES]: {
|
|
119
|
+
id: { type: "text", nullable: false, primaryKey: true },
|
|
120
|
+
parentSpanId: { type: "text", nullable: true },
|
|
121
|
+
name: { type: "text", nullable: false },
|
|
122
|
+
traceId: { type: "text", nullable: false },
|
|
123
|
+
scope: { type: "text", nullable: false },
|
|
124
|
+
kind: { type: "integer", nullable: false },
|
|
125
|
+
attributes: { type: "jsonb", nullable: true },
|
|
126
|
+
status: { type: "jsonb", nullable: true },
|
|
127
|
+
events: { type: "jsonb", nullable: true },
|
|
128
|
+
links: { type: "jsonb", nullable: true },
|
|
129
|
+
other: { type: "text", nullable: true },
|
|
130
|
+
startTime: { type: "bigint", nullable: false },
|
|
131
|
+
endTime: { type: "bigint", nullable: false },
|
|
132
|
+
createdAt: { type: "timestamp", nullable: false }
|
|
133
|
+
},
|
|
134
|
+
[TABLE_RESOURCES]: {
|
|
135
|
+
id: { type: "text", nullable: false, primaryKey: true },
|
|
136
|
+
workingMemory: { type: "text", nullable: true },
|
|
137
|
+
metadata: { type: "jsonb", nullable: true },
|
|
138
|
+
createdAt: { type: "timestamp", nullable: false },
|
|
139
|
+
updatedAt: { type: "timestamp", nullable: false }
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// src/storage/base.ts
|
|
144
|
+
function ensureDate(date) {
|
|
145
|
+
if (!date) return void 0;
|
|
146
|
+
return date instanceof Date ? date : new Date(date);
|
|
147
|
+
}
|
|
148
|
+
function serializeDate(date) {
|
|
149
|
+
if (!date) return void 0;
|
|
150
|
+
const dateObj = ensureDate(date);
|
|
151
|
+
return dateObj?.toISOString();
|
|
152
|
+
}
|
|
153
|
+
function normalizePerPage(perPageInput, defaultValue) {
|
|
154
|
+
if (perPageInput === false) {
|
|
155
|
+
return Number.MAX_SAFE_INTEGER;
|
|
156
|
+
} else if (perPageInput === 0) {
|
|
157
|
+
return 0;
|
|
158
|
+
} else if (typeof perPageInput === "number" && perPageInput > 0) {
|
|
159
|
+
return perPageInput;
|
|
160
|
+
}
|
|
161
|
+
return defaultValue;
|
|
162
|
+
}
|
|
163
|
+
function calculatePagination(page, perPageInput, normalizedPerPage) {
|
|
164
|
+
return {
|
|
165
|
+
offset: perPageInput === false ? 0 : page * normalizedPerPage,
|
|
166
|
+
perPage: perPageInput === false ? false : normalizedPerPage
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
var MastraStorage = class extends MastraBase {
|
|
170
|
+
hasInitialized = null;
|
|
171
|
+
shouldCacheInit = true;
|
|
172
|
+
id;
|
|
173
|
+
stores;
|
|
174
|
+
constructor({ id, name }) {
|
|
175
|
+
if (!id || typeof id !== "string" || id.trim() === "") {
|
|
176
|
+
throw new Error(`${name}: id must be provided and cannot be empty.`);
|
|
177
|
+
}
|
|
178
|
+
super({
|
|
179
|
+
component: "STORAGE",
|
|
180
|
+
name
|
|
181
|
+
});
|
|
182
|
+
this.id = id;
|
|
183
|
+
}
|
|
184
|
+
get supports() {
|
|
185
|
+
return {
|
|
186
|
+
selectByIncludeResourceScope: false,
|
|
187
|
+
resourceWorkingMemory: false,
|
|
188
|
+
hasColumn: false,
|
|
189
|
+
createTable: false,
|
|
190
|
+
deleteMessages: false,
|
|
191
|
+
observabilityInstance: false,
|
|
192
|
+
indexManagement: false,
|
|
193
|
+
listScoresBySpan: false
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
ensureDate(date) {
|
|
197
|
+
return ensureDate(date);
|
|
198
|
+
}
|
|
199
|
+
serializeDate(date) {
|
|
200
|
+
return serializeDate(date);
|
|
201
|
+
}
|
|
202
|
+
getSqlType(type) {
|
|
203
|
+
switch (type) {
|
|
204
|
+
case "text":
|
|
205
|
+
return "TEXT";
|
|
206
|
+
case "timestamp":
|
|
207
|
+
return "TIMESTAMP";
|
|
208
|
+
case "float":
|
|
209
|
+
return "FLOAT";
|
|
210
|
+
case "integer":
|
|
211
|
+
return "INTEGER";
|
|
212
|
+
case "bigint":
|
|
213
|
+
return "BIGINT";
|
|
214
|
+
case "jsonb":
|
|
215
|
+
return "JSONB";
|
|
216
|
+
default:
|
|
217
|
+
return "TEXT";
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
getDefaultValue(type) {
|
|
221
|
+
switch (type) {
|
|
222
|
+
case "text":
|
|
223
|
+
case "uuid":
|
|
224
|
+
return "DEFAULT ''";
|
|
225
|
+
case "timestamp":
|
|
226
|
+
return "DEFAULT '1970-01-01 00:00:00'";
|
|
227
|
+
case "integer":
|
|
228
|
+
case "float":
|
|
229
|
+
case "bigint":
|
|
230
|
+
return "DEFAULT 0";
|
|
231
|
+
case "jsonb":
|
|
232
|
+
return "DEFAULT '{}'";
|
|
233
|
+
default:
|
|
234
|
+
return "DEFAULT ''";
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async getResourceById(_) {
|
|
238
|
+
throw new Error(
|
|
239
|
+
`Resource working memory is not supported by this storage adapter (${this.constructor.name}). Supported storage adapters: LibSQL (@mastra/libsql), PostgreSQL (@mastra/pg), Upstash (@mastra/upstash). To use per-resource working memory, switch to one of these supported storage adapters.`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
async saveResource(_) {
|
|
243
|
+
throw new Error(
|
|
244
|
+
`Resource working memory is not supported by this storage adapter (${this.constructor.name}). Supported storage adapters: LibSQL (@mastra/libsql), PostgreSQL (@mastra/pg), Upstash (@mastra/upstash). To use per-resource working memory, switch to one of these supported storage adapters.`
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
async updateResource(_) {
|
|
248
|
+
throw new Error(
|
|
249
|
+
`Resource working memory is not supported by this storage adapter (${this.constructor.name}). Supported storage adapters: LibSQL (@mastra/libsql), PostgreSQL (@mastra/pg), Upstash (@mastra/upstash). To use per-resource working memory, switch to one of these supported storage adapters.`
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
async listMessages(args) {
|
|
253
|
+
if (this.stores?.memory) {
|
|
254
|
+
return this.stores.memory.listMessages(args);
|
|
255
|
+
}
|
|
256
|
+
throw new MastraError({
|
|
257
|
+
id: "MASTRA_STORAGE_LIST_MESSAGES_NOT_SUPPORTED",
|
|
258
|
+
domain: "STORAGE" /* STORAGE */,
|
|
259
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
260
|
+
text: `Listing messages is not implemented by this storage adapter (${this.constructor.name})`
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
async listWorkflowRuns(args) {
|
|
264
|
+
if (this.stores?.workflows) {
|
|
265
|
+
return this.stores.workflows.listWorkflowRuns(args);
|
|
266
|
+
}
|
|
267
|
+
throw new MastraError({
|
|
268
|
+
id: "MASTRA_STORAGE_LIST_WORKFLOW_RUNS_NOT_SUPPORTED",
|
|
269
|
+
domain: "STORAGE" /* STORAGE */,
|
|
270
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
271
|
+
text: `Listing workflow runs is not implemented by this storage adapter (${this.constructor.name})`
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
async listThreadsByResourceId(args) {
|
|
275
|
+
if (this.stores?.memory) {
|
|
276
|
+
return this.stores.memory.listThreadsByResourceId(args);
|
|
277
|
+
}
|
|
278
|
+
throw new MastraError({
|
|
279
|
+
id: "MASTRA_STORAGE_LIST_THREADS_BY_RESOURCE_ID_PAGINATED_NOT_SUPPORTED",
|
|
280
|
+
domain: "STORAGE" /* STORAGE */,
|
|
281
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
282
|
+
text: `Listing threads by resource ID paginated is not implemented by this storage adapter (${this.constructor.name})`
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
async listMessagesById({ messageIds }) {
|
|
286
|
+
if (this.stores?.memory) {
|
|
287
|
+
const result = await this.stores.memory.listMessagesById({ messageIds });
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
290
|
+
throw new MastraError({
|
|
291
|
+
id: "MASTRA_STORAGE_LIST_MESSAGES_BY_ID_NOT_SUPPORTED",
|
|
292
|
+
domain: "STORAGE" /* STORAGE */,
|
|
293
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
294
|
+
text: `Listing messages by ID is not implemented by this storage adapter (${this.constructor.name})`
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
async deleteMessages(_messageIds) {
|
|
298
|
+
throw new Error(
|
|
299
|
+
`Message deletion is not supported by this storage adapter (${this.constructor.name}). The deleteMessages method needs to be implemented in the storage adapter.`
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
async init() {
|
|
303
|
+
if (this.shouldCacheInit && await this.hasInitialized) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const tableCreationTasks = [
|
|
307
|
+
this.createTable({
|
|
308
|
+
tableName: TABLE_WORKFLOW_SNAPSHOT,
|
|
309
|
+
schema: TABLE_SCHEMAS[TABLE_WORKFLOW_SNAPSHOT]
|
|
310
|
+
}),
|
|
311
|
+
this.createTable({
|
|
312
|
+
tableName: TABLE_THREADS,
|
|
313
|
+
schema: TABLE_SCHEMAS[TABLE_THREADS]
|
|
314
|
+
}),
|
|
315
|
+
this.createTable({
|
|
316
|
+
tableName: TABLE_MESSAGES,
|
|
317
|
+
schema: TABLE_SCHEMAS[TABLE_MESSAGES]
|
|
318
|
+
}),
|
|
319
|
+
this.createTable({
|
|
320
|
+
tableName: TABLE_TRACES,
|
|
321
|
+
schema: TABLE_SCHEMAS[TABLE_TRACES]
|
|
322
|
+
}),
|
|
323
|
+
this.createTable({
|
|
324
|
+
tableName: TABLE_SCORERS,
|
|
325
|
+
schema: TABLE_SCHEMAS[TABLE_SCORERS]
|
|
326
|
+
})
|
|
327
|
+
];
|
|
328
|
+
if (this.supports.resourceWorkingMemory) {
|
|
329
|
+
tableCreationTasks.push(
|
|
330
|
+
this.createTable({
|
|
331
|
+
tableName: TABLE_RESOURCES,
|
|
332
|
+
schema: TABLE_SCHEMAS[TABLE_RESOURCES]
|
|
333
|
+
})
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
if (this.supports.observabilityInstance) {
|
|
337
|
+
tableCreationTasks.push(
|
|
338
|
+
this.createTable({
|
|
339
|
+
tableName: TABLE_SPANS,
|
|
340
|
+
schema: TABLE_SCHEMAS[TABLE_SPANS]
|
|
341
|
+
})
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
this.hasInitialized = Promise.all(tableCreationTasks).then(() => true);
|
|
345
|
+
await this.hasInitialized;
|
|
346
|
+
await this?.alterTable?.({
|
|
347
|
+
tableName: TABLE_MESSAGES,
|
|
348
|
+
schema: TABLE_SCHEMAS[TABLE_MESSAGES],
|
|
349
|
+
ifNotExists: ["resourceId"]
|
|
350
|
+
});
|
|
351
|
+
await this?.alterTable?.({
|
|
352
|
+
tableName: TABLE_WORKFLOW_SNAPSHOT,
|
|
353
|
+
schema: TABLE_SCHEMAS[TABLE_WORKFLOW_SNAPSHOT],
|
|
354
|
+
ifNotExists: ["resourceId"]
|
|
355
|
+
});
|
|
356
|
+
await this?.alterTable?.({
|
|
357
|
+
tableName: TABLE_SCORERS,
|
|
358
|
+
schema: TABLE_SCHEMAS[TABLE_SCORERS],
|
|
359
|
+
ifNotExists: ["spanId", "requestContext"]
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
async persistWorkflowSnapshot({
|
|
363
|
+
workflowName,
|
|
364
|
+
runId,
|
|
365
|
+
resourceId,
|
|
366
|
+
snapshot
|
|
367
|
+
}) {
|
|
368
|
+
await this.init();
|
|
369
|
+
const data = {
|
|
370
|
+
workflow_name: workflowName,
|
|
371
|
+
run_id: runId,
|
|
372
|
+
resourceId,
|
|
373
|
+
snapshot,
|
|
374
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
375
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
376
|
+
};
|
|
377
|
+
this.logger.debug("Persisting workflow snapshot", { workflowName, runId, data });
|
|
378
|
+
await this.insert({
|
|
379
|
+
tableName: TABLE_WORKFLOW_SNAPSHOT,
|
|
380
|
+
record: data
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
async loadWorkflowSnapshot({
|
|
384
|
+
workflowName,
|
|
385
|
+
runId
|
|
386
|
+
}) {
|
|
387
|
+
if (!this.hasInitialized) {
|
|
388
|
+
await this.init();
|
|
389
|
+
}
|
|
390
|
+
this.logger.debug("Loading workflow snapshot", { workflowName, runId });
|
|
391
|
+
const d = await this.load({
|
|
392
|
+
tableName: TABLE_WORKFLOW_SNAPSHOT,
|
|
393
|
+
keys: { workflow_name: workflowName, run_id: runId }
|
|
394
|
+
});
|
|
395
|
+
return d ? d.snapshot : null;
|
|
396
|
+
}
|
|
397
|
+
async listScoresBySpan({
|
|
398
|
+
traceId,
|
|
399
|
+
spanId,
|
|
400
|
+
pagination: _pagination
|
|
401
|
+
}) {
|
|
402
|
+
throw new MastraError({
|
|
403
|
+
id: "SCORES_STORAGE_GET_SCORES_BY_SPAN_NOT_IMPLEMENTED",
|
|
404
|
+
domain: "STORAGE" /* STORAGE */,
|
|
405
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
406
|
+
details: { traceId, spanId }
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* OBSERVABILITY
|
|
411
|
+
*/
|
|
412
|
+
/**
|
|
413
|
+
* Provides hints for tracing strategy selection by the DefaultExporter.
|
|
414
|
+
* Storage adapters can override this to specify their preferred and supported strategies.
|
|
415
|
+
*/
|
|
416
|
+
get tracingStrategy() {
|
|
417
|
+
if (this.stores?.observability) {
|
|
418
|
+
return this.stores.observability.tracingStrategy;
|
|
419
|
+
}
|
|
420
|
+
throw new MastraError({
|
|
421
|
+
id: "MASTRA_STORAGE_TRACING_STRATEGY_NOT_SUPPORTED",
|
|
422
|
+
domain: "STORAGE" /* STORAGE */,
|
|
423
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
424
|
+
text: `tracing is not supported by this storage adapter (${this.constructor.name})`
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Creates a single Span record in the storage provider.
|
|
429
|
+
*/
|
|
430
|
+
async createSpan(span) {
|
|
431
|
+
if (this.stores?.observability) {
|
|
432
|
+
return this.stores.observability.createSpan(span);
|
|
433
|
+
}
|
|
434
|
+
throw new MastraError({
|
|
435
|
+
id: "MASTRA_STORAGE_CREATE_AI_SPAN_NOT_SUPPORTED",
|
|
436
|
+
domain: "STORAGE" /* STORAGE */,
|
|
437
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
438
|
+
text: `tracing is not supported by this storage adapter (${this.constructor.name})`
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Updates a single Span with partial data. Primarily used for realtime trace creation.
|
|
443
|
+
*/
|
|
444
|
+
async updateSpan(params) {
|
|
445
|
+
if (this.stores?.observability) {
|
|
446
|
+
return this.stores.observability.updateSpan(params);
|
|
447
|
+
}
|
|
448
|
+
throw new MastraError({
|
|
449
|
+
id: "MASTRA_STORAGE_UPDATE_AI_SPAN_NOT_SUPPORTED",
|
|
450
|
+
domain: "STORAGE" /* STORAGE */,
|
|
451
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
452
|
+
text: `tracing is not supported by this storage adapter (${this.constructor.name})`
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Retrieves a single trace with all its associated spans.
|
|
457
|
+
*/
|
|
458
|
+
async getTrace(traceId) {
|
|
459
|
+
if (this.stores?.observability) {
|
|
460
|
+
return this.stores.observability.getTrace(traceId);
|
|
461
|
+
}
|
|
462
|
+
throw new MastraError({
|
|
463
|
+
id: "MASTRA_STORAGE_GET_TRACE_NOT_SUPPORTED",
|
|
464
|
+
domain: "STORAGE" /* STORAGE */,
|
|
465
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
466
|
+
text: `tracing is not supported by this storage adapter (${this.constructor.name})`
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Retrieves a paginated list of traces with optional filtering.
|
|
471
|
+
*/
|
|
472
|
+
async getTracesPaginated(args) {
|
|
473
|
+
if (this.stores?.observability) {
|
|
474
|
+
return this.stores.observability.getTracesPaginated(args);
|
|
475
|
+
}
|
|
476
|
+
throw new MastraError({
|
|
477
|
+
id: "MASTRA_STORAGE_GET_TRACES_PAGINATED_NOT_SUPPORTED",
|
|
478
|
+
domain: "STORAGE" /* STORAGE */,
|
|
479
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
480
|
+
text: `tracing is not supported by this storage adapter (${this.constructor.name})`
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Creates multiple Spans in a single batch.
|
|
485
|
+
*/
|
|
486
|
+
async batchCreateSpans(args) {
|
|
487
|
+
if (this.stores?.observability) {
|
|
488
|
+
return this.stores.observability.batchCreateSpans(args);
|
|
489
|
+
}
|
|
490
|
+
throw new MastraError({
|
|
491
|
+
id: "MASTRA_STORAGE_BATCH_CREATE_AI_SPANS_NOT_SUPPORTED",
|
|
492
|
+
domain: "STORAGE" /* STORAGE */,
|
|
493
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
494
|
+
text: `tracing is not supported by this storage adapter (${this.constructor.name})`
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Updates multiple Spans in a single batch.
|
|
499
|
+
*/
|
|
500
|
+
async batchUpdateSpans(args) {
|
|
501
|
+
if (this.stores?.observability) {
|
|
502
|
+
return this.stores.observability.batchUpdateSpans(args);
|
|
503
|
+
}
|
|
504
|
+
throw new MastraError({
|
|
505
|
+
id: "MASTRA_STORAGE_BATCH_UPDATE_AI_SPANS_NOT_SUPPORTED",
|
|
506
|
+
domain: "STORAGE" /* STORAGE */,
|
|
507
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
508
|
+
text: `tracing is not supported by this storage adapter (${this.constructor.name})`
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Deletes multiple traces and all their associated spans in a single batch operation.
|
|
513
|
+
*/
|
|
514
|
+
async batchDeleteTraces(args) {
|
|
515
|
+
if (this.stores?.observability) {
|
|
516
|
+
return this.stores.observability.batchDeleteTraces(args);
|
|
517
|
+
}
|
|
518
|
+
throw new MastraError({
|
|
519
|
+
id: "MASTRA_STORAGE_BATCH_DELETE_TRACES_NOT_SUPPORTED",
|
|
520
|
+
domain: "STORAGE" /* STORAGE */,
|
|
521
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
522
|
+
text: `tracing is not supported by this storage adapter (${this.constructor.name})`
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* DATABASE INDEX MANAGEMENT
|
|
527
|
+
* These methods delegate to the operations store for index management.
|
|
528
|
+
* Storage adapters that support indexes should implement these in their operations class.
|
|
529
|
+
*/
|
|
530
|
+
/**
|
|
531
|
+
* Creates a database index on specified columns
|
|
532
|
+
* @throws {MastraError} if not supported by the storage adapter
|
|
533
|
+
*/
|
|
534
|
+
async createIndex(options) {
|
|
535
|
+
if (this.stores?.operations) {
|
|
536
|
+
return this.stores.operations.createIndex(options);
|
|
537
|
+
}
|
|
538
|
+
throw new MastraError({
|
|
539
|
+
id: "MASTRA_STORAGE_CREATE_INDEX_NOT_SUPPORTED",
|
|
540
|
+
domain: "STORAGE" /* STORAGE */,
|
|
541
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
542
|
+
text: `Index management is not supported by this storage adapter (${this.constructor.name})`
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Drops a database index by name
|
|
547
|
+
* @throws {MastraError} if not supported by the storage adapter
|
|
548
|
+
*/
|
|
549
|
+
async dropIndex(indexName) {
|
|
550
|
+
if (this.stores?.operations) {
|
|
551
|
+
return this.stores.operations.dropIndex(indexName);
|
|
552
|
+
}
|
|
553
|
+
throw new MastraError({
|
|
554
|
+
id: "MASTRA_STORAGE_DROP_INDEX_NOT_SUPPORTED",
|
|
555
|
+
domain: "STORAGE" /* STORAGE */,
|
|
556
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
557
|
+
text: `Index management is not supported by this storage adapter (${this.constructor.name})`
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Lists database indexes for a table or all tables
|
|
562
|
+
* @throws {MastraError} if not supported by the storage adapter
|
|
563
|
+
*/
|
|
564
|
+
async listIndexes(tableName) {
|
|
565
|
+
if (this.stores?.operations) {
|
|
566
|
+
return this.stores.operations.listIndexes(tableName);
|
|
567
|
+
}
|
|
568
|
+
throw new MastraError({
|
|
569
|
+
id: "MASTRA_STORAGE_LIST_INDEXES_NOT_SUPPORTED",
|
|
570
|
+
domain: "STORAGE" /* STORAGE */,
|
|
571
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
572
|
+
text: `Index management is not supported by this storage adapter (${this.constructor.name})`
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Gets detailed statistics for a specific index
|
|
577
|
+
* @throws {MastraError} if not supported by the storage adapter
|
|
578
|
+
*/
|
|
579
|
+
async describeIndex(indexName) {
|
|
580
|
+
if (this.stores?.operations) {
|
|
581
|
+
return this.stores.operations.describeIndex(indexName);
|
|
582
|
+
}
|
|
583
|
+
throw new MastraError({
|
|
584
|
+
id: "MASTRA_STORAGE_DESCRIBE_INDEX_NOT_SUPPORTED",
|
|
585
|
+
domain: "STORAGE" /* STORAGE */,
|
|
586
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
587
|
+
text: `Index management is not supported by this storage adapter (${this.constructor.name})`
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
// src/storage/utils.ts
|
|
593
|
+
function safelyParseJSON(input) {
|
|
594
|
+
if (input && typeof input === "object") return input;
|
|
595
|
+
if (input == null) return {};
|
|
596
|
+
if (typeof input === "string") {
|
|
597
|
+
try {
|
|
598
|
+
return JSON.parse(input);
|
|
599
|
+
} catch {
|
|
600
|
+
return input;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
return {};
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// src/storage/domains/memory/base.ts
|
|
607
|
+
var MemoryStorage = class extends MastraBase {
|
|
608
|
+
constructor() {
|
|
609
|
+
super({
|
|
610
|
+
component: "STORAGE",
|
|
611
|
+
name: "MEMORY"
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
async deleteMessages(_messageIds) {
|
|
615
|
+
throw new Error(
|
|
616
|
+
`Message deletion is not supported by this storage adapter (${this.constructor.name}). The deleteMessages method needs to be implemented in the storage adapter.`
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
async getResourceById(_) {
|
|
620
|
+
throw new Error(
|
|
621
|
+
`Resource working memory is not implemented by this storage adapter (${this.constructor.name}). This is likely a bug - all Mastra storage adapters should implement resource support. Please report this issue at https://github.com/mastra-ai/mastra/issues`
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
async saveResource(_) {
|
|
625
|
+
throw new Error(
|
|
626
|
+
`Resource working memory is not implemented by this storage adapter (${this.constructor.name}). This is likely a bug - all Mastra storage adapters should implement resource support. Please report this issue at https://github.com/mastra-ai/mastra/issues`
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
async updateResource(_) {
|
|
630
|
+
throw new Error(
|
|
631
|
+
`Resource working memory is not implemented by this storage adapter (${this.constructor.name}). This is likely a bug - all Mastra storage adapters should implement resource support. Please report this issue at https://github.com/mastra-ai/mastra/issues`
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
parseOrderBy(orderBy, defaultDirection = "DESC") {
|
|
635
|
+
return {
|
|
636
|
+
field: orderBy?.field && orderBy.field in THREAD_ORDER_BY_SET ? orderBy.field : "createdAt",
|
|
637
|
+
direction: orderBy?.direction && orderBy.direction in THREAD_THREAD_SORT_DIRECTION_SET ? orderBy.direction : defaultDirection
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
var THREAD_ORDER_BY_SET = {
|
|
642
|
+
createdAt: true,
|
|
643
|
+
updatedAt: true
|
|
644
|
+
};
|
|
645
|
+
var THREAD_THREAD_SORT_DIRECTION_SET = {
|
|
646
|
+
ASC: true,
|
|
647
|
+
DESC: true
|
|
648
|
+
};
|
|
649
|
+
|
|
650
|
+
// src/storage/domains/memory/inmemory.ts
|
|
651
|
+
var InMemoryMemory = class extends MemoryStorage {
|
|
652
|
+
collection;
|
|
653
|
+
operations;
|
|
654
|
+
constructor({
|
|
655
|
+
collection,
|
|
656
|
+
operations
|
|
657
|
+
}) {
|
|
658
|
+
super();
|
|
659
|
+
this.collection = collection;
|
|
660
|
+
this.operations = operations;
|
|
661
|
+
}
|
|
662
|
+
async getThreadById({ threadId }) {
|
|
663
|
+
this.logger.debug(`MockStore: getThreadById called for ${threadId}`);
|
|
664
|
+
const thread = this.collection.threads.get(threadId);
|
|
665
|
+
return thread ? { ...thread, metadata: thread.metadata ? { ...thread.metadata } : thread.metadata } : null;
|
|
666
|
+
}
|
|
667
|
+
async saveThread({ thread }) {
|
|
668
|
+
this.logger.debug(`MockStore: saveThread called for ${thread.id}`);
|
|
669
|
+
const key = thread.id;
|
|
670
|
+
this.collection.threads.set(key, thread);
|
|
671
|
+
return thread;
|
|
672
|
+
}
|
|
673
|
+
async updateThread({
|
|
674
|
+
id,
|
|
675
|
+
title,
|
|
676
|
+
metadata
|
|
677
|
+
}) {
|
|
678
|
+
this.logger.debug(`MockStore: updateThread called for ${id}`);
|
|
679
|
+
const thread = this.collection.threads.get(id);
|
|
680
|
+
if (!thread) {
|
|
681
|
+
throw new Error(`Thread with id ${id} not found`);
|
|
682
|
+
}
|
|
683
|
+
if (thread) {
|
|
684
|
+
thread.title = title;
|
|
685
|
+
thread.metadata = { ...thread.metadata, ...metadata };
|
|
686
|
+
thread.updatedAt = /* @__PURE__ */ new Date();
|
|
687
|
+
}
|
|
688
|
+
return thread;
|
|
689
|
+
}
|
|
690
|
+
async deleteThread({ threadId }) {
|
|
691
|
+
this.logger.debug(`MockStore: deleteThread called for ${threadId}`);
|
|
692
|
+
this.collection.threads.delete(threadId);
|
|
693
|
+
this.collection.messages.forEach((msg, key) => {
|
|
694
|
+
if (msg.thread_id === threadId) {
|
|
695
|
+
this.collection.messages.delete(key);
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
async listMessages({
|
|
700
|
+
threadId,
|
|
701
|
+
resourceId,
|
|
702
|
+
include,
|
|
703
|
+
filter,
|
|
704
|
+
perPage: perPageInput,
|
|
705
|
+
page = 0,
|
|
706
|
+
orderBy
|
|
707
|
+
}) {
|
|
708
|
+
this.logger.debug(`MockStore: listMessages called for thread ${threadId}`);
|
|
709
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
710
|
+
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
711
|
+
const perPage = normalizePerPage(perPageInput, 40);
|
|
712
|
+
if (page < 0) {
|
|
713
|
+
throw new Error("page must be >= 0");
|
|
714
|
+
}
|
|
715
|
+
const maxOffset = Number.MAX_SAFE_INTEGER / 2;
|
|
716
|
+
if (page * perPage > maxOffset) {
|
|
717
|
+
throw new Error("page value too large");
|
|
718
|
+
}
|
|
719
|
+
const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
720
|
+
let threadMessages = Array.from(this.collection.messages.values()).filter((msg) => {
|
|
721
|
+
if (msg.thread_id !== threadId) return false;
|
|
722
|
+
if (resourceId && msg.resourceId !== resourceId) return false;
|
|
723
|
+
return true;
|
|
724
|
+
});
|
|
725
|
+
if (filter?.dateRange) {
|
|
726
|
+
const { start: from, end: to } = filter.dateRange;
|
|
727
|
+
threadMessages = threadMessages.filter((msg) => {
|
|
728
|
+
const msgDate = new Date(msg.createdAt);
|
|
729
|
+
const fromDate = from ? new Date(from) : null;
|
|
730
|
+
const toDate = to ? new Date(to) : null;
|
|
731
|
+
if (fromDate && msgDate < fromDate) return false;
|
|
732
|
+
if (toDate && msgDate > toDate) return false;
|
|
733
|
+
return true;
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
threadMessages.sort((a, b) => {
|
|
737
|
+
const isDateField = field === "createdAt" || field === "updatedAt";
|
|
738
|
+
const aValue = isDateField ? new Date(a[field]).getTime() : a[field];
|
|
739
|
+
const bValue = isDateField ? new Date(b[field]).getTime() : b[field];
|
|
740
|
+
if (typeof aValue === "number" && typeof bValue === "number") {
|
|
741
|
+
return direction === "ASC" ? aValue - bValue : bValue - aValue;
|
|
742
|
+
}
|
|
743
|
+
return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
|
|
744
|
+
});
|
|
745
|
+
const totalThreadMessages = threadMessages.length;
|
|
746
|
+
const start = offset;
|
|
747
|
+
const end = start + perPage;
|
|
748
|
+
const paginatedThreadMessages = threadMessages.slice(start, end);
|
|
749
|
+
const messages = [];
|
|
750
|
+
const messageIds = /* @__PURE__ */ new Set();
|
|
751
|
+
for (const msg of paginatedThreadMessages) {
|
|
752
|
+
const convertedMessage = this.parseStoredMessage(msg);
|
|
753
|
+
messages.push(convertedMessage);
|
|
754
|
+
messageIds.add(msg.id);
|
|
755
|
+
}
|
|
756
|
+
if (include && include.length > 0) {
|
|
757
|
+
for (const includeItem of include) {
|
|
758
|
+
const targetMessage = this.collection.messages.get(includeItem.id);
|
|
759
|
+
if (targetMessage) {
|
|
760
|
+
const convertedMessage = {
|
|
761
|
+
id: targetMessage.id,
|
|
762
|
+
threadId: targetMessage.thread_id,
|
|
763
|
+
content: safelyParseJSON(targetMessage.content),
|
|
764
|
+
role: targetMessage.role,
|
|
765
|
+
type: targetMessage.type,
|
|
766
|
+
createdAt: targetMessage.createdAt,
|
|
767
|
+
resourceId: targetMessage.resourceId
|
|
768
|
+
};
|
|
769
|
+
if (!messageIds.has(convertedMessage.id)) {
|
|
770
|
+
messages.push(convertedMessage);
|
|
771
|
+
messageIds.add(convertedMessage.id);
|
|
772
|
+
}
|
|
773
|
+
if (includeItem.withPreviousMessages) {
|
|
774
|
+
const allThreadMessages = Array.from(this.collection.messages.values()).filter((msg) => msg.thread_id === (includeItem.threadId || threadId)).sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
775
|
+
const targetIndex = allThreadMessages.findIndex((msg) => msg.id === includeItem.id);
|
|
776
|
+
if (targetIndex !== -1) {
|
|
777
|
+
const startIndex = Math.max(0, targetIndex - (includeItem.withPreviousMessages || 0));
|
|
778
|
+
for (let i = startIndex; i < targetIndex; i++) {
|
|
779
|
+
const message = allThreadMessages[i];
|
|
780
|
+
if (message && !messageIds.has(message.id)) {
|
|
781
|
+
const convertedPrevMessage = {
|
|
782
|
+
id: message.id,
|
|
783
|
+
threadId: message.thread_id,
|
|
784
|
+
content: safelyParseJSON(message.content),
|
|
785
|
+
role: message.role,
|
|
786
|
+
type: message.type,
|
|
787
|
+
createdAt: message.createdAt,
|
|
788
|
+
resourceId: message.resourceId
|
|
789
|
+
};
|
|
790
|
+
messages.push(convertedPrevMessage);
|
|
791
|
+
messageIds.add(message.id);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
if (includeItem.withNextMessages) {
|
|
797
|
+
const allThreadMessages = Array.from(this.collection.messages.values()).filter((msg) => msg.thread_id === (includeItem.threadId || threadId)).sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
798
|
+
const targetIndex = allThreadMessages.findIndex((msg) => msg.id === includeItem.id);
|
|
799
|
+
if (targetIndex !== -1) {
|
|
800
|
+
const endIndex = Math.min(
|
|
801
|
+
allThreadMessages.length,
|
|
802
|
+
targetIndex + (includeItem.withNextMessages || 0) + 1
|
|
803
|
+
);
|
|
804
|
+
for (let i = targetIndex + 1; i < endIndex; i++) {
|
|
805
|
+
const message = allThreadMessages[i];
|
|
806
|
+
if (message && !messageIds.has(message.id)) {
|
|
807
|
+
const convertedNextMessage = {
|
|
808
|
+
id: message.id,
|
|
809
|
+
threadId: message.thread_id,
|
|
810
|
+
content: safelyParseJSON(message.content),
|
|
811
|
+
role: message.role,
|
|
812
|
+
type: message.type,
|
|
813
|
+
createdAt: message.createdAt,
|
|
814
|
+
resourceId: message.resourceId
|
|
815
|
+
};
|
|
816
|
+
messages.push(convertedNextMessage);
|
|
817
|
+
messageIds.add(message.id);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
messages.sort((a, b) => {
|
|
826
|
+
const isDateField = field === "createdAt" || field === "updatedAt";
|
|
827
|
+
const aValue = isDateField ? new Date(a[field]).getTime() : a[field];
|
|
828
|
+
const bValue = isDateField ? new Date(b[field]).getTime() : b[field];
|
|
829
|
+
if (typeof aValue === "number" && typeof bValue === "number") {
|
|
830
|
+
return direction === "ASC" ? aValue - bValue : bValue - aValue;
|
|
831
|
+
}
|
|
832
|
+
return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
|
|
833
|
+
});
|
|
834
|
+
let hasMore;
|
|
835
|
+
if (include && include.length > 0) {
|
|
836
|
+
const returnedThreadMessageIds = new Set(messages.filter((m) => m.threadId === threadId).map((m) => m.id));
|
|
837
|
+
hasMore = returnedThreadMessageIds.size < totalThreadMessages;
|
|
838
|
+
} else {
|
|
839
|
+
hasMore = end < totalThreadMessages;
|
|
840
|
+
}
|
|
841
|
+
return {
|
|
842
|
+
messages,
|
|
843
|
+
total: totalThreadMessages,
|
|
844
|
+
page,
|
|
845
|
+
perPage: perPageForResponse,
|
|
846
|
+
hasMore
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
parseStoredMessage(message) {
|
|
850
|
+
const { resourceId, content, role, thread_id, ...rest } = message;
|
|
851
|
+
let parsedContent = safelyParseJSON(content);
|
|
852
|
+
if (typeof parsedContent === "string") {
|
|
853
|
+
parsedContent = {
|
|
854
|
+
format: 2,
|
|
855
|
+
content: parsedContent,
|
|
856
|
+
parts: [{ type: "text", text: parsedContent }]
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
return {
|
|
860
|
+
...rest,
|
|
861
|
+
threadId: thread_id,
|
|
862
|
+
...message.resourceId && { resourceId: message.resourceId },
|
|
863
|
+
content: parsedContent,
|
|
864
|
+
role
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
async listMessagesById({ messageIds }) {
|
|
868
|
+
this.logger.debug(`MockStore: listMessagesById called`);
|
|
869
|
+
const rawMessages = messageIds.map((id) => this.collection.messages.get(id)).filter((message) => !!message);
|
|
870
|
+
const list = new MessageList().add(rawMessages.map(this.parseStoredMessage), "memory");
|
|
871
|
+
return { messages: list.get.all.db() };
|
|
872
|
+
}
|
|
873
|
+
async saveMessages(args) {
|
|
874
|
+
const { messages } = args;
|
|
875
|
+
this.logger.debug(`MockStore: saveMessages called with ${messages.length} messages`);
|
|
876
|
+
if (messages.some((msg) => msg.id === "error-message" || msg.resourceId === null)) {
|
|
877
|
+
throw new Error("Simulated error for testing");
|
|
878
|
+
}
|
|
879
|
+
const threadIds = new Set(messages.map((msg) => msg.threadId).filter((id) => Boolean(id)));
|
|
880
|
+
for (const threadId of threadIds) {
|
|
881
|
+
const thread = this.collection.threads.get(threadId);
|
|
882
|
+
if (thread) {
|
|
883
|
+
thread.updatedAt = /* @__PURE__ */ new Date();
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
for (const message of messages) {
|
|
887
|
+
const key = message.id;
|
|
888
|
+
const storageMessage = {
|
|
889
|
+
id: message.id,
|
|
890
|
+
thread_id: message.threadId || "",
|
|
891
|
+
content: JSON.stringify(message.content),
|
|
892
|
+
role: message.role || "user",
|
|
893
|
+
type: message.type || "text",
|
|
894
|
+
createdAt: message.createdAt,
|
|
895
|
+
resourceId: message.resourceId || null
|
|
896
|
+
};
|
|
897
|
+
this.collection.messages.set(key, storageMessage);
|
|
898
|
+
}
|
|
899
|
+
const list = new MessageList().add(messages, "memory");
|
|
900
|
+
return { messages: list.get.all.db() };
|
|
901
|
+
}
|
|
902
|
+
async updateMessages(args) {
|
|
903
|
+
const updatedMessages = [];
|
|
904
|
+
for (const update of args.messages) {
|
|
905
|
+
const storageMsg = this.collection.messages.get(update.id);
|
|
906
|
+
if (!storageMsg) continue;
|
|
907
|
+
const oldThreadId = storageMsg.thread_id;
|
|
908
|
+
const newThreadId = update.threadId || oldThreadId;
|
|
909
|
+
let threadIdChanged = false;
|
|
910
|
+
if (update.threadId && update.threadId !== oldThreadId) {
|
|
911
|
+
threadIdChanged = true;
|
|
912
|
+
}
|
|
913
|
+
if (update.role !== void 0) storageMsg.role = update.role;
|
|
914
|
+
if (update.type !== void 0) storageMsg.type = update.type;
|
|
915
|
+
if (update.createdAt !== void 0) storageMsg.createdAt = update.createdAt;
|
|
916
|
+
if (update.resourceId !== void 0) storageMsg.resourceId = update.resourceId;
|
|
917
|
+
if (update.content !== void 0) {
|
|
918
|
+
let oldContent = safelyParseJSON(storageMsg.content);
|
|
919
|
+
let newContent = update.content;
|
|
920
|
+
if (typeof newContent === "object" && typeof oldContent === "object") {
|
|
921
|
+
newContent = { ...oldContent, ...newContent };
|
|
922
|
+
if (oldContent.metadata && newContent.metadata) {
|
|
923
|
+
newContent.metadata = { ...oldContent.metadata, ...newContent.metadata };
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
storageMsg.content = JSON.stringify(newContent);
|
|
927
|
+
}
|
|
928
|
+
if (threadIdChanged) {
|
|
929
|
+
storageMsg.thread_id = newThreadId;
|
|
930
|
+
const base = Date.now();
|
|
931
|
+
let oldThreadNewTime;
|
|
932
|
+
const oldThread = this.collection.threads.get(oldThreadId);
|
|
933
|
+
if (oldThread) {
|
|
934
|
+
const prev = new Date(oldThread.updatedAt).getTime();
|
|
935
|
+
oldThreadNewTime = Math.max(base, prev + 1);
|
|
936
|
+
oldThread.updatedAt = new Date(oldThreadNewTime);
|
|
937
|
+
}
|
|
938
|
+
const newThread = this.collection.threads.get(newThreadId);
|
|
939
|
+
if (newThread) {
|
|
940
|
+
const prev = new Date(newThread.updatedAt).getTime();
|
|
941
|
+
let newThreadNewTime = Math.max(base + 1, prev + 1);
|
|
942
|
+
if (oldThreadNewTime !== void 0 && newThreadNewTime <= oldThreadNewTime) {
|
|
943
|
+
newThreadNewTime = oldThreadNewTime + 1;
|
|
944
|
+
}
|
|
945
|
+
newThread.updatedAt = new Date(newThreadNewTime);
|
|
946
|
+
}
|
|
947
|
+
} else {
|
|
948
|
+
const thread = this.collection.threads.get(oldThreadId);
|
|
949
|
+
if (thread) {
|
|
950
|
+
const prev = new Date(thread.updatedAt).getTime();
|
|
951
|
+
let newTime = Date.now();
|
|
952
|
+
if (newTime <= prev) newTime = prev + 1;
|
|
953
|
+
thread.updatedAt = new Date(newTime);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
this.collection.messages.set(update.id, storageMsg);
|
|
957
|
+
updatedMessages.push({
|
|
958
|
+
id: storageMsg.id,
|
|
959
|
+
threadId: storageMsg.thread_id,
|
|
960
|
+
content: safelyParseJSON(storageMsg.content),
|
|
961
|
+
role: storageMsg.role === "user" || storageMsg.role === "assistant" ? storageMsg.role : "user",
|
|
962
|
+
type: storageMsg.type,
|
|
963
|
+
createdAt: storageMsg.createdAt,
|
|
964
|
+
resourceId: storageMsg.resourceId === null ? void 0 : storageMsg.resourceId
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
return updatedMessages;
|
|
968
|
+
}
|
|
969
|
+
async deleteMessages(messageIds) {
|
|
970
|
+
if (!messageIds || messageIds.length === 0) {
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
this.logger.debug(`MockStore: deleteMessages called for ${messageIds.length} messages`);
|
|
974
|
+
const threadIds = /* @__PURE__ */ new Set();
|
|
975
|
+
for (const messageId of messageIds) {
|
|
976
|
+
const message = this.collection.messages.get(messageId);
|
|
977
|
+
if (message && message.thread_id) {
|
|
978
|
+
threadIds.add(message.thread_id);
|
|
979
|
+
}
|
|
980
|
+
this.collection.messages.delete(messageId);
|
|
981
|
+
}
|
|
982
|
+
const now = /* @__PURE__ */ new Date();
|
|
983
|
+
for (const threadId of threadIds) {
|
|
984
|
+
const thread = this.collection.threads.get(threadId);
|
|
985
|
+
if (thread) {
|
|
986
|
+
thread.updatedAt = now;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
async listThreadsByResourceId(args) {
|
|
991
|
+
const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
|
|
992
|
+
const { field, direction } = this.parseOrderBy(orderBy);
|
|
993
|
+
const perPage = normalizePerPage(perPageInput, 100);
|
|
994
|
+
if (page < 0) {
|
|
995
|
+
throw new Error("page must be >= 0");
|
|
996
|
+
}
|
|
997
|
+
const maxOffset = Number.MAX_SAFE_INTEGER / 2;
|
|
998
|
+
if (page * perPage > maxOffset) {
|
|
999
|
+
throw new Error("page value too large");
|
|
1000
|
+
}
|
|
1001
|
+
this.logger.debug(`MockStore: listThreadsByResourceId called for ${resourceId}`);
|
|
1002
|
+
const threads = Array.from(this.collection.threads.values()).filter((t) => t.resourceId === resourceId);
|
|
1003
|
+
const sortedThreads = this.sortThreads(threads, field, direction);
|
|
1004
|
+
const clonedThreads = sortedThreads.map((thread) => ({
|
|
1005
|
+
...thread,
|
|
1006
|
+
metadata: thread.metadata ? { ...thread.metadata } : thread.metadata
|
|
1007
|
+
}));
|
|
1008
|
+
const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
1009
|
+
return {
|
|
1010
|
+
threads: clonedThreads.slice(offset, offset + perPage),
|
|
1011
|
+
total: clonedThreads.length,
|
|
1012
|
+
page,
|
|
1013
|
+
perPage: perPageForResponse,
|
|
1014
|
+
hasMore: offset + perPage < clonedThreads.length
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
async getResourceById({ resourceId }) {
|
|
1018
|
+
this.logger.debug(`MockStore: getResourceById called for ${resourceId}`);
|
|
1019
|
+
const resource = this.collection.resources.get(resourceId);
|
|
1020
|
+
return resource ? { ...resource, metadata: resource.metadata ? { ...resource.metadata } : resource.metadata } : null;
|
|
1021
|
+
}
|
|
1022
|
+
async saveResource({ resource }) {
|
|
1023
|
+
this.logger.debug(`MockStore: saveResource called for ${resource.id}`);
|
|
1024
|
+
this.collection.resources.set(resource.id, resource);
|
|
1025
|
+
return resource;
|
|
1026
|
+
}
|
|
1027
|
+
async updateResource({
|
|
1028
|
+
resourceId,
|
|
1029
|
+
workingMemory,
|
|
1030
|
+
metadata
|
|
1031
|
+
}) {
|
|
1032
|
+
this.logger.debug(`MockStore: updateResource called for ${resourceId}`);
|
|
1033
|
+
let resource = this.collection.resources.get(resourceId);
|
|
1034
|
+
if (!resource) {
|
|
1035
|
+
resource = {
|
|
1036
|
+
id: resourceId,
|
|
1037
|
+
workingMemory,
|
|
1038
|
+
metadata: metadata || {},
|
|
1039
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1040
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1041
|
+
};
|
|
1042
|
+
} else {
|
|
1043
|
+
resource = {
|
|
1044
|
+
...resource,
|
|
1045
|
+
workingMemory: workingMemory !== void 0 ? workingMemory : resource.workingMemory,
|
|
1046
|
+
metadata: {
|
|
1047
|
+
...resource.metadata,
|
|
1048
|
+
...metadata
|
|
1049
|
+
},
|
|
1050
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1051
|
+
};
|
|
1052
|
+
}
|
|
1053
|
+
this.collection.resources.set(resourceId, resource);
|
|
1054
|
+
return resource;
|
|
1055
|
+
}
|
|
1056
|
+
sortThreads(threads, field, direction) {
|
|
1057
|
+
return threads.sort((a, b) => {
|
|
1058
|
+
const isDateField = field === "createdAt" || field === "updatedAt";
|
|
1059
|
+
const aValue = isDateField ? new Date(a[field]).getTime() : a[field];
|
|
1060
|
+
const bValue = isDateField ? new Date(b[field]).getTime() : b[field];
|
|
1061
|
+
if (typeof aValue === "number" && typeof bValue === "number") {
|
|
1062
|
+
if (direction === "ASC") {
|
|
1063
|
+
return aValue - bValue;
|
|
1064
|
+
} else {
|
|
1065
|
+
return bValue - aValue;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
};
|
|
1072
|
+
|
|
1073
|
+
// src/storage/domains/observability/base.ts
|
|
1074
|
+
var ObservabilityStorage = class extends MastraBase {
|
|
1075
|
+
constructor() {
|
|
1076
|
+
super({
|
|
1077
|
+
component: "STORAGE",
|
|
1078
|
+
name: "OBSERVABILITY"
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
* Provides hints for tracing strategy selection by the DefaultExporter.
|
|
1083
|
+
* Storage adapters can override this to specify their preferred and supported strategies.
|
|
1084
|
+
*/
|
|
1085
|
+
get tracingStrategy() {
|
|
1086
|
+
return {
|
|
1087
|
+
preferred: "batch-with-updates",
|
|
1088
|
+
// Default for most SQL stores
|
|
1089
|
+
supported: ["realtime", "batch-with-updates", "insert-only"]
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Creates a single Span record in the storage provider.
|
|
1094
|
+
*/
|
|
1095
|
+
createSpan(_span) {
|
|
1096
|
+
throw new MastraError({
|
|
1097
|
+
id: "OBSERVABILITY_CREATE_SPAN_NOT_IMPLEMENTED",
|
|
1098
|
+
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1099
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1100
|
+
text: "This storage provider does not support creating spans"
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* Updates a single Span with partial data. Primarily used for realtime trace creation.
|
|
1105
|
+
*/
|
|
1106
|
+
updateSpan(_params) {
|
|
1107
|
+
throw new MastraError({
|
|
1108
|
+
id: "OBSERVABILITY_STORAGE_UPDATE_SPAN_NOT_IMPLEMENTED",
|
|
1109
|
+
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1110
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1111
|
+
text: "This storage provider does not support updating spans"
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* Retrieves a single trace with all its associated spans.
|
|
1116
|
+
*/
|
|
1117
|
+
getTrace(_traceId) {
|
|
1118
|
+
throw new MastraError({
|
|
1119
|
+
id: "OBSERVABILITY_STORAGE_GET_TRACE_NOT_IMPLEMENTED",
|
|
1120
|
+
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1121
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1122
|
+
text: "This storage provider does not support getting traces"
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Retrieves a paginated list of traces with optional filtering.
|
|
1127
|
+
*/
|
|
1128
|
+
getTracesPaginated(_args) {
|
|
1129
|
+
throw new MastraError({
|
|
1130
|
+
id: "OBSERVABILITY_STORAGE_GET_TRACES_PAGINATED_NOT_IMPLEMENTED",
|
|
1131
|
+
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1132
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1133
|
+
text: "This storage provider does not support getting traces paginated"
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* Creates multiple Spans in a single batch.
|
|
1138
|
+
*/
|
|
1139
|
+
batchCreateSpans(_args) {
|
|
1140
|
+
throw new MastraError({
|
|
1141
|
+
id: "OBSERVABILITY_STORAGE_BATCH_CREATE_SPAN_NOT_IMPLEMENTED",
|
|
1142
|
+
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1143
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1144
|
+
text: "This storage provider does not support batch creating spans"
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Updates multiple Spans in a single batch.
|
|
1149
|
+
*/
|
|
1150
|
+
batchUpdateSpans(_args) {
|
|
1151
|
+
throw new MastraError({
|
|
1152
|
+
id: "OBSERVABILITY_STORAGE_BATCH_UPDATE_SPANS_NOT_IMPLEMENTED",
|
|
1153
|
+
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1154
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1155
|
+
text: "This storage provider does not support batch updating spans"
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* Deletes multiple traces and all their associated spans in a single batch operation.
|
|
1160
|
+
*/
|
|
1161
|
+
batchDeleteTraces(_args) {
|
|
1162
|
+
throw new MastraError({
|
|
1163
|
+
id: "OBSERVABILITY_STORAGE_BATCH_DELETE_TRACES_NOT_IMPLEMENTED",
|
|
1164
|
+
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1165
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1166
|
+
text: "This storage provider does not support batch deleting traces"
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
};
|
|
1170
|
+
|
|
1171
|
+
// src/storage/domains/observability/inmemory.ts
|
|
1172
|
+
var ObservabilityInMemory = class extends ObservabilityStorage {
|
|
1173
|
+
operations;
|
|
1174
|
+
collection;
|
|
1175
|
+
constructor({ collection, operations }) {
|
|
1176
|
+
super();
|
|
1177
|
+
this.collection = collection;
|
|
1178
|
+
this.operations = operations;
|
|
1179
|
+
}
|
|
1180
|
+
get tracingStrategy() {
|
|
1181
|
+
return {
|
|
1182
|
+
preferred: "realtime",
|
|
1183
|
+
supported: ["realtime", "batch-with-updates", "insert-only"]
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
async createSpan(span) {
|
|
1187
|
+
this.validateCreateSpan(span);
|
|
1188
|
+
const id = this.generateId(span);
|
|
1189
|
+
const record = span;
|
|
1190
|
+
record.createdAt = /* @__PURE__ */ new Date();
|
|
1191
|
+
record.updatedAt = record.createdAt;
|
|
1192
|
+
this.collection.set(id, record);
|
|
1193
|
+
}
|
|
1194
|
+
async batchCreateSpans(args) {
|
|
1195
|
+
for (const record of args.records) {
|
|
1196
|
+
await this.createSpan(record);
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
validateCreateSpan(record) {
|
|
1200
|
+
if (!record.spanId) {
|
|
1201
|
+
throw new MastraError({
|
|
1202
|
+
id: "OBSERVABILITY_SPAN_ID_REQUIRED",
|
|
1203
|
+
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1204
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1205
|
+
text: "Span ID is required for creating a span"
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
if (!record.traceId) {
|
|
1209
|
+
throw new MastraError({
|
|
1210
|
+
id: "OBSERVABILITY_TRACE_ID_REQUIRED",
|
|
1211
|
+
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1212
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1213
|
+
text: "Trace ID is required for creating a span"
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
generateId({ traceId, spanId }) {
|
|
1218
|
+
return `${traceId}-${spanId}`;
|
|
1219
|
+
}
|
|
1220
|
+
async getTrace(traceId) {
|
|
1221
|
+
const spans = Array.from(this.collection.values()).filter((span) => span.traceId === traceId);
|
|
1222
|
+
if (spans.length === 0) {
|
|
1223
|
+
return null;
|
|
1224
|
+
}
|
|
1225
|
+
spans.sort((a, b) => a.startedAt.getTime() - b.startedAt.getTime());
|
|
1226
|
+
return {
|
|
1227
|
+
traceId,
|
|
1228
|
+
spans
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
async getTracesPaginated({
|
|
1232
|
+
filters,
|
|
1233
|
+
pagination
|
|
1234
|
+
}) {
|
|
1235
|
+
const allRootSpans = this.filterForRootSpans(Array.from(this.collection.values()));
|
|
1236
|
+
const filteredRootSpans = this.filterSpansByFilter(allRootSpans, filters);
|
|
1237
|
+
const startDate = pagination?.dateRange?.start;
|
|
1238
|
+
const endDate = pagination?.dateRange?.end;
|
|
1239
|
+
const filteredRootSpansByDate = this.filterSpansByDate(filteredRootSpans, startDate, endDate);
|
|
1240
|
+
const total = filteredRootSpansByDate.length;
|
|
1241
|
+
const page = pagination?.page ?? 0;
|
|
1242
|
+
const perPage = pagination?.perPage ?? 10;
|
|
1243
|
+
const start = page * perPage;
|
|
1244
|
+
const end = start + perPage;
|
|
1245
|
+
const paged = this.filterSpansByPagination(filteredRootSpansByDate, pagination);
|
|
1246
|
+
return {
|
|
1247
|
+
spans: paged,
|
|
1248
|
+
pagination: { total, page, perPage, hasMore: end < total }
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
filterForRootSpans(spans) {
|
|
1252
|
+
return spans.filter((span) => span.parentSpanId === null);
|
|
1253
|
+
}
|
|
1254
|
+
filterSpansByDate(spans, startDate, endDate) {
|
|
1255
|
+
return spans.filter((span) => {
|
|
1256
|
+
if (startDate && span.startedAt < startDate) return false;
|
|
1257
|
+
if (endDate && span.startedAt > endDate) return false;
|
|
1258
|
+
return true;
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
filterSpansByFilter(spans, filter) {
|
|
1262
|
+
return spans.filter((span) => {
|
|
1263
|
+
if (filter?.name && span.name !== filter.name) return false;
|
|
1264
|
+
if (filter?.spanType && span.spanType !== filter.spanType) return false;
|
|
1265
|
+
if (filter?.entityType === "agent" && filter.entityId !== span.attributes?.agentId) return false;
|
|
1266
|
+
if (filter?.entityType === "workflow" && filter.entityId !== span.attributes?.workflowId) return false;
|
|
1267
|
+
return true;
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1270
|
+
filterSpansByPagination(spans, pagination) {
|
|
1271
|
+
const page = pagination?.page ?? 0;
|
|
1272
|
+
const perPage = pagination?.perPage ?? 10;
|
|
1273
|
+
const start = page * perPage;
|
|
1274
|
+
const end = start + perPage;
|
|
1275
|
+
return spans.slice(start, end);
|
|
1276
|
+
}
|
|
1277
|
+
async updateSpan(params) {
|
|
1278
|
+
const id = this.generateId(params);
|
|
1279
|
+
const span = this.collection.get(id);
|
|
1280
|
+
if (!span) {
|
|
1281
|
+
throw new MastraError({
|
|
1282
|
+
id: "OBSERVABILITY_UPDATE_SPAN_NOT_FOUND",
|
|
1283
|
+
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1284
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1285
|
+
text: "Span not found for update"
|
|
1286
|
+
});
|
|
1287
|
+
}
|
|
1288
|
+
this.collection.set(id, { ...span, ...params.updates, updatedAt: /* @__PURE__ */ new Date() });
|
|
1289
|
+
}
|
|
1290
|
+
async batchUpdateSpans(args) {
|
|
1291
|
+
for (const record of args.records) {
|
|
1292
|
+
await this.updateSpan(record);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
async batchDeleteTraces(args) {
|
|
1296
|
+
for (const traceId of args.traceIds) {
|
|
1297
|
+
const spans = Array.from(this.collection.values()).filter((span) => span.traceId === traceId);
|
|
1298
|
+
for (const span of spans) {
|
|
1299
|
+
this.collection.delete(this.generateId(span));
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
|
|
1305
|
+
// src/storage/domains/operations/base.ts
|
|
1306
|
+
var StoreOperations = class extends MastraBase {
|
|
1307
|
+
constructor() {
|
|
1308
|
+
super({
|
|
1309
|
+
component: "STORAGE",
|
|
1310
|
+
name: "OPERATIONS"
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
getSqlType(type) {
|
|
1314
|
+
switch (type) {
|
|
1315
|
+
case "text":
|
|
1316
|
+
return "TEXT";
|
|
1317
|
+
case "timestamp":
|
|
1318
|
+
return "TIMESTAMP";
|
|
1319
|
+
case "float":
|
|
1320
|
+
return "FLOAT";
|
|
1321
|
+
case "integer":
|
|
1322
|
+
return "INTEGER";
|
|
1323
|
+
case "bigint":
|
|
1324
|
+
return "BIGINT";
|
|
1325
|
+
case "jsonb":
|
|
1326
|
+
return "JSONB";
|
|
1327
|
+
default:
|
|
1328
|
+
return "TEXT";
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
getDefaultValue(type) {
|
|
1332
|
+
switch (type) {
|
|
1333
|
+
case "text":
|
|
1334
|
+
case "uuid":
|
|
1335
|
+
return "DEFAULT ''";
|
|
1336
|
+
case "timestamp":
|
|
1337
|
+
return "DEFAULT '1970-01-01 00:00:00'";
|
|
1338
|
+
case "integer":
|
|
1339
|
+
case "bigint":
|
|
1340
|
+
case "float":
|
|
1341
|
+
return "DEFAULT 0";
|
|
1342
|
+
case "jsonb":
|
|
1343
|
+
return "DEFAULT '{}'";
|
|
1344
|
+
default:
|
|
1345
|
+
return "DEFAULT ''";
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* DATABASE INDEX MANAGEMENT
|
|
1350
|
+
* Optional methods for database index management.
|
|
1351
|
+
* Storage adapters can override these to provide index management capabilities.
|
|
1352
|
+
*/
|
|
1353
|
+
/**
|
|
1354
|
+
* Creates a database index on specified columns
|
|
1355
|
+
* @throws {MastraError} if not supported by the storage adapter
|
|
1356
|
+
*/
|
|
1357
|
+
async createIndex(_options) {
|
|
1358
|
+
throw new MastraError({
|
|
1359
|
+
id: "MASTRA_STORAGE_CREATE_INDEX_NOT_SUPPORTED",
|
|
1360
|
+
domain: "STORAGE" /* STORAGE */,
|
|
1361
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1362
|
+
text: `Index management is not supported by this storage adapter`
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* Drops a database index by name
|
|
1367
|
+
* @throws {MastraError} if not supported by the storage adapter
|
|
1368
|
+
*/
|
|
1369
|
+
async dropIndex(_indexName) {
|
|
1370
|
+
throw new MastraError({
|
|
1371
|
+
id: "MASTRA_STORAGE_DROP_INDEX_NOT_SUPPORTED",
|
|
1372
|
+
domain: "STORAGE" /* STORAGE */,
|
|
1373
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1374
|
+
text: `Index management is not supported by this storage adapter`
|
|
1375
|
+
});
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Lists database indexes for a table or all tables
|
|
1379
|
+
* @throws {MastraError} if not supported by the storage adapter
|
|
1380
|
+
*/
|
|
1381
|
+
async listIndexes(_tableName) {
|
|
1382
|
+
throw new MastraError({
|
|
1383
|
+
id: "MASTRA_STORAGE_LIST_INDEXES_NOT_SUPPORTED",
|
|
1384
|
+
domain: "STORAGE" /* STORAGE */,
|
|
1385
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1386
|
+
text: `Index management is not supported by this storage adapter`
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
/**
|
|
1390
|
+
* Gets detailed statistics for a specific index
|
|
1391
|
+
* @throws {MastraError} if not supported by the storage adapter
|
|
1392
|
+
*/
|
|
1393
|
+
async describeIndex(_indexName) {
|
|
1394
|
+
throw new MastraError({
|
|
1395
|
+
id: "MASTRA_STORAGE_DESCRIBE_INDEX_NOT_SUPPORTED",
|
|
1396
|
+
domain: "STORAGE" /* STORAGE */,
|
|
1397
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1398
|
+
text: `Index management is not supported by this storage adapter`
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
/**
|
|
1402
|
+
* Returns definitions for automatic performance indexes
|
|
1403
|
+
* Storage adapters can override this to define indexes that should be created during initialization
|
|
1404
|
+
* @returns Array of index definitions to create automatically
|
|
1405
|
+
*/
|
|
1406
|
+
getAutomaticIndexDefinitions() {
|
|
1407
|
+
return [];
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
|
|
1411
|
+
// src/storage/domains/operations/inmemory.ts
|
|
1412
|
+
var StoreOperationsInMemory = class extends StoreOperations {
|
|
1413
|
+
data;
|
|
1414
|
+
constructor() {
|
|
1415
|
+
super();
|
|
1416
|
+
this.data = {
|
|
1417
|
+
mastra_workflow_snapshot: /* @__PURE__ */ new Map(),
|
|
1418
|
+
mastra_messages: /* @__PURE__ */ new Map(),
|
|
1419
|
+
mastra_threads: /* @__PURE__ */ new Map(),
|
|
1420
|
+
mastra_traces: /* @__PURE__ */ new Map(),
|
|
1421
|
+
mastra_resources: /* @__PURE__ */ new Map(),
|
|
1422
|
+
mastra_scorers: /* @__PURE__ */ new Map(),
|
|
1423
|
+
mastra_ai_spans: /* @__PURE__ */ new Map()
|
|
1424
|
+
};
|
|
1425
|
+
}
|
|
1426
|
+
getDatabase() {
|
|
1427
|
+
return this.data;
|
|
1428
|
+
}
|
|
1429
|
+
async insert({ tableName, record }) {
|
|
1430
|
+
const table = this.data[tableName];
|
|
1431
|
+
let key = record.id;
|
|
1432
|
+
if ([TABLE_WORKFLOW_SNAPSHOT].includes(tableName) && !record.id && record.run_id) {
|
|
1433
|
+
key = record.workflow_name ? `${record.workflow_name}-${record.run_id}` : record.run_id;
|
|
1434
|
+
record.id = key;
|
|
1435
|
+
} else if (!record.id) {
|
|
1436
|
+
key = `auto-${Date.now()}-${Math.random()}`;
|
|
1437
|
+
record.id = key;
|
|
1438
|
+
}
|
|
1439
|
+
table.set(key, record);
|
|
1440
|
+
}
|
|
1441
|
+
async batchInsert({ tableName, records }) {
|
|
1442
|
+
const table = this.data[tableName];
|
|
1443
|
+
for (const record of records) {
|
|
1444
|
+
let key = record.id;
|
|
1445
|
+
if ([TABLE_WORKFLOW_SNAPSHOT].includes(tableName) && !record.id && record.run_id) {
|
|
1446
|
+
key = record.run_id;
|
|
1447
|
+
record.id = key;
|
|
1448
|
+
} else if (!record.id) {
|
|
1449
|
+
key = `auto-${Date.now()}-${Math.random()}`;
|
|
1450
|
+
record.id = key;
|
|
1451
|
+
}
|
|
1452
|
+
table.set(key, record);
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
async load({ tableName, keys }) {
|
|
1456
|
+
this.logger.debug(`MockStore: load called for ${tableName} with keys`, keys);
|
|
1457
|
+
const table = this.data[tableName];
|
|
1458
|
+
const records = Array.from(table.values());
|
|
1459
|
+
return records.filter((record) => Object.keys(keys).every((key) => record[key] === keys[key]))?.[0];
|
|
1460
|
+
}
|
|
1461
|
+
async createTable({
|
|
1462
|
+
tableName,
|
|
1463
|
+
schema
|
|
1464
|
+
}) {
|
|
1465
|
+
this.logger.debug(`MockStore: createTable called for ${tableName} with schema`, schema);
|
|
1466
|
+
this.data[tableName] = /* @__PURE__ */ new Map();
|
|
1467
|
+
}
|
|
1468
|
+
async clearTable({ tableName }) {
|
|
1469
|
+
this.logger.debug(`MockStore: clearTable called for ${tableName}`);
|
|
1470
|
+
this.data[tableName].clear();
|
|
1471
|
+
}
|
|
1472
|
+
async dropTable({ tableName }) {
|
|
1473
|
+
this.logger.debug(`MockStore: dropTable called for ${tableName}`);
|
|
1474
|
+
this.data[tableName].clear();
|
|
1475
|
+
}
|
|
1476
|
+
async alterTable({
|
|
1477
|
+
tableName,
|
|
1478
|
+
schema
|
|
1479
|
+
}) {
|
|
1480
|
+
this.logger.debug(`MockStore: alterTable called for ${tableName} with schema`, schema);
|
|
1481
|
+
}
|
|
1482
|
+
async hasColumn(table, column) {
|
|
1483
|
+
this.logger.debug(`MockStore: hasColumn called for ${table} with column ${column}`);
|
|
1484
|
+
return true;
|
|
1485
|
+
}
|
|
1486
|
+
};
|
|
1487
|
+
|
|
1488
|
+
// src/storage/domains/scores/base.ts
|
|
1489
|
+
var ScoresStorage = class extends MastraBase {
|
|
1490
|
+
constructor() {
|
|
1491
|
+
super({
|
|
1492
|
+
component: "STORAGE",
|
|
1493
|
+
name: "SCORES"
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
async listScoresBySpan({
|
|
1497
|
+
traceId,
|
|
1498
|
+
spanId,
|
|
1499
|
+
pagination: _pagination
|
|
1500
|
+
}) {
|
|
1501
|
+
throw new MastraError({
|
|
1502
|
+
id: "SCORES_STORAGE_GET_SCORES_BY_SPAN_NOT_IMPLEMENTED",
|
|
1503
|
+
domain: "STORAGE" /* STORAGE */,
|
|
1504
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1505
|
+
details: { traceId, spanId }
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1510
|
+
// src/storage/domains/scores/inmemory.ts
|
|
1511
|
+
var ScoresInMemory = class extends ScoresStorage {
|
|
1512
|
+
scores;
|
|
1513
|
+
constructor({ collection }) {
|
|
1514
|
+
super();
|
|
1515
|
+
this.scores = collection;
|
|
1516
|
+
}
|
|
1517
|
+
async getScoreById({ id }) {
|
|
1518
|
+
return this.scores.get(id) ?? null;
|
|
1519
|
+
}
|
|
1520
|
+
async saveScore(score) {
|
|
1521
|
+
const newScore = { id: crypto.randomUUID(), createdAt: /* @__PURE__ */ new Date(), updatedAt: /* @__PURE__ */ new Date(), ...score };
|
|
1522
|
+
this.scores.set(newScore.id, newScore);
|
|
1523
|
+
return { score: newScore };
|
|
1524
|
+
}
|
|
1525
|
+
async listScoresByScorerId({
|
|
1526
|
+
scorerId,
|
|
1527
|
+
pagination,
|
|
1528
|
+
entityId,
|
|
1529
|
+
entityType,
|
|
1530
|
+
source
|
|
1531
|
+
}) {
|
|
1532
|
+
const scores = Array.from(this.scores.values()).filter((score) => {
|
|
1533
|
+
let baseFilter = score.scorerId === scorerId;
|
|
1534
|
+
if (entityId) {
|
|
1535
|
+
baseFilter = baseFilter && score.entityId === entityId;
|
|
1536
|
+
}
|
|
1537
|
+
if (entityType) {
|
|
1538
|
+
baseFilter = baseFilter && score.entityType === entityType;
|
|
1539
|
+
}
|
|
1540
|
+
if (source) {
|
|
1541
|
+
baseFilter = baseFilter && score.source === source;
|
|
1542
|
+
}
|
|
1543
|
+
return baseFilter;
|
|
1544
|
+
});
|
|
1545
|
+
const { page, perPage: perPageInput } = pagination;
|
|
1546
|
+
const perPage = normalizePerPage(perPageInput, Number.MAX_SAFE_INTEGER);
|
|
1547
|
+
const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
1548
|
+
const end = perPageInput === false ? scores.length : start + perPage;
|
|
1549
|
+
return {
|
|
1550
|
+
scores: scores.slice(start, end),
|
|
1551
|
+
pagination: {
|
|
1552
|
+
total: scores.length,
|
|
1553
|
+
page,
|
|
1554
|
+
perPage: perPageForResponse,
|
|
1555
|
+
hasMore: perPageInput === false ? false : scores.length > end
|
|
1556
|
+
}
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
async listScoresByRunId({
|
|
1560
|
+
runId,
|
|
1561
|
+
pagination
|
|
1562
|
+
}) {
|
|
1563
|
+
const scores = Array.from(this.scores.values()).filter((score) => score.runId === runId);
|
|
1564
|
+
const { page, perPage: perPageInput } = pagination;
|
|
1565
|
+
const perPage = normalizePerPage(perPageInput, Number.MAX_SAFE_INTEGER);
|
|
1566
|
+
const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
1567
|
+
const end = perPageInput === false ? scores.length : start + perPage;
|
|
1568
|
+
return {
|
|
1569
|
+
scores: scores.slice(start, end),
|
|
1570
|
+
pagination: {
|
|
1571
|
+
total: scores.length,
|
|
1572
|
+
page,
|
|
1573
|
+
perPage: perPageForResponse,
|
|
1574
|
+
hasMore: perPageInput === false ? false : scores.length > end
|
|
1575
|
+
}
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1578
|
+
async listScoresByEntityId({
|
|
1579
|
+
entityId,
|
|
1580
|
+
entityType,
|
|
1581
|
+
pagination
|
|
1582
|
+
}) {
|
|
1583
|
+
const scores = Array.from(this.scores.values()).filter((score) => {
|
|
1584
|
+
const baseFilter = score.entityId === entityId && score.entityType === entityType;
|
|
1585
|
+
return baseFilter;
|
|
1586
|
+
});
|
|
1587
|
+
const { page, perPage: perPageInput } = pagination;
|
|
1588
|
+
const perPage = normalizePerPage(perPageInput, Number.MAX_SAFE_INTEGER);
|
|
1589
|
+
const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
1590
|
+
const end = perPageInput === false ? scores.length : start + perPage;
|
|
1591
|
+
return {
|
|
1592
|
+
scores: scores.slice(start, end),
|
|
1593
|
+
pagination: {
|
|
1594
|
+
total: scores.length,
|
|
1595
|
+
page,
|
|
1596
|
+
perPage: perPageForResponse,
|
|
1597
|
+
hasMore: perPageInput === false ? false : scores.length > end
|
|
1598
|
+
}
|
|
1599
|
+
};
|
|
1600
|
+
}
|
|
1601
|
+
async listScoresBySpan({
|
|
1602
|
+
traceId,
|
|
1603
|
+
spanId,
|
|
1604
|
+
pagination
|
|
1605
|
+
}) {
|
|
1606
|
+
const scores = Array.from(this.scores.values()).filter(
|
|
1607
|
+
(score) => score.traceId === traceId && score.spanId === spanId
|
|
1608
|
+
);
|
|
1609
|
+
scores.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
|
1610
|
+
const { page, perPage: perPageInput } = pagination;
|
|
1611
|
+
const perPage = normalizePerPage(perPageInput, Number.MAX_SAFE_INTEGER);
|
|
1612
|
+
const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
1613
|
+
const end = perPageInput === false ? scores.length : start + perPage;
|
|
1614
|
+
return {
|
|
1615
|
+
scores: scores.slice(start, end),
|
|
1616
|
+
pagination: {
|
|
1617
|
+
total: scores.length,
|
|
1618
|
+
page,
|
|
1619
|
+
perPage: perPageForResponse,
|
|
1620
|
+
hasMore: perPageInput === false ? false : scores.length > end
|
|
1621
|
+
}
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
};
|
|
1625
|
+
|
|
1626
|
+
// src/storage/domains/workflows/base.ts
|
|
1627
|
+
var WorkflowsStorage = class extends MastraBase {
|
|
1628
|
+
constructor() {
|
|
1629
|
+
super({
|
|
1630
|
+
component: "STORAGE",
|
|
1631
|
+
name: "WORKFLOWS"
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
|
|
1636
|
+
// src/storage/domains/workflows/inmemory.ts
|
|
1637
|
+
var WorkflowsInMemory = class extends WorkflowsStorage {
|
|
1638
|
+
operations;
|
|
1639
|
+
collection;
|
|
1640
|
+
constructor({ collection, operations }) {
|
|
1641
|
+
super();
|
|
1642
|
+
this.collection = collection;
|
|
1643
|
+
this.operations = operations;
|
|
1644
|
+
}
|
|
1645
|
+
async updateWorkflowResults({
|
|
1646
|
+
workflowName,
|
|
1647
|
+
runId,
|
|
1648
|
+
stepId,
|
|
1649
|
+
result,
|
|
1650
|
+
requestContext
|
|
1651
|
+
}) {
|
|
1652
|
+
this.logger.debug(`MockStore: updateWorkflowResults called for ${workflowName} ${runId} ${stepId}`, result);
|
|
1653
|
+
const run = this.collection.get(`${workflowName}-${runId}`);
|
|
1654
|
+
if (!run) {
|
|
1655
|
+
return {};
|
|
1656
|
+
}
|
|
1657
|
+
let snapshot;
|
|
1658
|
+
if (!run.snapshot) {
|
|
1659
|
+
snapshot = {
|
|
1660
|
+
context: {},
|
|
1661
|
+
activePaths: [],
|
|
1662
|
+
timestamp: Date.now(),
|
|
1663
|
+
suspendedPaths: {},
|
|
1664
|
+
resumeLabels: {},
|
|
1665
|
+
serializedStepGraph: [],
|
|
1666
|
+
value: {},
|
|
1667
|
+
waitingPaths: {},
|
|
1668
|
+
status: "pending",
|
|
1669
|
+
runId: run.run_id
|
|
1670
|
+
};
|
|
1671
|
+
this.collection.set(`${workflowName}-${runId}`, {
|
|
1672
|
+
...run,
|
|
1673
|
+
snapshot
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
snapshot = typeof run.snapshot === "string" ? JSON.parse(run.snapshot) : run.snapshot;
|
|
1677
|
+
if (!snapshot || !snapshot?.context) {
|
|
1678
|
+
throw new Error(`Snapshot not found for runId ${runId}`);
|
|
1679
|
+
}
|
|
1680
|
+
snapshot.context[stepId] = result;
|
|
1681
|
+
snapshot.requestContext = { ...snapshot.requestContext, ...requestContext };
|
|
1682
|
+
this.collection.set(`${workflowName}-${runId}`, {
|
|
1683
|
+
...run,
|
|
1684
|
+
snapshot
|
|
1685
|
+
});
|
|
1686
|
+
return JSON.parse(JSON.stringify(snapshot.context));
|
|
1687
|
+
}
|
|
1688
|
+
async updateWorkflowState({
|
|
1689
|
+
workflowName,
|
|
1690
|
+
runId,
|
|
1691
|
+
opts
|
|
1692
|
+
}) {
|
|
1693
|
+
const run = this.collection.get(`${workflowName}-${runId}`);
|
|
1694
|
+
if (!run) {
|
|
1695
|
+
return;
|
|
1696
|
+
}
|
|
1697
|
+
let snapshot;
|
|
1698
|
+
if (!run.snapshot) {
|
|
1699
|
+
snapshot = {
|
|
1700
|
+
context: {},
|
|
1701
|
+
activePaths: [],
|
|
1702
|
+
timestamp: Date.now(),
|
|
1703
|
+
suspendedPaths: {},
|
|
1704
|
+
resumeLabels: {},
|
|
1705
|
+
serializedStepGraph: [],
|
|
1706
|
+
value: {},
|
|
1707
|
+
waitingPaths: {},
|
|
1708
|
+
status: "pending",
|
|
1709
|
+
runId: run.run_id
|
|
1710
|
+
};
|
|
1711
|
+
this.collection.set(`${workflowName}-${runId}`, {
|
|
1712
|
+
...run,
|
|
1713
|
+
snapshot
|
|
1714
|
+
});
|
|
1715
|
+
} else {
|
|
1716
|
+
snapshot = typeof run.snapshot === "string" ? JSON.parse(run.snapshot) : run.snapshot;
|
|
1717
|
+
}
|
|
1718
|
+
if (!snapshot || !snapshot?.context) {
|
|
1719
|
+
throw new Error(`Snapshot not found for runId ${runId}`);
|
|
1720
|
+
}
|
|
1721
|
+
snapshot = { ...snapshot, ...opts };
|
|
1722
|
+
this.collection.set(`${workflowName}-${runId}`, {
|
|
1723
|
+
...run,
|
|
1724
|
+
snapshot
|
|
1725
|
+
});
|
|
1726
|
+
return snapshot;
|
|
1727
|
+
}
|
|
1728
|
+
async persistWorkflowSnapshot({
|
|
1729
|
+
workflowName,
|
|
1730
|
+
runId,
|
|
1731
|
+
resourceId,
|
|
1732
|
+
snapshot
|
|
1733
|
+
}) {
|
|
1734
|
+
const data = {
|
|
1735
|
+
workflow_name: workflowName,
|
|
1736
|
+
run_id: runId,
|
|
1737
|
+
resourceId,
|
|
1738
|
+
snapshot,
|
|
1739
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1740
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1741
|
+
};
|
|
1742
|
+
await this.operations.insert({
|
|
1743
|
+
tableName: TABLE_WORKFLOW_SNAPSHOT,
|
|
1744
|
+
record: data
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
async loadWorkflowSnapshot({
|
|
1748
|
+
workflowName,
|
|
1749
|
+
runId
|
|
1750
|
+
}) {
|
|
1751
|
+
this.logger.debug("Loading workflow snapshot", { workflowName, runId });
|
|
1752
|
+
const d = await this.operations.load({
|
|
1753
|
+
tableName: TABLE_WORKFLOW_SNAPSHOT,
|
|
1754
|
+
keys: { workflow_name: workflowName, run_id: runId }
|
|
1755
|
+
});
|
|
1756
|
+
return d ? JSON.parse(JSON.stringify(d.snapshot)) : null;
|
|
1757
|
+
}
|
|
1758
|
+
async listWorkflowRuns({
|
|
1759
|
+
workflowName,
|
|
1760
|
+
fromDate,
|
|
1761
|
+
toDate,
|
|
1762
|
+
perPage,
|
|
1763
|
+
page,
|
|
1764
|
+
resourceId
|
|
1765
|
+
} = {}) {
|
|
1766
|
+
if (page !== void 0 && page < 0) {
|
|
1767
|
+
throw new Error("page must be >= 0");
|
|
1768
|
+
}
|
|
1769
|
+
let runs = Array.from(this.collection.values());
|
|
1770
|
+
if (workflowName) runs = runs.filter((run) => run.workflow_name === workflowName);
|
|
1771
|
+
if (fromDate && toDate) {
|
|
1772
|
+
runs = runs.filter(
|
|
1773
|
+
(run) => new Date(run.createdAt).getTime() >= fromDate.getTime() && new Date(run.createdAt).getTime() <= toDate.getTime()
|
|
1774
|
+
);
|
|
1775
|
+
} else if (fromDate) {
|
|
1776
|
+
runs = runs.filter((run) => new Date(run.createdAt).getTime() >= fromDate.getTime());
|
|
1777
|
+
} else if (toDate) {
|
|
1778
|
+
runs = runs.filter((run) => new Date(run.createdAt).getTime() <= toDate.getTime());
|
|
1779
|
+
}
|
|
1780
|
+
if (resourceId) runs = runs.filter((run) => run.resourceId === resourceId);
|
|
1781
|
+
const total = runs.length;
|
|
1782
|
+
runs.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
|
1783
|
+
if (perPage !== void 0 && page !== void 0) {
|
|
1784
|
+
const normalizedPerPage = normalizePerPage(perPage, Number.MAX_SAFE_INTEGER);
|
|
1785
|
+
const offset = page * normalizedPerPage;
|
|
1786
|
+
const start = offset;
|
|
1787
|
+
const end = start + normalizedPerPage;
|
|
1788
|
+
runs = runs.slice(start, end);
|
|
1789
|
+
}
|
|
1790
|
+
const parsedRuns = runs.map((run) => ({
|
|
1791
|
+
...run,
|
|
1792
|
+
snapshot: typeof run.snapshot === "string" ? JSON.parse(run.snapshot) : JSON.parse(JSON.stringify(run.snapshot)),
|
|
1793
|
+
createdAt: new Date(run.createdAt),
|
|
1794
|
+
updatedAt: new Date(run.updatedAt),
|
|
1795
|
+
runId: run.run_id,
|
|
1796
|
+
workflowName: run.workflow_name,
|
|
1797
|
+
resourceId: run.resourceId
|
|
1798
|
+
}));
|
|
1799
|
+
return { runs: parsedRuns, total };
|
|
1800
|
+
}
|
|
1801
|
+
async getWorkflowRunById({
|
|
1802
|
+
runId,
|
|
1803
|
+
workflowName
|
|
1804
|
+
}) {
|
|
1805
|
+
const runs = Array.from(this.collection.values()).filter((r) => r.run_id === runId);
|
|
1806
|
+
let run = runs.find((r) => r.workflow_name === workflowName);
|
|
1807
|
+
if (!run) return null;
|
|
1808
|
+
const parsedRun = {
|
|
1809
|
+
...run,
|
|
1810
|
+
snapshot: typeof run.snapshot === "string" ? JSON.parse(run.snapshot) : JSON.parse(JSON.stringify(run.snapshot)),
|
|
1811
|
+
createdAt: new Date(run.createdAt),
|
|
1812
|
+
updatedAt: new Date(run.updatedAt),
|
|
1813
|
+
runId: run.run_id,
|
|
1814
|
+
workflowName: run.workflow_name,
|
|
1815
|
+
resourceId: run.resourceId
|
|
1816
|
+
};
|
|
1817
|
+
return parsedRun;
|
|
1818
|
+
}
|
|
1819
|
+
};
|
|
1820
|
+
|
|
1821
|
+
// src/storage/mock.ts
|
|
1822
|
+
var InMemoryStore = class extends MastraStorage {
|
|
1823
|
+
stores;
|
|
1824
|
+
constructor({ id = "in-memory" } = {}) {
|
|
1825
|
+
super({ id, name: "InMemoryStorage" });
|
|
1826
|
+
this.hasInitialized = Promise.resolve(true);
|
|
1827
|
+
const operationsStorage = new StoreOperationsInMemory();
|
|
1828
|
+
const database = operationsStorage.getDatabase();
|
|
1829
|
+
const scoresStorage = new ScoresInMemory({
|
|
1830
|
+
collection: database.mastra_scorers
|
|
1831
|
+
});
|
|
1832
|
+
const workflowsStorage = new WorkflowsInMemory({
|
|
1833
|
+
collection: database.mastra_workflow_snapshot,
|
|
1834
|
+
operations: operationsStorage
|
|
1835
|
+
});
|
|
1836
|
+
const memoryStorage = new InMemoryMemory({
|
|
1837
|
+
collection: {
|
|
1838
|
+
threads: database.mastra_threads,
|
|
1839
|
+
resources: database.mastra_resources,
|
|
1840
|
+
messages: database.mastra_messages
|
|
1841
|
+
},
|
|
1842
|
+
operations: operationsStorage
|
|
1843
|
+
});
|
|
1844
|
+
const observabilityStorage = new ObservabilityInMemory({
|
|
1845
|
+
collection: database.mastra_ai_spans,
|
|
1846
|
+
operations: operationsStorage
|
|
1847
|
+
});
|
|
1848
|
+
this.stores = {
|
|
1849
|
+
operations: operationsStorage,
|
|
1850
|
+
workflows: workflowsStorage,
|
|
1851
|
+
scores: scoresStorage,
|
|
1852
|
+
memory: memoryStorage,
|
|
1853
|
+
observability: observabilityStorage
|
|
1854
|
+
};
|
|
1855
|
+
}
|
|
1856
|
+
get supports() {
|
|
1857
|
+
return {
|
|
1858
|
+
selectByIncludeResourceScope: false,
|
|
1859
|
+
resourceWorkingMemory: false,
|
|
1860
|
+
hasColumn: false,
|
|
1861
|
+
createTable: false,
|
|
1862
|
+
deleteMessages: true,
|
|
1863
|
+
observabilityInstance: true,
|
|
1864
|
+
indexManagement: false,
|
|
1865
|
+
listScoresBySpan: true
|
|
1866
|
+
};
|
|
1867
|
+
}
|
|
1868
|
+
async persistWorkflowSnapshot({
|
|
1869
|
+
workflowName,
|
|
1870
|
+
runId,
|
|
1871
|
+
resourceId,
|
|
1872
|
+
snapshot
|
|
1873
|
+
}) {
|
|
1874
|
+
await this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
|
|
1875
|
+
}
|
|
1876
|
+
async loadWorkflowSnapshot({
|
|
1877
|
+
workflowName,
|
|
1878
|
+
runId
|
|
1879
|
+
}) {
|
|
1880
|
+
return this.stores.workflows.loadWorkflowSnapshot({ workflowName, runId });
|
|
1881
|
+
}
|
|
1882
|
+
async createTable({
|
|
1883
|
+
tableName,
|
|
1884
|
+
schema
|
|
1885
|
+
}) {
|
|
1886
|
+
await this.stores.operations.createTable({ tableName, schema });
|
|
1887
|
+
}
|
|
1888
|
+
async alterTable({
|
|
1889
|
+
tableName,
|
|
1890
|
+
schema,
|
|
1891
|
+
ifNotExists
|
|
1892
|
+
}) {
|
|
1893
|
+
await this.stores.operations.alterTable({ tableName, schema, ifNotExists });
|
|
1894
|
+
}
|
|
1895
|
+
async clearTable({ tableName }) {
|
|
1896
|
+
await this.stores.operations.clearTable({ tableName });
|
|
1897
|
+
}
|
|
1898
|
+
async dropTable({ tableName }) {
|
|
1899
|
+
await this.stores.operations.dropTable({ tableName });
|
|
1900
|
+
}
|
|
1901
|
+
async insert({ tableName, record }) {
|
|
1902
|
+
await this.stores.operations.insert({ tableName, record });
|
|
1903
|
+
}
|
|
1904
|
+
async updateWorkflowResults({
|
|
1905
|
+
workflowName,
|
|
1906
|
+
runId,
|
|
1907
|
+
stepId,
|
|
1908
|
+
result,
|
|
1909
|
+
requestContext
|
|
1910
|
+
}) {
|
|
1911
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, requestContext });
|
|
1912
|
+
}
|
|
1913
|
+
async updateWorkflowState({
|
|
1914
|
+
workflowName,
|
|
1915
|
+
runId,
|
|
1916
|
+
opts
|
|
1917
|
+
}) {
|
|
1918
|
+
return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
|
|
1919
|
+
}
|
|
1920
|
+
async batchInsert({ tableName, records }) {
|
|
1921
|
+
await this.stores.operations.batchInsert({ tableName, records });
|
|
1922
|
+
}
|
|
1923
|
+
async load({ tableName, keys }) {
|
|
1924
|
+
return this.stores.operations.load({ tableName, keys });
|
|
1925
|
+
}
|
|
1926
|
+
async getThreadById({ threadId }) {
|
|
1927
|
+
return this.stores.memory.getThreadById({ threadId });
|
|
1928
|
+
}
|
|
1929
|
+
async saveThread({ thread }) {
|
|
1930
|
+
return this.stores.memory.saveThread({ thread });
|
|
1931
|
+
}
|
|
1932
|
+
async updateThread({
|
|
1933
|
+
id,
|
|
1934
|
+
title,
|
|
1935
|
+
metadata
|
|
1936
|
+
}) {
|
|
1937
|
+
return this.stores.memory.updateThread({ id, title, metadata });
|
|
1938
|
+
}
|
|
1939
|
+
async deleteThread({ threadId }) {
|
|
1940
|
+
return this.stores.memory.deleteThread({ threadId });
|
|
1941
|
+
}
|
|
1942
|
+
async getResourceById({ resourceId }) {
|
|
1943
|
+
return this.stores.memory.getResourceById({ resourceId });
|
|
1944
|
+
}
|
|
1945
|
+
async saveResource({ resource }) {
|
|
1946
|
+
return this.stores.memory.saveResource({ resource });
|
|
1947
|
+
}
|
|
1948
|
+
async updateResource({
|
|
1949
|
+
resourceId,
|
|
1950
|
+
workingMemory,
|
|
1951
|
+
metadata
|
|
1952
|
+
}) {
|
|
1953
|
+
return this.stores.memory.updateResource({ resourceId, workingMemory, metadata });
|
|
1954
|
+
}
|
|
1955
|
+
async listMessagesById({ messageIds }) {
|
|
1956
|
+
return this.stores.memory.listMessagesById({ messageIds });
|
|
1957
|
+
}
|
|
1958
|
+
async saveMessages(args) {
|
|
1959
|
+
return this.stores.memory.saveMessages(args);
|
|
1960
|
+
}
|
|
1961
|
+
async updateMessages(args) {
|
|
1962
|
+
return this.stores.memory.updateMessages(args);
|
|
1963
|
+
}
|
|
1964
|
+
async deleteMessages(messageIds) {
|
|
1965
|
+
return this.stores.memory.deleteMessages(messageIds);
|
|
1966
|
+
}
|
|
1967
|
+
async getScoreById({ id }) {
|
|
1968
|
+
return this.stores.scores.getScoreById({ id });
|
|
1969
|
+
}
|
|
1970
|
+
async saveScore(score) {
|
|
1971
|
+
return this.stores.scores.saveScore(score);
|
|
1972
|
+
}
|
|
1973
|
+
async listScoresByScorerId({
|
|
1974
|
+
scorerId,
|
|
1975
|
+
entityId,
|
|
1976
|
+
entityType,
|
|
1977
|
+
source,
|
|
1978
|
+
pagination
|
|
1979
|
+
}) {
|
|
1980
|
+
return this.stores.scores.listScoresByScorerId({ scorerId, entityId, entityType, source, pagination });
|
|
1981
|
+
}
|
|
1982
|
+
async listScoresByRunId({
|
|
1983
|
+
runId,
|
|
1984
|
+
pagination
|
|
1985
|
+
}) {
|
|
1986
|
+
return this.stores.scores.listScoresByRunId({ runId, pagination });
|
|
1987
|
+
}
|
|
1988
|
+
async listScoresByEntityId({
|
|
1989
|
+
entityId,
|
|
1990
|
+
entityType,
|
|
1991
|
+
pagination
|
|
1992
|
+
}) {
|
|
1993
|
+
return this.stores.scores.listScoresByEntityId({ entityId, entityType, pagination });
|
|
1994
|
+
}
|
|
1995
|
+
async listScoresBySpan({
|
|
1996
|
+
traceId,
|
|
1997
|
+
spanId,
|
|
1998
|
+
pagination
|
|
1999
|
+
}) {
|
|
2000
|
+
return this.stores.scores.listScoresBySpan({ traceId, spanId, pagination });
|
|
2001
|
+
}
|
|
2002
|
+
async getWorkflowRunById({
|
|
2003
|
+
runId,
|
|
2004
|
+
workflowName
|
|
2005
|
+
}) {
|
|
2006
|
+
return this.stores.workflows.getWorkflowRunById({ runId, workflowName });
|
|
2007
|
+
}
|
|
2008
|
+
async createSpan(span) {
|
|
2009
|
+
return this.stores.observability.createSpan(span);
|
|
2010
|
+
}
|
|
2011
|
+
async updateSpan(params) {
|
|
2012
|
+
return this.stores.observability.updateSpan(params);
|
|
2013
|
+
}
|
|
2014
|
+
async getTrace(traceId) {
|
|
2015
|
+
return this.stores.observability.getTrace(traceId);
|
|
2016
|
+
}
|
|
2017
|
+
async batchCreateSpans(args) {
|
|
2018
|
+
return this.stores.observability.batchCreateSpans(args);
|
|
2019
|
+
}
|
|
2020
|
+
async batchUpdateSpans(args) {
|
|
2021
|
+
return this.stores.observability.batchUpdateSpans(args);
|
|
2022
|
+
}
|
|
2023
|
+
async batchDeleteTraces(args) {
|
|
2024
|
+
return this.stores.observability.batchDeleteTraces(args);
|
|
2025
|
+
}
|
|
2026
|
+
};
|
|
2027
|
+
var MockStore = InMemoryStore;
|
|
2028
|
+
|
|
2029
|
+
export { InMemoryMemory, InMemoryStore, MastraStorage, MemoryStorage, MockStore, ObservabilityInMemory, ObservabilityStorage, SCORERS_SCHEMA, SPAN_SCHEMA, ScoresInMemory, ScoresStorage, StoreOperations, StoreOperationsInMemory, TABLE_MESSAGES, TABLE_RESOURCES, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SPANS, TABLE_THREADS, TABLE_TRACES, TABLE_WORKFLOW_SNAPSHOT, WorkflowsInMemory, WorkflowsStorage, calculatePagination, ensureDate, normalizePerPage, safelyParseJSON, serializeDate };
|
|
2030
|
+
//# sourceMappingURL=chunk-MV7KHWUT.js.map
|
|
2031
|
+
//# sourceMappingURL=chunk-MV7KHWUT.js.map
|