@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,19 +1,19 @@
|
|
|
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
|
|
3
|
+
import { InMemoryStore } from './chunk-3HDRO3GG.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-BAZHNX5P.js';
|
|
8
|
+
import { MastraLLMV1 } from './chunk-4J4M2Q5R.js';
|
|
7
9
|
import { PubSub } from './chunk-BVUMKER5.js';
|
|
8
10
|
import { executeHook } from './chunk-L54GIUCB.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
11
|
+
import { removeUndefinedValues, ensureToolProperties, makeCoreTool, createMastraProxy, isZodType, deepMerge, selectFields, delay } from './chunk-XJB7J4UT.js';
|
|
12
|
+
import { getOrCreateSpan, wrapMastra, executeWithContextSync } from './chunk-ZGIVAQRI.js';
|
|
13
|
+
import { MastraError, getErrorFromUnknown } from './chunk-FJEVLHJT.js';
|
|
12
14
|
import { ToolStream } from './chunk-DD2VNRQM.js';
|
|
13
|
-
import { Tool, createTool } from './chunk-
|
|
14
|
-
import { getOrCreateSpan, wrapMastra, executeWithContextSync } from './chunk-Y36Y5MTD.js';
|
|
15
|
+
import { Tool, createTool } from './chunk-4HP7CS6L.js';
|
|
15
16
|
import { RequestContext, MASTRA_RESOURCE_ID_KEY, MASTRA_THREAD_ID_KEY } from './chunk-6TBWJV35.js';
|
|
16
|
-
import { MastraError, getErrorFromUnknown } from './chunk-YPLZDWG7.js';
|
|
17
17
|
import { zodToJsonSchema as zodToJsonSchema$1 } from './chunk-PJKCPRYF.js';
|
|
18
18
|
import { MastraBase } from './chunk-LSHPJWM5.js';
|
|
19
19
|
import { RegisteredLogger, ConsoleLogger } from './chunk-NRUZYMHE.js';
|
|
@@ -27,6 +27,7 @@ import { getErrorMessage, TypeValidationError } from '@ai-sdk/provider-v5';
|
|
|
27
27
|
import z4 from 'zod/v4';
|
|
28
28
|
import { OpenAIReasoningSchemaCompatLayer, OpenAISchemaCompatLayer, GoogleSchemaCompatLayer, AnthropicSchemaCompatLayer, DeepSeekSchemaCompatLayer, MetaSchemaCompatLayer, applyCompatLayer } from '@mastra/schema-compat';
|
|
29
29
|
import { isEmpty } from 'radash';
|
|
30
|
+
import { isAbortError, injectJsonInstructionIntoMessages } from '@ai-sdk/provider-utils-v5';
|
|
30
31
|
import { Tiktoken } from 'js-tiktoken/lite';
|
|
31
32
|
import o200k_base from 'js-tiktoken/ranks/o200k_base';
|
|
32
33
|
import { LRUCache } from 'lru-cache';
|
|
@@ -728,6 +729,69 @@ The input text may be in any format (sentences, bullet points, paragraphs, etc.)
|
|
|
728
729
|
}
|
|
729
730
|
};
|
|
730
731
|
|
|
732
|
+
// src/agent/utils.ts
|
|
733
|
+
var supportedLanguageModelSpecifications = ["v2", "v3"];
|
|
734
|
+
var isSupportedLanguageModel = (model) => {
|
|
735
|
+
return supportedLanguageModelSpecifications.includes(model.specificationVersion);
|
|
736
|
+
};
|
|
737
|
+
async function tryGenerateWithJsonFallback(agent, prompt, options) {
|
|
738
|
+
if (!options.structuredOutput?.schema) {
|
|
739
|
+
throw new MastraError({
|
|
740
|
+
id: "STRUCTURED_OUTPUT_OPTIONS_REQUIRED",
|
|
741
|
+
domain: "AGENT" /* AGENT */,
|
|
742
|
+
category: "USER" /* USER */,
|
|
743
|
+
text: "structuredOutput is required to use tryGenerateWithJsonFallback"
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
try {
|
|
747
|
+
return await agent.generate(prompt, options);
|
|
748
|
+
} catch (error) {
|
|
749
|
+
console.warn("Error in tryGenerateWithJsonFallback. Attempting fallback.", error);
|
|
750
|
+
return await agent.generate(prompt, {
|
|
751
|
+
...options,
|
|
752
|
+
structuredOutput: { ...options.structuredOutput, jsonPromptInjection: true }
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
async function tryStreamWithJsonFallback(agent, prompt, options) {
|
|
757
|
+
if (!options.structuredOutput?.schema) {
|
|
758
|
+
throw new MastraError({
|
|
759
|
+
id: "STRUCTURED_OUTPUT_OPTIONS_REQUIRED",
|
|
760
|
+
domain: "AGENT" /* AGENT */,
|
|
761
|
+
category: "USER" /* USER */,
|
|
762
|
+
text: "structuredOutput is required to use tryStreamWithJsonFallback"
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
try {
|
|
766
|
+
const result = await agent.stream(prompt, options);
|
|
767
|
+
const object = await result.object;
|
|
768
|
+
if (!object) {
|
|
769
|
+
throw new MastraError({
|
|
770
|
+
id: "STRUCTURED_OUTPUT_OBJECT_UNDEFINED",
|
|
771
|
+
domain: "AGENT" /* AGENT */,
|
|
772
|
+
category: "USER" /* USER */,
|
|
773
|
+
text: "structuredOutput object is undefined"
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
return result;
|
|
777
|
+
} catch (error) {
|
|
778
|
+
console.warn("Error in tryStreamWithJsonFallback. Attempting fallback.", error);
|
|
779
|
+
return await agent.stream(prompt, {
|
|
780
|
+
...options,
|
|
781
|
+
structuredOutput: { ...options.structuredOutput, jsonPromptInjection: true }
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
function resolveThreadIdFromArgs(args) {
|
|
786
|
+
if (args?.memory?.thread) {
|
|
787
|
+
if (typeof args.memory.thread === "string") return { id: args.memory.thread };
|
|
788
|
+
if (typeof args.memory.thread === "object" && args.memory.thread.id)
|
|
789
|
+
return args.memory.thread;
|
|
790
|
+
}
|
|
791
|
+
if (args?.threadId) return { id: args.threadId };
|
|
792
|
+
return void 0;
|
|
793
|
+
}
|
|
794
|
+
|
|
731
795
|
// src/processors/runner.ts
|
|
732
796
|
var ProcessorState = class {
|
|
733
797
|
accumulatedText = "";
|
|
@@ -741,8 +805,9 @@ var ProcessorState = class {
|
|
|
741
805
|
this.span = parentSpan?.createChildSpan({
|
|
742
806
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
743
807
|
name: `output processor: ${processorName}`,
|
|
808
|
+
entityType: "output_processor" /* OUTPUT_PROCESSOR */,
|
|
809
|
+
entityName: processorName,
|
|
744
810
|
attributes: {
|
|
745
|
-
processorName,
|
|
746
811
|
processorType: "output",
|
|
747
812
|
processorIndex: processorIndex ?? 0
|
|
748
813
|
},
|
|
@@ -841,8 +906,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
841
906
|
const processorSpan2 = parentSpan2?.createChildSpan({
|
|
842
907
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
843
908
|
name: `output processor workflow: ${processorOrWorkflow.id}`,
|
|
909
|
+
entityType: "output_processor" /* OUTPUT_PROCESSOR */,
|
|
910
|
+
entityId: processorOrWorkflow.id,
|
|
911
|
+
entityName: processorOrWorkflow.name,
|
|
844
912
|
attributes: {
|
|
845
|
-
processorName: processorOrWorkflow.id,
|
|
846
913
|
processorType: "output",
|
|
847
914
|
processorIndex: index
|
|
848
915
|
},
|
|
@@ -883,8 +950,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
883
950
|
const processorSpan = parentSpan?.createChildSpan({
|
|
884
951
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
885
952
|
name: `output processor: ${processor.id}`,
|
|
953
|
+
entityType: "output_processor" /* OUTPUT_PROCESSOR */,
|
|
954
|
+
entityId: processor.id,
|
|
955
|
+
entityName: processor.name,
|
|
886
956
|
attributes: {
|
|
887
|
-
processorName: processor.name ?? processor.id,
|
|
888
957
|
processorType: "output",
|
|
889
958
|
processorIndex: index
|
|
890
959
|
},
|
|
@@ -1119,8 +1188,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1119
1188
|
const processorSpan2 = parentSpan2?.createChildSpan({
|
|
1120
1189
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1121
1190
|
name: `input processor workflow: ${processorOrWorkflow.id}`,
|
|
1191
|
+
entityType: "input_processor" /* INPUT_PROCESSOR */,
|
|
1192
|
+
entityId: processorOrWorkflow.id,
|
|
1193
|
+
entityName: processorOrWorkflow.name,
|
|
1122
1194
|
attributes: {
|
|
1123
|
-
processorName: processorOrWorkflow.id,
|
|
1124
1195
|
processorType: "input",
|
|
1125
1196
|
processorIndex: index
|
|
1126
1197
|
},
|
|
@@ -1163,8 +1234,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1163
1234
|
const processorSpan = parentSpan?.createChildSpan({
|
|
1164
1235
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1165
1236
|
name: `input processor: ${processor.id}`,
|
|
1237
|
+
entityType: "input_processor" /* INPUT_PROCESSOR */,
|
|
1238
|
+
entityId: processor.id,
|
|
1239
|
+
entityName: processor.name,
|
|
1166
1240
|
attributes: {
|
|
1167
|
-
processorName: processor.name ?? processor.id,
|
|
1168
1241
|
processorType: "input",
|
|
1169
1242
|
processorIndex: index
|
|
1170
1243
|
},
|
|
@@ -1287,8 +1360,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1287
1360
|
const processorSpan2 = parentSpan?.createChildSpan({
|
|
1288
1361
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1289
1362
|
name: `input step processor workflow: ${processorOrWorkflow.id}`,
|
|
1363
|
+
entityType: "input_processor" /* INPUT_PROCESSOR */,
|
|
1364
|
+
entityId: processorOrWorkflow.id,
|
|
1365
|
+
entityName: processorOrWorkflow.name,
|
|
1290
1366
|
attributes: {
|
|
1291
|
-
processorName: processorOrWorkflow.id,
|
|
1292
1367
|
processorType: "input",
|
|
1293
1368
|
processorIndex: index
|
|
1294
1369
|
},
|
|
@@ -1347,8 +1422,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1347
1422
|
const processorSpan = currentSpan?.createChildSpan({
|
|
1348
1423
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1349
1424
|
name: `input step processor: ${processor.id}`,
|
|
1425
|
+
entityType: "input_processor" /* INPUT_PROCESSOR */,
|
|
1426
|
+
entityId: processor.id,
|
|
1427
|
+
entityName: processor.name,
|
|
1350
1428
|
attributes: {
|
|
1351
|
-
processorName: processor.name ?? processor.id,
|
|
1352
1429
|
processorType: "input",
|
|
1353
1430
|
processorIndex: index
|
|
1354
1431
|
},
|
|
@@ -1441,6 +1518,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1441
1518
|
*/
|
|
1442
1519
|
async runProcessOutputStep(args) {
|
|
1443
1520
|
const {
|
|
1521
|
+
steps,
|
|
1444
1522
|
messageList,
|
|
1445
1523
|
stepNumber,
|
|
1446
1524
|
finishReason,
|
|
@@ -1460,8 +1538,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1460
1538
|
const processorSpan2 = parentSpan2?.createChildSpan({
|
|
1461
1539
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1462
1540
|
name: `output step processor workflow: ${processorOrWorkflow.id}`,
|
|
1541
|
+
entityType: "output_processor" /* OUTPUT_PROCESSOR */,
|
|
1542
|
+
entityId: processorOrWorkflow.id,
|
|
1543
|
+
entityName: processorOrWorkflow.name,
|
|
1463
1544
|
attributes: {
|
|
1464
|
-
processorName: processorOrWorkflow.id,
|
|
1465
1545
|
processorType: "output",
|
|
1466
1546
|
processorIndex: index
|
|
1467
1547
|
},
|
|
@@ -1480,6 +1560,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1480
1560
|
toolCalls,
|
|
1481
1561
|
text,
|
|
1482
1562
|
systemMessages: currentSystemMessages2,
|
|
1563
|
+
steps,
|
|
1483
1564
|
retryCount
|
|
1484
1565
|
},
|
|
1485
1566
|
tracingContext,
|
|
@@ -1508,8 +1589,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1508
1589
|
const processorSpan = parentSpan?.createChildSpan({
|
|
1509
1590
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1510
1591
|
name: `output step processor: ${processor.id}`,
|
|
1592
|
+
entityType: "output_processor" /* OUTPUT_PROCESSOR */,
|
|
1593
|
+
entityId: processor.id,
|
|
1594
|
+
entityName: processor.name,
|
|
1511
1595
|
attributes: {
|
|
1512
|
-
processorName: processor.name ?? processor.id,
|
|
1513
1596
|
processorType: "output",
|
|
1514
1597
|
processorIndex: index
|
|
1515
1598
|
},
|
|
@@ -1526,6 +1609,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1526
1609
|
toolCalls,
|
|
1527
1610
|
text,
|
|
1528
1611
|
systemMessages: currentSystemMessages,
|
|
1612
|
+
steps,
|
|
1529
1613
|
abort,
|
|
1530
1614
|
tracingContext: { currentSpan: processorSpan },
|
|
1531
1615
|
requestContext,
|
|
@@ -1638,12 +1722,13 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1638
1722
|
const { model: _model, ...rest } = result;
|
|
1639
1723
|
if (result.model) {
|
|
1640
1724
|
const resolvedModel = await resolveModelConfig(result.model);
|
|
1641
|
-
|
|
1725
|
+
const isSupported = isSupportedLanguageModel(resolvedModel);
|
|
1726
|
+
if (!isSupported) {
|
|
1642
1727
|
throw new MastraError({
|
|
1643
1728
|
category: "USER",
|
|
1644
1729
|
domain: "AGENT",
|
|
1645
|
-
id: "
|
|
1646
|
-
text: `Processor ${processor.id} returned
|
|
1730
|
+
id: "PROCESSOR_RETURNED_UNSUPPORTED_MODEL",
|
|
1731
|
+
text: `Processor ${processor.id} returned an unsupported model version ${resolvedModel.specificationVersion} in step ${stepNumber}. Only ${supportedLanguageModelSpecifications.join(", ")} models are supported in processInputStep.`
|
|
1647
1732
|
});
|
|
1648
1733
|
}
|
|
1649
1734
|
return {
|
|
@@ -1839,13 +1924,11 @@ function convertFullStreamChunkToMastra(value, ctx) {
|
|
|
1839
1924
|
from: "AGENT" /* AGENT */,
|
|
1840
1925
|
payload: {
|
|
1841
1926
|
stepResult: {
|
|
1842
|
-
reason: value.finishReason
|
|
1927
|
+
reason: normalizeFinishReason(value.finishReason)
|
|
1843
1928
|
},
|
|
1844
1929
|
output: {
|
|
1845
|
-
usage
|
|
1846
|
-
|
|
1847
|
-
totalTokens: value?.usage?.totalTokens ?? (value.usage?.inputTokens ?? 0) + (value.usage?.outputTokens ?? 0)
|
|
1848
|
-
}
|
|
1930
|
+
// Normalize usage to handle both V2 (flat) and V3 (nested) formats
|
|
1931
|
+
usage: normalizeUsage(value.usage)
|
|
1849
1932
|
},
|
|
1850
1933
|
metadata: {
|
|
1851
1934
|
providerMetadata: value.providerMetadata
|
|
@@ -1897,6 +1980,7 @@ function convertMastraChunkToAISDKv5({
|
|
|
1897
1980
|
type: "finish",
|
|
1898
1981
|
// Cast needed: Mastra extends reason with 'tripwire' | 'retry' for processor scenarios
|
|
1899
1982
|
finishReason: chunk.payload.stepResult.reason,
|
|
1983
|
+
// Cast needed: Mastra's LanguageModelUsage has optional properties, V2 has required-but-nullable
|
|
1900
1984
|
totalUsage: chunk.payload.output.usage
|
|
1901
1985
|
};
|
|
1902
1986
|
}
|
|
@@ -1915,18 +1999,8 @@ function convertMastraChunkToAISDKv5({
|
|
|
1915
1999
|
};
|
|
1916
2000
|
case "reasoning-signature":
|
|
1917
2001
|
throw new Error('AISDKv5 chunk type "reasoning-signature" not supported');
|
|
1918
|
-
// return {
|
|
1919
|
-
// type: 'reasoning-signature' as const,
|
|
1920
|
-
// id: chunk.payload.id,
|
|
1921
|
-
// signature: chunk.payload.signature,
|
|
1922
|
-
// };
|
|
1923
2002
|
case "redacted-reasoning":
|
|
1924
2003
|
throw new Error('AISDKv5 chunk type "redacted-reasoning" not supported');
|
|
1925
|
-
// return {
|
|
1926
|
-
// type: 'redacted-reasoning',
|
|
1927
|
-
// id: chunk.payload.id,
|
|
1928
|
-
// data: chunk.payload.data,
|
|
1929
|
-
// };
|
|
1930
2004
|
case "reasoning-end":
|
|
1931
2005
|
return {
|
|
1932
2006
|
type: "reasoning-end",
|
|
@@ -2080,6 +2154,59 @@ function convertMastraChunkToAISDKv5({
|
|
|
2080
2154
|
return;
|
|
2081
2155
|
}
|
|
2082
2156
|
}
|
|
2157
|
+
function isV3Usage(usage) {
|
|
2158
|
+
if (!usage || typeof usage !== "object") return false;
|
|
2159
|
+
const u = usage;
|
|
2160
|
+
return typeof u.inputTokens === "object" && u.inputTokens !== null && "total" in u.inputTokens && typeof u.outputTokens === "object" && u.outputTokens !== null && "total" in u.outputTokens;
|
|
2161
|
+
}
|
|
2162
|
+
function normalizeUsage(usage) {
|
|
2163
|
+
if (!usage) {
|
|
2164
|
+
return {
|
|
2165
|
+
inputTokens: void 0,
|
|
2166
|
+
outputTokens: void 0,
|
|
2167
|
+
totalTokens: void 0,
|
|
2168
|
+
reasoningTokens: void 0,
|
|
2169
|
+
cachedInputTokens: void 0,
|
|
2170
|
+
raw: void 0
|
|
2171
|
+
};
|
|
2172
|
+
}
|
|
2173
|
+
if (isV3Usage(usage)) {
|
|
2174
|
+
const inputTokens = usage.inputTokens.total;
|
|
2175
|
+
const outputTokens = usage.outputTokens.total;
|
|
2176
|
+
return {
|
|
2177
|
+
inputTokens,
|
|
2178
|
+
outputTokens,
|
|
2179
|
+
totalTokens: (inputTokens ?? 0) + (outputTokens ?? 0),
|
|
2180
|
+
reasoningTokens: usage.outputTokens.reasoning,
|
|
2181
|
+
cachedInputTokens: usage.inputTokens.cacheRead,
|
|
2182
|
+
raw: usage
|
|
2183
|
+
};
|
|
2184
|
+
}
|
|
2185
|
+
const v2Usage = usage;
|
|
2186
|
+
return {
|
|
2187
|
+
inputTokens: v2Usage.inputTokens,
|
|
2188
|
+
outputTokens: v2Usage.outputTokens,
|
|
2189
|
+
totalTokens: v2Usage.totalTokens ?? (v2Usage.inputTokens ?? 0) + (v2Usage.outputTokens ?? 0),
|
|
2190
|
+
reasoningTokens: v2Usage.reasoningTokens,
|
|
2191
|
+
cachedInputTokens: v2Usage.cachedInputTokens,
|
|
2192
|
+
raw: usage
|
|
2193
|
+
};
|
|
2194
|
+
}
|
|
2195
|
+
function isV3FinishReason(finishReason) {
|
|
2196
|
+
return typeof finishReason === "object" && finishReason !== null && "unified" in finishReason;
|
|
2197
|
+
}
|
|
2198
|
+
function normalizeFinishReason(finishReason) {
|
|
2199
|
+
if (!finishReason) {
|
|
2200
|
+
return "other";
|
|
2201
|
+
}
|
|
2202
|
+
if (finishReason === "tripwire" || finishReason === "retry") {
|
|
2203
|
+
return finishReason;
|
|
2204
|
+
}
|
|
2205
|
+
if (isV3FinishReason(finishReason)) {
|
|
2206
|
+
return finishReason.unified;
|
|
2207
|
+
}
|
|
2208
|
+
return finishReason === "unknown" ? "other" : finishReason;
|
|
2209
|
+
}
|
|
2083
2210
|
|
|
2084
2211
|
// src/stream/aisdk/v5/output.ts
|
|
2085
2212
|
var AISDKV5OutputStream = class {
|
|
@@ -2975,7 +3102,11 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
2975
3102
|
#warnings = [];
|
|
2976
3103
|
#finishReason = void 0;
|
|
2977
3104
|
#request = {};
|
|
2978
|
-
#usageCount = {
|
|
3105
|
+
#usageCount = {
|
|
3106
|
+
inputTokens: void 0,
|
|
3107
|
+
outputTokens: void 0,
|
|
3108
|
+
totalTokens: void 0
|
|
3109
|
+
};
|
|
2979
3110
|
#tripwire = void 0;
|
|
2980
3111
|
#delayedPromises = {
|
|
2981
3112
|
suspendPayload: new DelayedPromise(),
|
|
@@ -3322,23 +3453,25 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
3322
3453
|
};
|
|
3323
3454
|
self.#finishReason = "other";
|
|
3324
3455
|
self.#streamFinished = true;
|
|
3325
|
-
self
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3456
|
+
self.resolvePromises({
|
|
3457
|
+
text: self.#bufferedText.join(""),
|
|
3458
|
+
finishReason: "other",
|
|
3459
|
+
object: void 0,
|
|
3460
|
+
usage: self.#usageCount,
|
|
3461
|
+
warnings: self.#warnings,
|
|
3462
|
+
providerMetadata: void 0,
|
|
3463
|
+
response: {},
|
|
3464
|
+
request: {},
|
|
3465
|
+
reasoning: [],
|
|
3466
|
+
reasoningText: void 0,
|
|
3467
|
+
sources: [],
|
|
3468
|
+
files: [],
|
|
3469
|
+
toolCalls: [],
|
|
3470
|
+
toolResults: [],
|
|
3471
|
+
steps: self.#bufferedSteps,
|
|
3472
|
+
totalUsage: self.#usageCount,
|
|
3473
|
+
content: []
|
|
3474
|
+
});
|
|
3342
3475
|
self.#emitChunk(chunk);
|
|
3343
3476
|
controller.enqueue(chunk);
|
|
3344
3477
|
self.#emitter.emit("finish");
|
|
@@ -3406,8 +3539,10 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
3406
3539
|
if (lastStep && outputText && outputText !== originalText) {
|
|
3407
3540
|
lastStep.text = outputText;
|
|
3408
3541
|
}
|
|
3409
|
-
|
|
3410
|
-
|
|
3542
|
+
this.resolvePromises({
|
|
3543
|
+
text: outputText || originalText,
|
|
3544
|
+
finishReason: self.#finishReason
|
|
3545
|
+
});
|
|
3411
3546
|
if (chunk.payload.metadata) {
|
|
3412
3547
|
const { providerMetadata, request, ...otherMetadata } = chunk.payload.metadata;
|
|
3413
3548
|
response = {
|
|
@@ -3417,9 +3552,10 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
3417
3552
|
};
|
|
3418
3553
|
}
|
|
3419
3554
|
} else if (!self.#options.isLLMExecutionStep) {
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3555
|
+
this.resolvePromises({
|
|
3556
|
+
text: self.#bufferedText.join(""),
|
|
3557
|
+
finishReason: self.#finishReason
|
|
3558
|
+
});
|
|
3423
3559
|
}
|
|
3424
3560
|
} catch (error2) {
|
|
3425
3561
|
if (error2 instanceof TripWire) {
|
|
@@ -3429,35 +3565,41 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
3429
3565
|
metadata: error2.options?.metadata,
|
|
3430
3566
|
processorId: error2.processorId
|
|
3431
3567
|
};
|
|
3432
|
-
self
|
|
3433
|
-
|
|
3568
|
+
self.resolvePromises({
|
|
3569
|
+
finishReason: "other",
|
|
3570
|
+
text: ""
|
|
3571
|
+
});
|
|
3434
3572
|
} else {
|
|
3435
3573
|
self.#error = getErrorFromUnknown(error2, {
|
|
3436
3574
|
fallbackMessage: "Unknown error in stream"
|
|
3437
3575
|
});
|
|
3438
|
-
self
|
|
3439
|
-
|
|
3576
|
+
self.resolvePromises({
|
|
3577
|
+
finishReason: "error",
|
|
3578
|
+
text: ""
|
|
3579
|
+
});
|
|
3440
3580
|
}
|
|
3441
3581
|
if (self.#delayedPromises.object.status.type !== "resolved") {
|
|
3442
3582
|
self.#delayedPromises.object.resolve(void 0);
|
|
3443
3583
|
}
|
|
3444
3584
|
}
|
|
3445
|
-
self.#delayedPromises.usage.resolve(self.#usageCount);
|
|
3446
|
-
self.#delayedPromises.warnings.resolve(self.#warnings);
|
|
3447
|
-
self.#delayedPromises.providerMetadata.resolve(chunk.payload.metadata?.providerMetadata);
|
|
3448
|
-
self.#delayedPromises.response.resolve(response);
|
|
3449
|
-
self.#delayedPromises.request.resolve(self.#request || {});
|
|
3450
3585
|
const reasoningText = self.#bufferedReasoning.length > 0 ? self.#bufferedReasoning.map((reasoningPart) => reasoningPart.payload.text).join("") : void 0;
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3586
|
+
this.resolvePromises({
|
|
3587
|
+
usage: self.#usageCount,
|
|
3588
|
+
warnings: self.#warnings,
|
|
3589
|
+
providerMetadata: chunk.payload.metadata?.providerMetadata,
|
|
3590
|
+
response,
|
|
3591
|
+
request: self.#request || {},
|
|
3592
|
+
reasoningText,
|
|
3593
|
+
reasoning: Object.values(self.#bufferedReasoningDetails || {}),
|
|
3594
|
+
sources: self.#bufferedSources,
|
|
3595
|
+
files: self.#bufferedFiles,
|
|
3596
|
+
toolCalls: self.#toolCalls,
|
|
3597
|
+
toolResults: self.#toolResults,
|
|
3598
|
+
steps: self.#bufferedSteps,
|
|
3599
|
+
totalUsage: self.#getTotalUsage(),
|
|
3600
|
+
content: messageList.get.response.aiV5.stepContent(),
|
|
3601
|
+
suspendPayload: void 0
|
|
3602
|
+
});
|
|
3461
3603
|
const baseFinishStep = self.#bufferedSteps[self.#bufferedSteps.length - 1];
|
|
3462
3604
|
if (baseFinishStep) {
|
|
3463
3605
|
const onFinishPayload = {
|
|
@@ -3525,6 +3667,28 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
3525
3667
|
if (self.#delayedPromises.object.status.type === "pending") {
|
|
3526
3668
|
self.#delayedPromises.object.resolve(void 0);
|
|
3527
3669
|
}
|
|
3670
|
+
if (self.#status === "suspended") {
|
|
3671
|
+
const reasoningText = self.#bufferedReasoning.length > 0 ? self.#bufferedReasoning.map((reasoningPart) => reasoningPart.payload.text).join("") : void 0;
|
|
3672
|
+
self.resolvePromises({
|
|
3673
|
+
toolResults: self.#toolResults,
|
|
3674
|
+
toolCalls: self.#toolCalls,
|
|
3675
|
+
text: self.#bufferedText.join(""),
|
|
3676
|
+
reasoning: Object.values(self.#bufferedReasoningDetails || {}),
|
|
3677
|
+
reasoningText,
|
|
3678
|
+
sources: self.#bufferedSources,
|
|
3679
|
+
files: self.#bufferedFiles,
|
|
3680
|
+
steps: self.#bufferedSteps,
|
|
3681
|
+
usage: self.#usageCount,
|
|
3682
|
+
totalUsage: self.#getTotalUsage(),
|
|
3683
|
+
warnings: self.#warnings,
|
|
3684
|
+
finishReason: "other",
|
|
3685
|
+
content: self.messageList.get.response.aiV5.stepContent(),
|
|
3686
|
+
object: void 0,
|
|
3687
|
+
request: self.#request,
|
|
3688
|
+
response: {},
|
|
3689
|
+
providerMetadata: void 0
|
|
3690
|
+
});
|
|
3691
|
+
}
|
|
3528
3692
|
Object.entries(self.#delayedPromises).forEach(([key, promise]) => {
|
|
3529
3693
|
if (promise.status.type === "pending") {
|
|
3530
3694
|
promise.reject(new Error(`promise '${key}' was not resolved or rejected when stream finished`));
|
|
@@ -3548,6 +3712,23 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
3548
3712
|
this.deserializeState(initialState);
|
|
3549
3713
|
}
|
|
3550
3714
|
}
|
|
3715
|
+
resolvePromise(key, value) {
|
|
3716
|
+
if (!(key in this.#delayedPromises)) {
|
|
3717
|
+
throw new MastraError({
|
|
3718
|
+
id: "MASTRA_MODEL_OUTPUT_INVALID_PROMISE_KEY",
|
|
3719
|
+
domain: "LLM" /* LLM */,
|
|
3720
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
3721
|
+
text: `Attempted to resolve invalid promise key '${key}' with value '${typeof value === "object" ? JSON.stringify(value, null, 2) : value}'`
|
|
3722
|
+
});
|
|
3723
|
+
}
|
|
3724
|
+
this.#delayedPromises[key].resolve(value);
|
|
3725
|
+
}
|
|
3726
|
+
resolvePromises(data) {
|
|
3727
|
+
for (const keyString in data) {
|
|
3728
|
+
const key = keyString;
|
|
3729
|
+
this.resolvePromise(key, data[key]);
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3551
3732
|
#getDelayedPromise(promise) {
|
|
3552
3733
|
if (!this.#consumptionStarted) {
|
|
3553
3734
|
void this.consumeStream();
|
|
@@ -4198,6 +4379,8 @@ var WorkflowRunOutput = class {
|
|
|
4198
4379
|
} else {
|
|
4199
4380
|
self.#status = "failed";
|
|
4200
4381
|
}
|
|
4382
|
+
} else if (chunk.type === "workflow-paused") {
|
|
4383
|
+
self.#status = "paused";
|
|
4201
4384
|
}
|
|
4202
4385
|
},
|
|
4203
4386
|
close() {
|
|
@@ -4333,6 +4516,8 @@ var WorkflowRunOutput = class {
|
|
|
4333
4516
|
} else {
|
|
4334
4517
|
self.#status = "failed";
|
|
4335
4518
|
}
|
|
4519
|
+
} else if (chunk.type === "workflow-paused") {
|
|
4520
|
+
self.#status = "paused";
|
|
4336
4521
|
}
|
|
4337
4522
|
},
|
|
4338
4523
|
close() {
|
|
@@ -4520,7 +4705,7 @@ var getModelOutputForTripwire = async ({
|
|
|
4520
4705
|
model: {
|
|
4521
4706
|
modelId: model.modelId,
|
|
4522
4707
|
provider: model.provider,
|
|
4523
|
-
version: model.specificationVersion
|
|
4708
|
+
version: model.specificationVersion
|
|
4524
4709
|
},
|
|
4525
4710
|
stream: tripwireStream,
|
|
4526
4711
|
messageList,
|
|
@@ -4591,11 +4776,6 @@ function runScorer({
|
|
|
4591
4776
|
};
|
|
4592
4777
|
executeHook("onScorerRun" /* ON_SCORER_RUN */, payload);
|
|
4593
4778
|
}
|
|
4594
|
-
|
|
4595
|
-
// src/llm/model/is-v2-model.ts
|
|
4596
|
-
function isV2Model(model) {
|
|
4597
|
-
return model.specificationVersion === "v2";
|
|
4598
|
-
}
|
|
4599
4779
|
var EventEmitterPubSub = class extends PubSub {
|
|
4600
4780
|
emitter;
|
|
4601
4781
|
constructor(existingEmitter) {
|
|
@@ -5062,7 +5242,7 @@ var getStepIds = (entry) => {
|
|
|
5062
5242
|
return [];
|
|
5063
5243
|
};
|
|
5064
5244
|
var createTimeTravelExecutionParams = (params) => {
|
|
5065
|
-
const { steps, inputData, resumeData, context, nestedStepsContext, snapshot, initialState, graph } = params;
|
|
5245
|
+
const { steps, inputData, resumeData, context, nestedStepsContext, snapshot, initialState, graph, perStep } = params;
|
|
5066
5246
|
const firstStepId = steps[0];
|
|
5067
5247
|
let executionPath = [];
|
|
5068
5248
|
const stepResults = {};
|
|
@@ -5129,7 +5309,8 @@ var createTimeTravelExecutionParams = (params) => {
|
|
|
5129
5309
|
suspendedAt: stepContext?.suspendedAt,
|
|
5130
5310
|
resumedAt: stepContext?.resumedAt
|
|
5131
5311
|
};
|
|
5132
|
-
|
|
5312
|
+
const execPathLengthToUse = perStep ? executionPath.length : currentExecPathLength;
|
|
5313
|
+
if (execPathLengthToUse > 0 && !steps?.includes(stepId) && !context?.[stepId] && (!snapshotContext[stepId] || snapshotContext[stepId] && snapshotContext[stepId].status !== "suspended")) {
|
|
5133
5314
|
result = void 0;
|
|
5134
5315
|
}
|
|
5135
5316
|
if (result) {
|
|
@@ -5184,7 +5365,8 @@ async function executeParallel(engine, params) {
|
|
|
5184
5365
|
abortController,
|
|
5185
5366
|
requestContext,
|
|
5186
5367
|
outputWriter,
|
|
5187
|
-
disableScorers
|
|
5368
|
+
disableScorers,
|
|
5369
|
+
perStep
|
|
5188
5370
|
} = params;
|
|
5189
5371
|
const parallelSpan = tracingContext.currentSpan?.createChildSpan({
|
|
5190
5372
|
type: "workflow_parallel" /* WORKFLOW_PARALLEL */,
|
|
@@ -5206,7 +5388,7 @@ async function executeParallel(engine, params) {
|
|
|
5206
5388
|
makeStepRunning = timeTravel.steps[0] === step.step.id;
|
|
5207
5389
|
}
|
|
5208
5390
|
if (!makeStepRunning) {
|
|
5209
|
-
|
|
5391
|
+
break;
|
|
5210
5392
|
}
|
|
5211
5393
|
const startTime = resume?.steps[0] === step.step.id ? void 0 : Date.now();
|
|
5212
5394
|
const resumeTime = resume?.steps[0] === step.step.id ? Date.now() : void 0;
|
|
@@ -5218,6 +5400,9 @@ async function executeParallel(engine, params) {
|
|
|
5218
5400
|
...resumeTime ? { resumedAt: resumeTime } : {}
|
|
5219
5401
|
};
|
|
5220
5402
|
executionContext.activeStepsPath[step.step.id] = [...executionContext.executionPath, stepIndex];
|
|
5403
|
+
if (perStep) {
|
|
5404
|
+
break;
|
|
5405
|
+
}
|
|
5221
5406
|
}
|
|
5222
5407
|
if (timeTravel && timeTravel.executionPath.length > 0) {
|
|
5223
5408
|
timeTravel.executionPath.shift();
|
|
@@ -5229,6 +5414,9 @@ async function executeParallel(engine, params) {
|
|
|
5229
5414
|
if (currStepResult && currStepResult.status !== "running") {
|
|
5230
5415
|
return currStepResult;
|
|
5231
5416
|
}
|
|
5417
|
+
if (!currStepResult && (perStep || timeTravel)) {
|
|
5418
|
+
return {};
|
|
5419
|
+
}
|
|
5232
5420
|
const stepExecResult = await engine.executeStep({
|
|
5233
5421
|
workflowId,
|
|
5234
5422
|
runId,
|
|
@@ -5257,7 +5445,8 @@ async function executeParallel(engine, params) {
|
|
|
5257
5445
|
abortController,
|
|
5258
5446
|
requestContext,
|
|
5259
5447
|
outputWriter,
|
|
5260
|
-
disableScorers
|
|
5448
|
+
disableScorers,
|
|
5449
|
+
perStep
|
|
5261
5450
|
});
|
|
5262
5451
|
engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
|
|
5263
5452
|
Object.assign(stepResults, stepExecResult.stepResults);
|
|
@@ -5318,7 +5507,8 @@ async function executeConditional(engine, params) {
|
|
|
5318
5507
|
abortController,
|
|
5319
5508
|
requestContext,
|
|
5320
5509
|
outputWriter,
|
|
5321
|
-
disableScorers
|
|
5510
|
+
disableScorers,
|
|
5511
|
+
perStep
|
|
5322
5512
|
} = params;
|
|
5323
5513
|
const conditionalSpan = tracingContext.currentSpan?.createChildSpan({
|
|
5324
5514
|
type: "workflow_conditional" /* WORKFLOW_CONDITIONAL */,
|
|
@@ -5413,7 +5603,18 @@ async function executeConditional(engine, params) {
|
|
|
5413
5603
|
}
|
|
5414
5604
|
})
|
|
5415
5605
|
)).filter((index) => index !== null);
|
|
5416
|
-
|
|
5606
|
+
let stepsToRun = entry.steps.filter((_, index) => truthyIndexes.includes(index));
|
|
5607
|
+
if (perStep || timeTravel && timeTravel.executionPath.length > 0) {
|
|
5608
|
+
const possibleStepsToRun = stepsToRun.filter((s) => {
|
|
5609
|
+
const currStepResult = stepResults[s.step.id];
|
|
5610
|
+
if (timeTravel && timeTravel.executionPath.length > 0) {
|
|
5611
|
+
return timeTravel.steps[0] === s.step.id;
|
|
5612
|
+
}
|
|
5613
|
+
return !currStepResult;
|
|
5614
|
+
});
|
|
5615
|
+
const possibleStepToRun = possibleStepsToRun?.[0];
|
|
5616
|
+
stepsToRun = possibleStepToRun ? [possibleStepToRun] : stepsToRun;
|
|
5617
|
+
}
|
|
5417
5618
|
conditionalSpan?.update({
|
|
5418
5619
|
attributes: {
|
|
5419
5620
|
truthyIndexes,
|
|
@@ -5460,7 +5661,8 @@ async function executeConditional(engine, params) {
|
|
|
5460
5661
|
abortController,
|
|
5461
5662
|
requestContext,
|
|
5462
5663
|
outputWriter,
|
|
5463
|
-
disableScorers
|
|
5664
|
+
disableScorers,
|
|
5665
|
+
perStep
|
|
5464
5666
|
});
|
|
5465
5667
|
engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
|
|
5466
5668
|
Object.assign(stepResults, stepExecResult.stepResults);
|
|
@@ -5522,7 +5724,8 @@ async function executeLoop(engine, params) {
|
|
|
5522
5724
|
requestContext,
|
|
5523
5725
|
outputWriter,
|
|
5524
5726
|
disableScorers,
|
|
5525
|
-
serializedStepGraph
|
|
5727
|
+
serializedStepGraph,
|
|
5728
|
+
perStep
|
|
5526
5729
|
} = params;
|
|
5527
5730
|
const { step, condition } = entry;
|
|
5528
5731
|
const loopSpan = tracingContext.currentSpan?.createChildSpan({
|
|
@@ -5563,7 +5766,8 @@ async function executeLoop(engine, params) {
|
|
|
5563
5766
|
outputWriter,
|
|
5564
5767
|
disableScorers,
|
|
5565
5768
|
serializedStepGraph,
|
|
5566
|
-
iterationCount: iteration + 1
|
|
5769
|
+
iterationCount: iteration + 1,
|
|
5770
|
+
perStep
|
|
5567
5771
|
});
|
|
5568
5772
|
engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
|
|
5569
5773
|
Object.assign(stepResults, stepExecResult.stepResults);
|
|
@@ -5663,7 +5867,8 @@ async function executeForeach(engine, params) {
|
|
|
5663
5867
|
requestContext,
|
|
5664
5868
|
outputWriter,
|
|
5665
5869
|
disableScorers,
|
|
5666
|
-
serializedStepGraph
|
|
5870
|
+
serializedStepGraph,
|
|
5871
|
+
perStep
|
|
5667
5872
|
} = params;
|
|
5668
5873
|
const { step, opts } = entry;
|
|
5669
5874
|
const results = [];
|
|
@@ -5740,7 +5945,8 @@ async function executeForeach(engine, params) {
|
|
|
5740
5945
|
skipEmits: true,
|
|
5741
5946
|
outputWriter,
|
|
5742
5947
|
disableScorers,
|
|
5743
|
-
serializedStepGraph
|
|
5948
|
+
serializedStepGraph,
|
|
5949
|
+
perStep
|
|
5744
5950
|
});
|
|
5745
5951
|
engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
|
|
5746
5952
|
Object.assign(stepResults, stepExecResult.stepResults);
|
|
@@ -5882,7 +6088,8 @@ async function persistStepUpdate(engine, params) {
|
|
|
5882
6088
|
requestContext.forEach((value, key) => {
|
|
5883
6089
|
requestContextObj[key] = value;
|
|
5884
6090
|
});
|
|
5885
|
-
await engine.mastra?.getStorage()?.
|
|
6091
|
+
const workflowsStore = await engine.mastra?.getStorage()?.getStore("workflows");
|
|
6092
|
+
await workflowsStore?.persistWorkflowSnapshot({
|
|
5886
6093
|
workflowName: workflowId,
|
|
5887
6094
|
runId,
|
|
5888
6095
|
resourceId,
|
|
@@ -5924,7 +6131,8 @@ async function executeEntry(engine, params) {
|
|
|
5924
6131
|
abortController,
|
|
5925
6132
|
requestContext,
|
|
5926
6133
|
outputWriter,
|
|
5927
|
-
disableScorers
|
|
6134
|
+
disableScorers,
|
|
6135
|
+
perStep
|
|
5928
6136
|
} = params;
|
|
5929
6137
|
const prevOutput = engine.getStepOutput(stepResults, prevStep);
|
|
5930
6138
|
let execResults;
|
|
@@ -5948,7 +6156,8 @@ async function executeEntry(engine, params) {
|
|
|
5948
6156
|
requestContext,
|
|
5949
6157
|
outputWriter,
|
|
5950
6158
|
disableScorers,
|
|
5951
|
-
serializedStepGraph
|
|
6159
|
+
serializedStepGraph,
|
|
6160
|
+
perStep
|
|
5952
6161
|
});
|
|
5953
6162
|
execResults = stepExecResult.result;
|
|
5954
6163
|
engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
|
|
@@ -5980,7 +6189,8 @@ async function executeEntry(engine, params) {
|
|
|
5980
6189
|
abortController,
|
|
5981
6190
|
requestContext,
|
|
5982
6191
|
outputWriter,
|
|
5983
|
-
disableScorers
|
|
6192
|
+
disableScorers,
|
|
6193
|
+
perStep
|
|
5984
6194
|
});
|
|
5985
6195
|
engine.applyMutableContext(executionContext, resumedStepResult.mutableContext);
|
|
5986
6196
|
Object.assign(stepResults, resumedStepResult.stepResults);
|
|
@@ -6050,7 +6260,8 @@ async function executeEntry(engine, params) {
|
|
|
6050
6260
|
abortController,
|
|
6051
6261
|
requestContext,
|
|
6052
6262
|
outputWriter,
|
|
6053
|
-
disableScorers
|
|
6263
|
+
disableScorers,
|
|
6264
|
+
perStep
|
|
6054
6265
|
});
|
|
6055
6266
|
} else if (entry.type === "conditional") {
|
|
6056
6267
|
execResults = await engine.executeConditional({
|
|
@@ -6069,7 +6280,8 @@ async function executeEntry(engine, params) {
|
|
|
6069
6280
|
abortController,
|
|
6070
6281
|
requestContext,
|
|
6071
6282
|
outputWriter,
|
|
6072
|
-
disableScorers
|
|
6283
|
+
disableScorers,
|
|
6284
|
+
perStep
|
|
6073
6285
|
});
|
|
6074
6286
|
} else if (entry.type === "loop") {
|
|
6075
6287
|
execResults = await engine.executeLoop({
|
|
@@ -6089,7 +6301,8 @@ async function executeEntry(engine, params) {
|
|
|
6089
6301
|
requestContext,
|
|
6090
6302
|
outputWriter,
|
|
6091
6303
|
disableScorers,
|
|
6092
|
-
serializedStepGraph
|
|
6304
|
+
serializedStepGraph,
|
|
6305
|
+
perStep
|
|
6093
6306
|
});
|
|
6094
6307
|
} else if (entry.type === "foreach") {
|
|
6095
6308
|
execResults = await engine.executeForeach({
|
|
@@ -6109,7 +6322,8 @@ async function executeEntry(engine, params) {
|
|
|
6109
6322
|
requestContext,
|
|
6110
6323
|
outputWriter,
|
|
6111
6324
|
disableScorers,
|
|
6112
|
-
serializedStepGraph
|
|
6325
|
+
serializedStepGraph,
|
|
6326
|
+
perStep
|
|
6113
6327
|
});
|
|
6114
6328
|
} else if (entry.type === "sleep") {
|
|
6115
6329
|
const startedAt = Date.now();
|
|
@@ -6521,7 +6735,8 @@ async function executeStep(engine, params) {
|
|
|
6521
6735
|
disableScorers,
|
|
6522
6736
|
serializedStepGraph,
|
|
6523
6737
|
tracingContext,
|
|
6524
|
-
iterationCount
|
|
6738
|
+
iterationCount,
|
|
6739
|
+
perStep
|
|
6525
6740
|
} = params;
|
|
6526
6741
|
const stepCallId = randomUUID();
|
|
6527
6742
|
const { inputData, validationError } = await validateStepInput({
|
|
@@ -6563,10 +6778,9 @@ async function executeStep(engine, params) {
|
|
|
6563
6778
|
const stepSpan = tracingContext.currentSpan?.createChildSpan({
|
|
6564
6779
|
name: `workflow step: '${step.id}'`,
|
|
6565
6780
|
type: "workflow_step" /* WORKFLOW_STEP */,
|
|
6781
|
+
entityType: "workflow_step" /* WORKFLOW_STEP */,
|
|
6782
|
+
entityId: step.id,
|
|
6566
6783
|
input: inputData,
|
|
6567
|
-
attributes: {
|
|
6568
|
-
stepId: step.id
|
|
6569
|
-
},
|
|
6570
6784
|
tracingPolicy: engine.options?.tracingPolicy
|
|
6571
6785
|
});
|
|
6572
6786
|
const operationId = `workflow.${workflowId}.run.${runId}.step.${step.id}.running_ev`;
|
|
@@ -6608,7 +6822,8 @@ async function executeStep(engine, params) {
|
|
|
6608
6822
|
requestContext,
|
|
6609
6823
|
tracingContext,
|
|
6610
6824
|
outputWriter,
|
|
6611
|
-
stepSpan
|
|
6825
|
+
stepSpan,
|
|
6826
|
+
perStep
|
|
6612
6827
|
});
|
|
6613
6828
|
if (workflowResult !== null) {
|
|
6614
6829
|
const stepResult2 = { ...stepInfo, ...workflowResult };
|
|
@@ -6740,12 +6955,15 @@ async function executeStep(engine, params) {
|
|
|
6740
6955
|
outputWriter,
|
|
6741
6956
|
// Disable scorers must be explicitly set to false they are on by default
|
|
6742
6957
|
scorers: disableScorers === false ? void 0 : step.scorers,
|
|
6743
|
-
validateInputs: engine.options?.validateInputs
|
|
6958
|
+
validateInputs: engine.options?.validateInputs,
|
|
6959
|
+
perStep
|
|
6744
6960
|
});
|
|
6745
6961
|
if (engine.requiresDurableContextSerialization()) {
|
|
6746
6962
|
contextMutations.requestContextUpdate = engine.serializeRequestContext(requestContext);
|
|
6747
6963
|
}
|
|
6748
|
-
|
|
6964
|
+
const isNestedWorkflowStep = step.component === "WORKFLOW";
|
|
6965
|
+
const nestedWflowStepPaused = isNestedWorkflowStep && perStep;
|
|
6966
|
+
return { output, suspended, bailed, contextMutations, nestedWflowStepPaused };
|
|
6749
6967
|
},
|
|
6750
6968
|
{ retries, delay: delay2, stepSpan, workflowId, runId }
|
|
6751
6969
|
);
|
|
@@ -6784,6 +7002,8 @@ async function executeStep(engine, params) {
|
|
|
6784
7002
|
};
|
|
6785
7003
|
} else if (durableResult.bailed) {
|
|
6786
7004
|
execResults = { status: "bailed", output: durableResult.bailed.payload, endedAt: Date.now() };
|
|
7005
|
+
} else if (durableResult.nestedWflowStepPaused) {
|
|
7006
|
+
execResults = { status: "paused" };
|
|
6787
7007
|
} else {
|
|
6788
7008
|
execResults = { status: "success", output: durableResult.output, endedAt: Date.now() };
|
|
6789
7009
|
}
|
|
@@ -7207,7 +7427,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7207
7427
|
workflowSpan,
|
|
7208
7428
|
disableScorers,
|
|
7209
7429
|
restart,
|
|
7210
|
-
timeTravel
|
|
7430
|
+
timeTravel,
|
|
7431
|
+
perStep
|
|
7211
7432
|
} = params;
|
|
7212
7433
|
const { attempts = 0, delay: delay2 = 0 } = retryConfig ?? {};
|
|
7213
7434
|
const steps = graph.steps;
|
|
@@ -7271,7 +7492,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7271
7492
|
pubsub: params.pubsub,
|
|
7272
7493
|
requestContext: currentRequestContext,
|
|
7273
7494
|
outputWriter: params.outputWriter,
|
|
7274
|
-
disableScorers
|
|
7495
|
+
disableScorers,
|
|
7496
|
+
perStep
|
|
7275
7497
|
});
|
|
7276
7498
|
this.applyMutableContext(executionContext, lastOutput.mutableContext);
|
|
7277
7499
|
lastState = lastOutput.mutableContext.state;
|
|
@@ -7310,13 +7532,47 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7310
7532
|
}
|
|
7311
7533
|
});
|
|
7312
7534
|
}
|
|
7313
|
-
|
|
7535
|
+
if (lastOutput.result.status !== "paused") {
|
|
7536
|
+
await this.invokeLifecycleCallbacks(result2);
|
|
7537
|
+
}
|
|
7538
|
+
if (lastOutput.result.status === "paused") {
|
|
7539
|
+
await params.pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
7540
|
+
type: "watch",
|
|
7541
|
+
runId,
|
|
7542
|
+
data: { type: "workflow-paused", payload: {} }
|
|
7543
|
+
});
|
|
7544
|
+
}
|
|
7314
7545
|
return {
|
|
7315
7546
|
...result2,
|
|
7316
7547
|
...lastOutput.result.status === "suspended" && params.outputOptions?.includeResumeLabels ? { resumeLabels: lastOutput.mutableContext.resumeLabels } : {},
|
|
7317
7548
|
...params.outputOptions?.includeState ? { state: lastState } : {}
|
|
7318
7549
|
};
|
|
7319
7550
|
}
|
|
7551
|
+
if (perStep) {
|
|
7552
|
+
const result2 = await this.fmtReturnValue(params.pubsub, stepResults, lastOutput.result);
|
|
7553
|
+
await this.persistStepUpdate({
|
|
7554
|
+
workflowId,
|
|
7555
|
+
runId,
|
|
7556
|
+
resourceId,
|
|
7557
|
+
stepResults: lastOutput.stepResults,
|
|
7558
|
+
serializedStepGraph: params.serializedStepGraph,
|
|
7559
|
+
executionContext: lastExecutionContext,
|
|
7560
|
+
workflowStatus: "paused",
|
|
7561
|
+
requestContext: currentRequestContext
|
|
7562
|
+
});
|
|
7563
|
+
await params.pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
7564
|
+
type: "watch",
|
|
7565
|
+
runId,
|
|
7566
|
+
data: { type: "workflow-paused", payload: {} }
|
|
7567
|
+
});
|
|
7568
|
+
workflowSpan?.end({
|
|
7569
|
+
attributes: {
|
|
7570
|
+
status: "paused"
|
|
7571
|
+
}
|
|
7572
|
+
});
|
|
7573
|
+
delete result2.result;
|
|
7574
|
+
return { ...result2, status: "paused", ...params.outputOptions?.includeState ? { state: lastState } : {} };
|
|
7575
|
+
}
|
|
7320
7576
|
}
|
|
7321
7577
|
const result = await this.fmtReturnValue(params.pubsub, stepResults, lastOutput.result);
|
|
7322
7578
|
await this.persistStepUpdate({
|
|
@@ -7848,7 +8104,8 @@ function createStep(params, agentOptions) {
|
|
|
7848
8104
|
finishReason,
|
|
7849
8105
|
toolCalls,
|
|
7850
8106
|
text,
|
|
7851
|
-
systemMessages: systemMessages ?? []
|
|
8107
|
+
systemMessages: systemMessages ?? [],
|
|
8108
|
+
steps: steps ?? []
|
|
7852
8109
|
});
|
|
7853
8110
|
const applyMessages = (msgs) => {
|
|
7854
8111
|
const deletedIds = idsBeforeProcessing.filter((i) => !msgs.some((m) => m.id === i));
|
|
@@ -8114,8 +8371,8 @@ var Workflow = class extends MastraBase {
|
|
|
8114
8371
|
if (typeof mappingConfig === "function") {
|
|
8115
8372
|
const mappingStep2 = createStep({
|
|
8116
8373
|
id: stepOptions?.id || `mapping_${this.#mastra?.generateId() || randomUUID()}`,
|
|
8117
|
-
inputSchema: z.
|
|
8118
|
-
outputSchema: z.
|
|
8374
|
+
inputSchema: z.any(),
|
|
8375
|
+
outputSchema: z.any(),
|
|
8119
8376
|
execute: mappingConfig
|
|
8120
8377
|
});
|
|
8121
8378
|
this.stepFlow.push({ type: "step", step: mappingStep2 });
|
|
@@ -8171,7 +8428,15 @@ var Workflow = class extends MastraBase {
|
|
|
8171
8428
|
result[key] = requestContext.get(m.requestContextPath);
|
|
8172
8429
|
continue;
|
|
8173
8430
|
}
|
|
8174
|
-
const stepResult = m.initData ? getInitData() : getStepResult2(
|
|
8431
|
+
const stepResult = m.initData ? getInitData() : getStepResult2(
|
|
8432
|
+
Array.isArray(m.step) ? m.step.find((s) => {
|
|
8433
|
+
const result2 = getStepResult2(s);
|
|
8434
|
+
if (typeof result2 === "object" && result2 !== null) {
|
|
8435
|
+
return Object.keys(result2).length > 0;
|
|
8436
|
+
}
|
|
8437
|
+
return result2;
|
|
8438
|
+
}) : m.step
|
|
8439
|
+
);
|
|
8175
8440
|
if (m.path === ".") {
|
|
8176
8441
|
result[key] = stepResult;
|
|
8177
8442
|
continue;
|
|
@@ -8382,12 +8647,15 @@ var Workflow = class extends MastraBase {
|
|
|
8382
8647
|
workflowStatus: run.workflowRunStatus,
|
|
8383
8648
|
stepResults: {}
|
|
8384
8649
|
});
|
|
8385
|
-
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse,
|
|
8650
|
+
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, {
|
|
8651
|
+
withNestedWorkflows: false
|
|
8652
|
+
});
|
|
8386
8653
|
if (workflowSnapshotInStorage && workflowSnapshotInStorage.status) {
|
|
8387
8654
|
run.workflowRunStatus = workflowSnapshotInStorage.status;
|
|
8388
8655
|
}
|
|
8389
8656
|
if (!workflowSnapshotInStorage && shouldPersistSnapshot) {
|
|
8390
|
-
await this.mastra?.getStorage()?.
|
|
8657
|
+
const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
|
|
8658
|
+
await workflowsStore?.persistWorkflowSnapshot({
|
|
8391
8659
|
workflowName: this.id,
|
|
8392
8660
|
runId: runIdToUse,
|
|
8393
8661
|
resourceId: options?.resourceId,
|
|
@@ -8452,7 +8720,8 @@ var Workflow = class extends MastraBase {
|
|
|
8452
8720
|
retryCount,
|
|
8453
8721
|
tracingContext,
|
|
8454
8722
|
outputWriter,
|
|
8455
|
-
validateInputs
|
|
8723
|
+
validateInputs,
|
|
8724
|
+
perStep
|
|
8456
8725
|
}) {
|
|
8457
8726
|
this.__registerMastra(mastra);
|
|
8458
8727
|
const effectiveValidateInputs = validateInputs ?? this.#options.validateInputs ?? true;
|
|
@@ -8500,7 +8769,8 @@ var Workflow = class extends MastraBase {
|
|
|
8500
8769
|
requestContext,
|
|
8501
8770
|
tracingContext,
|
|
8502
8771
|
outputWriter,
|
|
8503
|
-
outputOptions: { includeState: true, includeResumeLabels: true }
|
|
8772
|
+
outputOptions: { includeState: true, includeResumeLabels: true },
|
|
8773
|
+
perStep
|
|
8504
8774
|
});
|
|
8505
8775
|
} else if (restart) {
|
|
8506
8776
|
res = await run.restart({ requestContext, tracingContext, outputWriter });
|
|
@@ -8512,7 +8782,8 @@ var Workflow = class extends MastraBase {
|
|
|
8512
8782
|
tracingContext,
|
|
8513
8783
|
outputWriter,
|
|
8514
8784
|
outputOptions: { includeState: true, includeResumeLabels: true },
|
|
8515
|
-
label: resume.label
|
|
8785
|
+
label: resume.label,
|
|
8786
|
+
perStep
|
|
8516
8787
|
});
|
|
8517
8788
|
} else {
|
|
8518
8789
|
res = await run.start({
|
|
@@ -8521,7 +8792,8 @@ var Workflow = class extends MastraBase {
|
|
|
8521
8792
|
tracingContext,
|
|
8522
8793
|
outputWriter,
|
|
8523
8794
|
initialState: state,
|
|
8524
|
-
outputOptions: { includeState: true, includeResumeLabels: true }
|
|
8795
|
+
outputOptions: { includeState: true, includeResumeLabels: true },
|
|
8796
|
+
perStep
|
|
8525
8797
|
});
|
|
8526
8798
|
}
|
|
8527
8799
|
unwatch();
|
|
@@ -8557,7 +8829,12 @@ var Workflow = class extends MastraBase {
|
|
|
8557
8829
|
this.logger.debug("Cannot get workflow runs. Mastra storage is not initialized");
|
|
8558
8830
|
return { runs: [], total: 0 };
|
|
8559
8831
|
}
|
|
8560
|
-
|
|
8832
|
+
const workflowsStore = await storage.getStore("workflows");
|
|
8833
|
+
if (!workflowsStore) {
|
|
8834
|
+
this.logger.debug("Cannot get workflow runs. Workflows storage domain is not available");
|
|
8835
|
+
return { runs: [], total: 0 };
|
|
8836
|
+
}
|
|
8837
|
+
return workflowsStore.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
|
|
8561
8838
|
}
|
|
8562
8839
|
async listActiveWorkflowRuns() {
|
|
8563
8840
|
const runningRuns = await this.listWorkflowRuns({ status: "running" });
|
|
@@ -8594,7 +8871,12 @@ var Workflow = class extends MastraBase {
|
|
|
8594
8871
|
this.logger.debug("Cannot get workflow runs from storage. Mastra storage is not initialized");
|
|
8595
8872
|
return this.#runs.get(runId) ? { ...this.#runs.get(runId), workflowName: this.id } : null;
|
|
8596
8873
|
}
|
|
8597
|
-
const
|
|
8874
|
+
const workflowsStore = await storage.getStore("workflows");
|
|
8875
|
+
if (!workflowsStore) {
|
|
8876
|
+
this.logger.debug("Cannot get workflow runs. Workflows storage domain is not available");
|
|
8877
|
+
return this.#runs.get(runId) ? { ...this.#runs.get(runId), workflowName: this.id } : null;
|
|
8878
|
+
}
|
|
8879
|
+
const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: this.id });
|
|
8598
8880
|
return run ?? (this.#runs.get(runId) ? { ...this.#runs.get(runId), workflowName: this.id } : null);
|
|
8599
8881
|
}
|
|
8600
8882
|
async deleteWorkflowRunById(runId) {
|
|
@@ -8603,7 +8885,12 @@ var Workflow = class extends MastraBase {
|
|
|
8603
8885
|
this.logger.debug("Cannot delete workflow run by ID. Mastra storage is not initialized");
|
|
8604
8886
|
return;
|
|
8605
8887
|
}
|
|
8606
|
-
await storage.
|
|
8888
|
+
const workflowsStore = await storage.getStore("workflows");
|
|
8889
|
+
if (!workflowsStore) {
|
|
8890
|
+
this.logger.debug("Cannot delete workflow run. Workflows storage domain is not available");
|
|
8891
|
+
return;
|
|
8892
|
+
}
|
|
8893
|
+
await workflowsStore.deleteWorkflowRunById({ runId, workflowName: this.id });
|
|
8607
8894
|
this.#runs.delete(runId);
|
|
8608
8895
|
}
|
|
8609
8896
|
async getWorkflowRunSteps({ runId, workflowId }) {
|
|
@@ -8612,7 +8899,12 @@ var Workflow = class extends MastraBase {
|
|
|
8612
8899
|
this.logger.debug("Cannot get workflow run steps. Mastra storage is not initialized");
|
|
8613
8900
|
return {};
|
|
8614
8901
|
}
|
|
8615
|
-
const
|
|
8902
|
+
const workflowsStore = await storage.getStore("workflows");
|
|
8903
|
+
if (!workflowsStore) {
|
|
8904
|
+
this.logger.debug("Cannot get workflow run steps. Workflows storage domain is not available");
|
|
8905
|
+
return {};
|
|
8906
|
+
}
|
|
8907
|
+
const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: workflowId });
|
|
8616
8908
|
let snapshot = run?.snapshot;
|
|
8617
8909
|
if (!snapshot) {
|
|
8618
8910
|
return {};
|
|
@@ -8647,13 +8939,19 @@ var Workflow = class extends MastraBase {
|
|
|
8647
8939
|
}
|
|
8648
8940
|
return finalSteps;
|
|
8649
8941
|
}
|
|
8650
|
-
async getWorkflowRunExecutionResult(runId,
|
|
8942
|
+
async getWorkflowRunExecutionResult(runId, options = {}) {
|
|
8943
|
+
const { withNestedWorkflows = true, fields } = options;
|
|
8651
8944
|
const storage = this.#mastra?.getStorage();
|
|
8652
8945
|
if (!storage) {
|
|
8653
8946
|
this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
|
|
8654
8947
|
return null;
|
|
8655
8948
|
}
|
|
8656
|
-
const
|
|
8949
|
+
const workflowsStore = await storage.getStore("workflows");
|
|
8950
|
+
if (!workflowsStore) {
|
|
8951
|
+
this.logger.debug("Cannot get workflow run execution result. Workflows storage domain is not available");
|
|
8952
|
+
return null;
|
|
8953
|
+
}
|
|
8954
|
+
const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: this.id });
|
|
8657
8955
|
let snapshot = run?.snapshot;
|
|
8658
8956
|
if (!snapshot) {
|
|
8659
8957
|
return null;
|
|
@@ -8666,15 +8964,51 @@ var Workflow = class extends MastraBase {
|
|
|
8666
8964
|
return null;
|
|
8667
8965
|
}
|
|
8668
8966
|
}
|
|
8669
|
-
const
|
|
8967
|
+
const snapshotState = snapshot;
|
|
8968
|
+
const defaultResult = {
|
|
8969
|
+
status: snapshotState.status,
|
|
8970
|
+
result: snapshotState.result,
|
|
8971
|
+
error: snapshotState.error,
|
|
8972
|
+
payload: snapshotState.context?.input,
|
|
8973
|
+
steps: null,
|
|
8974
|
+
// Will be populated below
|
|
8975
|
+
activeStepsPath: snapshotState.activeStepsPath,
|
|
8976
|
+
serializedStepGraph: snapshotState.serializedStepGraph
|
|
8977
|
+
};
|
|
8978
|
+
const allowedFields = new Set(Object.keys(defaultResult));
|
|
8979
|
+
if (fields && fields.length > 0) {
|
|
8980
|
+
const result = {};
|
|
8981
|
+
for (const field of fields) {
|
|
8982
|
+
if (!allowedFields.has(field)) {
|
|
8983
|
+
continue;
|
|
8984
|
+
}
|
|
8985
|
+
if (field === "steps") {
|
|
8986
|
+
let fullSteps2;
|
|
8987
|
+
if (withNestedWorkflows) {
|
|
8988
|
+
fullSteps2 = await this.getWorkflowRunSteps({ runId, workflowId: this.id });
|
|
8989
|
+
} else {
|
|
8990
|
+
const { input, ...stepsOnly } = snapshotState.context || {};
|
|
8991
|
+
fullSteps2 = stepsOnly;
|
|
8992
|
+
}
|
|
8993
|
+
result.steps = fullSteps2;
|
|
8994
|
+
} else if (field === "payload") {
|
|
8995
|
+
result.payload = snapshotState.context?.input;
|
|
8996
|
+
} else {
|
|
8997
|
+
result[field] = snapshotState[field];
|
|
8998
|
+
}
|
|
8999
|
+
}
|
|
9000
|
+
return result;
|
|
9001
|
+
}
|
|
9002
|
+
let fullSteps;
|
|
9003
|
+
if (withNestedWorkflows) {
|
|
9004
|
+
fullSteps = await this.getWorkflowRunSteps({ runId, workflowId: this.id });
|
|
9005
|
+
} else {
|
|
9006
|
+
const { input, ...stepsOnly } = snapshotState.context || {};
|
|
9007
|
+
fullSteps = stepsOnly;
|
|
9008
|
+
}
|
|
8670
9009
|
return {
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
error: snapshot.error,
|
|
8674
|
-
payload: snapshot.context?.input,
|
|
8675
|
-
steps: fullSteps,
|
|
8676
|
-
activeStepsPath: snapshot.activeStepsPath,
|
|
8677
|
-
serializedStepGraph: snapshot.serializedStepGraph
|
|
9010
|
+
...defaultResult,
|
|
9011
|
+
steps: fullSteps
|
|
8678
9012
|
};
|
|
8679
9013
|
}
|
|
8680
9014
|
};
|
|
@@ -8776,7 +9110,8 @@ var Run = class {
|
|
|
8776
9110
|
this.abortController.abort();
|
|
8777
9111
|
this.workflowRunStatus = "canceled";
|
|
8778
9112
|
try {
|
|
8779
|
-
await this.mastra?.getStorage()?.
|
|
9113
|
+
const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
|
|
9114
|
+
await workflowsStore?.updateWorkflowState({
|
|
8780
9115
|
workflowName: this.workflowId,
|
|
8781
9116
|
runId: this.runId,
|
|
8782
9117
|
opts: {
|
|
@@ -8854,15 +9189,15 @@ var Run = class {
|
|
|
8854
9189
|
tracingContext,
|
|
8855
9190
|
tracingOptions,
|
|
8856
9191
|
format,
|
|
8857
|
-
outputOptions
|
|
9192
|
+
outputOptions,
|
|
9193
|
+
perStep
|
|
8858
9194
|
}) {
|
|
8859
9195
|
const workflowSpan = getOrCreateSpan({
|
|
8860
9196
|
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
8861
9197
|
name: `workflow run: '${this.workflowId}'`,
|
|
9198
|
+
entityType: "workflow_run" /* WORKFLOW_RUN */,
|
|
9199
|
+
entityId: this.workflowId,
|
|
8862
9200
|
input: inputData,
|
|
8863
|
-
attributes: {
|
|
8864
|
-
workflowId: this.workflowId
|
|
8865
|
-
},
|
|
8866
9201
|
metadata: {
|
|
8867
9202
|
resourceId: this.resourceId,
|
|
8868
9203
|
runId: this.runId
|
|
@@ -8892,7 +9227,8 @@ var Run = class {
|
|
|
8892
9227
|
outputWriter,
|
|
8893
9228
|
workflowSpan,
|
|
8894
9229
|
format,
|
|
8895
|
-
outputOptions
|
|
9230
|
+
outputOptions,
|
|
9231
|
+
perStep
|
|
8896
9232
|
});
|
|
8897
9233
|
if (result.status !== "suspended") {
|
|
8898
9234
|
this.cleanup?.();
|
|
@@ -9059,9 +9395,10 @@ var Run = class {
|
|
|
9059
9395
|
}
|
|
9060
9396
|
async streamAsync({
|
|
9061
9397
|
inputData,
|
|
9062
|
-
requestContext
|
|
9398
|
+
requestContext,
|
|
9399
|
+
perStep
|
|
9063
9400
|
} = {}) {
|
|
9064
|
-
return this.stream({ inputData, requestContext });
|
|
9401
|
+
return this.stream({ inputData, requestContext, perStep });
|
|
9065
9402
|
}
|
|
9066
9403
|
/**
|
|
9067
9404
|
* Starts the workflow execution with the provided input as a stream
|
|
@@ -9075,7 +9412,8 @@ var Run = class {
|
|
|
9075
9412
|
tracingOptions,
|
|
9076
9413
|
closeOnSuspend = true,
|
|
9077
9414
|
initialState,
|
|
9078
|
-
outputOptions
|
|
9415
|
+
outputOptions,
|
|
9416
|
+
perStep
|
|
9079
9417
|
} = {}) {
|
|
9080
9418
|
if (this.closeStreamAction && this.streamOutput) {
|
|
9081
9419
|
return this.streamOutput;
|
|
@@ -9130,7 +9468,8 @@ var Run = class {
|
|
|
9130
9468
|
runId: self.runId,
|
|
9131
9469
|
data: chunk
|
|
9132
9470
|
});
|
|
9133
|
-
}
|
|
9471
|
+
},
|
|
9472
|
+
perStep
|
|
9134
9473
|
});
|
|
9135
9474
|
let executionResults;
|
|
9136
9475
|
try {
|
|
@@ -9172,7 +9511,8 @@ var Run = class {
|
|
|
9172
9511
|
requestContext,
|
|
9173
9512
|
tracingContext,
|
|
9174
9513
|
tracingOptions,
|
|
9175
|
-
outputOptions
|
|
9514
|
+
outputOptions,
|
|
9515
|
+
perStep
|
|
9176
9516
|
} = {}) {
|
|
9177
9517
|
return this.resumeStreamVNext({
|
|
9178
9518
|
resumeData,
|
|
@@ -9180,7 +9520,8 @@ var Run = class {
|
|
|
9180
9520
|
requestContext,
|
|
9181
9521
|
tracingContext,
|
|
9182
9522
|
tracingOptions,
|
|
9183
|
-
outputOptions
|
|
9523
|
+
outputOptions,
|
|
9524
|
+
perStep
|
|
9184
9525
|
});
|
|
9185
9526
|
}
|
|
9186
9527
|
/**
|
|
@@ -9195,7 +9536,8 @@ var Run = class {
|
|
|
9195
9536
|
tracingContext,
|
|
9196
9537
|
tracingOptions,
|
|
9197
9538
|
forEachIndex,
|
|
9198
|
-
outputOptions
|
|
9539
|
+
outputOptions,
|
|
9540
|
+
perStep
|
|
9199
9541
|
} = {}) {
|
|
9200
9542
|
this.closeStreamAction = async () => {
|
|
9201
9543
|
};
|
|
@@ -9245,7 +9587,8 @@ var Run = class {
|
|
|
9245
9587
|
},
|
|
9246
9588
|
isVNext: true,
|
|
9247
9589
|
forEachIndex,
|
|
9248
|
-
outputOptions
|
|
9590
|
+
outputOptions,
|
|
9591
|
+
perStep
|
|
9249
9592
|
});
|
|
9250
9593
|
self.executionResults = executionResultsPromise;
|
|
9251
9594
|
let executionResults;
|
|
@@ -9316,7 +9659,8 @@ var Run = class {
|
|
|
9316
9659
|
return this._restart(args);
|
|
9317
9660
|
}
|
|
9318
9661
|
async _resume(params) {
|
|
9319
|
-
const
|
|
9662
|
+
const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
|
|
9663
|
+
const snapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
9320
9664
|
workflowName: this.workflowId,
|
|
9321
9665
|
runId: this.runId
|
|
9322
9666
|
});
|
|
@@ -9391,10 +9735,9 @@ var Run = class {
|
|
|
9391
9735
|
const workflowSpan = getOrCreateSpan({
|
|
9392
9736
|
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
9393
9737
|
name: `workflow run: '${this.workflowId}'`,
|
|
9738
|
+
entityType: "workflow_run" /* WORKFLOW_RUN */,
|
|
9739
|
+
entityId: this.workflowId,
|
|
9394
9740
|
input: resumeDataToUse,
|
|
9395
|
-
attributes: {
|
|
9396
|
-
workflowId: this.workflowId
|
|
9397
|
-
},
|
|
9398
9741
|
metadata: {
|
|
9399
9742
|
resourceId: this.resourceId,
|
|
9400
9743
|
runId: this.runId
|
|
@@ -9429,7 +9772,8 @@ var Run = class {
|
|
|
9429
9772
|
abortController: this.abortController,
|
|
9430
9773
|
workflowSpan,
|
|
9431
9774
|
outputOptions: params.outputOptions,
|
|
9432
|
-
outputWriter: params.outputWriter
|
|
9775
|
+
outputWriter: params.outputWriter,
|
|
9776
|
+
perStep: params.perStep
|
|
9433
9777
|
}).then((result) => {
|
|
9434
9778
|
if (!params.isVNext && result.status !== "suspended") {
|
|
9435
9779
|
this.closeStreamAction?.().catch(() => {
|
|
@@ -9453,7 +9797,8 @@ var Run = class {
|
|
|
9453
9797
|
if (this.workflowEngineType !== "default") {
|
|
9454
9798
|
throw new Error(`restart() is not supported on ${this.workflowEngineType} workflows`);
|
|
9455
9799
|
}
|
|
9456
|
-
const
|
|
9800
|
+
const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
|
|
9801
|
+
const snapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
9457
9802
|
workflowName: this.workflowId,
|
|
9458
9803
|
runId: this.runId
|
|
9459
9804
|
});
|
|
@@ -9502,9 +9847,8 @@ var Run = class {
|
|
|
9502
9847
|
const workflowSpan = getOrCreateSpan({
|
|
9503
9848
|
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
9504
9849
|
name: `workflow run: '${this.workflowId}'`,
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
},
|
|
9850
|
+
entityType: "workflow_run" /* WORKFLOW_RUN */,
|
|
9851
|
+
entityId: this.workflowId,
|
|
9508
9852
|
metadata: {
|
|
9509
9853
|
resourceId: this.resourceId,
|
|
9510
9854
|
runId: this.runId
|
|
@@ -9548,12 +9892,14 @@ var Run = class {
|
|
|
9548
9892
|
outputWriter,
|
|
9549
9893
|
tracingContext,
|
|
9550
9894
|
tracingOptions,
|
|
9551
|
-
outputOptions
|
|
9895
|
+
outputOptions,
|
|
9896
|
+
perStep
|
|
9552
9897
|
}) {
|
|
9553
9898
|
if (!stepParam || Array.isArray(stepParam) && stepParam.length === 0) {
|
|
9554
9899
|
throw new Error("Step is required and must be a valid step or array of steps");
|
|
9555
9900
|
}
|
|
9556
|
-
const
|
|
9901
|
+
const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
|
|
9902
|
+
const snapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
9557
9903
|
workflowName: this.workflowId,
|
|
9558
9904
|
runId: this.runId
|
|
9559
9905
|
});
|
|
@@ -9583,7 +9929,8 @@ var Run = class {
|
|
|
9583
9929
|
nestedStepsContext,
|
|
9584
9930
|
snapshot,
|
|
9585
9931
|
initialState,
|
|
9586
|
-
graph: this.executionGraph
|
|
9932
|
+
graph: this.executionGraph,
|
|
9933
|
+
perStep
|
|
9587
9934
|
});
|
|
9588
9935
|
const requestContextToUse = requestContext ?? new RequestContext();
|
|
9589
9936
|
for (const [key, value] of Object.entries(snapshot.requestContext ?? {})) {
|
|
@@ -9595,9 +9942,8 @@ var Run = class {
|
|
|
9595
9942
|
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
9596
9943
|
name: `workflow run: '${this.workflowId}'`,
|
|
9597
9944
|
input: inputData,
|
|
9598
|
-
|
|
9599
|
-
|
|
9600
|
-
},
|
|
9945
|
+
entityType: "workflow_run" /* WORKFLOW_RUN */,
|
|
9946
|
+
entityId: this.workflowId,
|
|
9601
9947
|
metadata: {
|
|
9602
9948
|
resourceId: this.resourceId,
|
|
9603
9949
|
runId: this.runId
|
|
@@ -9623,7 +9969,8 @@ var Run = class {
|
|
|
9623
9969
|
abortController: this.abortController,
|
|
9624
9970
|
outputWriter,
|
|
9625
9971
|
workflowSpan,
|
|
9626
|
-
outputOptions
|
|
9972
|
+
outputOptions,
|
|
9973
|
+
perStep
|
|
9627
9974
|
});
|
|
9628
9975
|
if (result.status !== "suspended") {
|
|
9629
9976
|
this.cleanup?.();
|
|
@@ -9644,7 +9991,8 @@ var Run = class {
|
|
|
9644
9991
|
requestContext,
|
|
9645
9992
|
tracingContext,
|
|
9646
9993
|
tracingOptions,
|
|
9647
|
-
outputOptions
|
|
9994
|
+
outputOptions,
|
|
9995
|
+
perStep
|
|
9648
9996
|
}) {
|
|
9649
9997
|
this.closeStreamAction = async () => {
|
|
9650
9998
|
};
|
|
@@ -9685,7 +10033,8 @@ var Run = class {
|
|
|
9685
10033
|
outputWriter: async (chunk) => {
|
|
9686
10034
|
void controller.enqueue(chunk);
|
|
9687
10035
|
},
|
|
9688
|
-
outputOptions
|
|
10036
|
+
outputOptions,
|
|
10037
|
+
perStep
|
|
9689
10038
|
});
|
|
9690
10039
|
self.executionResults = executionResultsPromise;
|
|
9691
10040
|
let executionResults;
|
|
@@ -10290,7 +10639,8 @@ async function processOutputStream({
|
|
|
10290
10639
|
messageList.add(message, "response");
|
|
10291
10640
|
runState.setState({
|
|
10292
10641
|
isReasoning: false,
|
|
10293
|
-
reasoningDeltas: []
|
|
10642
|
+
reasoningDeltas: [],
|
|
10643
|
+
providerOptions: void 0
|
|
10294
10644
|
});
|
|
10295
10645
|
if (isControllerOpen(controller)) {
|
|
10296
10646
|
controller.enqueue(chunk);
|
|
@@ -10419,11 +10769,14 @@ function executeStreamWithFallbackModels(models) {
|
|
|
10419
10769
|
while (attempt <= maxRetries) {
|
|
10420
10770
|
try {
|
|
10421
10771
|
const isLastModel = attempt === maxRetries && index === models.length;
|
|
10422
|
-
const result = await callback(modelConfig
|
|
10772
|
+
const result = await callback(modelConfig, isLastModel);
|
|
10423
10773
|
finalResult = result;
|
|
10424
10774
|
done = true;
|
|
10425
10775
|
break;
|
|
10426
10776
|
} catch (err) {
|
|
10777
|
+
if (err instanceof TripWire) {
|
|
10778
|
+
throw err;
|
|
10779
|
+
}
|
|
10427
10780
|
attempt++;
|
|
10428
10781
|
console.error(`Error executing model ${modelConfig.model.modelId}, attempt ${attempt}====`, err);
|
|
10429
10782
|
if (attempt > maxRetries) {
|
|
@@ -10461,7 +10814,6 @@ function createLLMExecutionStep({
|
|
|
10461
10814
|
inputProcessors,
|
|
10462
10815
|
logger,
|
|
10463
10816
|
agentId,
|
|
10464
|
-
headers,
|
|
10465
10817
|
downloadRetries,
|
|
10466
10818
|
downloadConcurrency,
|
|
10467
10819
|
processorStates,
|
|
@@ -10481,7 +10833,9 @@ function createLLMExecutionStep({
|
|
|
10481
10833
|
let warnings;
|
|
10482
10834
|
let request;
|
|
10483
10835
|
let rawResponse;
|
|
10484
|
-
const { outputStream, callBail, runState, stepTools } = await executeStreamWithFallbackModels(models)(async (
|
|
10836
|
+
const { outputStream, callBail, runState, stepTools } = await executeStreamWithFallbackModels(models)(async (modelConfig, isLastModel) => {
|
|
10837
|
+
const model = modelConfig.model;
|
|
10838
|
+
const modelHeaders = modelConfig.headers;
|
|
10485
10839
|
if (initialSystemMessages) {
|
|
10486
10840
|
messageList.replaceAllSystemMessages(initialSystemMessages);
|
|
10487
10841
|
}
|
|
@@ -10526,6 +10880,45 @@ function createLLMExecutionStep({
|
|
|
10526
10880
|
});
|
|
10527
10881
|
Object.assign(currentStep, processInputStepResult);
|
|
10528
10882
|
} catch (error) {
|
|
10883
|
+
if (error instanceof TripWire) {
|
|
10884
|
+
if (isControllerOpen(controller)) {
|
|
10885
|
+
controller.enqueue({
|
|
10886
|
+
type: "tripwire",
|
|
10887
|
+
runId,
|
|
10888
|
+
from: "AGENT" /* AGENT */,
|
|
10889
|
+
payload: {
|
|
10890
|
+
reason: error.message,
|
|
10891
|
+
retry: error.options?.retry,
|
|
10892
|
+
metadata: error.options?.metadata,
|
|
10893
|
+
processorId: error.processorId
|
|
10894
|
+
}
|
|
10895
|
+
});
|
|
10896
|
+
}
|
|
10897
|
+
const runState3 = new AgenticRunState({
|
|
10898
|
+
_internal,
|
|
10899
|
+
model
|
|
10900
|
+
});
|
|
10901
|
+
return {
|
|
10902
|
+
callBail: true,
|
|
10903
|
+
outputStream: new MastraModelOutput({
|
|
10904
|
+
model: {
|
|
10905
|
+
modelId: model.modelId,
|
|
10906
|
+
provider: model.provider,
|
|
10907
|
+
version: model.specificationVersion
|
|
10908
|
+
},
|
|
10909
|
+
stream: new ReadableStream$1({
|
|
10910
|
+
start(c) {
|
|
10911
|
+
c.close();
|
|
10912
|
+
}
|
|
10913
|
+
}),
|
|
10914
|
+
messageList,
|
|
10915
|
+
messageId,
|
|
10916
|
+
options: { runId }
|
|
10917
|
+
}),
|
|
10918
|
+
runState: runState3,
|
|
10919
|
+
stepTools: tools
|
|
10920
|
+
};
|
|
10921
|
+
}
|
|
10529
10922
|
console.error("Error in processInputStep processors:", error);
|
|
10530
10923
|
throw error;
|
|
10531
10924
|
}
|
|
@@ -10559,62 +10952,63 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
|
|
|
10559
10952
|
resumeData can not be an empty object nor null/undefined.
|
|
10560
10953
|
When you find that and call that tool, add the resumeData to the tool call arguments/input.
|
|
10561
10954
|
Also, add the runId of the suspended tool as suspendedToolRunId to the tool call arguments/input.
|
|
10562
|
-
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
|
|
10955
|
+
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.
|
|
10956
|
+
`;
|
|
10563
10957
|
}
|
|
10564
10958
|
return message;
|
|
10565
10959
|
});
|
|
10566
10960
|
}
|
|
10567
10961
|
}
|
|
10568
10962
|
}
|
|
10569
|
-
|
|
10570
|
-
|
|
10571
|
-
|
|
10572
|
-
|
|
10573
|
-
|
|
10574
|
-
|
|
10575
|
-
|
|
10576
|
-
|
|
10577
|
-
|
|
10578
|
-
|
|
10579
|
-
|
|
10580
|
-
|
|
10581
|
-
|
|
10582
|
-
|
|
10583
|
-
|
|
10584
|
-
|
|
10585
|
-
|
|
10586
|
-
|
|
10587
|
-
|
|
10588
|
-
|
|
10589
|
-
|
|
10590
|
-
|
|
10591
|
-
|
|
10592
|
-
|
|
10593
|
-
|
|
10594
|
-
|
|
10595
|
-
|
|
10596
|
-
|
|
10597
|
-
|
|
10963
|
+
if (isSupportedLanguageModel(currentStep.model)) {
|
|
10964
|
+
modelResult = executeWithContextSync({
|
|
10965
|
+
span: modelSpanTracker?.getTracingContext()?.currentSpan,
|
|
10966
|
+
fn: () => execute({
|
|
10967
|
+
runId,
|
|
10968
|
+
model: currentStep.model,
|
|
10969
|
+
providerOptions: currentStep.providerOptions,
|
|
10970
|
+
inputMessages,
|
|
10971
|
+
tools: currentStep.tools,
|
|
10972
|
+
toolChoice: currentStep.toolChoice,
|
|
10973
|
+
activeTools: currentStep.activeTools,
|
|
10974
|
+
options,
|
|
10975
|
+
modelSettings: currentStep.modelSettings,
|
|
10976
|
+
includeRawChunks,
|
|
10977
|
+
structuredOutput: currentStep.structuredOutput,
|
|
10978
|
+
// Merge headers: modelConfig headers first, then modelSettings overrides them
|
|
10979
|
+
// Only create object if there are actual headers to avoid passing empty {}
|
|
10980
|
+
headers: modelHeaders || currentStep.modelSettings?.headers ? { ...modelHeaders, ...currentStep.modelSettings?.headers } : void 0,
|
|
10981
|
+
methodType,
|
|
10982
|
+
generateId: _internal?.generateId,
|
|
10983
|
+
onResult: ({
|
|
10984
|
+
warnings: warningsFromStream,
|
|
10985
|
+
request: requestFromStream,
|
|
10986
|
+
rawResponse: rawResponseFromStream
|
|
10987
|
+
}) => {
|
|
10988
|
+
warnings = warningsFromStream;
|
|
10989
|
+
request = requestFromStream || {};
|
|
10990
|
+
rawResponse = rawResponseFromStream;
|
|
10991
|
+
if (!isControllerOpen(controller)) {
|
|
10992
|
+
return;
|
|
10993
|
+
}
|
|
10994
|
+
controller.enqueue({
|
|
10995
|
+
runId,
|
|
10996
|
+
from: "AGENT" /* AGENT */,
|
|
10997
|
+
type: "step-start",
|
|
10998
|
+
payload: {
|
|
10999
|
+
request: request || {},
|
|
11000
|
+
warnings: warnings || [],
|
|
11001
|
+
messageId
|
|
10598
11002
|
}
|
|
10599
|
-
|
|
10600
|
-
|
|
10601
|
-
|
|
10602
|
-
|
|
10603
|
-
|
|
10604
|
-
|
|
10605
|
-
|
|
10606
|
-
|
|
10607
|
-
|
|
10608
|
-
});
|
|
10609
|
-
},
|
|
10610
|
-
shouldThrowError: !isLastModel
|
|
10611
|
-
})
|
|
10612
|
-
});
|
|
10613
|
-
break;
|
|
10614
|
-
}
|
|
10615
|
-
default: {
|
|
10616
|
-
throw new Error(`Unsupported model version: ${model.specificationVersion}`);
|
|
10617
|
-
}
|
|
11003
|
+
});
|
|
11004
|
+
},
|
|
11005
|
+
shouldThrowError: !isLastModel
|
|
11006
|
+
})
|
|
11007
|
+
});
|
|
11008
|
+
} else {
|
|
11009
|
+
throw new Error(
|
|
11010
|
+
`Unsupported model version: ${currentStep.model.specificationVersion}. Supported versions: ${supportedLanguageModelSpecifications.join(", ")}`
|
|
11011
|
+
);
|
|
10618
11012
|
}
|
|
10619
11013
|
const outputStream2 = new MastraModelOutput({
|
|
10620
11014
|
model: {
|
|
@@ -10773,6 +11167,7 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
|
|
|
10773
11167
|
}));
|
|
10774
11168
|
const currentRetryCount = inputData.processorRetryCount || 0;
|
|
10775
11169
|
await processorRunner.runProcessOutputStep({
|
|
11170
|
+
steps: inputData.output?.steps ?? [],
|
|
10776
11171
|
messages: messageList.get.all.db(),
|
|
10777
11172
|
messageList,
|
|
10778
11173
|
stepNumber,
|
|
@@ -11182,7 +11577,17 @@ function createToolCallStep({
|
|
|
11182
11577
|
}
|
|
11183
11578
|
const resumeData = resumeDataFromArgs ?? workflowResumeData;
|
|
11184
11579
|
const isResumeToolCall = !!resumeDataFromArgs;
|
|
11185
|
-
|
|
11580
|
+
let toolRequiresApproval = requireToolApproval || tool2.requireApproval;
|
|
11581
|
+
if (tool2.needsApprovalFn) {
|
|
11582
|
+
try {
|
|
11583
|
+
const needsApprovalResult = await tool2.needsApprovalFn(args);
|
|
11584
|
+
toolRequiresApproval = needsApprovalResult;
|
|
11585
|
+
} catch (error) {
|
|
11586
|
+
console.error(`Error evaluating needsApprovalFn for tool ${inputData.toolName}:`, error);
|
|
11587
|
+
toolRequiresApproval = true;
|
|
11588
|
+
}
|
|
11589
|
+
}
|
|
11590
|
+
if (toolRequiresApproval) {
|
|
11186
11591
|
if (!resumeData) {
|
|
11187
11592
|
controller.enqueue({
|
|
11188
11593
|
type: "tool-call-approval",
|
|
@@ -11445,11 +11850,10 @@ function createAgenticLoopWorkflow(params) {
|
|
|
11445
11850
|
};
|
|
11446
11851
|
accumulatedSteps.push(currentStep);
|
|
11447
11852
|
if (rest.stopWhen && typedInputData.stepResult?.isContinued && accumulatedSteps.length > 0) {
|
|
11853
|
+
const steps = accumulatedSteps;
|
|
11448
11854
|
const conditions = await Promise.all(
|
|
11449
11855
|
(Array.isArray(rest.stopWhen) ? rest.stopWhen : [rest.stopWhen]).map((condition) => {
|
|
11450
|
-
return condition({
|
|
11451
|
-
steps: accumulatedSteps
|
|
11452
|
-
});
|
|
11856
|
+
return condition({ steps });
|
|
11453
11857
|
})
|
|
11454
11858
|
);
|
|
11455
11859
|
const hasStopped = conditions.some((condition) => condition);
|
|
@@ -11895,8 +12299,6 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
11895
12299
|
messages: [...messageList.getSystemMessages(), ...messages]
|
|
11896
12300
|
},
|
|
11897
12301
|
attributes: {
|
|
11898
|
-
agentId,
|
|
11899
|
-
agentName,
|
|
11900
12302
|
model: firstModel.modelId,
|
|
11901
12303
|
provider: firstModel.provider,
|
|
11902
12304
|
streaming: true,
|
|
@@ -13158,67 +13560,6 @@ async function networkLoop({
|
|
|
13158
13560
|
|
|
13159
13561
|
// src/agent/agent-legacy.ts
|
|
13160
13562
|
var import_fast_deep_equal = __toESM(require_fast_deep_equal(), 1);
|
|
13161
|
-
|
|
13162
|
-
// src/agent/utils.ts
|
|
13163
|
-
async function tryGenerateWithJsonFallback(agent, prompt, options) {
|
|
13164
|
-
if (!options.structuredOutput?.schema) {
|
|
13165
|
-
throw new MastraError({
|
|
13166
|
-
id: "STRUCTURED_OUTPUT_OPTIONS_REQUIRED",
|
|
13167
|
-
domain: "AGENT" /* AGENT */,
|
|
13168
|
-
category: "USER" /* USER */,
|
|
13169
|
-
text: "structuredOutput is required to use tryGenerateWithJsonFallback"
|
|
13170
|
-
});
|
|
13171
|
-
}
|
|
13172
|
-
try {
|
|
13173
|
-
return await agent.generate(prompt, options);
|
|
13174
|
-
} catch (error) {
|
|
13175
|
-
console.warn("Error in tryGenerateWithJsonFallback. Attempting fallback.", error);
|
|
13176
|
-
return await agent.generate(prompt, {
|
|
13177
|
-
...options,
|
|
13178
|
-
structuredOutput: { ...options.structuredOutput, jsonPromptInjection: true }
|
|
13179
|
-
});
|
|
13180
|
-
}
|
|
13181
|
-
}
|
|
13182
|
-
async function tryStreamWithJsonFallback(agent, prompt, options) {
|
|
13183
|
-
if (!options.structuredOutput?.schema) {
|
|
13184
|
-
throw new MastraError({
|
|
13185
|
-
id: "STRUCTURED_OUTPUT_OPTIONS_REQUIRED",
|
|
13186
|
-
domain: "AGENT" /* AGENT */,
|
|
13187
|
-
category: "USER" /* USER */,
|
|
13188
|
-
text: "structuredOutput is required to use tryStreamWithJsonFallback"
|
|
13189
|
-
});
|
|
13190
|
-
}
|
|
13191
|
-
try {
|
|
13192
|
-
const result = await agent.stream(prompt, options);
|
|
13193
|
-
const object = await result.object;
|
|
13194
|
-
if (!object) {
|
|
13195
|
-
throw new MastraError({
|
|
13196
|
-
id: "STRUCTURED_OUTPUT_OBJECT_UNDEFINED",
|
|
13197
|
-
domain: "AGENT" /* AGENT */,
|
|
13198
|
-
category: "USER" /* USER */,
|
|
13199
|
-
text: "structuredOutput object is undefined"
|
|
13200
|
-
});
|
|
13201
|
-
}
|
|
13202
|
-
return result;
|
|
13203
|
-
} catch (error) {
|
|
13204
|
-
console.warn("Error in tryStreamWithJsonFallback. Attempting fallback.", error);
|
|
13205
|
-
return await agent.stream(prompt, {
|
|
13206
|
-
...options,
|
|
13207
|
-
structuredOutput: { ...options.structuredOutput, jsonPromptInjection: true }
|
|
13208
|
-
});
|
|
13209
|
-
}
|
|
13210
|
-
}
|
|
13211
|
-
function resolveThreadIdFromArgs(args) {
|
|
13212
|
-
if (args?.memory?.thread) {
|
|
13213
|
-
if (typeof args.memory.thread === "string") return { id: args.memory.thread };
|
|
13214
|
-
if (typeof args.memory.thread === "object" && args.memory.thread.id)
|
|
13215
|
-
return args.memory.thread;
|
|
13216
|
-
}
|
|
13217
|
-
if (args?.threadId) return { id: args.threadId };
|
|
13218
|
-
return void 0;
|
|
13219
|
-
}
|
|
13220
|
-
|
|
13221
|
-
// src/agent/agent-legacy.ts
|
|
13222
13563
|
var AgentLegacyHandler = class {
|
|
13223
13564
|
constructor(capabilities) {
|
|
13224
13565
|
this.capabilities = capabilities;
|
|
@@ -13252,12 +13593,13 @@ var AgentLegacyHandler = class {
|
|
|
13252
13593
|
const agentSpan = getOrCreateSpan({
|
|
13253
13594
|
type: "agent_run" /* AGENT_RUN */,
|
|
13254
13595
|
name: `agent run: '${this.capabilities.id}'`,
|
|
13596
|
+
entityType: "agent" /* AGENT */,
|
|
13597
|
+
entityId: this.capabilities.id,
|
|
13598
|
+
entityName: this.capabilities.name,
|
|
13255
13599
|
input: {
|
|
13256
13600
|
messages
|
|
13257
13601
|
},
|
|
13258
13602
|
attributes: {
|
|
13259
|
-
agentId: this.capabilities.id,
|
|
13260
|
-
agentName: this.capabilities.name,
|
|
13261
13603
|
instructions: this.capabilities.convertInstructionsToString(instructions),
|
|
13262
13604
|
availableTools: [
|
|
13263
13605
|
...toolsets ? Object.keys(toolsets) : [],
|
|
@@ -14298,6 +14640,14 @@ function createMapResultsStep({
|
|
|
14298
14640
|
};
|
|
14299
14641
|
if (result.tripwire) {
|
|
14300
14642
|
const agentModel = await capabilities.getModel({ requestContext: result.requestContext });
|
|
14643
|
+
if (!isSupportedLanguageModel(agentModel)) {
|
|
14644
|
+
throw new MastraError({
|
|
14645
|
+
id: "MAP_RESULTS_STEP_UNSUPPORTED_MODEL",
|
|
14646
|
+
domain: "AGENT" /* AGENT */,
|
|
14647
|
+
category: "USER" /* USER */,
|
|
14648
|
+
text: "Tripwire handling requires a v2/v3 model"
|
|
14649
|
+
});
|
|
14650
|
+
}
|
|
14301
14651
|
const modelOutput = await getModelOutputForTripwire({
|
|
14302
14652
|
tripwire: memoryData.tripwire,
|
|
14303
14653
|
runId,
|
|
@@ -14939,7 +15289,6 @@ var Agent = class extends MastraBase {
|
|
|
14939
15289
|
}) {
|
|
14940
15290
|
const inputProcessors = inputProcessorOverrides ?? await this.listResolvedInputProcessors(requestContext);
|
|
14941
15291
|
const outputProcessors = outputProcessorOverrides ?? await this.listResolvedOutputProcessors(requestContext);
|
|
14942
|
-
this.logger.debug("outputProcessors", outputProcessors);
|
|
14943
15292
|
return new ProcessorRunner({
|
|
14944
15293
|
inputProcessors,
|
|
14945
15294
|
outputProcessors,
|
|
@@ -14996,7 +15345,7 @@ var Agent = class extends MastraBase {
|
|
|
14996
15345
|
async listResolvedOutputProcessors(requestContext) {
|
|
14997
15346
|
const configuredProcessors = this.#outputProcessors ? typeof this.#outputProcessors === "function" ? await this.#outputProcessors({ requestContext: requestContext || new RequestContext() }) : this.#outputProcessors : [];
|
|
14998
15347
|
const memory = await this.getMemory({ requestContext: requestContext || new RequestContext() });
|
|
14999
|
-
const memoryProcessors = memory ? memory.getOutputProcessors(configuredProcessors, requestContext) : [];
|
|
15348
|
+
const memoryProcessors = memory ? await memory.getOutputProcessors(configuredProcessors, requestContext) : [];
|
|
15000
15349
|
const allProcessors = [...configuredProcessors, ...memoryProcessors];
|
|
15001
15350
|
return this.combineProcessorsIntoWorkflow(allProcessors, `${this.id}-output-processor`);
|
|
15002
15351
|
}
|
|
@@ -15008,7 +15357,7 @@ var Agent = class extends MastraBase {
|
|
|
15008
15357
|
async listResolvedInputProcessors(requestContext) {
|
|
15009
15358
|
const configuredProcessors = this.#inputProcessors ? typeof this.#inputProcessors === "function" ? await this.#inputProcessors({ requestContext: requestContext || new RequestContext() }) : this.#inputProcessors : [];
|
|
15010
15359
|
const memory = await this.getMemory({ requestContext: requestContext || new RequestContext() });
|
|
15011
|
-
const memoryProcessors = memory ? memory.getInputProcessors(configuredProcessors, requestContext) : [];
|
|
15360
|
+
const memoryProcessors = memory ? await memory.getInputProcessors(configuredProcessors, requestContext) : [];
|
|
15012
15361
|
const allProcessors = [...memoryProcessors, ...configuredProcessors];
|
|
15013
15362
|
return this.combineProcessorsIntoWorkflow(allProcessors, `${this.id}-input-processor`);
|
|
15014
15363
|
}
|
|
@@ -15458,7 +15807,7 @@ var Agent = class extends MastraBase {
|
|
|
15458
15807
|
const modelToUse = this.getModel({ modelConfig: model, requestContext });
|
|
15459
15808
|
return resolveMaybePromise(modelToUse, (resolvedModel) => {
|
|
15460
15809
|
let llm;
|
|
15461
|
-
if (resolvedModel
|
|
15810
|
+
if (isSupportedLanguageModel(resolvedModel)) {
|
|
15462
15811
|
const modelsPromise = Array.isArray(this.model) && !model ? this.prepareModels(requestContext) : this.prepareModels(requestContext, resolvedModel);
|
|
15463
15812
|
llm = modelsPromise.then((models) => {
|
|
15464
15813
|
const enabledModels = models.filter((model2) => model2.enabled);
|
|
@@ -15722,7 +16071,7 @@ var Agent = class extends MastraBase {
|
|
|
15722
16071
|
}
|
|
15723
16072
|
const systemInstructions = await this.resolveTitleInstructions(requestContext, instructions);
|
|
15724
16073
|
let text = "";
|
|
15725
|
-
if (llm.getModel()
|
|
16074
|
+
if (isSupportedLanguageModel(llm.getModel())) {
|
|
15726
16075
|
const messageList = new MessageList().add(
|
|
15727
16076
|
[
|
|
15728
16077
|
{
|
|
@@ -16674,7 +17023,7 @@ var Agent = class extends MastraBase {
|
|
|
16674
17023
|
result[id] = scorerObject;
|
|
16675
17024
|
}
|
|
16676
17025
|
}
|
|
16677
|
-
if (Object.keys(result).length === 0) {
|
|
17026
|
+
if (Object.keys(result).length === 0 && Object.keys(overrideScorers).length > 0) {
|
|
16678
17027
|
throw new MastraError({
|
|
16679
17028
|
id: "AGENT_GENEREATE_SCORER_NOT_FOUND",
|
|
16680
17029
|
domain: "AGENT" /* AGENT */,
|
|
@@ -16691,8 +17040,11 @@ var Agent = class extends MastraBase {
|
|
|
16691
17040
|
async prepareModels(requestContext, model) {
|
|
16692
17041
|
if (model || !Array.isArray(this.model)) {
|
|
16693
17042
|
const modelToUse = model ?? this.model;
|
|
16694
|
-
const resolvedModel =
|
|
16695
|
-
|
|
17043
|
+
const resolvedModel = await this.resolveModelConfig(
|
|
17044
|
+
modelToUse,
|
|
17045
|
+
requestContext
|
|
17046
|
+
);
|
|
17047
|
+
if (!isSupportedLanguageModel(resolvedModel)) {
|
|
16696
17048
|
const mastraError = new MastraError({
|
|
16697
17049
|
id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
|
|
16698
17050
|
domain: "AGENT" /* AGENT */,
|
|
@@ -16700,26 +17052,30 @@ var Agent = class extends MastraBase {
|
|
|
16700
17052
|
details: {
|
|
16701
17053
|
agentName: this.name
|
|
16702
17054
|
},
|
|
16703
|
-
text: `[Agent:${this.name}] - Only v2 models are allowed when an array of models is provided`
|
|
17055
|
+
text: `[Agent:${this.name}] - Only v2/v3 models are allowed when an array of models is provided`
|
|
16704
17056
|
});
|
|
16705
17057
|
this.logger.trackException(mastraError);
|
|
16706
17058
|
this.logger.error(mastraError.toString());
|
|
16707
17059
|
throw mastraError;
|
|
16708
17060
|
}
|
|
17061
|
+
let headers;
|
|
17062
|
+
if (resolvedModel instanceof ModelRouterLanguageModel) {
|
|
17063
|
+
headers = resolvedModel.config?.headers;
|
|
17064
|
+
}
|
|
16709
17065
|
return [
|
|
16710
17066
|
{
|
|
16711
17067
|
id: "main",
|
|
16712
|
-
// TODO fix type check
|
|
16713
17068
|
model: resolvedModel,
|
|
16714
17069
|
maxRetries: this.maxRetries ?? 0,
|
|
16715
|
-
enabled: true
|
|
17070
|
+
enabled: true,
|
|
17071
|
+
headers
|
|
16716
17072
|
}
|
|
16717
17073
|
];
|
|
16718
17074
|
}
|
|
16719
17075
|
const models = await Promise.all(
|
|
16720
17076
|
this.model.map(async (modelConfig) => {
|
|
16721
17077
|
const model2 = await this.resolveModelConfig(modelConfig.model, requestContext);
|
|
16722
|
-
if (!
|
|
17078
|
+
if (!isSupportedLanguageModel(model2)) {
|
|
16723
17079
|
const mastraError = new MastraError({
|
|
16724
17080
|
id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
|
|
16725
17081
|
domain: "AGENT" /* AGENT */,
|
|
@@ -16727,7 +17083,7 @@ var Agent = class extends MastraBase {
|
|
|
16727
17083
|
details: {
|
|
16728
17084
|
agentName: this.name
|
|
16729
17085
|
},
|
|
16730
|
-
text: `[Agent:${this.name}] - Only v2 models are allowed when an array of models is provided`
|
|
17086
|
+
text: `[Agent:${this.name}] - Only v2/v3 models are allowed when an array of models is provided`
|
|
16731
17087
|
});
|
|
16732
17088
|
this.logger.trackException(mastraError);
|
|
16733
17089
|
this.logger.error(mastraError.toString());
|
|
@@ -16748,11 +17104,16 @@ var Agent = class extends MastraBase {
|
|
|
16748
17104
|
this.logger.error(mastraError.toString());
|
|
16749
17105
|
throw mastraError;
|
|
16750
17106
|
}
|
|
17107
|
+
let headers;
|
|
17108
|
+
if (model2 instanceof ModelRouterLanguageModel) {
|
|
17109
|
+
headers = model2.config?.headers;
|
|
17110
|
+
}
|
|
16751
17111
|
return {
|
|
16752
17112
|
id: modelId,
|
|
16753
17113
|
model: model2,
|
|
16754
17114
|
maxRetries: modelConfig.maxRetries ?? 0,
|
|
16755
|
-
enabled: modelConfig.enabled ?? true
|
|
17115
|
+
enabled: modelConfig.enabled ?? true,
|
|
17116
|
+
headers
|
|
16756
17117
|
};
|
|
16757
17118
|
})
|
|
16758
17119
|
);
|
|
@@ -16762,7 +17123,11 @@ var Agent = class extends MastraBase {
|
|
|
16762
17123
|
* Executes the agent call, handling tools, memory, and streaming.
|
|
16763
17124
|
* @internal
|
|
16764
17125
|
*/
|
|
16765
|
-
async #execute({
|
|
17126
|
+
async #execute({
|
|
17127
|
+
methodType,
|
|
17128
|
+
resumeContext,
|
|
17129
|
+
...options
|
|
17130
|
+
}) {
|
|
16766
17131
|
const existingSnapshot = resumeContext?.snapshot;
|
|
16767
17132
|
let snapshotMemoryInfo;
|
|
16768
17133
|
if (existingSnapshot) {
|
|
@@ -16822,10 +17187,11 @@ var Agent = class extends MastraBase {
|
|
|
16822
17187
|
const agentSpan = getOrCreateSpan({
|
|
16823
17188
|
type: "agent_run" /* AGENT_RUN */,
|
|
16824
17189
|
name: `agent run: '${this.id}'`,
|
|
17190
|
+
entityType: "agent" /* AGENT */,
|
|
17191
|
+
entityId: this.id,
|
|
17192
|
+
entityName: this.name,
|
|
16825
17193
|
input: options.messages,
|
|
16826
17194
|
attributes: {
|
|
16827
|
-
agentId: this.id,
|
|
16828
|
-
agentName: this.name,
|
|
16829
17195
|
conversationId: threadFromArgs?.id,
|
|
16830
17196
|
instructions: this.#convertInstructionsToString(instructions)
|
|
16831
17197
|
},
|
|
@@ -17109,14 +17475,14 @@ var Agent = class extends MastraBase {
|
|
|
17109
17475
|
requestContext: mergedOptions.requestContext
|
|
17110
17476
|
});
|
|
17111
17477
|
const modelInfo = llm.getModel();
|
|
17112
|
-
if (modelInfo
|
|
17478
|
+
if (!isSupportedLanguageModel(modelInfo)) {
|
|
17113
17479
|
const modelId = modelInfo.modelId || "unknown";
|
|
17114
17480
|
const provider = modelInfo.provider || "unknown";
|
|
17115
17481
|
throw new MastraError({
|
|
17116
17482
|
id: "AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED",
|
|
17117
17483
|
domain: "AGENT" /* AGENT */,
|
|
17118
17484
|
category: "USER" /* USER */,
|
|
17119
|
-
text: `Agent "${this.name}" is using AI SDK v4 model (${provider}:${modelId}) which is not compatible with generate(). Please use AI SDK v5 models or call the generateLegacy() method instead. See https://mastra.ai/en/docs/streaming/overview for more information.`,
|
|
17485
|
+
text: `Agent "${this.name}" is using AI SDK v4 model (${provider}:${modelId}) which is not compatible with generate(). Please use AI SDK v5+ models or call the generateLegacy() method instead. See https://mastra.ai/en/docs/streaming/overview for more information.`,
|
|
17120
17486
|
details: {
|
|
17121
17487
|
agentName: this.name,
|
|
17122
17488
|
modelId,
|
|
@@ -17171,14 +17537,14 @@ var Agent = class extends MastraBase {
|
|
|
17171
17537
|
requestContext: mergedOptions.requestContext
|
|
17172
17538
|
});
|
|
17173
17539
|
const modelInfo = llm.getModel();
|
|
17174
|
-
if (modelInfo
|
|
17540
|
+
if (!isSupportedLanguageModel(modelInfo)) {
|
|
17175
17541
|
const modelId = modelInfo.modelId || "unknown";
|
|
17176
17542
|
const provider = modelInfo.provider || "unknown";
|
|
17177
17543
|
throw new MastraError({
|
|
17178
17544
|
id: "AGENT_STREAM_V1_MODEL_NOT_SUPPORTED",
|
|
17179
17545
|
domain: "AGENT" /* AGENT */,
|
|
17180
17546
|
category: "USER" /* USER */,
|
|
17181
|
-
text: `Agent "${this.name}" is using AI SDK v4 model (${provider}:${modelId}) which is not compatible with stream(). Please use AI SDK v5 models or call the streamLegacy() method instead. See https://mastra.ai/en/docs/streaming/overview for more information.`,
|
|
17547
|
+
text: `Agent "${this.name}" is using AI SDK v4 model (${provider}:${modelId}) which is not compatible with stream(). Please use AI SDK v5+ models or call the streamLegacy() method instead. See https://mastra.ai/en/docs/streaming/overview for more information.`,
|
|
17182
17548
|
details: {
|
|
17183
17549
|
agentName: this.name,
|
|
17184
17550
|
modelId,
|
|
@@ -17240,7 +17606,7 @@ var Agent = class extends MastraBase {
|
|
|
17240
17606
|
const llm = await this.getLLM({
|
|
17241
17607
|
requestContext: mergedStreamOptions.requestContext
|
|
17242
17608
|
});
|
|
17243
|
-
if (llm.getModel()
|
|
17609
|
+
if (!isSupportedLanguageModel(llm.getModel())) {
|
|
17244
17610
|
throw new MastraError({
|
|
17245
17611
|
id: "AGENT_STREAM_V1_MODEL_NOT_SUPPORTED",
|
|
17246
17612
|
domain: "AGENT" /* AGENT */,
|
|
@@ -17248,7 +17614,8 @@ var Agent = class extends MastraBase {
|
|
|
17248
17614
|
text: "V1 models are not supported for stream. Please use streamLegacy instead."
|
|
17249
17615
|
});
|
|
17250
17616
|
}
|
|
17251
|
-
const
|
|
17617
|
+
const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
|
|
17618
|
+
const existingSnapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
17252
17619
|
workflowName: "agentic-loop",
|
|
17253
17620
|
runId: streamOptions?.runId ?? ""
|
|
17254
17621
|
});
|
|
@@ -17480,7 +17847,7 @@ var ModerationProcessor = class _ModerationProcessor {
|
|
|
17480
17847
|
reason: z8.string().describe("Brief explanation of why content was flagged").nullable()
|
|
17481
17848
|
});
|
|
17482
17849
|
let response;
|
|
17483
|
-
if (model
|
|
17850
|
+
if (isSupportedLanguageModel(model)) {
|
|
17484
17851
|
response = await this.moderationAgent.generate(prompt, {
|
|
17485
17852
|
structuredOutput: {
|
|
17486
17853
|
schema,
|
|
@@ -17700,7 +18067,7 @@ var PromptInjectionDetector = class _PromptInjectionDetector {
|
|
|
17700
18067
|
rewritten_content: z8.string().describe("The rewritten content that neutralizes the attack while preserving any legitimate user intent").nullable()
|
|
17701
18068
|
});
|
|
17702
18069
|
}
|
|
17703
|
-
if (model
|
|
18070
|
+
if (isSupportedLanguageModel(model)) {
|
|
17704
18071
|
response = await this.detectionAgent.generate(prompt, {
|
|
17705
18072
|
structuredOutput: {
|
|
17706
18073
|
schema,
|
|
@@ -17948,7 +18315,7 @@ var PIIDetector = class _PIIDetector {
|
|
|
17948
18315
|
redacted_content: z8.string().describe("The content with all PII redacted according to the redaction method").nullable()
|
|
17949
18316
|
}) : baseSchema;
|
|
17950
18317
|
let response;
|
|
17951
|
-
if (model
|
|
18318
|
+
if (isSupportedLanguageModel(model)) {
|
|
17952
18319
|
response = await this.detectionAgent.generate(prompt, {
|
|
17953
18320
|
structuredOutput: {
|
|
17954
18321
|
schema,
|
|
@@ -18410,7 +18777,7 @@ var LanguageDetector = class _LanguageDetector {
|
|
|
18410
18777
|
const schema = this.strategy === "translate" ? baseSchema.extend({
|
|
18411
18778
|
translated_text: z8.string().describe("Translated text").nullable()
|
|
18412
18779
|
}) : baseSchema;
|
|
18413
|
-
if (model
|
|
18780
|
+
if (isSupportedLanguageModel(model)) {
|
|
18414
18781
|
response = await this.detectionAgent.generate(prompt, {
|
|
18415
18782
|
structuredOutput: {
|
|
18416
18783
|
schema
|
|
@@ -19088,7 +19455,7 @@ var SystemPromptScrubber = class {
|
|
|
19088
19455
|
const schema = this.strategy === "redact" ? baseSchema.extend({
|
|
19089
19456
|
redacted_content: z.string().describe("Redacted content").nullable()
|
|
19090
19457
|
}) : baseSchema;
|
|
19091
|
-
if (model
|
|
19458
|
+
if (isSupportedLanguageModel(model)) {
|
|
19092
19459
|
result = await this.detectionAgent.generate(text, {
|
|
19093
19460
|
structuredOutput: {
|
|
19094
19461
|
schema,
|
|
@@ -19316,6 +19683,50 @@ var ToolCallFilter = class {
|
|
|
19316
19683
|
}
|
|
19317
19684
|
};
|
|
19318
19685
|
|
|
19686
|
+
// src/memory/working-memory-utils.ts
|
|
19687
|
+
var WORKING_MEMORY_START_TAG = "<working_memory>";
|
|
19688
|
+
var WORKING_MEMORY_END_TAG = "</working_memory>";
|
|
19689
|
+
function extractWorkingMemoryTags(text) {
|
|
19690
|
+
const results = [];
|
|
19691
|
+
let pos = 0;
|
|
19692
|
+
while (pos < text.length) {
|
|
19693
|
+
const start = text.indexOf(WORKING_MEMORY_START_TAG, pos);
|
|
19694
|
+
if (start === -1) break;
|
|
19695
|
+
const end = text.indexOf(WORKING_MEMORY_END_TAG, start + WORKING_MEMORY_START_TAG.length);
|
|
19696
|
+
if (end === -1) break;
|
|
19697
|
+
results.push(text.substring(start, end + WORKING_MEMORY_END_TAG.length));
|
|
19698
|
+
pos = end + WORKING_MEMORY_END_TAG.length;
|
|
19699
|
+
}
|
|
19700
|
+
return results.length > 0 ? results : null;
|
|
19701
|
+
}
|
|
19702
|
+
function removeWorkingMemoryTags(text) {
|
|
19703
|
+
let result = "";
|
|
19704
|
+
let pos = 0;
|
|
19705
|
+
while (pos < text.length) {
|
|
19706
|
+
const start = text.indexOf(WORKING_MEMORY_START_TAG, pos);
|
|
19707
|
+
if (start === -1) {
|
|
19708
|
+
result += text.substring(pos);
|
|
19709
|
+
break;
|
|
19710
|
+
}
|
|
19711
|
+
result += text.substring(pos, start);
|
|
19712
|
+
const end = text.indexOf(WORKING_MEMORY_END_TAG, start + WORKING_MEMORY_START_TAG.length);
|
|
19713
|
+
if (end === -1) {
|
|
19714
|
+
result += text.substring(start);
|
|
19715
|
+
break;
|
|
19716
|
+
}
|
|
19717
|
+
pos = end + WORKING_MEMORY_END_TAG.length;
|
|
19718
|
+
}
|
|
19719
|
+
return result;
|
|
19720
|
+
}
|
|
19721
|
+
function extractWorkingMemoryContent(text) {
|
|
19722
|
+
const start = text.indexOf(WORKING_MEMORY_START_TAG);
|
|
19723
|
+
if (start === -1) return null;
|
|
19724
|
+
const contentStart = start + WORKING_MEMORY_START_TAG.length;
|
|
19725
|
+
const end = text.indexOf(WORKING_MEMORY_END_TAG, contentStart);
|
|
19726
|
+
if (end === -1) return null;
|
|
19727
|
+
return text.substring(contentStart, end);
|
|
19728
|
+
}
|
|
19729
|
+
|
|
19319
19730
|
// src/processors/memory/message-history.ts
|
|
19320
19731
|
var MessageHistory = class {
|
|
19321
19732
|
id = "message-history";
|
|
@@ -19358,25 +19769,43 @@ var MessageHistory = class {
|
|
|
19358
19769
|
}
|
|
19359
19770
|
return messageList;
|
|
19360
19771
|
}
|
|
19361
|
-
|
|
19772
|
+
/**
|
|
19773
|
+
* Filters messages before persisting to storage:
|
|
19774
|
+
* 1. Removes incomplete tool calls (state === 'call' or 'partial-call')
|
|
19775
|
+
* 2. Removes updateWorkingMemory tool invocations (hide args from message history)
|
|
19776
|
+
* 3. Strips <working_memory> tags from text content
|
|
19777
|
+
*/
|
|
19778
|
+
filterMessagesForPersistence(messages) {
|
|
19362
19779
|
return messages.map((m) => {
|
|
19363
|
-
|
|
19364
|
-
|
|
19365
|
-
|
|
19366
|
-
|
|
19367
|
-
|
|
19368
|
-
|
|
19369
|
-
|
|
19370
|
-
|
|
19371
|
-
|
|
19372
|
-
|
|
19373
|
-
|
|
19780
|
+
const newMessage = { ...m };
|
|
19781
|
+
if (m.content && typeof m.content === "object" && !Array.isArray(m.content)) {
|
|
19782
|
+
newMessage.content = { ...m.content };
|
|
19783
|
+
}
|
|
19784
|
+
if (typeof newMessage.content?.content === "string" && newMessage.content.content.length > 0) {
|
|
19785
|
+
newMessage.content.content = removeWorkingMemoryTags(newMessage.content.content).trim();
|
|
19786
|
+
}
|
|
19787
|
+
if (Array.isArray(newMessage.content?.parts)) {
|
|
19788
|
+
newMessage.content.parts = newMessage.content.parts.map((p) => {
|
|
19789
|
+
if (p.type === `tool-invocation` && (p.toolInvocation.state === `call` || p.toolInvocation.state === `partial-call`)) {
|
|
19790
|
+
return null;
|
|
19374
19791
|
}
|
|
19375
|
-
|
|
19376
|
-
|
|
19377
|
-
|
|
19792
|
+
if (p.type === `tool-invocation` && p.toolInvocation.toolName === `updateWorkingMemory`) {
|
|
19793
|
+
return null;
|
|
19794
|
+
}
|
|
19795
|
+
if (p.type === `text`) {
|
|
19796
|
+
const text = typeof p.text === "string" ? p.text : "";
|
|
19797
|
+
return {
|
|
19798
|
+
...p,
|
|
19799
|
+
text: removeWorkingMemoryTags(text).trim()
|
|
19800
|
+
};
|
|
19801
|
+
}
|
|
19802
|
+
return p;
|
|
19803
|
+
}).filter((p) => Boolean(p));
|
|
19804
|
+
if (newMessage.content.parts.length === 0) {
|
|
19805
|
+
return null;
|
|
19806
|
+
}
|
|
19378
19807
|
}
|
|
19379
|
-
return
|
|
19808
|
+
return newMessage;
|
|
19380
19809
|
}).filter((m) => Boolean(m));
|
|
19381
19810
|
}
|
|
19382
19811
|
async processOutputResult(args) {
|
|
@@ -19393,7 +19822,7 @@ var MessageHistory = class {
|
|
|
19393
19822
|
if (messagesToSave.length === 0) {
|
|
19394
19823
|
return messageList;
|
|
19395
19824
|
}
|
|
19396
|
-
const filtered = this.
|
|
19825
|
+
const filtered = this.filterMessagesForPersistence(messagesToSave);
|
|
19397
19826
|
await this.storage.saveMessages({ messages: filtered });
|
|
19398
19827
|
const thread = await this.storage.getThreadById({ threadId });
|
|
19399
19828
|
if (thread) {
|
|
@@ -20007,6 +20436,7 @@ var MastraMemory = class extends MastraBase {
|
|
|
20007
20436
|
_storage;
|
|
20008
20437
|
vector;
|
|
20009
20438
|
embedder;
|
|
20439
|
+
embedderOptions;
|
|
20010
20440
|
threadConfig = { ...memoryDefaultOptions };
|
|
20011
20441
|
#mastra;
|
|
20012
20442
|
constructor(config) {
|
|
@@ -20097,7 +20527,11 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20097
20527
|
this.vector = vector;
|
|
20098
20528
|
}
|
|
20099
20529
|
setEmbedder(embedder) {
|
|
20100
|
-
|
|
20530
|
+
if (typeof embedder === "string") {
|
|
20531
|
+
this.embedder = new ModelRouterEmbeddingModel(embedder);
|
|
20532
|
+
} else {
|
|
20533
|
+
this.embedder = embedder;
|
|
20534
|
+
}
|
|
20101
20535
|
}
|
|
20102
20536
|
/**
|
|
20103
20537
|
* Get a system message to inject into the conversation.
|
|
@@ -20219,14 +20653,15 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20219
20653
|
* @param configuredProcessors - Processors already configured by the user (for deduplication)
|
|
20220
20654
|
* @returns Array of input processors configured for this memory instance
|
|
20221
20655
|
*/
|
|
20222
|
-
getInputProcessors(configuredProcessors = [], context) {
|
|
20656
|
+
async getInputProcessors(configuredProcessors = [], context) {
|
|
20657
|
+
const memoryStore = await this.storage.getStore("memory");
|
|
20223
20658
|
const processors = [];
|
|
20224
20659
|
const memoryContext = context?.get("MastraMemory");
|
|
20225
20660
|
const runtimeMemoryConfig = memoryContext?.memoryConfig;
|
|
20226
20661
|
const effectiveConfig = runtimeMemoryConfig ? this.getMergedThreadConfig(runtimeMemoryConfig) : this.threadConfig;
|
|
20227
20662
|
const isWorkingMemoryEnabled = typeof effectiveConfig.workingMemory === "object" && effectiveConfig.workingMemory.enabled !== false;
|
|
20228
20663
|
if (isWorkingMemoryEnabled) {
|
|
20229
|
-
if (!
|
|
20664
|
+
if (!memoryStore)
|
|
20230
20665
|
throw new MastraError({
|
|
20231
20666
|
category: "USER",
|
|
20232
20667
|
domain: "STORAGE" /* STORAGE */,
|
|
@@ -20244,7 +20679,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20244
20679
|
}
|
|
20245
20680
|
processors.push(
|
|
20246
20681
|
new WorkingMemory({
|
|
20247
|
-
storage:
|
|
20682
|
+
storage: memoryStore,
|
|
20248
20683
|
template,
|
|
20249
20684
|
scope: typeof effectiveConfig.workingMemory === "object" ? effectiveConfig.workingMemory.scope : void 0,
|
|
20250
20685
|
useVNext: typeof effectiveConfig.workingMemory === "object" && "version" in effectiveConfig.workingMemory && effectiveConfig.workingMemory.version === "vnext",
|
|
@@ -20255,7 +20690,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20255
20690
|
}
|
|
20256
20691
|
const lastMessages = effectiveConfig.lastMessages;
|
|
20257
20692
|
if (lastMessages) {
|
|
20258
|
-
if (!
|
|
20693
|
+
if (!memoryStore)
|
|
20259
20694
|
throw new MastraError({
|
|
20260
20695
|
category: "USER",
|
|
20261
20696
|
domain: "STORAGE" /* STORAGE */,
|
|
@@ -20266,14 +20701,14 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20266
20701
|
if (!hasMessageHistory) {
|
|
20267
20702
|
processors.push(
|
|
20268
20703
|
new MessageHistory({
|
|
20269
|
-
storage:
|
|
20704
|
+
storage: memoryStore,
|
|
20270
20705
|
lastMessages: typeof lastMessages === "number" ? lastMessages : void 0
|
|
20271
20706
|
})
|
|
20272
20707
|
);
|
|
20273
20708
|
}
|
|
20274
20709
|
}
|
|
20275
20710
|
if (effectiveConfig.semanticRecall) {
|
|
20276
|
-
if (!
|
|
20711
|
+
if (!memoryStore)
|
|
20277
20712
|
throw new MastraError({
|
|
20278
20713
|
category: "USER",
|
|
20279
20714
|
domain: "STORAGE" /* STORAGE */,
|
|
@@ -20300,7 +20735,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20300
20735
|
const indexName = this.getEmbeddingIndexName();
|
|
20301
20736
|
processors.push(
|
|
20302
20737
|
new SemanticRecall({
|
|
20303
|
-
storage:
|
|
20738
|
+
storage: memoryStore,
|
|
20304
20739
|
vector: this.vector,
|
|
20305
20740
|
embedder: this.embedder,
|
|
20306
20741
|
indexName,
|
|
@@ -20317,7 +20752,8 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20317
20752
|
* @param configuredProcessors - Processors already configured by the user (for deduplication)
|
|
20318
20753
|
* @returns Array of output processors configured for this memory instance
|
|
20319
20754
|
*/
|
|
20320
|
-
getOutputProcessors(configuredProcessors = [], context) {
|
|
20755
|
+
async getOutputProcessors(configuredProcessors = [], context) {
|
|
20756
|
+
const memoryStore = await this.storage.getStore("memory");
|
|
20321
20757
|
const processors = [];
|
|
20322
20758
|
const memoryContext = context?.get("MastraMemory");
|
|
20323
20759
|
const runtimeMemoryConfig = memoryContext?.memoryConfig;
|
|
@@ -20326,7 +20762,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20326
20762
|
return [];
|
|
20327
20763
|
}
|
|
20328
20764
|
if (effectiveConfig.semanticRecall) {
|
|
20329
|
-
if (!
|
|
20765
|
+
if (!memoryStore)
|
|
20330
20766
|
throw new MastraError({
|
|
20331
20767
|
category: "USER",
|
|
20332
20768
|
domain: "STORAGE" /* STORAGE */,
|
|
@@ -20353,7 +20789,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20353
20789
|
const indexName = this.getEmbeddingIndexName();
|
|
20354
20790
|
processors.push(
|
|
20355
20791
|
new SemanticRecall({
|
|
20356
|
-
storage:
|
|
20792
|
+
storage: memoryStore,
|
|
20357
20793
|
vector: this.vector,
|
|
20358
20794
|
embedder: this.embedder,
|
|
20359
20795
|
indexName,
|
|
@@ -20364,7 +20800,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20364
20800
|
}
|
|
20365
20801
|
const lastMessages = effectiveConfig.lastMessages;
|
|
20366
20802
|
if (lastMessages) {
|
|
20367
|
-
if (!
|
|
20803
|
+
if (!memoryStore)
|
|
20368
20804
|
throw new MastraError({
|
|
20369
20805
|
category: "USER",
|
|
20370
20806
|
domain: "STORAGE" /* STORAGE */,
|
|
@@ -20375,7 +20811,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20375
20811
|
if (!hasMessageHistory) {
|
|
20376
20812
|
processors.push(
|
|
20377
20813
|
new MessageHistory({
|
|
20378
|
-
storage:
|
|
20814
|
+
storage: memoryStore,
|
|
20379
20815
|
lastMessages: typeof lastMessages === "number" ? lastMessages : void 0
|
|
20380
20816
|
})
|
|
20381
20817
|
);
|
|
@@ -20402,22 +20838,39 @@ var MockMemory = class extends MastraMemory {
|
|
|
20402
20838
|
});
|
|
20403
20839
|
this._hasOwnStorage = true;
|
|
20404
20840
|
}
|
|
20841
|
+
async getMemoryStore() {
|
|
20842
|
+
const store = await this.storage.getStore("memory");
|
|
20843
|
+
if (!store) {
|
|
20844
|
+
throw new MastraError({
|
|
20845
|
+
id: "MASTRA_MEMORY_STORAGE_NOT_AVAILABLE",
|
|
20846
|
+
domain: "MASTRA_MEMORY" /* MASTRA_MEMORY */,
|
|
20847
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
20848
|
+
text: "Memory storage is not supported by this storage adapter"
|
|
20849
|
+
});
|
|
20850
|
+
}
|
|
20851
|
+
return store;
|
|
20852
|
+
}
|
|
20405
20853
|
async getThreadById({ threadId }) {
|
|
20406
|
-
|
|
20854
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20855
|
+
return memoryStorage.getThreadById({ threadId });
|
|
20407
20856
|
}
|
|
20408
20857
|
async saveThread({ thread }) {
|
|
20409
|
-
|
|
20858
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20859
|
+
return memoryStorage.saveThread({ thread });
|
|
20410
20860
|
}
|
|
20411
20861
|
async saveMessages({
|
|
20412
20862
|
messages
|
|
20413
20863
|
}) {
|
|
20414
|
-
|
|
20864
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20865
|
+
return memoryStorage.saveMessages({ messages });
|
|
20415
20866
|
}
|
|
20416
20867
|
async listThreadsByResourceId(args) {
|
|
20417
|
-
|
|
20868
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20869
|
+
return memoryStorage.listThreadsByResourceId(args);
|
|
20418
20870
|
}
|
|
20419
20871
|
async recall(args) {
|
|
20420
|
-
const
|
|
20872
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20873
|
+
const result = await memoryStorage.listMessages({
|
|
20421
20874
|
threadId: args.threadId,
|
|
20422
20875
|
resourceId: args.resourceId,
|
|
20423
20876
|
perPage: args.perPage,
|
|
@@ -20429,11 +20882,13 @@ var MockMemory = class extends MastraMemory {
|
|
|
20429
20882
|
return result;
|
|
20430
20883
|
}
|
|
20431
20884
|
async deleteThread(threadId) {
|
|
20432
|
-
|
|
20885
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20886
|
+
return memoryStorage.deleteThread({ threadId });
|
|
20433
20887
|
}
|
|
20434
20888
|
async deleteMessages(messageIds) {
|
|
20889
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20435
20890
|
const ids = Array.isArray(messageIds) ? messageIds?.map((item) => typeof item === "string" ? item : item.id) : [messageIds];
|
|
20436
|
-
return
|
|
20891
|
+
return memoryStorage.deleteMessages(ids);
|
|
20437
20892
|
}
|
|
20438
20893
|
async getWorkingMemory({
|
|
20439
20894
|
threadId,
|
|
@@ -20450,10 +20905,15 @@ var MockMemory = class extends MastraMemory {
|
|
|
20450
20905
|
if (!id) {
|
|
20451
20906
|
return null;
|
|
20452
20907
|
}
|
|
20453
|
-
const
|
|
20908
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20909
|
+
const resource = await memoryStorage.getResourceById({ resourceId: id });
|
|
20454
20910
|
return resource?.workingMemory || null;
|
|
20455
20911
|
}
|
|
20456
20912
|
listTools(_config) {
|
|
20913
|
+
const mergedConfig = this.getMergedThreadConfig(_config);
|
|
20914
|
+
if (!mergedConfig.workingMemory?.enabled) {
|
|
20915
|
+
return {};
|
|
20916
|
+
}
|
|
20457
20917
|
return {
|
|
20458
20918
|
updateWorkingMemory: createTool({
|
|
20459
20919
|
id: "update-working-memory",
|
|
@@ -20538,7 +20998,8 @@ var MockMemory = class extends MastraMemory {
|
|
|
20538
20998
|
if (!id) {
|
|
20539
20999
|
throw new Error(`Cannot update working memory: ${scope} ID is required`);
|
|
20540
21000
|
}
|
|
20541
|
-
await this.
|
|
21001
|
+
const memoryStorage = await this.getMemoryStore();
|
|
21002
|
+
await memoryStorage.updateResource({
|
|
20542
21003
|
resourceId: id,
|
|
20543
21004
|
workingMemory
|
|
20544
21005
|
});
|
|
@@ -20567,6 +21028,6 @@ var MockMemory = class extends MastraMemory {
|
|
|
20567
21028
|
}
|
|
20568
21029
|
};
|
|
20569
21030
|
|
|
20570
|
-
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, loop, mapVariable, memoryDefaultOptions, parseMemoryRequestContext, resolveThreadIdFromArgs, runCountDeprecationMessage, tryGenerateWithJsonFallback, tryStreamWithJsonFallback, validateStepInput, validateStepResumeData, validateStepStateData, validateStepSuspendData };
|
|
20571
|
-
//# sourceMappingURL=chunk-
|
|
20572
|
-
//# sourceMappingURL=chunk-
|
|
21031
|
+
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 };
|
|
21032
|
+
//# sourceMappingURL=chunk-NGWTSHNA.js.map
|
|
21033
|
+
//# sourceMappingURL=chunk-NGWTSHNA.js.map
|