@mastra/core 1.0.0-beta.14 → 1.0.0-beta.16
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 +472 -0
- package/dist/agent/agent-legacy.d.ts.map +1 -1
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/index.cjs +11 -11
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/index.cjs +3 -3
- package/dist/agent/message-list/index.d.ts +1 -1
- package/dist/agent/message-list/index.d.ts.map +1 -1
- package/dist/agent/message-list/index.js +1 -1
- package/dist/agent/message-list/prompt/attachments-to-parts.d.ts.map +1 -1
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
- package/dist/{chunk-DBW6S25C.cjs → chunk-33VDGXRH.cjs} +83 -65
- package/dist/chunk-33VDGXRH.cjs.map +1 -0
- package/dist/chunk-37YWZMBX.js +27 -0
- package/dist/chunk-37YWZMBX.js.map +1 -0
- package/dist/chunk-3ZRMVPQA.cjs +263 -0
- package/dist/chunk-3ZRMVPQA.cjs.map +1 -0
- package/dist/{chunk-VZJOEGQA.js → chunk-4DFWV4IR.js} +2 -2
- package/dist/chunk-4DFWV4IR.js.map +1 -0
- package/dist/{chunk-53SZJCBX.cjs → chunk-4KVIXN7K.cjs} +24 -24
- package/dist/{chunk-53SZJCBX.cjs.map → chunk-4KVIXN7K.cjs.map} +1 -1
- package/dist/{chunk-QDVYP2T7.js → chunk-4N6WB4EZ.js} +7 -7
- package/dist/{chunk-QDVYP2T7.js.map → chunk-4N6WB4EZ.js.map} +1 -1
- package/dist/{chunk-HWMMIRIF.cjs → chunk-4U7ZLI36.cjs} +3 -2
- package/dist/chunk-4U7ZLI36.cjs.map +1 -0
- package/dist/{chunk-O5BQBZEF.cjs → chunk-4UH5LAF5.cjs} +28 -28
- package/dist/{chunk-O5BQBZEF.cjs.map → chunk-4UH5LAF5.cjs.map} +1 -1
- package/dist/{chunk-JAGQZZ43.cjs → chunk-5DL6Y7PJ.cjs} +696 -352
- package/dist/chunk-5DL6Y7PJ.cjs.map +1 -0
- package/dist/{chunk-Z55SJVEC.cjs → chunk-6YUHA5UH.cjs} +7 -6
- package/dist/chunk-6YUHA5UH.cjs.map +1 -0
- package/dist/{chunk-TRUNX3AX.cjs → chunk-7KL2YFFK.cjs} +31 -31
- package/dist/chunk-7KL2YFFK.cjs.map +1 -0
- package/dist/{chunk-6CG7IY57.cjs → chunk-A6JNGJIU.cjs} +325 -164
- package/dist/chunk-A6JNGJIU.cjs.map +1 -0
- package/dist/{chunk-EGHGFLL3.cjs → chunk-AAX7ZOM7.cjs} +2 -2
- package/dist/chunk-AAX7ZOM7.cjs.map +1 -0
- package/dist/{chunk-O3ULBGV6.cjs → chunk-AQ22JIR7.cjs} +43 -21
- package/dist/chunk-AQ22JIR7.cjs.map +1 -0
- package/dist/chunk-CSCTVLD5.js +598 -0
- package/dist/chunk-CSCTVLD5.js.map +1 -0
- package/dist/chunk-DMX7MC4N.js +3 -0
- package/dist/{chunk-GXSERFAG.js.map → chunk-DMX7MC4N.js.map} +1 -1
- package/dist/{chunk-AYBJ5GAD.js → chunk-DT5RMENY.js} +302 -136
- package/dist/chunk-DT5RMENY.js.map +1 -0
- package/dist/{chunk-72E3YF6A.cjs → chunk-EMLEZXTQ.cjs} +15 -12
- package/dist/chunk-EMLEZXTQ.cjs.map +1 -0
- package/dist/{chunk-QF4MHFSU.js → chunk-F7PAZAGE.js} +530 -191
- package/dist/chunk-F7PAZAGE.js.map +1 -0
- package/dist/{chunk-LDXKZYOV.js → chunk-FB5QMTJJ.js} +30 -8
- package/dist/chunk-FB5QMTJJ.js.map +1 -0
- package/dist/{chunk-YPLZDWG7.js → chunk-FJEVLHJT.js} +3 -2
- package/dist/chunk-FJEVLHJT.js.map +1 -0
- package/dist/{chunk-GBQXIVL6.js → chunk-GNUITL2N.js} +801 -1240
- package/dist/chunk-GNUITL2N.js.map +1 -0
- package/dist/chunk-H2NHG7QL.cjs +32 -0
- package/dist/chunk-H2NHG7QL.cjs.map +1 -0
- package/dist/chunk-J4SXS7KN.js +259 -0
- package/dist/chunk-J4SXS7KN.js.map +1 -0
- package/dist/{chunk-Y36Y5MTD.js → chunk-JQM64OZF.js} +13 -3
- package/dist/chunk-JQM64OZF.js.map +1 -0
- package/dist/{chunk-67LM2UCT.js → chunk-K4XAKG7L.js} +5 -5
- package/dist/{chunk-67LM2UCT.js.map → chunk-K4XAKG7L.js.map} +1 -1
- package/dist/{chunk-4CMIJQF6.js → chunk-KKYAYRIO.js} +14 -14
- package/dist/chunk-KKYAYRIO.js.map +1 -0
- package/dist/{chunk-FPDJ4XN6.cjs → chunk-NCAMNQC3.cjs} +303 -137
- package/dist/chunk-NCAMNQC3.cjs.map +1 -0
- package/dist/chunk-NK4UN2LF.cjs +674 -0
- package/dist/chunk-NK4UN2LF.cjs.map +1 -0
- package/dist/{chunk-5UQ5TB6J.js → chunk-NNFF3URD.js} +41 -23
- package/dist/chunk-NNFF3URD.js.map +1 -0
- package/dist/{chunk-GELVUDUY.js → chunk-O7M7DR4E.js} +3 -3
- package/dist/{chunk-GELVUDUY.js.map → chunk-O7M7DR4E.js.map} +1 -1
- package/dist/chunk-OTIGV7CL.js +10215 -0
- package/dist/chunk-OTIGV7CL.js.map +1 -0
- package/dist/{chunk-ETWAR2YE.cjs → chunk-OXV6QFSV.cjs} +828 -1275
- package/dist/chunk-OXV6QFSV.cjs.map +1 -0
- package/dist/{chunk-373OC54J.js → chunk-QD776HMB.js} +7 -6
- package/dist/{chunk-373OC54J.js.map → chunk-QD776HMB.js.map} +1 -1
- package/dist/{chunk-4AT6YQKZ.js → chunk-QXL3F3T2.js} +7 -4
- package/dist/chunk-QXL3F3T2.js.map +1 -0
- package/dist/chunk-RMV5HJM7.cjs +10237 -0
- package/dist/chunk-RMV5HJM7.cjs.map +1 -0
- package/dist/chunk-ROOVGRNA.cjs +4 -0
- package/dist/{chunk-X4RMXTXF.cjs.map → chunk-ROOVGRNA.cjs.map} +1 -1
- package/dist/{chunk-OOUFPYSX.cjs → chunk-SSB4AVHU.cjs} +17 -17
- package/dist/{chunk-OOUFPYSX.cjs.map → chunk-SSB4AVHU.cjs.map} +1 -1
- package/dist/{chunk-TDM43G4I.cjs → chunk-UT6MASE5.cjs} +9 -9
- package/dist/{chunk-TDM43G4I.cjs.map → chunk-UT6MASE5.cjs.map} +1 -1
- package/dist/{chunk-3IP3DZ7G.js → chunk-UTMBASR5.js} +291 -130
- package/dist/chunk-UTMBASR5.js.map +1 -0
- package/dist/{chunk-SLBWA2F3.js → chunk-WDXYPI3P.js} +3 -3
- package/dist/{chunk-SLBWA2F3.js.map → chunk-WDXYPI3P.js.map} +1 -1
- package/dist/{chunk-72YCRTEX.cjs → chunk-ZSZOYPSJ.cjs} +13 -2
- package/dist/chunk-ZSZOYPSJ.cjs.map +1 -0
- package/dist/error/index.cjs +6 -6
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.d.ts.map +1 -1
- package/dist/error/index.js +1 -1
- package/dist/evals/index.cjs +49 -9
- package/dist/evals/index.js +2 -2
- package/dist/evals/scoreTraces/index.cjs +70 -22
- package/dist/evals/scoreTraces/index.cjs.map +1 -1
- package/dist/evals/scoreTraces/index.js +63 -15
- package/dist/evals/scoreTraces/index.js.map +1 -1
- package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
- package/dist/evals/scoreTraces/utils.d.ts.map +1 -1
- package/dist/evals/types.d.ts +566 -116
- package/dist/evals/types.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/integration/index.cjs +2 -2
- package/dist/integration/index.js +1 -1
- package/dist/llm/index.cjs +20 -20
- package/dist/llm/index.js +4 -4
- package/dist/llm/model/aisdk/v6/model.d.ts +1 -9
- package/dist/llm/model/aisdk/v6/model.d.ts.map +1 -1
- package/dist/llm/model/embedding-router.d.ts +1 -1
- package/dist/llm/model/model.d.ts.map +1 -1
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/provider-options.d.ts +2 -1
- package/dist/llm/model/provider-options.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +129 -58
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/network/index.d.ts +6 -6
- package/dist/loop/test-utils/MastraLanguageModelV3Mock.d.ts +1 -9
- package/dist/loop/test-utils/MastraLanguageModelV3Mock.d.ts.map +1 -1
- package/dist/loop/types.d.ts +5 -2
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/mastra/hooks.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +7 -2
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/mcp/index.cjs +7 -4
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +4 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/types.d.ts +2 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/memory/index.cjs +26 -6
- package/dist/memory/index.d.ts +1 -0
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +1 -1
- package/dist/memory/memory.d.ts +9 -8
- package/dist/memory/memory.d.ts.map +1 -1
- package/dist/memory/mock.d.ts +2 -1
- package/dist/memory/mock.d.ts.map +1 -1
- package/dist/memory/types.d.ts +3 -4
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/memory/working-memory-utils.d.ts +20 -0
- package/dist/memory/working-memory-utils.d.ts.map +1 -0
- package/dist/models-dev-26XLUKVK.cjs +12 -0
- package/dist/{models-dev-PPS7X4JM.cjs.map → models-dev-26XLUKVK.cjs.map} +1 -1
- package/dist/models-dev-HUFLQFPB.js +3 -0
- package/dist/{models-dev-E3WWI7VA.js.map → models-dev-HUFLQFPB.js.map} +1 -1
- package/dist/netlify-3MHHJG2E.js +3 -0
- package/dist/{netlify-TY656UYF.js.map → netlify-3MHHJG2E.js.map} +1 -1
- package/dist/netlify-5Y33S7WL.cjs +12 -0
- package/dist/{netlify-VZFM5UH3.cjs.map → netlify-5Y33S7WL.cjs.map} +1 -1
- package/dist/observability/index.cjs +14 -10
- package/dist/observability/index.js +1 -1
- package/dist/observability/types/tracing.d.ts +34 -20
- package/dist/observability/types/tracing.d.ts.map +1 -1
- package/dist/processors/index.cjs +37 -37
- package/dist/processors/index.d.ts +2 -0
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/memory/message-history.d.ts +7 -1
- package/dist/processors/memory/message-history.d.ts.map +1 -1
- package/dist/processors/processors/language-detector.d.ts.map +1 -1
- package/dist/processors/processors/moderation.d.ts.map +1 -1
- package/dist/processors/processors/pii-detector.d.ts.map +1 -1
- package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
- package/dist/processors/processors/structured-output.d.ts +1 -0
- package/dist/processors/processors/structured-output.d.ts.map +1 -1
- package/dist/processors/processors/token-limiter.d.ts +5 -2
- package/dist/processors/processors/token-limiter.d.ts.map +1 -1
- package/dist/processors/runner.d.ts +2 -0
- package/dist/processors/runner.d.ts.map +1 -1
- package/dist/provider-registry-LXSWMVEC.js +3 -0
- package/dist/{provider-registry-NXVD764B.js.map → provider-registry-LXSWMVEC.js.map} +1 -1
- package/dist/provider-registry-YJ2P5YY5.cjs +40 -0
- package/dist/{provider-registry-ZIWSEUQE.cjs.map → provider-registry-YJ2P5YY5.cjs.map} +1 -1
- package/dist/provider-registry.json +298 -132
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/server/index.cjs +5 -5
- package/dist/server/index.js +1 -1
- package/dist/server/types.d.ts +28 -0
- package/dist/server/types.d.ts.map +1 -1
- package/dist/storage/base.d.ts +95 -300
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/constants.cjs +60 -0
- package/dist/storage/constants.cjs.map +1 -0
- package/dist/storage/constants.d.ts +6 -1
- package/dist/storage/constants.d.ts.map +1 -1
- package/dist/storage/constants.js +3 -0
- package/dist/storage/constants.js.map +1 -0
- package/dist/storage/domains/agents/base.d.ts +2 -2
- package/dist/storage/domains/agents/base.d.ts.map +1 -1
- package/dist/storage/domains/agents/inmemory.d.ts +5 -4
- package/dist/storage/domains/agents/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/base.d.ts +20 -0
- package/dist/storage/domains/base.d.ts.map +1 -0
- package/dist/storage/domains/index.d.ts +3 -0
- package/dist/storage/domains/index.d.ts.map +1 -1
- package/dist/storage/domains/inmemory-db.d.ts +57 -0
- package/dist/storage/domains/inmemory-db.d.ts.map +1 -0
- package/dist/storage/domains/memory/base.d.ts +2 -2
- package/dist/storage/domains/memory/base.d.ts.map +1 -1
- package/dist/storage/domains/memory/inmemory.d.ts +5 -13
- package/dist/storage/domains/memory/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/observability/base.d.ts +24 -29
- package/dist/storage/domains/observability/base.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +1 -0
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/inmemory.d.ts +46 -35
- package/dist/storage/domains/observability/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/observability/types.d.ts +2365 -0
- package/dist/storage/domains/observability/types.d.ts.map +1 -0
- package/dist/storage/domains/scores/base.d.ts +9 -20
- package/dist/storage/domains/scores/base.d.ts.map +1 -1
- package/dist/storage/domains/scores/inmemory.d.ts +11 -22
- package/dist/storage/domains/scores/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/shared.d.ts +76 -0
- package/dist/storage/domains/shared.d.ts.map +1 -0
- package/dist/storage/domains/workflows/base.d.ts +4 -2
- package/dist/storage/domains/workflows/base.d.ts.map +1 -1
- package/dist/storage/domains/workflows/inmemory.d.ts +10 -9
- package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +272 -59
- package/dist/storage/index.js +2 -1
- package/dist/storage/mock.d.ts +26 -174
- package/dist/storage/mock.d.ts.map +1 -1
- package/dist/storage/types.d.ts +15 -44
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/storage/utils.d.ts +5 -0
- package/dist/storage/utils.d.ts.map +1 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts +1 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
- package/dist/stream/RunOutput.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat/consume-stream.d.ts +4 -1
- package/dist/stream/aisdk/v5/compat/consume-stream.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +12 -12
- package/dist/stream/index.js +2 -2
- package/dist/stream/types.d.ts +3 -0
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.cjs +4 -4
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/tool-loop-agent/index.cjs +20 -0
- package/dist/tool-loop-agent/index.cjs.map +1 -0
- package/dist/tool-loop-agent/index.d.ts +36 -0
- package/dist/tool-loop-agent/index.d.ts.map +1 -0
- package/dist/tool-loop-agent/index.js +3 -0
- package/dist/tool-loop-agent/index.js.map +1 -0
- package/dist/tool-loop-agent/tool-loop-processor.d.ts +30 -0
- package/dist/tool-loop-agent/tool-loop-processor.d.ts.map +1 -0
- package/dist/tool-loop-agent/utils.d.ts +17 -0
- package/dist/tool-loop-agent/utils.d.ts.map +1 -0
- package/dist/tools/index.cjs +4 -4
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/is-vercel-tool.cjs +2 -2
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/tool.d.ts +4 -4
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/tools/toolchecks.d.ts +1 -1
- package/dist/tools/toolchecks.d.ts.map +1 -1
- package/dist/tools/types.d.ts +3 -1
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/validation.d.ts +1 -1
- package/dist/tools/validation.d.ts.map +1 -1
- package/dist/utils/zod-utils.d.ts +34 -0
- package/dist/utils/zod-utils.d.ts.map +1 -0
- package/dist/utils.cjs +39 -22
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -1
- package/dist/vector/index.cjs +12 -5299
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.js +3 -5274
- package/dist/vector/index.js.map +1 -1
- package/dist/vector/vector.d.ts +13 -3
- package/dist/vector/vector.d.ts.map +1 -1
- package/dist/voice/index.cjs +6 -6
- package/dist/voice/index.js +1 -1
- package/dist/workflows/default.d.ts +2 -0
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/execution-engine.d.ts +1 -0
- package/dist/workflows/evented/execution-engine.d.ts.map +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/step-executor.d.ts +1 -0
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts +5 -4
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/parallel.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/parallel.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/sleep.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/sleep.d.ts.map +1 -1
- package/dist/workflows/evented/workflow.d.ts +5 -2
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/execution-engine.d.ts +1 -0
- package/dist/workflows/execution-engine.d.ts.map +1 -1
- package/dist/workflows/handlers/control-flow.d.ts +4 -0
- package/dist/workflows/handlers/control-flow.d.ts.map +1 -1
- package/dist/workflows/handlers/entry.d.ts +3 -2
- package/dist/workflows/handlers/entry.d.ts.map +1 -1
- package/dist/workflows/handlers/step.d.ts +1 -0
- package/dist/workflows/handlers/step.d.ts.map +1 -1
- package/dist/workflows/index.cjs +23 -23
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/types.d.ts +23 -3
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/utils.d.ts +1 -0
- package/dist/workflows/utils.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +22 -8
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +15 -5
- package/src/llm/model/provider-types.generated.d.ts +129 -58
- package/storage/constants.d.ts +1 -0
- package/tool-loop-agent.d.ts +1 -0
- package/dist/chunk-3IP3DZ7G.js.map +0 -1
- package/dist/chunk-4AT6YQKZ.js.map +0 -1
- package/dist/chunk-4CMIJQF6.js.map +0 -1
- package/dist/chunk-5UQ5TB6J.js.map +0 -1
- package/dist/chunk-6CG7IY57.cjs.map +0 -1
- package/dist/chunk-72E3YF6A.cjs.map +0 -1
- package/dist/chunk-72YCRTEX.cjs.map +0 -1
- package/dist/chunk-ADADLFDR.js +0 -42
- package/dist/chunk-ADADLFDR.js.map +0 -1
- package/dist/chunk-AYBJ5GAD.js.map +0 -1
- package/dist/chunk-DBW6S25C.cjs.map +0 -1
- package/dist/chunk-EGHGFLL3.cjs.map +0 -1
- package/dist/chunk-ETWAR2YE.cjs.map +0 -1
- package/dist/chunk-FPDJ4XN6.cjs.map +0 -1
- package/dist/chunk-GBQXIVL6.js.map +0 -1
- package/dist/chunk-GXSERFAG.js +0 -3
- package/dist/chunk-HWMMIRIF.cjs.map +0 -1
- package/dist/chunk-JAGQZZ43.cjs.map +0 -1
- package/dist/chunk-LDXKZYOV.js.map +0 -1
- package/dist/chunk-O3ULBGV6.cjs.map +0 -1
- package/dist/chunk-QF4MHFSU.js.map +0 -1
- package/dist/chunk-T2VLUFGG.cjs +0 -47
- package/dist/chunk-T2VLUFGG.cjs.map +0 -1
- package/dist/chunk-TRUNX3AX.cjs.map +0 -1
- package/dist/chunk-VZJOEGQA.js.map +0 -1
- package/dist/chunk-X4RMXTXF.cjs +0 -4
- package/dist/chunk-Y36Y5MTD.js.map +0 -1
- package/dist/chunk-YPLZDWG7.js.map +0 -1
- package/dist/chunk-Z55SJVEC.cjs.map +0 -1
- package/dist/models-dev-E3WWI7VA.js +0 -3
- package/dist/models-dev-PPS7X4JM.cjs +0 -12
- package/dist/netlify-TY656UYF.js +0 -3
- package/dist/netlify-VZFM5UH3.cjs +0 -12
- package/dist/provider-registry-NXVD764B.js +0 -3
- package/dist/provider-registry-ZIWSEUQE.cjs +0 -40
|
@@ -1,186 +1,9 @@
|
|
|
1
|
-
import { MessageList } from './chunk-
|
|
2
|
-
import {
|
|
1
|
+
import { MessageList } from './chunk-QXL3F3T2.js';
|
|
2
|
+
import { TABLE_SCHEMAS, TABLE_SCORERS, listTracesArgsSchema, TABLE_WORKFLOW_SNAPSHOT } from './chunk-CSCTVLD5.js';
|
|
3
|
+
import { MastraError } from './chunk-FJEVLHJT.js';
|
|
3
4
|
import { MastraBase } from './chunk-LSHPJWM5.js';
|
|
4
5
|
|
|
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 TABLE_AGENTS = "mastra_agents";
|
|
14
|
-
var SCORERS_SCHEMA = {
|
|
15
|
-
id: { type: "text", nullable: false, primaryKey: true },
|
|
16
|
-
scorerId: { type: "text" },
|
|
17
|
-
traceId: { type: "text", nullable: true },
|
|
18
|
-
spanId: { type: "text", nullable: true },
|
|
19
|
-
runId: { type: "text" },
|
|
20
|
-
scorer: { type: "jsonb" },
|
|
21
|
-
preprocessStepResult: { type: "jsonb", nullable: true },
|
|
22
|
-
extractStepResult: { type: "jsonb", nullable: true },
|
|
23
|
-
analyzeStepResult: { type: "jsonb", nullable: true },
|
|
24
|
-
score: { type: "float" },
|
|
25
|
-
reason: { type: "text", nullable: true },
|
|
26
|
-
metadata: { type: "jsonb", nullable: true },
|
|
27
|
-
preprocessPrompt: { type: "text", nullable: true },
|
|
28
|
-
extractPrompt: { type: "text", nullable: true },
|
|
29
|
-
generateScorePrompt: { type: "text", nullable: true },
|
|
30
|
-
generateReasonPrompt: { type: "text", nullable: true },
|
|
31
|
-
analyzePrompt: { type: "text", nullable: true },
|
|
32
|
-
// Deprecated
|
|
33
|
-
reasonPrompt: { type: "text", nullable: true },
|
|
34
|
-
input: { type: "jsonb" },
|
|
35
|
-
output: { type: "jsonb" },
|
|
36
|
-
// MESSAGE OUTPUT
|
|
37
|
-
additionalContext: { type: "jsonb", nullable: true },
|
|
38
|
-
// DATA FROM THE CONTEXT PARAM ON AN AGENT
|
|
39
|
-
requestContext: { type: "jsonb", nullable: true },
|
|
40
|
-
// THE EVALUATE Request Context FOR THE RUN
|
|
41
|
-
/**
|
|
42
|
-
* Things you can evaluate
|
|
43
|
-
*/
|
|
44
|
-
entityType: { type: "text", nullable: true },
|
|
45
|
-
// WORKFLOW, AGENT, TOOL, STEP, NETWORK
|
|
46
|
-
entity: { type: "jsonb", nullable: true },
|
|
47
|
-
// MINIMAL JSON DATA ABOUT WORKFLOW, AGENT, TOOL, STEP, NETWORK
|
|
48
|
-
entityId: { type: "text", nullable: true },
|
|
49
|
-
source: { type: "text" },
|
|
50
|
-
resourceId: { type: "text", nullable: true },
|
|
51
|
-
threadId: { type: "text", nullable: true },
|
|
52
|
-
createdAt: { type: "timestamp" },
|
|
53
|
-
updatedAt: { type: "timestamp" }
|
|
54
|
-
};
|
|
55
|
-
var SPAN_SCHEMA = {
|
|
56
|
-
// Composite primary key of traceId and spanId
|
|
57
|
-
traceId: { type: "text", nullable: false },
|
|
58
|
-
spanId: { type: "text", nullable: false },
|
|
59
|
-
parentSpanId: { type: "text", nullable: true },
|
|
60
|
-
name: { type: "text", nullable: false },
|
|
61
|
-
scope: { type: "jsonb", nullable: true },
|
|
62
|
-
// Mastra package info {"core-version": "0.1.0"}
|
|
63
|
-
spanType: { type: "text", nullable: false },
|
|
64
|
-
// WORKFLOW_RUN, WORKFLOW_STEP, AGENT_RUN, AGENT_STEP, TOOL_RUN, TOOL_STEP, etc.
|
|
65
|
-
attributes: { type: "jsonb", nullable: true },
|
|
66
|
-
metadata: { type: "jsonb", nullable: true },
|
|
67
|
-
links: { type: "jsonb", nullable: true },
|
|
68
|
-
input: { type: "jsonb", nullable: true },
|
|
69
|
-
output: { type: "jsonb", nullable: true },
|
|
70
|
-
error: { type: "jsonb", nullable: true },
|
|
71
|
-
startedAt: { type: "timestamp", nullable: false },
|
|
72
|
-
// When the span started
|
|
73
|
-
endedAt: { type: "timestamp", nullable: true },
|
|
74
|
-
// When the span ended
|
|
75
|
-
createdAt: { type: "timestamp", nullable: false },
|
|
76
|
-
// The time the database record was created
|
|
77
|
-
updatedAt: { type: "timestamp", nullable: true },
|
|
78
|
-
// The time the database record was last updated
|
|
79
|
-
isEvent: { type: "boolean", nullable: false }
|
|
80
|
-
};
|
|
81
|
-
var AGENTS_SCHEMA = {
|
|
82
|
-
id: { type: "text", nullable: false, primaryKey: true },
|
|
83
|
-
name: { type: "text", nullable: false },
|
|
84
|
-
description: { type: "text", nullable: true },
|
|
85
|
-
instructions: { type: "text", nullable: false },
|
|
86
|
-
// System instructions for the agent
|
|
87
|
-
model: { type: "jsonb", nullable: false },
|
|
88
|
-
// Model configuration (provider, name, etc.)
|
|
89
|
-
tools: { type: "jsonb", nullable: true },
|
|
90
|
-
// Serialized tool references/configurations
|
|
91
|
-
defaultOptions: { type: "jsonb", nullable: true },
|
|
92
|
-
// Default options for generate/stream calls
|
|
93
|
-
workflows: { type: "jsonb", nullable: true },
|
|
94
|
-
// Workflow references (IDs or configurations)
|
|
95
|
-
agents: { type: "jsonb", nullable: true },
|
|
96
|
-
// Sub-agent references (IDs or configurations)
|
|
97
|
-
inputProcessors: { type: "jsonb", nullable: true },
|
|
98
|
-
// Input processor configurations
|
|
99
|
-
outputProcessors: { type: "jsonb", nullable: true },
|
|
100
|
-
// Output processor configurations
|
|
101
|
-
memory: { type: "jsonb", nullable: true },
|
|
102
|
-
// Memory configuration
|
|
103
|
-
scorers: { type: "jsonb", nullable: true },
|
|
104
|
-
// Scorer configurations
|
|
105
|
-
metadata: { type: "jsonb", nullable: true },
|
|
106
|
-
// Additional metadata for the agent
|
|
107
|
-
createdAt: { type: "timestamp", nullable: false },
|
|
108
|
-
updatedAt: { type: "timestamp", nullable: false }
|
|
109
|
-
};
|
|
110
|
-
var TABLE_SCHEMAS = {
|
|
111
|
-
[TABLE_WORKFLOW_SNAPSHOT]: {
|
|
112
|
-
workflow_name: {
|
|
113
|
-
type: "text"
|
|
114
|
-
},
|
|
115
|
-
run_id: {
|
|
116
|
-
type: "text"
|
|
117
|
-
},
|
|
118
|
-
resourceId: { type: "text", nullable: true },
|
|
119
|
-
snapshot: {
|
|
120
|
-
type: "text"
|
|
121
|
-
},
|
|
122
|
-
createdAt: {
|
|
123
|
-
type: "timestamp"
|
|
124
|
-
},
|
|
125
|
-
updatedAt: {
|
|
126
|
-
type: "timestamp"
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
[TABLE_SCORERS]: SCORERS_SCHEMA,
|
|
130
|
-
[TABLE_THREADS]: {
|
|
131
|
-
id: { type: "text", nullable: false, primaryKey: true },
|
|
132
|
-
resourceId: { type: "text", nullable: false },
|
|
133
|
-
title: { type: "text", nullable: false },
|
|
134
|
-
metadata: { type: "text", nullable: true },
|
|
135
|
-
createdAt: { type: "timestamp", nullable: false },
|
|
136
|
-
updatedAt: { type: "timestamp", nullable: false }
|
|
137
|
-
},
|
|
138
|
-
[TABLE_MESSAGES]: {
|
|
139
|
-
id: { type: "text", nullable: false, primaryKey: true },
|
|
140
|
-
thread_id: { type: "text", nullable: false },
|
|
141
|
-
content: { type: "text", nullable: false },
|
|
142
|
-
role: { type: "text", nullable: false },
|
|
143
|
-
type: { type: "text", nullable: false },
|
|
144
|
-
createdAt: { type: "timestamp", nullable: false },
|
|
145
|
-
resourceId: { type: "text", nullable: true }
|
|
146
|
-
},
|
|
147
|
-
[TABLE_SPANS]: SPAN_SCHEMA,
|
|
148
|
-
[TABLE_TRACES]: {
|
|
149
|
-
id: { type: "text", nullable: false, primaryKey: true },
|
|
150
|
-
parentSpanId: { type: "text", nullable: true },
|
|
151
|
-
name: { type: "text", nullable: false },
|
|
152
|
-
traceId: { type: "text", nullable: false },
|
|
153
|
-
scope: { type: "text", nullable: false },
|
|
154
|
-
kind: { type: "integer", nullable: false },
|
|
155
|
-
attributes: { type: "jsonb", nullable: true },
|
|
156
|
-
status: { type: "jsonb", nullable: true },
|
|
157
|
-
events: { type: "jsonb", nullable: true },
|
|
158
|
-
links: { type: "jsonb", nullable: true },
|
|
159
|
-
other: { type: "text", nullable: true },
|
|
160
|
-
startTime: { type: "bigint", nullable: false },
|
|
161
|
-
endTime: { type: "bigint", nullable: false },
|
|
162
|
-
createdAt: { type: "timestamp", nullable: false }
|
|
163
|
-
},
|
|
164
|
-
[TABLE_RESOURCES]: {
|
|
165
|
-
id: { type: "text", nullable: false, primaryKey: true },
|
|
166
|
-
workingMemory: { type: "text", nullable: true },
|
|
167
|
-
metadata: { type: "jsonb", nullable: true },
|
|
168
|
-
createdAt: { type: "timestamp", nullable: false },
|
|
169
|
-
updatedAt: { type: "timestamp", nullable: false }
|
|
170
|
-
},
|
|
171
|
-
[TABLE_AGENTS]: AGENTS_SCHEMA
|
|
172
|
-
};
|
|
173
|
-
|
|
174
6
|
// src/storage/base.ts
|
|
175
|
-
function ensureDate(date) {
|
|
176
|
-
if (!date) return void 0;
|
|
177
|
-
return date instanceof Date ? date : new Date(date);
|
|
178
|
-
}
|
|
179
|
-
function serializeDate(date) {
|
|
180
|
-
if (!date) return void 0;
|
|
181
|
-
const dateObj = ensureDate(date);
|
|
182
|
-
return dateObj?.toISOString();
|
|
183
|
-
}
|
|
184
7
|
function normalizePerPage(perPageInput, defaultValue) {
|
|
185
8
|
if (perPageInput === false) {
|
|
186
9
|
return Number.MAX_SAFE_INTEGER;
|
|
@@ -204,558 +27,149 @@ var MastraStorage = class extends MastraBase {
|
|
|
204
27
|
stores;
|
|
205
28
|
/**
|
|
206
29
|
* When true, automatic initialization (table creation/migrations) is disabled.
|
|
207
|
-
* This is useful for CI/CD pipelines where you want to:
|
|
208
|
-
* 1. Run migrations explicitly during deployment (not at runtime)
|
|
209
|
-
* 2. Use different credentials for schema changes vs runtime operations
|
|
210
|
-
*
|
|
211
|
-
* When disableInit is true:
|
|
212
|
-
* - The storage will not automatically create/alter tables on first use
|
|
213
|
-
* - You must call `storage.init()` explicitly in your CI/CD scripts
|
|
214
|
-
*
|
|
215
|
-
* @example
|
|
216
|
-
* // In CI/CD script:
|
|
217
|
-
* const storage = new PostgresStore({ ...config, disableInit: false });
|
|
218
|
-
* await storage.init(); // Explicitly run migrations
|
|
219
|
-
*
|
|
220
|
-
* // In runtime application:
|
|
221
|
-
* const storage = new PostgresStore({ ...config, disableInit: true });
|
|
222
|
-
* // No auto-init, tables must already exist
|
|
223
30
|
*/
|
|
224
31
|
disableInit = false;
|
|
225
|
-
constructor(
|
|
226
|
-
|
|
32
|
+
constructor(config) {
|
|
33
|
+
const name = config.name ?? "MastraStorage";
|
|
34
|
+
if (!config.id || typeof config.id !== "string" || config.id.trim() === "") {
|
|
227
35
|
throw new Error(`${name}: id must be provided and cannot be empty.`);
|
|
228
36
|
}
|
|
229
37
|
super({
|
|
230
38
|
component: "STORAGE",
|
|
231
39
|
name
|
|
232
40
|
});
|
|
233
|
-
this.id = id;
|
|
234
|
-
this.disableInit = disableInit ?? false;
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
serializeDate(date) {
|
|
253
|
-
return serializeDate(date);
|
|
254
|
-
}
|
|
255
|
-
async getResourceById(_) {
|
|
256
|
-
throw new Error(
|
|
257
|
-
`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.`
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
async saveResource(_) {
|
|
261
|
-
throw new Error(
|
|
262
|
-
`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.`
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
async updateResource(_) {
|
|
266
|
-
throw new Error(
|
|
267
|
-
`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.`
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
async listMessages(args) {
|
|
271
|
-
if (this.stores?.memory) {
|
|
272
|
-
return this.stores.memory.listMessages(args);
|
|
273
|
-
}
|
|
274
|
-
throw new MastraError({
|
|
275
|
-
id: "MASTRA_STORAGE_LIST_MESSAGES_NOT_SUPPORTED",
|
|
276
|
-
domain: "STORAGE" /* STORAGE */,
|
|
277
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
278
|
-
text: `Listing messages is not implemented by this storage adapter (${this.constructor.name})`
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
async listWorkflowRuns(args) {
|
|
282
|
-
if (this.stores?.workflows) {
|
|
283
|
-
return this.stores.workflows.listWorkflowRuns(args);
|
|
284
|
-
}
|
|
285
|
-
throw new MastraError({
|
|
286
|
-
id: "MASTRA_STORAGE_LIST_WORKFLOW_RUNS_NOT_SUPPORTED",
|
|
287
|
-
domain: "STORAGE" /* STORAGE */,
|
|
288
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
289
|
-
text: `Listing workflow runs is not implemented by this storage adapter (${this.constructor.name})`
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
async listThreadsByResourceId(args) {
|
|
293
|
-
if (this.stores?.memory) {
|
|
294
|
-
return this.stores.memory.listThreadsByResourceId(args);
|
|
295
|
-
}
|
|
296
|
-
throw new MastraError({
|
|
297
|
-
id: "MASTRA_STORAGE_LIST_THREADS_BY_RESOURCE_ID_PAGINATED_NOT_SUPPORTED",
|
|
298
|
-
domain: "STORAGE" /* STORAGE */,
|
|
299
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
300
|
-
text: `Listing threads by resource ID paginated is not implemented by this storage adapter (${this.constructor.name})`
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
async listMessagesById({ messageIds }) {
|
|
304
|
-
if (this.stores?.memory) {
|
|
305
|
-
const result = await this.stores.memory.listMessagesById({ messageIds });
|
|
306
|
-
return result;
|
|
41
|
+
this.id = config.id;
|
|
42
|
+
this.disableInit = config.disableInit ?? false;
|
|
43
|
+
if (config.default || config.domains) {
|
|
44
|
+
const defaultStores = config.default?.stores;
|
|
45
|
+
const domainOverrides = config.domains ?? {};
|
|
46
|
+
const hasDefaultDomains = defaultStores && Object.values(defaultStores).some((v) => v !== void 0);
|
|
47
|
+
const hasOverrideDomains = Object.values(domainOverrides).some((v) => v !== void 0);
|
|
48
|
+
if (!hasDefaultDomains && !hasOverrideDomains) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
"MastraStorage requires at least one storage source. Provide either a default storage with domains or domain overrides."
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
this.stores = {
|
|
54
|
+
memory: domainOverrides.memory ?? defaultStores?.memory,
|
|
55
|
+
workflows: domainOverrides.workflows ?? defaultStores?.workflows,
|
|
56
|
+
scores: domainOverrides.scores ?? defaultStores?.scores,
|
|
57
|
+
observability: domainOverrides.observability ?? defaultStores?.observability,
|
|
58
|
+
agents: domainOverrides.agents ?? defaultStores?.agents
|
|
59
|
+
};
|
|
307
60
|
}
|
|
308
|
-
throw new MastraError({
|
|
309
|
-
id: "MASTRA_STORAGE_LIST_MESSAGES_BY_ID_NOT_SUPPORTED",
|
|
310
|
-
domain: "STORAGE" /* STORAGE */,
|
|
311
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
312
|
-
text: `Listing messages by ID is not implemented by this storage adapter (${this.constructor.name})`
|
|
313
|
-
});
|
|
314
61
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Get a domain-specific storage interface.
|
|
64
|
+
*
|
|
65
|
+
* @param storeName - The name of the domain to access ('memory', 'workflows', 'scores', 'observability', 'agents')
|
|
66
|
+
* @returns The domain storage interface, or undefined if not available
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const memory = await storage.getStore('memory');
|
|
71
|
+
* if (memory) {
|
|
72
|
+
* await memory.saveThread({ thread });
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
async getStore(storeName) {
|
|
77
|
+
return this.stores?.[storeName];
|
|
319
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Initialize all domain stores.
|
|
81
|
+
* This creates necessary tables, indexes, and performs any required migrations.
|
|
82
|
+
*/
|
|
320
83
|
async init() {
|
|
321
84
|
if (this.shouldCacheInit && await this.hasInitialized) {
|
|
322
85
|
return;
|
|
323
86
|
}
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
schema: TABLE_SCHEMAS[TABLE_WORKFLOW_SNAPSHOT]
|
|
328
|
-
}),
|
|
329
|
-
this.createTable({
|
|
330
|
-
tableName: TABLE_THREADS,
|
|
331
|
-
schema: TABLE_SCHEMAS[TABLE_THREADS]
|
|
332
|
-
}),
|
|
333
|
-
this.createTable({
|
|
334
|
-
tableName: TABLE_MESSAGES,
|
|
335
|
-
schema: TABLE_SCHEMAS[TABLE_MESSAGES]
|
|
336
|
-
}),
|
|
337
|
-
this.createTable({
|
|
338
|
-
tableName: TABLE_TRACES,
|
|
339
|
-
schema: TABLE_SCHEMAS[TABLE_TRACES]
|
|
340
|
-
}),
|
|
341
|
-
this.createTable({
|
|
342
|
-
tableName: TABLE_SCORERS,
|
|
343
|
-
schema: TABLE_SCHEMAS[TABLE_SCORERS]
|
|
344
|
-
})
|
|
345
|
-
];
|
|
346
|
-
if (this.supports.resourceWorkingMemory) {
|
|
347
|
-
tableCreationTasks.push(
|
|
348
|
-
this.createTable({
|
|
349
|
-
tableName: TABLE_RESOURCES,
|
|
350
|
-
schema: TABLE_SCHEMAS[TABLE_RESOURCES]
|
|
351
|
-
})
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
if (this.supports.observabilityInstance) {
|
|
355
|
-
tableCreationTasks.push(
|
|
356
|
-
this.createTable({
|
|
357
|
-
tableName: TABLE_SPANS,
|
|
358
|
-
schema: TABLE_SCHEMAS[TABLE_SPANS]
|
|
359
|
-
})
|
|
360
|
-
);
|
|
87
|
+
const initTasks = [];
|
|
88
|
+
if (this.stores?.memory) {
|
|
89
|
+
initTasks.push(this.stores.memory.init());
|
|
361
90
|
}
|
|
362
|
-
if (this.
|
|
363
|
-
|
|
364
|
-
this.createTable({
|
|
365
|
-
tableName: TABLE_AGENTS,
|
|
366
|
-
schema: TABLE_SCHEMAS[TABLE_AGENTS]
|
|
367
|
-
})
|
|
368
|
-
);
|
|
91
|
+
if (this.stores?.workflows) {
|
|
92
|
+
initTasks.push(this.stores.workflows.init());
|
|
369
93
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
await this?.alterTable?.({
|
|
373
|
-
tableName: TABLE_MESSAGES,
|
|
374
|
-
schema: TABLE_SCHEMAS[TABLE_MESSAGES],
|
|
375
|
-
ifNotExists: ["resourceId"]
|
|
376
|
-
});
|
|
377
|
-
await this?.alterTable?.({
|
|
378
|
-
tableName: TABLE_WORKFLOW_SNAPSHOT,
|
|
379
|
-
schema: TABLE_SCHEMAS[TABLE_WORKFLOW_SNAPSHOT],
|
|
380
|
-
ifNotExists: ["resourceId"]
|
|
381
|
-
});
|
|
382
|
-
await this?.alterTable?.({
|
|
383
|
-
tableName: TABLE_SCORERS,
|
|
384
|
-
schema: TABLE_SCHEMAS[TABLE_SCORERS],
|
|
385
|
-
ifNotExists: ["spanId", "requestContext"]
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
async persistWorkflowSnapshot({
|
|
389
|
-
workflowName,
|
|
390
|
-
runId,
|
|
391
|
-
resourceId,
|
|
392
|
-
snapshot
|
|
393
|
-
}) {
|
|
394
|
-
await this.init();
|
|
395
|
-
const data = {
|
|
396
|
-
workflow_name: workflowName,
|
|
397
|
-
run_id: runId,
|
|
398
|
-
resourceId,
|
|
399
|
-
snapshot,
|
|
400
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
401
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
402
|
-
};
|
|
403
|
-
this.logger.debug("Persisting workflow snapshot", { workflowName, runId, data });
|
|
404
|
-
await this.insert({
|
|
405
|
-
tableName: TABLE_WORKFLOW_SNAPSHOT,
|
|
406
|
-
record: data
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
async loadWorkflowSnapshot({
|
|
410
|
-
workflowName,
|
|
411
|
-
runId
|
|
412
|
-
}) {
|
|
413
|
-
if (!this.hasInitialized) {
|
|
414
|
-
await this.init();
|
|
94
|
+
if (this.stores?.scores) {
|
|
95
|
+
initTasks.push(this.stores.scores.init());
|
|
415
96
|
}
|
|
416
|
-
this.logger.debug("Loading workflow snapshot", { workflowName, runId });
|
|
417
|
-
const d = await this.load({
|
|
418
|
-
tableName: TABLE_WORKFLOW_SNAPSHOT,
|
|
419
|
-
keys: { workflow_name: workflowName, run_id: runId }
|
|
420
|
-
});
|
|
421
|
-
return d ? d.snapshot : null;
|
|
422
|
-
}
|
|
423
|
-
async listScoresBySpan({
|
|
424
|
-
traceId,
|
|
425
|
-
spanId,
|
|
426
|
-
pagination: _pagination
|
|
427
|
-
}) {
|
|
428
|
-
throw new MastraError({
|
|
429
|
-
id: "SCORES_STORAGE_GET_SCORES_BY_SPAN_NOT_IMPLEMENTED",
|
|
430
|
-
domain: "STORAGE" /* STORAGE */,
|
|
431
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
432
|
-
details: { traceId, spanId }
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* OBSERVABILITY
|
|
437
|
-
*/
|
|
438
|
-
/**
|
|
439
|
-
* Provides hints for tracing strategy selection by the DefaultExporter.
|
|
440
|
-
* Storage adapters can override this to specify their preferred and supported strategies.
|
|
441
|
-
*/
|
|
442
|
-
get tracingStrategy() {
|
|
443
97
|
if (this.stores?.observability) {
|
|
444
|
-
|
|
98
|
+
initTasks.push(this.stores.observability.init());
|
|
445
99
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
domain: "STORAGE" /* STORAGE */,
|
|
449
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
450
|
-
text: `tracing is not supported by this storage adapter (${this.constructor.name})`
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Creates a single Span record in the storage provider.
|
|
455
|
-
*/
|
|
456
|
-
async createSpan(span) {
|
|
457
|
-
if (this.stores?.observability) {
|
|
458
|
-
return this.stores.observability.createSpan(span);
|
|
100
|
+
if (this.stores?.agents) {
|
|
101
|
+
initTasks.push(this.stores.agents.init());
|
|
459
102
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
domain: "STORAGE" /* STORAGE */,
|
|
463
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
464
|
-
text: `tracing is not supported by this storage adapter (${this.constructor.name})`
|
|
465
|
-
});
|
|
103
|
+
this.hasInitialized = Promise.all(initTasks).then(() => true);
|
|
104
|
+
await this.hasInitialized;
|
|
466
105
|
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// src/storage/domains/base.ts
|
|
109
|
+
var StorageDomain = class extends MastraBase {
|
|
467
110
|
/**
|
|
468
|
-
*
|
|
111
|
+
* Initialize the storage domain.
|
|
112
|
+
* This should create any necessary tables/collections.
|
|
113
|
+
* Default implementation is a no-op - override in adapters that need initialization.
|
|
469
114
|
*/
|
|
470
|
-
async
|
|
471
|
-
if (this.stores?.observability) {
|
|
472
|
-
return this.stores.observability.updateSpan(params);
|
|
473
|
-
}
|
|
474
|
-
throw new MastraError({
|
|
475
|
-
id: "MASTRA_STORAGE_UPDATE_AI_SPAN_NOT_SUPPORTED",
|
|
476
|
-
domain: "STORAGE" /* STORAGE */,
|
|
477
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
478
|
-
text: `tracing is not supported by this storage adapter (${this.constructor.name})`
|
|
479
|
-
});
|
|
115
|
+
async init() {
|
|
480
116
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
id: "MASTRA_STORAGE_GET_TRACE_NOT_SUPPORTED",
|
|
490
|
-
domain: "STORAGE" /* STORAGE */,
|
|
491
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
492
|
-
text: `tracing is not supported by this storage adapter (${this.constructor.name})`
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// src/storage/domains/agents/base.ts
|
|
120
|
+
var AgentsStorage = class extends StorageDomain {
|
|
121
|
+
constructor() {
|
|
122
|
+
super({
|
|
123
|
+
component: "STORAGE",
|
|
124
|
+
name: "AGENTS"
|
|
493
125
|
});
|
|
494
126
|
}
|
|
495
127
|
/**
|
|
496
|
-
*
|
|
128
|
+
* Parses orderBy input for consistent sorting behavior.
|
|
497
129
|
*/
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
id: "MASTRA_STORAGE_GET_TRACES_PAGINATED_NOT_SUPPORTED",
|
|
504
|
-
domain: "STORAGE" /* STORAGE */,
|
|
505
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
506
|
-
text: `tracing is not supported by this storage adapter (${this.constructor.name})`
|
|
507
|
-
});
|
|
130
|
+
parseOrderBy(orderBy, defaultDirection = "DESC") {
|
|
131
|
+
return {
|
|
132
|
+
field: orderBy?.field && orderBy.field in AGENT_ORDER_BY_SET ? orderBy.field : "createdAt",
|
|
133
|
+
direction: orderBy?.direction && orderBy.direction in AGENT_SORT_DIRECTION_SET ? orderBy.direction : defaultDirection
|
|
134
|
+
};
|
|
508
135
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
136
|
+
};
|
|
137
|
+
var AGENT_ORDER_BY_SET = {
|
|
138
|
+
createdAt: true,
|
|
139
|
+
updatedAt: true
|
|
140
|
+
};
|
|
141
|
+
var AGENT_SORT_DIRECTION_SET = {
|
|
142
|
+
ASC: true,
|
|
143
|
+
DESC: true
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/storage/domains/agents/inmemory.ts
|
|
147
|
+
var InMemoryAgentsStorage = class extends AgentsStorage {
|
|
148
|
+
db;
|
|
149
|
+
constructor({ db }) {
|
|
150
|
+
super();
|
|
151
|
+
this.db = db;
|
|
522
152
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
*/
|
|
526
|
-
async batchUpdateSpans(args) {
|
|
527
|
-
if (this.stores?.observability) {
|
|
528
|
-
return this.stores.observability.batchUpdateSpans(args);
|
|
529
|
-
}
|
|
530
|
-
throw new MastraError({
|
|
531
|
-
id: "MASTRA_STORAGE_BATCH_UPDATE_AI_SPANS_NOT_SUPPORTED",
|
|
532
|
-
domain: "STORAGE" /* STORAGE */,
|
|
533
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
534
|
-
text: `tracing is not supported by this storage adapter (${this.constructor.name})`
|
|
535
|
-
});
|
|
153
|
+
async dangerouslyClearAll() {
|
|
154
|
+
this.db.agents.clear();
|
|
536
155
|
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
});
|
|
156
|
+
async getAgentById({ id }) {
|
|
157
|
+
this.logger.debug(`InMemoryAgentsStorage: getAgentById called for ${id}`);
|
|
158
|
+
const agent = this.db.agents.get(id);
|
|
159
|
+
return agent ? {
|
|
160
|
+
...agent,
|
|
161
|
+
metadata: agent.metadata ? { ...agent.metadata } : agent.metadata,
|
|
162
|
+
model: { ...agent.model },
|
|
163
|
+
tools: agent.tools ? [...agent.tools] : agent.tools,
|
|
164
|
+
workflows: agent.workflows ? [...agent.workflows] : agent.workflows,
|
|
165
|
+
agents: agent.agents ? [...agent.agents] : agent.agents,
|
|
166
|
+
scorers: agent.scorers ? { ...agent.scorers } : agent.scorers
|
|
167
|
+
} : null;
|
|
550
168
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
*/
|
|
556
|
-
/**
|
|
557
|
-
* Creates a database index on specified columns
|
|
558
|
-
* @throws {MastraError} if not supported by the storage adapter
|
|
559
|
-
*/
|
|
560
|
-
async createIndex(options) {
|
|
561
|
-
if (this.stores?.operations) {
|
|
562
|
-
return this.stores.operations.createIndex(options);
|
|
563
|
-
}
|
|
564
|
-
throw new MastraError({
|
|
565
|
-
id: "MASTRA_STORAGE_CREATE_INDEX_NOT_SUPPORTED",
|
|
566
|
-
domain: "STORAGE" /* STORAGE */,
|
|
567
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
568
|
-
text: `Index management is not supported by this storage adapter (${this.constructor.name})`
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
/**
|
|
572
|
-
* Drops a database index by name
|
|
573
|
-
* @throws {MastraError} if not supported by the storage adapter
|
|
574
|
-
*/
|
|
575
|
-
async dropIndex(indexName) {
|
|
576
|
-
if (this.stores?.operations) {
|
|
577
|
-
return this.stores.operations.dropIndex(indexName);
|
|
578
|
-
}
|
|
579
|
-
throw new MastraError({
|
|
580
|
-
id: "MASTRA_STORAGE_DROP_INDEX_NOT_SUPPORTED",
|
|
581
|
-
domain: "STORAGE" /* STORAGE */,
|
|
582
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
583
|
-
text: `Index management is not supported by this storage adapter (${this.constructor.name})`
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* Lists database indexes for a table or all tables
|
|
588
|
-
* @throws {MastraError} if not supported by the storage adapter
|
|
589
|
-
*/
|
|
590
|
-
async listIndexes(tableName) {
|
|
591
|
-
if (this.stores?.operations) {
|
|
592
|
-
return this.stores.operations.listIndexes(tableName);
|
|
593
|
-
}
|
|
594
|
-
throw new MastraError({
|
|
595
|
-
id: "MASTRA_STORAGE_LIST_INDEXES_NOT_SUPPORTED",
|
|
596
|
-
domain: "STORAGE" /* STORAGE */,
|
|
597
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
598
|
-
text: `Index management is not supported by this storage adapter (${this.constructor.name})`
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
/**
|
|
602
|
-
* Gets detailed statistics for a specific index
|
|
603
|
-
* @throws {MastraError} if not supported by the storage adapter
|
|
604
|
-
*/
|
|
605
|
-
async describeIndex(indexName) {
|
|
606
|
-
if (this.stores?.operations) {
|
|
607
|
-
return this.stores.operations.describeIndex(indexName);
|
|
608
|
-
}
|
|
609
|
-
throw new MastraError({
|
|
610
|
-
id: "MASTRA_STORAGE_DESCRIBE_INDEX_NOT_SUPPORTED",
|
|
611
|
-
domain: "STORAGE" /* STORAGE */,
|
|
612
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
613
|
-
text: `Index management is not supported by this storage adapter (${this.constructor.name})`
|
|
614
|
-
});
|
|
615
|
-
}
|
|
616
|
-
/**
|
|
617
|
-
* AGENTS STORAGE
|
|
618
|
-
* These methods delegate to the agents store for agent CRUD operations.
|
|
619
|
-
* This enables dynamic creation of agents via Mastra Studio.
|
|
620
|
-
*/
|
|
621
|
-
/**
|
|
622
|
-
* Retrieves an agent by its unique identifier.
|
|
623
|
-
* @param id - The unique identifier of the agent
|
|
624
|
-
* @returns The agent if found, null otherwise
|
|
625
|
-
* @throws {MastraError} if not supported by the storage adapter
|
|
626
|
-
*/
|
|
627
|
-
async getAgentById({ id }) {
|
|
628
|
-
if (this.stores?.agents) {
|
|
629
|
-
return this.stores.agents.getAgentById({ id });
|
|
630
|
-
}
|
|
631
|
-
throw new MastraError({
|
|
632
|
-
id: "MASTRA_STORAGE_GET_AGENT_BY_ID_NOT_SUPPORTED",
|
|
633
|
-
domain: "STORAGE" /* STORAGE */,
|
|
634
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
635
|
-
text: `Agent storage is not supported by this storage adapter (${this.constructor.name})`
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Creates a new agent in storage.
|
|
640
|
-
* @param agent - The agent data to create
|
|
641
|
-
* @returns The created agent with timestamps
|
|
642
|
-
* @throws {MastraError} if not supported by the storage adapter
|
|
643
|
-
*/
|
|
644
|
-
async createAgent({ agent }) {
|
|
645
|
-
if (this.stores?.agents) {
|
|
646
|
-
return this.stores.agents.createAgent({ agent });
|
|
647
|
-
}
|
|
648
|
-
throw new MastraError({
|
|
649
|
-
id: "MASTRA_STORAGE_CREATE_AGENT_NOT_SUPPORTED",
|
|
650
|
-
domain: "STORAGE" /* STORAGE */,
|
|
651
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
652
|
-
text: `Agent storage is not supported by this storage adapter (${this.constructor.name})`
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
/**
|
|
656
|
-
* Updates an existing agent in storage.
|
|
657
|
-
* @param id - The unique identifier of the agent to update
|
|
658
|
-
* @param updates - The fields to update
|
|
659
|
-
* @returns The updated agent
|
|
660
|
-
* @throws {MastraError} if not supported by the storage adapter
|
|
661
|
-
*/
|
|
662
|
-
async updateAgent(args) {
|
|
663
|
-
if (this.stores?.agents) {
|
|
664
|
-
return this.stores.agents.updateAgent(args);
|
|
665
|
-
}
|
|
666
|
-
throw new MastraError({
|
|
667
|
-
id: "MASTRA_STORAGE_UPDATE_AGENT_NOT_SUPPORTED",
|
|
668
|
-
domain: "STORAGE" /* STORAGE */,
|
|
669
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
670
|
-
text: `Agent storage is not supported by this storage adapter (${this.constructor.name})`
|
|
671
|
-
});
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* Deletes an agent from storage.
|
|
675
|
-
* @param id - The unique identifier of the agent to delete
|
|
676
|
-
* @throws {MastraError} if not supported by the storage adapter
|
|
677
|
-
*/
|
|
678
|
-
async deleteAgent({ id }) {
|
|
679
|
-
if (this.stores?.agents) {
|
|
680
|
-
return this.stores.agents.deleteAgent({ id });
|
|
681
|
-
}
|
|
682
|
-
throw new MastraError({
|
|
683
|
-
id: "MASTRA_STORAGE_DELETE_AGENT_NOT_SUPPORTED",
|
|
684
|
-
domain: "STORAGE" /* STORAGE */,
|
|
685
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
686
|
-
text: `Agent storage is not supported by this storage adapter (${this.constructor.name})`
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
/**
|
|
690
|
-
* Lists all agents with optional pagination.
|
|
691
|
-
* @param args - Pagination and ordering options
|
|
692
|
-
* @returns Paginated list of agents
|
|
693
|
-
* @throws {MastraError} if not supported by the storage adapter
|
|
694
|
-
*/
|
|
695
|
-
async listAgents(args) {
|
|
696
|
-
if (this.stores?.agents) {
|
|
697
|
-
return this.stores.agents.listAgents(args);
|
|
698
|
-
}
|
|
699
|
-
throw new MastraError({
|
|
700
|
-
id: "MASTRA_STORAGE_LIST_AGENTS_NOT_SUPPORTED",
|
|
701
|
-
domain: "STORAGE" /* STORAGE */,
|
|
702
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
703
|
-
text: `Agent storage is not supported by this storage adapter (${this.constructor.name})`
|
|
704
|
-
});
|
|
705
|
-
}
|
|
706
|
-
};
|
|
707
|
-
|
|
708
|
-
// src/storage/domains/agents/base.ts
|
|
709
|
-
var AgentsStorage = class extends MastraBase {
|
|
710
|
-
constructor() {
|
|
711
|
-
super({
|
|
712
|
-
component: "STORAGE",
|
|
713
|
-
name: "AGENTS"
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
/**
|
|
717
|
-
* Parses orderBy input for consistent sorting behavior.
|
|
718
|
-
*/
|
|
719
|
-
parseOrderBy(orderBy, defaultDirection = "DESC") {
|
|
720
|
-
return {
|
|
721
|
-
field: orderBy?.field && orderBy.field in AGENT_ORDER_BY_SET ? orderBy.field : "createdAt",
|
|
722
|
-
direction: orderBy?.direction && orderBy.direction in AGENT_SORT_DIRECTION_SET ? orderBy.direction : defaultDirection
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
};
|
|
726
|
-
var AGENT_ORDER_BY_SET = {
|
|
727
|
-
createdAt: true,
|
|
728
|
-
updatedAt: true
|
|
729
|
-
};
|
|
730
|
-
var AGENT_SORT_DIRECTION_SET = {
|
|
731
|
-
ASC: true,
|
|
732
|
-
DESC: true
|
|
733
|
-
};
|
|
734
|
-
|
|
735
|
-
// src/storage/domains/agents/inmemory.ts
|
|
736
|
-
var InMemoryAgentsStorage = class extends AgentsStorage {
|
|
737
|
-
collection;
|
|
738
|
-
constructor({ collection }) {
|
|
739
|
-
super();
|
|
740
|
-
this.collection = collection;
|
|
741
|
-
}
|
|
742
|
-
async getAgentById({ id }) {
|
|
743
|
-
this.logger.debug(`InMemoryAgentsStorage: getAgentById called for ${id}`);
|
|
744
|
-
const agent = this.collection.get(id);
|
|
745
|
-
return agent ? {
|
|
746
|
-
...agent,
|
|
747
|
-
metadata: agent.metadata ? { ...agent.metadata } : agent.metadata,
|
|
748
|
-
model: { ...agent.model },
|
|
749
|
-
tools: agent.tools ? [...agent.tools] : agent.tools,
|
|
750
|
-
workflows: agent.workflows ? [...agent.workflows] : agent.workflows,
|
|
751
|
-
agents: agent.agents ? [...agent.agents] : agent.agents,
|
|
752
|
-
scorers: agent.scorers ? { ...agent.scorers } : agent.scorers
|
|
753
|
-
} : null;
|
|
754
|
-
}
|
|
755
|
-
async createAgent({ agent }) {
|
|
756
|
-
this.logger.debug(`InMemoryAgentsStorage: createAgent called for ${agent.id}`);
|
|
757
|
-
if (this.collection.has(agent.id)) {
|
|
758
|
-
throw new Error(`Agent with id ${agent.id} already exists`);
|
|
169
|
+
async createAgent({ agent }) {
|
|
170
|
+
this.logger.debug(`InMemoryAgentsStorage: createAgent called for ${agent.id}`);
|
|
171
|
+
if (this.db.agents.has(agent.id)) {
|
|
172
|
+
throw new Error(`Agent with id ${agent.id} already exists`);
|
|
759
173
|
}
|
|
760
174
|
const now = /* @__PURE__ */ new Date();
|
|
761
175
|
const newAgent = {
|
|
@@ -763,12 +177,12 @@ var InMemoryAgentsStorage = class extends AgentsStorage {
|
|
|
763
177
|
createdAt: now,
|
|
764
178
|
updatedAt: now
|
|
765
179
|
};
|
|
766
|
-
this.
|
|
180
|
+
this.db.agents.set(agent.id, newAgent);
|
|
767
181
|
return { ...newAgent };
|
|
768
182
|
}
|
|
769
183
|
async updateAgent({ id, ...updates }) {
|
|
770
184
|
this.logger.debug(`InMemoryAgentsStorage: updateAgent called for ${id}`);
|
|
771
|
-
const existingAgent = this.
|
|
185
|
+
const existingAgent = this.db.agents.get(id);
|
|
772
186
|
if (!existingAgent) {
|
|
773
187
|
throw new Error(`Agent with id ${id} not found`);
|
|
774
188
|
}
|
|
@@ -793,12 +207,12 @@ var InMemoryAgentsStorage = class extends AgentsStorage {
|
|
|
793
207
|
},
|
|
794
208
|
updatedAt: /* @__PURE__ */ new Date()
|
|
795
209
|
};
|
|
796
|
-
this.
|
|
210
|
+
this.db.agents.set(id, updatedAgent);
|
|
797
211
|
return { ...updatedAgent };
|
|
798
212
|
}
|
|
799
213
|
async deleteAgent({ id }) {
|
|
800
214
|
this.logger.debug(`InMemoryAgentsStorage: deleteAgent called for ${id}`);
|
|
801
|
-
this.
|
|
215
|
+
this.db.agents.delete(id);
|
|
802
216
|
}
|
|
803
217
|
async listAgents(args) {
|
|
804
218
|
const { page = 0, perPage: perPageInput, orderBy } = args || {};
|
|
@@ -812,7 +226,7 @@ var InMemoryAgentsStorage = class extends AgentsStorage {
|
|
|
812
226
|
if (page * perPage > maxOffset) {
|
|
813
227
|
throw new Error("page value too large");
|
|
814
228
|
}
|
|
815
|
-
const agents = Array.from(this.
|
|
229
|
+
const agents = Array.from(this.db.agents.values());
|
|
816
230
|
const sortedAgents = this.sortAgents(agents, field, direction);
|
|
817
231
|
const clonedAgents = sortedAgents.map((agent) => ({
|
|
818
232
|
...agent,
|
|
@@ -841,6 +255,30 @@ var InMemoryAgentsStorage = class extends AgentsStorage {
|
|
|
841
255
|
}
|
|
842
256
|
};
|
|
843
257
|
|
|
258
|
+
// src/storage/domains/inmemory-db.ts
|
|
259
|
+
var InMemoryDB = class {
|
|
260
|
+
threads = /* @__PURE__ */ new Map();
|
|
261
|
+
messages = /* @__PURE__ */ new Map();
|
|
262
|
+
resources = /* @__PURE__ */ new Map();
|
|
263
|
+
workflows = /* @__PURE__ */ new Map();
|
|
264
|
+
scores = /* @__PURE__ */ new Map();
|
|
265
|
+
traces = /* @__PURE__ */ new Map();
|
|
266
|
+
agents = /* @__PURE__ */ new Map();
|
|
267
|
+
/**
|
|
268
|
+
* Clears all data from all collections.
|
|
269
|
+
* Useful for testing.
|
|
270
|
+
*/
|
|
271
|
+
clear() {
|
|
272
|
+
this.threads.clear();
|
|
273
|
+
this.messages.clear();
|
|
274
|
+
this.resources.clear();
|
|
275
|
+
this.workflows.clear();
|
|
276
|
+
this.scores.clear();
|
|
277
|
+
this.traces.clear();
|
|
278
|
+
this.agents.clear();
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
|
|
844
282
|
// src/storage/utils.ts
|
|
845
283
|
function safelyParseJSON(input) {
|
|
846
284
|
if (input && typeof input === "object") return input;
|
|
@@ -905,9 +343,57 @@ function createStorageErrorId(store, operation, status) {
|
|
|
905
343
|
function createVectorErrorId(store, operation, status) {
|
|
906
344
|
return createStoreErrorId("vector", store, operation, status);
|
|
907
345
|
}
|
|
346
|
+
function getSqlType(type) {
|
|
347
|
+
switch (type) {
|
|
348
|
+
case "text":
|
|
349
|
+
return "TEXT";
|
|
350
|
+
case "timestamp":
|
|
351
|
+
return "TIMESTAMP";
|
|
352
|
+
case "float":
|
|
353
|
+
return "FLOAT";
|
|
354
|
+
case "integer":
|
|
355
|
+
return "INTEGER";
|
|
356
|
+
case "bigint":
|
|
357
|
+
return "BIGINT";
|
|
358
|
+
case "jsonb":
|
|
359
|
+
return "JSONB";
|
|
360
|
+
case "boolean":
|
|
361
|
+
return "BOOLEAN";
|
|
362
|
+
default:
|
|
363
|
+
return "TEXT";
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
function getDefaultValue(type) {
|
|
367
|
+
switch (type) {
|
|
368
|
+
case "text":
|
|
369
|
+
case "uuid":
|
|
370
|
+
return "DEFAULT ''";
|
|
371
|
+
case "timestamp":
|
|
372
|
+
return "DEFAULT '1970-01-01 00:00:00'";
|
|
373
|
+
case "integer":
|
|
374
|
+
case "bigint":
|
|
375
|
+
case "float":
|
|
376
|
+
return "DEFAULT 0";
|
|
377
|
+
case "jsonb":
|
|
378
|
+
return "DEFAULT '{}'";
|
|
379
|
+
case "boolean":
|
|
380
|
+
return "DEFAULT FALSE";
|
|
381
|
+
default:
|
|
382
|
+
return "DEFAULT ''";
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function ensureDate(date) {
|
|
386
|
+
if (!date) return void 0;
|
|
387
|
+
return date instanceof Date ? date : new Date(date);
|
|
388
|
+
}
|
|
389
|
+
function serializeDate(date) {
|
|
390
|
+
if (!date) return void 0;
|
|
391
|
+
const dateObj = ensureDate(date);
|
|
392
|
+
return dateObj?.toISOString();
|
|
393
|
+
}
|
|
908
394
|
|
|
909
395
|
// src/storage/domains/memory/base.ts
|
|
910
|
-
var MemoryStorage = class extends
|
|
396
|
+
var MemoryStorage = class extends StorageDomain {
|
|
911
397
|
constructor() {
|
|
912
398
|
super({
|
|
913
399
|
component: "STORAGE",
|
|
@@ -952,25 +438,25 @@ var THREAD_THREAD_SORT_DIRECTION_SET = {
|
|
|
952
438
|
|
|
953
439
|
// src/storage/domains/memory/inmemory.ts
|
|
954
440
|
var InMemoryMemory = class extends MemoryStorage {
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
constructor({
|
|
958
|
-
collection,
|
|
959
|
-
operations
|
|
960
|
-
}) {
|
|
441
|
+
db;
|
|
442
|
+
constructor({ db }) {
|
|
961
443
|
super();
|
|
962
|
-
this.
|
|
963
|
-
|
|
444
|
+
this.db = db;
|
|
445
|
+
}
|
|
446
|
+
async dangerouslyClearAll() {
|
|
447
|
+
this.db.threads.clear();
|
|
448
|
+
this.db.messages.clear();
|
|
449
|
+
this.db.resources.clear();
|
|
964
450
|
}
|
|
965
451
|
async getThreadById({ threadId }) {
|
|
966
|
-
this.logger.debug(`
|
|
967
|
-
const thread = this.
|
|
452
|
+
this.logger.debug(`InMemoryMemory: getThreadById called for ${threadId}`);
|
|
453
|
+
const thread = this.db.threads.get(threadId);
|
|
968
454
|
return thread ? { ...thread, metadata: thread.metadata ? { ...thread.metadata } : thread.metadata } : null;
|
|
969
455
|
}
|
|
970
456
|
async saveThread({ thread }) {
|
|
971
|
-
this.logger.debug(`
|
|
457
|
+
this.logger.debug(`InMemoryMemory: saveThread called for ${thread.id}`);
|
|
972
458
|
const key = thread.id;
|
|
973
|
-
this.
|
|
459
|
+
this.db.threads.set(key, thread);
|
|
974
460
|
return thread;
|
|
975
461
|
}
|
|
976
462
|
async updateThread({
|
|
@@ -978,8 +464,8 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
978
464
|
title,
|
|
979
465
|
metadata
|
|
980
466
|
}) {
|
|
981
|
-
this.logger.debug(`
|
|
982
|
-
const thread = this.
|
|
467
|
+
this.logger.debug(`InMemoryMemory: updateThread called for ${id}`);
|
|
468
|
+
const thread = this.db.threads.get(id);
|
|
983
469
|
if (!thread) {
|
|
984
470
|
throw new Error(`Thread with id ${id} not found`);
|
|
985
471
|
}
|
|
@@ -991,11 +477,11 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
991
477
|
return thread;
|
|
992
478
|
}
|
|
993
479
|
async deleteThread({ threadId }) {
|
|
994
|
-
this.logger.debug(`
|
|
995
|
-
this.
|
|
996
|
-
this.
|
|
480
|
+
this.logger.debug(`InMemoryMemory: deleteThread called for ${threadId}`);
|
|
481
|
+
this.db.threads.delete(threadId);
|
|
482
|
+
this.db.messages.forEach((msg, key) => {
|
|
997
483
|
if (msg.thread_id === threadId) {
|
|
998
|
-
this.
|
|
484
|
+
this.db.messages.delete(key);
|
|
999
485
|
}
|
|
1000
486
|
});
|
|
1001
487
|
}
|
|
@@ -1009,7 +495,7 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1009
495
|
orderBy
|
|
1010
496
|
}) {
|
|
1011
497
|
const threadIds = Array.isArray(threadId) ? threadId : [threadId];
|
|
1012
|
-
this.logger.debug(`
|
|
498
|
+
this.logger.debug(`InMemoryMemory: listMessages called for threads ${threadIds.join(", ")}`);
|
|
1013
499
|
if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
|
|
1014
500
|
throw new Error("threadId must be a non-empty string or array of non-empty strings");
|
|
1015
501
|
}
|
|
@@ -1024,7 +510,7 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1024
510
|
throw new Error("page value too large");
|
|
1025
511
|
}
|
|
1026
512
|
const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
1027
|
-
let threadMessages = Array.from(this.
|
|
513
|
+
let threadMessages = Array.from(this.db.messages.values()).filter((msg) => {
|
|
1028
514
|
if (!threadIdSet.has(msg.thread_id)) return false;
|
|
1029
515
|
if (resourceId && msg.resourceId !== resourceId) return false;
|
|
1030
516
|
return true;
|
|
@@ -1062,7 +548,7 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1062
548
|
}
|
|
1063
549
|
if (include && include.length > 0) {
|
|
1064
550
|
for (const includeItem of include) {
|
|
1065
|
-
const targetMessage = this.
|
|
551
|
+
const targetMessage = this.db.messages.get(includeItem.id);
|
|
1066
552
|
if (targetMessage) {
|
|
1067
553
|
const convertedMessage = {
|
|
1068
554
|
id: targetMessage.id,
|
|
@@ -1078,7 +564,7 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1078
564
|
messageIds.add(convertedMessage.id);
|
|
1079
565
|
}
|
|
1080
566
|
if (includeItem.withPreviousMessages) {
|
|
1081
|
-
const allThreadMessages = Array.from(this.
|
|
567
|
+
const allThreadMessages = Array.from(this.db.messages.values()).filter((msg) => msg.thread_id === (includeItem.threadId || threadId)).sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
1082
568
|
const targetIndex = allThreadMessages.findIndex((msg) => msg.id === includeItem.id);
|
|
1083
569
|
if (targetIndex !== -1) {
|
|
1084
570
|
const startIndex = Math.max(0, targetIndex - (includeItem.withPreviousMessages || 0));
|
|
@@ -1101,7 +587,7 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1101
587
|
}
|
|
1102
588
|
}
|
|
1103
589
|
if (includeItem.withNextMessages) {
|
|
1104
|
-
const allThreadMessages = Array.from(this.
|
|
590
|
+
const allThreadMessages = Array.from(this.db.messages.values()).filter((msg) => msg.thread_id === (includeItem.threadId || threadId)).sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
1105
591
|
const targetIndex = allThreadMessages.findIndex((msg) => msg.id === includeItem.id);
|
|
1106
592
|
if (targetIndex !== -1) {
|
|
1107
593
|
const endIndex = Math.min(
|
|
@@ -1172,20 +658,23 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1172
658
|
};
|
|
1173
659
|
}
|
|
1174
660
|
async listMessagesById({ messageIds }) {
|
|
1175
|
-
this.logger.debug(`
|
|
1176
|
-
const rawMessages = messageIds.map((id) => this.
|
|
1177
|
-
const list = new MessageList().add(
|
|
661
|
+
this.logger.debug(`InMemoryMemory: listMessagesById called`);
|
|
662
|
+
const rawMessages = messageIds.map((id) => this.db.messages.get(id)).filter((message) => !!message);
|
|
663
|
+
const list = new MessageList().add(
|
|
664
|
+
rawMessages.map((m) => this.parseStoredMessage(m)),
|
|
665
|
+
"memory"
|
|
666
|
+
);
|
|
1178
667
|
return { messages: list.get.all.db() };
|
|
1179
668
|
}
|
|
1180
669
|
async saveMessages(args) {
|
|
1181
670
|
const { messages } = args;
|
|
1182
|
-
this.logger.debug(`
|
|
671
|
+
this.logger.debug(`InMemoryMemory: saveMessages called with ${messages.length} messages`);
|
|
1183
672
|
if (messages.some((msg) => msg.id === "error-message" || msg.resourceId === null)) {
|
|
1184
673
|
throw new Error("Simulated error for testing");
|
|
1185
674
|
}
|
|
1186
675
|
const threadIds = new Set(messages.map((msg) => msg.threadId).filter((id) => Boolean(id)));
|
|
1187
676
|
for (const threadId of threadIds) {
|
|
1188
|
-
const thread = this.
|
|
677
|
+
const thread = this.db.threads.get(threadId);
|
|
1189
678
|
if (thread) {
|
|
1190
679
|
thread.updatedAt = /* @__PURE__ */ new Date();
|
|
1191
680
|
}
|
|
@@ -1201,7 +690,7 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1201
690
|
createdAt: message.createdAt,
|
|
1202
691
|
resourceId: message.resourceId || null
|
|
1203
692
|
};
|
|
1204
|
-
this.
|
|
693
|
+
this.db.messages.set(key, storageMessage);
|
|
1205
694
|
}
|
|
1206
695
|
const list = new MessageList().add(messages, "memory");
|
|
1207
696
|
return { messages: list.get.all.db() };
|
|
@@ -1209,7 +698,7 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1209
698
|
async updateMessages(args) {
|
|
1210
699
|
const updatedMessages = [];
|
|
1211
700
|
for (const update of args.messages) {
|
|
1212
|
-
const storageMsg = this.
|
|
701
|
+
const storageMsg = this.db.messages.get(update.id);
|
|
1213
702
|
if (!storageMsg) continue;
|
|
1214
703
|
const oldThreadId = storageMsg.thread_id;
|
|
1215
704
|
const newThreadId = update.threadId || oldThreadId;
|
|
@@ -1236,13 +725,13 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1236
725
|
storageMsg.thread_id = newThreadId;
|
|
1237
726
|
const base = Date.now();
|
|
1238
727
|
let oldThreadNewTime;
|
|
1239
|
-
const oldThread = this.
|
|
728
|
+
const oldThread = this.db.threads.get(oldThreadId);
|
|
1240
729
|
if (oldThread) {
|
|
1241
730
|
const prev = new Date(oldThread.updatedAt).getTime();
|
|
1242
731
|
oldThreadNewTime = Math.max(base, prev + 1);
|
|
1243
732
|
oldThread.updatedAt = new Date(oldThreadNewTime);
|
|
1244
733
|
}
|
|
1245
|
-
const newThread = this.
|
|
734
|
+
const newThread = this.db.threads.get(newThreadId);
|
|
1246
735
|
if (newThread) {
|
|
1247
736
|
const prev = new Date(newThread.updatedAt).getTime();
|
|
1248
737
|
let newThreadNewTime = Math.max(base + 1, prev + 1);
|
|
@@ -1252,7 +741,7 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1252
741
|
newThread.updatedAt = new Date(newThreadNewTime);
|
|
1253
742
|
}
|
|
1254
743
|
} else {
|
|
1255
|
-
const thread = this.
|
|
744
|
+
const thread = this.db.threads.get(oldThreadId);
|
|
1256
745
|
if (thread) {
|
|
1257
746
|
const prev = new Date(thread.updatedAt).getTime();
|
|
1258
747
|
let newTime = Date.now();
|
|
@@ -1260,7 +749,7 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1260
749
|
thread.updatedAt = new Date(newTime);
|
|
1261
750
|
}
|
|
1262
751
|
}
|
|
1263
|
-
this.
|
|
752
|
+
this.db.messages.set(update.id, storageMsg);
|
|
1264
753
|
updatedMessages.push({
|
|
1265
754
|
id: storageMsg.id,
|
|
1266
755
|
threadId: storageMsg.thread_id,
|
|
@@ -1277,18 +766,18 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1277
766
|
if (!messageIds || messageIds.length === 0) {
|
|
1278
767
|
return;
|
|
1279
768
|
}
|
|
1280
|
-
this.logger.debug(`
|
|
769
|
+
this.logger.debug(`InMemoryMemory: deleteMessages called for ${messageIds.length} messages`);
|
|
1281
770
|
const threadIds = /* @__PURE__ */ new Set();
|
|
1282
771
|
for (const messageId of messageIds) {
|
|
1283
|
-
const message = this.
|
|
772
|
+
const message = this.db.messages.get(messageId);
|
|
1284
773
|
if (message && message.thread_id) {
|
|
1285
774
|
threadIds.add(message.thread_id);
|
|
1286
775
|
}
|
|
1287
|
-
this.
|
|
776
|
+
this.db.messages.delete(messageId);
|
|
1288
777
|
}
|
|
1289
778
|
const now = /* @__PURE__ */ new Date();
|
|
1290
779
|
for (const threadId of threadIds) {
|
|
1291
|
-
const thread = this.
|
|
780
|
+
const thread = this.db.threads.get(threadId);
|
|
1292
781
|
if (thread) {
|
|
1293
782
|
thread.updatedAt = now;
|
|
1294
783
|
}
|
|
@@ -1305,8 +794,8 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1305
794
|
if (page * perPage > maxOffset) {
|
|
1306
795
|
throw new Error("page value too large");
|
|
1307
796
|
}
|
|
1308
|
-
this.logger.debug(`
|
|
1309
|
-
const threads = Array.from(this.
|
|
797
|
+
this.logger.debug(`InMemoryMemory: listThreadsByResourceId called for ${resourceId}`);
|
|
798
|
+
const threads = Array.from(this.db.threads.values()).filter((t) => t.resourceId === resourceId);
|
|
1310
799
|
const sortedThreads = this.sortThreads(threads, field, direction);
|
|
1311
800
|
const clonedThreads = sortedThreads.map((thread) => ({
|
|
1312
801
|
...thread,
|
|
@@ -1322,13 +811,13 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1322
811
|
};
|
|
1323
812
|
}
|
|
1324
813
|
async getResourceById({ resourceId }) {
|
|
1325
|
-
this.logger.debug(`
|
|
1326
|
-
const resource = this.
|
|
814
|
+
this.logger.debug(`InMemoryMemory: getResourceById called for ${resourceId}`);
|
|
815
|
+
const resource = this.db.resources.get(resourceId);
|
|
1327
816
|
return resource ? { ...resource, metadata: resource.metadata ? { ...resource.metadata } : resource.metadata } : null;
|
|
1328
817
|
}
|
|
1329
818
|
async saveResource({ resource }) {
|
|
1330
|
-
this.logger.debug(`
|
|
1331
|
-
this.
|
|
819
|
+
this.logger.debug(`InMemoryMemory: saveResource called for ${resource.id}`);
|
|
820
|
+
this.db.resources.set(resource.id, resource);
|
|
1332
821
|
return resource;
|
|
1333
822
|
}
|
|
1334
823
|
async updateResource({
|
|
@@ -1336,8 +825,8 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1336
825
|
workingMemory,
|
|
1337
826
|
metadata
|
|
1338
827
|
}) {
|
|
1339
|
-
this.logger.debug(`
|
|
1340
|
-
let resource = this.
|
|
828
|
+
this.logger.debug(`InMemoryMemory: updateResource called for ${resourceId}`);
|
|
829
|
+
let resource = this.db.resources.get(resourceId);
|
|
1341
830
|
if (!resource) {
|
|
1342
831
|
resource = {
|
|
1343
832
|
id: resourceId,
|
|
@@ -1357,7 +846,7 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1357
846
|
updatedAt: /* @__PURE__ */ new Date()
|
|
1358
847
|
};
|
|
1359
848
|
}
|
|
1360
|
-
this.
|
|
849
|
+
this.db.resources.set(resourceId, resource);
|
|
1361
850
|
return resource;
|
|
1362
851
|
}
|
|
1363
852
|
sortThreads(threads, field, direction) {
|
|
@@ -1378,13 +867,15 @@ var InMemoryMemory = class extends MemoryStorage {
|
|
|
1378
867
|
};
|
|
1379
868
|
|
|
1380
869
|
// src/storage/domains/observability/base.ts
|
|
1381
|
-
var ObservabilityStorage = class extends
|
|
870
|
+
var ObservabilityStorage = class extends StorageDomain {
|
|
1382
871
|
constructor() {
|
|
1383
872
|
super({
|
|
1384
873
|
component: "STORAGE",
|
|
1385
874
|
name: "OBSERVABILITY"
|
|
1386
875
|
});
|
|
1387
876
|
}
|
|
877
|
+
async dangerouslyClearAll() {
|
|
878
|
+
}
|
|
1388
879
|
/**
|
|
1389
880
|
* Provides hints for tracing strategy selection by the DefaultExporter.
|
|
1390
881
|
* Storage adapters can override this to specify their preferred and supported strategies.
|
|
@@ -1399,7 +890,7 @@ var ObservabilityStorage = class extends MastraBase {
|
|
|
1399
890
|
/**
|
|
1400
891
|
* Creates a single Span record in the storage provider.
|
|
1401
892
|
*/
|
|
1402
|
-
createSpan(
|
|
893
|
+
async createSpan(_args) {
|
|
1403
894
|
throw new MastraError({
|
|
1404
895
|
id: "OBSERVABILITY_CREATE_SPAN_NOT_IMPLEMENTED",
|
|
1405
896
|
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
@@ -1410,7 +901,7 @@ var ObservabilityStorage = class extends MastraBase {
|
|
|
1410
901
|
/**
|
|
1411
902
|
* Updates a single Span with partial data. Primarily used for realtime trace creation.
|
|
1412
903
|
*/
|
|
1413
|
-
updateSpan(
|
|
904
|
+
async updateSpan(_args) {
|
|
1414
905
|
throw new MastraError({
|
|
1415
906
|
id: "OBSERVABILITY_STORAGE_UPDATE_SPAN_NOT_IMPLEMENTED",
|
|
1416
907
|
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
@@ -1418,10 +909,32 @@ var ObservabilityStorage = class extends MastraBase {
|
|
|
1418
909
|
text: "This storage provider does not support updating spans"
|
|
1419
910
|
});
|
|
1420
911
|
}
|
|
912
|
+
/**
|
|
913
|
+
* Retrieves a single span.
|
|
914
|
+
*/
|
|
915
|
+
async getSpan(_args) {
|
|
916
|
+
throw new MastraError({
|
|
917
|
+
id: "OBSERVABILITY_STORAGE_GET_SPAN_NOT_IMPLEMENTED",
|
|
918
|
+
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
919
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
920
|
+
text: "This storage provider does not support getting spans"
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Retrieves a single root span.
|
|
925
|
+
*/
|
|
926
|
+
async getRootSpan(_args) {
|
|
927
|
+
throw new MastraError({
|
|
928
|
+
id: "OBSERVABILITY_STORAGE_GET_ROOT_SPAN_NOT_IMPLEMENTED",
|
|
929
|
+
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
930
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
931
|
+
text: "This storage provider does not support getting root spans"
|
|
932
|
+
});
|
|
933
|
+
}
|
|
1421
934
|
/**
|
|
1422
935
|
* Retrieves a single trace with all its associated spans.
|
|
1423
936
|
*/
|
|
1424
|
-
getTrace(
|
|
937
|
+
async getTrace(_args) {
|
|
1425
938
|
throw new MastraError({
|
|
1426
939
|
id: "OBSERVABILITY_STORAGE_GET_TRACE_NOT_IMPLEMENTED",
|
|
1427
940
|
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
@@ -1430,20 +943,20 @@ var ObservabilityStorage = class extends MastraBase {
|
|
|
1430
943
|
});
|
|
1431
944
|
}
|
|
1432
945
|
/**
|
|
1433
|
-
* Retrieves a
|
|
946
|
+
* Retrieves a list of traces with optional filtering.
|
|
1434
947
|
*/
|
|
1435
|
-
|
|
948
|
+
async listTraces(_args) {
|
|
1436
949
|
throw new MastraError({
|
|
1437
|
-
id: "
|
|
950
|
+
id: "OBSERVABILITY_STORAGE_LIST_TRACES_NOT_IMPLEMENTED",
|
|
1438
951
|
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1439
952
|
category: "SYSTEM" /* SYSTEM */,
|
|
1440
|
-
text: "This storage provider does not support
|
|
953
|
+
text: "This storage provider does not support listing traces"
|
|
1441
954
|
});
|
|
1442
955
|
}
|
|
1443
956
|
/**
|
|
1444
957
|
* Creates multiple Spans in a single batch.
|
|
1445
958
|
*/
|
|
1446
|
-
batchCreateSpans(_args) {
|
|
959
|
+
async batchCreateSpans(_args) {
|
|
1447
960
|
throw new MastraError({
|
|
1448
961
|
id: "OBSERVABILITY_STORAGE_BATCH_CREATE_SPAN_NOT_IMPLEMENTED",
|
|
1449
962
|
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
@@ -1454,7 +967,7 @@ var ObservabilityStorage = class extends MastraBase {
|
|
|
1454
967
|
/**
|
|
1455
968
|
* Updates multiple Spans in a single batch.
|
|
1456
969
|
*/
|
|
1457
|
-
batchUpdateSpans(_args) {
|
|
970
|
+
async batchUpdateSpans(_args) {
|
|
1458
971
|
throw new MastraError({
|
|
1459
972
|
id: "OBSERVABILITY_STORAGE_BATCH_UPDATE_SPANS_NOT_IMPLEMENTED",
|
|
1460
973
|
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
@@ -1465,7 +978,7 @@ var ObservabilityStorage = class extends MastraBase {
|
|
|
1465
978
|
/**
|
|
1466
979
|
* Deletes multiple traces and all their associated spans in a single batch operation.
|
|
1467
980
|
*/
|
|
1468
|
-
batchDeleteTraces(_args) {
|
|
981
|
+
async batchDeleteTraces(_args) {
|
|
1469
982
|
throw new MastraError({
|
|
1470
983
|
id: "OBSERVABILITY_STORAGE_BATCH_DELETE_TRACES_NOT_IMPLEMENTED",
|
|
1471
984
|
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
@@ -1477,12 +990,13 @@ var ObservabilityStorage = class extends MastraBase {
|
|
|
1477
990
|
|
|
1478
991
|
// src/storage/domains/observability/inmemory.ts
|
|
1479
992
|
var ObservabilityInMemory = class extends ObservabilityStorage {
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
constructor({ collection, operations }) {
|
|
993
|
+
db;
|
|
994
|
+
constructor({ db }) {
|
|
1483
995
|
super();
|
|
1484
|
-
this.
|
|
1485
|
-
|
|
996
|
+
this.db = db;
|
|
997
|
+
}
|
|
998
|
+
async dangerouslyClearAll() {
|
|
999
|
+
this.db.traces.clear();
|
|
1486
1000
|
}
|
|
1487
1001
|
get tracingStrategy() {
|
|
1488
1002
|
return {
|
|
@@ -1490,17 +1004,27 @@ var ObservabilityInMemory = class extends ObservabilityStorage {
|
|
|
1490
1004
|
supported: ["realtime", "batch-with-updates", "insert-only"]
|
|
1491
1005
|
};
|
|
1492
1006
|
}
|
|
1493
|
-
async createSpan(
|
|
1007
|
+
async createSpan(args) {
|
|
1008
|
+
const { span } = args;
|
|
1494
1009
|
this.validateCreateSpan(span);
|
|
1495
|
-
const
|
|
1496
|
-
const record =
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1010
|
+
const now = /* @__PURE__ */ new Date();
|
|
1011
|
+
const record = {
|
|
1012
|
+
...span,
|
|
1013
|
+
createdAt: now,
|
|
1014
|
+
updatedAt: now
|
|
1015
|
+
};
|
|
1016
|
+
this.upsertSpanToTrace(record);
|
|
1500
1017
|
}
|
|
1501
1018
|
async batchCreateSpans(args) {
|
|
1502
|
-
|
|
1503
|
-
|
|
1019
|
+
const now = /* @__PURE__ */ new Date();
|
|
1020
|
+
for (const span of args.records) {
|
|
1021
|
+
this.validateCreateSpan(span);
|
|
1022
|
+
const record = {
|
|
1023
|
+
...span,
|
|
1024
|
+
createdAt: now,
|
|
1025
|
+
updatedAt: now
|
|
1026
|
+
};
|
|
1027
|
+
this.upsertSpanToTrace(record);
|
|
1504
1028
|
}
|
|
1505
1029
|
}
|
|
1506
1030
|
validateCreateSpan(record) {
|
|
@@ -1521,11 +1045,74 @@ var ObservabilityInMemory = class extends ObservabilityStorage {
|
|
|
1521
1045
|
});
|
|
1522
1046
|
}
|
|
1523
1047
|
}
|
|
1524
|
-
|
|
1525
|
-
|
|
1048
|
+
/**
|
|
1049
|
+
* Inserts or updates a span in the trace and recomputes trace-level properties
|
|
1050
|
+
*/
|
|
1051
|
+
upsertSpanToTrace(span) {
|
|
1052
|
+
const { traceId, spanId } = span;
|
|
1053
|
+
let traceEntry = this.db.traces.get(traceId);
|
|
1054
|
+
if (!traceEntry) {
|
|
1055
|
+
traceEntry = {
|
|
1056
|
+
spans: {},
|
|
1057
|
+
rootSpan: null,
|
|
1058
|
+
status: "running" /* RUNNING */,
|
|
1059
|
+
hasChildError: false
|
|
1060
|
+
};
|
|
1061
|
+
this.db.traces.set(traceId, traceEntry);
|
|
1062
|
+
}
|
|
1063
|
+
traceEntry.spans[spanId] = span;
|
|
1064
|
+
if (span.parentSpanId === null) {
|
|
1065
|
+
traceEntry.rootSpan = span;
|
|
1066
|
+
}
|
|
1067
|
+
this.recomputeTraceProperties(traceEntry);
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* Recomputes derived trace properties from all spans
|
|
1071
|
+
*/
|
|
1072
|
+
recomputeTraceProperties(traceEntry) {
|
|
1073
|
+
const spans = Object.values(traceEntry.spans);
|
|
1074
|
+
if (spans.length === 0) return;
|
|
1075
|
+
traceEntry.hasChildError = spans.some((s) => s.error != null);
|
|
1076
|
+
const rootSpan = traceEntry.rootSpan;
|
|
1077
|
+
if (rootSpan) {
|
|
1078
|
+
if (rootSpan.error != null) {
|
|
1079
|
+
traceEntry.status = "error" /* ERROR */;
|
|
1080
|
+
} else if (rootSpan.endedAt === null) {
|
|
1081
|
+
traceEntry.status = "running" /* RUNNING */;
|
|
1082
|
+
} else {
|
|
1083
|
+
traceEntry.status = "success" /* SUCCESS */;
|
|
1084
|
+
}
|
|
1085
|
+
} else {
|
|
1086
|
+
traceEntry.status = "running" /* RUNNING */;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
async getSpan(args) {
|
|
1090
|
+
const { traceId, spanId } = args;
|
|
1091
|
+
const traceEntry = this.db.traces.get(traceId);
|
|
1092
|
+
if (!traceEntry) {
|
|
1093
|
+
return null;
|
|
1094
|
+
}
|
|
1095
|
+
const span = traceEntry.spans[spanId];
|
|
1096
|
+
if (!span) {
|
|
1097
|
+
return null;
|
|
1098
|
+
}
|
|
1099
|
+
return { span };
|
|
1100
|
+
}
|
|
1101
|
+
async getRootSpan(args) {
|
|
1102
|
+
const { traceId } = args;
|
|
1103
|
+
const traceEntry = this.db.traces.get(traceId);
|
|
1104
|
+
if (!traceEntry || !traceEntry.rootSpan) {
|
|
1105
|
+
return null;
|
|
1106
|
+
}
|
|
1107
|
+
return { span: traceEntry.rootSpan };
|
|
1526
1108
|
}
|
|
1527
|
-
async getTrace(
|
|
1528
|
-
const
|
|
1109
|
+
async getTrace(args) {
|
|
1110
|
+
const { traceId } = args;
|
|
1111
|
+
const traceEntry = this.db.traces.get(traceId);
|
|
1112
|
+
if (!traceEntry) {
|
|
1113
|
+
return null;
|
|
1114
|
+
}
|
|
1115
|
+
const spans = Object.values(traceEntry.spans);
|
|
1529
1116
|
if (spans.length === 0) {
|
|
1530
1117
|
return null;
|
|
1531
1118
|
}
|
|
@@ -1535,272 +1122,233 @@ var ObservabilityInMemory = class extends ObservabilityStorage {
|
|
|
1535
1122
|
spans
|
|
1536
1123
|
};
|
|
1537
1124
|
}
|
|
1538
|
-
async
|
|
1539
|
-
filters,
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
const
|
|
1548
|
-
|
|
1549
|
-
|
|
1125
|
+
async listTraces(args) {
|
|
1126
|
+
const { filters, pagination, orderBy } = listTracesArgsSchema.parse(args);
|
|
1127
|
+
const matchingRootSpans = [];
|
|
1128
|
+
for (const [, traceEntry] of this.db.traces) {
|
|
1129
|
+
if (!traceEntry.rootSpan) continue;
|
|
1130
|
+
if (this.traceMatchesFilters(traceEntry, filters)) {
|
|
1131
|
+
matchingRootSpans.push(traceEntry.rootSpan);
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
const { field: sortField, direction: sortDirection } = orderBy;
|
|
1135
|
+
matchingRootSpans.sort((a, b) => {
|
|
1136
|
+
if (sortField === "endedAt") {
|
|
1137
|
+
const aVal = a.endedAt;
|
|
1138
|
+
const bVal = b.endedAt;
|
|
1139
|
+
if (aVal == null && bVal == null) return 0;
|
|
1140
|
+
if (aVal == null) return sortDirection === "DESC" ? -1 : 1;
|
|
1141
|
+
if (bVal == null) return sortDirection === "DESC" ? 1 : -1;
|
|
1142
|
+
const diff = aVal.getTime() - bVal.getTime();
|
|
1143
|
+
return sortDirection === "DESC" ? -diff : diff;
|
|
1144
|
+
} else {
|
|
1145
|
+
const diff = a.startedAt.getTime() - b.startedAt.getTime();
|
|
1146
|
+
return sortDirection === "DESC" ? -diff : diff;
|
|
1147
|
+
}
|
|
1148
|
+
});
|
|
1149
|
+
const total = matchingRootSpans.length;
|
|
1150
|
+
const { page, perPage } = pagination;
|
|
1550
1151
|
const start = page * perPage;
|
|
1551
1152
|
const end = start + perPage;
|
|
1552
|
-
const paged =
|
|
1153
|
+
const paged = matchingRootSpans.slice(start, end);
|
|
1553
1154
|
return {
|
|
1554
1155
|
spans: paged,
|
|
1555
1156
|
pagination: { total, page, perPage, hasMore: end < total }
|
|
1556
1157
|
};
|
|
1557
1158
|
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
if (filter?.entityType === "agent" && filter.entityId !== span.attributes?.agentId) return false;
|
|
1573
|
-
if (filter?.entityType === "workflow" && filter.entityId !== span.attributes?.workflowId) return false;
|
|
1574
|
-
return true;
|
|
1575
|
-
});
|
|
1576
|
-
}
|
|
1577
|
-
filterSpansByPagination(spans, pagination) {
|
|
1578
|
-
const page = pagination?.page ?? 0;
|
|
1579
|
-
const perPage = pagination?.perPage ?? 10;
|
|
1580
|
-
const start = page * perPage;
|
|
1581
|
-
const end = start + perPage;
|
|
1582
|
-
return spans.slice(start, end);
|
|
1583
|
-
}
|
|
1584
|
-
async updateSpan(params) {
|
|
1585
|
-
const id = this.generateId(params);
|
|
1586
|
-
const span = this.collection.get(id);
|
|
1587
|
-
if (!span) {
|
|
1588
|
-
throw new MastraError({
|
|
1589
|
-
id: "OBSERVABILITY_UPDATE_SPAN_NOT_FOUND",
|
|
1590
|
-
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1591
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
1592
|
-
text: "Span not found for update"
|
|
1593
|
-
});
|
|
1159
|
+
/**
|
|
1160
|
+
* Check if a trace matches all provided filters
|
|
1161
|
+
*/
|
|
1162
|
+
traceMatchesFilters(traceEntry, filters) {
|
|
1163
|
+
if (!filters) return true;
|
|
1164
|
+
const rootSpan = traceEntry.rootSpan;
|
|
1165
|
+
if (!rootSpan) return false;
|
|
1166
|
+
if (filters.startedAt) {
|
|
1167
|
+
if (filters.startedAt.start && rootSpan.startedAt < filters.startedAt.start) {
|
|
1168
|
+
return false;
|
|
1169
|
+
}
|
|
1170
|
+
if (filters.startedAt.end && rootSpan.startedAt > filters.startedAt.end) {
|
|
1171
|
+
return false;
|
|
1172
|
+
}
|
|
1594
1173
|
}
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1174
|
+
if (filters.endedAt) {
|
|
1175
|
+
if (rootSpan.endedAt == null) {
|
|
1176
|
+
return false;
|
|
1177
|
+
}
|
|
1178
|
+
if (filters.endedAt.start && rootSpan.endedAt < filters.endedAt.start) {
|
|
1179
|
+
return false;
|
|
1180
|
+
}
|
|
1181
|
+
if (filters.endedAt.end && rootSpan.endedAt > filters.endedAt.end) {
|
|
1182
|
+
return false;
|
|
1183
|
+
}
|
|
1600
1184
|
}
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1185
|
+
if (filters.spanType !== void 0 && rootSpan.spanType !== filters.spanType) {
|
|
1186
|
+
return false;
|
|
1187
|
+
}
|
|
1188
|
+
if (filters.entityType !== void 0 && rootSpan.entityType !== filters.entityType) {
|
|
1189
|
+
return false;
|
|
1190
|
+
}
|
|
1191
|
+
if (filters.entityId !== void 0 && rootSpan.entityId !== filters.entityId) {
|
|
1192
|
+
return false;
|
|
1193
|
+
}
|
|
1194
|
+
if (filters.entityName !== void 0 && rootSpan.entityName !== filters.entityName) {
|
|
1195
|
+
return false;
|
|
1196
|
+
}
|
|
1197
|
+
if (filters.userId !== void 0 && rootSpan.userId !== filters.userId) {
|
|
1198
|
+
return false;
|
|
1199
|
+
}
|
|
1200
|
+
if (filters.organizationId !== void 0 && rootSpan.organizationId !== filters.organizationId) {
|
|
1201
|
+
return false;
|
|
1202
|
+
}
|
|
1203
|
+
if (filters.resourceId !== void 0 && rootSpan.resourceId !== filters.resourceId) {
|
|
1204
|
+
return false;
|
|
1205
|
+
}
|
|
1206
|
+
if (filters.runId !== void 0 && rootSpan.runId !== filters.runId) {
|
|
1207
|
+
return false;
|
|
1208
|
+
}
|
|
1209
|
+
if (filters.sessionId !== void 0 && rootSpan.sessionId !== filters.sessionId) {
|
|
1210
|
+
return false;
|
|
1211
|
+
}
|
|
1212
|
+
if (filters.threadId !== void 0 && rootSpan.threadId !== filters.threadId) {
|
|
1213
|
+
return false;
|
|
1214
|
+
}
|
|
1215
|
+
if (filters.requestId !== void 0 && rootSpan.requestId !== filters.requestId) {
|
|
1216
|
+
return false;
|
|
1217
|
+
}
|
|
1218
|
+
if (filters.environment !== void 0 && rootSpan.environment !== filters.environment) {
|
|
1219
|
+
return false;
|
|
1220
|
+
}
|
|
1221
|
+
if (filters.source !== void 0 && rootSpan.source !== filters.source) {
|
|
1222
|
+
return false;
|
|
1223
|
+
}
|
|
1224
|
+
if (filters.serviceName !== void 0 && rootSpan.serviceName !== filters.serviceName) {
|
|
1225
|
+
return false;
|
|
1226
|
+
}
|
|
1227
|
+
if (filters.scope != null && rootSpan.scope != null) {
|
|
1228
|
+
for (const [key, value] of Object.entries(filters.scope)) {
|
|
1229
|
+
if (!this.jsonValueEquals(rootSpan.scope[key], value)) {
|
|
1230
|
+
return false;
|
|
1231
|
+
}
|
|
1607
1232
|
}
|
|
1233
|
+
} else if (filters.scope != null && rootSpan.scope == null) {
|
|
1234
|
+
return false;
|
|
1608
1235
|
}
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
name: "OPERATIONS"
|
|
1618
|
-
});
|
|
1619
|
-
}
|
|
1620
|
-
getSqlType(type) {
|
|
1621
|
-
switch (type) {
|
|
1622
|
-
case "text":
|
|
1623
|
-
return "TEXT";
|
|
1624
|
-
case "timestamp":
|
|
1625
|
-
return "TIMESTAMP";
|
|
1626
|
-
case "float":
|
|
1627
|
-
return "FLOAT";
|
|
1628
|
-
case "integer":
|
|
1629
|
-
return "INTEGER";
|
|
1630
|
-
case "bigint":
|
|
1631
|
-
return "BIGINT";
|
|
1632
|
-
case "jsonb":
|
|
1633
|
-
return "JSONB";
|
|
1634
|
-
default:
|
|
1635
|
-
return "TEXT";
|
|
1236
|
+
if (filters.metadata != null && rootSpan.metadata != null) {
|
|
1237
|
+
for (const [key, value] of Object.entries(filters.metadata)) {
|
|
1238
|
+
if (!this.jsonValueEquals(rootSpan.metadata[key], value)) {
|
|
1239
|
+
return false;
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
} else if (filters.metadata != null && rootSpan.metadata == null) {
|
|
1243
|
+
return false;
|
|
1636
1244
|
}
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
case "bigint":
|
|
1647
|
-
case "float":
|
|
1648
|
-
return "DEFAULT 0";
|
|
1649
|
-
case "jsonb":
|
|
1650
|
-
return "DEFAULT '{}'";
|
|
1651
|
-
default:
|
|
1652
|
-
return "DEFAULT ''";
|
|
1245
|
+
if (filters.tags != null && filters.tags.length > 0) {
|
|
1246
|
+
if (rootSpan.tags == null) {
|
|
1247
|
+
return false;
|
|
1248
|
+
}
|
|
1249
|
+
for (const tag of filters.tags) {
|
|
1250
|
+
if (!rootSpan.tags.includes(tag)) {
|
|
1251
|
+
return false;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1653
1254
|
}
|
|
1255
|
+
if (filters.status !== void 0 && traceEntry.status !== filters.status) {
|
|
1256
|
+
return false;
|
|
1257
|
+
}
|
|
1258
|
+
if (filters.hasChildError !== void 0 && traceEntry.hasChildError !== filters.hasChildError) {
|
|
1259
|
+
return false;
|
|
1260
|
+
}
|
|
1261
|
+
return true;
|
|
1654
1262
|
}
|
|
1655
1263
|
/**
|
|
1656
|
-
*
|
|
1657
|
-
* Optional methods for database index management.
|
|
1658
|
-
* Storage adapters can override these to provide index management capabilities.
|
|
1659
|
-
*/
|
|
1660
|
-
/**
|
|
1661
|
-
* Creates a database index on specified columns
|
|
1662
|
-
* @throws {MastraError} if not supported by the storage adapter
|
|
1663
|
-
*/
|
|
1664
|
-
async createIndex(_options) {
|
|
1665
|
-
throw new MastraError({
|
|
1666
|
-
id: "MASTRA_STORAGE_CREATE_INDEX_NOT_SUPPORTED",
|
|
1667
|
-
domain: "STORAGE" /* STORAGE */,
|
|
1668
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
1669
|
-
text: `Index management is not supported by this storage adapter`
|
|
1670
|
-
});
|
|
1671
|
-
}
|
|
1672
|
-
/**
|
|
1673
|
-
* Drops a database index by name
|
|
1674
|
-
* @throws {MastraError} if not supported by the storage adapter
|
|
1675
|
-
*/
|
|
1676
|
-
async dropIndex(_indexName) {
|
|
1677
|
-
throw new MastraError({
|
|
1678
|
-
id: "MASTRA_STORAGE_DROP_INDEX_NOT_SUPPORTED",
|
|
1679
|
-
domain: "STORAGE" /* STORAGE */,
|
|
1680
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
1681
|
-
text: `Index management is not supported by this storage adapter`
|
|
1682
|
-
});
|
|
1683
|
-
}
|
|
1684
|
-
/**
|
|
1685
|
-
* Lists database indexes for a table or all tables
|
|
1686
|
-
* @throws {MastraError} if not supported by the storage adapter
|
|
1687
|
-
*/
|
|
1688
|
-
async listIndexes(_tableName) {
|
|
1689
|
-
throw new MastraError({
|
|
1690
|
-
id: "MASTRA_STORAGE_LIST_INDEXES_NOT_SUPPORTED",
|
|
1691
|
-
domain: "STORAGE" /* STORAGE */,
|
|
1692
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
1693
|
-
text: `Index management is not supported by this storage adapter`
|
|
1694
|
-
});
|
|
1695
|
-
}
|
|
1696
|
-
/**
|
|
1697
|
-
* Gets detailed statistics for a specific index
|
|
1698
|
-
* @throws {MastraError} if not supported by the storage adapter
|
|
1699
|
-
*/
|
|
1700
|
-
async describeIndex(_indexName) {
|
|
1701
|
-
throw new MastraError({
|
|
1702
|
-
id: "MASTRA_STORAGE_DESCRIBE_INDEX_NOT_SUPPORTED",
|
|
1703
|
-
domain: "STORAGE" /* STORAGE */,
|
|
1704
|
-
category: "SYSTEM" /* SYSTEM */,
|
|
1705
|
-
text: `Index management is not supported by this storage adapter`
|
|
1706
|
-
});
|
|
1707
|
-
}
|
|
1708
|
-
/**
|
|
1709
|
-
* Returns definitions for automatic performance indexes
|
|
1710
|
-
* Storage adapters can override this to define indexes that should be created during initialization
|
|
1711
|
-
* @returns Array of index definitions to create automatically
|
|
1264
|
+
* Deep equality check for JSON values
|
|
1712
1265
|
*/
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
};
|
|
1717
|
-
|
|
1718
|
-
// src/storage/domains/operations/inmemory.ts
|
|
1719
|
-
var StoreOperationsInMemory = class extends StoreOperations {
|
|
1720
|
-
data;
|
|
1721
|
-
constructor() {
|
|
1722
|
-
super();
|
|
1723
|
-
this.data = {
|
|
1724
|
-
mastra_workflow_snapshot: /* @__PURE__ */ new Map(),
|
|
1725
|
-
mastra_messages: /* @__PURE__ */ new Map(),
|
|
1726
|
-
mastra_threads: /* @__PURE__ */ new Map(),
|
|
1727
|
-
mastra_traces: /* @__PURE__ */ new Map(),
|
|
1728
|
-
mastra_resources: /* @__PURE__ */ new Map(),
|
|
1729
|
-
mastra_scorers: /* @__PURE__ */ new Map(),
|
|
1730
|
-
mastra_ai_spans: /* @__PURE__ */ new Map(),
|
|
1731
|
-
mastra_agents: /* @__PURE__ */ new Map()
|
|
1732
|
-
};
|
|
1733
|
-
}
|
|
1734
|
-
getDatabase() {
|
|
1735
|
-
return this.data;
|
|
1736
|
-
}
|
|
1737
|
-
async insert({ tableName, record }) {
|
|
1738
|
-
const table = this.data[tableName];
|
|
1739
|
-
let key = record.id;
|
|
1740
|
-
if ([TABLE_WORKFLOW_SNAPSHOT].includes(tableName) && !record.id && record.run_id) {
|
|
1741
|
-
key = record.workflow_name ? `${record.workflow_name}-${record.run_id}` : record.run_id;
|
|
1742
|
-
record.id = key;
|
|
1743
|
-
} else if (!record.id) {
|
|
1744
|
-
key = `auto-${Date.now()}-${Math.random()}`;
|
|
1745
|
-
record.id = key;
|
|
1266
|
+
jsonValueEquals(a, b) {
|
|
1267
|
+
if (a === void 0 || b === void 0) {
|
|
1268
|
+
return a === b;
|
|
1746
1269
|
}
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1270
|
+
if (a === null || b === null) {
|
|
1271
|
+
return a === b;
|
|
1272
|
+
}
|
|
1273
|
+
if (typeof a !== typeof b) {
|
|
1274
|
+
return false;
|
|
1275
|
+
}
|
|
1276
|
+
if (a instanceof Date && b instanceof Date) {
|
|
1277
|
+
return a.getTime() === b.getTime();
|
|
1278
|
+
}
|
|
1279
|
+
if (a instanceof Date || b instanceof Date) {
|
|
1280
|
+
return false;
|
|
1281
|
+
}
|
|
1282
|
+
if (typeof a === "object") {
|
|
1283
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
1284
|
+
if (a.length !== b.length) return false;
|
|
1285
|
+
return a.every((val, i) => this.jsonValueEquals(val, b[i]));
|
|
1759
1286
|
}
|
|
1760
|
-
|
|
1287
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
1288
|
+
return false;
|
|
1289
|
+
}
|
|
1290
|
+
const aKeys = Object.keys(a);
|
|
1291
|
+
const bKeys = Object.keys(b);
|
|
1292
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
1293
|
+
return aKeys.every(
|
|
1294
|
+
(key) => this.jsonValueEquals(a[key], b[key])
|
|
1295
|
+
);
|
|
1761
1296
|
}
|
|
1297
|
+
return a === b;
|
|
1762
1298
|
}
|
|
1763
|
-
async
|
|
1764
|
-
|
|
1765
|
-
const
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1299
|
+
async updateSpan(args) {
|
|
1300
|
+
const { traceId, spanId, updates } = args;
|
|
1301
|
+
const traceEntry = this.db.traces.get(traceId);
|
|
1302
|
+
if (!traceEntry) {
|
|
1303
|
+
throw new MastraError({
|
|
1304
|
+
id: "OBSERVABILITY_UPDATE_SPAN_NOT_FOUND",
|
|
1305
|
+
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1306
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1307
|
+
text: "Trace not found for span update"
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
const span = traceEntry.spans[spanId];
|
|
1311
|
+
if (!span) {
|
|
1312
|
+
throw new MastraError({
|
|
1313
|
+
id: "OBSERVABILITY_UPDATE_SPAN_NOT_FOUND",
|
|
1314
|
+
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1315
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1316
|
+
text: "Span not found for update"
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
const updatedSpan = {
|
|
1320
|
+
...span,
|
|
1321
|
+
...updates,
|
|
1322
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1323
|
+
};
|
|
1324
|
+
traceEntry.spans[spanId] = updatedSpan;
|
|
1325
|
+
if (updatedSpan.parentSpanId === null) {
|
|
1326
|
+
traceEntry.rootSpan = updatedSpan;
|
|
1327
|
+
}
|
|
1328
|
+
this.recomputeTraceProperties(traceEntry);
|
|
1783
1329
|
}
|
|
1784
|
-
async
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
this.logger.debug(`MockStore: alterTable called for ${tableName} with schema`, schema);
|
|
1330
|
+
async batchUpdateSpans(args) {
|
|
1331
|
+
for (const record of args.records) {
|
|
1332
|
+
await this.updateSpan(record);
|
|
1333
|
+
}
|
|
1789
1334
|
}
|
|
1790
|
-
async
|
|
1791
|
-
|
|
1792
|
-
|
|
1335
|
+
async batchDeleteTraces(args) {
|
|
1336
|
+
for (const traceId of args.traceIds) {
|
|
1337
|
+
this.db.traces.delete(traceId);
|
|
1338
|
+
}
|
|
1793
1339
|
}
|
|
1794
1340
|
};
|
|
1795
1341
|
|
|
1796
1342
|
// src/storage/domains/scores/base.ts
|
|
1797
|
-
var ScoresStorage = class extends
|
|
1343
|
+
var ScoresStorage = class extends StorageDomain {
|
|
1798
1344
|
constructor() {
|
|
1799
1345
|
super({
|
|
1800
1346
|
component: "STORAGE",
|
|
1801
1347
|
name: "SCORES"
|
|
1802
1348
|
});
|
|
1803
1349
|
}
|
|
1350
|
+
async dangerouslyClearAll() {
|
|
1351
|
+
}
|
|
1804
1352
|
async listScoresBySpan({
|
|
1805
1353
|
traceId,
|
|
1806
1354
|
spanId,
|
|
@@ -1817,17 +1365,20 @@ var ScoresStorage = class extends MastraBase {
|
|
|
1817
1365
|
|
|
1818
1366
|
// src/storage/domains/scores/inmemory.ts
|
|
1819
1367
|
var ScoresInMemory = class extends ScoresStorage {
|
|
1820
|
-
|
|
1821
|
-
constructor({
|
|
1368
|
+
db;
|
|
1369
|
+
constructor({ db }) {
|
|
1822
1370
|
super();
|
|
1823
|
-
this.
|
|
1371
|
+
this.db = db;
|
|
1372
|
+
}
|
|
1373
|
+
async dangerouslyClearAll() {
|
|
1374
|
+
this.db.scores.clear();
|
|
1824
1375
|
}
|
|
1825
1376
|
async getScoreById({ id }) {
|
|
1826
|
-
return this.scores.get(id) ?? null;
|
|
1377
|
+
return this.db.scores.get(id) ?? null;
|
|
1827
1378
|
}
|
|
1828
1379
|
async saveScore(score) {
|
|
1829
1380
|
const newScore = { id: crypto.randomUUID(), createdAt: /* @__PURE__ */ new Date(), updatedAt: /* @__PURE__ */ new Date(), ...score };
|
|
1830
|
-
this.scores.set(newScore.id, newScore);
|
|
1381
|
+
this.db.scores.set(newScore.id, newScore);
|
|
1831
1382
|
return { score: newScore };
|
|
1832
1383
|
}
|
|
1833
1384
|
async listScoresByScorerId({
|
|
@@ -1837,7 +1388,7 @@ var ScoresInMemory = class extends ScoresStorage {
|
|
|
1837
1388
|
entityType,
|
|
1838
1389
|
source
|
|
1839
1390
|
}) {
|
|
1840
|
-
const scores = Array.from(this.scores.values()).filter((score) => {
|
|
1391
|
+
const scores = Array.from(this.db.scores.values()).filter((score) => {
|
|
1841
1392
|
let baseFilter = score.scorerId === scorerId;
|
|
1842
1393
|
if (entityId) {
|
|
1843
1394
|
baseFilter = baseFilter && score.entityId === entityId;
|
|
@@ -1868,7 +1419,7 @@ var ScoresInMemory = class extends ScoresStorage {
|
|
|
1868
1419
|
runId,
|
|
1869
1420
|
pagination
|
|
1870
1421
|
}) {
|
|
1871
|
-
const scores = Array.from(this.scores.values()).filter((score) => score.runId === runId);
|
|
1422
|
+
const scores = Array.from(this.db.scores.values()).filter((score) => score.runId === runId);
|
|
1872
1423
|
const { page, perPage: perPageInput } = pagination;
|
|
1873
1424
|
const perPage = normalizePerPage(perPageInput, Number.MAX_SAFE_INTEGER);
|
|
1874
1425
|
const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
@@ -1888,7 +1439,7 @@ var ScoresInMemory = class extends ScoresStorage {
|
|
|
1888
1439
|
entityType,
|
|
1889
1440
|
pagination
|
|
1890
1441
|
}) {
|
|
1891
|
-
const scores = Array.from(this.scores.values()).filter((score) => {
|
|
1442
|
+
const scores = Array.from(this.db.scores.values()).filter((score) => {
|
|
1892
1443
|
const baseFilter = score.entityId === entityId && score.entityType === entityType;
|
|
1893
1444
|
return baseFilter;
|
|
1894
1445
|
});
|
|
@@ -1911,7 +1462,7 @@ var ScoresInMemory = class extends ScoresStorage {
|
|
|
1911
1462
|
spanId,
|
|
1912
1463
|
pagination
|
|
1913
1464
|
}) {
|
|
1914
|
-
const scores = Array.from(this.scores.values()).filter(
|
|
1465
|
+
const scores = Array.from(this.db.scores.values()).filter(
|
|
1915
1466
|
(score) => score.traceId === traceId && score.spanId === spanId
|
|
1916
1467
|
);
|
|
1917
1468
|
scores.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
|
@@ -1932,7 +1483,7 @@ var ScoresInMemory = class extends ScoresStorage {
|
|
|
1932
1483
|
};
|
|
1933
1484
|
|
|
1934
1485
|
// src/storage/domains/workflows/base.ts
|
|
1935
|
-
var WorkflowsStorage = class extends
|
|
1486
|
+
var WorkflowsStorage = class extends StorageDomain {
|
|
1936
1487
|
constructor() {
|
|
1937
1488
|
super({
|
|
1938
1489
|
component: "STORAGE",
|
|
@@ -1943,12 +1494,16 @@ var WorkflowsStorage = class extends MastraBase {
|
|
|
1943
1494
|
|
|
1944
1495
|
// src/storage/domains/workflows/inmemory.ts
|
|
1945
1496
|
var WorkflowsInMemory = class extends WorkflowsStorage {
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
constructor({ collection, operations }) {
|
|
1497
|
+
db;
|
|
1498
|
+
constructor({ db }) {
|
|
1949
1499
|
super();
|
|
1950
|
-
this.
|
|
1951
|
-
|
|
1500
|
+
this.db = db;
|
|
1501
|
+
}
|
|
1502
|
+
async dangerouslyClearAll() {
|
|
1503
|
+
this.db.workflows.clear();
|
|
1504
|
+
}
|
|
1505
|
+
getWorkflowKey(workflowName, runId) {
|
|
1506
|
+
return `${workflowName}-${runId}`;
|
|
1952
1507
|
}
|
|
1953
1508
|
async updateWorkflowResults({
|
|
1954
1509
|
workflowName,
|
|
@@ -1957,8 +1512,9 @@ var WorkflowsInMemory = class extends WorkflowsStorage {
|
|
|
1957
1512
|
result,
|
|
1958
1513
|
requestContext
|
|
1959
1514
|
}) {
|
|
1960
|
-
this.logger.debug(`
|
|
1961
|
-
const
|
|
1515
|
+
this.logger.debug(`WorkflowsInMemory: updateWorkflowResults called for ${workflowName} ${runId} ${stepId}`, result);
|
|
1516
|
+
const key = this.getWorkflowKey(workflowName, runId);
|
|
1517
|
+
const run = this.db.workflows.get(key);
|
|
1962
1518
|
if (!run) {
|
|
1963
1519
|
return {};
|
|
1964
1520
|
}
|
|
@@ -1977,18 +1533,19 @@ var WorkflowsInMemory = class extends WorkflowsStorage {
|
|
|
1977
1533
|
status: "pending",
|
|
1978
1534
|
runId: run.run_id
|
|
1979
1535
|
};
|
|
1980
|
-
this.
|
|
1536
|
+
this.db.workflows.set(key, {
|
|
1981
1537
|
...run,
|
|
1982
1538
|
snapshot
|
|
1983
1539
|
});
|
|
1540
|
+
} else {
|
|
1541
|
+
snapshot = typeof run.snapshot === "string" ? JSON.parse(run.snapshot) : run.snapshot;
|
|
1984
1542
|
}
|
|
1985
|
-
snapshot = typeof run.snapshot === "string" ? JSON.parse(run.snapshot) : run.snapshot;
|
|
1986
1543
|
if (!snapshot || !snapshot?.context) {
|
|
1987
1544
|
throw new Error(`Snapshot not found for runId ${runId}`);
|
|
1988
1545
|
}
|
|
1989
1546
|
snapshot.context[stepId] = result;
|
|
1990
1547
|
snapshot.requestContext = { ...snapshot.requestContext, ...requestContext };
|
|
1991
|
-
this.
|
|
1548
|
+
this.db.workflows.set(key, {
|
|
1992
1549
|
...run,
|
|
1993
1550
|
snapshot
|
|
1994
1551
|
});
|
|
@@ -1999,7 +1556,8 @@ var WorkflowsInMemory = class extends WorkflowsStorage {
|
|
|
1999
1556
|
runId,
|
|
2000
1557
|
opts
|
|
2001
1558
|
}) {
|
|
2002
|
-
const
|
|
1559
|
+
const key = this.getWorkflowKey(workflowName, runId);
|
|
1560
|
+
const run = this.db.workflows.get(key);
|
|
2003
1561
|
if (!run) {
|
|
2004
1562
|
return;
|
|
2005
1563
|
}
|
|
@@ -2018,7 +1576,7 @@ var WorkflowsInMemory = class extends WorkflowsStorage {
|
|
|
2018
1576
|
status: "pending",
|
|
2019
1577
|
runId: run.run_id
|
|
2020
1578
|
};
|
|
2021
|
-
this.
|
|
1579
|
+
this.db.workflows.set(key, {
|
|
2022
1580
|
...run,
|
|
2023
1581
|
snapshot
|
|
2024
1582
|
});
|
|
@@ -2029,7 +1587,7 @@ var WorkflowsInMemory = class extends WorkflowsStorage {
|
|
|
2029
1587
|
throw new Error(`Snapshot not found for runId ${runId}`);
|
|
2030
1588
|
}
|
|
2031
1589
|
snapshot = { ...snapshot, ...opts };
|
|
2032
|
-
this.
|
|
1590
|
+
this.db.workflows.set(key, {
|
|
2033
1591
|
...run,
|
|
2034
1592
|
snapshot
|
|
2035
1593
|
});
|
|
@@ -2039,31 +1597,34 @@ var WorkflowsInMemory = class extends WorkflowsStorage {
|
|
|
2039
1597
|
workflowName,
|
|
2040
1598
|
runId,
|
|
2041
1599
|
resourceId,
|
|
2042
|
-
snapshot
|
|
1600
|
+
snapshot,
|
|
1601
|
+
createdAt,
|
|
1602
|
+
updatedAt
|
|
2043
1603
|
}) {
|
|
1604
|
+
const key = this.getWorkflowKey(workflowName, runId);
|
|
1605
|
+
const now = /* @__PURE__ */ new Date();
|
|
2044
1606
|
const data = {
|
|
2045
1607
|
workflow_name: workflowName,
|
|
2046
1608
|
run_id: runId,
|
|
2047
1609
|
resourceId,
|
|
2048
1610
|
snapshot,
|
|
2049
|
-
createdAt:
|
|
2050
|
-
updatedAt:
|
|
1611
|
+
createdAt: createdAt ?? now,
|
|
1612
|
+
updatedAt: updatedAt ?? now
|
|
2051
1613
|
};
|
|
2052
|
-
|
|
2053
|
-
tableName: TABLE_WORKFLOW_SNAPSHOT,
|
|
2054
|
-
record: data
|
|
2055
|
-
});
|
|
1614
|
+
this.db.workflows.set(key, data);
|
|
2056
1615
|
}
|
|
2057
1616
|
async loadWorkflowSnapshot({
|
|
2058
1617
|
workflowName,
|
|
2059
1618
|
runId
|
|
2060
1619
|
}) {
|
|
2061
1620
|
this.logger.debug("Loading workflow snapshot", { workflowName, runId });
|
|
2062
|
-
const
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
1621
|
+
const key = this.getWorkflowKey(workflowName, runId);
|
|
1622
|
+
const run = this.db.workflows.get(key);
|
|
1623
|
+
if (!run) {
|
|
1624
|
+
return null;
|
|
1625
|
+
}
|
|
1626
|
+
const snapshot = typeof run.snapshot === "string" ? JSON.parse(run.snapshot) : run.snapshot;
|
|
1627
|
+
return snapshot ? JSON.parse(JSON.stringify(snapshot)) : null;
|
|
2067
1628
|
}
|
|
2068
1629
|
async listWorkflowRuns({
|
|
2069
1630
|
workflowName,
|
|
@@ -2077,7 +1638,7 @@ var WorkflowsInMemory = class extends WorkflowsStorage {
|
|
|
2077
1638
|
if (page !== void 0 && page < 0) {
|
|
2078
1639
|
throw new Error("page must be >= 0");
|
|
2079
1640
|
}
|
|
2080
|
-
let runs = Array.from(this.
|
|
1641
|
+
let runs = Array.from(this.db.workflows.values());
|
|
2081
1642
|
if (workflowName) runs = runs.filter((run) => run.workflow_name === workflowName);
|
|
2082
1643
|
if (status) {
|
|
2083
1644
|
runs = runs.filter((run) => {
|
|
@@ -2131,7 +1692,7 @@ var WorkflowsInMemory = class extends WorkflowsStorage {
|
|
|
2131
1692
|
runId,
|
|
2132
1693
|
workflowName
|
|
2133
1694
|
}) {
|
|
2134
|
-
const runs = Array.from(this.
|
|
1695
|
+
const runs = Array.from(this.db.workflows.values()).filter((r) => r.run_id === runId);
|
|
2135
1696
|
let run = runs.find((r) => r.workflow_name === workflowName);
|
|
2136
1697
|
if (!run) return null;
|
|
2137
1698
|
const parsedRun = {
|
|
@@ -2146,227 +1707,227 @@ var WorkflowsInMemory = class extends WorkflowsStorage {
|
|
|
2146
1707
|
return parsedRun;
|
|
2147
1708
|
}
|
|
2148
1709
|
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
2149
|
-
this.
|
|
1710
|
+
const key = this.getWorkflowKey(workflowName, runId);
|
|
1711
|
+
this.db.workflows.delete(key);
|
|
2150
1712
|
}
|
|
2151
1713
|
};
|
|
2152
1714
|
|
|
2153
1715
|
// src/storage/mock.ts
|
|
2154
1716
|
var InMemoryStore = class extends MastraStorage {
|
|
2155
1717
|
stores;
|
|
1718
|
+
/**
|
|
1719
|
+
* Internal database layer shared across all domains.
|
|
1720
|
+
* This is an implementation detail - domains interact with this
|
|
1721
|
+
* rather than managing their own data structures.
|
|
1722
|
+
*/
|
|
1723
|
+
#db;
|
|
2156
1724
|
constructor({ id = "in-memory" } = {}) {
|
|
2157
1725
|
super({ id, name: "InMemoryStorage" });
|
|
2158
1726
|
this.hasInitialized = Promise.resolve(true);
|
|
2159
|
-
|
|
2160
|
-
const database = operationsStorage.getDatabase();
|
|
2161
|
-
const scoresStorage = new ScoresInMemory({
|
|
2162
|
-
collection: database.mastra_scorers
|
|
2163
|
-
});
|
|
2164
|
-
const workflowsStorage = new WorkflowsInMemory({
|
|
2165
|
-
collection: database.mastra_workflow_snapshot,
|
|
2166
|
-
operations: operationsStorage
|
|
2167
|
-
});
|
|
2168
|
-
const memoryStorage = new InMemoryMemory({
|
|
2169
|
-
collection: {
|
|
2170
|
-
threads: database.mastra_threads,
|
|
2171
|
-
resources: database.mastra_resources,
|
|
2172
|
-
messages: database.mastra_messages
|
|
2173
|
-
},
|
|
2174
|
-
operations: operationsStorage
|
|
2175
|
-
});
|
|
2176
|
-
const observabilityStorage = new ObservabilityInMemory({
|
|
2177
|
-
collection: database.mastra_ai_spans,
|
|
2178
|
-
operations: operationsStorage
|
|
2179
|
-
});
|
|
2180
|
-
const agentsCollection = /* @__PURE__ */ new Map();
|
|
2181
|
-
const agentsStorage = new InMemoryAgentsStorage({
|
|
2182
|
-
collection: agentsCollection
|
|
2183
|
-
});
|
|
1727
|
+
this.#db = new InMemoryDB();
|
|
2184
1728
|
this.stores = {
|
|
2185
|
-
|
|
2186
|
-
workflows:
|
|
2187
|
-
scores:
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
agents: agentsStorage
|
|
2191
|
-
};
|
|
2192
|
-
}
|
|
2193
|
-
get supports() {
|
|
2194
|
-
return {
|
|
2195
|
-
selectByIncludeResourceScope: false,
|
|
2196
|
-
resourceWorkingMemory: false,
|
|
2197
|
-
hasColumn: false,
|
|
2198
|
-
createTable: false,
|
|
2199
|
-
deleteMessages: true,
|
|
2200
|
-
observabilityInstance: true,
|
|
2201
|
-
indexManagement: false,
|
|
2202
|
-
listScoresBySpan: true,
|
|
2203
|
-
agents: true
|
|
1729
|
+
memory: new InMemoryMemory({ db: this.#db }),
|
|
1730
|
+
workflows: new WorkflowsInMemory({ db: this.#db }),
|
|
1731
|
+
scores: new ScoresInMemory({ db: this.#db }),
|
|
1732
|
+
observability: new ObservabilityInMemory({ db: this.#db }),
|
|
1733
|
+
agents: new InMemoryAgentsStorage({ db: this.#db })
|
|
2204
1734
|
};
|
|
2205
1735
|
}
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
}
|
|
2214
|
-
async loadWorkflowSnapshot({
|
|
2215
|
-
workflowName,
|
|
2216
|
-
runId
|
|
2217
|
-
}) {
|
|
2218
|
-
return this.stores.workflows.loadWorkflowSnapshot({ workflowName, runId });
|
|
2219
|
-
}
|
|
2220
|
-
async createTable({
|
|
2221
|
-
tableName,
|
|
2222
|
-
schema
|
|
2223
|
-
}) {
|
|
2224
|
-
await this.stores.operations.createTable({ tableName, schema });
|
|
2225
|
-
}
|
|
2226
|
-
async alterTable({
|
|
2227
|
-
tableName,
|
|
2228
|
-
schema,
|
|
2229
|
-
ifNotExists
|
|
2230
|
-
}) {
|
|
2231
|
-
await this.stores.operations.alterTable({ tableName, schema, ifNotExists });
|
|
2232
|
-
}
|
|
2233
|
-
async clearTable({ tableName }) {
|
|
2234
|
-
await this.stores.operations.clearTable({ tableName });
|
|
2235
|
-
}
|
|
2236
|
-
async dropTable({ tableName }) {
|
|
2237
|
-
await this.stores.operations.dropTable({ tableName });
|
|
2238
|
-
}
|
|
2239
|
-
async insert({ tableName, record }) {
|
|
2240
|
-
await this.stores.operations.insert({ tableName, record });
|
|
2241
|
-
}
|
|
2242
|
-
async updateWorkflowResults({
|
|
2243
|
-
workflowName,
|
|
2244
|
-
runId,
|
|
2245
|
-
stepId,
|
|
2246
|
-
result,
|
|
2247
|
-
requestContext
|
|
2248
|
-
}) {
|
|
2249
|
-
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, requestContext });
|
|
2250
|
-
}
|
|
2251
|
-
async updateWorkflowState({
|
|
2252
|
-
workflowName,
|
|
2253
|
-
runId,
|
|
2254
|
-
opts
|
|
2255
|
-
}) {
|
|
2256
|
-
return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
|
|
2257
|
-
}
|
|
2258
|
-
async batchInsert({ tableName, records }) {
|
|
2259
|
-
await this.stores.operations.batchInsert({ tableName, records });
|
|
2260
|
-
}
|
|
2261
|
-
async load({ tableName, keys }) {
|
|
2262
|
-
return this.stores.operations.load({ tableName, keys });
|
|
2263
|
-
}
|
|
2264
|
-
async getThreadById({ threadId }) {
|
|
2265
|
-
return this.stores.memory.getThreadById({ threadId });
|
|
1736
|
+
/**
|
|
1737
|
+
* Clears all data from the in-memory database.
|
|
1738
|
+
* Useful for testing.
|
|
1739
|
+
* @deprecated Use dangerouslyClearAll() on individual domains instead.
|
|
1740
|
+
*/
|
|
1741
|
+
clear() {
|
|
1742
|
+
this.#db.clear();
|
|
2266
1743
|
}
|
|
2267
|
-
|
|
2268
|
-
|
|
1744
|
+
};
|
|
1745
|
+
var MockStore = InMemoryStore;
|
|
1746
|
+
|
|
1747
|
+
// src/storage/domains/operations/base.ts
|
|
1748
|
+
var StoreOperations = class extends MastraBase {
|
|
1749
|
+
constructor() {
|
|
1750
|
+
super({
|
|
1751
|
+
component: "STORAGE",
|
|
1752
|
+
name: "OPERATIONS"
|
|
1753
|
+
});
|
|
2269
1754
|
}
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
1755
|
+
getSqlType(type) {
|
|
1756
|
+
switch (type) {
|
|
1757
|
+
case "text":
|
|
1758
|
+
return "TEXT";
|
|
1759
|
+
case "timestamp":
|
|
1760
|
+
return "TIMESTAMP";
|
|
1761
|
+
case "float":
|
|
1762
|
+
return "FLOAT";
|
|
1763
|
+
case "integer":
|
|
1764
|
+
return "INTEGER";
|
|
1765
|
+
case "bigint":
|
|
1766
|
+
return "BIGINT";
|
|
1767
|
+
case "jsonb":
|
|
1768
|
+
return "JSONB";
|
|
1769
|
+
default:
|
|
1770
|
+
return "TEXT";
|
|
1771
|
+
}
|
|
2276
1772
|
}
|
|
2277
|
-
|
|
2278
|
-
|
|
1773
|
+
getDefaultValue(type) {
|
|
1774
|
+
switch (type) {
|
|
1775
|
+
case "text":
|
|
1776
|
+
case "uuid":
|
|
1777
|
+
return "DEFAULT ''";
|
|
1778
|
+
case "timestamp":
|
|
1779
|
+
return "DEFAULT '1970-01-01 00:00:00'";
|
|
1780
|
+
case "integer":
|
|
1781
|
+
case "bigint":
|
|
1782
|
+
case "float":
|
|
1783
|
+
return "DEFAULT 0";
|
|
1784
|
+
case "jsonb":
|
|
1785
|
+
return "DEFAULT '{}'";
|
|
1786
|
+
default:
|
|
1787
|
+
return "DEFAULT ''";
|
|
1788
|
+
}
|
|
2279
1789
|
}
|
|
2280
|
-
|
|
2281
|
-
|
|
1790
|
+
/**
|
|
1791
|
+
* DATABASE INDEX MANAGEMENT
|
|
1792
|
+
* Optional methods for database index management.
|
|
1793
|
+
* Storage adapters can override these to provide index management capabilities.
|
|
1794
|
+
*/
|
|
1795
|
+
/**
|
|
1796
|
+
* Creates a database index on specified columns
|
|
1797
|
+
* @throws {MastraError} if not supported by the storage adapter
|
|
1798
|
+
*/
|
|
1799
|
+
async createIndex(_options) {
|
|
1800
|
+
throw new MastraError({
|
|
1801
|
+
id: "MASTRA_STORAGE_CREATE_INDEX_NOT_SUPPORTED",
|
|
1802
|
+
domain: "STORAGE" /* STORAGE */,
|
|
1803
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1804
|
+
text: `Index management is not supported by this storage adapter`
|
|
1805
|
+
});
|
|
2282
1806
|
}
|
|
2283
|
-
|
|
2284
|
-
|
|
1807
|
+
/**
|
|
1808
|
+
* Drops a database index by name
|
|
1809
|
+
* @throws {MastraError} if not supported by the storage adapter
|
|
1810
|
+
*/
|
|
1811
|
+
async dropIndex(_indexName) {
|
|
1812
|
+
throw new MastraError({
|
|
1813
|
+
id: "MASTRA_STORAGE_DROP_INDEX_NOT_SUPPORTED",
|
|
1814
|
+
domain: "STORAGE" /* STORAGE */,
|
|
1815
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1816
|
+
text: `Index management is not supported by this storage adapter`
|
|
1817
|
+
});
|
|
2285
1818
|
}
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
1819
|
+
/**
|
|
1820
|
+
* Lists database indexes for a table or all tables
|
|
1821
|
+
* @throws {MastraError} if not supported by the storage adapter
|
|
1822
|
+
*/
|
|
1823
|
+
async listIndexes(_tableName) {
|
|
1824
|
+
throw new MastraError({
|
|
1825
|
+
id: "MASTRA_STORAGE_LIST_INDEXES_NOT_SUPPORTED",
|
|
1826
|
+
domain: "STORAGE" /* STORAGE */,
|
|
1827
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1828
|
+
text: `Index management is not supported by this storage adapter`
|
|
1829
|
+
});
|
|
2292
1830
|
}
|
|
2293
|
-
|
|
2294
|
-
|
|
1831
|
+
/**
|
|
1832
|
+
* Gets detailed statistics for a specific index
|
|
1833
|
+
* @throws {MastraError} if not supported by the storage adapter
|
|
1834
|
+
*/
|
|
1835
|
+
async describeIndex(_indexName) {
|
|
1836
|
+
throw new MastraError({
|
|
1837
|
+
id: "MASTRA_STORAGE_DESCRIBE_INDEX_NOT_SUPPORTED",
|
|
1838
|
+
domain: "STORAGE" /* STORAGE */,
|
|
1839
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
1840
|
+
text: `Index management is not supported by this storage adapter`
|
|
1841
|
+
});
|
|
2295
1842
|
}
|
|
2296
|
-
|
|
2297
|
-
|
|
1843
|
+
/**
|
|
1844
|
+
* Returns definitions for automatic performance indexes
|
|
1845
|
+
* Storage adapters can override this to define indexes that should be created during initialization
|
|
1846
|
+
* @returns Array of index definitions to create automatically
|
|
1847
|
+
*/
|
|
1848
|
+
getAutomaticIndexDefinitions() {
|
|
1849
|
+
return [];
|
|
2298
1850
|
}
|
|
2299
|
-
|
|
2300
|
-
|
|
1851
|
+
};
|
|
1852
|
+
|
|
1853
|
+
// src/storage/domains/operations/inmemory.ts
|
|
1854
|
+
var StoreOperationsInMemory = class extends StoreOperations {
|
|
1855
|
+
data;
|
|
1856
|
+
constructor() {
|
|
1857
|
+
super();
|
|
1858
|
+
this.data = {
|
|
1859
|
+
mastra_workflow_snapshot: /* @__PURE__ */ new Map(),
|
|
1860
|
+
mastra_messages: /* @__PURE__ */ new Map(),
|
|
1861
|
+
mastra_threads: /* @__PURE__ */ new Map(),
|
|
1862
|
+
mastra_traces: /* @__PURE__ */ new Map(),
|
|
1863
|
+
mastra_resources: /* @__PURE__ */ new Map(),
|
|
1864
|
+
mastra_scorers: /* @__PURE__ */ new Map(),
|
|
1865
|
+
mastra_ai_spans: /* @__PURE__ */ new Map(),
|
|
1866
|
+
mastra_agents: /* @__PURE__ */ new Map()
|
|
1867
|
+
};
|
|
2301
1868
|
}
|
|
2302
|
-
|
|
2303
|
-
return this.
|
|
1869
|
+
getDatabase() {
|
|
1870
|
+
return this.data;
|
|
2304
1871
|
}
|
|
2305
|
-
async
|
|
2306
|
-
|
|
1872
|
+
async insert({ tableName, record }) {
|
|
1873
|
+
const table = this.data[tableName];
|
|
1874
|
+
let key = record.id;
|
|
1875
|
+
if ([TABLE_WORKFLOW_SNAPSHOT].includes(tableName) && !record.id && record.run_id) {
|
|
1876
|
+
key = record.workflow_name ? `${record.workflow_name}-${record.run_id}` : record.run_id;
|
|
1877
|
+
record.id = key;
|
|
1878
|
+
} else if (!record.id) {
|
|
1879
|
+
key = `auto-${Date.now()}-${Math.random()}`;
|
|
1880
|
+
record.id = key;
|
|
1881
|
+
}
|
|
1882
|
+
table.set(key, record);
|
|
2307
1883
|
}
|
|
2308
|
-
async
|
|
2309
|
-
|
|
1884
|
+
async batchInsert({ tableName, records }) {
|
|
1885
|
+
const table = this.data[tableName];
|
|
1886
|
+
for (const record of records) {
|
|
1887
|
+
let key = record.id;
|
|
1888
|
+
if ([TABLE_WORKFLOW_SNAPSHOT].includes(tableName) && !record.id && record.run_id) {
|
|
1889
|
+
key = record.run_id;
|
|
1890
|
+
record.id = key;
|
|
1891
|
+
} else if (!record.id) {
|
|
1892
|
+
key = `auto-${Date.now()}-${Math.random()}`;
|
|
1893
|
+
record.id = key;
|
|
1894
|
+
}
|
|
1895
|
+
table.set(key, record);
|
|
1896
|
+
}
|
|
2310
1897
|
}
|
|
2311
|
-
async
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
pagination
|
|
2317
|
-
}) {
|
|
2318
|
-
return this.stores.scores.listScoresByScorerId({ scorerId, entityId, entityType, source, pagination });
|
|
1898
|
+
async load({ tableName, keys }) {
|
|
1899
|
+
this.logger.debug(`MockStore: load called for ${tableName} with keys`, keys);
|
|
1900
|
+
const table = this.data[tableName];
|
|
1901
|
+
const records = Array.from(table.values());
|
|
1902
|
+
return records.filter((record) => Object.keys(keys).every((key) => record[key] === keys[key]))?.[0];
|
|
2319
1903
|
}
|
|
2320
|
-
async
|
|
2321
|
-
|
|
2322
|
-
|
|
1904
|
+
async createTable({
|
|
1905
|
+
tableName,
|
|
1906
|
+
schema
|
|
2323
1907
|
}) {
|
|
2324
|
-
|
|
1908
|
+
this.logger.debug(`MockStore: createTable called for ${tableName} with schema`, schema);
|
|
1909
|
+
this.data[tableName] = /* @__PURE__ */ new Map();
|
|
2325
1910
|
}
|
|
2326
|
-
async
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
pagination
|
|
2330
|
-
}) {
|
|
2331
|
-
return this.stores.scores.listScoresByEntityId({ entityId, entityType, pagination });
|
|
1911
|
+
async clearTable({ tableName }) {
|
|
1912
|
+
this.logger.debug(`MockStore: clearTable called for ${tableName}`);
|
|
1913
|
+
this.data[tableName].clear();
|
|
2332
1914
|
}
|
|
2333
|
-
async
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
pagination
|
|
2337
|
-
}) {
|
|
2338
|
-
return this.stores.scores.listScoresBySpan({ traceId, spanId, pagination });
|
|
1915
|
+
async dropTable({ tableName }) {
|
|
1916
|
+
this.logger.debug(`MockStore: dropTable called for ${tableName}`);
|
|
1917
|
+
this.data[tableName].clear();
|
|
2339
1918
|
}
|
|
2340
|
-
async
|
|
2341
|
-
|
|
2342
|
-
|
|
1919
|
+
async alterTable({
|
|
1920
|
+
tableName,
|
|
1921
|
+
schema
|
|
2343
1922
|
}) {
|
|
2344
|
-
|
|
2345
|
-
}
|
|
2346
|
-
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
2347
|
-
return this.stores.workflows.deleteWorkflowRunById({ runId, workflowName });
|
|
2348
|
-
}
|
|
2349
|
-
async createSpan(span) {
|
|
2350
|
-
return this.stores.observability.createSpan(span);
|
|
2351
|
-
}
|
|
2352
|
-
async updateSpan(params) {
|
|
2353
|
-
return this.stores.observability.updateSpan(params);
|
|
2354
|
-
}
|
|
2355
|
-
async getTrace(traceId) {
|
|
2356
|
-
return this.stores.observability.getTrace(traceId);
|
|
2357
|
-
}
|
|
2358
|
-
async batchCreateSpans(args) {
|
|
2359
|
-
return this.stores.observability.batchCreateSpans(args);
|
|
2360
|
-
}
|
|
2361
|
-
async batchUpdateSpans(args) {
|
|
2362
|
-
return this.stores.observability.batchUpdateSpans(args);
|
|
1923
|
+
this.logger.debug(`MockStore: alterTable called for ${tableName} with schema`, schema);
|
|
2363
1924
|
}
|
|
2364
|
-
async
|
|
2365
|
-
|
|
1925
|
+
async hasColumn(table, column) {
|
|
1926
|
+
this.logger.debug(`MockStore: hasColumn called for ${table} with column ${column}`);
|
|
1927
|
+
return true;
|
|
2366
1928
|
}
|
|
2367
1929
|
};
|
|
2368
|
-
var MockStore = InMemoryStore;
|
|
2369
1930
|
|
|
2370
|
-
export {
|
|
2371
|
-
//# sourceMappingURL=chunk-
|
|
2372
|
-
//# sourceMappingURL=chunk-
|
|
1931
|
+
export { AgentsStorage, InMemoryAgentsStorage, InMemoryDB, InMemoryMemory, InMemoryStore, MastraStorage, MemoryStorage, MockStore, ObservabilityInMemory, ObservabilityStorage, ScoresInMemory, ScoresStorage, StorageDomain, StoreOperations, StoreOperationsInMemory, WorkflowsInMemory, WorkflowsStorage, calculatePagination, createStorageErrorId, createStoreErrorId, createVectorErrorId, ensureDate, getDefaultValue, getSqlType, normalizePerPage, safelyParseJSON, serializeDate, transformRow, transformScoreRow };
|
|
1932
|
+
//# sourceMappingURL=chunk-GNUITL2N.js.map
|
|
1933
|
+
//# sourceMappingURL=chunk-GNUITL2N.js.map
|