@mastra/core 1.0.0-beta.11 → 1.0.0-beta.14
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 +343 -0
- package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +7549 -0
- package/dist/_types/@internal_ai-sdk-v4/dist/test.d.ts +65 -0
- package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +8396 -0
- package/dist/_types/@internal_ai-sdk-v5/dist/test.d.ts +1708 -0
- package/dist/_types/@internal_external-types/dist/index.d.ts +858 -0
- package/dist/agent/agent-legacy.d.ts +1 -1
- package/dist/agent/agent.d.ts +3 -3
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +11 -8
- 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 +4 -3
- 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 +1 -1
- package/dist/agent/message-list/prompt/invalid-content-error.d.ts +1 -1
- package/dist/agent/message-list/types.d.ts +3 -3
- package/dist/agent/message-list/types.d.ts.map +1 -1
- package/dist/agent/message-list/utils/ai-v4-v5/core-model-message.d.ts +1 -1
- package/dist/agent/message-list/utils/ai-v4-v5/ui-message.d.ts +1 -1
- package/dist/agent/message-list/utils/ai-v5/gemini-compatibility.d.ts +2 -2
- package/dist/agent/message-list/utils/ai-v5/gemini-compatibility.d.ts.map +1 -1
- package/dist/agent/message-list/utils/convert-messages.d.ts +2 -2
- package/dist/agent/message-list/utils/convert-messages.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/types.d.ts +3 -3
- package/dist/agent/utils.d.ts +7 -4
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +4 -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/agent/workflows/prepare-stream/stream-step.d.ts +3 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
- package/dist/bundler/types.d.ts +15 -1
- 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-2SQB3WBT.js +4574 -0
- package/dist/chunk-2SQB3WBT.js.map +1 -0
- package/dist/{chunk-THZTRBFS.js → chunk-373OC54J.js} +8 -8
- package/dist/chunk-373OC54J.js.map +1 -0
- package/dist/{chunk-US2U7ECW.js → chunk-3IP3DZ7G.js} +234 -101
- package/dist/chunk-3IP3DZ7G.js.map +1 -0
- package/dist/{chunk-SXNQRJQD.js → chunk-4AT6YQKZ.js} +26 -20
- package/dist/chunk-4AT6YQKZ.js.map +1 -0
- package/dist/{chunk-C36YRTZ6.js → chunk-4CMIJQF6.js} +117 -114
- package/dist/chunk-4CMIJQF6.js.map +1 -0
- package/dist/chunk-53SZJCBX.cjs +4888 -0
- package/dist/chunk-53SZJCBX.cjs.map +1 -0
- package/dist/chunk-55VPMN3N.js +250 -0
- package/dist/chunk-55VPMN3N.js.map +1 -0
- package/dist/{chunk-QM5SRDJX.js → chunk-5PTZG26U.js} +66 -84
- package/dist/chunk-5PTZG26U.js.map +1 -0
- package/dist/{chunk-U3XOLEPX.js → chunk-5UQ5TB6J.js} +6 -32
- package/dist/chunk-5UQ5TB6J.js.map +1 -0
- package/dist/{chunk-O2BJW7YA.js → chunk-67LM2UCT.js} +9 -9
- package/dist/chunk-67LM2UCT.js.map +1 -0
- package/dist/{chunk-YC6PJEPH.cjs → chunk-6CG7IY57.cjs} +266 -133
- package/dist/chunk-6CG7IY57.cjs.map +1 -0
- package/dist/chunk-6PMMP3FR.js +7 -0
- package/dist/chunk-6PMMP3FR.js.map +1 -0
- package/dist/{chunk-DZUJEN5N.cjs → chunk-6SZKM6EC.cjs} +10 -3
- package/dist/{chunk-DZUJEN5N.cjs.map → chunk-6SZKM6EC.cjs.map} +1 -1
- package/dist/{chunk-5Q6WAYEY.cjs → chunk-72E3YF6A.cjs} +35 -49
- package/dist/chunk-72E3YF6A.cjs.map +1 -0
- package/dist/{chunk-5WRI5ZAA.js → chunk-7D4SUZUM.js} +10 -4
- package/dist/{chunk-5WRI5ZAA.js.map → chunk-7D4SUZUM.js.map} +1 -1
- package/dist/{chunk-7P6BNIJH.js → chunk-AYBJ5GAD.js} +281 -35
- package/dist/chunk-AYBJ5GAD.js.map +1 -0
- package/dist/chunk-D22XABFZ.js +79 -0
- package/dist/chunk-D22XABFZ.js.map +1 -0
- package/dist/{chunk-SCUWP4II.cjs → chunk-DBW6S25C.cjs} +47 -74
- package/dist/chunk-DBW6S25C.cjs.map +1 -0
- package/dist/{chunk-MRFUISXC.cjs → chunk-EGHGFLL3.cjs} +2631 -179
- package/dist/chunk-EGHGFLL3.cjs.map +1 -0
- package/dist/{chunk-BJXKH4LG.cjs → chunk-ETWAR2YE.cjs} +43 -78
- package/dist/chunk-ETWAR2YE.cjs.map +1 -0
- package/dist/{chunk-CZEJQSWB.cjs → chunk-F75EQ574.cjs} +65 -6
- package/dist/chunk-F75EQ574.cjs.map +1 -0
- package/dist/{chunk-BUKY6CTR.cjs → chunk-FPDJ4XN6.cjs} +282 -36
- package/dist/chunk-FPDJ4XN6.cjs.map +1 -0
- package/dist/chunk-FST2G2FQ.cjs +84 -0
- package/dist/chunk-FST2G2FQ.cjs.map +1 -0
- package/dist/chunk-FVQTJUBD.cjs +2120 -0
- package/dist/chunk-FVQTJUBD.cjs.map +1 -0
- package/dist/chunk-G6E6V2Z4.js +2070 -0
- package/dist/chunk-G6E6V2Z4.js.map +1 -0
- package/dist/{chunk-JIGDJK2O.js → chunk-GBQXIVL6.js} +4 -39
- package/dist/chunk-GBQXIVL6.js.map +1 -0
- package/dist/{chunk-F2GAJSBI.js → chunk-GELVUDUY.js} +11 -8
- package/dist/chunk-GELVUDUY.js.map +1 -0
- package/dist/chunk-GVAPYQRO.cjs +252 -0
- package/dist/chunk-GVAPYQRO.cjs.map +1 -0
- package/dist/{chunk-TWH4PTDG.cjs → chunk-HWMMIRIF.cjs} +32 -27
- package/dist/chunk-HWMMIRIF.cjs.map +1 -0
- package/dist/{chunk-52RSUALV.cjs → chunk-JAGQZZ43.cjs} +1660 -1196
- package/dist/chunk-JAGQZZ43.cjs.map +1 -0
- package/dist/{chunk-PK2A5WBG.js → chunk-K66U47VL.js} +54 -7
- package/dist/chunk-K66U47VL.js.map +1 -0
- package/dist/chunk-L3NKIMF5.cjs +10 -0
- package/dist/chunk-L3NKIMF5.cjs.map +1 -0
- package/dist/chunk-L4JCRWDY.cjs +252 -0
- package/dist/chunk-L4JCRWDY.cjs.map +1 -0
- package/dist/{chunk-IVV5TOMD.js → chunk-LDXKZYOV.js} +31 -11
- package/dist/chunk-LDXKZYOV.js.map +1 -0
- package/dist/chunk-NESKUIRE.cjs +4586 -0
- package/dist/chunk-NESKUIRE.cjs.map +1 -0
- package/dist/{chunk-SVLMF4UZ.cjs → chunk-NIOEY3N3.cjs} +66 -85
- package/dist/chunk-NIOEY3N3.cjs.map +1 -0
- package/dist/{chunk-PG5H6QIO.cjs → chunk-O3ULBGV6.cjs} +40 -20
- package/dist/chunk-O3ULBGV6.cjs.map +1 -0
- package/dist/{chunk-WTSZBHIZ.cjs → chunk-O5BQBZEF.cjs} +28 -28
- package/dist/chunk-O5BQBZEF.cjs.map +1 -0
- package/dist/{chunk-4JKEUSCC.cjs → chunk-OOUFPYSX.cjs} +25 -22
- package/dist/chunk-OOUFPYSX.cjs.map +1 -0
- package/dist/chunk-QDVYP2T7.js +4883 -0
- package/dist/chunk-QDVYP2T7.js.map +1 -0
- package/dist/{chunk-2ULLRN4Y.js → chunk-QF4MHFSU.js} +1294 -834
- package/dist/chunk-QF4MHFSU.js.map +1 -0
- package/dist/{chunk-Z57R5WS4.js → chunk-SLBWA2F3.js} +4 -4
- package/dist/{chunk-Z57R5WS4.js.map → chunk-SLBWA2F3.js.map} +1 -1
- package/dist/chunk-ST7NBF4H.cjs +84 -0
- package/dist/chunk-ST7NBF4H.cjs.map +1 -0
- package/dist/{chunk-YWMMBIOM.cjs → chunk-TDM43G4I.cjs} +15 -15
- package/dist/{chunk-YWMMBIOM.cjs.map → chunk-TDM43G4I.cjs.map} +1 -1
- package/dist/{chunk-S73Z3PBJ.cjs → chunk-TRUNX3AX.cjs} +138 -134
- package/dist/chunk-TRUNX3AX.cjs.map +1 -0
- package/dist/chunk-VE6HQ7H6.js +250 -0
- package/dist/chunk-VE6HQ7H6.js.map +1 -0
- package/dist/{chunk-OEIVMCWX.js → chunk-VZJOEGQA.js} +2536 -84
- package/dist/chunk-VZJOEGQA.js.map +1 -0
- package/dist/{chunk-JJ5O45LH.js → chunk-YPLZDWG7.js} +32 -27
- package/dist/chunk-YPLZDWG7.js.map +1 -0
- package/dist/{chunk-MGCGWPQJ.cjs → chunk-Z55SJVEC.cjs} +8 -8
- package/dist/chunk-Z55SJVEC.cjs.map +1 -0
- package/dist/error/index.cjs +6 -6
- package/dist/error/index.d.ts +26 -20
- package/dist/error/index.d.ts.map +1 -1
- package/dist/error/index.js +1 -1
- package/dist/error/utils.d.ts +19 -5
- package/dist/error/utils.d.ts.map +1 -1
- package/dist/evals/index.cjs +4 -4
- package/dist/evals/index.js +1 -1
- package/dist/evals/run/index.d.ts +1 -1
- package/dist/evals/run/index.d.ts.map +1 -1
- package/dist/evals/scoreTraces/index.cjs +8 -8
- package/dist/evals/scoreTraces/index.js +2 -2
- package/dist/evals/types.d.ts +1 -1
- package/dist/events/event-emitter.d.ts +6 -1
- package/dist/events/event-emitter.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 +15 -15
- package/dist/llm/index.d.ts +2 -2
- package/dist/llm/index.d.ts.map +1 -1
- 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 +5 -1
- package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -1
- package/dist/llm/model/aisdk/v6/model.d.ts +51 -0
- package/dist/llm/model/aisdk/v6/model.d.ts.map +1 -0
- package/dist/llm/model/base.types.d.ts +2 -2
- package/dist/llm/model/model.d.ts +1 -1
- package/dist/llm/model/model.d.ts.map +1 -1
- package/dist/llm/model/model.loop.d.ts +3 -3
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/model.loop.types.d.ts +1 -1
- package/dist/llm/model/model.loop.types.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +135 -11
- 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 +19 -8
- 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/loop.d.ts +2 -2
- package/dist/loop/loop.d.ts.map +1 -1
- package/dist/loop/network/index.d.ts +2 -2
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts +2 -2
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts.map +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV3Mock.d.ts +37 -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/options.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 +1 -1
- package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
- package/dist/loop/test-utils/tools.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 +8 -7
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +49 -49
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +34 -34
- 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 +17 -17
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +22 -21
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +49 -49
- 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 +18 -18
- package/dist/loop/workflows/schema.d.ts.map +1 -1
- package/dist/loop/workflows/stream.d.ts +2 -2
- package/dist/loop/workflows/stream.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- 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 +6 -6
- package/dist/memory/index.js +1 -1
- package/dist/memory/memory.d.ts +1 -1
- package/dist/memory/types.d.ts +3 -3
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/models-dev-E3WWI7VA.js +3 -0
- package/dist/{models-dev-23RN2WHG.js.map → models-dev-E3WWI7VA.js.map} +1 -1
- package/dist/models-dev-PPS7X4JM.cjs +12 -0
- package/dist/{models-dev-EO3SUIY2.cjs.map → models-dev-PPS7X4JM.cjs.map} +1 -1
- package/dist/netlify-TY656UYF.js +3 -0
- package/dist/{netlify-GXJ5D5DD.js.map → netlify-TY656UYF.js.map} +1 -1
- package/dist/netlify-VZFM5UH3.cjs +12 -0
- package/dist/{netlify-KJLY3GFS.cjs.map → netlify-VZFM5UH3.cjs.map} +1 -1
- package/dist/processors/index.cjs +37 -37
- package/dist/processors/index.d.ts +9 -9
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/runner.d.ts.map +1 -1
- package/dist/processors/step-schema.d.ts +1293 -1293
- package/dist/processors/step-schema.d.ts.map +1 -1
- package/dist/provider-registry-NXVD764B.js +3 -0
- package/dist/{provider-registry-F67Y6OF2.js.map → provider-registry-NXVD764B.js.map} +1 -1
- package/dist/provider-registry-ZIWSEUQE.cjs +40 -0
- package/dist/{provider-registry-3TG2KUD2.cjs.map → provider-registry-ZIWSEUQE.cjs.map} +1 -1
- package/dist/provider-registry.json +276 -30
- package/dist/{registry-generator-UMTNPBJX.js → registry-generator-AVQXI3GX.js} +2 -2
- package/dist/{registry-generator-UMTNPBJX.js.map → registry-generator-AVQXI3GX.js.map} +1 -1
- package/dist/{registry-generator-34SC4TAU.cjs → registry-generator-KOFNIIWJ.cjs} +2 -2
- package/dist/{registry-generator-34SC4TAU.cjs.map → registry-generator-KOFNIIWJ.cjs.map} +1 -1
- 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 +2 -10
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/domains/workflows/base.d.ts +2 -8
- package/dist/storage/domains/workflows/base.d.ts.map +1 -1
- package/dist/storage/domains/workflows/inmemory.d.ts +2 -8
- package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +38 -38
- package/dist/storage/index.js +1 -1
- package/dist/storage/mock.d.ts +2 -8
- package/dist/storage/mock.d.ts.map +1 -1
- package/dist/storage/types.d.ts +9 -1
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/RunOutput.d.ts +1 -1
- package/dist/stream/aisdk/v4/input.d.ts +1 -1
- package/dist/stream/aisdk/v5/compat/content.d.ts +1 -1
- package/dist/stream/aisdk/v5/compat/content.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts +1 -1
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat/ui-message.d.ts +1 -1
- package/dist/stream/aisdk/v5/compat/ui-message.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat/validation.d.ts +1 -1
- package/dist/stream/aisdk/v5/compat/validation.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/execute.d.ts +6 -6
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/input.d.ts +1 -1
- package/dist/stream/aisdk/v5/input.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output-helpers.d.ts +12 -27
- package/dist/stream/aisdk/v5/output-helpers.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output.d.ts +41 -91
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/transform.d.ts +1 -1
- package/dist/stream/aisdk/v5/transform.d.ts.map +1 -1
- package/dist/stream/base/input.d.ts +1 -1
- package/dist/stream/base/output.d.ts +16 -36
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/base/schema.d.ts +2 -2
- package/dist/stream/base/schema.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 -23
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.cjs +14587 -14
- package/dist/test-utils/llm-mock.cjs.map +1 -1
- package/dist/test-utils/llm-mock.d.ts +3 -3
- package/dist/test-utils/llm-mock.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.js +14577 -4
- 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-SGVIXFCP.cjs +63 -0
- package/dist/token-6GSAFR2W-SGVIXFCP.cjs.map +1 -0
- package/dist/token-6GSAFR2W-SPYPLMBM.js +61 -0
- package/dist/token-6GSAFR2W-SPYPLMBM.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-7GMW5FXI.cjs +10 -0
- package/dist/token-util-NEHG7TUY-7GMW5FXI.cjs.map +1 -0
- package/dist/token-util-NEHG7TUY-JRJTGTAB.js +8 -0
- package/dist/token-util-NEHG7TUY-JRJTGTAB.js.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/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 +2 -1
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/tools/types.d.ts +5 -5
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils.cjs +22 -22
- package/dist/utils.d.ts +5 -5
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/vector/embed.d.ts +3 -2
- package/dist/vector/embed.d.ts.map +1 -1
- package/dist/vector/index.cjs +5316 -16
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.js +5282 -4
- package/dist/vector/index.js.map +1 -1
- package/dist/vector/vector.d.ts +15 -2
- package/dist/vector/vector.d.ts.map +1 -1
- package/dist/voice/aisdk/speech.d.ts +1 -1
- package/dist/voice/aisdk/speech.d.ts.map +1 -1
- package/dist/voice/aisdk/transcription.d.ts +1 -1
- package/dist/voice/aisdk/transcription.d.ts.map +1 -1
- package/dist/voice/composite-voice.d.ts +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/constants.cjs +4 -4
- package/dist/workflows/constants.d.ts +1 -1
- package/dist/workflows/constants.d.ts.map +1 -1
- package/dist/workflows/constants.js +1 -1
- package/dist/workflows/default.d.ts +9 -16
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/execution-engine.d.ts +3 -2
- 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 -1
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts +16 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/evented/workflow.d.ts +20 -0
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/execution-engine.d.ts +25 -2
- package/dist/workflows/execution-engine.d.ts.map +1 -1
- package/dist/workflows/handlers/control-flow.d.ts +6 -5
- package/dist/workflows/handlers/control-flow.d.ts.map +1 -1
- package/dist/workflows/handlers/entry.d.ts +5 -3
- package/dist/workflows/handlers/entry.d.ts.map +1 -1
- package/dist/workflows/handlers/sleep.d.ts +4 -3
- package/dist/workflows/handlers/sleep.d.ts.map +1 -1
- package/dist/workflows/handlers/step.d.ts +5 -3
- package/dist/workflows/handlers/step.d.ts.map +1 -1
- package/dist/workflows/index.cjs +26 -22
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts +5 -4
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +66 -14
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/utils.d.ts +11 -0
- package/dist/workflows/utils.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +30 -9
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +13 -14
- package/src/llm/model/provider-types.generated.d.ts +135 -11
- package/dist/agent/__tests__/mock-model.d.ts +0 -8
- package/dist/agent/__tests__/mock-model.d.ts.map +0 -1
- package/dist/agent/agent-types.test-d.d.ts +0 -2
- package/dist/agent/agent-types.test-d.d.ts.map +0 -1
- package/dist/ai-sdk.types.d.ts +0 -4705
- package/dist/chunk-2ULLRN4Y.js.map +0 -1
- package/dist/chunk-3E3ILV6T.cjs +0 -518
- package/dist/chunk-3E3ILV6T.cjs.map +0 -1
- package/dist/chunk-4JKEUSCC.cjs.map +0 -1
- package/dist/chunk-52RSUALV.cjs.map +0 -1
- package/dist/chunk-5PAEYE3Q.js +0 -513
- package/dist/chunk-5PAEYE3Q.js.map +0 -1
- package/dist/chunk-5Q6WAYEY.cjs.map +0 -1
- package/dist/chunk-7P6BNIJH.js.map +0 -1
- package/dist/chunk-ABJOUEVA.cjs +0 -10
- package/dist/chunk-ABJOUEVA.cjs.map +0 -1
- package/dist/chunk-BJXKH4LG.cjs.map +0 -1
- package/dist/chunk-BUKY6CTR.cjs.map +0 -1
- package/dist/chunk-C36YRTZ6.js.map +0 -1
- package/dist/chunk-CZEJQSWB.cjs.map +0 -1
- package/dist/chunk-F2GAJSBI.js.map +0 -1
- package/dist/chunk-IVV5TOMD.js.map +0 -1
- package/dist/chunk-JIGDJK2O.js.map +0 -1
- package/dist/chunk-JJ5O45LH.js.map +0 -1
- package/dist/chunk-MGCGWPQJ.cjs.map +0 -1
- package/dist/chunk-MRFUISXC.cjs.map +0 -1
- package/dist/chunk-NLNKQD2T.js +0 -7
- package/dist/chunk-NLNKQD2T.js.map +0 -1
- package/dist/chunk-O2BJW7YA.js.map +0 -1
- package/dist/chunk-OEIVMCWX.js.map +0 -1
- package/dist/chunk-PG5H6QIO.cjs.map +0 -1
- package/dist/chunk-PK2A5WBG.js.map +0 -1
- package/dist/chunk-QM5SRDJX.js.map +0 -1
- package/dist/chunk-S73Z3PBJ.cjs.map +0 -1
- package/dist/chunk-SCUWP4II.cjs.map +0 -1
- package/dist/chunk-SVLMF4UZ.cjs.map +0 -1
- package/dist/chunk-SXNQRJQD.js.map +0 -1
- package/dist/chunk-THZTRBFS.js.map +0 -1
- package/dist/chunk-TWH4PTDG.cjs.map +0 -1
- package/dist/chunk-U3XOLEPX.js.map +0 -1
- package/dist/chunk-US2U7ECW.js.map +0 -1
- package/dist/chunk-WTSZBHIZ.cjs.map +0 -1
- package/dist/chunk-YC6PJEPH.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-23RN2WHG.js +0 -3
- package/dist/models-dev-EO3SUIY2.cjs +0 -12
- package/dist/netlify-GXJ5D5DD.js +0 -3
- package/dist/netlify-KJLY3GFS.cjs +0 -12
- package/dist/provider-registry-3TG2KUD2.cjs +0 -40
- package/dist/provider-registry-F67Y6OF2.js +0 -3
- package/dist/tools/tool-stream-types.test-d.d.ts +0 -2
- package/dist/tools/tool-stream-types.test-d.d.ts.map +0 -1
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import { DefaultVoice } from './chunk-
|
|
2
|
-
import {
|
|
3
|
-
import { InMemoryStore } from './chunk-
|
|
4
|
-
import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { DefaultVoice } from './chunk-GELVUDUY.js';
|
|
2
|
+
import { PUBSUB_SYMBOL, STREAM_FORMAT_SYMBOL } from './chunk-6PMMP3FR.js';
|
|
3
|
+
import { InMemoryStore } from './chunk-GBQXIVL6.js';
|
|
4
|
+
import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-4AT6YQKZ.js';
|
|
5
|
+
import { createTextStreamResponse, createUIMessageStreamResponse, createUIMessageStream, parsePartialJson, isDeepEqualData, stepCountIs } from './chunk-2SQB3WBT.js';
|
|
6
|
+
import { generateId, asSchema, jsonSchema, APICallError, tool } from './chunk-G6E6V2Z4.js';
|
|
7
|
+
import { resolveModelConfig, ModelRouterEmbeddingModel, ModelRouterLanguageModel } from './chunk-QDVYP2T7.js';
|
|
8
|
+
import { MastraLLMV1 } from './chunk-4CMIJQF6.js';
|
|
9
|
+
import { PubSub } from './chunk-BVUMKER5.js';
|
|
7
10
|
import { executeHook } from './chunk-L54GIUCB.js';
|
|
8
|
-
import { removeUndefinedValues, ensureToolProperties, makeCoreTool, createMastraProxy, isZodType, deepMerge, selectFields, delay } from './chunk-
|
|
11
|
+
import { removeUndefinedValues, ensureToolProperties, makeCoreTool, createMastraProxy, isZodType, deepMerge, selectFields, delay } from './chunk-LDXKZYOV.js';
|
|
9
12
|
import { getOrCreateSpan, wrapMastra, executeWithContextSync } from './chunk-Y36Y5MTD.js';
|
|
10
|
-
import { MastraError, getErrorFromUnknown } from './chunk-
|
|
13
|
+
import { MastraError, getErrorFromUnknown } from './chunk-YPLZDWG7.js';
|
|
11
14
|
import { ToolStream } from './chunk-DD2VNRQM.js';
|
|
12
|
-
import { Tool, createTool } from './chunk-
|
|
15
|
+
import { Tool, createTool } from './chunk-373OC54J.js';
|
|
13
16
|
import { RequestContext, MASTRA_RESOURCE_ID_KEY, MASTRA_THREAD_ID_KEY } from './chunk-6TBWJV35.js';
|
|
14
17
|
import { zodToJsonSchema as zodToJsonSchema$1 } from './chunk-PJKCPRYF.js';
|
|
15
18
|
import { MastraBase } from './chunk-LSHPJWM5.js';
|
|
16
19
|
import { RegisteredLogger, ConsoleLogger } from './chunk-NRUZYMHE.js';
|
|
17
|
-
import { __commonJS, __toESM } from './chunk-
|
|
18
|
-
import
|
|
20
|
+
import { __commonJS, __toESM } from './chunk-7D4SUZUM.js';
|
|
21
|
+
import z8, { z, ZodObject } from 'zod';
|
|
19
22
|
import * as crypto2 from 'crypto';
|
|
20
23
|
import { randomUUID } from 'crypto';
|
|
21
24
|
import { TransformStream, ReadableStream as ReadableStream$1, WritableStream as WritableStream$1 } from 'stream/web';
|
|
22
25
|
import EventEmitter2, { EventEmitter } from 'events';
|
|
23
26
|
import { getErrorMessage, TypeValidationError } from '@ai-sdk/provider-v5';
|
|
24
|
-
import { createTextStreamResponse, createUIMessageStreamResponse, createUIMessageStream, generateId, asSchema, parsePartialJson, isDeepEqualData, jsonSchema, APICallError, tool, stepCountIs } from 'ai-v5';
|
|
25
27
|
import z4 from 'zod/v4';
|
|
26
28
|
import { OpenAIReasoningSchemaCompatLayer, OpenAISchemaCompatLayer, GoogleSchemaCompatLayer, AnthropicSchemaCompatLayer, DeepSeekSchemaCompatLayer, MetaSchemaCompatLayer, applyCompatLayer } from '@mastra/schema-compat';
|
|
27
29
|
import { isEmpty } from 'radash';
|
|
@@ -426,6 +428,8 @@ var DelayedPromise = class {
|
|
|
426
428
|
}
|
|
427
429
|
}
|
|
428
430
|
};
|
|
431
|
+
|
|
432
|
+
// src/stream/aisdk/v5/compat/prepare-tools.ts
|
|
429
433
|
function prepareToolsAndToolChoice({
|
|
430
434
|
tools,
|
|
431
435
|
toolChoice,
|
|
@@ -439,17 +443,17 @@ function prepareToolsAndToolChoice({
|
|
|
439
443
|
}
|
|
440
444
|
const filteredTools = activeTools != null ? Object.entries(tools || {}).filter(([name]) => activeTools.includes(name)) : Object.entries(tools || {});
|
|
441
445
|
return {
|
|
442
|
-
tools: filteredTools.map(([name,
|
|
446
|
+
tools: filteredTools.map(([name, tool2]) => {
|
|
443
447
|
try {
|
|
444
448
|
let inputSchema;
|
|
445
|
-
if ("inputSchema" in
|
|
446
|
-
inputSchema =
|
|
447
|
-
} else if ("parameters" in
|
|
448
|
-
inputSchema =
|
|
449
|
+
if ("inputSchema" in tool2) {
|
|
450
|
+
inputSchema = tool2.inputSchema;
|
|
451
|
+
} else if ("parameters" in tool2) {
|
|
452
|
+
inputSchema = tool2.parameters;
|
|
449
453
|
}
|
|
450
454
|
const sdkTool = tool({
|
|
451
455
|
type: "function",
|
|
452
|
-
...
|
|
456
|
+
...tool2,
|
|
453
457
|
inputSchema
|
|
454
458
|
});
|
|
455
459
|
const toolType = sdkTool?.type ?? "function";
|
|
@@ -489,7 +493,7 @@ function prepareToolsAndToolChoice({
|
|
|
489
493
|
console.error("Error preparing tool", e);
|
|
490
494
|
return null;
|
|
491
495
|
}
|
|
492
|
-
}).filter((
|
|
496
|
+
}).filter((tool2) => tool2 !== null),
|
|
493
497
|
toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
|
|
494
498
|
};
|
|
495
499
|
}
|
|
@@ -725,6 +729,69 @@ The input text may be in any format (sentences, bullet points, paragraphs, etc.)
|
|
|
725
729
|
}
|
|
726
730
|
};
|
|
727
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
|
+
|
|
728
795
|
// src/processors/runner.ts
|
|
729
796
|
var ProcessorState = class {
|
|
730
797
|
accumulatedText = "";
|
|
@@ -1635,12 +1702,13 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1635
1702
|
const { model: _model, ...rest } = result;
|
|
1636
1703
|
if (result.model) {
|
|
1637
1704
|
const resolvedModel = await resolveModelConfig(result.model);
|
|
1638
|
-
|
|
1705
|
+
const isSupported = isSupportedLanguageModel(resolvedModel);
|
|
1706
|
+
if (!isSupported) {
|
|
1639
1707
|
throw new MastraError({
|
|
1640
1708
|
category: "USER",
|
|
1641
1709
|
domain: "AGENT",
|
|
1642
|
-
id: "
|
|
1643
|
-
text: `Processor ${processor.id} returned
|
|
1710
|
+
id: "PROCESSOR_RETURNED_UNSUPPORTED_MODEL",
|
|
1711
|
+
text: `Processor ${processor.id} returned an unsupported model version ${resolvedModel.specificationVersion} in step ${stepNumber}. Only ${supportedLanguageModelSpecifications.join(", ")} models are supported in processInputStep.`
|
|
1644
1712
|
});
|
|
1645
1713
|
}
|
|
1646
1714
|
return {
|
|
@@ -1839,10 +1907,8 @@ function convertFullStreamChunkToMastra(value, ctx) {
|
|
|
1839
1907
|
reason: value.finishReason
|
|
1840
1908
|
},
|
|
1841
1909
|
output: {
|
|
1842
|
-
usage
|
|
1843
|
-
|
|
1844
|
-
totalTokens: value?.usage?.totalTokens ?? (value.usage?.inputTokens ?? 0) + (value.usage?.outputTokens ?? 0)
|
|
1845
|
-
}
|
|
1910
|
+
// Normalize usage to handle both V2 (flat) and V3 (nested) formats
|
|
1911
|
+
usage: normalizeUsage(value.usage)
|
|
1846
1912
|
},
|
|
1847
1913
|
metadata: {
|
|
1848
1914
|
providerMetadata: value.providerMetadata
|
|
@@ -1894,6 +1960,7 @@ function convertMastraChunkToAISDKv5({
|
|
|
1894
1960
|
type: "finish",
|
|
1895
1961
|
// Cast needed: Mastra extends reason with 'tripwire' | 'retry' for processor scenarios
|
|
1896
1962
|
finishReason: chunk.payload.stepResult.reason,
|
|
1963
|
+
// Cast needed: Mastra's LanguageModelUsage has optional properties, V2 has required-but-nullable
|
|
1897
1964
|
totalUsage: chunk.payload.output.usage
|
|
1898
1965
|
};
|
|
1899
1966
|
}
|
|
@@ -1912,18 +1979,8 @@ function convertMastraChunkToAISDKv5({
|
|
|
1912
1979
|
};
|
|
1913
1980
|
case "reasoning-signature":
|
|
1914
1981
|
throw new Error('AISDKv5 chunk type "reasoning-signature" not supported');
|
|
1915
|
-
// return {
|
|
1916
|
-
// type: 'reasoning-signature' as const,
|
|
1917
|
-
// id: chunk.payload.id,
|
|
1918
|
-
// signature: chunk.payload.signature,
|
|
1919
|
-
// };
|
|
1920
1982
|
case "redacted-reasoning":
|
|
1921
1983
|
throw new Error('AISDKv5 chunk type "redacted-reasoning" not supported');
|
|
1922
|
-
// return {
|
|
1923
|
-
// type: 'redacted-reasoning',
|
|
1924
|
-
// id: chunk.payload.id,
|
|
1925
|
-
// data: chunk.payload.data,
|
|
1926
|
-
// };
|
|
1927
1984
|
case "reasoning-end":
|
|
1928
1985
|
return {
|
|
1929
1986
|
type: "reasoning-end",
|
|
@@ -2077,6 +2134,44 @@ function convertMastraChunkToAISDKv5({
|
|
|
2077
2134
|
return;
|
|
2078
2135
|
}
|
|
2079
2136
|
}
|
|
2137
|
+
function isV3Usage(usage) {
|
|
2138
|
+
if (!usage || typeof usage !== "object") return false;
|
|
2139
|
+
const u = usage;
|
|
2140
|
+
return typeof u.inputTokens === "object" && u.inputTokens !== null && "total" in u.inputTokens && typeof u.outputTokens === "object" && u.outputTokens !== null && "total" in u.outputTokens;
|
|
2141
|
+
}
|
|
2142
|
+
function normalizeUsage(usage) {
|
|
2143
|
+
if (!usage) {
|
|
2144
|
+
return {
|
|
2145
|
+
inputTokens: void 0,
|
|
2146
|
+
outputTokens: void 0,
|
|
2147
|
+
totalTokens: void 0,
|
|
2148
|
+
reasoningTokens: void 0,
|
|
2149
|
+
cachedInputTokens: void 0,
|
|
2150
|
+
raw: void 0
|
|
2151
|
+
};
|
|
2152
|
+
}
|
|
2153
|
+
if (isV3Usage(usage)) {
|
|
2154
|
+
const inputTokens = usage.inputTokens.total;
|
|
2155
|
+
const outputTokens = usage.outputTokens.total;
|
|
2156
|
+
return {
|
|
2157
|
+
inputTokens,
|
|
2158
|
+
outputTokens,
|
|
2159
|
+
totalTokens: (inputTokens ?? 0) + (outputTokens ?? 0),
|
|
2160
|
+
reasoningTokens: usage.outputTokens.reasoning,
|
|
2161
|
+
cachedInputTokens: usage.inputTokens.cacheRead,
|
|
2162
|
+
raw: usage
|
|
2163
|
+
};
|
|
2164
|
+
}
|
|
2165
|
+
const v2Usage = usage;
|
|
2166
|
+
return {
|
|
2167
|
+
inputTokens: v2Usage.inputTokens,
|
|
2168
|
+
outputTokens: v2Usage.outputTokens,
|
|
2169
|
+
totalTokens: v2Usage.totalTokens ?? (v2Usage.inputTokens ?? 0) + (v2Usage.outputTokens ?? 0),
|
|
2170
|
+
reasoningTokens: v2Usage.reasoningTokens,
|
|
2171
|
+
cachedInputTokens: v2Usage.cachedInputTokens,
|
|
2172
|
+
raw: usage
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2080
2175
|
|
|
2081
2176
|
// src/stream/aisdk/v5/output.ts
|
|
2082
2177
|
var AISDKV5OutputStream = class {
|
|
@@ -2366,6 +2461,8 @@ var AISDKV5OutputStream = class {
|
|
|
2366
2461
|
return this.#modelOutput.object;
|
|
2367
2462
|
}
|
|
2368
2463
|
};
|
|
2464
|
+
|
|
2465
|
+
// src/stream/base/schema.ts
|
|
2369
2466
|
function asJsonSchema(schema) {
|
|
2370
2467
|
if (!schema) {
|
|
2371
2468
|
return void 0;
|
|
@@ -2970,7 +3067,11 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
2970
3067
|
#warnings = [];
|
|
2971
3068
|
#finishReason = void 0;
|
|
2972
3069
|
#request = {};
|
|
2973
|
-
#usageCount = {
|
|
3070
|
+
#usageCount = {
|
|
3071
|
+
inputTokens: void 0,
|
|
3072
|
+
outputTokens: void 0,
|
|
3073
|
+
totalTokens: void 0
|
|
3074
|
+
};
|
|
2974
3075
|
#tripwire = void 0;
|
|
2975
3076
|
#delayedPromises = {
|
|
2976
3077
|
suspendPayload: new DelayedPromise(),
|
|
@@ -3317,23 +3418,25 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
3317
3418
|
};
|
|
3318
3419
|
self.#finishReason = "other";
|
|
3319
3420
|
self.#streamFinished = true;
|
|
3320
|
-
self
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3421
|
+
self.resolvePromises({
|
|
3422
|
+
text: self.#bufferedText.join(""),
|
|
3423
|
+
finishReason: "other",
|
|
3424
|
+
object: void 0,
|
|
3425
|
+
usage: self.#usageCount,
|
|
3426
|
+
warnings: self.#warnings,
|
|
3427
|
+
providerMetadata: void 0,
|
|
3428
|
+
response: {},
|
|
3429
|
+
request: {},
|
|
3430
|
+
reasoning: [],
|
|
3431
|
+
reasoningText: void 0,
|
|
3432
|
+
sources: [],
|
|
3433
|
+
files: [],
|
|
3434
|
+
toolCalls: [],
|
|
3435
|
+
toolResults: [],
|
|
3436
|
+
steps: self.#bufferedSteps,
|
|
3437
|
+
totalUsage: self.#usageCount,
|
|
3438
|
+
content: []
|
|
3439
|
+
});
|
|
3337
3440
|
self.#emitChunk(chunk);
|
|
3338
3441
|
controller.enqueue(chunk);
|
|
3339
3442
|
self.#emitter.emit("finish");
|
|
@@ -3401,8 +3504,10 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
3401
3504
|
if (lastStep && outputText && outputText !== originalText) {
|
|
3402
3505
|
lastStep.text = outputText;
|
|
3403
3506
|
}
|
|
3404
|
-
|
|
3405
|
-
|
|
3507
|
+
this.resolvePromises({
|
|
3508
|
+
text: outputText || originalText,
|
|
3509
|
+
finishReason: self.#finishReason
|
|
3510
|
+
});
|
|
3406
3511
|
if (chunk.payload.metadata) {
|
|
3407
3512
|
const { providerMetadata, request, ...otherMetadata } = chunk.payload.metadata;
|
|
3408
3513
|
response = {
|
|
@@ -3412,9 +3517,10 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
3412
3517
|
};
|
|
3413
3518
|
}
|
|
3414
3519
|
} else if (!self.#options.isLLMExecutionStep) {
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3520
|
+
this.resolvePromises({
|
|
3521
|
+
text: self.#bufferedText.join(""),
|
|
3522
|
+
finishReason: self.#finishReason
|
|
3523
|
+
});
|
|
3418
3524
|
}
|
|
3419
3525
|
} catch (error2) {
|
|
3420
3526
|
if (error2 instanceof TripWire) {
|
|
@@ -3424,35 +3530,41 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
3424
3530
|
metadata: error2.options?.metadata,
|
|
3425
3531
|
processorId: error2.processorId
|
|
3426
3532
|
};
|
|
3427
|
-
self
|
|
3428
|
-
|
|
3533
|
+
self.resolvePromises({
|
|
3534
|
+
finishReason: "other",
|
|
3535
|
+
text: ""
|
|
3536
|
+
});
|
|
3429
3537
|
} else {
|
|
3430
3538
|
self.#error = getErrorFromUnknown(error2, {
|
|
3431
3539
|
fallbackMessage: "Unknown error in stream"
|
|
3432
3540
|
});
|
|
3433
|
-
self
|
|
3434
|
-
|
|
3541
|
+
self.resolvePromises({
|
|
3542
|
+
finishReason: "error",
|
|
3543
|
+
text: ""
|
|
3544
|
+
});
|
|
3435
3545
|
}
|
|
3436
3546
|
if (self.#delayedPromises.object.status.type !== "resolved") {
|
|
3437
3547
|
self.#delayedPromises.object.resolve(void 0);
|
|
3438
3548
|
}
|
|
3439
3549
|
}
|
|
3440
|
-
self.#delayedPromises.usage.resolve(self.#usageCount);
|
|
3441
|
-
self.#delayedPromises.warnings.resolve(self.#warnings);
|
|
3442
|
-
self.#delayedPromises.providerMetadata.resolve(chunk.payload.metadata?.providerMetadata);
|
|
3443
|
-
self.#delayedPromises.response.resolve(response);
|
|
3444
|
-
self.#delayedPromises.request.resolve(self.#request || {});
|
|
3445
3550
|
const reasoningText = self.#bufferedReasoning.length > 0 ? self.#bufferedReasoning.map((reasoningPart) => reasoningPart.payload.text).join("") : void 0;
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3551
|
+
this.resolvePromises({
|
|
3552
|
+
usage: self.#usageCount,
|
|
3553
|
+
warnings: self.#warnings,
|
|
3554
|
+
providerMetadata: chunk.payload.metadata?.providerMetadata,
|
|
3555
|
+
response,
|
|
3556
|
+
request: self.#request || {},
|
|
3557
|
+
reasoningText,
|
|
3558
|
+
reasoning: Object.values(self.#bufferedReasoningDetails || {}),
|
|
3559
|
+
sources: self.#bufferedSources,
|
|
3560
|
+
files: self.#bufferedFiles,
|
|
3561
|
+
toolCalls: self.#toolCalls,
|
|
3562
|
+
toolResults: self.#toolResults,
|
|
3563
|
+
steps: self.#bufferedSteps,
|
|
3564
|
+
totalUsage: self.#getTotalUsage(),
|
|
3565
|
+
content: messageList.get.response.aiV5.stepContent(),
|
|
3566
|
+
suspendPayload: void 0
|
|
3567
|
+
});
|
|
3456
3568
|
const baseFinishStep = self.#bufferedSteps[self.#bufferedSteps.length - 1];
|
|
3457
3569
|
if (baseFinishStep) {
|
|
3458
3570
|
const onFinishPayload = {
|
|
@@ -3520,6 +3632,28 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
3520
3632
|
if (self.#delayedPromises.object.status.type === "pending") {
|
|
3521
3633
|
self.#delayedPromises.object.resolve(void 0);
|
|
3522
3634
|
}
|
|
3635
|
+
if (self.#status === "suspended") {
|
|
3636
|
+
const reasoningText = self.#bufferedReasoning.length > 0 ? self.#bufferedReasoning.map((reasoningPart) => reasoningPart.payload.text).join("") : void 0;
|
|
3637
|
+
self.resolvePromises({
|
|
3638
|
+
toolResults: self.#toolResults,
|
|
3639
|
+
toolCalls: self.#toolCalls,
|
|
3640
|
+
text: self.#bufferedText.join(""),
|
|
3641
|
+
reasoning: Object.values(self.#bufferedReasoningDetails || {}),
|
|
3642
|
+
reasoningText,
|
|
3643
|
+
sources: self.#bufferedSources,
|
|
3644
|
+
files: self.#bufferedFiles,
|
|
3645
|
+
steps: self.#bufferedSteps,
|
|
3646
|
+
usage: self.#usageCount,
|
|
3647
|
+
totalUsage: self.#getTotalUsage(),
|
|
3648
|
+
warnings: self.#warnings,
|
|
3649
|
+
finishReason: "other",
|
|
3650
|
+
content: self.messageList.get.response.aiV5.stepContent(),
|
|
3651
|
+
object: void 0,
|
|
3652
|
+
request: self.#request,
|
|
3653
|
+
response: {},
|
|
3654
|
+
providerMetadata: void 0
|
|
3655
|
+
});
|
|
3656
|
+
}
|
|
3523
3657
|
Object.entries(self.#delayedPromises).forEach(([key, promise]) => {
|
|
3524
3658
|
if (promise.status.type === "pending") {
|
|
3525
3659
|
promise.reject(new Error(`promise '${key}' was not resolved or rejected when stream finished`));
|
|
@@ -3543,6 +3677,23 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
3543
3677
|
this.deserializeState(initialState);
|
|
3544
3678
|
}
|
|
3545
3679
|
}
|
|
3680
|
+
resolvePromise(key, value) {
|
|
3681
|
+
if (!(key in this.#delayedPromises)) {
|
|
3682
|
+
throw new MastraError({
|
|
3683
|
+
id: "MASTRA_MODEL_OUTPUT_INVALID_PROMISE_KEY",
|
|
3684
|
+
domain: "LLM" /* LLM */,
|
|
3685
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
3686
|
+
text: `Attempted to resolve invalid promise key '${key}' with value '${typeof value === "object" ? JSON.stringify(value, null, 2) : value}'`
|
|
3687
|
+
});
|
|
3688
|
+
}
|
|
3689
|
+
this.#delayedPromises[key].resolve(value);
|
|
3690
|
+
}
|
|
3691
|
+
resolvePromises(data) {
|
|
3692
|
+
for (const keyString in data) {
|
|
3693
|
+
const key = keyString;
|
|
3694
|
+
this.resolvePromise(key, data[key]);
|
|
3695
|
+
}
|
|
3696
|
+
}
|
|
3546
3697
|
#getDelayedPromise(promise) {
|
|
3547
3698
|
if (!this.#consumptionStarted) {
|
|
3548
3699
|
void this.consumeStream();
|
|
@@ -4515,7 +4666,7 @@ var getModelOutputForTripwire = async ({
|
|
|
4515
4666
|
model: {
|
|
4516
4667
|
modelId: model.modelId,
|
|
4517
4668
|
provider: model.provider,
|
|
4518
|
-
version: model.specificationVersion
|
|
4669
|
+
version: model.specificationVersion
|
|
4519
4670
|
},
|
|
4520
4671
|
stream: tripwireStream,
|
|
4521
4672
|
messageList,
|
|
@@ -4586,11 +4737,36 @@ function runScorer({
|
|
|
4586
4737
|
};
|
|
4587
4738
|
executeHook("onScorerRun" /* ON_SCORER_RUN */, payload);
|
|
4588
4739
|
}
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4740
|
+
var EventEmitterPubSub = class extends PubSub {
|
|
4741
|
+
emitter;
|
|
4742
|
+
constructor(existingEmitter) {
|
|
4743
|
+
super();
|
|
4744
|
+
this.emitter = existingEmitter ?? new EventEmitter2();
|
|
4745
|
+
}
|
|
4746
|
+
async publish(topic, event) {
|
|
4747
|
+
const id = crypto.randomUUID();
|
|
4748
|
+
const createdAt = /* @__PURE__ */ new Date();
|
|
4749
|
+
this.emitter.emit(topic, {
|
|
4750
|
+
...event,
|
|
4751
|
+
id,
|
|
4752
|
+
createdAt
|
|
4753
|
+
});
|
|
4754
|
+
}
|
|
4755
|
+
async subscribe(topic, cb) {
|
|
4756
|
+
this.emitter.on(topic, cb);
|
|
4757
|
+
}
|
|
4758
|
+
async unsubscribe(topic, cb) {
|
|
4759
|
+
this.emitter.off(topic, cb);
|
|
4760
|
+
}
|
|
4761
|
+
async flush() {
|
|
4762
|
+
}
|
|
4763
|
+
/**
|
|
4764
|
+
* Clean up all listeners during graceful shutdown.
|
|
4765
|
+
*/
|
|
4766
|
+
async close() {
|
|
4767
|
+
this.emitter.removeAllListeners();
|
|
4768
|
+
}
|
|
4769
|
+
};
|
|
4594
4770
|
var TextPartSchema = z.object({
|
|
4595
4771
|
type: z.literal("text"),
|
|
4596
4772
|
text: z.string()
|
|
@@ -4818,6 +4994,43 @@ var ExecutionEngine = class extends MastraBase {
|
|
|
4818
4994
|
getLogger() {
|
|
4819
4995
|
return this.logger;
|
|
4820
4996
|
}
|
|
4997
|
+
/**
|
|
4998
|
+
* Invokes the onFinish and onError lifecycle callbacks if they are defined.
|
|
4999
|
+
* Errors in callbacks are caught and logged, not propagated.
|
|
5000
|
+
* @param result The workflow result containing status, result, error, steps, and tripwire info
|
|
5001
|
+
*/
|
|
5002
|
+
async invokeLifecycleCallbacks(result) {
|
|
5003
|
+
const { onFinish, onError } = this.options;
|
|
5004
|
+
if (onFinish) {
|
|
5005
|
+
try {
|
|
5006
|
+
await Promise.resolve(
|
|
5007
|
+
onFinish({
|
|
5008
|
+
status: result.status,
|
|
5009
|
+
result: result.result,
|
|
5010
|
+
error: result.error,
|
|
5011
|
+
steps: result.steps,
|
|
5012
|
+
tripwire: result.tripwire
|
|
5013
|
+
})
|
|
5014
|
+
);
|
|
5015
|
+
} catch (err) {
|
|
5016
|
+
this.logger.error("Error in onFinish callback", { error: err });
|
|
5017
|
+
}
|
|
5018
|
+
}
|
|
5019
|
+
if (onError && (result.status === "failed" || result.status === "tripwire")) {
|
|
5020
|
+
try {
|
|
5021
|
+
await Promise.resolve(
|
|
5022
|
+
onError({
|
|
5023
|
+
status: result.status,
|
|
5024
|
+
error: result.error,
|
|
5025
|
+
steps: result.steps,
|
|
5026
|
+
tripwire: result.tripwire
|
|
5027
|
+
})
|
|
5028
|
+
);
|
|
5029
|
+
} catch (err) {
|
|
5030
|
+
this.logger.error("Error in onError callback", { error: err });
|
|
5031
|
+
}
|
|
5032
|
+
}
|
|
5033
|
+
}
|
|
4821
5034
|
};
|
|
4822
5035
|
|
|
4823
5036
|
// src/workflows/step.ts
|
|
@@ -4850,7 +5063,16 @@ async function validateStepInput({
|
|
|
4850
5063
|
if (!validatedInput.success) {
|
|
4851
5064
|
const errors = getZodErrors(validatedInput.error);
|
|
4852
5065
|
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
4853
|
-
validationError = new
|
|
5066
|
+
validationError = new MastraError(
|
|
5067
|
+
{
|
|
5068
|
+
id: "WORKFLOW_STEP_INPUT_VALIDATION_FAILED",
|
|
5069
|
+
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
5070
|
+
category: "USER" /* USER */,
|
|
5071
|
+
text: "Step input validation failed: \n" + errorMessages
|
|
5072
|
+
},
|
|
5073
|
+
// keep the original zod error as the cause for consumers
|
|
5074
|
+
validatedInput.error
|
|
5075
|
+
);
|
|
4854
5076
|
} else {
|
|
4855
5077
|
const isEmptyData = isEmpty(validatedInput.data);
|
|
4856
5078
|
inputData = isEmptyData ? prevOutput : validatedInput.data;
|
|
@@ -4869,7 +5091,16 @@ async function validateStepResumeData({ resumeData, step }) {
|
|
|
4869
5091
|
if (!validatedResumeData.success) {
|
|
4870
5092
|
const errors = getZodErrors(validatedResumeData.error);
|
|
4871
5093
|
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
4872
|
-
validationError = new
|
|
5094
|
+
validationError = new MastraError(
|
|
5095
|
+
{
|
|
5096
|
+
id: "WORKFLOW_STEP_RESUME_DATA_VALIDATION_FAILED",
|
|
5097
|
+
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
5098
|
+
category: "USER" /* USER */,
|
|
5099
|
+
text: "Step resume data validation failed: \n" + errorMessages
|
|
5100
|
+
},
|
|
5101
|
+
// keep the original zod error as the cause for consumers
|
|
5102
|
+
validatedResumeData.error
|
|
5103
|
+
);
|
|
4873
5104
|
} else {
|
|
4874
5105
|
resumeData = validatedResumeData.data;
|
|
4875
5106
|
}
|
|
@@ -4891,7 +5122,16 @@ async function validateStepSuspendData({
|
|
|
4891
5122
|
if (!validatedSuspendData.success) {
|
|
4892
5123
|
const errors = getZodErrors(validatedSuspendData.error);
|
|
4893
5124
|
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
4894
|
-
validationError = new
|
|
5125
|
+
validationError = new MastraError(
|
|
5126
|
+
{
|
|
5127
|
+
id: "WORKFLOW_STEP_SUSPEND_DATA_VALIDATION_FAILED",
|
|
5128
|
+
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
5129
|
+
category: "USER" /* USER */,
|
|
5130
|
+
text: "Step suspend data validation failed: \n" + errorMessages
|
|
5131
|
+
},
|
|
5132
|
+
// keep the original zod error as the cause for consumers
|
|
5133
|
+
validatedSuspendData.error
|
|
5134
|
+
);
|
|
4895
5135
|
} else {
|
|
4896
5136
|
suspendData = validatedSuspendData.data;
|
|
4897
5137
|
}
|
|
@@ -5055,6 +5295,16 @@ var createTimeTravelExecutionParams = (params) => {
|
|
|
5055
5295
|
};
|
|
5056
5296
|
return timeTravelData;
|
|
5057
5297
|
};
|
|
5298
|
+
function hydrateSerializedStepErrors(steps) {
|
|
5299
|
+
if (steps) {
|
|
5300
|
+
for (const step of Object.values(steps)) {
|
|
5301
|
+
if (step.status === "failed" && "error" in step && step.error) {
|
|
5302
|
+
step.error = getErrorFromUnknown(step.error, { serializeStack: false });
|
|
5303
|
+
}
|
|
5304
|
+
}
|
|
5305
|
+
}
|
|
5306
|
+
return steps;
|
|
5307
|
+
}
|
|
5058
5308
|
|
|
5059
5309
|
// src/workflows/handlers/control-flow.ts
|
|
5060
5310
|
async function executeParallel(engine, params) {
|
|
@@ -5071,7 +5321,7 @@ async function executeParallel(engine, params) {
|
|
|
5071
5321
|
timeTravel,
|
|
5072
5322
|
executionContext,
|
|
5073
5323
|
tracingContext,
|
|
5074
|
-
|
|
5324
|
+
pubsub,
|
|
5075
5325
|
abortController,
|
|
5076
5326
|
requestContext,
|
|
5077
5327
|
outputWriter,
|
|
@@ -5144,7 +5394,7 @@ async function executeParallel(engine, params) {
|
|
|
5144
5394
|
tracingContext: {
|
|
5145
5395
|
currentSpan: parallelSpan
|
|
5146
5396
|
},
|
|
5147
|
-
|
|
5397
|
+
pubsub,
|
|
5148
5398
|
abortController,
|
|
5149
5399
|
requestContext,
|
|
5150
5400
|
outputWriter,
|
|
@@ -5183,9 +5433,7 @@ async function executeParallel(engine, params) {
|
|
|
5183
5433
|
};
|
|
5184
5434
|
}
|
|
5185
5435
|
if (execResults.status === "failed") {
|
|
5186
|
-
parallelSpan?.error({
|
|
5187
|
-
error: new Error(execResults.error)
|
|
5188
|
-
});
|
|
5436
|
+
parallelSpan?.error({ error: execResults.error });
|
|
5189
5437
|
} else {
|
|
5190
5438
|
parallelSpan?.end({
|
|
5191
5439
|
output: execResults.output || execResults
|
|
@@ -5207,7 +5455,7 @@ async function executeConditional(engine, params) {
|
|
|
5207
5455
|
timeTravel,
|
|
5208
5456
|
executionContext,
|
|
5209
5457
|
tracingContext,
|
|
5210
|
-
|
|
5458
|
+
pubsub,
|
|
5211
5459
|
abortController,
|
|
5212
5460
|
requestContext,
|
|
5213
5461
|
outputWriter,
|
|
@@ -5254,7 +5502,7 @@ async function executeConditional(engine, params) {
|
|
|
5254
5502
|
abort: () => {
|
|
5255
5503
|
abortController?.abort();
|
|
5256
5504
|
},
|
|
5257
|
-
[
|
|
5505
|
+
[PUBSUB_SYMBOL]: pubsub,
|
|
5258
5506
|
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
5259
5507
|
engine: engine.getEngineContext(),
|
|
5260
5508
|
abortSignal: abortController?.signal,
|
|
@@ -5284,18 +5532,20 @@ async function executeConditional(engine, params) {
|
|
|
5284
5532
|
});
|
|
5285
5533
|
return result;
|
|
5286
5534
|
} catch (e) {
|
|
5287
|
-
const
|
|
5288
|
-
|
|
5535
|
+
const errorInstance = getErrorFromUnknown(e, { serializeStack: false });
|
|
5536
|
+
const mastraError = new MastraError(
|
|
5289
5537
|
{
|
|
5290
5538
|
id: "WORKFLOW_CONDITION_EVALUATION_FAILED",
|
|
5291
|
-
domain: "MASTRA_WORKFLOW"
|
|
5292
|
-
category: "USER"
|
|
5539
|
+
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
5540
|
+
category: "USER" /* USER */,
|
|
5293
5541
|
details: { workflowId, runId }
|
|
5294
5542
|
},
|
|
5295
|
-
|
|
5543
|
+
errorInstance
|
|
5296
5544
|
);
|
|
5545
|
+
engine.getLogger()?.trackException(mastraError);
|
|
5546
|
+
engine.getLogger()?.error("Error evaluating condition: " + errorInstance.stack);
|
|
5297
5547
|
evalSpan?.error({
|
|
5298
|
-
error,
|
|
5548
|
+
error: mastraError,
|
|
5299
5549
|
attributes: {
|
|
5300
5550
|
result: false
|
|
5301
5551
|
}
|
|
@@ -5347,7 +5597,7 @@ async function executeConditional(engine, params) {
|
|
|
5347
5597
|
tracingContext: {
|
|
5348
5598
|
currentSpan: conditionalSpan
|
|
5349
5599
|
},
|
|
5350
|
-
|
|
5600
|
+
pubsub,
|
|
5351
5601
|
abortController,
|
|
5352
5602
|
requestContext,
|
|
5353
5603
|
outputWriter,
|
|
@@ -5387,9 +5637,7 @@ async function executeConditional(engine, params) {
|
|
|
5387
5637
|
};
|
|
5388
5638
|
}
|
|
5389
5639
|
if (execResults.status === "failed") {
|
|
5390
|
-
conditionalSpan?.error({
|
|
5391
|
-
error: new Error(execResults.error)
|
|
5392
|
-
});
|
|
5640
|
+
conditionalSpan?.error({ error: execResults.error });
|
|
5393
5641
|
} else {
|
|
5394
5642
|
conditionalSpan?.end({
|
|
5395
5643
|
output: execResults.output || execResults
|
|
@@ -5410,7 +5658,7 @@ async function executeLoop(engine, params) {
|
|
|
5410
5658
|
timeTravel,
|
|
5411
5659
|
executionContext,
|
|
5412
5660
|
tracingContext,
|
|
5413
|
-
|
|
5661
|
+
pubsub,
|
|
5414
5662
|
abortController,
|
|
5415
5663
|
requestContext,
|
|
5416
5664
|
outputWriter,
|
|
@@ -5450,7 +5698,7 @@ async function executeLoop(engine, params) {
|
|
|
5450
5698
|
tracingContext: {
|
|
5451
5699
|
currentSpan: loopSpan
|
|
5452
5700
|
},
|
|
5453
|
-
|
|
5701
|
+
pubsub,
|
|
5454
5702
|
abortController,
|
|
5455
5703
|
requestContext,
|
|
5456
5704
|
outputWriter,
|
|
@@ -5504,7 +5752,7 @@ async function executeLoop(engine, params) {
|
|
|
5504
5752
|
abort: () => {
|
|
5505
5753
|
abortController?.abort();
|
|
5506
5754
|
},
|
|
5507
|
-
[
|
|
5755
|
+
[PUBSUB_SYMBOL]: pubsub,
|
|
5508
5756
|
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
5509
5757
|
engine: engine.getEngineContext(),
|
|
5510
5758
|
abortSignal: abortController?.signal,
|
|
@@ -5551,7 +5799,7 @@ async function executeForeach(engine, params) {
|
|
|
5551
5799
|
timeTravel,
|
|
5552
5800
|
executionContext,
|
|
5553
5801
|
tracingContext,
|
|
5554
|
-
|
|
5802
|
+
pubsub,
|
|
5555
5803
|
abortController,
|
|
5556
5804
|
requestContext,
|
|
5557
5805
|
outputWriter,
|
|
@@ -5579,12 +5827,16 @@ async function executeForeach(engine, params) {
|
|
|
5579
5827
|
},
|
|
5580
5828
|
tracingPolicy: engine.options?.tracingPolicy
|
|
5581
5829
|
});
|
|
5582
|
-
await
|
|
5583
|
-
type: "
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5830
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
5831
|
+
type: "watch",
|
|
5832
|
+
runId,
|
|
5833
|
+
data: {
|
|
5834
|
+
type: "workflow-step-start",
|
|
5835
|
+
payload: {
|
|
5836
|
+
id: step.id,
|
|
5837
|
+
...stepInfo,
|
|
5838
|
+
status: "running"
|
|
5839
|
+
}
|
|
5588
5840
|
}
|
|
5589
5841
|
});
|
|
5590
5842
|
const prevPayload = stepResults[step.id];
|
|
@@ -5623,7 +5875,7 @@ async function executeForeach(engine, params) {
|
|
|
5623
5875
|
resume: resumeToUse,
|
|
5624
5876
|
prevOutput: item,
|
|
5625
5877
|
tracingContext: { currentSpan: loopSpan },
|
|
5626
|
-
|
|
5878
|
+
pubsub,
|
|
5627
5879
|
abortController,
|
|
5628
5880
|
requestContext,
|
|
5629
5881
|
skipEmits: true,
|
|
@@ -5643,18 +5895,26 @@ async function executeForeach(engine, params) {
|
|
|
5643
5895
|
if (execResults.status === "suspended") {
|
|
5644
5896
|
foreachIndexObj[i + resultIndex] = execResults;
|
|
5645
5897
|
} else {
|
|
5646
|
-
await
|
|
5647
|
-
type: "
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5898
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
5899
|
+
type: "watch",
|
|
5900
|
+
runId,
|
|
5901
|
+
data: {
|
|
5902
|
+
type: "workflow-step-result",
|
|
5903
|
+
payload: {
|
|
5904
|
+
id: step.id,
|
|
5905
|
+
...execResults
|
|
5906
|
+
}
|
|
5651
5907
|
}
|
|
5652
5908
|
});
|
|
5653
|
-
await
|
|
5654
|
-
type: "
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5909
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
5910
|
+
type: "watch",
|
|
5911
|
+
runId,
|
|
5912
|
+
data: {
|
|
5913
|
+
type: "workflow-step-finish",
|
|
5914
|
+
payload: {
|
|
5915
|
+
id: step.id,
|
|
5916
|
+
metadata: {}
|
|
5917
|
+
}
|
|
5658
5918
|
}
|
|
5659
5919
|
});
|
|
5660
5920
|
return result;
|
|
@@ -5673,11 +5933,15 @@ async function executeForeach(engine, params) {
|
|
|
5673
5933
|
if (Object.keys(foreachIndexObj).length > 0) {
|
|
5674
5934
|
const suspendedIndices = Object.keys(foreachIndexObj).map(Number);
|
|
5675
5935
|
const foreachIndex = suspendedIndices[0];
|
|
5676
|
-
await
|
|
5677
|
-
type: "
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5936
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
5937
|
+
type: "watch",
|
|
5938
|
+
runId,
|
|
5939
|
+
data: {
|
|
5940
|
+
type: "workflow-step-suspended",
|
|
5941
|
+
payload: {
|
|
5942
|
+
id: step.id,
|
|
5943
|
+
...foreachIndexObj[foreachIndex]
|
|
5944
|
+
}
|
|
5681
5945
|
}
|
|
5682
5946
|
});
|
|
5683
5947
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
@@ -5699,20 +5963,28 @@ async function executeForeach(engine, params) {
|
|
|
5699
5963
|
};
|
|
5700
5964
|
}
|
|
5701
5965
|
}
|
|
5702
|
-
await
|
|
5703
|
-
type: "
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5966
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
5967
|
+
type: "watch",
|
|
5968
|
+
runId,
|
|
5969
|
+
data: {
|
|
5970
|
+
type: "workflow-step-result",
|
|
5971
|
+
payload: {
|
|
5972
|
+
id: step.id,
|
|
5973
|
+
status: "success",
|
|
5974
|
+
output: results,
|
|
5975
|
+
endedAt: Date.now()
|
|
5976
|
+
}
|
|
5709
5977
|
}
|
|
5710
5978
|
});
|
|
5711
|
-
await
|
|
5712
|
-
type: "
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
|
|
5979
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
5980
|
+
type: "watch",
|
|
5981
|
+
runId,
|
|
5982
|
+
data: {
|
|
5983
|
+
type: "workflow-step-finish",
|
|
5984
|
+
payload: {
|
|
5985
|
+
id: step.id,
|
|
5986
|
+
metadata: {}
|
|
5987
|
+
}
|
|
5716
5988
|
}
|
|
5717
5989
|
});
|
|
5718
5990
|
loopSpan?.end({
|
|
@@ -5789,7 +6061,7 @@ async function executeEntry(engine, params) {
|
|
|
5789
6061
|
resume,
|
|
5790
6062
|
executionContext,
|
|
5791
6063
|
tracingContext,
|
|
5792
|
-
|
|
6064
|
+
pubsub,
|
|
5793
6065
|
abortController,
|
|
5794
6066
|
requestContext,
|
|
5795
6067
|
outputWriter,
|
|
@@ -5812,7 +6084,7 @@ async function executeEntry(engine, params) {
|
|
|
5812
6084
|
resume,
|
|
5813
6085
|
prevOutput,
|
|
5814
6086
|
tracingContext,
|
|
5815
|
-
|
|
6087
|
+
pubsub,
|
|
5816
6088
|
abortController,
|
|
5817
6089
|
requestContext,
|
|
5818
6090
|
outputWriter,
|
|
@@ -5845,7 +6117,7 @@ async function executeEntry(engine, params) {
|
|
|
5845
6117
|
state: executionContext.state
|
|
5846
6118
|
},
|
|
5847
6119
|
tracingContext,
|
|
5848
|
-
|
|
6120
|
+
pubsub,
|
|
5849
6121
|
abortController,
|
|
5850
6122
|
requestContext,
|
|
5851
6123
|
outputWriter,
|
|
@@ -5915,7 +6187,7 @@ async function executeEntry(engine, params) {
|
|
|
5915
6187
|
resume,
|
|
5916
6188
|
executionContext,
|
|
5917
6189
|
tracingContext,
|
|
5918
|
-
|
|
6190
|
+
pubsub,
|
|
5919
6191
|
abortController,
|
|
5920
6192
|
requestContext,
|
|
5921
6193
|
outputWriter,
|
|
@@ -5934,7 +6206,7 @@ async function executeEntry(engine, params) {
|
|
|
5934
6206
|
resume,
|
|
5935
6207
|
executionContext,
|
|
5936
6208
|
tracingContext,
|
|
5937
|
-
|
|
6209
|
+
pubsub,
|
|
5938
6210
|
abortController,
|
|
5939
6211
|
requestContext,
|
|
5940
6212
|
outputWriter,
|
|
@@ -5953,7 +6225,7 @@ async function executeEntry(engine, params) {
|
|
|
5953
6225
|
resume,
|
|
5954
6226
|
executionContext,
|
|
5955
6227
|
tracingContext,
|
|
5956
|
-
|
|
6228
|
+
pubsub,
|
|
5957
6229
|
abortController,
|
|
5958
6230
|
requestContext,
|
|
5959
6231
|
outputWriter,
|
|
@@ -5973,7 +6245,7 @@ async function executeEntry(engine, params) {
|
|
|
5973
6245
|
resume,
|
|
5974
6246
|
executionContext,
|
|
5975
6247
|
tracingContext,
|
|
5976
|
-
|
|
6248
|
+
pubsub,
|
|
5977
6249
|
abortController,
|
|
5978
6250
|
requestContext,
|
|
5979
6251
|
outputWriter,
|
|
@@ -5984,13 +6256,17 @@ async function executeEntry(engine, params) {
|
|
|
5984
6256
|
const startedAt = Date.now();
|
|
5985
6257
|
const sleepWaitingOperationId = `workflow.${workflowId}.run.${runId}.sleep.${entry.id}.waiting_ev`;
|
|
5986
6258
|
await engine.wrapDurableOperation(sleepWaitingOperationId, async () => {
|
|
5987
|
-
await
|
|
5988
|
-
type: "
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
6259
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6260
|
+
type: "watch",
|
|
6261
|
+
runId,
|
|
6262
|
+
data: {
|
|
6263
|
+
type: "workflow-step-waiting",
|
|
6264
|
+
payload: {
|
|
6265
|
+
id: entry.id,
|
|
6266
|
+
payload: prevOutput,
|
|
6267
|
+
startedAt,
|
|
6268
|
+
status: "waiting"
|
|
6269
|
+
}
|
|
5994
6270
|
}
|
|
5995
6271
|
});
|
|
5996
6272
|
});
|
|
@@ -6021,7 +6297,7 @@ async function executeEntry(engine, params) {
|
|
|
6021
6297
|
resume,
|
|
6022
6298
|
executionContext,
|
|
6023
6299
|
tracingContext,
|
|
6024
|
-
|
|
6300
|
+
pubsub,
|
|
6025
6301
|
abortController,
|
|
6026
6302
|
requestContext,
|
|
6027
6303
|
outputWriter
|
|
@@ -6047,20 +6323,28 @@ async function executeEntry(engine, params) {
|
|
|
6047
6323
|
stepResults[entry.id] = { ...stepInfo, status: "success", output: prevOutput };
|
|
6048
6324
|
const sleepResultOperationId = `workflow.${workflowId}.run.${runId}.sleep.${entry.id}.result_ev`;
|
|
6049
6325
|
await engine.wrapDurableOperation(sleepResultOperationId, async () => {
|
|
6050
|
-
await
|
|
6051
|
-
type: "
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6326
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6327
|
+
type: "watch",
|
|
6328
|
+
runId,
|
|
6329
|
+
data: {
|
|
6330
|
+
type: "workflow-step-result",
|
|
6331
|
+
payload: {
|
|
6332
|
+
id: entry.id,
|
|
6333
|
+
endedAt,
|
|
6334
|
+
status: "success",
|
|
6335
|
+
output: prevOutput
|
|
6336
|
+
}
|
|
6057
6337
|
}
|
|
6058
6338
|
});
|
|
6059
|
-
await
|
|
6060
|
-
type: "
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6339
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6340
|
+
type: "watch",
|
|
6341
|
+
runId,
|
|
6342
|
+
data: {
|
|
6343
|
+
type: "workflow-step-finish",
|
|
6344
|
+
payload: {
|
|
6345
|
+
id: entry.id,
|
|
6346
|
+
metadata: {}
|
|
6347
|
+
}
|
|
6064
6348
|
}
|
|
6065
6349
|
});
|
|
6066
6350
|
});
|
|
@@ -6068,13 +6352,17 @@ async function executeEntry(engine, params) {
|
|
|
6068
6352
|
const startedAt = Date.now();
|
|
6069
6353
|
const sleepUntilWaitingOperationId = `workflow.${workflowId}.run.${runId}.sleepUntil.${entry.id}.waiting_ev`;
|
|
6070
6354
|
await engine.wrapDurableOperation(sleepUntilWaitingOperationId, async () => {
|
|
6071
|
-
await
|
|
6072
|
-
type: "
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6355
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6356
|
+
type: "watch",
|
|
6357
|
+
runId,
|
|
6358
|
+
data: {
|
|
6359
|
+
type: "workflow-step-waiting",
|
|
6360
|
+
payload: {
|
|
6361
|
+
id: entry.id,
|
|
6362
|
+
payload: prevOutput,
|
|
6363
|
+
startedAt,
|
|
6364
|
+
status: "waiting"
|
|
6365
|
+
}
|
|
6078
6366
|
}
|
|
6079
6367
|
});
|
|
6080
6368
|
});
|
|
@@ -6105,7 +6393,7 @@ async function executeEntry(engine, params) {
|
|
|
6105
6393
|
resume,
|
|
6106
6394
|
executionContext,
|
|
6107
6395
|
tracingContext,
|
|
6108
|
-
|
|
6396
|
+
pubsub,
|
|
6109
6397
|
abortController,
|
|
6110
6398
|
requestContext,
|
|
6111
6399
|
outputWriter
|
|
@@ -6131,20 +6419,28 @@ async function executeEntry(engine, params) {
|
|
|
6131
6419
|
stepResults[entry.id] = { ...stepInfo, status: "success", output: prevOutput };
|
|
6132
6420
|
const sleepUntilResultOperationId = `workflow.${workflowId}.run.${runId}.sleepUntil.${entry.id}.result_ev`;
|
|
6133
6421
|
await engine.wrapDurableOperation(sleepUntilResultOperationId, async () => {
|
|
6134
|
-
await
|
|
6135
|
-
type: "
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6422
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6423
|
+
type: "watch",
|
|
6424
|
+
runId,
|
|
6425
|
+
data: {
|
|
6426
|
+
type: "workflow-step-result",
|
|
6427
|
+
payload: {
|
|
6428
|
+
id: entry.id,
|
|
6429
|
+
endedAt,
|
|
6430
|
+
status: "success",
|
|
6431
|
+
output: prevOutput
|
|
6432
|
+
}
|
|
6141
6433
|
}
|
|
6142
6434
|
});
|
|
6143
|
-
await
|
|
6144
|
-
type: "
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6435
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6436
|
+
type: "watch",
|
|
6437
|
+
runId,
|
|
6438
|
+
data: {
|
|
6439
|
+
type: "workflow-step-finish",
|
|
6440
|
+
payload: {
|
|
6441
|
+
id: entry.id,
|
|
6442
|
+
metadata: {}
|
|
6443
|
+
}
|
|
6148
6444
|
}
|
|
6149
6445
|
});
|
|
6150
6446
|
});
|
|
@@ -6166,9 +6462,10 @@ async function executeEntry(engine, params) {
|
|
|
6166
6462
|
requestContext
|
|
6167
6463
|
});
|
|
6168
6464
|
if (execResults.status === "canceled") {
|
|
6169
|
-
await
|
|
6170
|
-
type: "
|
|
6171
|
-
|
|
6465
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6466
|
+
type: "watch",
|
|
6467
|
+
runId,
|
|
6468
|
+
data: { type: "workflow-canceled", payload: {} }
|
|
6172
6469
|
});
|
|
6173
6470
|
}
|
|
6174
6471
|
return {
|
|
@@ -6185,7 +6482,7 @@ async function executeSleep(engine, params) {
|
|
|
6185
6482
|
entry,
|
|
6186
6483
|
prevOutput,
|
|
6187
6484
|
stepResults,
|
|
6188
|
-
|
|
6485
|
+
pubsub,
|
|
6189
6486
|
abortController,
|
|
6190
6487
|
requestContext,
|
|
6191
6488
|
executionContext,
|
|
@@ -6229,7 +6526,7 @@ async function executeSleep(engine, params) {
|
|
|
6229
6526
|
abort: () => {
|
|
6230
6527
|
abortController?.abort();
|
|
6231
6528
|
},
|
|
6232
|
-
[
|
|
6529
|
+
[PUBSUB_SYMBOL]: pubsub,
|
|
6233
6530
|
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
6234
6531
|
engine: engine.getEngineContext(),
|
|
6235
6532
|
abortSignal: abortController?.signal,
|
|
@@ -6265,7 +6562,7 @@ async function executeSleepUntil(engine, params) {
|
|
|
6265
6562
|
entry,
|
|
6266
6563
|
prevOutput,
|
|
6267
6564
|
stepResults,
|
|
6268
|
-
|
|
6565
|
+
pubsub,
|
|
6269
6566
|
abortController,
|
|
6270
6567
|
requestContext,
|
|
6271
6568
|
executionContext,
|
|
@@ -6310,7 +6607,7 @@ async function executeSleepUntil(engine, params) {
|
|
|
6310
6607
|
abort: () => {
|
|
6311
6608
|
abortController?.abort();
|
|
6312
6609
|
},
|
|
6313
|
-
[
|
|
6610
|
+
[PUBSUB_SYMBOL]: pubsub,
|
|
6314
6611
|
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
6315
6612
|
engine: engine.getEngineContext(),
|
|
6316
6613
|
abortSignal: abortController?.signal,
|
|
@@ -6357,7 +6654,7 @@ async function executeStep(engine, params) {
|
|
|
6357
6654
|
resume,
|
|
6358
6655
|
timeTravel,
|
|
6359
6656
|
prevOutput,
|
|
6360
|
-
|
|
6657
|
+
pubsub,
|
|
6361
6658
|
abortController,
|
|
6362
6659
|
requestContext,
|
|
6363
6660
|
skipEmits = false,
|
|
@@ -6417,7 +6714,7 @@ async function executeStep(engine, params) {
|
|
|
6417
6714
|
await engine.onStepExecutionStart({
|
|
6418
6715
|
step,
|
|
6419
6716
|
inputData,
|
|
6420
|
-
|
|
6717
|
+
pubsub,
|
|
6421
6718
|
executionContext,
|
|
6422
6719
|
stepCallId,
|
|
6423
6720
|
stepInfo,
|
|
@@ -6446,7 +6743,7 @@ async function executeStep(engine, params) {
|
|
|
6446
6743
|
timeTravel,
|
|
6447
6744
|
prevOutput,
|
|
6448
6745
|
inputData,
|
|
6449
|
-
|
|
6746
|
+
pubsub,
|
|
6450
6747
|
startedAt: startTime ?? Date.now(),
|
|
6451
6748
|
abortController,
|
|
6452
6749
|
requestContext,
|
|
@@ -6568,7 +6865,7 @@ async function executeStep(engine, params) {
|
|
|
6568
6865
|
nestedStepResults: timeTravel?.nestedStepResults,
|
|
6569
6866
|
resumeData: timeTravel?.resumeData
|
|
6570
6867
|
} : void 0,
|
|
6571
|
-
[
|
|
6868
|
+
[PUBSUB_SYMBOL]: pubsub,
|
|
6572
6869
|
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
6573
6870
|
engine: engine.getEngineContext(),
|
|
6574
6871
|
abortSignal: abortController?.signal,
|
|
@@ -6640,7 +6937,8 @@ async function executeStep(engine, params) {
|
|
|
6640
6937
|
stepId: step.id,
|
|
6641
6938
|
stepCallId,
|
|
6642
6939
|
execResults: { ...stepInfo, ...execResults },
|
|
6643
|
-
|
|
6940
|
+
pubsub,
|
|
6941
|
+
runId
|
|
6644
6942
|
});
|
|
6645
6943
|
});
|
|
6646
6944
|
}
|
|
@@ -6671,9 +6969,9 @@ async function runScorersForStep(params) {
|
|
|
6671
6969
|
scorersToUse = await scorersToUse({
|
|
6672
6970
|
requestContext
|
|
6673
6971
|
});
|
|
6674
|
-
} catch (
|
|
6675
|
-
|
|
6676
|
-
|
|
6972
|
+
} catch (e) {
|
|
6973
|
+
const errorInstance = getErrorFromUnknown(e, { serializeStack: false });
|
|
6974
|
+
const mastraError = new MastraError(
|
|
6677
6975
|
{
|
|
6678
6976
|
id: "WORKFLOW_FAILED_TO_FETCH_SCORERS",
|
|
6679
6977
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
@@ -6684,8 +6982,10 @@ async function runScorersForStep(params) {
|
|
|
6684
6982
|
stepId
|
|
6685
6983
|
}
|
|
6686
6984
|
},
|
|
6687
|
-
|
|
6985
|
+
errorInstance
|
|
6688
6986
|
);
|
|
6987
|
+
engine.getLogger()?.trackException(mastraError);
|
|
6988
|
+
engine.getLogger()?.error("Error fetching scorers: " + errorInstance?.stack);
|
|
6689
6989
|
}
|
|
6690
6990
|
}
|
|
6691
6991
|
if (!disableScorers && scorersToUse && Object.keys(scorersToUse || {}).length > 0) {
|
|
@@ -6710,42 +7010,30 @@ async function runScorersForStep(params) {
|
|
|
6710
7010
|
}
|
|
6711
7011
|
}
|
|
6712
7012
|
async function emitStepResultEvents(params) {
|
|
6713
|
-
const { stepId, stepCallId, execResults,
|
|
7013
|
+
const { stepId, stepCallId, execResults, pubsub, runId } = params;
|
|
6714
7014
|
const payloadBase = stepCallId ? { id: stepId, stepCallId } : { id: stepId };
|
|
6715
7015
|
if (execResults.status === "suspended") {
|
|
6716
|
-
await
|
|
6717
|
-
type: "
|
|
6718
|
-
|
|
7016
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
7017
|
+
type: "watch",
|
|
7018
|
+
runId,
|
|
7019
|
+
data: { type: "workflow-step-suspended", payload: { ...payloadBase, ...execResults } }
|
|
6719
7020
|
});
|
|
6720
7021
|
} else {
|
|
6721
|
-
await
|
|
6722
|
-
type: "
|
|
6723
|
-
|
|
7022
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
7023
|
+
type: "watch",
|
|
7024
|
+
runId,
|
|
7025
|
+
data: { type: "workflow-step-result", payload: { ...payloadBase, ...execResults } }
|
|
6724
7026
|
});
|
|
6725
|
-
await
|
|
6726
|
-
type: "
|
|
6727
|
-
|
|
7027
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
7028
|
+
type: "watch",
|
|
7029
|
+
runId,
|
|
7030
|
+
data: { type: "workflow-step-finish", payload: { ...payloadBase, metadata: {} } }
|
|
6728
7031
|
});
|
|
6729
7032
|
}
|
|
6730
7033
|
}
|
|
6731
7034
|
|
|
6732
7035
|
// src/workflows/default.ts
|
|
6733
7036
|
var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
6734
|
-
/**
|
|
6735
|
-
* Preprocesses an error caught during workflow execution.
|
|
6736
|
-
*
|
|
6737
|
-
* - Wraps a non-MastraError exception
|
|
6738
|
-
* - Logs error details
|
|
6739
|
-
*/
|
|
6740
|
-
preprocessExecutionError(e, errorDefinition, logPrefix) {
|
|
6741
|
-
const error = e instanceof MastraError ? e : new MastraError(errorDefinition, e);
|
|
6742
|
-
if (!(e instanceof MastraError) && e instanceof Error && e.stack) {
|
|
6743
|
-
error.stack = e.stack;
|
|
6744
|
-
}
|
|
6745
|
-
this.logger?.trackException(error);
|
|
6746
|
-
this.logger?.error(logPrefix + error?.stack);
|
|
6747
|
-
return error;
|
|
6748
|
-
}
|
|
6749
7037
|
/**
|
|
6750
7038
|
* The retryCounts map is used to keep track of the retry count for each step.
|
|
6751
7039
|
* The step id is used as the key and the retry count is the value.
|
|
@@ -6852,12 +7140,16 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
6852
7140
|
return this.wrapDurableOperation(params.operationId, async () => {
|
|
6853
7141
|
const startedAt = Date.now();
|
|
6854
7142
|
if (!params.skipEmits) {
|
|
6855
|
-
await params.
|
|
6856
|
-
type: "
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
7143
|
+
await params.pubsub.publish(`workflow.events.v2.${params.executionContext.runId}`, {
|
|
7144
|
+
type: "watch",
|
|
7145
|
+
runId: params.executionContext.runId,
|
|
7146
|
+
data: {
|
|
7147
|
+
type: "workflow-step-start",
|
|
7148
|
+
payload: {
|
|
7149
|
+
id: params.step.id,
|
|
7150
|
+
stepCallId: params.stepCallId,
|
|
7151
|
+
...params.stepInfo
|
|
7152
|
+
}
|
|
6861
7153
|
}
|
|
6862
7154
|
});
|
|
6863
7155
|
}
|
|
@@ -6897,29 +7189,30 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
6897
7189
|
return { ok: true, result };
|
|
6898
7190
|
} catch (e) {
|
|
6899
7191
|
if (i === params.retries) {
|
|
6900
|
-
const
|
|
6901
|
-
|
|
7192
|
+
const errorInstance = getErrorFromUnknown(e, {
|
|
7193
|
+
serializeStack: false,
|
|
7194
|
+
fallbackMessage: "Unknown step execution error"
|
|
7195
|
+
});
|
|
7196
|
+
const mastraError = new MastraError(
|
|
6902
7197
|
{
|
|
6903
7198
|
id: "WORKFLOW_STEP_INVOKE_FAILED",
|
|
6904
7199
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
6905
7200
|
category: "USER" /* USER */,
|
|
6906
7201
|
details: { workflowId: params.workflowId, runId: params.runId, stepId }
|
|
6907
7202
|
},
|
|
6908
|
-
|
|
7203
|
+
errorInstance
|
|
6909
7204
|
);
|
|
7205
|
+
this.logger?.trackException(mastraError);
|
|
7206
|
+
this.logger?.error(`Error executing step ${stepId}: ` + errorInstance?.stack);
|
|
6910
7207
|
params.stepSpan?.error({
|
|
6911
|
-
error:
|
|
7208
|
+
error: mastraError,
|
|
6912
7209
|
attributes: { status: "failed" }
|
|
6913
7210
|
});
|
|
6914
|
-
const errorInstance = getErrorFromUnknown(processedError, {
|
|
6915
|
-
includeStack: false,
|
|
6916
|
-
fallbackMessage: "Unknown step execution error"
|
|
6917
|
-
});
|
|
6918
7211
|
return {
|
|
6919
7212
|
ok: false,
|
|
6920
7213
|
error: {
|
|
6921
7214
|
status: "failed",
|
|
6922
|
-
error:
|
|
7215
|
+
error: errorInstance,
|
|
6923
7216
|
endedAt: Date.now(),
|
|
6924
7217
|
// Preserve TripWire data as plain object for proper serialization
|
|
6925
7218
|
tripwire: e instanceof TripWire ? {
|
|
@@ -6933,7 +7226,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
6933
7226
|
}
|
|
6934
7227
|
}
|
|
6935
7228
|
}
|
|
6936
|
-
return { ok: false, error: { status: "failed", error: "Unknown error", endedAt: Date.now() } };
|
|
7229
|
+
return { ok: false, error: { status: "failed", error: new Error("Unknown error"), endedAt: Date.now() } };
|
|
6937
7230
|
}
|
|
6938
7231
|
/**
|
|
6939
7232
|
* Format an error for the workflow result.
|
|
@@ -6943,12 +7236,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
6943
7236
|
const outputError = lastOutput?.error;
|
|
6944
7237
|
const errorSource = error || outputError;
|
|
6945
7238
|
const errorInstance = getErrorFromUnknown(errorSource, {
|
|
6946
|
-
|
|
7239
|
+
serializeStack: false,
|
|
6947
7240
|
fallbackMessage: "Unknown workflow error"
|
|
6948
7241
|
});
|
|
6949
|
-
return
|
|
7242
|
+
return errorInstance.toJSON();
|
|
6950
7243
|
}
|
|
6951
|
-
async fmtReturnValue(
|
|
7244
|
+
async fmtReturnValue(_pubsub, stepResults, lastOutput, error) {
|
|
6952
7245
|
const base = {
|
|
6953
7246
|
status: lastOutput.status,
|
|
6954
7247
|
steps: stepResults,
|
|
@@ -6973,14 +7266,18 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
6973
7266
|
base.error = this.formatResultError(error, lastOutput);
|
|
6974
7267
|
}
|
|
6975
7268
|
} else if (lastOutput.status === "suspended") {
|
|
7269
|
+
const suspendPayload = {};
|
|
6976
7270
|
const suspendedStepIds = Object.entries(stepResults).flatMap(([stepId, stepResult]) => {
|
|
6977
7271
|
if (stepResult?.status === "suspended") {
|
|
6978
|
-
const
|
|
7272
|
+
const { __workflow_meta, ...rest } = stepResult?.suspendPayload ?? {};
|
|
7273
|
+
suspendPayload[stepId] = rest;
|
|
7274
|
+
const nestedPath = __workflow_meta?.path;
|
|
6979
7275
|
return nestedPath ? [[stepId, ...nestedPath]] : [[stepId]];
|
|
6980
7276
|
}
|
|
6981
7277
|
return [];
|
|
6982
7278
|
});
|
|
6983
7279
|
base.suspended = suspendedStepIds;
|
|
7280
|
+
base.suspendPayload = suspendPayload;
|
|
6984
7281
|
}
|
|
6985
7282
|
return base;
|
|
6986
7283
|
}
|
|
@@ -7112,7 +7409,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7112
7409
|
currentSpan: workflowSpan
|
|
7113
7410
|
},
|
|
7114
7411
|
abortController: params.abortController,
|
|
7115
|
-
|
|
7412
|
+
pubsub: params.pubsub,
|
|
7116
7413
|
requestContext: currentRequestContext,
|
|
7117
7414
|
outputWriter: params.outputWriter,
|
|
7118
7415
|
disableScorers
|
|
@@ -7126,7 +7423,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7126
7423
|
if (lastOutput.result.status === "bailed") {
|
|
7127
7424
|
lastOutput.result.status = "success";
|
|
7128
7425
|
}
|
|
7129
|
-
const result2 = await this.fmtReturnValue(params.
|
|
7426
|
+
const result2 = await this.fmtReturnValue(params.pubsub, stepResults, lastOutput.result);
|
|
7130
7427
|
await this.persistStepUpdate({
|
|
7131
7428
|
workflowId,
|
|
7132
7429
|
runId,
|
|
@@ -7154,6 +7451,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7154
7451
|
}
|
|
7155
7452
|
});
|
|
7156
7453
|
}
|
|
7454
|
+
await this.invokeLifecycleCallbacks(result2);
|
|
7157
7455
|
return {
|
|
7158
7456
|
...result2,
|
|
7159
7457
|
...lastOutput.result.status === "suspended" && params.outputOptions?.includeResumeLabels ? { resumeLabels: lastOutput.mutableContext.resumeLabels } : {},
|
|
@@ -7161,7 +7459,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7161
7459
|
};
|
|
7162
7460
|
}
|
|
7163
7461
|
}
|
|
7164
|
-
const result = await this.fmtReturnValue(params.
|
|
7462
|
+
const result = await this.fmtReturnValue(params.pubsub, stepResults, lastOutput.result);
|
|
7165
7463
|
await this.persistStepUpdate({
|
|
7166
7464
|
workflowId,
|
|
7167
7465
|
runId,
|
|
@@ -7180,6 +7478,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7180
7478
|
status: result.status
|
|
7181
7479
|
}
|
|
7182
7480
|
});
|
|
7481
|
+
await this.invokeLifecycleCallbacks(result);
|
|
7183
7482
|
if (params.outputOptions?.includeState) {
|
|
7184
7483
|
return { ...result, state: lastState };
|
|
7185
7484
|
}
|
|
@@ -7255,7 +7554,8 @@ function createStep(params, agentOptions) {
|
|
|
7255
7554
|
outputSchema,
|
|
7256
7555
|
execute: async ({
|
|
7257
7556
|
inputData,
|
|
7258
|
-
|
|
7557
|
+
runId,
|
|
7558
|
+
[PUBSUB_SYMBOL]: pubsub,
|
|
7259
7559
|
[STREAM_FORMAT_SYMBOL]: streamFormat,
|
|
7260
7560
|
requestContext,
|
|
7261
7561
|
tracingContext,
|
|
@@ -7311,9 +7611,10 @@ function createStep(params, agentOptions) {
|
|
|
7311
7611
|
}
|
|
7312
7612
|
let tripwireChunk = null;
|
|
7313
7613
|
if (streamFormat === "legacy") {
|
|
7314
|
-
await
|
|
7315
|
-
type: "
|
|
7316
|
-
|
|
7614
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
7615
|
+
type: "watch",
|
|
7616
|
+
runId,
|
|
7617
|
+
data: { type: "tool-call-streaming-start", ...toolData ?? {} }
|
|
7317
7618
|
});
|
|
7318
7619
|
for await (const chunk of stream) {
|
|
7319
7620
|
if (chunk.type === "tripwire") {
|
|
@@ -7321,16 +7622,17 @@ function createStep(params, agentOptions) {
|
|
|
7321
7622
|
break;
|
|
7322
7623
|
}
|
|
7323
7624
|
if (chunk.type === "text-delta") {
|
|
7324
|
-
await
|
|
7325
|
-
type: "
|
|
7326
|
-
|
|
7327
|
-
argsTextDelta: chunk.textDelta
|
|
7625
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
7626
|
+
type: "watch",
|
|
7627
|
+
runId,
|
|
7628
|
+
data: { type: "tool-call-delta", ...toolData ?? {}, argsTextDelta: chunk.textDelta }
|
|
7328
7629
|
});
|
|
7329
7630
|
}
|
|
7330
7631
|
}
|
|
7331
|
-
await
|
|
7332
|
-
type: "
|
|
7333
|
-
|
|
7632
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
7633
|
+
type: "watch",
|
|
7634
|
+
runId,
|
|
7635
|
+
data: { type: "tool-call-streaming-finish", ...toolData ?? {} }
|
|
7334
7636
|
});
|
|
7335
7637
|
} else {
|
|
7336
7638
|
for await (const chunk of stream) {
|
|
@@ -7840,7 +8142,9 @@ var Workflow = class extends MastraBase {
|
|
|
7840
8142
|
this.#options = {
|
|
7841
8143
|
validateInputs: options.validateInputs ?? true,
|
|
7842
8144
|
shouldPersistSnapshot: options.shouldPersistSnapshot ?? (() => true),
|
|
7843
|
-
tracingPolicy: options.tracingPolicy
|
|
8145
|
+
tracingPolicy: options.tracingPolicy,
|
|
8146
|
+
onFinish: options.onFinish,
|
|
8147
|
+
onError: options.onError
|
|
7844
8148
|
};
|
|
7845
8149
|
if (!executionEngine) {
|
|
7846
8150
|
this.executionEngine = new DefaultExecutionEngine({
|
|
@@ -7960,7 +8264,7 @@ var Workflow = class extends MastraBase {
|
|
|
7960
8264
|
type: "step",
|
|
7961
8265
|
step: {
|
|
7962
8266
|
id: mappingStep2.id,
|
|
7963
|
-
mapConfig: mappingConfig.toString()
|
|
8267
|
+
mapConfig: mappingConfig.toString()?.length > 1e3 ? mappingConfig.toString().slice(0, 1e3) + "...\n}" : mappingConfig.toString()
|
|
7964
8268
|
}
|
|
7965
8269
|
});
|
|
7966
8270
|
return this;
|
|
@@ -8032,7 +8336,7 @@ var Workflow = class extends MastraBase {
|
|
|
8032
8336
|
type: "step",
|
|
8033
8337
|
step: {
|
|
8034
8338
|
id: mappingStep.id,
|
|
8035
|
-
mapConfig: JSON.stringify(newMappingConfig, null, 2)
|
|
8339
|
+
mapConfig: JSON.stringify(newMappingConfig, null, 2)?.length > 1e3 ? JSON.stringify(newMappingConfig, null, 2).slice(0, 1e3) + "...\n}" : JSON.stringify(newMappingConfig, null, 2)
|
|
8036
8340
|
}
|
|
8037
8341
|
});
|
|
8038
8342
|
return this;
|
|
@@ -8219,7 +8523,9 @@ var Workflow = class extends MastraBase {
|
|
|
8219
8523
|
workflowStatus: run.workflowRunStatus,
|
|
8220
8524
|
stepResults: {}
|
|
8221
8525
|
});
|
|
8222
|
-
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse,
|
|
8526
|
+
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, {
|
|
8527
|
+
withNestedWorkflows: false
|
|
8528
|
+
});
|
|
8223
8529
|
if (workflowSnapshotInStorage && workflowSnapshotInStorage.status) {
|
|
8224
8530
|
run.workflowRunStatus = workflowSnapshotInStorage.status;
|
|
8225
8531
|
}
|
|
@@ -8281,7 +8587,7 @@ var Workflow = class extends MastraBase {
|
|
|
8281
8587
|
restart,
|
|
8282
8588
|
resume,
|
|
8283
8589
|
timeTravel,
|
|
8284
|
-
[
|
|
8590
|
+
[PUBSUB_SYMBOL]: pubsub,
|
|
8285
8591
|
mastra,
|
|
8286
8592
|
requestContext,
|
|
8287
8593
|
abort,
|
|
@@ -8316,7 +8622,11 @@ var Workflow = class extends MastraBase {
|
|
|
8316
8622
|
await run.cancel();
|
|
8317
8623
|
});
|
|
8318
8624
|
const unwatch = run.watch((event) => {
|
|
8319
|
-
|
|
8625
|
+
void pubsub.publish("nested-watch", {
|
|
8626
|
+
type: "nested-watch",
|
|
8627
|
+
runId: run.runId,
|
|
8628
|
+
data: { event, workflowId: this.id }
|
|
8629
|
+
});
|
|
8320
8630
|
});
|
|
8321
8631
|
if (retryCount && retryCount > 0 && isResume && requestContext) {
|
|
8322
8632
|
requestContext.set("__mastraWorflowInputData", inputData);
|
|
@@ -8480,7 +8790,8 @@ var Workflow = class extends MastraBase {
|
|
|
8480
8790
|
}
|
|
8481
8791
|
return finalSteps;
|
|
8482
8792
|
}
|
|
8483
|
-
async getWorkflowRunExecutionResult(runId,
|
|
8793
|
+
async getWorkflowRunExecutionResult(runId, options = {}) {
|
|
8794
|
+
const { withNestedWorkflows = true, fields } = options;
|
|
8484
8795
|
const storage = this.#mastra?.getStorage();
|
|
8485
8796
|
if (!storage) {
|
|
8486
8797
|
this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
|
|
@@ -8499,21 +8810,57 @@ var Workflow = class extends MastraBase {
|
|
|
8499
8810
|
return null;
|
|
8500
8811
|
}
|
|
8501
8812
|
}
|
|
8502
|
-
const
|
|
8813
|
+
const snapshotState = snapshot;
|
|
8814
|
+
const defaultResult = {
|
|
8815
|
+
status: snapshotState.status,
|
|
8816
|
+
result: snapshotState.result,
|
|
8817
|
+
error: snapshotState.error,
|
|
8818
|
+
payload: snapshotState.context?.input,
|
|
8819
|
+
steps: null,
|
|
8820
|
+
// Will be populated below
|
|
8821
|
+
activeStepsPath: snapshotState.activeStepsPath,
|
|
8822
|
+
serializedStepGraph: snapshotState.serializedStepGraph
|
|
8823
|
+
};
|
|
8824
|
+
const allowedFields = new Set(Object.keys(defaultResult));
|
|
8825
|
+
if (fields && fields.length > 0) {
|
|
8826
|
+
const result = {};
|
|
8827
|
+
for (const field of fields) {
|
|
8828
|
+
if (!allowedFields.has(field)) {
|
|
8829
|
+
continue;
|
|
8830
|
+
}
|
|
8831
|
+
if (field === "steps") {
|
|
8832
|
+
let fullSteps2;
|
|
8833
|
+
if (withNestedWorkflows) {
|
|
8834
|
+
fullSteps2 = await this.getWorkflowRunSteps({ runId, workflowId: this.id });
|
|
8835
|
+
} else {
|
|
8836
|
+
const { input, ...stepsOnly } = snapshotState.context || {};
|
|
8837
|
+
fullSteps2 = stepsOnly;
|
|
8838
|
+
}
|
|
8839
|
+
result.steps = fullSteps2;
|
|
8840
|
+
} else if (field === "payload") {
|
|
8841
|
+
result.payload = snapshotState.context?.input;
|
|
8842
|
+
} else {
|
|
8843
|
+
result[field] = snapshotState[field];
|
|
8844
|
+
}
|
|
8845
|
+
}
|
|
8846
|
+
return result;
|
|
8847
|
+
}
|
|
8848
|
+
let fullSteps;
|
|
8849
|
+
if (withNestedWorkflows) {
|
|
8850
|
+
fullSteps = await this.getWorkflowRunSteps({ runId, workflowId: this.id });
|
|
8851
|
+
} else {
|
|
8852
|
+
const { input, ...stepsOnly } = snapshotState.context || {};
|
|
8853
|
+
fullSteps = stepsOnly;
|
|
8854
|
+
}
|
|
8503
8855
|
return {
|
|
8504
|
-
|
|
8505
|
-
|
|
8506
|
-
error: snapshot.error,
|
|
8507
|
-
payload: snapshot.context?.input,
|
|
8508
|
-
steps: fullSteps,
|
|
8509
|
-
activeStepsPath: snapshot.activeStepsPath,
|
|
8510
|
-
serializedStepGraph: snapshot.serializedStepGraph
|
|
8856
|
+
...defaultResult,
|
|
8857
|
+
steps: fullSteps
|
|
8511
8858
|
};
|
|
8512
8859
|
}
|
|
8513
8860
|
};
|
|
8514
8861
|
var Run = class {
|
|
8515
8862
|
#abortController;
|
|
8516
|
-
|
|
8863
|
+
pubsub;
|
|
8517
8864
|
/**
|
|
8518
8865
|
* Unique identifier for this workflow
|
|
8519
8866
|
*/
|
|
@@ -8583,7 +8930,7 @@ var Run = class {
|
|
|
8583
8930
|
this.executionEngine = params.executionEngine;
|
|
8584
8931
|
this.executionGraph = params.executionGraph;
|
|
8585
8932
|
this.#mastra = params.mastra;
|
|
8586
|
-
this.
|
|
8933
|
+
this.pubsub = new EventEmitterPubSub();
|
|
8587
8934
|
this.retryConfig = params.retryConfig;
|
|
8588
8935
|
this.cleanup = params.cleanup;
|
|
8589
8936
|
this.disableScorers = params.disableScorers;
|
|
@@ -8602,10 +8949,22 @@ var Run = class {
|
|
|
8602
8949
|
return this.#abortController;
|
|
8603
8950
|
}
|
|
8604
8951
|
/**
|
|
8605
|
-
* Cancels the workflow execution
|
|
8952
|
+
* Cancels the workflow execution.
|
|
8953
|
+
* This aborts any running execution and updates the workflow status to 'canceled' in storage.
|
|
8606
8954
|
*/
|
|
8607
8955
|
async cancel() {
|
|
8608
|
-
this.abortController
|
|
8956
|
+
this.abortController.abort();
|
|
8957
|
+
this.workflowRunStatus = "canceled";
|
|
8958
|
+
try {
|
|
8959
|
+
await this.mastra?.getStorage()?.updateWorkflowState({
|
|
8960
|
+
workflowName: this.workflowId,
|
|
8961
|
+
runId: this.runId,
|
|
8962
|
+
opts: {
|
|
8963
|
+
status: "canceled"
|
|
8964
|
+
}
|
|
8965
|
+
});
|
|
8966
|
+
} catch {
|
|
8967
|
+
}
|
|
8609
8968
|
}
|
|
8610
8969
|
async _validateInput(inputData) {
|
|
8611
8970
|
let inputDataToUse = inputData;
|
|
@@ -8706,20 +9065,7 @@ var Run = class {
|
|
|
8706
9065
|
serializedStepGraph: this.serializedStepGraph,
|
|
8707
9066
|
input: inputDataToUse,
|
|
8708
9067
|
initialState: initialStateToUse,
|
|
8709
|
-
|
|
8710
|
-
emit: async (event, data) => {
|
|
8711
|
-
this.emitter.emit(event, data);
|
|
8712
|
-
},
|
|
8713
|
-
on: (event, callback) => {
|
|
8714
|
-
this.emitter.on(event, callback);
|
|
8715
|
-
},
|
|
8716
|
-
off: (event, callback) => {
|
|
8717
|
-
this.emitter.off(event, callback);
|
|
8718
|
-
},
|
|
8719
|
-
once: (event, callback) => {
|
|
8720
|
-
this.emitter.once(event, callback);
|
|
8721
|
-
}
|
|
8722
|
-
},
|
|
9068
|
+
pubsub: this.pubsub,
|
|
8723
9069
|
retryConfig: this.retryConfig,
|
|
8724
9070
|
requestContext: requestContext ?? new RequestContext(),
|
|
8725
9071
|
abortController: this.abortController,
|
|
@@ -8742,6 +9088,19 @@ var Run = class {
|
|
|
8742
9088
|
async start(args) {
|
|
8743
9089
|
return this._start(args);
|
|
8744
9090
|
}
|
|
9091
|
+
/**
|
|
9092
|
+
* Starts the workflow execution without waiting for completion (fire-and-forget).
|
|
9093
|
+
* Returns immediately with the runId. The workflow executes in the background.
|
|
9094
|
+
* Use this when you don't need to wait for the result or want to avoid polling failures.
|
|
9095
|
+
* @param args The input data and configuration for the workflow
|
|
9096
|
+
* @returns A promise that resolves immediately with the runId
|
|
9097
|
+
*/
|
|
9098
|
+
async startAsync(args) {
|
|
9099
|
+
this._start(args).catch((err) => {
|
|
9100
|
+
console.error(`[Workflow ${this.workflowId}] Background execution failed:`, err);
|
|
9101
|
+
});
|
|
9102
|
+
return { runId: this.runId };
|
|
9103
|
+
}
|
|
8745
9104
|
/**
|
|
8746
9105
|
* Starts the workflow execution with the provided input as a stream
|
|
8747
9106
|
* @param input The input data for the workflow
|
|
@@ -8776,9 +9135,10 @@ var Run = class {
|
|
|
8776
9135
|
}
|
|
8777
9136
|
});
|
|
8778
9137
|
this.closeStreamAction = async () => {
|
|
8779
|
-
this.
|
|
8780
|
-
type: "
|
|
8781
|
-
|
|
9138
|
+
await this.pubsub.publish(`workflow.events.v2.${this.runId}`, {
|
|
9139
|
+
type: "watch",
|
|
9140
|
+
runId: this.runId,
|
|
9141
|
+
data: { type: "workflow-finish", payload: { runId: this.runId } }
|
|
8782
9142
|
});
|
|
8783
9143
|
unwatch();
|
|
8784
9144
|
await Promise.all(this.#observerHandlers.map((handler) => handler()));
|
|
@@ -8791,9 +9151,10 @@ var Run = class {
|
|
|
8791
9151
|
writer.releaseLock();
|
|
8792
9152
|
}
|
|
8793
9153
|
};
|
|
8794
|
-
this.
|
|
8795
|
-
type: "
|
|
8796
|
-
|
|
9154
|
+
void this.pubsub.publish(`workflow.events.v2.${this.runId}`, {
|
|
9155
|
+
type: "watch",
|
|
9156
|
+
runId: this.runId,
|
|
9157
|
+
data: { type: "workflow-start", payload: { runId: this.runId } }
|
|
8797
9158
|
});
|
|
8798
9159
|
this.executionResults = this._start({
|
|
8799
9160
|
inputData,
|
|
@@ -8929,7 +9290,9 @@ var Run = class {
|
|
|
8929
9290
|
self.closeStreamAction = async () => {
|
|
8930
9291
|
unwatch();
|
|
8931
9292
|
try {
|
|
8932
|
-
|
|
9293
|
+
if (controller.desiredSize !== null) {
|
|
9294
|
+
controller.close();
|
|
9295
|
+
}
|
|
8933
9296
|
} catch (err) {
|
|
8934
9297
|
console.error("Error closing stream:", err);
|
|
8935
9298
|
}
|
|
@@ -8942,7 +9305,11 @@ var Run = class {
|
|
|
8942
9305
|
initialState,
|
|
8943
9306
|
outputOptions,
|
|
8944
9307
|
outputWriter: async (chunk) => {
|
|
8945
|
-
void self.
|
|
9308
|
+
void self.pubsub.publish(`workflow.events.v2.${self.runId}`, {
|
|
9309
|
+
type: "watch",
|
|
9310
|
+
runId: self.runId,
|
|
9311
|
+
data: chunk
|
|
9312
|
+
});
|
|
8946
9313
|
}
|
|
8947
9314
|
});
|
|
8948
9315
|
let executionResults;
|
|
@@ -9040,7 +9407,9 @@ var Run = class {
|
|
|
9040
9407
|
self.closeStreamAction = async () => {
|
|
9041
9408
|
unwatch();
|
|
9042
9409
|
try {
|
|
9043
|
-
|
|
9410
|
+
if (controller.desiredSize !== null) {
|
|
9411
|
+
controller.close();
|
|
9412
|
+
}
|
|
9044
9413
|
} catch (err) {
|
|
9045
9414
|
console.error("Error closing stream:", err);
|
|
9046
9415
|
}
|
|
@@ -9085,20 +9454,29 @@ var Run = class {
|
|
|
9085
9454
|
* @internal
|
|
9086
9455
|
*/
|
|
9087
9456
|
watch(cb) {
|
|
9088
|
-
const
|
|
9089
|
-
event
|
|
9090
|
-
|
|
9091
|
-
|
|
9092
|
-
this.emitter.emit("watch", {
|
|
9093
|
-
...event,
|
|
9094
|
-
...event.payload?.id ? { payload: { ...event.payload, id: `${workflowId}.${event.payload.id}` } } : {}
|
|
9095
|
-
});
|
|
9457
|
+
const wrappedCb = (event) => {
|
|
9458
|
+
if (event.runId === this.runId) {
|
|
9459
|
+
cb(event.data);
|
|
9460
|
+
}
|
|
9096
9461
|
};
|
|
9097
|
-
|
|
9098
|
-
|
|
9462
|
+
const nestedWatchCb = (event) => {
|
|
9463
|
+
if (event.runId === this.runId) {
|
|
9464
|
+
const { event: nestedEvent, workflowId } = event.data;
|
|
9465
|
+
void this.pubsub.publish(`workflow.events.v2.${this.runId}`, {
|
|
9466
|
+
type: "watch",
|
|
9467
|
+
runId: this.runId,
|
|
9468
|
+
data: {
|
|
9469
|
+
...nestedEvent,
|
|
9470
|
+
...nestedEvent.payload?.id ? { payload: { ...nestedEvent.payload, id: `${workflowId}.${nestedEvent.payload.id}` } } : {}
|
|
9471
|
+
}
|
|
9472
|
+
});
|
|
9473
|
+
}
|
|
9474
|
+
};
|
|
9475
|
+
void this.pubsub.subscribe(`workflow.events.v2.${this.runId}`, wrappedCb);
|
|
9476
|
+
void this.pubsub.subscribe("nested-watch", nestedWatchCb);
|
|
9099
9477
|
return () => {
|
|
9100
|
-
this.
|
|
9101
|
-
this.
|
|
9478
|
+
void this.pubsub.unsubscribe(`workflow.events.v2.${this.runId}`, wrappedCb);
|
|
9479
|
+
void this.pubsub.unsubscribe("nested-watch", nestedWatchCb);
|
|
9102
9480
|
};
|
|
9103
9481
|
}
|
|
9104
9482
|
/**
|
|
@@ -9226,21 +9604,7 @@ var Run = class {
|
|
|
9226
9604
|
label: params.label
|
|
9227
9605
|
},
|
|
9228
9606
|
format: params.format,
|
|
9229
|
-
|
|
9230
|
-
emit: (event, data) => {
|
|
9231
|
-
this.emitter.emit(event, data);
|
|
9232
|
-
return Promise.resolve();
|
|
9233
|
-
},
|
|
9234
|
-
on: (event, callback) => {
|
|
9235
|
-
this.emitter.on(event, callback);
|
|
9236
|
-
},
|
|
9237
|
-
off: (event, callback) => {
|
|
9238
|
-
this.emitter.off(event, callback);
|
|
9239
|
-
},
|
|
9240
|
-
once: (event, callback) => {
|
|
9241
|
-
this.emitter.once(event, callback);
|
|
9242
|
-
}
|
|
9243
|
-
},
|
|
9607
|
+
pubsub: this.pubsub,
|
|
9244
9608
|
requestContext: requestContextToUse,
|
|
9245
9609
|
abortController: this.abortController,
|
|
9246
9610
|
workflowSpan,
|
|
@@ -9340,20 +9704,7 @@ var Run = class {
|
|
|
9340
9704
|
graph: this.executionGraph,
|
|
9341
9705
|
serializedStepGraph: this.serializedStepGraph,
|
|
9342
9706
|
restart: restartData,
|
|
9343
|
-
|
|
9344
|
-
emit: async (event, data) => {
|
|
9345
|
-
this.emitter.emit(event, data);
|
|
9346
|
-
},
|
|
9347
|
-
on: (event, callback) => {
|
|
9348
|
-
this.emitter.on(event, callback);
|
|
9349
|
-
},
|
|
9350
|
-
off: (event, callback) => {
|
|
9351
|
-
this.emitter.off(event, callback);
|
|
9352
|
-
},
|
|
9353
|
-
once: (event, callback) => {
|
|
9354
|
-
this.emitter.once(event, callback);
|
|
9355
|
-
}
|
|
9356
|
-
},
|
|
9707
|
+
pubsub: this.pubsub,
|
|
9357
9708
|
retryConfig: this.retryConfig,
|
|
9358
9709
|
requestContext: requestContextToUse,
|
|
9359
9710
|
abortController: this.abortController,
|
|
@@ -9446,20 +9797,7 @@ var Run = class {
|
|
|
9446
9797
|
graph: this.executionGraph,
|
|
9447
9798
|
timeTravel: timeTravelData,
|
|
9448
9799
|
serializedStepGraph: this.serializedStepGraph,
|
|
9449
|
-
|
|
9450
|
-
emit: async (event, data) => {
|
|
9451
|
-
this.emitter.emit(event, data);
|
|
9452
|
-
},
|
|
9453
|
-
on: (event, callback) => {
|
|
9454
|
-
this.emitter.on(event, callback);
|
|
9455
|
-
},
|
|
9456
|
-
off: (event, callback) => {
|
|
9457
|
-
this.emitter.off(event, callback);
|
|
9458
|
-
},
|
|
9459
|
-
once: (event, callback) => {
|
|
9460
|
-
this.emitter.once(event, callback);
|
|
9461
|
-
}
|
|
9462
|
-
},
|
|
9800
|
+
pubsub: this.pubsub,
|
|
9463
9801
|
retryConfig: this.retryConfig,
|
|
9464
9802
|
requestContext: requestContextToUse,
|
|
9465
9803
|
abortController: this.abortController,
|
|
@@ -9507,7 +9845,9 @@ var Run = class {
|
|
|
9507
9845
|
self.closeStreamAction = async () => {
|
|
9508
9846
|
unwatch();
|
|
9509
9847
|
try {
|
|
9510
|
-
|
|
9848
|
+
if (controller.desiredSize !== null) {
|
|
9849
|
+
controller.close();
|
|
9850
|
+
}
|
|
9511
9851
|
} catch (err) {
|
|
9512
9852
|
console.error("Error closing stream:", err);
|
|
9513
9853
|
}
|
|
@@ -9558,80 +9898,80 @@ var Run = class {
|
|
|
9558
9898
|
return this.executionResults ?? this.streamOutput?.result;
|
|
9559
9899
|
}
|
|
9560
9900
|
};
|
|
9561
|
-
var languageModelUsageSchema =
|
|
9562
|
-
inputTokens:
|
|
9563
|
-
outputTokens:
|
|
9564
|
-
totalTokens:
|
|
9565
|
-
reasoningTokens:
|
|
9566
|
-
cachedInputTokens:
|
|
9901
|
+
var languageModelUsageSchema = z8.object({
|
|
9902
|
+
inputTokens: z8.number(),
|
|
9903
|
+
outputTokens: z8.number(),
|
|
9904
|
+
totalTokens: z8.number(),
|
|
9905
|
+
reasoningTokens: z8.number().optional(),
|
|
9906
|
+
cachedInputTokens: z8.number().optional()
|
|
9567
9907
|
});
|
|
9568
|
-
var llmIterationStepResultSchema =
|
|
9569
|
-
reason:
|
|
9570
|
-
warnings:
|
|
9571
|
-
isContinued:
|
|
9572
|
-
logprobs:
|
|
9908
|
+
var llmIterationStepResultSchema = z8.object({
|
|
9909
|
+
reason: z8.string(),
|
|
9910
|
+
warnings: z8.array(z8.any()),
|
|
9911
|
+
isContinued: z8.boolean(),
|
|
9912
|
+
logprobs: z8.any().optional(),
|
|
9573
9913
|
totalUsage: languageModelUsageSchema.optional(),
|
|
9574
|
-
headers:
|
|
9575
|
-
messageId:
|
|
9576
|
-
request:
|
|
9914
|
+
headers: z8.record(z8.string()).optional(),
|
|
9915
|
+
messageId: z8.string().optional(),
|
|
9916
|
+
request: z8.record(z8.any()).optional()
|
|
9577
9917
|
});
|
|
9578
|
-
var llmIterationOutputSchema =
|
|
9579
|
-
messageId:
|
|
9580
|
-
messages:
|
|
9581
|
-
all:
|
|
9918
|
+
var llmIterationOutputSchema = z8.object({
|
|
9919
|
+
messageId: z8.string(),
|
|
9920
|
+
messages: z8.object({
|
|
9921
|
+
all: z8.array(z8.any()),
|
|
9582
9922
|
// ModelMessage[] but too complex to validate at runtime
|
|
9583
|
-
user:
|
|
9584
|
-
nonUser:
|
|
9923
|
+
user: z8.array(z8.any()),
|
|
9924
|
+
nonUser: z8.array(z8.any())
|
|
9585
9925
|
}),
|
|
9586
|
-
output:
|
|
9587
|
-
text:
|
|
9588
|
-
reasoning:
|
|
9589
|
-
reasoningText:
|
|
9590
|
-
files:
|
|
9926
|
+
output: z8.object({
|
|
9927
|
+
text: z8.string().optional(),
|
|
9928
|
+
reasoning: z8.array(z8.any()).optional(),
|
|
9929
|
+
reasoningText: z8.string().optional(),
|
|
9930
|
+
files: z8.array(z8.any()).optional(),
|
|
9591
9931
|
// GeneratedFile[]
|
|
9592
|
-
toolCalls:
|
|
9932
|
+
toolCalls: z8.array(z8.any()).optional(),
|
|
9593
9933
|
// TypedToolCall[]
|
|
9594
|
-
toolResults:
|
|
9934
|
+
toolResults: z8.array(z8.any()).optional(),
|
|
9595
9935
|
// TypedToolResult[]
|
|
9596
|
-
sources:
|
|
9936
|
+
sources: z8.array(z8.any()).optional(),
|
|
9597
9937
|
// LanguageModelV2Source[]
|
|
9598
|
-
staticToolCalls:
|
|
9599
|
-
dynamicToolCalls:
|
|
9600
|
-
staticToolResults:
|
|
9601
|
-
dynamicToolResults:
|
|
9938
|
+
staticToolCalls: z8.array(z8.any()).optional(),
|
|
9939
|
+
dynamicToolCalls: z8.array(z8.any()).optional(),
|
|
9940
|
+
staticToolResults: z8.array(z8.any()).optional(),
|
|
9941
|
+
dynamicToolResults: z8.array(z8.any()).optional(),
|
|
9602
9942
|
usage: languageModelUsageSchema,
|
|
9603
|
-
steps:
|
|
9943
|
+
steps: z8.array(z8.any())
|
|
9604
9944
|
// StepResult[]
|
|
9605
9945
|
}),
|
|
9606
|
-
metadata:
|
|
9607
|
-
id:
|
|
9608
|
-
model:
|
|
9609
|
-
modelId:
|
|
9610
|
-
modelMetadata:
|
|
9611
|
-
modelId:
|
|
9612
|
-
modelVersion:
|
|
9613
|
-
modelProvider:
|
|
9946
|
+
metadata: z8.object({
|
|
9947
|
+
id: z8.string().optional(),
|
|
9948
|
+
model: z8.string().optional(),
|
|
9949
|
+
modelId: z8.string().optional(),
|
|
9950
|
+
modelMetadata: z8.object({
|
|
9951
|
+
modelId: z8.string(),
|
|
9952
|
+
modelVersion: z8.string(),
|
|
9953
|
+
modelProvider: z8.string()
|
|
9614
9954
|
}).optional(),
|
|
9615
|
-
timestamp:
|
|
9616
|
-
providerMetadata:
|
|
9617
|
-
headers:
|
|
9618
|
-
request:
|
|
9955
|
+
timestamp: z8.date().optional(),
|
|
9956
|
+
providerMetadata: z8.record(z8.any()).optional(),
|
|
9957
|
+
headers: z8.record(z8.string()).optional(),
|
|
9958
|
+
request: z8.record(z8.any()).optional()
|
|
9619
9959
|
}),
|
|
9620
9960
|
stepResult: llmIterationStepResultSchema,
|
|
9621
|
-
processorRetryCount:
|
|
9622
|
-
processorRetryFeedback:
|
|
9961
|
+
processorRetryCount: z8.number().optional(),
|
|
9962
|
+
processorRetryFeedback: z8.string().optional()
|
|
9623
9963
|
});
|
|
9624
|
-
var toolCallInputSchema =
|
|
9625
|
-
toolCallId:
|
|
9626
|
-
toolName:
|
|
9627
|
-
args:
|
|
9628
|
-
providerMetadata:
|
|
9629
|
-
providerExecuted:
|
|
9630
|
-
output:
|
|
9964
|
+
var toolCallInputSchema = z8.object({
|
|
9965
|
+
toolCallId: z8.string(),
|
|
9966
|
+
toolName: z8.string(),
|
|
9967
|
+
args: z8.record(z8.any()),
|
|
9968
|
+
providerMetadata: z8.record(z8.any()).optional(),
|
|
9969
|
+
providerExecuted: z8.boolean().optional(),
|
|
9970
|
+
output: z8.any().optional()
|
|
9631
9971
|
});
|
|
9632
9972
|
var toolCallOutputSchema = toolCallInputSchema.extend({
|
|
9633
|
-
result:
|
|
9634
|
-
error:
|
|
9973
|
+
result: z8.any(),
|
|
9974
|
+
error: z8.any().optional()
|
|
9635
9975
|
});
|
|
9636
9976
|
|
|
9637
9977
|
// src/processors/processors/prepare-step.ts
|
|
@@ -9684,10 +10024,10 @@ var AISDKV5InputStream = class extends MastraModelInput {
|
|
|
9684
10024
|
constructor({
|
|
9685
10025
|
component,
|
|
9686
10026
|
name,
|
|
9687
|
-
generateId:
|
|
10027
|
+
generateId: generateId2
|
|
9688
10028
|
}) {
|
|
9689
10029
|
super({ component, name });
|
|
9690
|
-
this.#generateId =
|
|
10030
|
+
this.#generateId = generateId2 ?? generateId;
|
|
9691
10031
|
}
|
|
9692
10032
|
async transform({
|
|
9693
10033
|
runId,
|
|
@@ -9739,12 +10079,12 @@ function execute({
|
|
|
9739
10079
|
headers,
|
|
9740
10080
|
shouldThrowError,
|
|
9741
10081
|
methodType,
|
|
9742
|
-
generateId:
|
|
10082
|
+
generateId: generateId2
|
|
9743
10083
|
}) {
|
|
9744
10084
|
const v5 = new AISDKV5InputStream({
|
|
9745
10085
|
component: "LLM",
|
|
9746
10086
|
name: model.modelId,
|
|
9747
|
-
generateId:
|
|
10087
|
+
generateId: generateId2
|
|
9748
10088
|
});
|
|
9749
10089
|
const toolsAndToolChoice = prepareToolsAndToolChoice({
|
|
9750
10090
|
tools,
|
|
@@ -10027,10 +10367,10 @@ async function processOutputStream({
|
|
|
10027
10367
|
break;
|
|
10028
10368
|
}
|
|
10029
10369
|
case "tool-call-input-streaming-start": {
|
|
10030
|
-
const
|
|
10031
|
-
if (
|
|
10370
|
+
const tool2 = tools?.[chunk.payload.toolName] || Object.values(tools || {})?.find((tool3) => `id` in tool3 && tool3.id === chunk.payload.toolName);
|
|
10371
|
+
if (tool2 && "onInputStart" in tool2) {
|
|
10032
10372
|
try {
|
|
10033
|
-
await
|
|
10373
|
+
await tool2?.onInputStart?.({
|
|
10034
10374
|
toolCallId: chunk.payload.toolCallId,
|
|
10035
10375
|
messages: messageList.get.input.aiV5.model(),
|
|
10036
10376
|
abortSignal: options?.abortSignal
|
|
@@ -10045,10 +10385,10 @@ async function processOutputStream({
|
|
|
10045
10385
|
break;
|
|
10046
10386
|
}
|
|
10047
10387
|
case "tool-call-delta": {
|
|
10048
|
-
const
|
|
10049
|
-
if (
|
|
10388
|
+
const tool2 = tools?.[chunk.payload.toolName || ""] || Object.values(tools || {})?.find((tool3) => `id` in tool3 && tool3.id === chunk.payload.toolName);
|
|
10389
|
+
if (tool2 && "onInputDelta" in tool2) {
|
|
10050
10390
|
try {
|
|
10051
|
-
await
|
|
10391
|
+
await tool2?.onInputDelta?.({
|
|
10052
10392
|
inputTextDelta: chunk.payload.argsTextDelta,
|
|
10053
10393
|
toolCallId: chunk.payload.toolCallId,
|
|
10054
10394
|
messages: messageList.get.input.aiV5.model(),
|
|
@@ -10259,7 +10599,7 @@ function executeStreamWithFallbackModels(models) {
|
|
|
10259
10599
|
while (attempt <= maxRetries) {
|
|
10260
10600
|
try {
|
|
10261
10601
|
const isLastModel = attempt === maxRetries && index === models.length;
|
|
10262
|
-
const result = await callback(modelConfig
|
|
10602
|
+
const result = await callback(modelConfig, isLastModel);
|
|
10263
10603
|
finalResult = result;
|
|
10264
10604
|
done = true;
|
|
10265
10605
|
break;
|
|
@@ -10301,13 +10641,13 @@ function createLLMExecutionStep({
|
|
|
10301
10641
|
inputProcessors,
|
|
10302
10642
|
logger,
|
|
10303
10643
|
agentId,
|
|
10304
|
-
headers,
|
|
10305
10644
|
downloadRetries,
|
|
10306
10645
|
downloadConcurrency,
|
|
10307
10646
|
processorStates,
|
|
10308
10647
|
requestContext,
|
|
10309
10648
|
methodType,
|
|
10310
10649
|
modelSpanTracker,
|
|
10650
|
+
autoResumeSuspendedTools,
|
|
10311
10651
|
maxProcessorRetries
|
|
10312
10652
|
}) {
|
|
10313
10653
|
const initialSystemMessages = messageList.getAllSystemMessages();
|
|
@@ -10320,7 +10660,9 @@ function createLLMExecutionStep({
|
|
|
10320
10660
|
let warnings;
|
|
10321
10661
|
let request;
|
|
10322
10662
|
let rawResponse;
|
|
10323
|
-
const { outputStream, callBail, runState, stepTools } = await executeStreamWithFallbackModels(models)(async (
|
|
10663
|
+
const { outputStream, callBail, runState, stepTools } = await executeStreamWithFallbackModels(models)(async (modelConfig, isLastModel) => {
|
|
10664
|
+
const model = modelConfig.model;
|
|
10665
|
+
const modelHeaders = modelConfig.headers;
|
|
10324
10666
|
if (initialSystemMessages) {
|
|
10325
10667
|
messageList.replaceAllSystemMessages(initialSystemMessages);
|
|
10326
10668
|
}
|
|
@@ -10378,57 +10720,83 @@ function createLLMExecutionStep({
|
|
|
10378
10720
|
downloadConcurrency,
|
|
10379
10721
|
supportedUrls: currentStep.model?.supportedUrls
|
|
10380
10722
|
};
|
|
10381
|
-
|
|
10382
|
-
|
|
10383
|
-
|
|
10384
|
-
|
|
10385
|
-
|
|
10386
|
-
|
|
10387
|
-
|
|
10388
|
-
|
|
10389
|
-
|
|
10390
|
-
|
|
10391
|
-
|
|
10392
|
-
|
|
10393
|
-
|
|
10394
|
-
|
|
10395
|
-
|
|
10396
|
-
|
|
10397
|
-
|
|
10398
|
-
|
|
10399
|
-
|
|
10400
|
-
|
|
10401
|
-
|
|
10402
|
-
|
|
10403
|
-
|
|
10404
|
-
|
|
10405
|
-
|
|
10406
|
-
warnings = warningsFromStream;
|
|
10407
|
-
request = requestFromStream || {};
|
|
10408
|
-
rawResponse = rawResponseFromStream;
|
|
10409
|
-
if (!isControllerOpen(controller)) {
|
|
10410
|
-
return;
|
|
10411
|
-
}
|
|
10412
|
-
controller.enqueue({
|
|
10413
|
-
runId,
|
|
10414
|
-
from: "AGENT" /* AGENT */,
|
|
10415
|
-
type: "step-start",
|
|
10416
|
-
payload: {
|
|
10417
|
-
request: request || {},
|
|
10418
|
-
warnings: warnings || [],
|
|
10419
|
-
messageId
|
|
10420
|
-
}
|
|
10421
|
-
});
|
|
10422
|
-
},
|
|
10423
|
-
shouldThrowError: !isLastModel
|
|
10424
|
-
})
|
|
10425
|
-
});
|
|
10426
|
-
break;
|
|
10427
|
-
}
|
|
10428
|
-
default: {
|
|
10429
|
-
throw new Error(`Unsupported model version: ${model.specificationVersion}`);
|
|
10723
|
+
let inputMessages = await messageList.get.all.aiV5.llmPrompt(messageListPromptArgs);
|
|
10724
|
+
if (autoResumeSuspendedTools) {
|
|
10725
|
+
const messages2 = messageList.get.all.db();
|
|
10726
|
+
const assistantMessages = [...messages2].reverse().filter((message) => message.role === "assistant");
|
|
10727
|
+
const suspendedToolsMessage = assistantMessages.find(
|
|
10728
|
+
(message) => message.content.metadata?.suspendedTools || message.content.metadata?.pendingToolApprovals
|
|
10729
|
+
);
|
|
10730
|
+
if (suspendedToolsMessage) {
|
|
10731
|
+
const metadata = suspendedToolsMessage.content.metadata;
|
|
10732
|
+
const suspendedToolObj = metadata?.suspendedTools || metadata?.pendingToolApprovals;
|
|
10733
|
+
const suspendedTools = Object.values(suspendedToolObj);
|
|
10734
|
+
if (suspendedTools.length > 0) {
|
|
10735
|
+
inputMessages = inputMessages.map((message, index) => {
|
|
10736
|
+
if (message.role === "system" && index === 0) {
|
|
10737
|
+
message.content = message.content + `
|
|
10738
|
+
|
|
10739
|
+
Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messages available to you and the resumeSchema of each suspended tool, find the tool whose resumeData you can construct properly.
|
|
10740
|
+
resumeData can not be an empty object nor null/undefined.
|
|
10741
|
+
When you find that and call that tool, add the resumeData to the tool call arguments/input.
|
|
10742
|
+
Also, add the runId of the suspended tool as suspendedToolRunId to the tool call arguments/input.
|
|
10743
|
+
If the suspendedTool.type is 'approval', resumeData will be an object that contains 'approved' which can either be true or false depending on the user's message.`;
|
|
10744
|
+
}
|
|
10745
|
+
return message;
|
|
10746
|
+
});
|
|
10747
|
+
}
|
|
10430
10748
|
}
|
|
10431
10749
|
}
|
|
10750
|
+
if (isSupportedLanguageModel(currentStep.model)) {
|
|
10751
|
+
modelResult = executeWithContextSync({
|
|
10752
|
+
span: modelSpanTracker?.getTracingContext()?.currentSpan,
|
|
10753
|
+
fn: () => execute({
|
|
10754
|
+
runId,
|
|
10755
|
+
model: currentStep.model,
|
|
10756
|
+
providerOptions: currentStep.providerOptions,
|
|
10757
|
+
inputMessages,
|
|
10758
|
+
tools: currentStep.tools,
|
|
10759
|
+
toolChoice: currentStep.toolChoice,
|
|
10760
|
+
activeTools: currentStep.activeTools,
|
|
10761
|
+
options,
|
|
10762
|
+
modelSettings: currentStep.modelSettings,
|
|
10763
|
+
includeRawChunks,
|
|
10764
|
+
structuredOutput: currentStep.structuredOutput,
|
|
10765
|
+
// Merge headers: modelConfig headers first, then modelSettings overrides them
|
|
10766
|
+
// Only create object if there are actual headers to avoid passing empty {}
|
|
10767
|
+
headers: modelHeaders || currentStep.modelSettings?.headers ? { ...modelHeaders, ...currentStep.modelSettings?.headers } : void 0,
|
|
10768
|
+
methodType,
|
|
10769
|
+
generateId: _internal?.generateId,
|
|
10770
|
+
onResult: ({
|
|
10771
|
+
warnings: warningsFromStream,
|
|
10772
|
+
request: requestFromStream,
|
|
10773
|
+
rawResponse: rawResponseFromStream
|
|
10774
|
+
}) => {
|
|
10775
|
+
warnings = warningsFromStream;
|
|
10776
|
+
request = requestFromStream || {};
|
|
10777
|
+
rawResponse = rawResponseFromStream;
|
|
10778
|
+
if (!isControllerOpen(controller)) {
|
|
10779
|
+
return;
|
|
10780
|
+
}
|
|
10781
|
+
controller.enqueue({
|
|
10782
|
+
runId,
|
|
10783
|
+
from: "AGENT" /* AGENT */,
|
|
10784
|
+
type: "step-start",
|
|
10785
|
+
payload: {
|
|
10786
|
+
request: request || {},
|
|
10787
|
+
warnings: warnings || [],
|
|
10788
|
+
messageId
|
|
10789
|
+
}
|
|
10790
|
+
});
|
|
10791
|
+
},
|
|
10792
|
+
shouldThrowError: !isLastModel
|
|
10793
|
+
})
|
|
10794
|
+
});
|
|
10795
|
+
} else {
|
|
10796
|
+
throw new Error(
|
|
10797
|
+
`Unsupported model version: ${currentStep.model.specificationVersion}. Supported versions: ${supportedLanguageModelSpecifications.join(", ")}`
|
|
10798
|
+
);
|
|
10799
|
+
}
|
|
10432
10800
|
const outputStream2 = new MastraModelOutput({
|
|
10433
10801
|
model: {
|
|
10434
10802
|
modelId: currentStep.model.modelId,
|
|
@@ -10739,11 +11107,11 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
|
|
|
10739
11107
|
}
|
|
10740
11108
|
return createStep({
|
|
10741
11109
|
id: "llmExecutionMappingStep",
|
|
10742
|
-
inputSchema:
|
|
11110
|
+
inputSchema: z8.array(toolCallOutputSchema),
|
|
10743
11111
|
outputSchema: llmIterationOutputSchema,
|
|
10744
11112
|
execute: async ({ inputData, getStepResult: getStepResult2, bail }) => {
|
|
10745
11113
|
const initialResult = getStepResult2(llmExecutionStep);
|
|
10746
|
-
if (inputData?.
|
|
11114
|
+
if (inputData?.some((toolCall) => toolCall?.result === void 0)) {
|
|
10747
11115
|
const errorResults = inputData.filter((toolCall) => toolCall?.error);
|
|
10748
11116
|
const toolResultMessageId = rest.experimental_generateMessageId?.() || _internal?.generateId?.();
|
|
10749
11117
|
if (errorResults?.length) {
|
|
@@ -10788,7 +11156,14 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
|
|
|
10788
11156
|
if (initialResult.stepResult.reason !== "retry") {
|
|
10789
11157
|
initialResult.stepResult.isContinued = false;
|
|
10790
11158
|
}
|
|
10791
|
-
return bail(
|
|
11159
|
+
return bail({
|
|
11160
|
+
...initialResult,
|
|
11161
|
+
messages: {
|
|
11162
|
+
all: rest.messageList.get.all.aiV5.model(),
|
|
11163
|
+
user: rest.messageList.get.input.aiV5.model(),
|
|
11164
|
+
nonUser: rest.messageList.get.response.aiV5.model()
|
|
11165
|
+
}
|
|
11166
|
+
});
|
|
10792
11167
|
}
|
|
10793
11168
|
if (inputData?.length) {
|
|
10794
11169
|
for (const toolCall of inputData) {
|
|
@@ -10846,11 +11221,10 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
|
|
|
10846
11221
|
}
|
|
10847
11222
|
};
|
|
10848
11223
|
}
|
|
11224
|
+
return initialResult;
|
|
10849
11225
|
}
|
|
10850
11226
|
});
|
|
10851
11227
|
}
|
|
10852
|
-
|
|
10853
|
-
// src/loop/workflows/agentic-execution/tool-call-step.ts
|
|
10854
11228
|
function createToolCallStep({
|
|
10855
11229
|
tools,
|
|
10856
11230
|
messageList,
|
|
@@ -10866,28 +11240,39 @@ function createToolCallStep({
|
|
|
10866
11240
|
id: "toolCallStep",
|
|
10867
11241
|
inputSchema: toolCallInputSchema,
|
|
10868
11242
|
outputSchema: toolCallOutputSchema,
|
|
10869
|
-
execute: async ({ inputData, suspend, resumeData, requestContext }) => {
|
|
11243
|
+
execute: async ({ inputData, suspend, resumeData: workflowResumeData, requestContext }) => {
|
|
10870
11244
|
const stepTools = _internal?.stepTools || tools;
|
|
10871
|
-
const
|
|
10872
|
-
const
|
|
11245
|
+
const tool2 = stepTools?.[inputData.toolName] || Object.values(stepTools || {})?.find((t) => `id` in t && t.id === inputData.toolName);
|
|
11246
|
+
const addToolMetadata = ({
|
|
11247
|
+
toolCallId,
|
|
11248
|
+
toolName,
|
|
11249
|
+
args,
|
|
11250
|
+
suspendPayload,
|
|
11251
|
+
resumeSchema,
|
|
11252
|
+
type
|
|
11253
|
+
}) => {
|
|
11254
|
+
const metadataKey = type === "suspension" ? "suspendedTools" : "pendingToolApprovals";
|
|
10873
11255
|
const responseMessages = messageList.get.response.db();
|
|
10874
11256
|
const lastAssistantMessage = [...responseMessages].reverse().find((msg) => msg.role === "assistant");
|
|
10875
11257
|
if (lastAssistantMessage) {
|
|
10876
11258
|
const content = lastAssistantMessage.content;
|
|
10877
11259
|
if (!content) return;
|
|
10878
11260
|
const metadata = typeof lastAssistantMessage.content.metadata === "object" && lastAssistantMessage.content.metadata !== null ? lastAssistantMessage.content.metadata : {};
|
|
10879
|
-
metadata
|
|
10880
|
-
metadata
|
|
11261
|
+
metadata[metadataKey] = metadata[metadataKey] || {};
|
|
11262
|
+
metadata[metadataKey][toolName] = {
|
|
11263
|
+
toolCallId,
|
|
10881
11264
|
toolName,
|
|
10882
11265
|
args,
|
|
10883
|
-
type
|
|
10884
|
-
runId
|
|
11266
|
+
type,
|
|
11267
|
+
runId,
|
|
10885
11268
|
// Store the runId so we can resume after page refresh
|
|
11269
|
+
...type === "suspension" ? { suspendPayload } : {},
|
|
11270
|
+
resumeSchema
|
|
10886
11271
|
};
|
|
10887
11272
|
lastAssistantMessage.content.metadata = metadata;
|
|
10888
11273
|
}
|
|
10889
11274
|
};
|
|
10890
|
-
const
|
|
11275
|
+
const removeToolMetadata = async (toolName, type) => {
|
|
10891
11276
|
const { saveQueueManager, memoryConfig, threadId } = _internal || {};
|
|
10892
11277
|
if (!saveQueueManager || !threadId) {
|
|
10893
11278
|
return;
|
|
@@ -10898,24 +11283,25 @@ function createToolCallStep({
|
|
|
10898
11283
|
const metadata = typeof content.metadata === "object" && content.metadata !== null ? content.metadata : void 0;
|
|
10899
11284
|
return metadata;
|
|
10900
11285
|
};
|
|
11286
|
+
const metadataKey = type === "suspension" ? "suspendedTools" : "pendingToolApprovals";
|
|
10901
11287
|
const allMessages = messageList.get.all.db();
|
|
10902
11288
|
const lastAssistantMessage = [...allMessages].reverse().find((msg) => {
|
|
10903
11289
|
const metadata = getMetadata(msg);
|
|
10904
|
-
const
|
|
10905
|
-
return !!
|
|
11290
|
+
const suspendedTools = metadata?.[metadataKey];
|
|
11291
|
+
return !!suspendedTools?.[toolName];
|
|
10906
11292
|
});
|
|
10907
11293
|
if (lastAssistantMessage) {
|
|
10908
11294
|
const metadata = getMetadata(lastAssistantMessage);
|
|
10909
|
-
const
|
|
10910
|
-
if (
|
|
10911
|
-
delete
|
|
10912
|
-
if (metadata && Object.keys(
|
|
10913
|
-
delete metadata
|
|
11295
|
+
const suspendedTools = metadata?.[metadataKey];
|
|
11296
|
+
if (suspendedTools && typeof suspendedTools === "object") {
|
|
11297
|
+
delete suspendedTools[toolName];
|
|
11298
|
+
if (metadata && Object.keys(suspendedTools).length === 0) {
|
|
11299
|
+
delete metadata[metadataKey];
|
|
10914
11300
|
}
|
|
10915
11301
|
try {
|
|
10916
11302
|
await saveQueueManager.flushMessages(messageList, threadId, memoryConfig);
|
|
10917
11303
|
} catch (error) {
|
|
10918
|
-
console.error("Error removing tool
|
|
11304
|
+
console.error("Error removing tool suspension metadata:", error);
|
|
10919
11305
|
}
|
|
10920
11306
|
}
|
|
10921
11307
|
}
|
|
@@ -10948,12 +11334,12 @@ function createToolCallStep({
|
|
|
10948
11334
|
result: inputData.output
|
|
10949
11335
|
};
|
|
10950
11336
|
}
|
|
10951
|
-
if (!
|
|
11337
|
+
if (!tool2) {
|
|
10952
11338
|
throw new Error(`Tool ${inputData.toolName} not found`);
|
|
10953
11339
|
}
|
|
10954
|
-
if (
|
|
11340
|
+
if (tool2 && "onInputAvailable" in tool2) {
|
|
10955
11341
|
try {
|
|
10956
|
-
await
|
|
11342
|
+
await tool2?.onInputAvailable?.({
|
|
10957
11343
|
toolCallId: inputData.toolCallId,
|
|
10958
11344
|
input: inputData.args,
|
|
10959
11345
|
messages: messageList.get.input.aiV5.model(),
|
|
@@ -10963,12 +11349,21 @@ function createToolCallStep({
|
|
|
10963
11349
|
console.error("Error calling onInputAvailable", error);
|
|
10964
11350
|
}
|
|
10965
11351
|
}
|
|
10966
|
-
if (!
|
|
11352
|
+
if (!tool2.execute) {
|
|
10967
11353
|
return inputData;
|
|
10968
11354
|
}
|
|
10969
11355
|
try {
|
|
10970
11356
|
const requireToolApproval = requestContext.get("__mastra_requireToolApproval");
|
|
10971
|
-
|
|
11357
|
+
let resumeDataFromArgs = void 0;
|
|
11358
|
+
let args = inputData.args;
|
|
11359
|
+
if (typeof inputData.args === "object" && inputData.args !== null) {
|
|
11360
|
+
const { resumeData: resumeDataFromInput, ...argsFromInput } = inputData.args;
|
|
11361
|
+
args = argsFromInput;
|
|
11362
|
+
resumeDataFromArgs = resumeDataFromInput;
|
|
11363
|
+
}
|
|
11364
|
+
const resumeData = resumeDataFromArgs ?? workflowResumeData;
|
|
11365
|
+
const isResumeToolCall = !!resumeDataFromArgs;
|
|
11366
|
+
if (requireToolApproval || tool2.requireApproval) {
|
|
10972
11367
|
if (!resumeData) {
|
|
10973
11368
|
controller.enqueue({
|
|
10974
11369
|
type: "tool-call-approval",
|
|
@@ -10980,7 +11375,17 @@ function createToolCallStep({
|
|
|
10980
11375
|
args: inputData.args
|
|
10981
11376
|
}
|
|
10982
11377
|
});
|
|
10983
|
-
|
|
11378
|
+
addToolMetadata({
|
|
11379
|
+
toolCallId: inputData.toolCallId,
|
|
11380
|
+
toolName: inputData.toolName,
|
|
11381
|
+
args: inputData.args,
|
|
11382
|
+
type: "approval",
|
|
11383
|
+
resumeSchema: z8.object({
|
|
11384
|
+
approved: z8.boolean().describe(
|
|
11385
|
+
"Controls if the tool call is approved or not, should be true when approved and false when declined"
|
|
11386
|
+
)
|
|
11387
|
+
})
|
|
11388
|
+
});
|
|
10984
11389
|
await flushMessagesBeforeSuspension();
|
|
10985
11390
|
return suspend(
|
|
10986
11391
|
{
|
|
@@ -10996,7 +11401,7 @@ function createToolCallStep({
|
|
|
10996
11401
|
}
|
|
10997
11402
|
);
|
|
10998
11403
|
} else {
|
|
10999
|
-
await
|
|
11404
|
+
await removeToolMetadata(inputData.toolName, "approval");
|
|
11000
11405
|
if (!resumeData.approved) {
|
|
11001
11406
|
return {
|
|
11002
11407
|
result: "Tool call was not approved by the user",
|
|
@@ -11004,6 +11409,8 @@ function createToolCallStep({
|
|
|
11004
11409
|
};
|
|
11005
11410
|
}
|
|
11006
11411
|
}
|
|
11412
|
+
} else if (isResumeToolCall) {
|
|
11413
|
+
await removeToolMetadata(inputData.toolName, "suspension");
|
|
11007
11414
|
}
|
|
11008
11415
|
const toolOptions = {
|
|
11009
11416
|
abortSignal: options?.abortSignal,
|
|
@@ -11012,18 +11419,33 @@ function createToolCallStep({
|
|
|
11012
11419
|
outputWriter,
|
|
11013
11420
|
// Pass current step span as parent for tool call spans
|
|
11014
11421
|
tracingContext: modelSpanTracker?.getTracingContext(),
|
|
11015
|
-
suspend: async (suspendPayload) => {
|
|
11422
|
+
suspend: async (suspendPayload, options2) => {
|
|
11016
11423
|
controller.enqueue({
|
|
11017
11424
|
type: "tool-call-suspended",
|
|
11018
11425
|
runId,
|
|
11019
11426
|
from: "AGENT" /* AGENT */,
|
|
11020
|
-
payload: {
|
|
11427
|
+
payload: {
|
|
11428
|
+
toolCallId: inputData.toolCallId,
|
|
11429
|
+
toolName: inputData.toolName,
|
|
11430
|
+
suspendPayload,
|
|
11431
|
+
args: inputData.args
|
|
11432
|
+
}
|
|
11433
|
+
});
|
|
11434
|
+
addToolMetadata({
|
|
11435
|
+
toolCallId: inputData.toolCallId,
|
|
11436
|
+
toolName: inputData.toolName,
|
|
11437
|
+
args,
|
|
11438
|
+
suspendPayload,
|
|
11439
|
+
type: "suspension",
|
|
11440
|
+
resumeSchema: options2?.resumeSchema
|
|
11021
11441
|
});
|
|
11022
11442
|
await flushMessagesBeforeSuspension();
|
|
11023
11443
|
return await suspend(
|
|
11024
11444
|
{
|
|
11025
11445
|
toolCallSuspended: suspendPayload,
|
|
11026
|
-
__streamState: streamState.serialize()
|
|
11446
|
+
__streamState: streamState.serialize(),
|
|
11447
|
+
toolName: inputData.toolName,
|
|
11448
|
+
resumeLabel: options2?.resumeLabel
|
|
11027
11449
|
},
|
|
11028
11450
|
{
|
|
11029
11451
|
resumeLabel: inputData.toolCallId
|
|
@@ -11032,10 +11454,10 @@ function createToolCallStep({
|
|
|
11032
11454
|
},
|
|
11033
11455
|
resumeData
|
|
11034
11456
|
};
|
|
11035
|
-
const result = await
|
|
11036
|
-
if (
|
|
11457
|
+
const result = await tool2.execute(args, toolOptions);
|
|
11458
|
+
if (tool2 && "onOutput" in tool2 && typeof tool2.onOutput === "function") {
|
|
11037
11459
|
try {
|
|
11038
|
-
await
|
|
11460
|
+
await tool2.onOutput({
|
|
11039
11461
|
toolCallId: inputData.toolCallId,
|
|
11040
11462
|
toolName: inputData.toolName,
|
|
11041
11463
|
output: result,
|
|
@@ -11075,6 +11497,25 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
|
|
|
11075
11497
|
},
|
|
11076
11498
|
llmExecutionStep
|
|
11077
11499
|
);
|
|
11500
|
+
let toolCallConcurrency = 10;
|
|
11501
|
+
if (rest?.toolCallConcurrency) {
|
|
11502
|
+
toolCallConcurrency = rest.toolCallConcurrency > 0 ? rest.toolCallConcurrency : 10;
|
|
11503
|
+
}
|
|
11504
|
+
const hasRequireToolApproval = !!rest.requireToolApproval;
|
|
11505
|
+
let hasSuspendSchema = false;
|
|
11506
|
+
let hasRequireApproval = false;
|
|
11507
|
+
if (rest.tools) {
|
|
11508
|
+
for (const tool2 of Object.values(rest.tools)) {
|
|
11509
|
+
if (tool2?.hasSuspendSchema) {
|
|
11510
|
+
hasSuspendSchema = true;
|
|
11511
|
+
}
|
|
11512
|
+
if (tool2?.requireApproval) {
|
|
11513
|
+
hasRequireApproval = true;
|
|
11514
|
+
}
|
|
11515
|
+
if (hasSuspendSchema || hasRequireApproval) break;
|
|
11516
|
+
}
|
|
11517
|
+
}
|
|
11518
|
+
const sequentialExecutionRequired = hasRequireToolApproval || hasSuspendSchema || hasRequireApproval;
|
|
11078
11519
|
return createWorkflow({
|
|
11079
11520
|
id: "executionWorkflow",
|
|
11080
11521
|
inputSchema: llmIterationOutputSchema,
|
|
@@ -11104,7 +11545,7 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
|
|
|
11104
11545
|
return typedInputData.output.toolCalls || [];
|
|
11105
11546
|
},
|
|
11106
11547
|
{ id: "map-tool-calls" }
|
|
11107
|
-
).foreach(toolCallStep, { concurrency:
|
|
11548
|
+
).foreach(toolCallStep, { concurrency: sequentialExecutionRequired ? 1 : toolCallConcurrency }).then(llmMappingStep).commit();
|
|
11108
11549
|
}
|
|
11109
11550
|
|
|
11110
11551
|
// src/loop/workflows/agentic-loop/index.ts
|
|
@@ -11237,6 +11678,7 @@ function workflowLoopStream({
|
|
|
11237
11678
|
streamState,
|
|
11238
11679
|
agentId,
|
|
11239
11680
|
toolCallId,
|
|
11681
|
+
toolCallConcurrency,
|
|
11240
11682
|
...rest
|
|
11241
11683
|
}) {
|
|
11242
11684
|
return new ReadableStream$1({
|
|
@@ -11254,7 +11696,9 @@ function workflowLoopStream({
|
|
|
11254
11696
|
format: 2,
|
|
11255
11697
|
parts: [dataPart]
|
|
11256
11698
|
},
|
|
11257
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
11699
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
11700
|
+
threadId: _internal?.threadId,
|
|
11701
|
+
resourceId: _internal?.resourceId
|
|
11258
11702
|
};
|
|
11259
11703
|
messageList.add(message, "response");
|
|
11260
11704
|
}
|
|
@@ -11274,6 +11718,8 @@ function workflowLoopStream({
|
|
|
11274
11718
|
startTimestamp,
|
|
11275
11719
|
streamState,
|
|
11276
11720
|
agentId,
|
|
11721
|
+
requireToolApproval,
|
|
11722
|
+
toolCallConcurrency,
|
|
11277
11723
|
...rest
|
|
11278
11724
|
});
|
|
11279
11725
|
if (rest.mastra) {
|
|
@@ -11304,7 +11750,8 @@ function workflowLoopStream({
|
|
|
11304
11750
|
runId,
|
|
11305
11751
|
from: "AGENT" /* AGENT */,
|
|
11306
11752
|
payload: {
|
|
11307
|
-
id: agentId
|
|
11753
|
+
id: agentId,
|
|
11754
|
+
messageId
|
|
11308
11755
|
}
|
|
11309
11756
|
});
|
|
11310
11757
|
}
|
|
@@ -11326,18 +11773,7 @@ function workflowLoopStream({
|
|
|
11326
11773
|
});
|
|
11327
11774
|
if (executionResult.status !== "success") {
|
|
11328
11775
|
if (executionResult.status === "failed") {
|
|
11329
|
-
|
|
11330
|
-
if (typeof executionResult.error === "string") {
|
|
11331
|
-
const prependedErrorString = "Error: ";
|
|
11332
|
-
if (executionResult.error.startsWith(`${prependedErrorString}${prependedErrorString}`)) {
|
|
11333
|
-
executionResultError = executionResult.error.substring(
|
|
11334
|
-
`${prependedErrorString}${prependedErrorString}`.length
|
|
11335
|
-
);
|
|
11336
|
-
} else if (executionResult.error.startsWith(prependedErrorString)) {
|
|
11337
|
-
executionResultError = executionResult.error.substring(prependedErrorString.length);
|
|
11338
|
-
}
|
|
11339
|
-
}
|
|
11340
|
-
const error = getErrorFromUnknown(executionResultError, {
|
|
11776
|
+
const error = getErrorFromUnknown(executionResult.error, {
|
|
11341
11777
|
fallbackMessage: "Unknown error in agent workflow stream"
|
|
11342
11778
|
});
|
|
11343
11779
|
controller.enqueue({
|
|
@@ -11350,9 +11786,13 @@ function workflowLoopStream({
|
|
|
11350
11786
|
await rest.options?.onError?.({ error });
|
|
11351
11787
|
}
|
|
11352
11788
|
}
|
|
11789
|
+
if (executionResult.status !== "suspended") {
|
|
11790
|
+
await agenticLoopWorkflow.deleteWorkflowRunById(runId);
|
|
11791
|
+
}
|
|
11353
11792
|
controller.close();
|
|
11354
11793
|
return;
|
|
11355
11794
|
}
|
|
11795
|
+
await agenticLoopWorkflow.deleteWorkflowRunById(runId);
|
|
11356
11796
|
controller.enqueue({
|
|
11357
11797
|
type: "finish",
|
|
11358
11798
|
runId,
|
|
@@ -11387,6 +11827,7 @@ function loop({
|
|
|
11387
11827
|
returnScorerData,
|
|
11388
11828
|
requireToolApproval,
|
|
11389
11829
|
agentId,
|
|
11830
|
+
toolCallConcurrency,
|
|
11390
11831
|
...rest
|
|
11391
11832
|
}) {
|
|
11392
11833
|
let loggerToUse = logger || new ConsoleLogger({
|
|
@@ -11443,6 +11884,7 @@ function loop({
|
|
|
11443
11884
|
messageId,
|
|
11444
11885
|
agentId,
|
|
11445
11886
|
requireToolApproval,
|
|
11887
|
+
toolCallConcurrency,
|
|
11446
11888
|
streamState: {
|
|
11447
11889
|
serialize: serializeStreamState,
|
|
11448
11890
|
deserialize: deserializeStreamState
|
|
@@ -11601,6 +12043,7 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
11601
12043
|
tracingContext,
|
|
11602
12044
|
messageList,
|
|
11603
12045
|
requireToolApproval,
|
|
12046
|
+
toolCallConcurrency,
|
|
11604
12047
|
_internal,
|
|
11605
12048
|
agentId,
|
|
11606
12049
|
agentName,
|
|
@@ -11608,6 +12051,7 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
11608
12051
|
requestContext,
|
|
11609
12052
|
methodType,
|
|
11610
12053
|
includeRawChunks,
|
|
12054
|
+
autoResumeSuspendedTools,
|
|
11611
12055
|
maxProcessorRetries
|
|
11612
12056
|
}) {
|
|
11613
12057
|
let stopWhenToUse;
|
|
@@ -11667,11 +12111,13 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
11667
12111
|
returnScorerData,
|
|
11668
12112
|
modelSpanTracker,
|
|
11669
12113
|
requireToolApproval,
|
|
12114
|
+
toolCallConcurrency,
|
|
11670
12115
|
agentId,
|
|
11671
12116
|
agentName,
|
|
11672
12117
|
requestContext,
|
|
11673
12118
|
methodType,
|
|
11674
12119
|
includeRawChunks,
|
|
12120
|
+
autoResumeSuspendedTools,
|
|
11675
12121
|
maxProcessorRetries,
|
|
11676
12122
|
options: {
|
|
11677
12123
|
...options,
|
|
@@ -11796,7 +12242,7 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
11796
12242
|
}
|
|
11797
12243
|
}
|
|
11798
12244
|
};
|
|
11799
|
-
var PRIMITIVE_TYPES =
|
|
12245
|
+
var PRIMITIVE_TYPES = z8.enum(["agent", "workflow", "none", "tool"]);
|
|
11800
12246
|
|
|
11801
12247
|
// src/loop/network/index.ts
|
|
11802
12248
|
async function getRoutingAgent({ requestContext, agent }) {
|
|
@@ -11815,9 +12261,9 @@ async function getRoutingAgent({ requestContext, agent }) {
|
|
|
11815
12261
|
)}`;
|
|
11816
12262
|
}).join("\n");
|
|
11817
12263
|
const memoryTools = await memoryToUse?.listTools?.();
|
|
11818
|
-
const toolList = Object.entries({ ...toolsToUse, ...memoryTools }).map(([name,
|
|
11819
|
-
return ` - **${name}**: ${
|
|
11820
|
-
zodToJsonSchema$1(
|
|
12264
|
+
const toolList = Object.entries({ ...toolsToUse, ...memoryTools }).map(([name, tool2]) => {
|
|
12265
|
+
return ` - **${name}**: ${tool2.description}, input schema: ${JSON.stringify(
|
|
12266
|
+
zodToJsonSchema$1(tool2.inputSchema || z8.object({}))
|
|
11821
12267
|
)}`;
|
|
11822
12268
|
}).join("\n");
|
|
11823
12269
|
const instructions = `
|
|
@@ -11888,7 +12334,7 @@ async function prepareMemoryStep({
|
|
|
11888
12334
|
messages,
|
|
11889
12335
|
routingAgent,
|
|
11890
12336
|
requestContext,
|
|
11891
|
-
generateId:
|
|
12337
|
+
generateId: generateId2,
|
|
11892
12338
|
tracingContext,
|
|
11893
12339
|
memoryConfig
|
|
11894
12340
|
}) {
|
|
@@ -11910,7 +12356,7 @@ async function prepareMemoryStep({
|
|
|
11910
12356
|
memory.saveMessages({
|
|
11911
12357
|
messages: [
|
|
11912
12358
|
{
|
|
11913
|
-
id:
|
|
12359
|
+
id: generateId2(),
|
|
11914
12360
|
type: "text",
|
|
11915
12361
|
role: "user",
|
|
11916
12362
|
content: { parts: [{ type: "text", text: messages }], format: 2 },
|
|
@@ -11977,43 +12423,43 @@ async function createNetworkLoop({
|
|
|
11977
12423
|
requestContext,
|
|
11978
12424
|
runId,
|
|
11979
12425
|
agent,
|
|
11980
|
-
generateId:
|
|
12426
|
+
generateId: generateId2,
|
|
11981
12427
|
routingAgentOptions
|
|
11982
12428
|
}) {
|
|
11983
12429
|
const routingStep = createStep({
|
|
11984
12430
|
id: "routing-agent-step",
|
|
11985
|
-
inputSchema:
|
|
11986
|
-
task:
|
|
11987
|
-
primitiveId:
|
|
12431
|
+
inputSchema: z8.object({
|
|
12432
|
+
task: z8.string(),
|
|
12433
|
+
primitiveId: z8.string(),
|
|
11988
12434
|
primitiveType: PRIMITIVE_TYPES,
|
|
11989
|
-
result:
|
|
11990
|
-
iteration:
|
|
11991
|
-
threadId:
|
|
11992
|
-
threadResourceId:
|
|
11993
|
-
isOneOff:
|
|
11994
|
-
verboseIntrospection:
|
|
12435
|
+
result: z8.string().optional(),
|
|
12436
|
+
iteration: z8.number(),
|
|
12437
|
+
threadId: z8.string().optional(),
|
|
12438
|
+
threadResourceId: z8.string().optional(),
|
|
12439
|
+
isOneOff: z8.boolean(),
|
|
12440
|
+
verboseIntrospection: z8.boolean()
|
|
11995
12441
|
}),
|
|
11996
|
-
outputSchema:
|
|
11997
|
-
task:
|
|
11998
|
-
primitiveId:
|
|
12442
|
+
outputSchema: z8.object({
|
|
12443
|
+
task: z8.string(),
|
|
12444
|
+
primitiveId: z8.string(),
|
|
11999
12445
|
primitiveType: PRIMITIVE_TYPES,
|
|
12000
|
-
prompt:
|
|
12001
|
-
result:
|
|
12002
|
-
isComplete:
|
|
12003
|
-
selectionReason:
|
|
12004
|
-
iteration:
|
|
12446
|
+
prompt: z8.string(),
|
|
12447
|
+
result: z8.string(),
|
|
12448
|
+
isComplete: z8.boolean().optional(),
|
|
12449
|
+
selectionReason: z8.string(),
|
|
12450
|
+
iteration: z8.number()
|
|
12005
12451
|
}),
|
|
12006
12452
|
execute: async ({ inputData, getInitData, writer }) => {
|
|
12007
12453
|
const initData = await getInitData();
|
|
12008
|
-
const completionSchema =
|
|
12009
|
-
isComplete:
|
|
12010
|
-
finalResult:
|
|
12011
|
-
completionReason:
|
|
12454
|
+
const completionSchema = z8.object({
|
|
12455
|
+
isComplete: z8.boolean(),
|
|
12456
|
+
finalResult: z8.string(),
|
|
12457
|
+
completionReason: z8.string()
|
|
12012
12458
|
});
|
|
12013
12459
|
const routingAgent = await getRoutingAgent({ requestContext, agent });
|
|
12014
12460
|
let completionResult;
|
|
12015
12461
|
const iterationCount = (inputData.iteration ?? -1) + 1;
|
|
12016
|
-
const stepId =
|
|
12462
|
+
const stepId = generateId2();
|
|
12017
12463
|
await writer.write({
|
|
12018
12464
|
type: "routing-agent-start",
|
|
12019
12465
|
payload: {
|
|
@@ -12149,7 +12595,7 @@ async function createNetworkLoop({
|
|
|
12149
12595
|
await memory?.saveMessages({
|
|
12150
12596
|
messages: [
|
|
12151
12597
|
{
|
|
12152
|
-
id:
|
|
12598
|
+
id: generateId2(),
|
|
12153
12599
|
type: "text",
|
|
12154
12600
|
role: "assistant",
|
|
12155
12601
|
content: {
|
|
@@ -12209,11 +12655,11 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12209
12655
|
];
|
|
12210
12656
|
const options = {
|
|
12211
12657
|
structuredOutput: {
|
|
12212
|
-
schema:
|
|
12213
|
-
primitiveId:
|
|
12658
|
+
schema: z8.object({
|
|
12659
|
+
primitiveId: z8.string().describe("The id of the primitive to be called"),
|
|
12214
12660
|
primitiveType: PRIMITIVE_TYPES.describe("The type of the primitive to be called"),
|
|
12215
|
-
prompt:
|
|
12216
|
-
selectionReason:
|
|
12661
|
+
prompt: z8.string().describe("The json string or text value to be sent to the primitive"),
|
|
12662
|
+
selectionReason: z8.string().describe("The reason you picked the primitive")
|
|
12217
12663
|
})
|
|
12218
12664
|
},
|
|
12219
12665
|
requestContext,
|
|
@@ -12257,23 +12703,23 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12257
12703
|
});
|
|
12258
12704
|
const agentStep = createStep({
|
|
12259
12705
|
id: "agent-execution-step",
|
|
12260
|
-
inputSchema:
|
|
12261
|
-
task:
|
|
12262
|
-
primitiveId:
|
|
12706
|
+
inputSchema: z8.object({
|
|
12707
|
+
task: z8.string(),
|
|
12708
|
+
primitiveId: z8.string(),
|
|
12263
12709
|
primitiveType: PRIMITIVE_TYPES,
|
|
12264
|
-
prompt:
|
|
12265
|
-
result:
|
|
12266
|
-
isComplete:
|
|
12267
|
-
selectionReason:
|
|
12268
|
-
iteration:
|
|
12710
|
+
prompt: z8.string(),
|
|
12711
|
+
result: z8.string(),
|
|
12712
|
+
isComplete: z8.boolean().optional(),
|
|
12713
|
+
selectionReason: z8.string(),
|
|
12714
|
+
iteration: z8.number()
|
|
12269
12715
|
}),
|
|
12270
|
-
outputSchema:
|
|
12271
|
-
task:
|
|
12272
|
-
primitiveId:
|
|
12716
|
+
outputSchema: z8.object({
|
|
12717
|
+
task: z8.string(),
|
|
12718
|
+
primitiveId: z8.string(),
|
|
12273
12719
|
primitiveType: PRIMITIVE_TYPES,
|
|
12274
|
-
result:
|
|
12275
|
-
isComplete:
|
|
12276
|
-
iteration:
|
|
12720
|
+
result: z8.string(),
|
|
12721
|
+
isComplete: z8.boolean().optional(),
|
|
12722
|
+
iteration: z8.number()
|
|
12277
12723
|
}),
|
|
12278
12724
|
execute: async ({ inputData, writer, getInitData }) => {
|
|
12279
12725
|
const agentsMap = await agent.listAgents({ requestContext });
|
|
@@ -12288,7 +12734,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12288
12734
|
throw mastraError;
|
|
12289
12735
|
}
|
|
12290
12736
|
const agentId = agentForStep.id;
|
|
12291
|
-
const stepId =
|
|
12737
|
+
const stepId = generateId2();
|
|
12292
12738
|
await writer.write({
|
|
12293
12739
|
type: "agent-execution-start",
|
|
12294
12740
|
payload: {
|
|
@@ -12329,7 +12775,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12329
12775
|
await memory?.saveMessages({
|
|
12330
12776
|
messages: [
|
|
12331
12777
|
{
|
|
12332
|
-
id:
|
|
12778
|
+
id: generateId2(),
|
|
12333
12779
|
type: "text",
|
|
12334
12780
|
role: "assistant",
|
|
12335
12781
|
content: {
|
|
@@ -12342,7 +12788,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12342
12788
|
primitiveType: inputData.primitiveType,
|
|
12343
12789
|
primitiveId: inputData.primitiveId,
|
|
12344
12790
|
input: inputData.prompt,
|
|
12345
|
-
finalResult: { text: await result.text,
|
|
12791
|
+
finalResult: { text: await result.text, messages }
|
|
12346
12792
|
})
|
|
12347
12793
|
}
|
|
12348
12794
|
],
|
|
@@ -12383,23 +12829,23 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12383
12829
|
});
|
|
12384
12830
|
const workflowStep = createStep({
|
|
12385
12831
|
id: "workflow-execution-step",
|
|
12386
|
-
inputSchema:
|
|
12387
|
-
task:
|
|
12388
|
-
primitiveId:
|
|
12832
|
+
inputSchema: z8.object({
|
|
12833
|
+
task: z8.string(),
|
|
12834
|
+
primitiveId: z8.string(),
|
|
12389
12835
|
primitiveType: PRIMITIVE_TYPES,
|
|
12390
|
-
prompt:
|
|
12391
|
-
result:
|
|
12392
|
-
isComplete:
|
|
12393
|
-
selectionReason:
|
|
12394
|
-
iteration:
|
|
12836
|
+
prompt: z8.string(),
|
|
12837
|
+
result: z8.string(),
|
|
12838
|
+
isComplete: z8.boolean().optional(),
|
|
12839
|
+
selectionReason: z8.string(),
|
|
12840
|
+
iteration: z8.number()
|
|
12395
12841
|
}),
|
|
12396
|
-
outputSchema:
|
|
12397
|
-
task:
|
|
12398
|
-
primitiveId:
|
|
12842
|
+
outputSchema: z8.object({
|
|
12843
|
+
task: z8.string(),
|
|
12844
|
+
primitiveId: z8.string(),
|
|
12399
12845
|
primitiveType: PRIMITIVE_TYPES,
|
|
12400
|
-
result:
|
|
12401
|
-
isComplete:
|
|
12402
|
-
iteration:
|
|
12846
|
+
result: z8.string(),
|
|
12847
|
+
isComplete: z8.boolean().optional(),
|
|
12848
|
+
iteration: z8.number()
|
|
12403
12849
|
}),
|
|
12404
12850
|
execute: async ({ inputData, writer, getInitData }) => {
|
|
12405
12851
|
const workflowsMap = await agent.listWorkflows({ requestContext });
|
|
@@ -12429,7 +12875,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12429
12875
|
);
|
|
12430
12876
|
throw mastraError;
|
|
12431
12877
|
}
|
|
12432
|
-
const stepId =
|
|
12878
|
+
const stepId = generateId2();
|
|
12433
12879
|
const run = await wf.createRun({ runId });
|
|
12434
12880
|
const toolData = {
|
|
12435
12881
|
workflowId: wf.id,
|
|
@@ -12482,7 +12928,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12482
12928
|
await memory?.saveMessages({
|
|
12483
12929
|
messages: [
|
|
12484
12930
|
{
|
|
12485
|
-
id:
|
|
12931
|
+
id: generateId2(),
|
|
12486
12932
|
type: "text",
|
|
12487
12933
|
role: "assistant",
|
|
12488
12934
|
content: { parts: [{ type: "text", text: finalResult }], format: 2 },
|
|
@@ -12517,23 +12963,23 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12517
12963
|
});
|
|
12518
12964
|
const toolStep = createStep({
|
|
12519
12965
|
id: "tool-execution-step",
|
|
12520
|
-
inputSchema:
|
|
12521
|
-
task:
|
|
12522
|
-
primitiveId:
|
|
12966
|
+
inputSchema: z8.object({
|
|
12967
|
+
task: z8.string(),
|
|
12968
|
+
primitiveId: z8.string(),
|
|
12523
12969
|
primitiveType: PRIMITIVE_TYPES,
|
|
12524
|
-
prompt:
|
|
12525
|
-
result:
|
|
12526
|
-
isComplete:
|
|
12527
|
-
selectionReason:
|
|
12528
|
-
iteration:
|
|
12970
|
+
prompt: z8.string(),
|
|
12971
|
+
result: z8.string(),
|
|
12972
|
+
isComplete: z8.boolean().optional(),
|
|
12973
|
+
selectionReason: z8.string(),
|
|
12974
|
+
iteration: z8.number()
|
|
12529
12975
|
}),
|
|
12530
|
-
outputSchema:
|
|
12531
|
-
task:
|
|
12532
|
-
primitiveId:
|
|
12976
|
+
outputSchema: z8.object({
|
|
12977
|
+
task: z8.string(),
|
|
12978
|
+
primitiveId: z8.string(),
|
|
12533
12979
|
primitiveType: PRIMITIVE_TYPES,
|
|
12534
|
-
result:
|
|
12535
|
-
isComplete:
|
|
12536
|
-
iteration:
|
|
12980
|
+
result: z8.string(),
|
|
12981
|
+
isComplete: z8.boolean().optional(),
|
|
12982
|
+
iteration: z8.number()
|
|
12537
12983
|
}),
|
|
12538
12984
|
execute: async ({ inputData, getInitData, writer }) => {
|
|
12539
12985
|
const initData = await getInitData();
|
|
@@ -12541,8 +12987,8 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12541
12987
|
const memory = await agent.getMemory({ requestContext });
|
|
12542
12988
|
const memoryTools = await memory?.listTools?.();
|
|
12543
12989
|
const toolsMap = { ...agentTools, ...memoryTools };
|
|
12544
|
-
let
|
|
12545
|
-
if (!
|
|
12990
|
+
let tool2 = toolsMap[inputData.primitiveId];
|
|
12991
|
+
if (!tool2) {
|
|
12546
12992
|
const mastraError = new MastraError({
|
|
12547
12993
|
id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
12548
12994
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
@@ -12551,7 +12997,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12551
12997
|
});
|
|
12552
12998
|
throw mastraError;
|
|
12553
12999
|
}
|
|
12554
|
-
if (!
|
|
13000
|
+
if (!tool2.execute) {
|
|
12555
13001
|
const mastraError = new MastraError({
|
|
12556
13002
|
id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
12557
13003
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
@@ -12560,7 +13006,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12560
13006
|
});
|
|
12561
13007
|
throw mastraError;
|
|
12562
13008
|
}
|
|
12563
|
-
const toolId =
|
|
13009
|
+
const toolId = tool2.id;
|
|
12564
13010
|
let inputDataToUse;
|
|
12565
13011
|
try {
|
|
12566
13012
|
inputDataToUse = JSON.parse(inputData.prompt);
|
|
@@ -12576,7 +13022,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12576
13022
|
);
|
|
12577
13023
|
throw mastraError;
|
|
12578
13024
|
}
|
|
12579
|
-
const toolCallId =
|
|
13025
|
+
const toolCallId = generateId2();
|
|
12580
13026
|
await writer?.write({
|
|
12581
13027
|
type: "tool-execution-start",
|
|
12582
13028
|
payload: {
|
|
@@ -12591,7 +13037,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12591
13037
|
from: "NETWORK" /* NETWORK */,
|
|
12592
13038
|
runId
|
|
12593
13039
|
});
|
|
12594
|
-
const finalResult = await
|
|
13040
|
+
const finalResult = await tool2.execute(
|
|
12595
13041
|
inputDataToUse,
|
|
12596
13042
|
{
|
|
12597
13043
|
requestContext,
|
|
@@ -12613,7 +13059,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12613
13059
|
await memory?.saveMessages({
|
|
12614
13060
|
messages: [
|
|
12615
13061
|
{
|
|
12616
|
-
id:
|
|
13062
|
+
id: generateId2(),
|
|
12617
13063
|
type: "text",
|
|
12618
13064
|
role: "assistant",
|
|
12619
13065
|
content: {
|
|
@@ -12659,21 +13105,21 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12659
13105
|
});
|
|
12660
13106
|
const finishStep = createStep({
|
|
12661
13107
|
id: "finish-step",
|
|
12662
|
-
inputSchema:
|
|
12663
|
-
task:
|
|
12664
|
-
primitiveId:
|
|
13108
|
+
inputSchema: z8.object({
|
|
13109
|
+
task: z8.string(),
|
|
13110
|
+
primitiveId: z8.string(),
|
|
12665
13111
|
primitiveType: PRIMITIVE_TYPES,
|
|
12666
|
-
prompt:
|
|
12667
|
-
result:
|
|
12668
|
-
isComplete:
|
|
12669
|
-
selectionReason:
|
|
12670
|
-
iteration:
|
|
13112
|
+
prompt: z8.string(),
|
|
13113
|
+
result: z8.string(),
|
|
13114
|
+
isComplete: z8.boolean().optional(),
|
|
13115
|
+
selectionReason: z8.string(),
|
|
13116
|
+
iteration: z8.number()
|
|
12671
13117
|
}),
|
|
12672
|
-
outputSchema:
|
|
12673
|
-
task:
|
|
12674
|
-
result:
|
|
12675
|
-
isComplete:
|
|
12676
|
-
iteration:
|
|
13118
|
+
outputSchema: z8.object({
|
|
13119
|
+
task: z8.string(),
|
|
13120
|
+
result: z8.string(),
|
|
13121
|
+
isComplete: z8.boolean(),
|
|
13122
|
+
iteration: z8.number()
|
|
12677
13123
|
}),
|
|
12678
13124
|
execute: async ({ inputData, writer }) => {
|
|
12679
13125
|
let endResult = inputData.result;
|
|
@@ -12698,29 +13144,29 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12698
13144
|
});
|
|
12699
13145
|
const networkWorkflow = createWorkflow({
|
|
12700
13146
|
id: "Agent-Network-Outer-Workflow",
|
|
12701
|
-
inputSchema:
|
|
12702
|
-
task:
|
|
12703
|
-
primitiveId:
|
|
13147
|
+
inputSchema: z8.object({
|
|
13148
|
+
task: z8.string(),
|
|
13149
|
+
primitiveId: z8.string(),
|
|
12704
13150
|
primitiveType: PRIMITIVE_TYPES,
|
|
12705
|
-
result:
|
|
12706
|
-
iteration:
|
|
12707
|
-
threadId:
|
|
12708
|
-
threadResourceId:
|
|
12709
|
-
isOneOff:
|
|
12710
|
-
verboseIntrospection:
|
|
13151
|
+
result: z8.string().optional(),
|
|
13152
|
+
iteration: z8.number(),
|
|
13153
|
+
threadId: z8.string().optional(),
|
|
13154
|
+
threadResourceId: z8.string().optional(),
|
|
13155
|
+
isOneOff: z8.boolean(),
|
|
13156
|
+
verboseIntrospection: z8.boolean()
|
|
12711
13157
|
}),
|
|
12712
|
-
outputSchema:
|
|
12713
|
-
task:
|
|
12714
|
-
primitiveId:
|
|
13158
|
+
outputSchema: z8.object({
|
|
13159
|
+
task: z8.string(),
|
|
13160
|
+
primitiveId: z8.string(),
|
|
12715
13161
|
primitiveType: PRIMITIVE_TYPES,
|
|
12716
|
-
prompt:
|
|
12717
|
-
result:
|
|
12718
|
-
isComplete:
|
|
12719
|
-
completionReason:
|
|
12720
|
-
iteration:
|
|
12721
|
-
threadId:
|
|
12722
|
-
threadResourceId:
|
|
12723
|
-
isOneOff:
|
|
13162
|
+
prompt: z8.string(),
|
|
13163
|
+
result: z8.string(),
|
|
13164
|
+
isComplete: z8.boolean().optional(),
|
|
13165
|
+
completionReason: z8.string().optional(),
|
|
13166
|
+
iteration: z8.number(),
|
|
13167
|
+
threadId: z8.string().optional(),
|
|
13168
|
+
threadResourceId: z8.string().optional(),
|
|
13169
|
+
isOneOff: z8.boolean()
|
|
12724
13170
|
}),
|
|
12725
13171
|
options: {
|
|
12726
13172
|
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
|
|
@@ -12782,7 +13228,7 @@ async function networkLoop({
|
|
|
12782
13228
|
runId,
|
|
12783
13229
|
routingAgent,
|
|
12784
13230
|
routingAgentOptions,
|
|
12785
|
-
generateId:
|
|
13231
|
+
generateId: generateId2,
|
|
12786
13232
|
maxIterations,
|
|
12787
13233
|
threadId,
|
|
12788
13234
|
resourceId,
|
|
@@ -12807,7 +13253,7 @@ async function networkLoop({
|
|
|
12807
13253
|
runId,
|
|
12808
13254
|
agent: routingAgent,
|
|
12809
13255
|
routingAgentOptions: routingAgentOptionsWithoutMemory,
|
|
12810
|
-
generateId:
|
|
13256
|
+
generateId: generateId2
|
|
12811
13257
|
});
|
|
12812
13258
|
const finalStep = createStep({
|
|
12813
13259
|
id: "final-step",
|
|
@@ -12829,26 +13275,26 @@ async function networkLoop({
|
|
|
12829
13275
|
});
|
|
12830
13276
|
const mainWorkflow = createWorkflow({
|
|
12831
13277
|
id: "agent-loop-main-workflow",
|
|
12832
|
-
inputSchema:
|
|
12833
|
-
iteration:
|
|
12834
|
-
task:
|
|
12835
|
-
primitiveId:
|
|
13278
|
+
inputSchema: z8.object({
|
|
13279
|
+
iteration: z8.number(),
|
|
13280
|
+
task: z8.string(),
|
|
13281
|
+
primitiveId: z8.string(),
|
|
12836
13282
|
primitiveType: PRIMITIVE_TYPES,
|
|
12837
|
-
result:
|
|
12838
|
-
threadId:
|
|
12839
|
-
threadResourceId:
|
|
12840
|
-
isOneOff:
|
|
12841
|
-
verboseIntrospection:
|
|
13283
|
+
result: z8.string().optional(),
|
|
13284
|
+
threadId: z8.string().optional(),
|
|
13285
|
+
threadResourceId: z8.string().optional(),
|
|
13286
|
+
isOneOff: z8.boolean(),
|
|
13287
|
+
verboseIntrospection: z8.boolean()
|
|
12842
13288
|
}),
|
|
12843
|
-
outputSchema:
|
|
12844
|
-
task:
|
|
12845
|
-
primitiveId:
|
|
13289
|
+
outputSchema: z8.object({
|
|
13290
|
+
task: z8.string(),
|
|
13291
|
+
primitiveId: z8.string(),
|
|
12846
13292
|
primitiveType: PRIMITIVE_TYPES,
|
|
12847
|
-
prompt:
|
|
12848
|
-
result:
|
|
12849
|
-
isComplete:
|
|
12850
|
-
completionReason:
|
|
12851
|
-
iteration:
|
|
13293
|
+
prompt: z8.string(),
|
|
13294
|
+
result: z8.string(),
|
|
13295
|
+
isComplete: z8.boolean().optional(),
|
|
13296
|
+
completionReason: z8.string().optional(),
|
|
13297
|
+
iteration: z8.number()
|
|
12852
13298
|
}),
|
|
12853
13299
|
options: {
|
|
12854
13300
|
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
|
|
@@ -12866,7 +13312,7 @@ async function networkLoop({
|
|
|
12866
13312
|
resourceId: resourceId || networkName,
|
|
12867
13313
|
messages,
|
|
12868
13314
|
routingAgent,
|
|
12869
|
-
generateId:
|
|
13315
|
+
generateId: generateId2,
|
|
12870
13316
|
tracingContext: routingAgentOptions?.tracingContext,
|
|
12871
13317
|
memoryConfig: routingAgentMemoryOptions?.options
|
|
12872
13318
|
});
|
|
@@ -12893,67 +13339,6 @@ async function networkLoop({
|
|
|
12893
13339
|
|
|
12894
13340
|
// src/agent/agent-legacy.ts
|
|
12895
13341
|
var import_fast_deep_equal = __toESM(require_fast_deep_equal(), 1);
|
|
12896
|
-
|
|
12897
|
-
// src/agent/utils.ts
|
|
12898
|
-
async function tryGenerateWithJsonFallback(agent, prompt, options) {
|
|
12899
|
-
if (!options.structuredOutput?.schema) {
|
|
12900
|
-
throw new MastraError({
|
|
12901
|
-
id: "STRUCTURED_OUTPUT_OPTIONS_REQUIRED",
|
|
12902
|
-
domain: "AGENT" /* AGENT */,
|
|
12903
|
-
category: "USER" /* USER */,
|
|
12904
|
-
text: "structuredOutput is required to use tryGenerateWithJsonFallback"
|
|
12905
|
-
});
|
|
12906
|
-
}
|
|
12907
|
-
try {
|
|
12908
|
-
return await agent.generate(prompt, options);
|
|
12909
|
-
} catch (error) {
|
|
12910
|
-
console.warn("Error in tryGenerateWithJsonFallback. Attempting fallback.", error);
|
|
12911
|
-
return await agent.generate(prompt, {
|
|
12912
|
-
...options,
|
|
12913
|
-
structuredOutput: { ...options.structuredOutput, jsonPromptInjection: true }
|
|
12914
|
-
});
|
|
12915
|
-
}
|
|
12916
|
-
}
|
|
12917
|
-
async function tryStreamWithJsonFallback(agent, prompt, options) {
|
|
12918
|
-
if (!options.structuredOutput?.schema) {
|
|
12919
|
-
throw new MastraError({
|
|
12920
|
-
id: "STRUCTURED_OUTPUT_OPTIONS_REQUIRED",
|
|
12921
|
-
domain: "AGENT" /* AGENT */,
|
|
12922
|
-
category: "USER" /* USER */,
|
|
12923
|
-
text: "structuredOutput is required to use tryStreamWithJsonFallback"
|
|
12924
|
-
});
|
|
12925
|
-
}
|
|
12926
|
-
try {
|
|
12927
|
-
const result = await agent.stream(prompt, options);
|
|
12928
|
-
const object = await result.object;
|
|
12929
|
-
if (!object) {
|
|
12930
|
-
throw new MastraError({
|
|
12931
|
-
id: "STRUCTURED_OUTPUT_OBJECT_UNDEFINED",
|
|
12932
|
-
domain: "AGENT" /* AGENT */,
|
|
12933
|
-
category: "USER" /* USER */,
|
|
12934
|
-
text: "structuredOutput object is undefined"
|
|
12935
|
-
});
|
|
12936
|
-
}
|
|
12937
|
-
return result;
|
|
12938
|
-
} catch (error) {
|
|
12939
|
-
console.warn("Error in tryStreamWithJsonFallback. Attempting fallback.", error);
|
|
12940
|
-
return await agent.stream(prompt, {
|
|
12941
|
-
...options,
|
|
12942
|
-
structuredOutput: { ...options.structuredOutput, jsonPromptInjection: true }
|
|
12943
|
-
});
|
|
12944
|
-
}
|
|
12945
|
-
}
|
|
12946
|
-
function resolveThreadIdFromArgs(args) {
|
|
12947
|
-
if (args?.memory?.thread) {
|
|
12948
|
-
if (typeof args.memory.thread === "string") return { id: args.memory.thread };
|
|
12949
|
-
if (typeof args.memory.thread === "object" && args.memory.thread.id)
|
|
12950
|
-
return args.memory.thread;
|
|
12951
|
-
}
|
|
12952
|
-
if (args?.threadId) return { id: args.threadId };
|
|
12953
|
-
return void 0;
|
|
12954
|
-
}
|
|
12955
|
-
|
|
12956
|
-
// src/agent/agent-legacy.ts
|
|
12957
13342
|
var AgentLegacyHandler = class {
|
|
12958
13343
|
constructor(capabilities) {
|
|
12959
13344
|
this.capabilities = capabilities;
|
|
@@ -14033,6 +14418,14 @@ function createMapResultsStep({
|
|
|
14033
14418
|
};
|
|
14034
14419
|
if (result.tripwire) {
|
|
14035
14420
|
const agentModel = await capabilities.getModel({ requestContext: result.requestContext });
|
|
14421
|
+
if (!isSupportedLanguageModel(agentModel)) {
|
|
14422
|
+
throw new MastraError({
|
|
14423
|
+
id: "MAP_RESULTS_STEP_UNSUPPORTED_MODEL",
|
|
14424
|
+
domain: "AGENT" /* AGENT */,
|
|
14425
|
+
category: "USER" /* USER */,
|
|
14426
|
+
text: "Tripwire handling requires a v2/v3 model"
|
|
14427
|
+
});
|
|
14428
|
+
}
|
|
14036
14429
|
const modelOutput = await getModelOutputForTripwire({
|
|
14037
14430
|
tripwire: memoryData.tripwire,
|
|
14038
14431
|
runId,
|
|
@@ -14331,7 +14724,8 @@ function createPrepareToolsStep({
|
|
|
14331
14724
|
tracingContext: { currentSpan: agentSpan },
|
|
14332
14725
|
outputWriter: options.outputWriter,
|
|
14333
14726
|
methodType,
|
|
14334
|
-
memoryConfig: options.memory?.options
|
|
14727
|
+
memoryConfig: options.memory?.options,
|
|
14728
|
+
autoResumeSuspendedTools: options.autoResumeSuspendedTools
|
|
14335
14729
|
});
|
|
14336
14730
|
return {
|
|
14337
14731
|
convertedTools
|
|
@@ -14344,6 +14738,7 @@ function createStreamStep({
|
|
|
14344
14738
|
runId,
|
|
14345
14739
|
returnScorerData,
|
|
14346
14740
|
requireToolApproval,
|
|
14741
|
+
toolCallConcurrency,
|
|
14347
14742
|
resumeContext,
|
|
14348
14743
|
agentId,
|
|
14349
14744
|
agentName,
|
|
@@ -14352,7 +14747,8 @@ function createStreamStep({
|
|
|
14352
14747
|
saveQueueManager,
|
|
14353
14748
|
memoryConfig,
|
|
14354
14749
|
memory,
|
|
14355
|
-
resourceId
|
|
14750
|
+
resourceId,
|
|
14751
|
+
autoResumeSuspendedTools
|
|
14356
14752
|
}) {
|
|
14357
14753
|
return createStep({
|
|
14358
14754
|
id: "stream-text-step",
|
|
@@ -14377,6 +14773,7 @@ function createStreamStep({
|
|
|
14377
14773
|
returnScorerData,
|
|
14378
14774
|
tracingContext,
|
|
14379
14775
|
requireToolApproval,
|
|
14776
|
+
toolCallConcurrency,
|
|
14380
14777
|
resumeContext,
|
|
14381
14778
|
_internal: {
|
|
14382
14779
|
generateId: capabilities.generateMessageId,
|
|
@@ -14389,7 +14786,8 @@ function createStreamStep({
|
|
|
14389
14786
|
agentId,
|
|
14390
14787
|
agentName,
|
|
14391
14788
|
toolCallId,
|
|
14392
|
-
methodType: modelMethodType
|
|
14789
|
+
methodType: modelMethodType,
|
|
14790
|
+
autoResumeSuspendedTools
|
|
14393
14791
|
});
|
|
14394
14792
|
return streamResult;
|
|
14395
14793
|
}
|
|
@@ -14412,6 +14810,7 @@ function createPrepareStreamWorkflow({
|
|
|
14412
14810
|
returnScorerData,
|
|
14413
14811
|
saveQueueManager,
|
|
14414
14812
|
requireToolApproval,
|
|
14813
|
+
toolCallConcurrency,
|
|
14415
14814
|
resumeContext,
|
|
14416
14815
|
agentId,
|
|
14417
14816
|
agentName,
|
|
@@ -14444,6 +14843,7 @@ function createPrepareStreamWorkflow({
|
|
|
14444
14843
|
runId,
|
|
14445
14844
|
returnScorerData,
|
|
14446
14845
|
requireToolApproval,
|
|
14846
|
+
toolCallConcurrency,
|
|
14447
14847
|
resumeContext,
|
|
14448
14848
|
agentId,
|
|
14449
14849
|
agentName,
|
|
@@ -14452,7 +14852,8 @@ function createPrepareStreamWorkflow({
|
|
|
14452
14852
|
saveQueueManager,
|
|
14453
14853
|
memoryConfig,
|
|
14454
14854
|
memory,
|
|
14455
|
-
resourceId
|
|
14855
|
+
resourceId,
|
|
14856
|
+
autoResumeSuspendedTools: options.autoResumeSuspendedTools
|
|
14456
14857
|
});
|
|
14457
14858
|
const mapResultsStep = createMapResultsStep({
|
|
14458
14859
|
capabilities,
|
|
@@ -14666,7 +15067,6 @@ var Agent = class extends MastraBase {
|
|
|
14666
15067
|
}) {
|
|
14667
15068
|
const inputProcessors = inputProcessorOverrides ?? await this.listResolvedInputProcessors(requestContext);
|
|
14668
15069
|
const outputProcessors = outputProcessorOverrides ?? await this.listResolvedOutputProcessors(requestContext);
|
|
14669
|
-
this.logger.debug("outputProcessors", outputProcessors);
|
|
14670
15070
|
return new ProcessorRunner({
|
|
14671
15071
|
inputProcessors,
|
|
14672
15072
|
outputProcessors,
|
|
@@ -14706,7 +15106,8 @@ var Agent = class extends MastraBase {
|
|
|
14706
15106
|
id: workflowId,
|
|
14707
15107
|
inputSchema: ProcessorStepSchema,
|
|
14708
15108
|
outputSchema: ProcessorStepSchema,
|
|
14709
|
-
type: "processor"
|
|
15109
|
+
type: "processor",
|
|
15110
|
+
options: { validateInputs: false }
|
|
14710
15111
|
});
|
|
14711
15112
|
for (const processorOrWorkflow of validProcessors) {
|
|
14712
15113
|
const step = isProcessorWorkflow(processorOrWorkflow) ? processorOrWorkflow : createStep(processorOrWorkflow);
|
|
@@ -15184,7 +15585,7 @@ var Agent = class extends MastraBase {
|
|
|
15184
15585
|
const modelToUse = this.getModel({ modelConfig: model, requestContext });
|
|
15185
15586
|
return resolveMaybePromise(modelToUse, (resolvedModel) => {
|
|
15186
15587
|
let llm;
|
|
15187
|
-
if (resolvedModel
|
|
15588
|
+
if (isSupportedLanguageModel(resolvedModel)) {
|
|
15188
15589
|
const modelsPromise = Array.isArray(this.model) && !model ? this.prepareModels(requestContext) : this.prepareModels(requestContext, resolvedModel);
|
|
15189
15590
|
llm = modelsPromise.then((models) => {
|
|
15190
15591
|
const enabledModels = models.filter((model2) => model2.enabled);
|
|
@@ -15373,11 +15774,11 @@ var Agent = class extends MastraBase {
|
|
|
15373
15774
|
__registerMastra(mastra) {
|
|
15374
15775
|
this.#mastra = mastra;
|
|
15375
15776
|
if (this.#tools && typeof this.#tools === "object") {
|
|
15376
|
-
Object.entries(this.#tools).forEach(([key,
|
|
15777
|
+
Object.entries(this.#tools).forEach(([key, tool2]) => {
|
|
15377
15778
|
try {
|
|
15378
|
-
if (
|
|
15379
|
-
const toolKey = typeof
|
|
15380
|
-
mastra.addTool(
|
|
15779
|
+
if (tool2 && typeof tool2 === "object" && "id" in tool2) {
|
|
15780
|
+
const toolKey = typeof tool2.id === "string" ? tool2.id : key;
|
|
15781
|
+
mastra.addTool(tool2, toolKey);
|
|
15381
15782
|
}
|
|
15382
15783
|
} catch (error) {
|
|
15383
15784
|
if (error instanceof MastraError && error.id !== "MASTRA_ADD_TOOL_DUPLICATE_KEY") {
|
|
@@ -15448,7 +15849,7 @@ var Agent = class extends MastraBase {
|
|
|
15448
15849
|
}
|
|
15449
15850
|
const systemInstructions = await this.resolveTitleInstructions(requestContext, instructions);
|
|
15450
15851
|
let text = "";
|
|
15451
|
-
if (llm.getModel()
|
|
15852
|
+
if (isSupportedLanguageModel(llm.getModel())) {
|
|
15452
15853
|
const messageList = new MessageList().add(
|
|
15453
15854
|
[
|
|
15454
15855
|
{
|
|
@@ -15533,7 +15934,8 @@ var Agent = class extends MastraBase {
|
|
|
15533
15934
|
requestContext,
|
|
15534
15935
|
tracingContext,
|
|
15535
15936
|
mastraProxy,
|
|
15536
|
-
memoryConfig
|
|
15937
|
+
memoryConfig,
|
|
15938
|
+
autoResumeSuspendedTools
|
|
15537
15939
|
}) {
|
|
15538
15940
|
let convertedMemoryTools = {};
|
|
15539
15941
|
if (this._agentNetworkAppend) {
|
|
@@ -15549,8 +15951,8 @@ var Agent = class extends MastraBase {
|
|
|
15549
15951
|
runId
|
|
15550
15952
|
}
|
|
15551
15953
|
);
|
|
15552
|
-
for (const [toolName,
|
|
15553
|
-
const toolObj =
|
|
15954
|
+
for (const [toolName, tool2] of Object.entries(memoryTools)) {
|
|
15955
|
+
const toolObj = tool2;
|
|
15554
15956
|
const options = {
|
|
15555
15957
|
name: toolName,
|
|
15556
15958
|
runId,
|
|
@@ -15566,7 +15968,7 @@ var Agent = class extends MastraBase {
|
|
|
15566
15968
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
15567
15969
|
requireApproval: toolObj.requireApproval
|
|
15568
15970
|
};
|
|
15569
|
-
const convertedToCoreTool = makeCoreTool(toolObj, options);
|
|
15971
|
+
const convertedToCoreTool = makeCoreTool(toolObj, options, void 0, autoResumeSuspendedTools);
|
|
15570
15972
|
convertedMemoryTools[toolName] = convertedToCoreTool;
|
|
15571
15973
|
}
|
|
15572
15974
|
}
|
|
@@ -15692,7 +16094,8 @@ var Agent = class extends MastraBase {
|
|
|
15692
16094
|
requestContext,
|
|
15693
16095
|
tracingContext,
|
|
15694
16096
|
mastraProxy,
|
|
15695
|
-
outputWriter
|
|
16097
|
+
outputWriter,
|
|
16098
|
+
autoResumeSuspendedTools
|
|
15696
16099
|
}) {
|
|
15697
16100
|
let toolsForRequest = {};
|
|
15698
16101
|
this.logger.debug(`[Agents:${this.name}] - Assembling assigned tools`, { runId, threadId, resourceId });
|
|
@@ -15700,8 +16103,8 @@ var Agent = class extends MastraBase {
|
|
|
15700
16103
|
const assignedTools = await this.listTools({ requestContext });
|
|
15701
16104
|
const assignedToolEntries = Object.entries(assignedTools || {});
|
|
15702
16105
|
const assignedCoreToolEntries = await Promise.all(
|
|
15703
|
-
assignedToolEntries.map(async ([k,
|
|
15704
|
-
if (!
|
|
16106
|
+
assignedToolEntries.map(async ([k, tool2]) => {
|
|
16107
|
+
if (!tool2) {
|
|
15705
16108
|
return;
|
|
15706
16109
|
}
|
|
15707
16110
|
const options = {
|
|
@@ -15718,9 +16121,9 @@ var Agent = class extends MastraBase {
|
|
|
15718
16121
|
model: await this.getModel({ requestContext }),
|
|
15719
16122
|
outputWriter,
|
|
15720
16123
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
15721
|
-
requireApproval:
|
|
16124
|
+
requireApproval: tool2.requireApproval
|
|
15722
16125
|
};
|
|
15723
|
-
return [k, makeCoreTool(
|
|
16126
|
+
return [k, makeCoreTool(tool2, options, void 0, autoResumeSuspendedTools)];
|
|
15724
16127
|
})
|
|
15725
16128
|
);
|
|
15726
16129
|
const assignedToolEntriesConverted = Object.fromEntries(
|
|
@@ -15742,7 +16145,8 @@ var Agent = class extends MastraBase {
|
|
|
15742
16145
|
toolsets,
|
|
15743
16146
|
requestContext,
|
|
15744
16147
|
tracingContext,
|
|
15745
|
-
mastraProxy
|
|
16148
|
+
mastraProxy,
|
|
16149
|
+
autoResumeSuspendedTools
|
|
15746
16150
|
}) {
|
|
15747
16151
|
let toolsForRequest = {};
|
|
15748
16152
|
const memory = await this.getMemory({ requestContext });
|
|
@@ -15752,8 +16156,8 @@ var Agent = class extends MastraBase {
|
|
|
15752
16156
|
runId
|
|
15753
16157
|
});
|
|
15754
16158
|
for (const toolset of toolsFromToolsets) {
|
|
15755
|
-
for (const [toolName,
|
|
15756
|
-
const toolObj =
|
|
16159
|
+
for (const [toolName, tool2] of Object.entries(toolset)) {
|
|
16160
|
+
const toolObj = tool2;
|
|
15757
16161
|
const options = {
|
|
15758
16162
|
name: toolName,
|
|
15759
16163
|
runId,
|
|
@@ -15769,7 +16173,7 @@ var Agent = class extends MastraBase {
|
|
|
15769
16173
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
15770
16174
|
requireApproval: toolObj.requireApproval
|
|
15771
16175
|
};
|
|
15772
|
-
const convertedToCoreTool = makeCoreTool(toolObj, options, "toolset");
|
|
16176
|
+
const convertedToCoreTool = makeCoreTool(toolObj, options, "toolset", autoResumeSuspendedTools);
|
|
15773
16177
|
toolsForRequest[toolName] = convertedToCoreTool;
|
|
15774
16178
|
}
|
|
15775
16179
|
}
|
|
@@ -15787,7 +16191,8 @@ var Agent = class extends MastraBase {
|
|
|
15787
16191
|
requestContext,
|
|
15788
16192
|
tracingContext,
|
|
15789
16193
|
mastraProxy,
|
|
15790
|
-
clientTools
|
|
16194
|
+
clientTools,
|
|
16195
|
+
autoResumeSuspendedTools
|
|
15791
16196
|
}) {
|
|
15792
16197
|
let toolsForRequest = {};
|
|
15793
16198
|
const memory = await this.getMemory({ requestContext });
|
|
@@ -15796,8 +16201,8 @@ var Agent = class extends MastraBase {
|
|
|
15796
16201
|
this.logger.debug(`[Agent:${this.name}] - Adding client tools ${Object.keys(clientTools || {}).join(", ")}`, {
|
|
15797
16202
|
runId
|
|
15798
16203
|
});
|
|
15799
|
-
for (const [toolName,
|
|
15800
|
-
const { execute: execute2, ...rest } =
|
|
16204
|
+
for (const [toolName, tool2] of clientToolsForInput) {
|
|
16205
|
+
const { execute: execute2, ...rest } = tool2;
|
|
15801
16206
|
const options = {
|
|
15802
16207
|
name: toolName,
|
|
15803
16208
|
runId,
|
|
@@ -15811,9 +16216,9 @@ var Agent = class extends MastraBase {
|
|
|
15811
16216
|
tracingContext,
|
|
15812
16217
|
model: await this.getModel({ requestContext }),
|
|
15813
16218
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
15814
|
-
requireApproval:
|
|
16219
|
+
requireApproval: tool2.requireApproval
|
|
15815
16220
|
};
|
|
15816
|
-
const convertedToCoreTool = makeCoreTool(rest, options, "client-tool");
|
|
16221
|
+
const convertedToCoreTool = makeCoreTool(rest, options, "client-tool", autoResumeSuspendedTools);
|
|
15817
16222
|
toolsForRequest[toolName] = convertedToCoreTool;
|
|
15818
16223
|
}
|
|
15819
16224
|
}
|
|
@@ -15829,7 +16234,8 @@ var Agent = class extends MastraBase {
|
|
|
15829
16234
|
resourceId,
|
|
15830
16235
|
requestContext,
|
|
15831
16236
|
tracingContext,
|
|
15832
|
-
methodType
|
|
16237
|
+
methodType,
|
|
16238
|
+
autoResumeSuspendedTools
|
|
15833
16239
|
}) {
|
|
15834
16240
|
const convertedAgentTools = {};
|
|
15835
16241
|
const agents = await this.listAgents({ requestContext });
|
|
@@ -15982,7 +16388,12 @@ var Agent = class extends MastraBase {
|
|
|
15982
16388
|
tracingContext,
|
|
15983
16389
|
tracingPolicy: this.#options?.tracingPolicy
|
|
15984
16390
|
};
|
|
15985
|
-
convertedAgentTools[`agent-${agentName}`] = makeCoreTool(
|
|
16391
|
+
convertedAgentTools[`agent-${agentName}`] = makeCoreTool(
|
|
16392
|
+
toolObj,
|
|
16393
|
+
options,
|
|
16394
|
+
void 0,
|
|
16395
|
+
autoResumeSuspendedTools
|
|
16396
|
+
);
|
|
15986
16397
|
}
|
|
15987
16398
|
}
|
|
15988
16399
|
return convertedAgentTools;
|
|
@@ -15997,7 +16408,8 @@ var Agent = class extends MastraBase {
|
|
|
15997
16408
|
resourceId,
|
|
15998
16409
|
requestContext,
|
|
15999
16410
|
tracingContext,
|
|
16000
|
-
methodType
|
|
16411
|
+
methodType,
|
|
16412
|
+
autoResumeSuspendedTools
|
|
16001
16413
|
}) {
|
|
16002
16414
|
const convertedWorkflowTools = {};
|
|
16003
16415
|
const workflows = await this.listWorkflows({ requestContext });
|
|
@@ -16026,16 +16438,17 @@ var Agent = class extends MastraBase {
|
|
|
16026
16438
|
// current tool span onto the workflow to maintain continuity of the trace
|
|
16027
16439
|
execute: async (inputData, context) => {
|
|
16028
16440
|
try {
|
|
16441
|
+
const { initialState, inputData: workflowInputData, suspendedToolRunId } = inputData;
|
|
16442
|
+
const runIdToUse = suspendedToolRunId ?? runId;
|
|
16029
16443
|
this.logger.debug(`[Agent:${this.name}] - Executing workflow as tool ${workflowName}`, {
|
|
16030
16444
|
name: workflowName,
|
|
16031
16445
|
description: workflow.description,
|
|
16032
16446
|
args: inputData,
|
|
16033
|
-
runId,
|
|
16447
|
+
runId: runIdToUse,
|
|
16034
16448
|
threadId,
|
|
16035
16449
|
resourceId
|
|
16036
16450
|
});
|
|
16037
|
-
const run = await workflow.createRun({ runId });
|
|
16038
|
-
const { initialState, inputData: workflowInputData } = inputData;
|
|
16451
|
+
const run = await workflow.createRun({ runId: runIdToUse });
|
|
16039
16452
|
const { resumeData, suspend } = context?.agent ?? {};
|
|
16040
16453
|
let result = void 0;
|
|
16041
16454
|
if (methodType === "generate" || methodType === "generateLegacy") {
|
|
@@ -16094,10 +16507,24 @@ var Agent = class extends MastraBase {
|
|
|
16094
16507
|
} else if (result?.status === "suspended") {
|
|
16095
16508
|
const suspendedStep = result?.suspended?.[0]?.[0];
|
|
16096
16509
|
const suspendPayload = result?.steps?.[suspendedStep]?.suspendPayload;
|
|
16510
|
+
const suspendedStepIds = result?.suspended?.map((stepPath) => stepPath.join("."));
|
|
16511
|
+
const firstSuspendedStepPath = [...result?.suspended?.[0] ?? []];
|
|
16512
|
+
let wflowStep = workflow;
|
|
16513
|
+
while (firstSuspendedStepPath.length > 0) {
|
|
16514
|
+
const key = firstSuspendedStepPath.shift();
|
|
16515
|
+
if (key) {
|
|
16516
|
+
if (!workflow.steps[key]) {
|
|
16517
|
+
this.logger.warn(`Suspended step '${key}' not found in workflow '${workflowName}'`);
|
|
16518
|
+
break;
|
|
16519
|
+
}
|
|
16520
|
+
wflowStep = workflow.steps[key];
|
|
16521
|
+
}
|
|
16522
|
+
}
|
|
16523
|
+
const resumeSchema = wflowStep?.resumeSchema;
|
|
16097
16524
|
if (suspendPayload?.__workflow_meta) {
|
|
16098
16525
|
delete suspendPayload.__workflow_meta;
|
|
16099
16526
|
}
|
|
16100
|
-
return suspend?.(suspendPayload);
|
|
16527
|
+
return suspend?.(suspendPayload, { resumeLabel: suspendedStepIds, resumeSchema });
|
|
16101
16528
|
} else {
|
|
16102
16529
|
return {
|
|
16103
16530
|
error: `Workflow should never reach this path, workflow returned no status`,
|
|
@@ -16112,7 +16539,7 @@ var Agent = class extends MastraBase {
|
|
|
16112
16539
|
category: "USER" /* USER */,
|
|
16113
16540
|
details: {
|
|
16114
16541
|
agentName: this.name,
|
|
16115
|
-
runId: runId || "",
|
|
16542
|
+
runId: inputData.suspendedToolRunId || runId || "",
|
|
16116
16543
|
threadId: threadId || "",
|
|
16117
16544
|
resourceId: resourceId || ""
|
|
16118
16545
|
},
|
|
@@ -16140,7 +16567,12 @@ var Agent = class extends MastraBase {
|
|
|
16140
16567
|
tracingContext,
|
|
16141
16568
|
tracingPolicy: this.#options?.tracingPolicy
|
|
16142
16569
|
};
|
|
16143
|
-
convertedWorkflowTools[`workflow-${workflowName}`] = makeCoreTool(
|
|
16570
|
+
convertedWorkflowTools[`workflow-${workflowName}`] = makeCoreTool(
|
|
16571
|
+
toolObj,
|
|
16572
|
+
options,
|
|
16573
|
+
void 0,
|
|
16574
|
+
autoResumeSuspendedTools
|
|
16575
|
+
);
|
|
16144
16576
|
}
|
|
16145
16577
|
}
|
|
16146
16578
|
return convertedWorkflowTools;
|
|
@@ -16159,7 +16591,8 @@ var Agent = class extends MastraBase {
|
|
|
16159
16591
|
tracingContext,
|
|
16160
16592
|
outputWriter,
|
|
16161
16593
|
methodType,
|
|
16162
|
-
memoryConfig
|
|
16594
|
+
memoryConfig,
|
|
16595
|
+
autoResumeSuspendedTools
|
|
16163
16596
|
}) {
|
|
16164
16597
|
let mastraProxy = void 0;
|
|
16165
16598
|
const logger = this.logger;
|
|
@@ -16173,7 +16606,8 @@ var Agent = class extends MastraBase {
|
|
|
16173
16606
|
requestContext,
|
|
16174
16607
|
tracingContext,
|
|
16175
16608
|
mastraProxy,
|
|
16176
|
-
outputWriter
|
|
16609
|
+
outputWriter,
|
|
16610
|
+
autoResumeSuspendedTools
|
|
16177
16611
|
});
|
|
16178
16612
|
const memoryTools = await this.listMemoryTools({
|
|
16179
16613
|
runId,
|
|
@@ -16182,7 +16616,8 @@ var Agent = class extends MastraBase {
|
|
|
16182
16616
|
requestContext,
|
|
16183
16617
|
tracingContext,
|
|
16184
16618
|
mastraProxy,
|
|
16185
|
-
memoryConfig
|
|
16619
|
+
memoryConfig,
|
|
16620
|
+
autoResumeSuspendedTools
|
|
16186
16621
|
});
|
|
16187
16622
|
const toolsetTools = await this.listToolsets({
|
|
16188
16623
|
runId,
|
|
@@ -16191,7 +16626,8 @@ var Agent = class extends MastraBase {
|
|
|
16191
16626
|
requestContext,
|
|
16192
16627
|
tracingContext,
|
|
16193
16628
|
mastraProxy,
|
|
16194
|
-
toolsets
|
|
16629
|
+
toolsets,
|
|
16630
|
+
autoResumeSuspendedTools
|
|
16195
16631
|
});
|
|
16196
16632
|
const clientSideTools = await this.listClientTools({
|
|
16197
16633
|
runId,
|
|
@@ -16200,7 +16636,8 @@ var Agent = class extends MastraBase {
|
|
|
16200
16636
|
requestContext,
|
|
16201
16637
|
tracingContext,
|
|
16202
16638
|
mastraProxy,
|
|
16203
|
-
clientTools
|
|
16639
|
+
clientTools,
|
|
16640
|
+
autoResumeSuspendedTools
|
|
16204
16641
|
});
|
|
16205
16642
|
const agentTools = await this.listAgentTools({
|
|
16206
16643
|
runId,
|
|
@@ -16208,7 +16645,8 @@ var Agent = class extends MastraBase {
|
|
|
16208
16645
|
threadId,
|
|
16209
16646
|
requestContext,
|
|
16210
16647
|
methodType,
|
|
16211
|
-
tracingContext
|
|
16648
|
+
tracingContext,
|
|
16649
|
+
autoResumeSuspendedTools
|
|
16212
16650
|
});
|
|
16213
16651
|
const workflowTools = await this.listWorkflowTools({
|
|
16214
16652
|
runId,
|
|
@@ -16216,7 +16654,8 @@ var Agent = class extends MastraBase {
|
|
|
16216
16654
|
threadId,
|
|
16217
16655
|
requestContext,
|
|
16218
16656
|
methodType,
|
|
16219
|
-
tracingContext
|
|
16657
|
+
tracingContext,
|
|
16658
|
+
autoResumeSuspendedTools
|
|
16220
16659
|
});
|
|
16221
16660
|
return this.formatTools({
|
|
16222
16661
|
...assignedTools,
|
|
@@ -16362,7 +16801,7 @@ var Agent = class extends MastraBase {
|
|
|
16362
16801
|
result[id] = scorerObject;
|
|
16363
16802
|
}
|
|
16364
16803
|
}
|
|
16365
|
-
if (Object.keys(result).length === 0) {
|
|
16804
|
+
if (Object.keys(result).length === 0 && Object.keys(overrideScorers).length > 0) {
|
|
16366
16805
|
throw new MastraError({
|
|
16367
16806
|
id: "AGENT_GENEREATE_SCORER_NOT_FOUND",
|
|
16368
16807
|
domain: "AGENT" /* AGENT */,
|
|
@@ -16379,8 +16818,11 @@ var Agent = class extends MastraBase {
|
|
|
16379
16818
|
async prepareModels(requestContext, model) {
|
|
16380
16819
|
if (model || !Array.isArray(this.model)) {
|
|
16381
16820
|
const modelToUse = model ?? this.model;
|
|
16382
|
-
const resolvedModel =
|
|
16383
|
-
|
|
16821
|
+
const resolvedModel = await this.resolveModelConfig(
|
|
16822
|
+
modelToUse,
|
|
16823
|
+
requestContext
|
|
16824
|
+
);
|
|
16825
|
+
if (!isSupportedLanguageModel(resolvedModel)) {
|
|
16384
16826
|
const mastraError = new MastraError({
|
|
16385
16827
|
id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
|
|
16386
16828
|
domain: "AGENT" /* AGENT */,
|
|
@@ -16388,26 +16830,30 @@ var Agent = class extends MastraBase {
|
|
|
16388
16830
|
details: {
|
|
16389
16831
|
agentName: this.name
|
|
16390
16832
|
},
|
|
16391
|
-
text: `[Agent:${this.name}] - Only v2 models are allowed when an array of models is provided`
|
|
16833
|
+
text: `[Agent:${this.name}] - Only v2/v3 models are allowed when an array of models is provided`
|
|
16392
16834
|
});
|
|
16393
16835
|
this.logger.trackException(mastraError);
|
|
16394
16836
|
this.logger.error(mastraError.toString());
|
|
16395
16837
|
throw mastraError;
|
|
16396
16838
|
}
|
|
16839
|
+
let headers;
|
|
16840
|
+
if (resolvedModel instanceof ModelRouterLanguageModel) {
|
|
16841
|
+
headers = resolvedModel.config?.headers;
|
|
16842
|
+
}
|
|
16397
16843
|
return [
|
|
16398
16844
|
{
|
|
16399
16845
|
id: "main",
|
|
16400
|
-
// TODO fix type check
|
|
16401
16846
|
model: resolvedModel,
|
|
16402
16847
|
maxRetries: this.maxRetries ?? 0,
|
|
16403
|
-
enabled: true
|
|
16848
|
+
enabled: true,
|
|
16849
|
+
headers
|
|
16404
16850
|
}
|
|
16405
16851
|
];
|
|
16406
16852
|
}
|
|
16407
16853
|
const models = await Promise.all(
|
|
16408
16854
|
this.model.map(async (modelConfig) => {
|
|
16409
16855
|
const model2 = await this.resolveModelConfig(modelConfig.model, requestContext);
|
|
16410
|
-
if (!
|
|
16856
|
+
if (!isSupportedLanguageModel(model2)) {
|
|
16411
16857
|
const mastraError = new MastraError({
|
|
16412
16858
|
id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
|
|
16413
16859
|
domain: "AGENT" /* AGENT */,
|
|
@@ -16415,7 +16861,7 @@ var Agent = class extends MastraBase {
|
|
|
16415
16861
|
details: {
|
|
16416
16862
|
agentName: this.name
|
|
16417
16863
|
},
|
|
16418
|
-
text: `[Agent:${this.name}] - Only v2 models are allowed when an array of models is provided`
|
|
16864
|
+
text: `[Agent:${this.name}] - Only v2/v3 models are allowed when an array of models is provided`
|
|
16419
16865
|
});
|
|
16420
16866
|
this.logger.trackException(mastraError);
|
|
16421
16867
|
this.logger.error(mastraError.toString());
|
|
@@ -16436,11 +16882,16 @@ var Agent = class extends MastraBase {
|
|
|
16436
16882
|
this.logger.error(mastraError.toString());
|
|
16437
16883
|
throw mastraError;
|
|
16438
16884
|
}
|
|
16885
|
+
let headers;
|
|
16886
|
+
if (model2 instanceof ModelRouterLanguageModel) {
|
|
16887
|
+
headers = model2.config?.headers;
|
|
16888
|
+
}
|
|
16439
16889
|
return {
|
|
16440
16890
|
id: modelId,
|
|
16441
16891
|
model: model2,
|
|
16442
16892
|
maxRetries: modelConfig.maxRetries ?? 0,
|
|
16443
|
-
enabled: modelConfig.enabled ?? true
|
|
16893
|
+
enabled: modelConfig.enabled ?? true,
|
|
16894
|
+
headers
|
|
16444
16895
|
};
|
|
16445
16896
|
})
|
|
16446
16897
|
);
|
|
@@ -16450,7 +16901,11 @@ var Agent = class extends MastraBase {
|
|
|
16450
16901
|
* Executes the agent call, handling tools, memory, and streaming.
|
|
16451
16902
|
* @internal
|
|
16452
16903
|
*/
|
|
16453
|
-
async #execute({
|
|
16904
|
+
async #execute({
|
|
16905
|
+
methodType,
|
|
16906
|
+
resumeContext,
|
|
16907
|
+
...options
|
|
16908
|
+
}) {
|
|
16454
16909
|
const existingSnapshot = resumeContext?.snapshot;
|
|
16455
16910
|
let snapshotMemoryInfo;
|
|
16456
16911
|
if (existingSnapshot) {
|
|
@@ -16567,6 +17022,7 @@ var Agent = class extends MastraBase {
|
|
|
16567
17022
|
saveQueueManager,
|
|
16568
17023
|
returnScorerData: options.returnScorerData,
|
|
16569
17024
|
requireToolApproval: options.requireToolApproval,
|
|
17025
|
+
toolCallConcurrency: options.toolCallConcurrency,
|
|
16570
17026
|
resumeContext,
|
|
16571
17027
|
agentId: this.id,
|
|
16572
17028
|
agentName: this.name,
|
|
@@ -16764,6 +17220,10 @@ var Agent = class extends MastraBase {
|
|
|
16764
17220
|
async network(messages, options) {
|
|
16765
17221
|
const runId = options?.runId || this.#mastra?.generateId() || randomUUID();
|
|
16766
17222
|
const requestContextToUse = options?.requestContext || new RequestContext();
|
|
17223
|
+
const resourceIdFromContext = requestContextToUse.get(MASTRA_RESOURCE_ID_KEY);
|
|
17224
|
+
const threadIdFromContext = requestContextToUse.get(MASTRA_THREAD_ID_KEY);
|
|
17225
|
+
const threadId = threadIdFromContext || (typeof options?.memory?.thread === "string" ? options?.memory?.thread : options?.memory?.thread?.id);
|
|
17226
|
+
const resourceId = resourceIdFromContext || options?.memory?.resource;
|
|
16767
17227
|
return await networkLoop({
|
|
16768
17228
|
networkName: this.name,
|
|
16769
17229
|
requestContext: requestContextToUse,
|
|
@@ -16776,8 +17236,8 @@ var Agent = class extends MastraBase {
|
|
|
16776
17236
|
generateId: () => this.#mastra?.generateId() || randomUUID(),
|
|
16777
17237
|
maxIterations: options?.maxSteps || 1,
|
|
16778
17238
|
messages,
|
|
16779
|
-
threadId
|
|
16780
|
-
resourceId
|
|
17239
|
+
threadId,
|
|
17240
|
+
resourceId
|
|
16781
17241
|
});
|
|
16782
17242
|
}
|
|
16783
17243
|
async generate(messages, options) {
|
|
@@ -16792,14 +17252,14 @@ var Agent = class extends MastraBase {
|
|
|
16792
17252
|
requestContext: mergedOptions.requestContext
|
|
16793
17253
|
});
|
|
16794
17254
|
const modelInfo = llm.getModel();
|
|
16795
|
-
if (modelInfo
|
|
17255
|
+
if (!isSupportedLanguageModel(modelInfo)) {
|
|
16796
17256
|
const modelId = modelInfo.modelId || "unknown";
|
|
16797
17257
|
const provider = modelInfo.provider || "unknown";
|
|
16798
17258
|
throw new MastraError({
|
|
16799
17259
|
id: "AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED",
|
|
16800
17260
|
domain: "AGENT" /* AGENT */,
|
|
16801
17261
|
category: "USER" /* USER */,
|
|
16802
|
-
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.`,
|
|
17262
|
+
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.`,
|
|
16803
17263
|
details: {
|
|
16804
17264
|
agentName: this.name,
|
|
16805
17265
|
modelId,
|
|
@@ -16854,14 +17314,14 @@ var Agent = class extends MastraBase {
|
|
|
16854
17314
|
requestContext: mergedOptions.requestContext
|
|
16855
17315
|
});
|
|
16856
17316
|
const modelInfo = llm.getModel();
|
|
16857
|
-
if (modelInfo
|
|
17317
|
+
if (!isSupportedLanguageModel(modelInfo)) {
|
|
16858
17318
|
const modelId = modelInfo.modelId || "unknown";
|
|
16859
17319
|
const provider = modelInfo.provider || "unknown";
|
|
16860
17320
|
throw new MastraError({
|
|
16861
17321
|
id: "AGENT_STREAM_V1_MODEL_NOT_SUPPORTED",
|
|
16862
17322
|
domain: "AGENT" /* AGENT */,
|
|
16863
17323
|
category: "USER" /* USER */,
|
|
16864
|
-
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.`,
|
|
17324
|
+
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.`,
|
|
16865
17325
|
details: {
|
|
16866
17326
|
agentName: this.name,
|
|
16867
17327
|
modelId,
|
|
@@ -16923,7 +17383,7 @@ var Agent = class extends MastraBase {
|
|
|
16923
17383
|
const llm = await this.getLLM({
|
|
16924
17384
|
requestContext: mergedStreamOptions.requestContext
|
|
16925
17385
|
});
|
|
16926
|
-
if (llm.getModel()
|
|
17386
|
+
if (!isSupportedLanguageModel(llm.getModel())) {
|
|
16927
17387
|
throw new MastraError({
|
|
16928
17388
|
id: "AGENT_STREAM_V1_MODEL_NOT_SUPPORTED",
|
|
16929
17389
|
domain: "AGENT" /* AGENT */,
|
|
@@ -17153,17 +17613,17 @@ var ModerationProcessor = class _ModerationProcessor {
|
|
|
17153
17613
|
const prompt = this.createModerationPrompt(content, isStream);
|
|
17154
17614
|
try {
|
|
17155
17615
|
const model = await this.moderationAgent.getModel();
|
|
17156
|
-
const schema =
|
|
17157
|
-
category_scores:
|
|
17158
|
-
|
|
17159
|
-
category:
|
|
17160
|
-
score:
|
|
17616
|
+
const schema = z8.object({
|
|
17617
|
+
category_scores: z8.array(
|
|
17618
|
+
z8.object({
|
|
17619
|
+
category: z8.enum(this.categories).describe("The moderation category being evaluated"),
|
|
17620
|
+
score: z8.number().min(0).max(1).describe("Confidence score between 0 and 1 indicating how strongly the content matches this category")
|
|
17161
17621
|
})
|
|
17162
17622
|
).describe("Array of flagged categories with their confidence scores").nullable(),
|
|
17163
|
-
reason:
|
|
17623
|
+
reason: z8.string().describe("Brief explanation of why content was flagged").nullable()
|
|
17164
17624
|
});
|
|
17165
17625
|
let response;
|
|
17166
|
-
if (model
|
|
17626
|
+
if (isSupportedLanguageModel(model)) {
|
|
17167
17627
|
response = await this.moderationAgent.generate(prompt, {
|
|
17168
17628
|
structuredOutput: {
|
|
17169
17629
|
schema,
|
|
@@ -17368,22 +17828,22 @@ var PromptInjectionDetector = class _PromptInjectionDetector {
|
|
|
17368
17828
|
try {
|
|
17369
17829
|
const model = await this.detectionAgent.getModel();
|
|
17370
17830
|
let response;
|
|
17371
|
-
const baseSchema =
|
|
17372
|
-
categories:
|
|
17373
|
-
|
|
17374
|
-
type:
|
|
17375
|
-
score:
|
|
17831
|
+
const baseSchema = z8.object({
|
|
17832
|
+
categories: z8.array(
|
|
17833
|
+
z8.object({
|
|
17834
|
+
type: z8.enum(this.detectionTypes).describe("The type of attack detected from the list of detection types"),
|
|
17835
|
+
score: z8.number().min(0).max(1).describe("Confidence level between 0 and 1 indicating how certain the detection is")
|
|
17376
17836
|
})
|
|
17377
17837
|
).nullable(),
|
|
17378
|
-
reason:
|
|
17838
|
+
reason: z8.string().describe("The reason for the detection").nullable()
|
|
17379
17839
|
});
|
|
17380
17840
|
let schema = baseSchema;
|
|
17381
17841
|
if (this.strategy === "rewrite") {
|
|
17382
17842
|
schema = baseSchema.extend({
|
|
17383
|
-
rewritten_content:
|
|
17843
|
+
rewritten_content: z8.string().describe("The rewritten content that neutralizes the attack while preserving any legitimate user intent").nullable()
|
|
17384
17844
|
});
|
|
17385
17845
|
}
|
|
17386
|
-
if (model
|
|
17846
|
+
if (isSupportedLanguageModel(model)) {
|
|
17387
17847
|
response = await this.detectionAgent.generate(prompt, {
|
|
17388
17848
|
structuredOutput: {
|
|
17389
17849
|
schema,
|
|
@@ -17608,30 +18068,30 @@ var PIIDetector = class _PIIDetector {
|
|
|
17608
18068
|
const prompt = this.createDetectionPrompt(content);
|
|
17609
18069
|
try {
|
|
17610
18070
|
const model = await this.detectionAgent.getModel();
|
|
17611
|
-
const baseDetectionSchema =
|
|
17612
|
-
type:
|
|
17613
|
-
value:
|
|
17614
|
-
confidence:
|
|
17615
|
-
start:
|
|
17616
|
-
end:
|
|
18071
|
+
const baseDetectionSchema = z8.object({
|
|
18072
|
+
type: z8.string().describe("Type of PII detected"),
|
|
18073
|
+
value: z8.string().describe("The actual PII value found"),
|
|
18074
|
+
confidence: z8.number().min(0).max(1).describe("Confidence of this detection"),
|
|
18075
|
+
start: z8.number().describe("Start position in the text"),
|
|
18076
|
+
end: z8.number().describe("End position in the text")
|
|
17617
18077
|
});
|
|
17618
18078
|
const detectionSchema = this.strategy === "redact" ? baseDetectionSchema.extend({
|
|
17619
|
-
redacted_value:
|
|
18079
|
+
redacted_value: z8.string().describe("Redacted version of the value").nullable()
|
|
17620
18080
|
}) : baseDetectionSchema;
|
|
17621
|
-
const baseSchema =
|
|
17622
|
-
categories:
|
|
17623
|
-
|
|
17624
|
-
type:
|
|
17625
|
-
score:
|
|
18081
|
+
const baseSchema = z8.object({
|
|
18082
|
+
categories: z8.array(
|
|
18083
|
+
z8.object({
|
|
18084
|
+
type: z8.enum(this.detectionTypes).describe("The type of PII detected from the list of detection types"),
|
|
18085
|
+
score: z8.number().min(0).max(1).describe("Confidence level between 0 and 1 indicating how certain the detection is")
|
|
17626
18086
|
})
|
|
17627
18087
|
).describe("Array of detected PII types with their confidence scores").nullable(),
|
|
17628
|
-
detections:
|
|
18088
|
+
detections: z8.array(detectionSchema).describe("Array of specific PII detections with locations").nullable()
|
|
17629
18089
|
});
|
|
17630
18090
|
const schema = this.strategy === "redact" ? baseSchema.extend({
|
|
17631
|
-
redacted_content:
|
|
18091
|
+
redacted_content: z8.string().describe("The content with all PII redacted according to the redaction method").nullable()
|
|
17632
18092
|
}) : baseSchema;
|
|
17633
18093
|
let response;
|
|
17634
|
-
if (model
|
|
18094
|
+
if (isSupportedLanguageModel(model)) {
|
|
17635
18095
|
response = await this.detectionAgent.generate(prompt, {
|
|
17636
18096
|
structuredOutput: {
|
|
17637
18097
|
schema,
|
|
@@ -18086,14 +18546,14 @@ var LanguageDetector = class _LanguageDetector {
|
|
|
18086
18546
|
try {
|
|
18087
18547
|
const model = await this.detectionAgent.getModel();
|
|
18088
18548
|
let response;
|
|
18089
|
-
const baseSchema =
|
|
18090
|
-
iso_code:
|
|
18091
|
-
confidence:
|
|
18549
|
+
const baseSchema = z8.object({
|
|
18550
|
+
iso_code: z8.string().describe("ISO language code").nullable(),
|
|
18551
|
+
confidence: z8.number().min(0).max(1).describe("Detection confidence").nullable()
|
|
18092
18552
|
});
|
|
18093
18553
|
const schema = this.strategy === "translate" ? baseSchema.extend({
|
|
18094
|
-
translated_text:
|
|
18554
|
+
translated_text: z8.string().describe("Translated text").nullable()
|
|
18095
18555
|
}) : baseSchema;
|
|
18096
|
-
if (model
|
|
18556
|
+
if (isSupportedLanguageModel(model)) {
|
|
18097
18557
|
response = await this.detectionAgent.generate(prompt, {
|
|
18098
18558
|
structuredOutput: {
|
|
18099
18559
|
schema
|
|
@@ -18771,7 +19231,7 @@ var SystemPromptScrubber = class {
|
|
|
18771
19231
|
const schema = this.strategy === "redact" ? baseSchema.extend({
|
|
18772
19232
|
redacted_content: z.string().describe("Redacted content").nullable()
|
|
18773
19233
|
}) : baseSchema;
|
|
18774
|
-
if (model
|
|
19234
|
+
if (isSupportedLanguageModel(model)) {
|
|
18775
19235
|
result = await this.detectionAgent.generate(text, {
|
|
18776
19236
|
structuredOutput: {
|
|
18777
19237
|
schema,
|
|
@@ -20141,7 +20601,7 @@ var MockMemory = class extends MastraMemory {
|
|
|
20141
20601
|
updateWorkingMemory: createTool({
|
|
20142
20602
|
id: "update-working-memory",
|
|
20143
20603
|
description: `Update the working memory with new information. Any data not included will be overwritten.`,
|
|
20144
|
-
inputSchema:
|
|
20604
|
+
inputSchema: z8.object({ memory: z8.string() }),
|
|
20145
20605
|
execute: async (inputData, context) => {
|
|
20146
20606
|
const threadId = context?.agent?.threadId;
|
|
20147
20607
|
const resourceId = context?.agent?.resourceId;
|
|
@@ -20250,6 +20710,6 @@ var MockMemory = class extends MastraMemory {
|
|
|
20250
20710
|
}
|
|
20251
20711
|
};
|
|
20252
20712
|
|
|
20253
|
-
export { AISDKV5OutputStream, Agent, BatchPartsProcessor, ChunkFrom, DefaultExecutionEngine, 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, isProcessor, isProcessorWorkflow, loop, mapVariable, memoryDefaultOptions, parseMemoryRequestContext, resolveThreadIdFromArgs, runCountDeprecationMessage, tryGenerateWithJsonFallback, tryStreamWithJsonFallback, validateStepInput, validateStepResumeData, validateStepStateData, validateStepSuspendData };
|
|
20254
|
-
//# sourceMappingURL=chunk-
|
|
20255
|
-
//# sourceMappingURL=chunk-
|
|
20713
|
+
export { AISDKV5OutputStream, Agent, BatchPartsProcessor, ChunkFrom, DefaultExecutionEngine, EventEmitterPubSub, ExecutionEngine, FilePartSchema, ImagePartSchema, LanguageDetector, MastraAgentNetworkStream, MastraMemory, MastraModelOutput, MemoryProcessor, MessageContentSchema, MessageHistory, MessagePartSchema, MockMemory, ModerationProcessor, PIIDetector, ProcessorInputPhaseSchema, ProcessorInputStepPhaseSchema, ProcessorMessageContentSchema, ProcessorMessageSchema, ProcessorOutputResultPhaseSchema, ProcessorOutputStepPhaseSchema, ProcessorOutputStreamPhaseSchema, ProcessorRunner, ProcessorState, ProcessorStepInputSchema, ProcessorStepOutputSchema, ProcessorStepSchema, PromptInjectionDetector, ReasoningPartSchema, Run, SemanticRecall, SourcePartSchema, StepStartPartSchema, StructuredOutputProcessor, SystemPromptScrubber, TextPartSchema, TokenLimiterProcessor, ToolCallFilter, ToolInvocationPartSchema, TripWire, UnicodeNormalizer, Workflow, WorkflowRunOutput, WorkingMemory, augmentWithInit, cloneStep, cloneWorkflow, convertFullStreamChunkToMastra, convertFullStreamChunkToUIMessageStream, convertMastraChunkToAISDKv5, createDeprecationProxy, createStep, createTimeTravelExecutionParams, createWorkflow, getResumeLabelsByStepId, getStepIds, getStepResult, getZodErrors, hydrateSerializedStepErrors, isProcessor, isProcessorWorkflow, isSupportedLanguageModel, loop, mapVariable, memoryDefaultOptions, parseMemoryRequestContext, resolveThreadIdFromArgs, runCountDeprecationMessage, supportedLanguageModelSpecifications, tryGenerateWithJsonFallback, tryStreamWithJsonFallback, validateStepInput, validateStepResumeData, validateStepStateData, validateStepSuspendData };
|
|
20714
|
+
//# sourceMappingURL=chunk-QF4MHFSU.js.map
|
|
20715
|
+
//# sourceMappingURL=chunk-QF4MHFSU.js.map
|