@mastra/core 1.0.0-beta.13 → 1.0.0-beta.15
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 +477 -0
- package/dist/agent/agent-legacy.d.ts.map +1 -1
- package/dist/agent/agent.d.ts +2 -2
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +6 -7
- package/dist/agent/agent.types.d.ts.map +1 -1
- package/dist/agent/index.cjs +17 -9
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/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/trip-wire.d.ts +2 -2
- package/dist/agent/trip-wire.d.ts.map +1 -1
- package/dist/agent/utils.d.ts +4 -1
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +3 -3
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts +3 -3
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +3 -3
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts +3 -3
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
- package/dist/bundler/types.d.ts +1 -0
- package/dist/bundler/types.d.ts.map +1 -1
- package/dist/chunk-2AU5ZHBL.js +79 -0
- package/dist/chunk-2AU5ZHBL.js.map +1 -0
- package/dist/{chunk-7HEAVZRS.cjs → chunk-2OOMJRXZ.cjs} +15 -15
- package/dist/{chunk-7HEAVZRS.cjs.map → chunk-2OOMJRXZ.cjs.map} +1 -1
- package/dist/chunk-37YWZMBX.js +27 -0
- package/dist/chunk-37YWZMBX.js.map +1 -0
- package/dist/{chunk-VETAQUW3.js → chunk-3HDRO3GG.js} +790 -1206
- package/dist/chunk-3HDRO3GG.js.map +1 -0
- package/dist/{chunk-MRRFTNF4.js → chunk-4DFWV4IR.js} +3 -4
- package/dist/chunk-4DFWV4IR.js.map +1 -0
- package/dist/{chunk-373OC54J.js → chunk-4HP7CS6L.js} +7 -6
- package/dist/chunk-4HP7CS6L.js.map +1 -0
- package/dist/{chunk-62Q7K656.js → chunk-4J4M2Q5R.js} +125 -121
- package/dist/chunk-4J4M2Q5R.js.map +1 -0
- package/dist/{chunk-HWMMIRIF.cjs → chunk-4U7ZLI36.cjs} +3 -2
- package/dist/chunk-4U7ZLI36.cjs.map +1 -0
- package/dist/{chunk-Z55SJVEC.cjs → chunk-6HJFCSJ4.cjs} +7 -6
- package/dist/chunk-6HJFCSJ4.cjs.map +1 -0
- package/dist/{chunk-Y7MZ5LJT.cjs → chunk-AAX7ZOM7.cjs} +101 -102
- package/dist/chunk-AAX7ZOM7.cjs.map +1 -0
- package/dist/{chunk-WPTTKULS.js → chunk-AR5CF3IN.js} +4 -4
- package/dist/{chunk-WPTTKULS.js.map → chunk-AR5CF3IN.js.map} +1 -1
- package/dist/{chunk-5VZGJTPR.js → chunk-BAZHNX5P.js} +57 -11
- package/dist/chunk-BAZHNX5P.js.map +1 -0
- package/dist/{chunk-MLKE7HRS.cjs → chunk-BC2VKOH4.cjs} +43 -21
- package/dist/chunk-BC2VKOH4.cjs.map +1 -0
- package/dist/{chunk-2IU4RGU5.js → chunk-BCUKD2XG.js} +59 -19
- package/dist/chunk-BCUKD2XG.js.map +1 -0
- package/dist/{chunk-WYGUWVTF.js → chunk-CBQ6WDUJ.js} +9 -9
- package/dist/chunk-CBQ6WDUJ.js.map +1 -0
- package/dist/chunk-CBVHOGXX.cjs +674 -0
- package/dist/chunk-CBVHOGXX.cjs.map +1 -0
- package/dist/{chunk-PJAK4U6R.cjs → chunk-CBY37FTP.cjs} +28 -28
- package/dist/chunk-CBY37FTP.cjs.map +1 -0
- package/dist/{chunk-BQDZIQ3G.js → chunk-D2IFWD7A.js} +365 -137
- package/dist/chunk-D2IFWD7A.js.map +1 -0
- package/dist/{chunk-R5AJGM55.cjs → chunk-DDK3URK2.cjs} +987 -519
- package/dist/chunk-DDK3URK2.cjs.map +1 -0
- package/dist/chunk-DRJTNGI4.cjs +263 -0
- package/dist/chunk-DRJTNGI4.cjs.map +1 -0
- package/dist/{chunk-X6IBA7FP.cjs → chunk-EMLEZXTQ.cjs} +22 -120
- package/dist/chunk-EMLEZXTQ.cjs.map +1 -0
- package/dist/{chunk-OWIEOL55.cjs → chunk-F75EQ574.cjs} +695 -254
- package/dist/chunk-F75EQ574.cjs.map +1 -0
- package/dist/{chunk-YPLZDWG7.js → chunk-FJEVLHJT.js} +3 -2
- package/dist/chunk-FJEVLHJT.js.map +1 -0
- package/dist/chunk-GVAPYQRO.cjs +252 -0
- package/dist/chunk-GVAPYQRO.cjs.map +1 -0
- package/dist/{chunk-MXBVP7HX.cjs → chunk-GXMJ5URG.cjs} +227 -181
- package/dist/chunk-GXMJ5URG.cjs.map +1 -0
- package/dist/chunk-H2NHG7QL.cjs +32 -0
- package/dist/chunk-H2NHG7QL.cjs.map +1 -0
- package/dist/chunk-HAYBGFPA.js +259 -0
- package/dist/chunk-HAYBGFPA.js.map +1 -0
- package/dist/{chunk-GIWC35YQ.js → chunk-IHISDRFV.js} +299 -49
- package/dist/chunk-IHISDRFV.js.map +1 -0
- package/dist/{chunk-VEPP75C4.cjs → chunk-IRTICXRZ.cjs} +101 -61
- package/dist/chunk-IRTICXRZ.cjs.map +1 -0
- package/dist/{chunk-ARAQIW6E.js → chunk-K66U47VL.js} +617 -188
- package/dist/chunk-K66U47VL.js.map +1 -0
- package/dist/{chunk-LGB4VNZI.cjs → chunk-LOV5NNGK.cjs} +811 -1235
- package/dist/chunk-LOV5NNGK.cjs.map +1 -0
- package/dist/{chunk-E5BQRAJK.js → chunk-NGWTSHNA.js} +823 -362
- package/dist/chunk-NGWTSHNA.js.map +1 -0
- package/dist/{chunk-72YCRTEX.cjs → chunk-O2CAMK4A.cjs} +13 -2
- package/dist/chunk-O2CAMK4A.cjs.map +1 -0
- package/dist/{chunk-4BC5FUAO.js → chunk-O7M7DR4E.js} +6 -5
- package/dist/chunk-O7M7DR4E.js.map +1 -0
- package/dist/chunk-OTIGV7CL.js +10215 -0
- package/dist/chunk-OTIGV7CL.js.map +1 -0
- package/dist/{chunk-WYWRMIQC.js → chunk-QXL3F3T2.js} +9 -105
- package/dist/chunk-QXL3F3T2.js.map +1 -0
- package/dist/{chunk-U4CSOY6T.cjs → chunk-RA2CHJCY.cjs} +399 -171
- package/dist/chunk-RA2CHJCY.cjs.map +1 -0
- package/dist/chunk-RMV5HJM7.cjs +10237 -0
- package/dist/chunk-RMV5HJM7.cjs.map +1 -0
- package/dist/{chunk-AGHLXC4I.cjs → chunk-S23TNDXG.cjs} +300 -50
- package/dist/chunk-S23TNDXG.cjs.map +1 -0
- package/dist/{chunk-H4VUIOWU.cjs → chunk-SSB4AVHU.cjs} +20 -19
- package/dist/chunk-SSB4AVHU.cjs.map +1 -0
- package/dist/chunk-ST7NBF4H.cjs +84 -0
- package/dist/chunk-ST7NBF4H.cjs.map +1 -0
- package/dist/{chunk-SZYSDJTN.cjs → chunk-T2LVULCK.cjs} +142 -137
- package/dist/chunk-T2LVULCK.cjs.map +1 -0
- package/dist/chunk-VE6HQ7H6.js +250 -0
- package/dist/chunk-VE6HQ7H6.js.map +1 -0
- package/dist/{chunk-RCJLMMTO.js → chunk-XJB7J4UT.js} +30 -8
- package/dist/chunk-XJB7J4UT.js.map +1 -0
- package/dist/chunk-YV43YEZ6.js +598 -0
- package/dist/chunk-YV43YEZ6.js.map +1 -0
- package/dist/{chunk-Y36Y5MTD.js → chunk-ZGIVAQRI.js} +13 -3
- package/dist/chunk-ZGIVAQRI.js.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/run/index.d.ts.map +1 -1
- 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 +568 -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 +21 -21
- package/dist/llm/index.js +5 -5
- package/dist/llm/model/aisdk/generate-to-stream.d.ts +20 -0
- package/dist/llm/model/aisdk/generate-to-stream.d.ts.map +1 -0
- package/dist/llm/model/aisdk/v5/model.d.ts +4 -0
- package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -1
- package/dist/llm/model/aisdk/v6/model.d.ts +43 -0
- package/dist/llm/model/aisdk/v6/model.d.ts.map +1 -0
- 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 +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 +126 -17
- package/dist/llm/model/resolve-model.d.ts +2 -2
- package/dist/llm/model/resolve-model.d.ts.map +1 -1
- package/dist/llm/model/shared.types.d.ts +18 -7
- package/dist/llm/model/shared.types.d.ts.map +1 -1
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/network/index.d.ts +8 -8
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts.map +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV3Mock.d.ts +29 -0
- package/dist/loop/test-utils/MastraLanguageModelV3Mock.d.ts.map +1 -0
- package/dist/loop/test-utils/fullStream.d.ts +2 -1
- package/dist/loop/test-utils/fullStream.d.ts.map +1 -1
- package/dist/loop/test-utils/resultObject.d.ts +2 -1
- package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
- package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
- package/dist/loop/test-utils/utils-v3.d.ts +55 -0
- package/dist/loop/test-utils/utils-v3.d.ts.map +1 -0
- package/dist/loop/types.d.ts +10 -8
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +36 -36
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +25 -25
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +12 -12
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +36 -36
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/loop/workflows/run-state.d.ts +2 -2
- package/dist/loop/workflows/run-state.d.ts.map +1 -1
- package/dist/loop/workflows/schema.d.ts +12 -12
- 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 +4 -4
- package/dist/mcp/index.js +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-D3EKFGAO.cjs.map → models-dev-26XLUKVK.cjs.map} +1 -1
- package/dist/models-dev-HUFLQFPB.js +3 -0
- package/dist/{models-dev-EO22XOXQ.js.map → models-dev-HUFLQFPB.js.map} +1 -1
- package/dist/netlify-CUYK2MZ2.cjs +12 -0
- package/dist/{netlify-WE42TZIT.cjs.map → netlify-CUYK2MZ2.cjs.map} +1 -1
- package/dist/netlify-J4QPOROO.js +3 -0
- package/dist/{netlify-AE4LNCAI.js.map → netlify-J4QPOROO.js.map} +1 -1
- package/dist/observability/index.cjs +14 -10
- package/dist/observability/index.js +1 -1
- package/dist/observability/types/tracing.d.ts +32 -19
- package/dist/observability/types/tracing.d.ts.map +1 -1
- package/dist/processors/index.cjs +37 -37
- package/dist/processors/index.d.ts +9 -7
- 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/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/processors/step-schema.d.ts +26 -26
- package/dist/processors/step-schema.d.ts.map +1 -1
- package/dist/provider-registry-6CIGRQVZ.js +3 -0
- package/dist/{provider-registry-6LF3NGC5.js.map → provider-registry-6CIGRQVZ.js.map} +1 -1
- package/dist/provider-registry-7O7FJ4BS.cjs +40 -0
- package/dist/{provider-registry-73FKMXJV.cjs.map → provider-registry-7O7FJ4BS.cjs.map} +1 -1
- package/dist/provider-registry.json +295 -45
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.cjs.map +1 -1
- package/dist/relevance/index.js +2 -2
- package/dist/relevance/index.js.map +1 -1
- package/dist/server/index.cjs +5 -5
- package/dist/server/index.js +1 -1
- package/dist/storage/base.d.ts +40 -292
- 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 +28 -174
- package/dist/storage/mock.d.ts.map +1 -1
- package/dist/storage/types.d.ts +39 -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/execute.d.ts +4 -4
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output.d.ts +2 -2
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/transform.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts +7 -5
- 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 +32 -21
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.cjs +4 -4
- package/dist/test-utils/llm-mock.cjs.map +1 -1
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/test-utils/llm-mock.js.map +1 -1
- package/dist/token-6GSAFR2W-LTZ7QQUP.js +61 -0
- package/dist/token-6GSAFR2W-LTZ7QQUP.js.map +1 -0
- package/dist/token-6GSAFR2W-UEEINYAN.cjs +63 -0
- package/dist/token-6GSAFR2W-UEEINYAN.cjs.map +1 -0
- package/dist/token-util-NEHG7TUY-QTFZ26EN.js +8 -0
- package/dist/token-util-NEHG7TUY-QTFZ26EN.js.map +1 -0
- package/dist/token-util-NEHG7TUY-WZL2DNCG.cjs +10 -0
- package/dist/token-util-NEHG7TUY-WZL2DNCG.cjs.map +1 -0
- 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.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/toolchecks.d.ts +1 -1
- package/dist/tools/toolchecks.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 +3 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -1
- package/dist/vector/embed.d.ts +1 -0
- package/dist/vector/embed.d.ts.map +1 -1
- package/dist/vector/index.cjs +18 -5
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.js +9 -2
- package/dist/vector/index.js.map +1 -1
- package/dist/vector/vector.d.ts +26 -3
- package/dist/vector/vector.d.ts.map +1 -1
- package/dist/voice/composite-voice.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 +5 -0
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts +20 -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 +10 -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 +26 -9
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +20 -12
- package/src/llm/model/provider-types.generated.d.ts +126 -17
- package/storage/constants.d.ts +1 -0
- package/tool-loop-agent.d.ts +1 -0
- package/dist/chunk-2IU4RGU5.js.map +0 -1
- package/dist/chunk-373OC54J.js.map +0 -1
- package/dist/chunk-4BC5FUAO.js.map +0 -1
- package/dist/chunk-5VZGJTPR.js.map +0 -1
- package/dist/chunk-62Q7K656.js.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-AGHLXC4I.cjs.map +0 -1
- package/dist/chunk-ARAQIW6E.js.map +0 -1
- package/dist/chunk-BQDZIQ3G.js.map +0 -1
- package/dist/chunk-E5BQRAJK.js.map +0 -1
- package/dist/chunk-GIWC35YQ.js.map +0 -1
- package/dist/chunk-H4VUIOWU.cjs.map +0 -1
- package/dist/chunk-HWMMIRIF.cjs.map +0 -1
- package/dist/chunk-IXZ2T2QX.cjs +0 -448
- package/dist/chunk-IXZ2T2QX.cjs.map +0 -1
- package/dist/chunk-LGB4VNZI.cjs.map +0 -1
- package/dist/chunk-MLKE7HRS.cjs.map +0 -1
- package/dist/chunk-MRRFTNF4.js.map +0 -1
- package/dist/chunk-MXBVP7HX.cjs.map +0 -1
- package/dist/chunk-OWIEOL55.cjs.map +0 -1
- package/dist/chunk-PJAK4U6R.cjs.map +0 -1
- package/dist/chunk-R5AJGM55.cjs.map +0 -1
- package/dist/chunk-RCJLMMTO.js.map +0 -1
- package/dist/chunk-SZYSDJTN.cjs.map +0 -1
- package/dist/chunk-T2VLUFGG.cjs +0 -47
- package/dist/chunk-T2VLUFGG.cjs.map +0 -1
- package/dist/chunk-U4CSOY6T.cjs.map +0 -1
- package/dist/chunk-UBSPZTQX.js +0 -434
- package/dist/chunk-UBSPZTQX.js.map +0 -1
- package/dist/chunk-VEPP75C4.cjs.map +0 -1
- package/dist/chunk-VETAQUW3.js.map +0 -1
- package/dist/chunk-WYGUWVTF.js.map +0 -1
- package/dist/chunk-WYWRMIQC.js.map +0 -1
- package/dist/chunk-X6IBA7FP.cjs.map +0 -1
- package/dist/chunk-Y36Y5MTD.js.map +0 -1
- package/dist/chunk-Y7MZ5LJT.cjs.map +0 -1
- package/dist/chunk-YPLZDWG7.js.map +0 -1
- package/dist/chunk-Z55SJVEC.cjs.map +0 -1
- package/dist/llm/model/is-v2-model.d.ts +0 -3
- package/dist/llm/model/is-v2-model.d.ts.map +0 -1
- package/dist/models-dev-D3EKFGAO.cjs +0 -12
- package/dist/models-dev-EO22XOXQ.js +0 -3
- package/dist/netlify-AE4LNCAI.js +0 -3
- package/dist/netlify-WE42TZIT.cjs +0 -12
- package/dist/provider-registry-6LF3NGC5.js +0 -3
- package/dist/provider-registry-73FKMXJV.cjs +0 -40
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { validateStepInput, createDeprecationProxy, EventEmitterPubSub, getStepResult, validateStepSuspendData, runCountDeprecationMessage, createTimeTravelExecutionParams, validateStepResumeData, Workflow, Run, ExecutionEngine, hydrateSerializedStepErrors } from './chunk-
|
|
1
|
+
import { validateStepInput, createDeprecationProxy, EventEmitterPubSub, getStepResult, validateStepSuspendData, runCountDeprecationMessage, createTimeTravelExecutionParams, validateStepResumeData, Workflow, Run, ExecutionEngine, hydrateSerializedStepErrors } from './chunk-NGWTSHNA.js';
|
|
2
2
|
import { STREAM_FORMAT_SYMBOL, PUBSUB_SYMBOL } from './chunk-6PMMP3FR.js';
|
|
3
|
-
import {
|
|
3
|
+
import { getErrorFromUnknown, MastraError } from './chunk-FJEVLHJT.js';
|
|
4
|
+
import { Tool } from './chunk-4HP7CS6L.js';
|
|
4
5
|
import { RequestContext } from './chunk-6TBWJV35.js';
|
|
5
|
-
import { getErrorFromUnknown, MastraError } from './chunk-YPLZDWG7.js';
|
|
6
6
|
import { MastraBase } from './chunk-LSHPJWM5.js';
|
|
7
7
|
import { RegisteredLogger } from './chunk-NRUZYMHE.js';
|
|
8
8
|
import EventEmitter from 'events';
|
|
@@ -19,8 +19,8 @@ var StepExecutor = class extends MastraBase {
|
|
|
19
19
|
this.mastra = mastra;
|
|
20
20
|
}
|
|
21
21
|
async execute(params) {
|
|
22
|
-
const { step, stepResults, runId, requestContext, retryCount = 0 } = params;
|
|
23
|
-
const abortController = new AbortController();
|
|
22
|
+
const { step, stepResults, runId, requestContext, retryCount = 0, perStep } = params;
|
|
23
|
+
const abortController = params.abortController ?? new AbortController();
|
|
24
24
|
let suspended;
|
|
25
25
|
let bailed;
|
|
26
26
|
const startedAt = Date.now();
|
|
@@ -48,7 +48,7 @@ var StepExecutor = class extends MastraBase {
|
|
|
48
48
|
if (validationError) {
|
|
49
49
|
throw validationError;
|
|
50
50
|
}
|
|
51
|
-
const
|
|
51
|
+
const stepOutput = await step.execute(
|
|
52
52
|
createDeprecationProxy(
|
|
53
53
|
{
|
|
54
54
|
workflowId: params.workflowId,
|
|
@@ -99,6 +99,8 @@ var StepExecutor = class extends MastraBase {
|
|
|
99
99
|
}
|
|
100
100
|
)
|
|
101
101
|
);
|
|
102
|
+
const isNestedWorkflowStep = step.component === "WORKFLOW";
|
|
103
|
+
const nestedWflowStepPaused = isNestedWorkflowStep && perStep;
|
|
102
104
|
const endedAt = Date.now();
|
|
103
105
|
let finalResult;
|
|
104
106
|
if (suspended) {
|
|
@@ -106,7 +108,7 @@ var StepExecutor = class extends MastraBase {
|
|
|
106
108
|
...stepInfo,
|
|
107
109
|
status: "suspended",
|
|
108
110
|
suspendedAt: endedAt,
|
|
109
|
-
...
|
|
111
|
+
...stepOutput ? { suspendOutput: stepOutput } : {}
|
|
110
112
|
};
|
|
111
113
|
if (suspended.payload) {
|
|
112
114
|
finalResult.suspendPayload = suspended.payload;
|
|
@@ -119,12 +121,17 @@ var StepExecutor = class extends MastraBase {
|
|
|
119
121
|
endedAt,
|
|
120
122
|
output: bailed.payload
|
|
121
123
|
};
|
|
124
|
+
} else if (nestedWflowStepPaused) {
|
|
125
|
+
finalResult = {
|
|
126
|
+
...stepInfo,
|
|
127
|
+
status: "paused"
|
|
128
|
+
};
|
|
122
129
|
} else {
|
|
123
130
|
finalResult = {
|
|
124
131
|
...stepInfo,
|
|
125
132
|
status: "success",
|
|
126
133
|
endedAt,
|
|
127
|
-
output:
|
|
134
|
+
output: stepOutput
|
|
128
135
|
};
|
|
129
136
|
}
|
|
130
137
|
return finalResult;
|
|
@@ -144,7 +151,7 @@ var StepExecutor = class extends MastraBase {
|
|
|
144
151
|
}
|
|
145
152
|
async evaluateConditions(params) {
|
|
146
153
|
const { step, stepResults, runId, requestContext, retryCount = 0 } = params;
|
|
147
|
-
const abortController = new AbortController();
|
|
154
|
+
const abortController = params.abortController ?? new AbortController();
|
|
148
155
|
const ee = new EventEmitter();
|
|
149
156
|
const results = await Promise.all(
|
|
150
157
|
step.conditions.map((condition) => {
|
|
@@ -231,7 +238,7 @@ var StepExecutor = class extends MastraBase {
|
|
|
231
238
|
}
|
|
232
239
|
async resolveSleep(params) {
|
|
233
240
|
const { step, stepResults, runId, requestContext, retryCount = 0 } = params;
|
|
234
|
-
const abortController = new AbortController();
|
|
241
|
+
const abortController = params.abortController ?? new AbortController();
|
|
235
242
|
const ee = new EventEmitter();
|
|
236
243
|
if (step.duration) {
|
|
237
244
|
return step.duration;
|
|
@@ -289,7 +296,7 @@ var StepExecutor = class extends MastraBase {
|
|
|
289
296
|
}
|
|
290
297
|
async resolveSleepUntil(params) {
|
|
291
298
|
const { step, stepResults, runId, requestContext, retryCount = 0 } = params;
|
|
292
|
-
const abortController = new AbortController();
|
|
299
|
+
const abortController = params.abortController ?? new AbortController();
|
|
293
300
|
const ee = new EventEmitter();
|
|
294
301
|
if (step.date) {
|
|
295
302
|
return step.date.getTime() - Date.now();
|
|
@@ -369,7 +376,8 @@ async function processWorkflowLoop({
|
|
|
369
376
|
resumeData,
|
|
370
377
|
parentWorkflow,
|
|
371
378
|
requestContext,
|
|
372
|
-
retryCount = 0
|
|
379
|
+
retryCount = 0,
|
|
380
|
+
perStep
|
|
373
381
|
}, {
|
|
374
382
|
pubsub,
|
|
375
383
|
stepExecutor,
|
|
@@ -409,7 +417,8 @@ async function processWorkflowLoop({
|
|
|
409
417
|
prevResult: stepResult,
|
|
410
418
|
resumeData,
|
|
411
419
|
activeSteps,
|
|
412
|
-
requestContext
|
|
420
|
+
requestContext,
|
|
421
|
+
perStep
|
|
413
422
|
}
|
|
414
423
|
});
|
|
415
424
|
} else {
|
|
@@ -427,7 +436,8 @@ async function processWorkflowLoop({
|
|
|
427
436
|
resumeData,
|
|
428
437
|
activeSteps,
|
|
429
438
|
requestContext,
|
|
430
|
-
retryCount
|
|
439
|
+
retryCount,
|
|
440
|
+
perStep
|
|
431
441
|
}
|
|
432
442
|
});
|
|
433
443
|
}
|
|
@@ -447,7 +457,8 @@ async function processWorkflowLoop({
|
|
|
447
457
|
resumeData,
|
|
448
458
|
activeSteps,
|
|
449
459
|
requestContext,
|
|
450
|
-
retryCount
|
|
460
|
+
retryCount,
|
|
461
|
+
perStep
|
|
451
462
|
}
|
|
452
463
|
});
|
|
453
464
|
} else {
|
|
@@ -464,7 +475,8 @@ async function processWorkflowLoop({
|
|
|
464
475
|
prevResult: stepResult,
|
|
465
476
|
resumeData,
|
|
466
477
|
activeSteps,
|
|
467
|
-
requestContext
|
|
478
|
+
requestContext,
|
|
479
|
+
perStep
|
|
468
480
|
}
|
|
469
481
|
});
|
|
470
482
|
}
|
|
@@ -481,7 +493,8 @@ async function processWorkflowForEach({
|
|
|
481
493
|
timeTravel,
|
|
482
494
|
resumeData,
|
|
483
495
|
parentWorkflow,
|
|
484
|
-
requestContext
|
|
496
|
+
requestContext,
|
|
497
|
+
perStep
|
|
485
498
|
}, {
|
|
486
499
|
pubsub,
|
|
487
500
|
mastra,
|
|
@@ -505,22 +518,24 @@ async function processWorkflowForEach({
|
|
|
505
518
|
prevResult: currentResult,
|
|
506
519
|
resumeData,
|
|
507
520
|
activeSteps,
|
|
508
|
-
requestContext
|
|
521
|
+
requestContext,
|
|
522
|
+
perStep
|
|
509
523
|
}
|
|
510
524
|
});
|
|
511
525
|
return;
|
|
512
526
|
} else if (idx >= targetLen) {
|
|
513
527
|
return;
|
|
514
528
|
}
|
|
529
|
+
const workflowsStore = await mastra.getStorage()?.getStore("workflows");
|
|
515
530
|
if (executionPath.length === 1 && idx === 0) {
|
|
516
531
|
const concurrency = Math.min(step.opts.concurrency ?? 1, targetLen);
|
|
517
532
|
const dummyResult = Array.from({ length: concurrency }, () => null);
|
|
518
|
-
await
|
|
533
|
+
await workflowsStore?.updateWorkflowResults({
|
|
519
534
|
workflowName: workflowId,
|
|
520
535
|
runId,
|
|
521
536
|
stepId: step.step.id,
|
|
522
537
|
result: {
|
|
523
|
-
status: "
|
|
538
|
+
status: "success",
|
|
524
539
|
output: dummyResult,
|
|
525
540
|
startedAt: Date.now(),
|
|
526
541
|
payload: prevResult?.output
|
|
@@ -542,19 +557,20 @@ async function processWorkflowForEach({
|
|
|
542
557
|
prevResult,
|
|
543
558
|
resumeData,
|
|
544
559
|
activeSteps,
|
|
545
|
-
requestContext
|
|
560
|
+
requestContext,
|
|
561
|
+
perStep
|
|
546
562
|
}
|
|
547
563
|
});
|
|
548
564
|
}
|
|
549
565
|
return;
|
|
550
566
|
}
|
|
551
567
|
currentResult.output.push(null);
|
|
552
|
-
await
|
|
568
|
+
await workflowsStore?.updateWorkflowResults({
|
|
553
569
|
workflowName: workflowId,
|
|
554
570
|
runId,
|
|
555
571
|
stepId: step.step.id,
|
|
556
572
|
result: {
|
|
557
|
-
status: "
|
|
573
|
+
status: "success",
|
|
558
574
|
output: currentResult.output,
|
|
559
575
|
startedAt: Date.now(),
|
|
560
576
|
payload: prevResult?.output
|
|
@@ -575,7 +591,8 @@ async function processWorkflowForEach({
|
|
|
575
591
|
prevResult,
|
|
576
592
|
resumeData,
|
|
577
593
|
activeSteps,
|
|
578
|
-
requestContext
|
|
594
|
+
requestContext,
|
|
595
|
+
perStep
|
|
579
596
|
}
|
|
580
597
|
});
|
|
581
598
|
}
|
|
@@ -590,7 +607,8 @@ async function processWorkflowParallel({
|
|
|
590
607
|
prevResult,
|
|
591
608
|
resumeData,
|
|
592
609
|
parentWorkflow,
|
|
593
|
-
requestContext
|
|
610
|
+
requestContext,
|
|
611
|
+
perStep
|
|
594
612
|
}, {
|
|
595
613
|
pubsub,
|
|
596
614
|
step
|
|
@@ -599,10 +617,13 @@ async function processWorkflowParallel({
|
|
|
599
617
|
const nestedStep = step.steps[i];
|
|
600
618
|
if (nestedStep?.type === "step") {
|
|
601
619
|
activeSteps[nestedStep.step.id] = true;
|
|
620
|
+
if (perStep) {
|
|
621
|
+
break;
|
|
622
|
+
}
|
|
602
623
|
}
|
|
603
624
|
}
|
|
604
625
|
await Promise.all(
|
|
605
|
-
step.steps.map(async (_step, idx) => {
|
|
626
|
+
step.steps?.filter((step2) => activeSteps[step2.step.id]).map(async (_step, idx) => {
|
|
606
627
|
return pubsub.publish("workflows", {
|
|
607
628
|
type: "workflow.step.run",
|
|
608
629
|
runId,
|
|
@@ -617,7 +638,8 @@ async function processWorkflowParallel({
|
|
|
617
638
|
timeTravel,
|
|
618
639
|
parentWorkflow,
|
|
619
640
|
activeSteps,
|
|
620
|
-
requestContext
|
|
641
|
+
requestContext,
|
|
642
|
+
perStep
|
|
621
643
|
}
|
|
622
644
|
});
|
|
623
645
|
})
|
|
@@ -634,7 +656,8 @@ async function processWorkflowConditional({
|
|
|
634
656
|
prevResult,
|
|
635
657
|
resumeData,
|
|
636
658
|
parentWorkflow,
|
|
637
|
-
requestContext
|
|
659
|
+
requestContext,
|
|
660
|
+
perStep
|
|
638
661
|
}, {
|
|
639
662
|
pubsub,
|
|
640
663
|
stepExecutor,
|
|
@@ -658,49 +681,79 @@ async function processWorkflowConditional({
|
|
|
658
681
|
for (let i = 0; i < idxs.length; i++) {
|
|
659
682
|
truthyIdxs[idxs[i]] = true;
|
|
660
683
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
684
|
+
let onlyStepToRun;
|
|
685
|
+
if (perStep) {
|
|
686
|
+
const stepsToRun = step.steps.filter((_, idx) => truthyIdxs[idx]);
|
|
687
|
+
onlyStepToRun = stepsToRun[0];
|
|
688
|
+
}
|
|
689
|
+
if (onlyStepToRun) {
|
|
690
|
+
activeSteps[onlyStepToRun.step.id] = true;
|
|
691
|
+
const stepIndex = step.steps.findIndex((step2) => step2.step.id === onlyStepToRun.step.id);
|
|
692
|
+
await pubsub.publish("workflows", {
|
|
693
|
+
type: "workflow.step.run",
|
|
694
|
+
runId,
|
|
695
|
+
data: {
|
|
696
|
+
workflowId,
|
|
697
|
+
runId,
|
|
698
|
+
executionPath: executionPath.concat([stepIndex]),
|
|
699
|
+
resumeSteps,
|
|
700
|
+
stepResults,
|
|
701
|
+
timeTravel,
|
|
702
|
+
prevResult,
|
|
703
|
+
resumeData,
|
|
704
|
+
parentWorkflow,
|
|
705
|
+
activeSteps,
|
|
706
|
+
requestContext,
|
|
707
|
+
perStep
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
} else {
|
|
711
|
+
await Promise.all(
|
|
712
|
+
step.steps.map(async (step2, idx) => {
|
|
713
|
+
if (truthyIdxs[idx]) {
|
|
714
|
+
if (step2?.type === "step") {
|
|
715
|
+
activeSteps[step2.step.id] = true;
|
|
682
716
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
return pubsub.publish("workflows", {
|
|
686
|
-
type: "workflow.step.end",
|
|
687
|
-
runId,
|
|
688
|
-
data: {
|
|
689
|
-
workflowId,
|
|
717
|
+
return pubsub.publish("workflows", {
|
|
718
|
+
type: "workflow.step.run",
|
|
690
719
|
runId,
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
720
|
+
data: {
|
|
721
|
+
workflowId,
|
|
722
|
+
runId,
|
|
723
|
+
executionPath: executionPath.concat([idx]),
|
|
724
|
+
resumeSteps,
|
|
725
|
+
stepResults,
|
|
726
|
+
timeTravel,
|
|
727
|
+
prevResult,
|
|
728
|
+
resumeData,
|
|
729
|
+
parentWorkflow,
|
|
730
|
+
activeSteps,
|
|
731
|
+
requestContext,
|
|
732
|
+
perStep
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
} else {
|
|
736
|
+
return pubsub.publish("workflows", {
|
|
737
|
+
type: "workflow.step.end",
|
|
738
|
+
runId,
|
|
739
|
+
data: {
|
|
740
|
+
workflowId,
|
|
741
|
+
runId,
|
|
742
|
+
executionPath: executionPath.concat([idx]),
|
|
743
|
+
resumeSteps,
|
|
744
|
+
stepResults,
|
|
745
|
+
prevResult: { status: "skipped" },
|
|
746
|
+
resumeData,
|
|
747
|
+
parentWorkflow,
|
|
748
|
+
activeSteps,
|
|
749
|
+
requestContext,
|
|
750
|
+
perStep
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
})
|
|
755
|
+
);
|
|
756
|
+
}
|
|
704
757
|
}
|
|
705
758
|
async function processWorkflowWaitForEvent(workflowData, {
|
|
706
759
|
pubsub,
|
|
@@ -729,7 +782,8 @@ async function processWorkflowWaitForEvent(workflowData, {
|
|
|
729
782
|
stepResults: currentState?.context,
|
|
730
783
|
prevResult,
|
|
731
784
|
activeSteps: [],
|
|
732
|
-
requestContext: currentState?.requestContext
|
|
785
|
+
requestContext: currentState?.requestContext,
|
|
786
|
+
perStep: workflowData.perStep
|
|
733
787
|
}
|
|
734
788
|
});
|
|
735
789
|
}
|
|
@@ -744,7 +798,8 @@ async function processWorkflowSleep({
|
|
|
744
798
|
prevResult,
|
|
745
799
|
resumeData,
|
|
746
800
|
parentWorkflow,
|
|
747
|
-
requestContext
|
|
801
|
+
requestContext,
|
|
802
|
+
perStep
|
|
748
803
|
}, {
|
|
749
804
|
pubsub,
|
|
750
805
|
stepExecutor,
|
|
@@ -818,7 +873,8 @@ async function processWorkflowSleep({
|
|
|
818
873
|
resumeData,
|
|
819
874
|
parentWorkflow,
|
|
820
875
|
activeSteps,
|
|
821
|
-
requestContext
|
|
876
|
+
requestContext,
|
|
877
|
+
perStep
|
|
822
878
|
}
|
|
823
879
|
});
|
|
824
880
|
},
|
|
@@ -836,7 +892,8 @@ async function processWorkflowSleepUntil({
|
|
|
836
892
|
prevResult,
|
|
837
893
|
resumeData,
|
|
838
894
|
parentWorkflow,
|
|
839
|
-
requestContext
|
|
895
|
+
requestContext,
|
|
896
|
+
perStep
|
|
840
897
|
}, {
|
|
841
898
|
pubsub,
|
|
842
899
|
stepExecutor,
|
|
@@ -910,7 +967,8 @@ async function processWorkflowSleepUntil({
|
|
|
910
967
|
resumeData,
|
|
911
968
|
parentWorkflow,
|
|
912
969
|
activeSteps,
|
|
913
|
-
requestContext
|
|
970
|
+
requestContext,
|
|
971
|
+
perStep
|
|
914
972
|
}
|
|
915
973
|
});
|
|
916
974
|
},
|
|
@@ -921,10 +979,52 @@ async function processWorkflowSleepUntil({
|
|
|
921
979
|
// src/workflows/evented/workflow-event-processor/index.ts
|
|
922
980
|
var WorkflowEventProcessor = class extends EventProcessor {
|
|
923
981
|
stepExecutor;
|
|
982
|
+
// Map of runId -> AbortController for active workflow runs
|
|
983
|
+
abortControllers = /* @__PURE__ */ new Map();
|
|
984
|
+
// Map of child runId -> parent runId for tracking nested workflows
|
|
985
|
+
parentChildRelationships = /* @__PURE__ */ new Map();
|
|
924
986
|
constructor({ mastra }) {
|
|
925
987
|
super({ mastra });
|
|
926
988
|
this.stepExecutor = new StepExecutor({ mastra });
|
|
927
989
|
}
|
|
990
|
+
/**
|
|
991
|
+
* Get or create an AbortController for a workflow run
|
|
992
|
+
*/
|
|
993
|
+
getOrCreateAbortController(runId) {
|
|
994
|
+
let controller = this.abortControllers.get(runId);
|
|
995
|
+
if (!controller) {
|
|
996
|
+
controller = new AbortController();
|
|
997
|
+
this.abortControllers.set(runId, controller);
|
|
998
|
+
}
|
|
999
|
+
return controller;
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Cancel a workflow run and all its nested child workflows
|
|
1003
|
+
*/
|
|
1004
|
+
cancelRunAndChildren(runId) {
|
|
1005
|
+
const controller = this.abortControllers.get(runId);
|
|
1006
|
+
if (controller) {
|
|
1007
|
+
controller.abort();
|
|
1008
|
+
}
|
|
1009
|
+
for (const [childRunId, parentRunId] of this.parentChildRelationships.entries()) {
|
|
1010
|
+
if (parentRunId === runId) {
|
|
1011
|
+
this.cancelRunAndChildren(childRunId);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Clean up abort controller and relationships when a workflow completes.
|
|
1017
|
+
* Also cleans up any orphaned child entries that reference this run as parent.
|
|
1018
|
+
*/
|
|
1019
|
+
cleanupRun(runId) {
|
|
1020
|
+
this.abortControllers.delete(runId);
|
|
1021
|
+
this.parentChildRelationships.delete(runId);
|
|
1022
|
+
for (const [childRunId, parentRunId] of this.parentChildRelationships.entries()) {
|
|
1023
|
+
if (parentRunId === runId) {
|
|
1024
|
+
this.parentChildRelationships.delete(childRunId);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
928
1028
|
__registerMastra(mastra) {
|
|
929
1029
|
super.__registerMastra(mastra);
|
|
930
1030
|
this.stepExecutor.__registerMastra(mastra);
|
|
@@ -956,11 +1056,15 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
956
1056
|
});
|
|
957
1057
|
}
|
|
958
1058
|
async processWorkflowCancel({ workflowId, runId }) {
|
|
959
|
-
|
|
960
|
-
const
|
|
1059
|
+
this.cancelRunAndChildren(runId);
|
|
1060
|
+
const workflowsStore = await this.mastra.getStorage()?.getStore("workflows");
|
|
1061
|
+
const currentState = await workflowsStore?.loadWorkflowSnapshot({
|
|
961
1062
|
workflowName: workflowId,
|
|
962
1063
|
runId
|
|
963
1064
|
});
|
|
1065
|
+
if (!currentState) {
|
|
1066
|
+
this.mastra.getLogger()?.warn("Canceling workflow without loaded state", { workflowId, runId });
|
|
1067
|
+
}
|
|
964
1068
|
await this.endWorkflow(
|
|
965
1069
|
{
|
|
966
1070
|
workflow: void 0,
|
|
@@ -989,11 +1093,17 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
989
1093
|
timeTravel,
|
|
990
1094
|
executionPath,
|
|
991
1095
|
stepResults,
|
|
992
|
-
requestContext
|
|
1096
|
+
requestContext,
|
|
1097
|
+
perStep
|
|
993
1098
|
}) {
|
|
994
|
-
|
|
1099
|
+
this.getOrCreateAbortController(runId);
|
|
1100
|
+
if (parentWorkflow?.runId) {
|
|
1101
|
+
this.parentChildRelationships.set(runId, parentWorkflow.runId);
|
|
1102
|
+
}
|
|
1103
|
+
const workflowsStore = await this.mastra.getStorage()?.getStore("workflows");
|
|
1104
|
+
const existingRun = await workflowsStore?.getWorkflowRunById({ runId, workflowName: workflow.id });
|
|
995
1105
|
const resourceId = existingRun?.resourceId;
|
|
996
|
-
await
|
|
1106
|
+
await workflowsStore?.persistWorkflowSnapshot({
|
|
997
1107
|
workflowName: workflow.id,
|
|
998
1108
|
runId,
|
|
999
1109
|
resourceId,
|
|
@@ -1029,20 +1139,32 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1029
1139
|
timeTravel,
|
|
1030
1140
|
requestContext,
|
|
1031
1141
|
resumeData,
|
|
1032
|
-
activeSteps: {}
|
|
1142
|
+
activeSteps: {},
|
|
1143
|
+
perStep
|
|
1033
1144
|
}
|
|
1034
1145
|
});
|
|
1035
1146
|
}
|
|
1036
1147
|
async endWorkflow(args, status = "success") {
|
|
1037
|
-
const { workflowId, runId, prevResult } = args;
|
|
1038
|
-
await this.mastra.getStorage()?.
|
|
1148
|
+
const { workflowId, runId, prevResult, perStep } = args;
|
|
1149
|
+
const workflowsStore = await this.mastra.getStorage()?.getStore("workflows");
|
|
1150
|
+
await workflowsStore?.updateWorkflowState({
|
|
1039
1151
|
workflowName: workflowId,
|
|
1040
1152
|
runId,
|
|
1041
1153
|
opts: {
|
|
1042
|
-
status,
|
|
1154
|
+
status: perStep && status === "success" ? "paused" : status,
|
|
1043
1155
|
result: prevResult
|
|
1044
1156
|
}
|
|
1045
1157
|
});
|
|
1158
|
+
if (perStep) {
|
|
1159
|
+
await this.mastra.pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
1160
|
+
type: "watch",
|
|
1161
|
+
runId,
|
|
1162
|
+
data: {
|
|
1163
|
+
type: "workflow-paused",
|
|
1164
|
+
payload: {}
|
|
1165
|
+
}
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1046
1168
|
await this.mastra.pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
1047
1169
|
type: "watch",
|
|
1048
1170
|
runId,
|
|
@@ -1060,7 +1182,18 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1060
1182
|
});
|
|
1061
1183
|
}
|
|
1062
1184
|
async processWorkflowEnd(args) {
|
|
1063
|
-
const {
|
|
1185
|
+
const {
|
|
1186
|
+
resumeSteps,
|
|
1187
|
+
prevResult,
|
|
1188
|
+
resumeData,
|
|
1189
|
+
parentWorkflow,
|
|
1190
|
+
activeSteps,
|
|
1191
|
+
requestContext,
|
|
1192
|
+
runId,
|
|
1193
|
+
timeTravel,
|
|
1194
|
+
perStep
|
|
1195
|
+
} = args;
|
|
1196
|
+
this.cleanupRun(runId);
|
|
1064
1197
|
if (parentWorkflow) {
|
|
1065
1198
|
await this.mastra.pubsub.publish("workflows", {
|
|
1066
1199
|
type: "workflow.step.end",
|
|
@@ -1077,7 +1210,8 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1077
1210
|
parentWorkflow: parentWorkflow.parentWorkflow,
|
|
1078
1211
|
parentContext: parentWorkflow,
|
|
1079
1212
|
requestContext,
|
|
1080
|
-
timeTravel
|
|
1213
|
+
timeTravel,
|
|
1214
|
+
perStep
|
|
1081
1215
|
}
|
|
1082
1216
|
});
|
|
1083
1217
|
}
|
|
@@ -1136,7 +1270,9 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1136
1270
|
requestContext,
|
|
1137
1271
|
timeTravel
|
|
1138
1272
|
} = args;
|
|
1139
|
-
|
|
1273
|
+
this.cleanupRun(runId);
|
|
1274
|
+
const workflowsStore = await this.mastra.getStorage()?.getStore("workflows");
|
|
1275
|
+
await workflowsStore?.updateWorkflowState({
|
|
1140
1276
|
workflowName: workflowId,
|
|
1141
1277
|
runId,
|
|
1142
1278
|
opts: {
|
|
@@ -1183,7 +1319,8 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1183
1319
|
resumeData,
|
|
1184
1320
|
parentWorkflow,
|
|
1185
1321
|
requestContext,
|
|
1186
|
-
retryCount = 0
|
|
1322
|
+
retryCount = 0,
|
|
1323
|
+
perStep
|
|
1187
1324
|
}) {
|
|
1188
1325
|
let stepGraph = workflow.stepGraph;
|
|
1189
1326
|
if (!executionPath?.length) {
|
|
@@ -1246,7 +1383,8 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1246
1383
|
prevResult,
|
|
1247
1384
|
resumeData,
|
|
1248
1385
|
parentWorkflow,
|
|
1249
|
-
requestContext
|
|
1386
|
+
requestContext,
|
|
1387
|
+
perStep
|
|
1250
1388
|
},
|
|
1251
1389
|
{
|
|
1252
1390
|
pubsub: this.mastra.pubsub,
|
|
@@ -1266,7 +1404,8 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1266
1404
|
prevResult,
|
|
1267
1405
|
resumeData,
|
|
1268
1406
|
parentWorkflow,
|
|
1269
|
-
requestContext
|
|
1407
|
+
requestContext,
|
|
1408
|
+
perStep
|
|
1270
1409
|
},
|
|
1271
1410
|
{
|
|
1272
1411
|
pubsub: this.mastra.pubsub,
|
|
@@ -1287,7 +1426,8 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1287
1426
|
prevResult,
|
|
1288
1427
|
resumeData,
|
|
1289
1428
|
parentWorkflow,
|
|
1290
|
-
requestContext
|
|
1429
|
+
requestContext,
|
|
1430
|
+
perStep
|
|
1291
1431
|
},
|
|
1292
1432
|
{
|
|
1293
1433
|
pubsub: this.mastra.pubsub,
|
|
@@ -1308,7 +1448,8 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1308
1448
|
prevResult,
|
|
1309
1449
|
resumeData,
|
|
1310
1450
|
parentWorkflow,
|
|
1311
|
-
requestContext
|
|
1451
|
+
requestContext,
|
|
1452
|
+
perStep
|
|
1312
1453
|
},
|
|
1313
1454
|
{
|
|
1314
1455
|
pubsub: this.mastra.pubsub,
|
|
@@ -1329,7 +1470,8 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1329
1470
|
prevResult,
|
|
1330
1471
|
resumeData,
|
|
1331
1472
|
parentWorkflow,
|
|
1332
|
-
requestContext
|
|
1473
|
+
requestContext,
|
|
1474
|
+
perStep
|
|
1333
1475
|
},
|
|
1334
1476
|
{
|
|
1335
1477
|
pubsub: this.mastra.pubsub,
|
|
@@ -1361,6 +1503,7 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1361
1503
|
);
|
|
1362
1504
|
}
|
|
1363
1505
|
activeSteps[step.step.id] = true;
|
|
1506
|
+
const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
|
|
1364
1507
|
if (step.step instanceof EventedWorkflow) {
|
|
1365
1508
|
if (resumeSteps?.length > 1) {
|
|
1366
1509
|
const stepData = stepResults[step.step.id];
|
|
@@ -1387,7 +1530,7 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1387
1530
|
})
|
|
1388
1531
|
);
|
|
1389
1532
|
}
|
|
1390
|
-
const snapshot = await
|
|
1533
|
+
const snapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
1391
1534
|
workflowName: step.step.id,
|
|
1392
1535
|
runId: nestedRunId
|
|
1393
1536
|
});
|
|
@@ -1415,11 +1558,12 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1415
1558
|
prevResult,
|
|
1416
1559
|
resumeData,
|
|
1417
1560
|
activeSteps,
|
|
1418
|
-
requestContext
|
|
1561
|
+
requestContext,
|
|
1562
|
+
perStep
|
|
1419
1563
|
}
|
|
1420
1564
|
});
|
|
1421
1565
|
} else if (timeTravel && timeTravel.steps?.length > 1 && timeTravel.steps[0] === step.step.id) {
|
|
1422
|
-
const snapshot = await
|
|
1566
|
+
const snapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
1423
1567
|
workflowName: step.step.id,
|
|
1424
1568
|
runId
|
|
1425
1569
|
}) ?? { context: {} };
|
|
@@ -1430,7 +1574,8 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1430
1574
|
context: timeTravel.nestedStepResults?.[step.step.id] ?? {},
|
|
1431
1575
|
nestedStepsContext: timeTravel.nestedStepResults ?? {},
|
|
1432
1576
|
snapshot,
|
|
1433
|
-
graph: step.step.buildExecutionGraph()
|
|
1577
|
+
graph: step.step.buildExecutionGraph(),
|
|
1578
|
+
perStep
|
|
1434
1579
|
});
|
|
1435
1580
|
const nestedPrevStep = getStep(step.step, timeTravelParams.executionPath);
|
|
1436
1581
|
const nestedPrevResult = timeTravelParams.stepResults[nestedPrevStep?.id ?? "input"];
|
|
@@ -1456,7 +1601,8 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1456
1601
|
prevResult: { status: "success", output: nestedPrevResult?.payload },
|
|
1457
1602
|
timeTravel: timeTravelParams,
|
|
1458
1603
|
activeSteps,
|
|
1459
|
-
requestContext
|
|
1604
|
+
requestContext,
|
|
1605
|
+
perStep
|
|
1460
1606
|
}
|
|
1461
1607
|
});
|
|
1462
1608
|
} else {
|
|
@@ -1481,7 +1627,8 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1481
1627
|
prevResult,
|
|
1482
1628
|
resumeData,
|
|
1483
1629
|
activeSteps,
|
|
1484
|
-
requestContext
|
|
1630
|
+
requestContext,
|
|
1631
|
+
perStep
|
|
1485
1632
|
}
|
|
1486
1633
|
});
|
|
1487
1634
|
}
|
|
@@ -1529,6 +1676,7 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1529
1676
|
} else if (resumeSteps?.length > 0 && resumeSteps?.[0] === step.step.id) {
|
|
1530
1677
|
resumeDataToUse = resumeData;
|
|
1531
1678
|
}
|
|
1679
|
+
const abortController = this.getOrCreateAbortController(runId);
|
|
1532
1680
|
const stepResult = await this.stepExecutor.execute({
|
|
1533
1681
|
workflowId,
|
|
1534
1682
|
step: step.step,
|
|
@@ -1542,7 +1690,9 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1542
1690
|
resumeData: resumeDataToUse,
|
|
1543
1691
|
retryCount,
|
|
1544
1692
|
foreachIdx: step.type === "foreach" ? executionPath[1] : void 0,
|
|
1545
|
-
validateInputs: workflow.options.validateInputs
|
|
1693
|
+
validateInputs: workflow.options.validateInputs,
|
|
1694
|
+
abortController,
|
|
1695
|
+
perStep
|
|
1546
1696
|
});
|
|
1547
1697
|
requestContext = Object.fromEntries(rc.entries());
|
|
1548
1698
|
if (stepResult.status === "bailed") {
|
|
@@ -1561,7 +1711,8 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1561
1711
|
},
|
|
1562
1712
|
prevResult: stepResult,
|
|
1563
1713
|
activeSteps,
|
|
1564
|
-
requestContext
|
|
1714
|
+
requestContext,
|
|
1715
|
+
perStep
|
|
1565
1716
|
});
|
|
1566
1717
|
return;
|
|
1567
1718
|
}
|
|
@@ -1639,7 +1790,8 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1639
1790
|
stepResults,
|
|
1640
1791
|
prevResult: stepResult,
|
|
1641
1792
|
activeSteps,
|
|
1642
|
-
requestContext
|
|
1793
|
+
requestContext,
|
|
1794
|
+
perStep
|
|
1643
1795
|
}
|
|
1644
1796
|
});
|
|
1645
1797
|
}
|
|
@@ -1656,7 +1808,8 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1656
1808
|
stepResults,
|
|
1657
1809
|
activeSteps,
|
|
1658
1810
|
parentContext,
|
|
1659
|
-
requestContext
|
|
1811
|
+
requestContext,
|
|
1812
|
+
perStep
|
|
1660
1813
|
}) {
|
|
1661
1814
|
let step = workflow.stepGraph[executionPath[0]];
|
|
1662
1815
|
if ((step?.type === "parallel" || step?.type === "conditional") && executionPath.length > 1) {
|
|
@@ -1682,8 +1835,9 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1682
1835
|
})
|
|
1683
1836
|
);
|
|
1684
1837
|
}
|
|
1838
|
+
const workflowsStore = await this.mastra.getStorage()?.getStore("workflows");
|
|
1685
1839
|
if (step.type === "foreach") {
|
|
1686
|
-
const snapshot = await
|
|
1840
|
+
const snapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
1687
1841
|
workflowName: workflowId,
|
|
1688
1842
|
runId
|
|
1689
1843
|
});
|
|
@@ -1698,7 +1852,7 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1698
1852
|
newResult = { ...prevResult, output: [prevResult.output] };
|
|
1699
1853
|
}
|
|
1700
1854
|
}
|
|
1701
|
-
const newStepResults = await
|
|
1855
|
+
const newStepResults = await workflowsStore?.updateWorkflowResults({
|
|
1702
1856
|
workflowName: workflow.id,
|
|
1703
1857
|
runId,
|
|
1704
1858
|
stepId: step.step.id,
|
|
@@ -1717,7 +1871,7 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1717
1871
|
payload: parentContext.input?.output ?? {}
|
|
1718
1872
|
};
|
|
1719
1873
|
}
|
|
1720
|
-
const newStepResults = await
|
|
1874
|
+
const newStepResults = await workflowsStore?.updateWorkflowResults({
|
|
1721
1875
|
workflowName: workflow.id,
|
|
1722
1876
|
runId,
|
|
1723
1877
|
stepId: step.step.id,
|
|
@@ -1753,7 +1907,7 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1753
1907
|
if (suspendedStep) {
|
|
1754
1908
|
suspendedPaths[suspendedStep.id] = executionPath;
|
|
1755
1909
|
}
|
|
1756
|
-
await
|
|
1910
|
+
await workflowsStore?.updateWorkflowState({
|
|
1757
1911
|
workflowName: workflowId,
|
|
1758
1912
|
runId,
|
|
1759
1913
|
opts: {
|
|
@@ -1820,7 +1974,38 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1820
1974
|
}
|
|
1821
1975
|
}
|
|
1822
1976
|
step = workflow.stepGraph[executionPath[0]];
|
|
1823
|
-
if (
|
|
1977
|
+
if (perStep) {
|
|
1978
|
+
if (parentWorkflow && executionPath[0] < workflow.stepGraph.length - 1) {
|
|
1979
|
+
const { endedAt, output, status, ...nestedPrevResult } = prevResult;
|
|
1980
|
+
await this.endWorkflow({
|
|
1981
|
+
workflow,
|
|
1982
|
+
parentWorkflow,
|
|
1983
|
+
workflowId,
|
|
1984
|
+
runId,
|
|
1985
|
+
executionPath,
|
|
1986
|
+
resumeSteps,
|
|
1987
|
+
stepResults,
|
|
1988
|
+
prevResult: { ...nestedPrevResult, status: "paused" },
|
|
1989
|
+
activeSteps,
|
|
1990
|
+
requestContext,
|
|
1991
|
+
perStep
|
|
1992
|
+
});
|
|
1993
|
+
} else {
|
|
1994
|
+
await this.endWorkflow({
|
|
1995
|
+
workflow,
|
|
1996
|
+
parentWorkflow,
|
|
1997
|
+
workflowId,
|
|
1998
|
+
runId,
|
|
1999
|
+
executionPath,
|
|
2000
|
+
resumeSteps,
|
|
2001
|
+
stepResults,
|
|
2002
|
+
prevResult,
|
|
2003
|
+
activeSteps,
|
|
2004
|
+
requestContext,
|
|
2005
|
+
perStep
|
|
2006
|
+
});
|
|
2007
|
+
}
|
|
2008
|
+
} else if ((step?.type === "parallel" || step?.type === "conditional") && executionPath.length > 1) {
|
|
1824
2009
|
let skippedCount = 0;
|
|
1825
2010
|
const allResults = step.steps.reduce(
|
|
1826
2011
|
(acc, step2) => {
|
|
@@ -1909,7 +2094,8 @@ var WorkflowEventProcessor = class extends EventProcessor {
|
|
|
1909
2094
|
workflowId,
|
|
1910
2095
|
runId
|
|
1911
2096
|
}) {
|
|
1912
|
-
const
|
|
2097
|
+
const workflowsStore = await this.mastra.getStorage()?.getStore("workflows");
|
|
2098
|
+
const snapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
1913
2099
|
workflowName: workflowId,
|
|
1914
2100
|
runId
|
|
1915
2101
|
});
|
|
@@ -2229,9 +2415,12 @@ var EventedWorkflow = class extends Workflow {
|
|
|
2229
2415
|
workflowStatus: run.workflowRunStatus,
|
|
2230
2416
|
stepResults: {}
|
|
2231
2417
|
});
|
|
2232
|
-
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse,
|
|
2418
|
+
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, {
|
|
2419
|
+
withNestedWorkflows: false
|
|
2420
|
+
});
|
|
2233
2421
|
if (!workflowSnapshotInStorage && shouldPersistSnapshot) {
|
|
2234
|
-
await this.mastra?.getStorage()?.
|
|
2422
|
+
const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
|
|
2423
|
+
await workflowsStore?.persistWorkflowSnapshot({
|
|
2235
2424
|
workflowName: this.id,
|
|
2236
2425
|
runId: runIdToUse,
|
|
2237
2426
|
resourceId: options?.resourceId,
|
|
@@ -2261,10 +2450,30 @@ var EventedRun = class extends Run {
|
|
|
2261
2450
|
super(params);
|
|
2262
2451
|
this.serializedStepGraph = params.serializedStepGraph;
|
|
2263
2452
|
}
|
|
2453
|
+
/**
|
|
2454
|
+
* Set up abort signal handler to publish workflow.cancel event when abortController.abort() is called.
|
|
2455
|
+
* This ensures consistent cancellation behavior whether abort() is called directly or via cancel().
|
|
2456
|
+
*/
|
|
2457
|
+
setupAbortHandler() {
|
|
2458
|
+
const abortHandler = () => {
|
|
2459
|
+
this.mastra?.pubsub.publish("workflows", {
|
|
2460
|
+
type: "workflow.cancel",
|
|
2461
|
+
runId: this.runId,
|
|
2462
|
+
data: {
|
|
2463
|
+
workflowId: this.workflowId,
|
|
2464
|
+
runId: this.runId
|
|
2465
|
+
}
|
|
2466
|
+
}).catch((err) => {
|
|
2467
|
+
console.error(`Failed to publish workflow.cancel for runId ${this.runId}:`, err);
|
|
2468
|
+
});
|
|
2469
|
+
};
|
|
2470
|
+
this.abortController.signal.addEventListener("abort", abortHandler, { once: true });
|
|
2471
|
+
}
|
|
2264
2472
|
async start({
|
|
2265
2473
|
inputData,
|
|
2266
2474
|
initialState,
|
|
2267
|
-
requestContext
|
|
2475
|
+
requestContext,
|
|
2476
|
+
perStep
|
|
2268
2477
|
}) {
|
|
2269
2478
|
if (this.serializedStepGraph.length === 0) {
|
|
2270
2479
|
throw new Error(
|
|
@@ -2275,7 +2484,8 @@ var EventedRun = class extends Run {
|
|
|
2275
2484
|
throw new Error("Uncommitted step flow changes detected. Call .commit() to register the steps.");
|
|
2276
2485
|
}
|
|
2277
2486
|
requestContext = requestContext ?? new RequestContext();
|
|
2278
|
-
await this.mastra?.getStorage()?.
|
|
2487
|
+
const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
|
|
2488
|
+
await workflowsStore?.persistWorkflowSnapshot({
|
|
2279
2489
|
workflowName: this.workflowId,
|
|
2280
2490
|
runId: this.runId,
|
|
2281
2491
|
resourceId: this.resourceId,
|
|
@@ -2299,6 +2509,7 @@ var EventedRun = class extends Run {
|
|
|
2299
2509
|
if (!this.mastra?.pubsub) {
|
|
2300
2510
|
throw new Error("Mastra instance with pubsub is required for workflow execution");
|
|
2301
2511
|
}
|
|
2512
|
+
this.setupAbortHandler();
|
|
2302
2513
|
const result = await this.executionEngine.execute({
|
|
2303
2514
|
workflowId: this.workflowId,
|
|
2304
2515
|
runId: this.runId,
|
|
@@ -2309,7 +2520,8 @@ var EventedRun = class extends Run {
|
|
|
2309
2520
|
pubsub: this.mastra.pubsub,
|
|
2310
2521
|
retryConfig: this.retryConfig,
|
|
2311
2522
|
requestContext,
|
|
2312
|
-
abortController: this.abortController
|
|
2523
|
+
abortController: this.abortController,
|
|
2524
|
+
perStep
|
|
2313
2525
|
});
|
|
2314
2526
|
if (result.status !== "suspended") {
|
|
2315
2527
|
this.cleanup?.();
|
|
@@ -2324,7 +2536,8 @@ var EventedRun = class extends Run {
|
|
|
2324
2536
|
async startAsync({
|
|
2325
2537
|
inputData,
|
|
2326
2538
|
initialState,
|
|
2327
|
-
requestContext
|
|
2539
|
+
requestContext,
|
|
2540
|
+
perStep
|
|
2328
2541
|
}) {
|
|
2329
2542
|
if (this.serializedStepGraph.length === 0) {
|
|
2330
2543
|
throw new Error(
|
|
@@ -2335,7 +2548,8 @@ var EventedRun = class extends Run {
|
|
|
2335
2548
|
throw new Error("Uncommitted step flow changes detected. Call .commit() to register the steps.");
|
|
2336
2549
|
}
|
|
2337
2550
|
requestContext = requestContext ?? new RequestContext();
|
|
2338
|
-
await this.mastra?.getStorage()?.
|
|
2551
|
+
const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
|
|
2552
|
+
await workflowsStore?.persistWorkflowSnapshot({
|
|
2339
2553
|
workflowName: this.workflowId,
|
|
2340
2554
|
runId: this.runId,
|
|
2341
2555
|
resourceId: this.resourceId,
|
|
@@ -2367,7 +2581,8 @@ var EventedRun = class extends Run {
|
|
|
2367
2581
|
runId: this.runId,
|
|
2368
2582
|
prevResult: { status: "success", output: inputDataToUse },
|
|
2369
2583
|
requestContext: Object.fromEntries(requestContext.entries()),
|
|
2370
|
-
initialState: initialStateToUse
|
|
2584
|
+
initialState: initialStateToUse,
|
|
2585
|
+
perStep
|
|
2371
2586
|
}
|
|
2372
2587
|
});
|
|
2373
2588
|
return { runId: this.runId };
|
|
@@ -2385,21 +2600,28 @@ var EventedRun = class extends Run {
|
|
|
2385
2600
|
if (steps.length === 0) {
|
|
2386
2601
|
throw new Error("No steps provided to resume");
|
|
2387
2602
|
}
|
|
2388
|
-
const
|
|
2603
|
+
const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
|
|
2604
|
+
if (!workflowsStore) {
|
|
2605
|
+
throw new Error("Cannot resume workflow: workflows store is required");
|
|
2606
|
+
}
|
|
2607
|
+
const snapshot = await workflowsStore.loadWorkflowSnapshot({
|
|
2389
2608
|
workflowName: this.workflowId,
|
|
2390
2609
|
runId: this.runId
|
|
2391
2610
|
});
|
|
2392
|
-
|
|
2611
|
+
if (!snapshot) {
|
|
2612
|
+
throw new Error(`Cannot resume workflow: no snapshot found for runId ${this.runId}`);
|
|
2613
|
+
}
|
|
2614
|
+
const resumePath = snapshot.suspendedPaths?.[steps[0]];
|
|
2393
2615
|
if (!resumePath) {
|
|
2394
2616
|
throw new Error(
|
|
2395
|
-
`No resume path found for step ${JSON.stringify(steps)}, currently suspended paths are ${JSON.stringify(snapshot
|
|
2617
|
+
`No resume path found for step ${JSON.stringify(steps)}, currently suspended paths are ${JSON.stringify(snapshot.suspendedPaths)}`
|
|
2396
2618
|
);
|
|
2397
2619
|
}
|
|
2398
2620
|
console.dir(
|
|
2399
|
-
{ resume: { requestContextObj: snapshot
|
|
2621
|
+
{ resume: { requestContextObj: snapshot.requestContext, requestContext: params.requestContext } },
|
|
2400
2622
|
{ depth: null }
|
|
2401
2623
|
);
|
|
2402
|
-
const requestContextObj = snapshot
|
|
2624
|
+
const requestContextObj = snapshot.requestContext ?? {};
|
|
2403
2625
|
const requestContext = new RequestContext();
|
|
2404
2626
|
for (const [key, value] of Object.entries(requestContextObj)) {
|
|
2405
2627
|
requestContext.set(key, value);
|
|
@@ -2414,6 +2636,7 @@ var EventedRun = class extends Run {
|
|
|
2414
2636
|
if (!this.mastra?.pubsub) {
|
|
2415
2637
|
throw new Error("Mastra instance with pubsub is required for workflow execution");
|
|
2416
2638
|
}
|
|
2639
|
+
this.setupAbortHandler();
|
|
2417
2640
|
const executionResultPromise = this.executionEngine.execute({
|
|
2418
2641
|
workflowId: this.workflowId,
|
|
2419
2642
|
runId: this.runId,
|
|
@@ -2428,7 +2651,8 @@ var EventedRun = class extends Run {
|
|
|
2428
2651
|
},
|
|
2429
2652
|
pubsub: this.mastra.pubsub,
|
|
2430
2653
|
requestContext,
|
|
2431
|
-
abortController: this.abortController
|
|
2654
|
+
abortController: this.abortController,
|
|
2655
|
+
perStep: params.perStep
|
|
2432
2656
|
}).then((result) => {
|
|
2433
2657
|
if (result.status !== "suspended") {
|
|
2434
2658
|
this.closeStreamAction?.().catch(() => {
|
|
@@ -2470,21 +2694,15 @@ var EventedRun = class extends Run {
|
|
|
2470
2694
|
};
|
|
2471
2695
|
}
|
|
2472
2696
|
async cancel() {
|
|
2473
|
-
await this.mastra?.getStorage()?.
|
|
2697
|
+
const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
|
|
2698
|
+
await workflowsStore?.updateWorkflowState({
|
|
2474
2699
|
workflowName: this.workflowId,
|
|
2475
2700
|
runId: this.runId,
|
|
2476
2701
|
opts: {
|
|
2477
2702
|
status: "canceled"
|
|
2478
2703
|
}
|
|
2479
2704
|
});
|
|
2480
|
-
|
|
2481
|
-
type: "workflow.cancel",
|
|
2482
|
-
runId: this.runId,
|
|
2483
|
-
data: {
|
|
2484
|
-
workflowId: this.workflowId,
|
|
2485
|
-
runId: this.runId
|
|
2486
|
-
}
|
|
2487
|
-
});
|
|
2705
|
+
this.abortController.abort();
|
|
2488
2706
|
}
|
|
2489
2707
|
};
|
|
2490
2708
|
|
|
@@ -2572,7 +2790,8 @@ var EventedExecutionEngine = class extends ExecutionEngine {
|
|
|
2572
2790
|
prevResult: { status: "success", output: prevResult?.payload },
|
|
2573
2791
|
resumeData: params.resume.resumePayload,
|
|
2574
2792
|
requestContext: Object.fromEntries(params.requestContext.entries()),
|
|
2575
|
-
format: params.format
|
|
2793
|
+
format: params.format,
|
|
2794
|
+
perStep: params.perStep
|
|
2576
2795
|
}
|
|
2577
2796
|
});
|
|
2578
2797
|
} else if (params.timeTravel) {
|
|
@@ -2589,7 +2808,8 @@ var EventedExecutionEngine = class extends ExecutionEngine {
|
|
|
2589
2808
|
timeTravel: params.timeTravel,
|
|
2590
2809
|
prevResult: { status: "success", output: prevResult?.payload },
|
|
2591
2810
|
requestContext: Object.fromEntries(params.requestContext.entries()),
|
|
2592
|
-
format: params.format
|
|
2811
|
+
format: params.format,
|
|
2812
|
+
perStep: params.perStep
|
|
2593
2813
|
}
|
|
2594
2814
|
});
|
|
2595
2815
|
} else {
|
|
@@ -2601,7 +2821,8 @@ var EventedExecutionEngine = class extends ExecutionEngine {
|
|
|
2601
2821
|
runId: params.runId,
|
|
2602
2822
|
prevResult: { status: "success", output: params.input },
|
|
2603
2823
|
requestContext: Object.fromEntries(params.requestContext.entries()),
|
|
2604
|
-
format: params.format
|
|
2824
|
+
format: params.format,
|
|
2825
|
+
perStep: params.perStep
|
|
2605
2826
|
}
|
|
2606
2827
|
});
|
|
2607
2828
|
}
|
|
@@ -2639,6 +2860,11 @@ var EventedExecutionEngine = class extends ExecutionEngine {
|
|
|
2639
2860
|
status: "suspended",
|
|
2640
2861
|
steps: resultData.stepResults
|
|
2641
2862
|
};
|
|
2863
|
+
} else if (resultData.prevResult.status === "paused" || params.perStep) {
|
|
2864
|
+
callbackArg = {
|
|
2865
|
+
status: "paused",
|
|
2866
|
+
steps: resultData.stepResults
|
|
2867
|
+
};
|
|
2642
2868
|
} else {
|
|
2643
2869
|
callbackArg = {
|
|
2644
2870
|
status: resultData.prevResult.status,
|
|
@@ -2646,7 +2872,9 @@ var EventedExecutionEngine = class extends ExecutionEngine {
|
|
|
2646
2872
|
steps: resultData.stepResults
|
|
2647
2873
|
};
|
|
2648
2874
|
}
|
|
2649
|
-
|
|
2875
|
+
if (callbackArg.status !== "paused") {
|
|
2876
|
+
await this.invokeLifecycleCallbacks(callbackArg);
|
|
2877
|
+
}
|
|
2650
2878
|
let result;
|
|
2651
2879
|
if (resultData.prevResult.status === "suspended") {
|
|
2652
2880
|
const suspendedSteps = Object.entries(resultData.stepResults).map(([_stepId, stepResult]) => {
|
|
@@ -2667,5 +2895,5 @@ var EventedExecutionEngine = class extends ExecutionEngine {
|
|
|
2667
2895
|
};
|
|
2668
2896
|
|
|
2669
2897
|
export { EventedExecutionEngine, EventedRun, EventedWorkflow, StepExecutor, WorkflowEventProcessor, cloneStep, cloneWorkflow, createStep, createWorkflow };
|
|
2670
|
-
//# sourceMappingURL=chunk-
|
|
2671
|
-
//# sourceMappingURL=chunk-
|
|
2898
|
+
//# sourceMappingURL=chunk-D2IFWD7A.js.map
|
|
2899
|
+
//# sourceMappingURL=chunk-D2IFWD7A.js.map
|