@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,18 +1,18 @@
|
|
|
1
|
-
import { DefaultVoice } from './chunk-
|
|
1
|
+
import { DefaultVoice } from './chunk-O7M7DR4E.js';
|
|
2
2
|
import { PUBSUB_SYMBOL, STREAM_FORMAT_SYMBOL } from './chunk-6PMMP3FR.js';
|
|
3
|
-
import { InMemoryStore } from './chunk-
|
|
4
|
-
import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-
|
|
3
|
+
import { InMemoryStore } from './chunk-GNUITL2N.js';
|
|
4
|
+
import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-QXL3F3T2.js';
|
|
5
5
|
import { createTextStreamResponse, createUIMessageStreamResponse, createUIMessageStream, parsePartialJson, isDeepEqualData, stepCountIs } from './chunk-2SQB3WBT.js';
|
|
6
6
|
import { generateId, asSchema, jsonSchema, APICallError, tool } from './chunk-G6E6V2Z4.js';
|
|
7
|
-
import { resolveModelConfig, ModelRouterEmbeddingModel, ModelRouterLanguageModel } from './chunk-
|
|
8
|
-
import { MastraLLMV1 } from './chunk-
|
|
7
|
+
import { resolveModelConfig, ModelRouterEmbeddingModel, ModelRouterLanguageModel } from './chunk-4N6WB4EZ.js';
|
|
8
|
+
import { MastraLLMV1 } from './chunk-KKYAYRIO.js';
|
|
9
9
|
import { PubSub } from './chunk-BVUMKER5.js';
|
|
10
10
|
import { executeHook } from './chunk-L54GIUCB.js';
|
|
11
|
-
import { removeUndefinedValues, ensureToolProperties, makeCoreTool, createMastraProxy, isZodType, deepMerge, selectFields, delay } from './chunk-
|
|
12
|
-
import { getOrCreateSpan, wrapMastra, executeWithContextSync } from './chunk-
|
|
13
|
-
import { MastraError, getErrorFromUnknown } from './chunk-
|
|
11
|
+
import { removeUndefinedValues, ensureToolProperties, makeCoreTool, createMastraProxy, isZodType, deepMerge, selectFields, delay } from './chunk-FB5QMTJJ.js';
|
|
12
|
+
import { getOrCreateSpan, wrapMastra, executeWithContextSync } from './chunk-JQM64OZF.js';
|
|
13
|
+
import { MastraError, getErrorFromUnknown } from './chunk-FJEVLHJT.js';
|
|
14
14
|
import { ToolStream } from './chunk-DD2VNRQM.js';
|
|
15
|
-
import { Tool, createTool } from './chunk-
|
|
15
|
+
import { Tool, createTool } from './chunk-QD776HMB.js';
|
|
16
16
|
import { RequestContext, MASTRA_RESOURCE_ID_KEY, MASTRA_THREAD_ID_KEY } from './chunk-6TBWJV35.js';
|
|
17
17
|
import { zodToJsonSchema as zodToJsonSchema$1 } from './chunk-PJKCPRYF.js';
|
|
18
18
|
import { MastraBase } from './chunk-LSHPJWM5.js';
|
|
@@ -501,7 +501,8 @@ function prepareToolsAndToolChoice({
|
|
|
501
501
|
// src/stream/aisdk/v5/compat/consume-stream.ts
|
|
502
502
|
async function consumeStream({
|
|
503
503
|
stream,
|
|
504
|
-
onError
|
|
504
|
+
onError,
|
|
505
|
+
logger
|
|
505
506
|
}) {
|
|
506
507
|
const reader = stream.getReader();
|
|
507
508
|
try {
|
|
@@ -510,7 +511,7 @@ async function consumeStream({
|
|
|
510
511
|
if (done) break;
|
|
511
512
|
}
|
|
512
513
|
} catch (error) {
|
|
513
|
-
|
|
514
|
+
logger?.error("consumeStream error", error);
|
|
514
515
|
onError?.(error);
|
|
515
516
|
} finally {
|
|
516
517
|
reader.releaseLock();
|
|
@@ -529,6 +530,7 @@ var StructuredOutputProcessor = class {
|
|
|
529
530
|
isStructuringAgentStreamStarted = false;
|
|
530
531
|
jsonPromptInjection;
|
|
531
532
|
providerOptions;
|
|
533
|
+
logger;
|
|
532
534
|
constructor(options) {
|
|
533
535
|
if (!options.schema) {
|
|
534
536
|
throw new MastraError({
|
|
@@ -551,6 +553,7 @@ var StructuredOutputProcessor = class {
|
|
|
551
553
|
this.fallbackValue = options.fallbackValue;
|
|
552
554
|
this.jsonPromptInjection = options.jsonPromptInjection;
|
|
553
555
|
this.providerOptions = options.providerOptions;
|
|
556
|
+
this.logger = options.logger;
|
|
554
557
|
this.structuringAgent = new Agent({
|
|
555
558
|
id: "structured-output-structurer",
|
|
556
559
|
name: "structured-output-structurer",
|
|
@@ -716,14 +719,14 @@ The input text may be in any format (sentences, bullet points, paragraphs, etc.)
|
|
|
716
719
|
const message = `[StructuredOutputProcessor] ${context}: ${error}`;
|
|
717
720
|
switch (this.errorStrategy) {
|
|
718
721
|
case "strict":
|
|
719
|
-
|
|
722
|
+
this.logger?.error(message);
|
|
720
723
|
abort(message);
|
|
721
724
|
break;
|
|
722
725
|
case "warn":
|
|
723
|
-
|
|
726
|
+
this.logger?.warn(message);
|
|
724
727
|
break;
|
|
725
728
|
case "fallback":
|
|
726
|
-
|
|
729
|
+
this.logger?.info(`${message} (using fallback)`);
|
|
727
730
|
break;
|
|
728
731
|
}
|
|
729
732
|
}
|
|
@@ -805,8 +808,9 @@ var ProcessorState = class {
|
|
|
805
808
|
this.span = parentSpan?.createChildSpan({
|
|
806
809
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
807
810
|
name: `output processor: ${processorName}`,
|
|
811
|
+
entityType: "output_processor" /* OUTPUT_PROCESSOR */,
|
|
812
|
+
entityName: processorName,
|
|
808
813
|
attributes: {
|
|
809
|
-
processorName,
|
|
810
814
|
processorType: "output",
|
|
811
815
|
processorIndex: processorIndex ?? 0
|
|
812
816
|
},
|
|
@@ -905,8 +909,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
905
909
|
const processorSpan2 = parentSpan2?.createChildSpan({
|
|
906
910
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
907
911
|
name: `output processor workflow: ${processorOrWorkflow.id}`,
|
|
912
|
+
entityType: "output_processor" /* OUTPUT_PROCESSOR */,
|
|
913
|
+
entityId: processorOrWorkflow.id,
|
|
914
|
+
entityName: processorOrWorkflow.name,
|
|
908
915
|
attributes: {
|
|
909
|
-
processorName: processorOrWorkflow.id,
|
|
910
916
|
processorType: "output",
|
|
911
917
|
processorIndex: index
|
|
912
918
|
},
|
|
@@ -947,8 +953,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
947
953
|
const processorSpan = parentSpan?.createChildSpan({
|
|
948
954
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
949
955
|
name: `output processor: ${processor.id}`,
|
|
956
|
+
entityType: "output_processor" /* OUTPUT_PROCESSOR */,
|
|
957
|
+
entityId: processor.id,
|
|
958
|
+
entityName: processor.name,
|
|
950
959
|
attributes: {
|
|
951
|
-
processorName: processor.name ?? processor.id,
|
|
952
960
|
processorType: "output",
|
|
953
961
|
processorIndex: index
|
|
954
962
|
},
|
|
@@ -1183,8 +1191,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1183
1191
|
const processorSpan2 = parentSpan2?.createChildSpan({
|
|
1184
1192
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1185
1193
|
name: `input processor workflow: ${processorOrWorkflow.id}`,
|
|
1194
|
+
entityType: "input_processor" /* INPUT_PROCESSOR */,
|
|
1195
|
+
entityId: processorOrWorkflow.id,
|
|
1196
|
+
entityName: processorOrWorkflow.name,
|
|
1186
1197
|
attributes: {
|
|
1187
|
-
processorName: processorOrWorkflow.id,
|
|
1188
1198
|
processorType: "input",
|
|
1189
1199
|
processorIndex: index
|
|
1190
1200
|
},
|
|
@@ -1227,8 +1237,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1227
1237
|
const processorSpan = parentSpan?.createChildSpan({
|
|
1228
1238
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1229
1239
|
name: `input processor: ${processor.id}`,
|
|
1240
|
+
entityType: "input_processor" /* INPUT_PROCESSOR */,
|
|
1241
|
+
entityId: processor.id,
|
|
1242
|
+
entityName: processor.name,
|
|
1230
1243
|
attributes: {
|
|
1231
|
-
processorName: processor.name ?? processor.id,
|
|
1232
1244
|
processorType: "input",
|
|
1233
1245
|
processorIndex: index
|
|
1234
1246
|
},
|
|
@@ -1351,8 +1363,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1351
1363
|
const processorSpan2 = parentSpan?.createChildSpan({
|
|
1352
1364
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1353
1365
|
name: `input step processor workflow: ${processorOrWorkflow.id}`,
|
|
1366
|
+
entityType: "input_processor" /* INPUT_PROCESSOR */,
|
|
1367
|
+
entityId: processorOrWorkflow.id,
|
|
1368
|
+
entityName: processorOrWorkflow.name,
|
|
1354
1369
|
attributes: {
|
|
1355
|
-
processorName: processorOrWorkflow.id,
|
|
1356
1370
|
processorType: "input",
|
|
1357
1371
|
processorIndex: index
|
|
1358
1372
|
},
|
|
@@ -1411,8 +1425,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1411
1425
|
const processorSpan = currentSpan?.createChildSpan({
|
|
1412
1426
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1413
1427
|
name: `input step processor: ${processor.id}`,
|
|
1428
|
+
entityType: "input_processor" /* INPUT_PROCESSOR */,
|
|
1429
|
+
entityId: processor.id,
|
|
1430
|
+
entityName: processor.name,
|
|
1414
1431
|
attributes: {
|
|
1415
|
-
processorName: processor.name ?? processor.id,
|
|
1416
1432
|
processorType: "input",
|
|
1417
1433
|
processorIndex: index
|
|
1418
1434
|
},
|
|
@@ -1505,6 +1521,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1505
1521
|
*/
|
|
1506
1522
|
async runProcessOutputStep(args) {
|
|
1507
1523
|
const {
|
|
1524
|
+
steps,
|
|
1508
1525
|
messageList,
|
|
1509
1526
|
stepNumber,
|
|
1510
1527
|
finishReason,
|
|
@@ -1524,8 +1541,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1524
1541
|
const processorSpan2 = parentSpan2?.createChildSpan({
|
|
1525
1542
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1526
1543
|
name: `output step processor workflow: ${processorOrWorkflow.id}`,
|
|
1544
|
+
entityType: "output_processor" /* OUTPUT_PROCESSOR */,
|
|
1545
|
+
entityId: processorOrWorkflow.id,
|
|
1546
|
+
entityName: processorOrWorkflow.name,
|
|
1527
1547
|
attributes: {
|
|
1528
|
-
processorName: processorOrWorkflow.id,
|
|
1529
1548
|
processorType: "output",
|
|
1530
1549
|
processorIndex: index
|
|
1531
1550
|
},
|
|
@@ -1544,6 +1563,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1544
1563
|
toolCalls,
|
|
1545
1564
|
text,
|
|
1546
1565
|
systemMessages: currentSystemMessages2,
|
|
1566
|
+
steps,
|
|
1547
1567
|
retryCount
|
|
1548
1568
|
},
|
|
1549
1569
|
tracingContext,
|
|
@@ -1572,8 +1592,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1572
1592
|
const processorSpan = parentSpan?.createChildSpan({
|
|
1573
1593
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1574
1594
|
name: `output step processor: ${processor.id}`,
|
|
1595
|
+
entityType: "output_processor" /* OUTPUT_PROCESSOR */,
|
|
1596
|
+
entityId: processor.id,
|
|
1597
|
+
entityName: processor.name,
|
|
1575
1598
|
attributes: {
|
|
1576
|
-
processorName: processor.name ?? processor.id,
|
|
1577
1599
|
processorType: "output",
|
|
1578
1600
|
processorIndex: index
|
|
1579
1601
|
},
|
|
@@ -1590,6 +1612,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1590
1612
|
toolCalls,
|
|
1591
1613
|
text,
|
|
1592
1614
|
systemMessages: currentSystemMessages,
|
|
1615
|
+
steps,
|
|
1593
1616
|
abort,
|
|
1594
1617
|
tracingContext: { currentSpan: processorSpan },
|
|
1595
1618
|
requestContext,
|
|
@@ -1904,7 +1927,7 @@ function convertFullStreamChunkToMastra(value, ctx) {
|
|
|
1904
1927
|
from: "AGENT" /* AGENT */,
|
|
1905
1928
|
payload: {
|
|
1906
1929
|
stepResult: {
|
|
1907
|
-
reason: value.finishReason
|
|
1930
|
+
reason: normalizeFinishReason(value.finishReason)
|
|
1908
1931
|
},
|
|
1909
1932
|
output: {
|
|
1910
1933
|
// Normalize usage to handle both V2 (flat) and V3 (nested) formats
|
|
@@ -2172,6 +2195,21 @@ function normalizeUsage(usage) {
|
|
|
2172
2195
|
raw: usage
|
|
2173
2196
|
};
|
|
2174
2197
|
}
|
|
2198
|
+
function isV3FinishReason(finishReason) {
|
|
2199
|
+
return typeof finishReason === "object" && finishReason !== null && "unified" in finishReason;
|
|
2200
|
+
}
|
|
2201
|
+
function normalizeFinishReason(finishReason) {
|
|
2202
|
+
if (!finishReason) {
|
|
2203
|
+
return "other";
|
|
2204
|
+
}
|
|
2205
|
+
if (finishReason === "tripwire" || finishReason === "retry") {
|
|
2206
|
+
return finishReason;
|
|
2207
|
+
}
|
|
2208
|
+
if (isV3FinishReason(finishReason)) {
|
|
2209
|
+
return finishReason.unified;
|
|
2210
|
+
}
|
|
2211
|
+
return finishReason === "unknown" ? "other" : finishReason;
|
|
2212
|
+
}
|
|
2175
2213
|
|
|
2176
2214
|
// src/stream/aisdk/v5/output.ts
|
|
2177
2215
|
var AISDKV5OutputStream = class {
|
|
@@ -2421,7 +2459,6 @@ var AISDKV5OutputStream = class {
|
|
|
2421
2459
|
async getFullOutput() {
|
|
2422
2460
|
await this.consumeStream({
|
|
2423
2461
|
onError: (error) => {
|
|
2424
|
-
console.error(error);
|
|
2425
2462
|
throw error;
|
|
2426
2463
|
}
|
|
2427
2464
|
});
|
|
@@ -3838,7 +3875,8 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
3838
3875
|
try {
|
|
3839
3876
|
await consumeStream({
|
|
3840
3877
|
stream: this.#baseStream,
|
|
3841
|
-
onError: options?.onError
|
|
3878
|
+
onError: options?.onError,
|
|
3879
|
+
logger: this.logger
|
|
3842
3880
|
});
|
|
3843
3881
|
} catch (error) {
|
|
3844
3882
|
options?.onError?.(error);
|
|
@@ -3850,7 +3888,7 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
3850
3888
|
async getFullOutput() {
|
|
3851
3889
|
await this.consumeStream({
|
|
3852
3890
|
onError: (error) => {
|
|
3853
|
-
|
|
3891
|
+
this.logger.error("Error consuming stream", error);
|
|
3854
3892
|
throw error;
|
|
3855
3893
|
}
|
|
3856
3894
|
});
|
|
@@ -4344,6 +4382,8 @@ var WorkflowRunOutput = class {
|
|
|
4344
4382
|
} else {
|
|
4345
4383
|
self.#status = "failed";
|
|
4346
4384
|
}
|
|
4385
|
+
} else if (chunk.type === "workflow-paused") {
|
|
4386
|
+
self.#status = "paused";
|
|
4347
4387
|
}
|
|
4348
4388
|
},
|
|
4349
4389
|
close() {
|
|
@@ -4479,6 +4519,8 @@ var WorkflowRunOutput = class {
|
|
|
4479
4519
|
} else {
|
|
4480
4520
|
self.#status = "failed";
|
|
4481
4521
|
}
|
|
4522
|
+
} else if (chunk.type === "workflow-paused") {
|
|
4523
|
+
self.#status = "paused";
|
|
4482
4524
|
}
|
|
4483
4525
|
},
|
|
4484
4526
|
close() {
|
|
@@ -5203,7 +5245,7 @@ var getStepIds = (entry) => {
|
|
|
5203
5245
|
return [];
|
|
5204
5246
|
};
|
|
5205
5247
|
var createTimeTravelExecutionParams = (params) => {
|
|
5206
|
-
const { steps, inputData, resumeData, context, nestedStepsContext, snapshot, initialState, graph } = params;
|
|
5248
|
+
const { steps, inputData, resumeData, context, nestedStepsContext, snapshot, initialState, graph, perStep } = params;
|
|
5207
5249
|
const firstStepId = steps[0];
|
|
5208
5250
|
let executionPath = [];
|
|
5209
5251
|
const stepResults = {};
|
|
@@ -5270,7 +5312,8 @@ var createTimeTravelExecutionParams = (params) => {
|
|
|
5270
5312
|
suspendedAt: stepContext?.suspendedAt,
|
|
5271
5313
|
resumedAt: stepContext?.resumedAt
|
|
5272
5314
|
};
|
|
5273
|
-
|
|
5315
|
+
const execPathLengthToUse = perStep ? executionPath.length : currentExecPathLength;
|
|
5316
|
+
if (execPathLengthToUse > 0 && !steps?.includes(stepId) && !context?.[stepId] && (!snapshotContext[stepId] || snapshotContext[stepId] && snapshotContext[stepId].status !== "suspended")) {
|
|
5274
5317
|
result = void 0;
|
|
5275
5318
|
}
|
|
5276
5319
|
if (result) {
|
|
@@ -5325,7 +5368,8 @@ async function executeParallel(engine, params) {
|
|
|
5325
5368
|
abortController,
|
|
5326
5369
|
requestContext,
|
|
5327
5370
|
outputWriter,
|
|
5328
|
-
disableScorers
|
|
5371
|
+
disableScorers,
|
|
5372
|
+
perStep
|
|
5329
5373
|
} = params;
|
|
5330
5374
|
const parallelSpan = tracingContext.currentSpan?.createChildSpan({
|
|
5331
5375
|
type: "workflow_parallel" /* WORKFLOW_PARALLEL */,
|
|
@@ -5347,7 +5391,7 @@ async function executeParallel(engine, params) {
|
|
|
5347
5391
|
makeStepRunning = timeTravel.steps[0] === step.step.id;
|
|
5348
5392
|
}
|
|
5349
5393
|
if (!makeStepRunning) {
|
|
5350
|
-
|
|
5394
|
+
break;
|
|
5351
5395
|
}
|
|
5352
5396
|
const startTime = resume?.steps[0] === step.step.id ? void 0 : Date.now();
|
|
5353
5397
|
const resumeTime = resume?.steps[0] === step.step.id ? Date.now() : void 0;
|
|
@@ -5359,6 +5403,9 @@ async function executeParallel(engine, params) {
|
|
|
5359
5403
|
...resumeTime ? { resumedAt: resumeTime } : {}
|
|
5360
5404
|
};
|
|
5361
5405
|
executionContext.activeStepsPath[step.step.id] = [...executionContext.executionPath, stepIndex];
|
|
5406
|
+
if (perStep) {
|
|
5407
|
+
break;
|
|
5408
|
+
}
|
|
5362
5409
|
}
|
|
5363
5410
|
if (timeTravel && timeTravel.executionPath.length > 0) {
|
|
5364
5411
|
timeTravel.executionPath.shift();
|
|
@@ -5370,6 +5417,9 @@ async function executeParallel(engine, params) {
|
|
|
5370
5417
|
if (currStepResult && currStepResult.status !== "running") {
|
|
5371
5418
|
return currStepResult;
|
|
5372
5419
|
}
|
|
5420
|
+
if (!currStepResult && (perStep || timeTravel)) {
|
|
5421
|
+
return {};
|
|
5422
|
+
}
|
|
5373
5423
|
const stepExecResult = await engine.executeStep({
|
|
5374
5424
|
workflowId,
|
|
5375
5425
|
runId,
|
|
@@ -5398,7 +5448,8 @@ async function executeParallel(engine, params) {
|
|
|
5398
5448
|
abortController,
|
|
5399
5449
|
requestContext,
|
|
5400
5450
|
outputWriter,
|
|
5401
|
-
disableScorers
|
|
5451
|
+
disableScorers,
|
|
5452
|
+
perStep
|
|
5402
5453
|
});
|
|
5403
5454
|
engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
|
|
5404
5455
|
Object.assign(stepResults, stepExecResult.stepResults);
|
|
@@ -5459,7 +5510,8 @@ async function executeConditional(engine, params) {
|
|
|
5459
5510
|
abortController,
|
|
5460
5511
|
requestContext,
|
|
5461
5512
|
outputWriter,
|
|
5462
|
-
disableScorers
|
|
5513
|
+
disableScorers,
|
|
5514
|
+
perStep
|
|
5463
5515
|
} = params;
|
|
5464
5516
|
const conditionalSpan = tracingContext.currentSpan?.createChildSpan({
|
|
5465
5517
|
type: "workflow_conditional" /* WORKFLOW_CONDITIONAL */,
|
|
@@ -5554,7 +5606,18 @@ async function executeConditional(engine, params) {
|
|
|
5554
5606
|
}
|
|
5555
5607
|
})
|
|
5556
5608
|
)).filter((index) => index !== null);
|
|
5557
|
-
|
|
5609
|
+
let stepsToRun = entry.steps.filter((_, index) => truthyIndexes.includes(index));
|
|
5610
|
+
if (perStep || timeTravel && timeTravel.executionPath.length > 0) {
|
|
5611
|
+
const possibleStepsToRun = stepsToRun.filter((s) => {
|
|
5612
|
+
const currStepResult = stepResults[s.step.id];
|
|
5613
|
+
if (timeTravel && timeTravel.executionPath.length > 0) {
|
|
5614
|
+
return timeTravel.steps[0] === s.step.id;
|
|
5615
|
+
}
|
|
5616
|
+
return !currStepResult;
|
|
5617
|
+
});
|
|
5618
|
+
const possibleStepToRun = possibleStepsToRun?.[0];
|
|
5619
|
+
stepsToRun = possibleStepToRun ? [possibleStepToRun] : stepsToRun;
|
|
5620
|
+
}
|
|
5558
5621
|
conditionalSpan?.update({
|
|
5559
5622
|
attributes: {
|
|
5560
5623
|
truthyIndexes,
|
|
@@ -5601,7 +5664,8 @@ async function executeConditional(engine, params) {
|
|
|
5601
5664
|
abortController,
|
|
5602
5665
|
requestContext,
|
|
5603
5666
|
outputWriter,
|
|
5604
|
-
disableScorers
|
|
5667
|
+
disableScorers,
|
|
5668
|
+
perStep
|
|
5605
5669
|
});
|
|
5606
5670
|
engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
|
|
5607
5671
|
Object.assign(stepResults, stepExecResult.stepResults);
|
|
@@ -5663,7 +5727,8 @@ async function executeLoop(engine, params) {
|
|
|
5663
5727
|
requestContext,
|
|
5664
5728
|
outputWriter,
|
|
5665
5729
|
disableScorers,
|
|
5666
|
-
serializedStepGraph
|
|
5730
|
+
serializedStepGraph,
|
|
5731
|
+
perStep
|
|
5667
5732
|
} = params;
|
|
5668
5733
|
const { step, condition } = entry;
|
|
5669
5734
|
const loopSpan = tracingContext.currentSpan?.createChildSpan({
|
|
@@ -5704,7 +5769,8 @@ async function executeLoop(engine, params) {
|
|
|
5704
5769
|
outputWriter,
|
|
5705
5770
|
disableScorers,
|
|
5706
5771
|
serializedStepGraph,
|
|
5707
|
-
iterationCount: iteration + 1
|
|
5772
|
+
iterationCount: iteration + 1,
|
|
5773
|
+
perStep
|
|
5708
5774
|
});
|
|
5709
5775
|
engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
|
|
5710
5776
|
Object.assign(stepResults, stepExecResult.stepResults);
|
|
@@ -5804,7 +5870,8 @@ async function executeForeach(engine, params) {
|
|
|
5804
5870
|
requestContext,
|
|
5805
5871
|
outputWriter,
|
|
5806
5872
|
disableScorers,
|
|
5807
|
-
serializedStepGraph
|
|
5873
|
+
serializedStepGraph,
|
|
5874
|
+
perStep
|
|
5808
5875
|
} = params;
|
|
5809
5876
|
const { step, opts } = entry;
|
|
5810
5877
|
const results = [];
|
|
@@ -5881,7 +5948,8 @@ async function executeForeach(engine, params) {
|
|
|
5881
5948
|
skipEmits: true,
|
|
5882
5949
|
outputWriter,
|
|
5883
5950
|
disableScorers,
|
|
5884
|
-
serializedStepGraph
|
|
5951
|
+
serializedStepGraph,
|
|
5952
|
+
perStep
|
|
5885
5953
|
});
|
|
5886
5954
|
engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
|
|
5887
5955
|
Object.assign(stepResults, stepExecResult.stepResults);
|
|
@@ -6023,7 +6091,8 @@ async function persistStepUpdate(engine, params) {
|
|
|
6023
6091
|
requestContext.forEach((value, key) => {
|
|
6024
6092
|
requestContextObj[key] = value;
|
|
6025
6093
|
});
|
|
6026
|
-
await engine.mastra?.getStorage()?.
|
|
6094
|
+
const workflowsStore = await engine.mastra?.getStorage()?.getStore("workflows");
|
|
6095
|
+
await workflowsStore?.persistWorkflowSnapshot({
|
|
6027
6096
|
workflowName: workflowId,
|
|
6028
6097
|
runId,
|
|
6029
6098
|
resourceId,
|
|
@@ -6065,7 +6134,8 @@ async function executeEntry(engine, params) {
|
|
|
6065
6134
|
abortController,
|
|
6066
6135
|
requestContext,
|
|
6067
6136
|
outputWriter,
|
|
6068
|
-
disableScorers
|
|
6137
|
+
disableScorers,
|
|
6138
|
+
perStep
|
|
6069
6139
|
} = params;
|
|
6070
6140
|
const prevOutput = engine.getStepOutput(stepResults, prevStep);
|
|
6071
6141
|
let execResults;
|
|
@@ -6089,7 +6159,8 @@ async function executeEntry(engine, params) {
|
|
|
6089
6159
|
requestContext,
|
|
6090
6160
|
outputWriter,
|
|
6091
6161
|
disableScorers,
|
|
6092
|
-
serializedStepGraph
|
|
6162
|
+
serializedStepGraph,
|
|
6163
|
+
perStep
|
|
6093
6164
|
});
|
|
6094
6165
|
execResults = stepExecResult.result;
|
|
6095
6166
|
engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
|
|
@@ -6121,7 +6192,8 @@ async function executeEntry(engine, params) {
|
|
|
6121
6192
|
abortController,
|
|
6122
6193
|
requestContext,
|
|
6123
6194
|
outputWriter,
|
|
6124
|
-
disableScorers
|
|
6195
|
+
disableScorers,
|
|
6196
|
+
perStep
|
|
6125
6197
|
});
|
|
6126
6198
|
engine.applyMutableContext(executionContext, resumedStepResult.mutableContext);
|
|
6127
6199
|
Object.assign(stepResults, resumedStepResult.stepResults);
|
|
@@ -6191,7 +6263,8 @@ async function executeEntry(engine, params) {
|
|
|
6191
6263
|
abortController,
|
|
6192
6264
|
requestContext,
|
|
6193
6265
|
outputWriter,
|
|
6194
|
-
disableScorers
|
|
6266
|
+
disableScorers,
|
|
6267
|
+
perStep
|
|
6195
6268
|
});
|
|
6196
6269
|
} else if (entry.type === "conditional") {
|
|
6197
6270
|
execResults = await engine.executeConditional({
|
|
@@ -6210,7 +6283,8 @@ async function executeEntry(engine, params) {
|
|
|
6210
6283
|
abortController,
|
|
6211
6284
|
requestContext,
|
|
6212
6285
|
outputWriter,
|
|
6213
|
-
disableScorers
|
|
6286
|
+
disableScorers,
|
|
6287
|
+
perStep
|
|
6214
6288
|
});
|
|
6215
6289
|
} else if (entry.type === "loop") {
|
|
6216
6290
|
execResults = await engine.executeLoop({
|
|
@@ -6230,7 +6304,8 @@ async function executeEntry(engine, params) {
|
|
|
6230
6304
|
requestContext,
|
|
6231
6305
|
outputWriter,
|
|
6232
6306
|
disableScorers,
|
|
6233
|
-
serializedStepGraph
|
|
6307
|
+
serializedStepGraph,
|
|
6308
|
+
perStep
|
|
6234
6309
|
});
|
|
6235
6310
|
} else if (entry.type === "foreach") {
|
|
6236
6311
|
execResults = await engine.executeForeach({
|
|
@@ -6250,7 +6325,8 @@ async function executeEntry(engine, params) {
|
|
|
6250
6325
|
requestContext,
|
|
6251
6326
|
outputWriter,
|
|
6252
6327
|
disableScorers,
|
|
6253
|
-
serializedStepGraph
|
|
6328
|
+
serializedStepGraph,
|
|
6329
|
+
perStep
|
|
6254
6330
|
});
|
|
6255
6331
|
} else if (entry.type === "sleep") {
|
|
6256
6332
|
const startedAt = Date.now();
|
|
@@ -6662,7 +6738,8 @@ async function executeStep(engine, params) {
|
|
|
6662
6738
|
disableScorers,
|
|
6663
6739
|
serializedStepGraph,
|
|
6664
6740
|
tracingContext,
|
|
6665
|
-
iterationCount
|
|
6741
|
+
iterationCount,
|
|
6742
|
+
perStep
|
|
6666
6743
|
} = params;
|
|
6667
6744
|
const stepCallId = randomUUID();
|
|
6668
6745
|
const { inputData, validationError } = await validateStepInput({
|
|
@@ -6704,10 +6781,9 @@ async function executeStep(engine, params) {
|
|
|
6704
6781
|
const stepSpan = tracingContext.currentSpan?.createChildSpan({
|
|
6705
6782
|
name: `workflow step: '${step.id}'`,
|
|
6706
6783
|
type: "workflow_step" /* WORKFLOW_STEP */,
|
|
6784
|
+
entityType: "workflow_step" /* WORKFLOW_STEP */,
|
|
6785
|
+
entityId: step.id,
|
|
6707
6786
|
input: inputData,
|
|
6708
|
-
attributes: {
|
|
6709
|
-
stepId: step.id
|
|
6710
|
-
},
|
|
6711
6787
|
tracingPolicy: engine.options?.tracingPolicy
|
|
6712
6788
|
});
|
|
6713
6789
|
const operationId = `workflow.${workflowId}.run.${runId}.step.${step.id}.running_ev`;
|
|
@@ -6749,7 +6825,8 @@ async function executeStep(engine, params) {
|
|
|
6749
6825
|
requestContext,
|
|
6750
6826
|
tracingContext,
|
|
6751
6827
|
outputWriter,
|
|
6752
|
-
stepSpan
|
|
6828
|
+
stepSpan,
|
|
6829
|
+
perStep
|
|
6753
6830
|
});
|
|
6754
6831
|
if (workflowResult !== null) {
|
|
6755
6832
|
const stepResult2 = { ...stepInfo, ...workflowResult };
|
|
@@ -6881,12 +6958,15 @@ async function executeStep(engine, params) {
|
|
|
6881
6958
|
outputWriter,
|
|
6882
6959
|
// Disable scorers must be explicitly set to false they are on by default
|
|
6883
6960
|
scorers: disableScorers === false ? void 0 : step.scorers,
|
|
6884
|
-
validateInputs: engine.options?.validateInputs
|
|
6961
|
+
validateInputs: engine.options?.validateInputs,
|
|
6962
|
+
perStep
|
|
6885
6963
|
});
|
|
6886
6964
|
if (engine.requiresDurableContextSerialization()) {
|
|
6887
6965
|
contextMutations.requestContextUpdate = engine.serializeRequestContext(requestContext);
|
|
6888
6966
|
}
|
|
6889
|
-
|
|
6967
|
+
const isNestedWorkflowStep = step.component === "WORKFLOW";
|
|
6968
|
+
const nestedWflowStepPaused = isNestedWorkflowStep && perStep;
|
|
6969
|
+
return { output, suspended, bailed, contextMutations, nestedWflowStepPaused };
|
|
6890
6970
|
},
|
|
6891
6971
|
{ retries, delay: delay2, stepSpan, workflowId, runId }
|
|
6892
6972
|
);
|
|
@@ -6925,6 +7005,8 @@ async function executeStep(engine, params) {
|
|
|
6925
7005
|
};
|
|
6926
7006
|
} else if (durableResult.bailed) {
|
|
6927
7007
|
execResults = { status: "bailed", output: durableResult.bailed.payload, endedAt: Date.now() };
|
|
7008
|
+
} else if (durableResult.nestedWflowStepPaused) {
|
|
7009
|
+
execResults = { status: "paused" };
|
|
6928
7010
|
} else {
|
|
6929
7011
|
execResults = { status: "success", output: durableResult.output, endedAt: Date.now() };
|
|
6930
7012
|
}
|
|
@@ -7348,7 +7430,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7348
7430
|
workflowSpan,
|
|
7349
7431
|
disableScorers,
|
|
7350
7432
|
restart,
|
|
7351
|
-
timeTravel
|
|
7433
|
+
timeTravel,
|
|
7434
|
+
perStep
|
|
7352
7435
|
} = params;
|
|
7353
7436
|
const { attempts = 0, delay: delay2 = 0 } = retryConfig ?? {};
|
|
7354
7437
|
const steps = graph.steps;
|
|
@@ -7412,7 +7495,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7412
7495
|
pubsub: params.pubsub,
|
|
7413
7496
|
requestContext: currentRequestContext,
|
|
7414
7497
|
outputWriter: params.outputWriter,
|
|
7415
|
-
disableScorers
|
|
7498
|
+
disableScorers,
|
|
7499
|
+
perStep
|
|
7416
7500
|
});
|
|
7417
7501
|
this.applyMutableContext(executionContext, lastOutput.mutableContext);
|
|
7418
7502
|
lastState = lastOutput.mutableContext.state;
|
|
@@ -7451,13 +7535,47 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7451
7535
|
}
|
|
7452
7536
|
});
|
|
7453
7537
|
}
|
|
7454
|
-
|
|
7538
|
+
if (lastOutput.result.status !== "paused") {
|
|
7539
|
+
await this.invokeLifecycleCallbacks(result2);
|
|
7540
|
+
}
|
|
7541
|
+
if (lastOutput.result.status === "paused") {
|
|
7542
|
+
await params.pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
7543
|
+
type: "watch",
|
|
7544
|
+
runId,
|
|
7545
|
+
data: { type: "workflow-paused", payload: {} }
|
|
7546
|
+
});
|
|
7547
|
+
}
|
|
7455
7548
|
return {
|
|
7456
7549
|
...result2,
|
|
7457
7550
|
...lastOutput.result.status === "suspended" && params.outputOptions?.includeResumeLabels ? { resumeLabels: lastOutput.mutableContext.resumeLabels } : {},
|
|
7458
7551
|
...params.outputOptions?.includeState ? { state: lastState } : {}
|
|
7459
7552
|
};
|
|
7460
7553
|
}
|
|
7554
|
+
if (perStep) {
|
|
7555
|
+
const result2 = await this.fmtReturnValue(params.pubsub, stepResults, lastOutput.result);
|
|
7556
|
+
await this.persistStepUpdate({
|
|
7557
|
+
workflowId,
|
|
7558
|
+
runId,
|
|
7559
|
+
resourceId,
|
|
7560
|
+
stepResults: lastOutput.stepResults,
|
|
7561
|
+
serializedStepGraph: params.serializedStepGraph,
|
|
7562
|
+
executionContext: lastExecutionContext,
|
|
7563
|
+
workflowStatus: "paused",
|
|
7564
|
+
requestContext: currentRequestContext
|
|
7565
|
+
});
|
|
7566
|
+
await params.pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
7567
|
+
type: "watch",
|
|
7568
|
+
runId,
|
|
7569
|
+
data: { type: "workflow-paused", payload: {} }
|
|
7570
|
+
});
|
|
7571
|
+
workflowSpan?.end({
|
|
7572
|
+
attributes: {
|
|
7573
|
+
status: "paused"
|
|
7574
|
+
}
|
|
7575
|
+
});
|
|
7576
|
+
delete result2.result;
|
|
7577
|
+
return { ...result2, status: "paused", ...params.outputOptions?.includeState ? { state: lastState } : {} };
|
|
7578
|
+
}
|
|
7461
7579
|
}
|
|
7462
7580
|
const result = await this.fmtReturnValue(params.pubsub, stepResults, lastOutput.result);
|
|
7463
7581
|
await this.persistStepUpdate({
|
|
@@ -7989,7 +8107,8 @@ function createStep(params, agentOptions) {
|
|
|
7989
8107
|
finishReason,
|
|
7990
8108
|
toolCalls,
|
|
7991
8109
|
text,
|
|
7992
|
-
systemMessages: systemMessages ?? []
|
|
8110
|
+
systemMessages: systemMessages ?? [],
|
|
8111
|
+
steps: steps ?? []
|
|
7993
8112
|
});
|
|
7994
8113
|
const applyMessages = (msgs) => {
|
|
7995
8114
|
const deletedIds = idsBeforeProcessing.filter((i) => !msgs.some((m) => m.id === i));
|
|
@@ -8255,8 +8374,8 @@ var Workflow = class extends MastraBase {
|
|
|
8255
8374
|
if (typeof mappingConfig === "function") {
|
|
8256
8375
|
const mappingStep2 = createStep({
|
|
8257
8376
|
id: stepOptions?.id || `mapping_${this.#mastra?.generateId() || randomUUID()}`,
|
|
8258
|
-
inputSchema: z.
|
|
8259
|
-
outputSchema: z.
|
|
8377
|
+
inputSchema: z.any(),
|
|
8378
|
+
outputSchema: z.any(),
|
|
8260
8379
|
execute: mappingConfig
|
|
8261
8380
|
});
|
|
8262
8381
|
this.stepFlow.push({ type: "step", step: mappingStep2 });
|
|
@@ -8312,7 +8431,15 @@ var Workflow = class extends MastraBase {
|
|
|
8312
8431
|
result[key] = requestContext.get(m.requestContextPath);
|
|
8313
8432
|
continue;
|
|
8314
8433
|
}
|
|
8315
|
-
const stepResult = m.initData ? getInitData() : getStepResult2(
|
|
8434
|
+
const stepResult = m.initData ? getInitData() : getStepResult2(
|
|
8435
|
+
Array.isArray(m.step) ? m.step.find((s) => {
|
|
8436
|
+
const result2 = getStepResult2(s);
|
|
8437
|
+
if (typeof result2 === "object" && result2 !== null) {
|
|
8438
|
+
return Object.keys(result2).length > 0;
|
|
8439
|
+
}
|
|
8440
|
+
return result2;
|
|
8441
|
+
}) : m.step
|
|
8442
|
+
);
|
|
8316
8443
|
if (m.path === ".") {
|
|
8317
8444
|
result[key] = stepResult;
|
|
8318
8445
|
continue;
|
|
@@ -8530,7 +8657,8 @@ var Workflow = class extends MastraBase {
|
|
|
8530
8657
|
run.workflowRunStatus = workflowSnapshotInStorage.status;
|
|
8531
8658
|
}
|
|
8532
8659
|
if (!workflowSnapshotInStorage && shouldPersistSnapshot) {
|
|
8533
|
-
await this.mastra?.getStorage()?.
|
|
8660
|
+
const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
|
|
8661
|
+
await workflowsStore?.persistWorkflowSnapshot({
|
|
8534
8662
|
workflowName: this.id,
|
|
8535
8663
|
runId: runIdToUse,
|
|
8536
8664
|
resourceId: options?.resourceId,
|
|
@@ -8595,7 +8723,8 @@ var Workflow = class extends MastraBase {
|
|
|
8595
8723
|
retryCount,
|
|
8596
8724
|
tracingContext,
|
|
8597
8725
|
outputWriter,
|
|
8598
|
-
validateInputs
|
|
8726
|
+
validateInputs,
|
|
8727
|
+
perStep
|
|
8599
8728
|
}) {
|
|
8600
8729
|
this.__registerMastra(mastra);
|
|
8601
8730
|
const effectiveValidateInputs = validateInputs ?? this.#options.validateInputs ?? true;
|
|
@@ -8643,7 +8772,8 @@ var Workflow = class extends MastraBase {
|
|
|
8643
8772
|
requestContext,
|
|
8644
8773
|
tracingContext,
|
|
8645
8774
|
outputWriter,
|
|
8646
|
-
outputOptions: { includeState: true, includeResumeLabels: true }
|
|
8775
|
+
outputOptions: { includeState: true, includeResumeLabels: true },
|
|
8776
|
+
perStep
|
|
8647
8777
|
});
|
|
8648
8778
|
} else if (restart) {
|
|
8649
8779
|
res = await run.restart({ requestContext, tracingContext, outputWriter });
|
|
@@ -8655,7 +8785,8 @@ var Workflow = class extends MastraBase {
|
|
|
8655
8785
|
tracingContext,
|
|
8656
8786
|
outputWriter,
|
|
8657
8787
|
outputOptions: { includeState: true, includeResumeLabels: true },
|
|
8658
|
-
label: resume.label
|
|
8788
|
+
label: resume.label,
|
|
8789
|
+
perStep
|
|
8659
8790
|
});
|
|
8660
8791
|
} else {
|
|
8661
8792
|
res = await run.start({
|
|
@@ -8664,7 +8795,8 @@ var Workflow = class extends MastraBase {
|
|
|
8664
8795
|
tracingContext,
|
|
8665
8796
|
outputWriter,
|
|
8666
8797
|
initialState: state,
|
|
8667
|
-
outputOptions: { includeState: true, includeResumeLabels: true }
|
|
8798
|
+
outputOptions: { includeState: true, includeResumeLabels: true },
|
|
8799
|
+
perStep
|
|
8668
8800
|
});
|
|
8669
8801
|
}
|
|
8670
8802
|
unwatch();
|
|
@@ -8700,7 +8832,12 @@ var Workflow = class extends MastraBase {
|
|
|
8700
8832
|
this.logger.debug("Cannot get workflow runs. Mastra storage is not initialized");
|
|
8701
8833
|
return { runs: [], total: 0 };
|
|
8702
8834
|
}
|
|
8703
|
-
|
|
8835
|
+
const workflowsStore = await storage.getStore("workflows");
|
|
8836
|
+
if (!workflowsStore) {
|
|
8837
|
+
this.logger.debug("Cannot get workflow runs. Workflows storage domain is not available");
|
|
8838
|
+
return { runs: [], total: 0 };
|
|
8839
|
+
}
|
|
8840
|
+
return workflowsStore.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
|
|
8704
8841
|
}
|
|
8705
8842
|
async listActiveWorkflowRuns() {
|
|
8706
8843
|
const runningRuns = await this.listWorkflowRuns({ status: "running" });
|
|
@@ -8737,7 +8874,12 @@ var Workflow = class extends MastraBase {
|
|
|
8737
8874
|
this.logger.debug("Cannot get workflow runs from storage. Mastra storage is not initialized");
|
|
8738
8875
|
return this.#runs.get(runId) ? { ...this.#runs.get(runId), workflowName: this.id } : null;
|
|
8739
8876
|
}
|
|
8740
|
-
const
|
|
8877
|
+
const workflowsStore = await storage.getStore("workflows");
|
|
8878
|
+
if (!workflowsStore) {
|
|
8879
|
+
this.logger.debug("Cannot get workflow runs. Workflows storage domain is not available");
|
|
8880
|
+
return this.#runs.get(runId) ? { ...this.#runs.get(runId), workflowName: this.id } : null;
|
|
8881
|
+
}
|
|
8882
|
+
const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: this.id });
|
|
8741
8883
|
return run ?? (this.#runs.get(runId) ? { ...this.#runs.get(runId), workflowName: this.id } : null);
|
|
8742
8884
|
}
|
|
8743
8885
|
async deleteWorkflowRunById(runId) {
|
|
@@ -8746,7 +8888,12 @@ var Workflow = class extends MastraBase {
|
|
|
8746
8888
|
this.logger.debug("Cannot delete workflow run by ID. Mastra storage is not initialized");
|
|
8747
8889
|
return;
|
|
8748
8890
|
}
|
|
8749
|
-
await storage.
|
|
8891
|
+
const workflowsStore = await storage.getStore("workflows");
|
|
8892
|
+
if (!workflowsStore) {
|
|
8893
|
+
this.logger.debug("Cannot delete workflow run. Workflows storage domain is not available");
|
|
8894
|
+
return;
|
|
8895
|
+
}
|
|
8896
|
+
await workflowsStore.deleteWorkflowRunById({ runId, workflowName: this.id });
|
|
8750
8897
|
this.#runs.delete(runId);
|
|
8751
8898
|
}
|
|
8752
8899
|
async getWorkflowRunSteps({ runId, workflowId }) {
|
|
@@ -8755,7 +8902,12 @@ var Workflow = class extends MastraBase {
|
|
|
8755
8902
|
this.logger.debug("Cannot get workflow run steps. Mastra storage is not initialized");
|
|
8756
8903
|
return {};
|
|
8757
8904
|
}
|
|
8758
|
-
const
|
|
8905
|
+
const workflowsStore = await storage.getStore("workflows");
|
|
8906
|
+
if (!workflowsStore) {
|
|
8907
|
+
this.logger.debug("Cannot get workflow run steps. Workflows storage domain is not available");
|
|
8908
|
+
return {};
|
|
8909
|
+
}
|
|
8910
|
+
const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: workflowId });
|
|
8759
8911
|
let snapshot = run?.snapshot;
|
|
8760
8912
|
if (!snapshot) {
|
|
8761
8913
|
return {};
|
|
@@ -8797,7 +8949,12 @@ var Workflow = class extends MastraBase {
|
|
|
8797
8949
|
this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
|
|
8798
8950
|
return null;
|
|
8799
8951
|
}
|
|
8800
|
-
const
|
|
8952
|
+
const workflowsStore = await storage.getStore("workflows");
|
|
8953
|
+
if (!workflowsStore) {
|
|
8954
|
+
this.logger.debug("Cannot get workflow run execution result. Workflows storage domain is not available");
|
|
8955
|
+
return null;
|
|
8956
|
+
}
|
|
8957
|
+
const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: this.id });
|
|
8801
8958
|
let snapshot = run?.snapshot;
|
|
8802
8959
|
if (!snapshot) {
|
|
8803
8960
|
return null;
|
|
@@ -8956,7 +9113,8 @@ var Run = class {
|
|
|
8956
9113
|
this.abortController.abort();
|
|
8957
9114
|
this.workflowRunStatus = "canceled";
|
|
8958
9115
|
try {
|
|
8959
|
-
await this.mastra?.getStorage()?.
|
|
9116
|
+
const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
|
|
9117
|
+
await workflowsStore?.updateWorkflowState({
|
|
8960
9118
|
workflowName: this.workflowId,
|
|
8961
9119
|
runId: this.runId,
|
|
8962
9120
|
opts: {
|
|
@@ -9034,15 +9192,15 @@ var Run = class {
|
|
|
9034
9192
|
tracingContext,
|
|
9035
9193
|
tracingOptions,
|
|
9036
9194
|
format,
|
|
9037
|
-
outputOptions
|
|
9195
|
+
outputOptions,
|
|
9196
|
+
perStep
|
|
9038
9197
|
}) {
|
|
9039
9198
|
const workflowSpan = getOrCreateSpan({
|
|
9040
9199
|
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
9041
9200
|
name: `workflow run: '${this.workflowId}'`,
|
|
9201
|
+
entityType: "workflow_run" /* WORKFLOW_RUN */,
|
|
9202
|
+
entityId: this.workflowId,
|
|
9042
9203
|
input: inputData,
|
|
9043
|
-
attributes: {
|
|
9044
|
-
workflowId: this.workflowId
|
|
9045
|
-
},
|
|
9046
9204
|
metadata: {
|
|
9047
9205
|
resourceId: this.resourceId,
|
|
9048
9206
|
runId: this.runId
|
|
@@ -9072,7 +9230,8 @@ var Run = class {
|
|
|
9072
9230
|
outputWriter,
|
|
9073
9231
|
workflowSpan,
|
|
9074
9232
|
format,
|
|
9075
|
-
outputOptions
|
|
9233
|
+
outputOptions,
|
|
9234
|
+
perStep
|
|
9076
9235
|
});
|
|
9077
9236
|
if (result.status !== "suspended") {
|
|
9078
9237
|
this.cleanup?.();
|
|
@@ -9097,7 +9256,7 @@ var Run = class {
|
|
|
9097
9256
|
*/
|
|
9098
9257
|
async startAsync(args) {
|
|
9099
9258
|
this._start(args).catch((err) => {
|
|
9100
|
-
|
|
9259
|
+
this.mastra?.getLogger()?.error(`[Workflow ${this.workflowId}] Background execution failed:`, err);
|
|
9101
9260
|
});
|
|
9102
9261
|
return { runId: this.runId };
|
|
9103
9262
|
}
|
|
@@ -9146,7 +9305,7 @@ var Run = class {
|
|
|
9146
9305
|
try {
|
|
9147
9306
|
await writer.close();
|
|
9148
9307
|
} catch (err) {
|
|
9149
|
-
|
|
9308
|
+
this.mastra?.getLogger()?.error("Error closing stream:", err);
|
|
9150
9309
|
} finally {
|
|
9151
9310
|
writer.releaseLock();
|
|
9152
9311
|
}
|
|
@@ -9204,7 +9363,7 @@ var Run = class {
|
|
|
9204
9363
|
try {
|
|
9205
9364
|
await writer.close();
|
|
9206
9365
|
} catch (err) {
|
|
9207
|
-
|
|
9366
|
+
this.mastra?.getLogger()?.error("Error closing stream:", err);
|
|
9208
9367
|
} finally {
|
|
9209
9368
|
writer.releaseLock();
|
|
9210
9369
|
}
|
|
@@ -9239,9 +9398,10 @@ var Run = class {
|
|
|
9239
9398
|
}
|
|
9240
9399
|
async streamAsync({
|
|
9241
9400
|
inputData,
|
|
9242
|
-
requestContext
|
|
9401
|
+
requestContext,
|
|
9402
|
+
perStep
|
|
9243
9403
|
} = {}) {
|
|
9244
|
-
return this.stream({ inputData, requestContext });
|
|
9404
|
+
return this.stream({ inputData, requestContext, perStep });
|
|
9245
9405
|
}
|
|
9246
9406
|
/**
|
|
9247
9407
|
* Starts the workflow execution with the provided input as a stream
|
|
@@ -9255,7 +9415,8 @@ var Run = class {
|
|
|
9255
9415
|
tracingOptions,
|
|
9256
9416
|
closeOnSuspend = true,
|
|
9257
9417
|
initialState,
|
|
9258
|
-
outputOptions
|
|
9418
|
+
outputOptions,
|
|
9419
|
+
perStep
|
|
9259
9420
|
} = {}) {
|
|
9260
9421
|
if (this.closeStreamAction && this.streamOutput) {
|
|
9261
9422
|
return this.streamOutput;
|
|
@@ -9294,7 +9455,7 @@ var Run = class {
|
|
|
9294
9455
|
controller.close();
|
|
9295
9456
|
}
|
|
9296
9457
|
} catch (err) {
|
|
9297
|
-
|
|
9458
|
+
self.mastra?.getLogger()?.error("Error closing stream:", err);
|
|
9298
9459
|
}
|
|
9299
9460
|
};
|
|
9300
9461
|
const executionResultsPromise = self._start({
|
|
@@ -9310,7 +9471,8 @@ var Run = class {
|
|
|
9310
9471
|
runId: self.runId,
|
|
9311
9472
|
data: chunk
|
|
9312
9473
|
});
|
|
9313
|
-
}
|
|
9474
|
+
},
|
|
9475
|
+
perStep
|
|
9314
9476
|
});
|
|
9315
9477
|
let executionResults;
|
|
9316
9478
|
try {
|
|
@@ -9352,7 +9514,8 @@ var Run = class {
|
|
|
9352
9514
|
requestContext,
|
|
9353
9515
|
tracingContext,
|
|
9354
9516
|
tracingOptions,
|
|
9355
|
-
outputOptions
|
|
9517
|
+
outputOptions,
|
|
9518
|
+
perStep
|
|
9356
9519
|
} = {}) {
|
|
9357
9520
|
return this.resumeStreamVNext({
|
|
9358
9521
|
resumeData,
|
|
@@ -9360,7 +9523,8 @@ var Run = class {
|
|
|
9360
9523
|
requestContext,
|
|
9361
9524
|
tracingContext,
|
|
9362
9525
|
tracingOptions,
|
|
9363
|
-
outputOptions
|
|
9526
|
+
outputOptions,
|
|
9527
|
+
perStep
|
|
9364
9528
|
});
|
|
9365
9529
|
}
|
|
9366
9530
|
/**
|
|
@@ -9375,7 +9539,8 @@ var Run = class {
|
|
|
9375
9539
|
tracingContext,
|
|
9376
9540
|
tracingOptions,
|
|
9377
9541
|
forEachIndex,
|
|
9378
|
-
outputOptions
|
|
9542
|
+
outputOptions,
|
|
9543
|
+
perStep
|
|
9379
9544
|
} = {}) {
|
|
9380
9545
|
this.closeStreamAction = async () => {
|
|
9381
9546
|
};
|
|
@@ -9411,7 +9576,7 @@ var Run = class {
|
|
|
9411
9576
|
controller.close();
|
|
9412
9577
|
}
|
|
9413
9578
|
} catch (err) {
|
|
9414
|
-
|
|
9579
|
+
self.mastra?.getLogger()?.error("Error closing stream:", err);
|
|
9415
9580
|
}
|
|
9416
9581
|
};
|
|
9417
9582
|
const executionResultsPromise = self._resume({
|
|
@@ -9425,7 +9590,8 @@ var Run = class {
|
|
|
9425
9590
|
},
|
|
9426
9591
|
isVNext: true,
|
|
9427
9592
|
forEachIndex,
|
|
9428
|
-
outputOptions
|
|
9593
|
+
outputOptions,
|
|
9594
|
+
perStep
|
|
9429
9595
|
});
|
|
9430
9596
|
self.executionResults = executionResultsPromise;
|
|
9431
9597
|
let executionResults;
|
|
@@ -9462,14 +9628,22 @@ var Run = class {
|
|
|
9462
9628
|
const nestedWatchCb = (event) => {
|
|
9463
9629
|
if (event.runId === this.runId) {
|
|
9464
9630
|
const { event: nestedEvent, workflowId } = event.data;
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
|
|
9631
|
+
if (nestedEvent.type.startsWith("data-") && nestedEvent.data !== void 0) {
|
|
9632
|
+
void this.pubsub.publish(`workflow.events.v2.${this.runId}`, {
|
|
9633
|
+
type: "watch",
|
|
9634
|
+
runId: this.runId,
|
|
9635
|
+
data: nestedEvent
|
|
9636
|
+
});
|
|
9637
|
+
} else {
|
|
9638
|
+
void this.pubsub.publish(`workflow.events.v2.${this.runId}`, {
|
|
9639
|
+
type: "watch",
|
|
9640
|
+
runId: this.runId,
|
|
9641
|
+
data: {
|
|
9642
|
+
...nestedEvent,
|
|
9643
|
+
...nestedEvent.payload?.id ? { payload: { ...nestedEvent.payload, id: `${workflowId}.${nestedEvent.payload.id}` } } : {}
|
|
9644
|
+
}
|
|
9645
|
+
});
|
|
9646
|
+
}
|
|
9473
9647
|
}
|
|
9474
9648
|
};
|
|
9475
9649
|
void this.pubsub.subscribe(`workflow.events.v2.${this.runId}`, wrappedCb);
|
|
@@ -9496,7 +9670,8 @@ var Run = class {
|
|
|
9496
9670
|
return this._restart(args);
|
|
9497
9671
|
}
|
|
9498
9672
|
async _resume(params) {
|
|
9499
|
-
const
|
|
9673
|
+
const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
|
|
9674
|
+
const snapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
9500
9675
|
workflowName: this.workflowId,
|
|
9501
9676
|
runId: this.runId
|
|
9502
9677
|
});
|
|
@@ -9571,10 +9746,9 @@ var Run = class {
|
|
|
9571
9746
|
const workflowSpan = getOrCreateSpan({
|
|
9572
9747
|
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
9573
9748
|
name: `workflow run: '${this.workflowId}'`,
|
|
9749
|
+
entityType: "workflow_run" /* WORKFLOW_RUN */,
|
|
9750
|
+
entityId: this.workflowId,
|
|
9574
9751
|
input: resumeDataToUse,
|
|
9575
|
-
attributes: {
|
|
9576
|
-
workflowId: this.workflowId
|
|
9577
|
-
},
|
|
9578
9752
|
metadata: {
|
|
9579
9753
|
resourceId: this.resourceId,
|
|
9580
9754
|
runId: this.runId
|
|
@@ -9609,7 +9783,8 @@ var Run = class {
|
|
|
9609
9783
|
abortController: this.abortController,
|
|
9610
9784
|
workflowSpan,
|
|
9611
9785
|
outputOptions: params.outputOptions,
|
|
9612
|
-
outputWriter: params.outputWriter
|
|
9786
|
+
outputWriter: params.outputWriter,
|
|
9787
|
+
perStep: params.perStep
|
|
9613
9788
|
}).then((result) => {
|
|
9614
9789
|
if (!params.isVNext && result.status !== "suspended") {
|
|
9615
9790
|
this.closeStreamAction?.().catch(() => {
|
|
@@ -9633,7 +9808,8 @@ var Run = class {
|
|
|
9633
9808
|
if (this.workflowEngineType !== "default") {
|
|
9634
9809
|
throw new Error(`restart() is not supported on ${this.workflowEngineType} workflows`);
|
|
9635
9810
|
}
|
|
9636
|
-
const
|
|
9811
|
+
const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
|
|
9812
|
+
const snapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
9637
9813
|
workflowName: this.workflowId,
|
|
9638
9814
|
runId: this.runId
|
|
9639
9815
|
});
|
|
@@ -9682,9 +9858,8 @@ var Run = class {
|
|
|
9682
9858
|
const workflowSpan = getOrCreateSpan({
|
|
9683
9859
|
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
9684
9860
|
name: `workflow run: '${this.workflowId}'`,
|
|
9685
|
-
|
|
9686
|
-
|
|
9687
|
-
},
|
|
9861
|
+
entityType: "workflow_run" /* WORKFLOW_RUN */,
|
|
9862
|
+
entityId: this.workflowId,
|
|
9688
9863
|
metadata: {
|
|
9689
9864
|
resourceId: this.resourceId,
|
|
9690
9865
|
runId: this.runId
|
|
@@ -9728,12 +9903,14 @@ var Run = class {
|
|
|
9728
9903
|
outputWriter,
|
|
9729
9904
|
tracingContext,
|
|
9730
9905
|
tracingOptions,
|
|
9731
|
-
outputOptions
|
|
9906
|
+
outputOptions,
|
|
9907
|
+
perStep
|
|
9732
9908
|
}) {
|
|
9733
9909
|
if (!stepParam || Array.isArray(stepParam) && stepParam.length === 0) {
|
|
9734
9910
|
throw new Error("Step is required and must be a valid step or array of steps");
|
|
9735
9911
|
}
|
|
9736
|
-
const
|
|
9912
|
+
const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
|
|
9913
|
+
const snapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
9737
9914
|
workflowName: this.workflowId,
|
|
9738
9915
|
runId: this.runId
|
|
9739
9916
|
});
|
|
@@ -9763,7 +9940,8 @@ var Run = class {
|
|
|
9763
9940
|
nestedStepsContext,
|
|
9764
9941
|
snapshot,
|
|
9765
9942
|
initialState,
|
|
9766
|
-
graph: this.executionGraph
|
|
9943
|
+
graph: this.executionGraph,
|
|
9944
|
+
perStep
|
|
9767
9945
|
});
|
|
9768
9946
|
const requestContextToUse = requestContext ?? new RequestContext();
|
|
9769
9947
|
for (const [key, value] of Object.entries(snapshot.requestContext ?? {})) {
|
|
@@ -9775,9 +9953,8 @@ var Run = class {
|
|
|
9775
9953
|
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
9776
9954
|
name: `workflow run: '${this.workflowId}'`,
|
|
9777
9955
|
input: inputData,
|
|
9778
|
-
|
|
9779
|
-
|
|
9780
|
-
},
|
|
9956
|
+
entityType: "workflow_run" /* WORKFLOW_RUN */,
|
|
9957
|
+
entityId: this.workflowId,
|
|
9781
9958
|
metadata: {
|
|
9782
9959
|
resourceId: this.resourceId,
|
|
9783
9960
|
runId: this.runId
|
|
@@ -9803,7 +9980,8 @@ var Run = class {
|
|
|
9803
9980
|
abortController: this.abortController,
|
|
9804
9981
|
outputWriter,
|
|
9805
9982
|
workflowSpan,
|
|
9806
|
-
outputOptions
|
|
9983
|
+
outputOptions,
|
|
9984
|
+
perStep
|
|
9807
9985
|
});
|
|
9808
9986
|
if (result.status !== "suspended") {
|
|
9809
9987
|
this.cleanup?.();
|
|
@@ -9824,7 +10002,8 @@ var Run = class {
|
|
|
9824
10002
|
requestContext,
|
|
9825
10003
|
tracingContext,
|
|
9826
10004
|
tracingOptions,
|
|
9827
|
-
outputOptions
|
|
10005
|
+
outputOptions,
|
|
10006
|
+
perStep
|
|
9828
10007
|
}) {
|
|
9829
10008
|
this.closeStreamAction = async () => {
|
|
9830
10009
|
};
|
|
@@ -9849,7 +10028,7 @@ var Run = class {
|
|
|
9849
10028
|
controller.close();
|
|
9850
10029
|
}
|
|
9851
10030
|
} catch (err) {
|
|
9852
|
-
|
|
10031
|
+
self.mastra?.getLogger()?.error("Error closing stream:", err);
|
|
9853
10032
|
}
|
|
9854
10033
|
};
|
|
9855
10034
|
const executionResultsPromise = self._timeTravel({
|
|
@@ -9865,7 +10044,8 @@ var Run = class {
|
|
|
9865
10044
|
outputWriter: async (chunk) => {
|
|
9866
10045
|
void controller.enqueue(chunk);
|
|
9867
10046
|
},
|
|
9868
|
-
outputOptions
|
|
10047
|
+
outputOptions,
|
|
10048
|
+
perStep
|
|
9869
10049
|
});
|
|
9870
10050
|
self.executionResults = executionResultsPromise;
|
|
9871
10051
|
let executionResults;
|
|
@@ -10293,7 +10473,8 @@ async function processOutputStream({
|
|
|
10293
10473
|
options,
|
|
10294
10474
|
controller,
|
|
10295
10475
|
responseFromModel,
|
|
10296
|
-
includeRawChunks
|
|
10476
|
+
includeRawChunks,
|
|
10477
|
+
logger
|
|
10297
10478
|
}) {
|
|
10298
10479
|
for await (const chunk of outputStream._getBaseStream()) {
|
|
10299
10480
|
if (!chunk) {
|
|
@@ -10376,7 +10557,7 @@ async function processOutputStream({
|
|
|
10376
10557
|
abortSignal: options?.abortSignal
|
|
10377
10558
|
});
|
|
10378
10559
|
} catch (error2) {
|
|
10379
|
-
|
|
10560
|
+
logger?.error("Error calling onInputStart", error2);
|
|
10380
10561
|
}
|
|
10381
10562
|
}
|
|
10382
10563
|
if (isControllerOpen(controller)) {
|
|
@@ -10395,7 +10576,7 @@ async function processOutputStream({
|
|
|
10395
10576
|
abortSignal: options?.abortSignal
|
|
10396
10577
|
});
|
|
10397
10578
|
} catch (error2) {
|
|
10398
|
-
|
|
10579
|
+
logger?.error("Error calling onInputDelta", error2);
|
|
10399
10580
|
}
|
|
10400
10581
|
}
|
|
10401
10582
|
if (isControllerOpen(controller)) {
|
|
@@ -10470,7 +10651,8 @@ async function processOutputStream({
|
|
|
10470
10651
|
messageList.add(message, "response");
|
|
10471
10652
|
runState.setState({
|
|
10472
10653
|
isReasoning: false,
|
|
10473
|
-
reasoningDeltas: []
|
|
10654
|
+
reasoningDeltas: [],
|
|
10655
|
+
providerOptions: void 0
|
|
10474
10656
|
});
|
|
10475
10657
|
if (isControllerOpen(controller)) {
|
|
10476
10658
|
controller.enqueue(chunk);
|
|
@@ -10584,7 +10766,7 @@ async function processOutputStream({
|
|
|
10584
10766
|
}
|
|
10585
10767
|
}
|
|
10586
10768
|
}
|
|
10587
|
-
function executeStreamWithFallbackModels(models) {
|
|
10769
|
+
function executeStreamWithFallbackModels(models, logger) {
|
|
10588
10770
|
return async (callback) => {
|
|
10589
10771
|
let index = 0;
|
|
10590
10772
|
let finalResult;
|
|
@@ -10604,8 +10786,11 @@ function executeStreamWithFallbackModels(models) {
|
|
|
10604
10786
|
done = true;
|
|
10605
10787
|
break;
|
|
10606
10788
|
} catch (err) {
|
|
10789
|
+
if (err instanceof TripWire) {
|
|
10790
|
+
throw err;
|
|
10791
|
+
}
|
|
10607
10792
|
attempt++;
|
|
10608
|
-
|
|
10793
|
+
logger?.error(`Error executing model ${modelConfig.model.modelId}, attempt ${attempt}====`, err);
|
|
10609
10794
|
if (attempt > maxRetries) {
|
|
10610
10795
|
break;
|
|
10611
10796
|
}
|
|
@@ -10615,7 +10800,7 @@ function executeStreamWithFallbackModels(models) {
|
|
|
10615
10800
|
}
|
|
10616
10801
|
}
|
|
10617
10802
|
if (typeof finalResult === "undefined") {
|
|
10618
|
-
|
|
10803
|
+
logger?.error("Exhausted all fallback models and reached the maximum number of retries.");
|
|
10619
10804
|
throw new Error("Exhausted all fallback models and reached the maximum number of retries.");
|
|
10620
10805
|
}
|
|
10621
10806
|
return finalResult;
|
|
@@ -10656,11 +10841,15 @@ function createLLMExecutionStep({
|
|
|
10656
10841
|
inputSchema: llmIterationOutputSchema,
|
|
10657
10842
|
outputSchema: llmIterationOutputSchema,
|
|
10658
10843
|
execute: async ({ inputData, bail, tracingContext }) => {
|
|
10844
|
+
modelSpanTracker?.startStep();
|
|
10659
10845
|
let modelResult;
|
|
10660
10846
|
let warnings;
|
|
10661
10847
|
let request;
|
|
10662
10848
|
let rawResponse;
|
|
10663
|
-
const { outputStream, callBail, runState, stepTools } = await executeStreamWithFallbackModels(
|
|
10849
|
+
const { outputStream, callBail, runState, stepTools } = await executeStreamWithFallbackModels(
|
|
10850
|
+
models,
|
|
10851
|
+
logger
|
|
10852
|
+
)(async (modelConfig, isLastModel) => {
|
|
10664
10853
|
const model = modelConfig.model;
|
|
10665
10854
|
const modelHeaders = modelConfig.headers;
|
|
10666
10855
|
if (initialSystemMessages) {
|
|
@@ -10707,7 +10896,46 @@ function createLLMExecutionStep({
|
|
|
10707
10896
|
});
|
|
10708
10897
|
Object.assign(currentStep, processInputStepResult);
|
|
10709
10898
|
} catch (error) {
|
|
10710
|
-
|
|
10899
|
+
if (error instanceof TripWire) {
|
|
10900
|
+
if (isControllerOpen(controller)) {
|
|
10901
|
+
controller.enqueue({
|
|
10902
|
+
type: "tripwire",
|
|
10903
|
+
runId,
|
|
10904
|
+
from: "AGENT" /* AGENT */,
|
|
10905
|
+
payload: {
|
|
10906
|
+
reason: error.message,
|
|
10907
|
+
retry: error.options?.retry,
|
|
10908
|
+
metadata: error.options?.metadata,
|
|
10909
|
+
processorId: error.processorId
|
|
10910
|
+
}
|
|
10911
|
+
});
|
|
10912
|
+
}
|
|
10913
|
+
const runState3 = new AgenticRunState({
|
|
10914
|
+
_internal,
|
|
10915
|
+
model
|
|
10916
|
+
});
|
|
10917
|
+
return {
|
|
10918
|
+
callBail: true,
|
|
10919
|
+
outputStream: new MastraModelOutput({
|
|
10920
|
+
model: {
|
|
10921
|
+
modelId: model.modelId,
|
|
10922
|
+
provider: model.provider,
|
|
10923
|
+
version: model.specificationVersion
|
|
10924
|
+
},
|
|
10925
|
+
stream: new ReadableStream$1({
|
|
10926
|
+
start(c) {
|
|
10927
|
+
c.close();
|
|
10928
|
+
}
|
|
10929
|
+
}),
|
|
10930
|
+
messageList,
|
|
10931
|
+
messageId,
|
|
10932
|
+
options: { runId }
|
|
10933
|
+
}),
|
|
10934
|
+
runState: runState3,
|
|
10935
|
+
stepTools: tools
|
|
10936
|
+
};
|
|
10937
|
+
}
|
|
10938
|
+
logger?.error("Error in processInputStep processors:", error);
|
|
10711
10939
|
throw error;
|
|
10712
10940
|
}
|
|
10713
10941
|
}
|
|
@@ -10740,7 +10968,8 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
|
|
|
10740
10968
|
resumeData can not be an empty object nor null/undefined.
|
|
10741
10969
|
When you find that and call that tool, add the resumeData to the tool call arguments/input.
|
|
10742
10970
|
Also, add the runId of the suspended tool as suspendedToolRunId to the tool call arguments/input.
|
|
10743
|
-
If the suspendedTool.type is 'approval', resumeData will be an object that contains 'approved' which can either be true or false depending on the user's message
|
|
10971
|
+
If the suspendedTool.type is 'approval', resumeData will be an object that contains 'approved' which can either be true or false depending on the user's message. If you can't construct resumeData from the message for approval type, set approved to true and add resumeData: { approved: true } to the tool call arguments/input.
|
|
10972
|
+
`;
|
|
10744
10973
|
}
|
|
10745
10974
|
return message;
|
|
10746
10975
|
});
|
|
@@ -10832,10 +11061,11 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
|
|
|
10832
11061
|
warnings,
|
|
10833
11062
|
request,
|
|
10834
11063
|
rawResponse
|
|
10835
|
-
}
|
|
11064
|
+
},
|
|
11065
|
+
logger
|
|
10836
11066
|
});
|
|
10837
11067
|
} catch (error) {
|
|
10838
|
-
|
|
11068
|
+
logger?.error("Error in LLM Execution Step", error);
|
|
10839
11069
|
if (isAbortError(error) && options?.abortSignal?.aborted) {
|
|
10840
11070
|
await options?.onAbort?.({
|
|
10841
11071
|
steps: inputData?.output?.steps ?? []
|
|
@@ -10954,6 +11184,7 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
|
|
|
10954
11184
|
}));
|
|
10955
11185
|
const currentRetryCount = inputData.processorRetryCount || 0;
|
|
10956
11186
|
await processorRunner.runProcessOutputStep({
|
|
11187
|
+
steps: inputData.output?.steps ?? [],
|
|
10957
11188
|
messages: messageList.get.all.db(),
|
|
10958
11189
|
messageList,
|
|
10959
11190
|
stepNumber,
|
|
@@ -10968,7 +11199,7 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
|
|
|
10968
11199
|
if (error instanceof TripWire) {
|
|
10969
11200
|
processOutputStepTripwire = error;
|
|
10970
11201
|
} else {
|
|
10971
|
-
|
|
11202
|
+
logger?.error("Error in processOutputStep processors:", error);
|
|
10972
11203
|
throw error;
|
|
10973
11204
|
}
|
|
10974
11205
|
}
|
|
@@ -11234,7 +11465,8 @@ function createToolCallStep({
|
|
|
11234
11465
|
runId,
|
|
11235
11466
|
streamState,
|
|
11236
11467
|
modelSpanTracker,
|
|
11237
|
-
_internal
|
|
11468
|
+
_internal,
|
|
11469
|
+
logger
|
|
11238
11470
|
}) {
|
|
11239
11471
|
return createStep({
|
|
11240
11472
|
id: "toolCallStep",
|
|
@@ -11301,7 +11533,7 @@ function createToolCallStep({
|
|
|
11301
11533
|
try {
|
|
11302
11534
|
await saveQueueManager.flushMessages(messageList, threadId, memoryConfig);
|
|
11303
11535
|
} catch (error) {
|
|
11304
|
-
|
|
11536
|
+
logger?.error("Error removing tool suspension metadata:", error);
|
|
11305
11537
|
}
|
|
11306
11538
|
}
|
|
11307
11539
|
}
|
|
@@ -11325,7 +11557,7 @@ function createToolCallStep({
|
|
|
11325
11557
|
}
|
|
11326
11558
|
await saveQueueManager.flushMessages(messageList, threadId, memoryConfig);
|
|
11327
11559
|
} catch (error) {
|
|
11328
|
-
|
|
11560
|
+
logger?.error("Error flushing messages before suspension:", error);
|
|
11329
11561
|
}
|
|
11330
11562
|
};
|
|
11331
11563
|
if (inputData.providerExecuted) {
|
|
@@ -11346,7 +11578,7 @@ function createToolCallStep({
|
|
|
11346
11578
|
abortSignal: options?.abortSignal
|
|
11347
11579
|
});
|
|
11348
11580
|
} catch (error) {
|
|
11349
|
-
|
|
11581
|
+
logger?.error("Error calling onInputAvailable", error);
|
|
11350
11582
|
}
|
|
11351
11583
|
}
|
|
11352
11584
|
if (!tool2.execute) {
|
|
@@ -11363,7 +11595,17 @@ function createToolCallStep({
|
|
|
11363
11595
|
}
|
|
11364
11596
|
const resumeData = resumeDataFromArgs ?? workflowResumeData;
|
|
11365
11597
|
const isResumeToolCall = !!resumeDataFromArgs;
|
|
11366
|
-
|
|
11598
|
+
let toolRequiresApproval = requireToolApproval || tool2.requireApproval;
|
|
11599
|
+
if (tool2.needsApprovalFn) {
|
|
11600
|
+
try {
|
|
11601
|
+
const needsApprovalResult = await tool2.needsApprovalFn(args);
|
|
11602
|
+
toolRequiresApproval = needsApprovalResult;
|
|
11603
|
+
} catch (error) {
|
|
11604
|
+
logger?.error(`Error evaluating needsApprovalFn for tool ${inputData.toolName}:`, error);
|
|
11605
|
+
toolRequiresApproval = true;
|
|
11606
|
+
}
|
|
11607
|
+
}
|
|
11608
|
+
if (toolRequiresApproval) {
|
|
11367
11609
|
if (!resumeData) {
|
|
11368
11610
|
controller.enqueue({
|
|
11369
11611
|
type: "tool-call-approval",
|
|
@@ -11464,7 +11706,7 @@ function createToolCallStep({
|
|
|
11464
11706
|
abortSignal: options?.abortSignal
|
|
11465
11707
|
});
|
|
11466
11708
|
} catch (error) {
|
|
11467
|
-
|
|
11709
|
+
logger?.error("Error calling onOutput", error);
|
|
11468
11710
|
}
|
|
11469
11711
|
}
|
|
11470
11712
|
return { result, ...inputData };
|
|
@@ -11626,11 +11868,10 @@ function createAgenticLoopWorkflow(params) {
|
|
|
11626
11868
|
};
|
|
11627
11869
|
accumulatedSteps.push(currentStep);
|
|
11628
11870
|
if (rest.stopWhen && typedInputData.stepResult?.isContinued && accumulatedSteps.length > 0) {
|
|
11871
|
+
const steps = accumulatedSteps;
|
|
11629
11872
|
const conditions = await Promise.all(
|
|
11630
11873
|
(Array.isArray(rest.stopWhen) ? rest.stopWhen : [rest.stopWhen]).map((condition) => {
|
|
11631
|
-
return condition({
|
|
11632
|
-
steps: accumulatedSteps
|
|
11633
|
-
});
|
|
11874
|
+
return condition({ steps });
|
|
11634
11875
|
})
|
|
11635
11876
|
);
|
|
11636
11877
|
const hasStopped = conditions.some((condition) => condition);
|
|
@@ -12076,8 +12317,6 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
12076
12317
|
messages: [...messageList.getSystemMessages(), ...messages]
|
|
12077
12318
|
},
|
|
12078
12319
|
attributes: {
|
|
12079
|
-
agentId,
|
|
12080
|
-
agentName,
|
|
12081
12320
|
model: firstModel.modelId,
|
|
12082
12321
|
provider: firstModel.provider,
|
|
12083
12322
|
streaming: true,
|
|
@@ -13372,12 +13611,13 @@ var AgentLegacyHandler = class {
|
|
|
13372
13611
|
const agentSpan = getOrCreateSpan({
|
|
13373
13612
|
type: "agent_run" /* AGENT_RUN */,
|
|
13374
13613
|
name: `agent run: '${this.capabilities.id}'`,
|
|
13614
|
+
entityType: "agent" /* AGENT */,
|
|
13615
|
+
entityId: this.capabilities.id,
|
|
13616
|
+
entityName: this.capabilities.name,
|
|
13375
13617
|
input: {
|
|
13376
13618
|
messages
|
|
13377
13619
|
},
|
|
13378
13620
|
attributes: {
|
|
13379
|
-
agentId: this.capabilities.id,
|
|
13380
|
-
agentName: this.capabilities.name,
|
|
13381
13621
|
instructions: this.capabilities.convertInstructionsToString(instructions),
|
|
13382
13622
|
availableTools: [
|
|
13383
13623
|
...toolsets ? Object.keys(toolsets) : [],
|
|
@@ -14440,7 +14680,10 @@ function createMapResultsStep({
|
|
|
14440
14680
|
requestContext: result.requestContext
|
|
14441
14681
|
}) : capabilities.outputProcessors : []);
|
|
14442
14682
|
if (options.structuredOutput?.model) {
|
|
14443
|
-
const structuredProcessor = new StructuredOutputProcessor(
|
|
14683
|
+
const structuredProcessor = new StructuredOutputProcessor({
|
|
14684
|
+
...options.structuredOutput,
|
|
14685
|
+
logger: capabilities.logger
|
|
14686
|
+
});
|
|
14444
14687
|
effectiveOutputProcessors = effectiveOutputProcessors ? [...effectiveOutputProcessors, structuredProcessor] : [structuredProcessor];
|
|
14445
14688
|
}
|
|
14446
14689
|
const effectiveInputProcessors = options.inputProcessors || (capabilities.inputProcessors ? typeof capabilities.inputProcessors === "function" ? await capabilities.inputProcessors({
|
|
@@ -15123,7 +15366,7 @@ var Agent = class extends MastraBase {
|
|
|
15123
15366
|
async listResolvedOutputProcessors(requestContext) {
|
|
15124
15367
|
const configuredProcessors = this.#outputProcessors ? typeof this.#outputProcessors === "function" ? await this.#outputProcessors({ requestContext: requestContext || new RequestContext() }) : this.#outputProcessors : [];
|
|
15125
15368
|
const memory = await this.getMemory({ requestContext: requestContext || new RequestContext() });
|
|
15126
|
-
const memoryProcessors = memory ? memory.getOutputProcessors(configuredProcessors, requestContext) : [];
|
|
15369
|
+
const memoryProcessors = memory ? await memory.getOutputProcessors(configuredProcessors, requestContext) : [];
|
|
15127
15370
|
const allProcessors = [...configuredProcessors, ...memoryProcessors];
|
|
15128
15371
|
return this.combineProcessorsIntoWorkflow(allProcessors, `${this.id}-output-processor`);
|
|
15129
15372
|
}
|
|
@@ -15135,7 +15378,7 @@ var Agent = class extends MastraBase {
|
|
|
15135
15378
|
async listResolvedInputProcessors(requestContext) {
|
|
15136
15379
|
const configuredProcessors = this.#inputProcessors ? typeof this.#inputProcessors === "function" ? await this.#inputProcessors({ requestContext: requestContext || new RequestContext() }) : this.#inputProcessors : [];
|
|
15137
15380
|
const memory = await this.getMemory({ requestContext: requestContext || new RequestContext() });
|
|
15138
|
-
const memoryProcessors = memory ? memory.getInputProcessors(configuredProcessors, requestContext) : [];
|
|
15381
|
+
const memoryProcessors = memory ? await memory.getInputProcessors(configuredProcessors, requestContext) : [];
|
|
15139
15382
|
const allProcessors = [...memoryProcessors, ...configuredProcessors];
|
|
15140
15383
|
return this.combineProcessorsIntoWorkflow(allProcessors, `${this.id}-input-processor`);
|
|
15141
15384
|
}
|
|
@@ -16965,10 +17208,11 @@ var Agent = class extends MastraBase {
|
|
|
16965
17208
|
const agentSpan = getOrCreateSpan({
|
|
16966
17209
|
type: "agent_run" /* AGENT_RUN */,
|
|
16967
17210
|
name: `agent run: '${this.id}'`,
|
|
17211
|
+
entityType: "agent" /* AGENT */,
|
|
17212
|
+
entityId: this.id,
|
|
17213
|
+
entityName: this.name,
|
|
16968
17214
|
input: options.messages,
|
|
16969
17215
|
attributes: {
|
|
16970
|
-
agentId: this.id,
|
|
16971
|
-
agentName: this.name,
|
|
16972
17216
|
conversationId: threadFromArgs?.id,
|
|
16973
17217
|
instructions: this.#convertInstructionsToString(instructions)
|
|
16974
17218
|
},
|
|
@@ -17391,7 +17635,8 @@ var Agent = class extends MastraBase {
|
|
|
17391
17635
|
text: "V1 models are not supported for stream. Please use streamLegacy instead."
|
|
17392
17636
|
});
|
|
17393
17637
|
}
|
|
17394
|
-
const
|
|
17638
|
+
const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
|
|
17639
|
+
const existingSnapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
17395
17640
|
workflowName: "agentic-loop",
|
|
17396
17641
|
runId: streamOptions?.runId ?? ""
|
|
17397
17642
|
});
|
|
@@ -19459,6 +19704,50 @@ var ToolCallFilter = class {
|
|
|
19459
19704
|
}
|
|
19460
19705
|
};
|
|
19461
19706
|
|
|
19707
|
+
// src/memory/working-memory-utils.ts
|
|
19708
|
+
var WORKING_MEMORY_START_TAG = "<working_memory>";
|
|
19709
|
+
var WORKING_MEMORY_END_TAG = "</working_memory>";
|
|
19710
|
+
function extractWorkingMemoryTags(text) {
|
|
19711
|
+
const results = [];
|
|
19712
|
+
let pos = 0;
|
|
19713
|
+
while (pos < text.length) {
|
|
19714
|
+
const start = text.indexOf(WORKING_MEMORY_START_TAG, pos);
|
|
19715
|
+
if (start === -1) break;
|
|
19716
|
+
const end = text.indexOf(WORKING_MEMORY_END_TAG, start + WORKING_MEMORY_START_TAG.length);
|
|
19717
|
+
if (end === -1) break;
|
|
19718
|
+
results.push(text.substring(start, end + WORKING_MEMORY_END_TAG.length));
|
|
19719
|
+
pos = end + WORKING_MEMORY_END_TAG.length;
|
|
19720
|
+
}
|
|
19721
|
+
return results.length > 0 ? results : null;
|
|
19722
|
+
}
|
|
19723
|
+
function removeWorkingMemoryTags(text) {
|
|
19724
|
+
let result = "";
|
|
19725
|
+
let pos = 0;
|
|
19726
|
+
while (pos < text.length) {
|
|
19727
|
+
const start = text.indexOf(WORKING_MEMORY_START_TAG, pos);
|
|
19728
|
+
if (start === -1) {
|
|
19729
|
+
result += text.substring(pos);
|
|
19730
|
+
break;
|
|
19731
|
+
}
|
|
19732
|
+
result += text.substring(pos, start);
|
|
19733
|
+
const end = text.indexOf(WORKING_MEMORY_END_TAG, start + WORKING_MEMORY_START_TAG.length);
|
|
19734
|
+
if (end === -1) {
|
|
19735
|
+
result += text.substring(start);
|
|
19736
|
+
break;
|
|
19737
|
+
}
|
|
19738
|
+
pos = end + WORKING_MEMORY_END_TAG.length;
|
|
19739
|
+
}
|
|
19740
|
+
return result;
|
|
19741
|
+
}
|
|
19742
|
+
function extractWorkingMemoryContent(text) {
|
|
19743
|
+
const start = text.indexOf(WORKING_MEMORY_START_TAG);
|
|
19744
|
+
if (start === -1) return null;
|
|
19745
|
+
const contentStart = start + WORKING_MEMORY_START_TAG.length;
|
|
19746
|
+
const end = text.indexOf(WORKING_MEMORY_END_TAG, contentStart);
|
|
19747
|
+
if (end === -1) return null;
|
|
19748
|
+
return text.substring(contentStart, end);
|
|
19749
|
+
}
|
|
19750
|
+
|
|
19462
19751
|
// src/processors/memory/message-history.ts
|
|
19463
19752
|
var MessageHistory = class {
|
|
19464
19753
|
id = "message-history";
|
|
@@ -19501,25 +19790,43 @@ var MessageHistory = class {
|
|
|
19501
19790
|
}
|
|
19502
19791
|
return messageList;
|
|
19503
19792
|
}
|
|
19504
|
-
|
|
19793
|
+
/**
|
|
19794
|
+
* Filters messages before persisting to storage:
|
|
19795
|
+
* 1. Removes incomplete tool calls (state === 'call' or 'partial-call')
|
|
19796
|
+
* 2. Removes updateWorkingMemory tool invocations (hide args from message history)
|
|
19797
|
+
* 3. Strips <working_memory> tags from text content
|
|
19798
|
+
*/
|
|
19799
|
+
filterMessagesForPersistence(messages) {
|
|
19505
19800
|
return messages.map((m) => {
|
|
19506
|
-
|
|
19507
|
-
|
|
19508
|
-
|
|
19509
|
-
|
|
19510
|
-
|
|
19511
|
-
|
|
19512
|
-
|
|
19513
|
-
|
|
19514
|
-
|
|
19515
|
-
|
|
19516
|
-
|
|
19801
|
+
const newMessage = { ...m };
|
|
19802
|
+
if (m.content && typeof m.content === "object" && !Array.isArray(m.content)) {
|
|
19803
|
+
newMessage.content = { ...m.content };
|
|
19804
|
+
}
|
|
19805
|
+
if (typeof newMessage.content?.content === "string" && newMessage.content.content.length > 0) {
|
|
19806
|
+
newMessage.content.content = removeWorkingMemoryTags(newMessage.content.content).trim();
|
|
19807
|
+
}
|
|
19808
|
+
if (Array.isArray(newMessage.content?.parts)) {
|
|
19809
|
+
newMessage.content.parts = newMessage.content.parts.map((p) => {
|
|
19810
|
+
if (p.type === `tool-invocation` && (p.toolInvocation.state === `call` || p.toolInvocation.state === `partial-call`)) {
|
|
19811
|
+
return null;
|
|
19517
19812
|
}
|
|
19518
|
-
|
|
19519
|
-
|
|
19520
|
-
|
|
19813
|
+
if (p.type === `tool-invocation` && p.toolInvocation.toolName === `updateWorkingMemory`) {
|
|
19814
|
+
return null;
|
|
19815
|
+
}
|
|
19816
|
+
if (p.type === `text`) {
|
|
19817
|
+
const text = typeof p.text === "string" ? p.text : "";
|
|
19818
|
+
return {
|
|
19819
|
+
...p,
|
|
19820
|
+
text: removeWorkingMemoryTags(text).trim()
|
|
19821
|
+
};
|
|
19822
|
+
}
|
|
19823
|
+
return p;
|
|
19824
|
+
}).filter((p) => Boolean(p));
|
|
19825
|
+
if (newMessage.content.parts.length === 0) {
|
|
19826
|
+
return null;
|
|
19827
|
+
}
|
|
19521
19828
|
}
|
|
19522
|
-
return
|
|
19829
|
+
return newMessage;
|
|
19523
19830
|
}).filter((m) => Boolean(m));
|
|
19524
19831
|
}
|
|
19525
19832
|
async processOutputResult(args) {
|
|
@@ -19536,7 +19843,7 @@ var MessageHistory = class {
|
|
|
19536
19843
|
if (messagesToSave.length === 0) {
|
|
19537
19844
|
return messageList;
|
|
19538
19845
|
}
|
|
19539
|
-
const filtered = this.
|
|
19846
|
+
const filtered = this.filterMessagesForPersistence(messagesToSave);
|
|
19540
19847
|
await this.storage.saveMessages({ messages: filtered });
|
|
19541
19848
|
const thread = await this.storage.getThreadById({ threadId });
|
|
19542
19849
|
if (thread) {
|
|
@@ -20150,6 +20457,7 @@ var MastraMemory = class extends MastraBase {
|
|
|
20150
20457
|
_storage;
|
|
20151
20458
|
vector;
|
|
20152
20459
|
embedder;
|
|
20460
|
+
embedderOptions;
|
|
20153
20461
|
threadConfig = { ...memoryDefaultOptions };
|
|
20154
20462
|
#mastra;
|
|
20155
20463
|
constructor(config) {
|
|
@@ -20240,7 +20548,11 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20240
20548
|
this.vector = vector;
|
|
20241
20549
|
}
|
|
20242
20550
|
setEmbedder(embedder) {
|
|
20243
|
-
|
|
20551
|
+
if (typeof embedder === "string") {
|
|
20552
|
+
this.embedder = new ModelRouterEmbeddingModel(embedder);
|
|
20553
|
+
} else {
|
|
20554
|
+
this.embedder = embedder;
|
|
20555
|
+
}
|
|
20244
20556
|
}
|
|
20245
20557
|
/**
|
|
20246
20558
|
* Get a system message to inject into the conversation.
|
|
@@ -20362,14 +20674,15 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20362
20674
|
* @param configuredProcessors - Processors already configured by the user (for deduplication)
|
|
20363
20675
|
* @returns Array of input processors configured for this memory instance
|
|
20364
20676
|
*/
|
|
20365
|
-
getInputProcessors(configuredProcessors = [], context) {
|
|
20677
|
+
async getInputProcessors(configuredProcessors = [], context) {
|
|
20678
|
+
const memoryStore = await this.storage.getStore("memory");
|
|
20366
20679
|
const processors = [];
|
|
20367
20680
|
const memoryContext = context?.get("MastraMemory");
|
|
20368
20681
|
const runtimeMemoryConfig = memoryContext?.memoryConfig;
|
|
20369
20682
|
const effectiveConfig = runtimeMemoryConfig ? this.getMergedThreadConfig(runtimeMemoryConfig) : this.threadConfig;
|
|
20370
20683
|
const isWorkingMemoryEnabled = typeof effectiveConfig.workingMemory === "object" && effectiveConfig.workingMemory.enabled !== false;
|
|
20371
20684
|
if (isWorkingMemoryEnabled) {
|
|
20372
|
-
if (!
|
|
20685
|
+
if (!memoryStore)
|
|
20373
20686
|
throw new MastraError({
|
|
20374
20687
|
category: "USER",
|
|
20375
20688
|
domain: "STORAGE" /* STORAGE */,
|
|
@@ -20387,7 +20700,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20387
20700
|
}
|
|
20388
20701
|
processors.push(
|
|
20389
20702
|
new WorkingMemory({
|
|
20390
|
-
storage:
|
|
20703
|
+
storage: memoryStore,
|
|
20391
20704
|
template,
|
|
20392
20705
|
scope: typeof effectiveConfig.workingMemory === "object" ? effectiveConfig.workingMemory.scope : void 0,
|
|
20393
20706
|
useVNext: typeof effectiveConfig.workingMemory === "object" && "version" in effectiveConfig.workingMemory && effectiveConfig.workingMemory.version === "vnext",
|
|
@@ -20398,7 +20711,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20398
20711
|
}
|
|
20399
20712
|
const lastMessages = effectiveConfig.lastMessages;
|
|
20400
20713
|
if (lastMessages) {
|
|
20401
|
-
if (!
|
|
20714
|
+
if (!memoryStore)
|
|
20402
20715
|
throw new MastraError({
|
|
20403
20716
|
category: "USER",
|
|
20404
20717
|
domain: "STORAGE" /* STORAGE */,
|
|
@@ -20409,14 +20722,14 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20409
20722
|
if (!hasMessageHistory) {
|
|
20410
20723
|
processors.push(
|
|
20411
20724
|
new MessageHistory({
|
|
20412
|
-
storage:
|
|
20725
|
+
storage: memoryStore,
|
|
20413
20726
|
lastMessages: typeof lastMessages === "number" ? lastMessages : void 0
|
|
20414
20727
|
})
|
|
20415
20728
|
);
|
|
20416
20729
|
}
|
|
20417
20730
|
}
|
|
20418
20731
|
if (effectiveConfig.semanticRecall) {
|
|
20419
|
-
if (!
|
|
20732
|
+
if (!memoryStore)
|
|
20420
20733
|
throw new MastraError({
|
|
20421
20734
|
category: "USER",
|
|
20422
20735
|
domain: "STORAGE" /* STORAGE */,
|
|
@@ -20443,7 +20756,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20443
20756
|
const indexName = this.getEmbeddingIndexName();
|
|
20444
20757
|
processors.push(
|
|
20445
20758
|
new SemanticRecall({
|
|
20446
|
-
storage:
|
|
20759
|
+
storage: memoryStore,
|
|
20447
20760
|
vector: this.vector,
|
|
20448
20761
|
embedder: this.embedder,
|
|
20449
20762
|
indexName,
|
|
@@ -20460,7 +20773,8 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20460
20773
|
* @param configuredProcessors - Processors already configured by the user (for deduplication)
|
|
20461
20774
|
* @returns Array of output processors configured for this memory instance
|
|
20462
20775
|
*/
|
|
20463
|
-
getOutputProcessors(configuredProcessors = [], context) {
|
|
20776
|
+
async getOutputProcessors(configuredProcessors = [], context) {
|
|
20777
|
+
const memoryStore = await this.storage.getStore("memory");
|
|
20464
20778
|
const processors = [];
|
|
20465
20779
|
const memoryContext = context?.get("MastraMemory");
|
|
20466
20780
|
const runtimeMemoryConfig = memoryContext?.memoryConfig;
|
|
@@ -20469,7 +20783,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20469
20783
|
return [];
|
|
20470
20784
|
}
|
|
20471
20785
|
if (effectiveConfig.semanticRecall) {
|
|
20472
|
-
if (!
|
|
20786
|
+
if (!memoryStore)
|
|
20473
20787
|
throw new MastraError({
|
|
20474
20788
|
category: "USER",
|
|
20475
20789
|
domain: "STORAGE" /* STORAGE */,
|
|
@@ -20496,7 +20810,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20496
20810
|
const indexName = this.getEmbeddingIndexName();
|
|
20497
20811
|
processors.push(
|
|
20498
20812
|
new SemanticRecall({
|
|
20499
|
-
storage:
|
|
20813
|
+
storage: memoryStore,
|
|
20500
20814
|
vector: this.vector,
|
|
20501
20815
|
embedder: this.embedder,
|
|
20502
20816
|
indexName,
|
|
@@ -20507,7 +20821,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20507
20821
|
}
|
|
20508
20822
|
const lastMessages = effectiveConfig.lastMessages;
|
|
20509
20823
|
if (lastMessages) {
|
|
20510
|
-
if (!
|
|
20824
|
+
if (!memoryStore)
|
|
20511
20825
|
throw new MastraError({
|
|
20512
20826
|
category: "USER",
|
|
20513
20827
|
domain: "STORAGE" /* STORAGE */,
|
|
@@ -20518,7 +20832,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20518
20832
|
if (!hasMessageHistory) {
|
|
20519
20833
|
processors.push(
|
|
20520
20834
|
new MessageHistory({
|
|
20521
|
-
storage:
|
|
20835
|
+
storage: memoryStore,
|
|
20522
20836
|
lastMessages: typeof lastMessages === "number" ? lastMessages : void 0
|
|
20523
20837
|
})
|
|
20524
20838
|
);
|
|
@@ -20545,22 +20859,39 @@ var MockMemory = class extends MastraMemory {
|
|
|
20545
20859
|
});
|
|
20546
20860
|
this._hasOwnStorage = true;
|
|
20547
20861
|
}
|
|
20862
|
+
async getMemoryStore() {
|
|
20863
|
+
const store = await this.storage.getStore("memory");
|
|
20864
|
+
if (!store) {
|
|
20865
|
+
throw new MastraError({
|
|
20866
|
+
id: "MASTRA_MEMORY_STORAGE_NOT_AVAILABLE",
|
|
20867
|
+
domain: "MASTRA_MEMORY" /* MASTRA_MEMORY */,
|
|
20868
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
20869
|
+
text: "Memory storage is not supported by this storage adapter"
|
|
20870
|
+
});
|
|
20871
|
+
}
|
|
20872
|
+
return store;
|
|
20873
|
+
}
|
|
20548
20874
|
async getThreadById({ threadId }) {
|
|
20549
|
-
|
|
20875
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20876
|
+
return memoryStorage.getThreadById({ threadId });
|
|
20550
20877
|
}
|
|
20551
20878
|
async saveThread({ thread }) {
|
|
20552
|
-
|
|
20879
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20880
|
+
return memoryStorage.saveThread({ thread });
|
|
20553
20881
|
}
|
|
20554
20882
|
async saveMessages({
|
|
20555
20883
|
messages
|
|
20556
20884
|
}) {
|
|
20557
|
-
|
|
20885
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20886
|
+
return memoryStorage.saveMessages({ messages });
|
|
20558
20887
|
}
|
|
20559
20888
|
async listThreadsByResourceId(args) {
|
|
20560
|
-
|
|
20889
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20890
|
+
return memoryStorage.listThreadsByResourceId(args);
|
|
20561
20891
|
}
|
|
20562
20892
|
async recall(args) {
|
|
20563
|
-
const
|
|
20893
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20894
|
+
const result = await memoryStorage.listMessages({
|
|
20564
20895
|
threadId: args.threadId,
|
|
20565
20896
|
resourceId: args.resourceId,
|
|
20566
20897
|
perPage: args.perPage,
|
|
@@ -20572,11 +20903,13 @@ var MockMemory = class extends MastraMemory {
|
|
|
20572
20903
|
return result;
|
|
20573
20904
|
}
|
|
20574
20905
|
async deleteThread(threadId) {
|
|
20575
|
-
|
|
20906
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20907
|
+
return memoryStorage.deleteThread({ threadId });
|
|
20576
20908
|
}
|
|
20577
20909
|
async deleteMessages(messageIds) {
|
|
20910
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20578
20911
|
const ids = Array.isArray(messageIds) ? messageIds?.map((item) => typeof item === "string" ? item : item.id) : [messageIds];
|
|
20579
|
-
return
|
|
20912
|
+
return memoryStorage.deleteMessages(ids);
|
|
20580
20913
|
}
|
|
20581
20914
|
async getWorkingMemory({
|
|
20582
20915
|
threadId,
|
|
@@ -20593,10 +20926,15 @@ var MockMemory = class extends MastraMemory {
|
|
|
20593
20926
|
if (!id) {
|
|
20594
20927
|
return null;
|
|
20595
20928
|
}
|
|
20596
|
-
const
|
|
20929
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20930
|
+
const resource = await memoryStorage.getResourceById({ resourceId: id });
|
|
20597
20931
|
return resource?.workingMemory || null;
|
|
20598
20932
|
}
|
|
20599
20933
|
listTools(_config) {
|
|
20934
|
+
const mergedConfig = this.getMergedThreadConfig(_config);
|
|
20935
|
+
if (!mergedConfig.workingMemory?.enabled) {
|
|
20936
|
+
return {};
|
|
20937
|
+
}
|
|
20600
20938
|
return {
|
|
20601
20939
|
updateWorkingMemory: createTool({
|
|
20602
20940
|
id: "update-working-memory",
|
|
@@ -20681,7 +21019,8 @@ var MockMemory = class extends MastraMemory {
|
|
|
20681
21019
|
if (!id) {
|
|
20682
21020
|
throw new Error(`Cannot update working memory: ${scope} ID is required`);
|
|
20683
21021
|
}
|
|
20684
|
-
await this.
|
|
21022
|
+
const memoryStorage = await this.getMemoryStore();
|
|
21023
|
+
await memoryStorage.updateResource({
|
|
20685
21024
|
resourceId: id,
|
|
20686
21025
|
workingMemory
|
|
20687
21026
|
});
|
|
@@ -20710,6 +21049,6 @@ var MockMemory = class extends MastraMemory {
|
|
|
20710
21049
|
}
|
|
20711
21050
|
};
|
|
20712
21051
|
|
|
20713
|
-
export { AISDKV5OutputStream, Agent, BatchPartsProcessor, ChunkFrom, DefaultExecutionEngine, EventEmitterPubSub, ExecutionEngine, FilePartSchema, ImagePartSchema, LanguageDetector, MastraAgentNetworkStream, MastraMemory, MastraModelOutput, MemoryProcessor, MessageContentSchema, MessageHistory, MessagePartSchema, MockMemory, ModerationProcessor, PIIDetector, ProcessorInputPhaseSchema, ProcessorInputStepPhaseSchema, ProcessorMessageContentSchema, ProcessorMessageSchema, ProcessorOutputResultPhaseSchema, ProcessorOutputStepPhaseSchema, ProcessorOutputStreamPhaseSchema, ProcessorRunner, ProcessorState, ProcessorStepInputSchema, ProcessorStepOutputSchema, ProcessorStepSchema, PromptInjectionDetector, ReasoningPartSchema, Run, SemanticRecall, SourcePartSchema, StepStartPartSchema, StructuredOutputProcessor, SystemPromptScrubber, TextPartSchema, TokenLimiterProcessor, ToolCallFilter, ToolInvocationPartSchema, TripWire, UnicodeNormalizer, Workflow, WorkflowRunOutput, WorkingMemory, augmentWithInit, cloneStep, cloneWorkflow, convertFullStreamChunkToMastra, convertFullStreamChunkToUIMessageStream, convertMastraChunkToAISDKv5, createDeprecationProxy, createStep, createTimeTravelExecutionParams, createWorkflow, getResumeLabelsByStepId, getStepIds, getStepResult, getZodErrors, hydrateSerializedStepErrors, isProcessor, isProcessorWorkflow, isSupportedLanguageModel, loop, mapVariable, memoryDefaultOptions, parseMemoryRequestContext, resolveThreadIdFromArgs, runCountDeprecationMessage, supportedLanguageModelSpecifications, tryGenerateWithJsonFallback, tryStreamWithJsonFallback, validateStepInput, validateStepResumeData, validateStepStateData, validateStepSuspendData };
|
|
20714
|
-
//# sourceMappingURL=chunk-
|
|
20715
|
-
//# sourceMappingURL=chunk-
|
|
21052
|
+
export { AISDKV5OutputStream, Agent, BatchPartsProcessor, ChunkFrom, DefaultExecutionEngine, EventEmitterPubSub, ExecutionEngine, FilePartSchema, ImagePartSchema, LanguageDetector, MastraAgentNetworkStream, MastraMemory, MastraModelOutput, MemoryProcessor, MessageContentSchema, MessageHistory, MessagePartSchema, MockMemory, ModerationProcessor, PIIDetector, ProcessorInputPhaseSchema, ProcessorInputStepPhaseSchema, ProcessorMessageContentSchema, ProcessorMessageSchema, ProcessorOutputResultPhaseSchema, ProcessorOutputStepPhaseSchema, ProcessorOutputStreamPhaseSchema, ProcessorRunner, ProcessorState, ProcessorStepInputSchema, ProcessorStepOutputSchema, ProcessorStepSchema, PromptInjectionDetector, ReasoningPartSchema, Run, SemanticRecall, SourcePartSchema, StepStartPartSchema, StructuredOutputProcessor, SystemPromptScrubber, TextPartSchema, TokenLimiterProcessor, ToolCallFilter, ToolInvocationPartSchema, TripWire, UnicodeNormalizer, WORKING_MEMORY_END_TAG, WORKING_MEMORY_START_TAG, Workflow, WorkflowRunOutput, WorkingMemory, augmentWithInit, cloneStep, cloneWorkflow, convertFullStreamChunkToMastra, convertFullStreamChunkToUIMessageStream, convertMastraChunkToAISDKv5, createDeprecationProxy, createStep, createTimeTravelExecutionParams, createWorkflow, extractWorkingMemoryContent, extractWorkingMemoryTags, getResumeLabelsByStepId, getStepIds, getStepResult, getZodErrors, hydrateSerializedStepErrors, isProcessor, isProcessorWorkflow, isSupportedLanguageModel, loop, mapVariable, memoryDefaultOptions, parseMemoryRequestContext, removeWorkingMemoryTags, resolveThreadIdFromArgs, runCountDeprecationMessage, supportedLanguageModelSpecifications, tryGenerateWithJsonFallback, tryStreamWithJsonFallback, validateStepInput, validateStepResumeData, validateStepStateData, validateStepSuspendData };
|
|
21053
|
+
//# sourceMappingURL=chunk-F7PAZAGE.js.map
|
|
21054
|
+
//# sourceMappingURL=chunk-F7PAZAGE.js.map
|