@mastra/core 1.0.0-beta.11 → 1.0.0-beta.13
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 +173 -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 +1 -1
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +5 -1
- package/dist/agent/agent.types.d.ts.map +1 -1
- package/dist/agent/index.cjs +9 -9
- 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/types.d.ts +3 -3
- package/dist/agent/utils.d.ts +3 -3
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +2 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- 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 +14 -1
- package/dist/bundler/types.d.ts.map +1 -1
- package/dist/{chunk-U3XOLEPX.js → chunk-2IU4RGU5.js} +6 -32
- package/dist/chunk-2IU4RGU5.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-F2GAJSBI.js → chunk-4BC5FUAO.js} +8 -6
- package/dist/{chunk-F2GAJSBI.js.map → chunk-4BC5FUAO.js.map} +1 -1
- 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-5VZGJTPR.js +4837 -0
- package/dist/chunk-5VZGJTPR.js.map +1 -0
- package/dist/{chunk-C36YRTZ6.js → chunk-62Q7K656.js} +6 -7
- package/dist/chunk-62Q7K656.js.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-5WRI5ZAA.js → chunk-7D4SUZUM.js} +10 -4
- package/dist/{chunk-5WRI5ZAA.js.map → chunk-7D4SUZUM.js.map} +1 -1
- package/dist/{chunk-YWMMBIOM.cjs → chunk-7HEAVZRS.cjs} +15 -15
- package/dist/{chunk-YWMMBIOM.cjs.map → chunk-7HEAVZRS.cjs.map} +1 -1
- package/dist/{chunk-BUKY6CTR.cjs → chunk-AGHLXC4I.cjs} +106 -36
- package/dist/chunk-AGHLXC4I.cjs.map +1 -0
- package/dist/{chunk-PK2A5WBG.js → chunk-ARAQIW6E.js} +222 -604
- package/dist/chunk-ARAQIW6E.js.map +1 -0
- package/dist/{chunk-US2U7ECW.js → chunk-BQDZIQ3G.js} +156 -90
- package/dist/chunk-BQDZIQ3G.js.map +1 -0
- package/dist/chunk-D22XABFZ.js +79 -0
- package/dist/chunk-D22XABFZ.js.map +1 -0
- package/dist/{chunk-2ULLRN4Y.js → chunk-E5BQRAJK.js} +943 -626
- package/dist/chunk-E5BQRAJK.js.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-7P6BNIJH.js → chunk-GIWC35YQ.js} +105 -35
- package/dist/chunk-GIWC35YQ.js.map +1 -0
- package/dist/{chunk-4JKEUSCC.cjs → chunk-H4VUIOWU.cjs} +22 -20
- package/dist/chunk-H4VUIOWU.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-IXZ2T2QX.cjs +448 -0
- package/dist/chunk-IXZ2T2QX.cjs.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-BJXKH4LG.cjs → chunk-LGB4VNZI.cjs} +43 -78
- package/dist/chunk-LGB4VNZI.cjs.map +1 -0
- package/dist/{chunk-PG5H6QIO.cjs → chunk-MLKE7HRS.cjs} +41 -21
- package/dist/chunk-MLKE7HRS.cjs.map +1 -0
- package/dist/{chunk-OEIVMCWX.js → chunk-MRRFTNF4.js} +2537 -84
- package/dist/chunk-MRRFTNF4.js.map +1 -0
- package/dist/chunk-MXBVP7HX.cjs +4842 -0
- package/dist/chunk-MXBVP7HX.cjs.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-CZEJQSWB.cjs → chunk-OWIEOL55.cjs} +295 -677
- package/dist/chunk-OWIEOL55.cjs.map +1 -0
- package/dist/{chunk-WTSZBHIZ.cjs → chunk-PJAK4U6R.cjs} +24 -24
- package/dist/{chunk-WTSZBHIZ.cjs.map → chunk-PJAK4U6R.cjs.map} +1 -1
- package/dist/{chunk-52RSUALV.cjs → chunk-R5AJGM55.cjs} +1314 -995
- package/dist/chunk-R5AJGM55.cjs.map +1 -0
- package/dist/{chunk-IVV5TOMD.js → chunk-RCJLMMTO.js} +32 -12
- package/dist/chunk-RCJLMMTO.js.map +1 -0
- package/dist/{chunk-S73Z3PBJ.cjs → chunk-SZYSDJTN.cjs} +27 -28
- package/dist/chunk-SZYSDJTN.cjs.map +1 -0
- package/dist/{chunk-YC6PJEPH.cjs → chunk-U4CSOY6T.cjs} +188 -122
- package/dist/chunk-U4CSOY6T.cjs.map +1 -0
- package/dist/chunk-UBSPZTQX.js +434 -0
- package/dist/chunk-UBSPZTQX.js.map +1 -0
- package/dist/{chunk-SCUWP4II.cjs → chunk-VEPP75C4.cjs} +47 -74
- package/dist/chunk-VEPP75C4.cjs.map +1 -0
- package/dist/{chunk-JIGDJK2O.js → chunk-VETAQUW3.js} +4 -39
- package/dist/chunk-VETAQUW3.js.map +1 -0
- package/dist/{chunk-Z57R5WS4.js → chunk-WPTTKULS.js} +4 -4
- package/dist/{chunk-Z57R5WS4.js.map → chunk-WPTTKULS.js.map} +1 -1
- package/dist/{chunk-O2BJW7YA.js → chunk-WYGUWVTF.js} +5 -5
- package/dist/{chunk-O2BJW7YA.js.map → chunk-WYGUWVTF.js.map} +1 -1
- package/dist/{chunk-SXNQRJQD.js → chunk-WYWRMIQC.js} +127 -22
- package/dist/chunk-WYWRMIQC.js.map +1 -0
- package/dist/{chunk-5Q6WAYEY.cjs → chunk-X6IBA7FP.cjs} +137 -50
- package/dist/chunk-X6IBA7FP.cjs.map +1 -0
- package/dist/{chunk-MRFUISXC.cjs → chunk-Y7MZ5LJT.cjs} +2632 -179
- package/dist/chunk-Y7MZ5LJT.cjs.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/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/v5/model.d.ts +1 -1
- 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 +2 -2
- 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 +51 -11
- package/dist/llm/model/shared.types.d.ts +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/test-utils/MastraLanguageModelV2Mock.d.ts +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts.map +1 -1
- package/dist/loop/test-utils/options.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/types.d.ts +3 -1
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +13 -13
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +10 -10
- 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 +5 -5
- 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 +13 -13
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/loop/workflows/schema.d.ts +6 -6
- 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-D3EKFGAO.cjs +12 -0
- package/dist/{models-dev-EO3SUIY2.cjs.map → models-dev-D3EKFGAO.cjs.map} +1 -1
- package/dist/models-dev-EO22XOXQ.js +3 -0
- package/dist/{models-dev-23RN2WHG.js.map → models-dev-EO22XOXQ.js.map} +1 -1
- package/dist/netlify-AE4LNCAI.js +3 -0
- package/dist/{netlify-GXJ5D5DD.js.map → netlify-AE4LNCAI.js.map} +1 -1
- package/dist/netlify-WE42TZIT.cjs +12 -0
- package/dist/{netlify-KJLY3GFS.cjs.map → netlify-WE42TZIT.cjs.map} +1 -1
- package/dist/processors/index.cjs +37 -37
- package/dist/processors/index.d.ts +2 -2
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/step-schema.d.ts +1267 -1267
- package/dist/processors/step-schema.d.ts.map +1 -1
- package/dist/provider-registry-6LF3NGC5.js +3 -0
- package/dist/{provider-registry-F67Y6OF2.js.map → provider-registry-6LF3NGC5.js.map} +1 -1
- package/dist/provider-registry-73FKMXJV.cjs +40 -0
- package/dist/{provider-registry-3TG2KUD2.cjs.map → provider-registry-73FKMXJV.cjs.map} +1 -1
- package/dist/provider-registry.json +100 -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 +2 -2
- package/dist/relevance/index.js +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 +2 -2
- 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 +9 -31
- 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 +3 -2
- 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-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-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/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 +3 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/vector/embed.d.ts +2 -2
- package/dist/vector/embed.d.ts.map +1 -1
- package/dist/vector/index.cjs +11 -11
- package/dist/vector/index.js +3 -3
- package/dist/vector/vector.d.ts +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 +1 -1
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/evented/workflow.d.ts +15 -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 +26 -8
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +12 -11
- package/src/llm/model/provider-types.generated.d.ts +51 -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-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-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-YC6PJEPH.cjs.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,32 +1,33 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
3
|
+
var chunkH4VUIOWU_cjs = require('./chunk-H4VUIOWU.cjs');
|
|
4
|
+
var chunkL3NKIMF5_cjs = require('./chunk-L3NKIMF5.cjs');
|
|
5
|
+
var chunkLGB4VNZI_cjs = require('./chunk-LGB4VNZI.cjs');
|
|
6
|
+
var chunkX6IBA7FP_cjs = require('./chunk-X6IBA7FP.cjs');
|
|
7
|
+
var chunkNESKUIRE_cjs = require('./chunk-NESKUIRE.cjs');
|
|
8
|
+
var chunkFVQTJUBD_cjs = require('./chunk-FVQTJUBD.cjs');
|
|
9
|
+
var chunk4D4KB75Y_cjs = require('./chunk-4D4KB75Y.cjs');
|
|
9
10
|
var chunkMR7ZWBL6_cjs = require('./chunk-MR7ZWBL6.cjs');
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
11
|
+
var chunkMXBVP7HX_cjs = require('./chunk-MXBVP7HX.cjs');
|
|
12
|
+
var chunkSZYSDJTN_cjs = require('./chunk-SZYSDJTN.cjs');
|
|
13
|
+
var chunkMLKE7HRS_cjs = require('./chunk-MLKE7HRS.cjs');
|
|
13
14
|
var chunkKJBMTK5B_cjs = require('./chunk-KJBMTK5B.cjs');
|
|
14
|
-
var
|
|
15
|
+
var chunkZ55SJVEC_cjs = require('./chunk-Z55SJVEC.cjs');
|
|
16
|
+
var chunk72YCRTEX_cjs = require('./chunk-72YCRTEX.cjs');
|
|
15
17
|
var chunkUVHSM2GU_cjs = require('./chunk-UVHSM2GU.cjs');
|
|
18
|
+
var chunkHWMMIRIF_cjs = require('./chunk-HWMMIRIF.cjs');
|
|
16
19
|
var chunk4WQYXT2I_cjs = require('./chunk-4WQYXT2I.cjs');
|
|
17
20
|
var chunkDGV2FWB4_cjs = require('./chunk-DGV2FWB4.cjs');
|
|
18
21
|
var chunkAF74UXR5_cjs = require('./chunk-AF74UXR5.cjs');
|
|
19
|
-
var
|
|
20
|
-
var
|
|
22
|
+
var chunk6SZKM6EC_cjs = require('./chunk-6SZKM6EC.cjs');
|
|
23
|
+
var z8 = require('zod');
|
|
21
24
|
var crypto2 = require('crypto');
|
|
22
25
|
var web = require('stream/web');
|
|
23
26
|
var EventEmitter2 = require('events');
|
|
24
27
|
var providerV5 = require('@ai-sdk/provider-v5');
|
|
25
|
-
var aiV5 = require('ai-v5');
|
|
26
28
|
var z4 = require('zod/v4');
|
|
27
29
|
var schemaCompat = require('@mastra/schema-compat');
|
|
28
30
|
var radash = require('radash');
|
|
29
|
-
var providerUtilsV5 = require('@ai-sdk/provider-utils-v5');
|
|
30
31
|
var lite = require('js-tiktoken/lite');
|
|
31
32
|
var o200k_base = require('js-tiktoken/ranks/o200k_base');
|
|
32
33
|
var lruCache = require('lru-cache');
|
|
@@ -53,7 +54,7 @@ function _interopNamespace(e) {
|
|
|
53
54
|
return Object.freeze(n);
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
var
|
|
57
|
+
var z8__default = /*#__PURE__*/_interopDefault(z8);
|
|
57
58
|
var crypto2__namespace = /*#__PURE__*/_interopNamespace(crypto2);
|
|
58
59
|
var EventEmitter2__default = /*#__PURE__*/_interopDefault(EventEmitter2);
|
|
59
60
|
var z4__default = /*#__PURE__*/_interopDefault(z4);
|
|
@@ -61,7 +62,7 @@ var o200k_base__default = /*#__PURE__*/_interopDefault(o200k_base);
|
|
|
61
62
|
var xxhash__default = /*#__PURE__*/_interopDefault(xxhash);
|
|
62
63
|
|
|
63
64
|
// ../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js
|
|
64
|
-
var require_fast_deep_equal =
|
|
65
|
+
var require_fast_deep_equal = chunk6SZKM6EC_cjs.__commonJS({
|
|
65
66
|
"../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js"(exports, module) {
|
|
66
67
|
module.exports = function equal(a, b) {
|
|
67
68
|
if (a === b) return true;
|
|
@@ -454,6 +455,8 @@ var DelayedPromise = class {
|
|
|
454
455
|
}
|
|
455
456
|
}
|
|
456
457
|
};
|
|
458
|
+
|
|
459
|
+
// src/stream/aisdk/v5/compat/prepare-tools.ts
|
|
457
460
|
function prepareToolsAndToolChoice({
|
|
458
461
|
tools,
|
|
459
462
|
toolChoice,
|
|
@@ -467,17 +470,17 @@ function prepareToolsAndToolChoice({
|
|
|
467
470
|
}
|
|
468
471
|
const filteredTools = activeTools != null ? Object.entries(tools || {}).filter(([name]) => activeTools.includes(name)) : Object.entries(tools || {});
|
|
469
472
|
return {
|
|
470
|
-
tools: filteredTools.map(([name,
|
|
473
|
+
tools: filteredTools.map(([name, tool2]) => {
|
|
471
474
|
try {
|
|
472
475
|
let inputSchema;
|
|
473
|
-
if ("inputSchema" in
|
|
474
|
-
inputSchema =
|
|
475
|
-
} else if ("parameters" in
|
|
476
|
-
inputSchema =
|
|
476
|
+
if ("inputSchema" in tool2) {
|
|
477
|
+
inputSchema = tool2.inputSchema;
|
|
478
|
+
} else if ("parameters" in tool2) {
|
|
479
|
+
inputSchema = tool2.parameters;
|
|
477
480
|
}
|
|
478
|
-
const sdkTool =
|
|
481
|
+
const sdkTool = chunkFVQTJUBD_cjs.tool({
|
|
479
482
|
type: "function",
|
|
480
|
-
...
|
|
483
|
+
...tool2,
|
|
481
484
|
inputSchema
|
|
482
485
|
});
|
|
483
486
|
const toolType = sdkTool?.type ?? "function";
|
|
@@ -489,7 +492,7 @@ function prepareToolsAndToolChoice({
|
|
|
489
492
|
type: "function",
|
|
490
493
|
name,
|
|
491
494
|
description: sdkTool.description,
|
|
492
|
-
inputSchema:
|
|
495
|
+
inputSchema: chunkFVQTJUBD_cjs.asSchema(sdkTool.inputSchema).jsonSchema,
|
|
493
496
|
providerOptions: sdkTool.providerOptions
|
|
494
497
|
};
|
|
495
498
|
case "provider-defined": {
|
|
@@ -517,7 +520,7 @@ function prepareToolsAndToolChoice({
|
|
|
517
520
|
console.error("Error preparing tool", e);
|
|
518
521
|
return null;
|
|
519
522
|
}
|
|
520
|
-
}).filter((
|
|
523
|
+
}).filter((tool2) => tool2 !== null),
|
|
521
524
|
toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
|
|
522
525
|
};
|
|
523
526
|
}
|
|
@@ -555,7 +558,7 @@ var StructuredOutputProcessor = class {
|
|
|
555
558
|
providerOptions;
|
|
556
559
|
constructor(options) {
|
|
557
560
|
if (!options.schema) {
|
|
558
|
-
throw new
|
|
561
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
559
562
|
id: "STRUCTURED_OUTPUT_PROCESSOR_SCHEMA_REQUIRED",
|
|
560
563
|
domain: "AGENT" /* AGENT */,
|
|
561
564
|
category: "USER" /* USER */,
|
|
@@ -563,7 +566,7 @@ var StructuredOutputProcessor = class {
|
|
|
563
566
|
});
|
|
564
567
|
}
|
|
565
568
|
if (!options.model) {
|
|
566
|
-
throw new
|
|
569
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
567
570
|
id: "STRUCTURED_OUTPUT_PROCESSOR_MODEL_REQUIRED",
|
|
568
571
|
domain: "AGENT" /* AGENT */,
|
|
569
572
|
category: "USER" /* USER */,
|
|
@@ -833,7 +836,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
833
836
|
);
|
|
834
837
|
}
|
|
835
838
|
if (result.status !== "success") {
|
|
836
|
-
throw new
|
|
839
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
837
840
|
category: "USER",
|
|
838
841
|
domain: "AGENT",
|
|
839
842
|
id: "PROCESSOR_WORKFLOW_FAILED",
|
|
@@ -845,7 +848,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
845
848
|
return input;
|
|
846
849
|
}
|
|
847
850
|
if (!("phase" in output) || !("messages" in output || "part" in output || "messageList" in output)) {
|
|
848
|
-
throw new
|
|
851
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
849
852
|
category: "USER",
|
|
850
853
|
domain: "AGENT",
|
|
851
854
|
id: "PROCESSOR_WORKFLOW_INVALID_OUTPUT",
|
|
@@ -925,9 +928,9 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
925
928
|
retryCount
|
|
926
929
|
});
|
|
927
930
|
const mutations = messageList.stopRecording();
|
|
928
|
-
if (result instanceof
|
|
931
|
+
if (result instanceof chunkX6IBA7FP_cjs.MessageList) {
|
|
929
932
|
if (result !== messageList) {
|
|
930
|
-
throw new
|
|
933
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
931
934
|
category: "USER",
|
|
932
935
|
domain: "AGENT",
|
|
933
936
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -1207,9 +1210,9 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1207
1210
|
retryCount
|
|
1208
1211
|
});
|
|
1209
1212
|
let mutations;
|
|
1210
|
-
if (result instanceof
|
|
1213
|
+
if (result instanceof chunkX6IBA7FP_cjs.MessageList) {
|
|
1211
1214
|
if (result !== messageList) {
|
|
1212
|
-
throw new
|
|
1215
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
1213
1216
|
category: "USER",
|
|
1214
1217
|
domain: "AGENT",
|
|
1215
1218
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -1557,9 +1560,9 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1557
1560
|
retryCount
|
|
1558
1561
|
});
|
|
1559
1562
|
const mutations = messageList.stopRecording();
|
|
1560
|
-
if (result instanceof
|
|
1563
|
+
if (result instanceof chunkX6IBA7FP_cjs.MessageList) {
|
|
1561
1564
|
if (result !== messageList) {
|
|
1562
|
-
throw new
|
|
1565
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
1563
1566
|
category: "USER",
|
|
1564
1567
|
domain: "AGENT",
|
|
1565
1568
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -1627,9 +1630,9 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1627
1630
|
processor,
|
|
1628
1631
|
stepNumber
|
|
1629
1632
|
}) {
|
|
1630
|
-
if (result instanceof
|
|
1633
|
+
if (result instanceof chunkX6IBA7FP_cjs.MessageList) {
|
|
1631
1634
|
if (result !== messageList) {
|
|
1632
|
-
throw new
|
|
1635
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
1633
1636
|
category: "USER",
|
|
1634
1637
|
domain: "AGENT",
|
|
1635
1638
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -1645,7 +1648,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1645
1648
|
};
|
|
1646
1649
|
} else if (result) {
|
|
1647
1650
|
if (result.messageList && result.messageList !== messageList) {
|
|
1648
|
-
throw new
|
|
1651
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
1649
1652
|
category: "USER",
|
|
1650
1653
|
domain: "AGENT",
|
|
1651
1654
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -1653,7 +1656,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1653
1656
|
});
|
|
1654
1657
|
}
|
|
1655
1658
|
if (result.messages && result.messageList) {
|
|
1656
|
-
throw new
|
|
1659
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
1657
1660
|
category: "USER",
|
|
1658
1661
|
domain: "AGENT",
|
|
1659
1662
|
id: "PROCESSOR_RETURNED_MESSAGES_AND_MESSAGE_LIST",
|
|
@@ -1662,9 +1665,9 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1662
1665
|
}
|
|
1663
1666
|
const { model: _model, ...rest } = result;
|
|
1664
1667
|
if (result.model) {
|
|
1665
|
-
const resolvedModel = await
|
|
1668
|
+
const resolvedModel = await chunkMXBVP7HX_cjs.resolveModelConfig(result.model);
|
|
1666
1669
|
if (resolvedModel.specificationVersion === "v1") {
|
|
1667
|
-
throw new
|
|
1670
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
1668
1671
|
category: "USER",
|
|
1669
1672
|
domain: "AGENT",
|
|
1670
1673
|
id: "PROCESSOR_RETURNED_V1_MODEL",
|
|
@@ -1983,7 +1986,7 @@ function convertMastraChunkToAISDKv5({
|
|
|
1983
1986
|
if (mode === "generate") {
|
|
1984
1987
|
return {
|
|
1985
1988
|
type: "file",
|
|
1986
|
-
file: new
|
|
1989
|
+
file: new chunkX6IBA7FP_cjs.DefaultGeneratedFile({
|
|
1987
1990
|
data: chunk.payload.data,
|
|
1988
1991
|
mediaType: chunk.payload.mimeType
|
|
1989
1992
|
})
|
|
@@ -1991,7 +1994,7 @@ function convertMastraChunkToAISDKv5({
|
|
|
1991
1994
|
}
|
|
1992
1995
|
return {
|
|
1993
1996
|
type: "file",
|
|
1994
|
-
file: new
|
|
1997
|
+
file: new chunkX6IBA7FP_cjs.DefaultGeneratedFileWithType({
|
|
1995
1998
|
data: chunk.payload.data,
|
|
1996
1999
|
mediaType: chunk.payload.mimeType
|
|
1997
2000
|
})
|
|
@@ -2126,7 +2129,7 @@ var AISDKV5OutputStream = class {
|
|
|
2126
2129
|
this.traceId = options.tracingContext?.currentSpan?.externalTraceId;
|
|
2127
2130
|
}
|
|
2128
2131
|
toTextStreamResponse(init) {
|
|
2129
|
-
return
|
|
2132
|
+
return chunkNESKUIRE_cjs.createTextStreamResponse({
|
|
2130
2133
|
// Type assertion needed due to ReadableStream type mismatch between Node.js (stream/web) and DOM types
|
|
2131
2134
|
// Both have the same interface but TypeScript treats them as incompatible
|
|
2132
2135
|
textStream: this.#modelOutput.textStream,
|
|
@@ -2145,7 +2148,7 @@ var AISDKV5OutputStream = class {
|
|
|
2145
2148
|
onFinish,
|
|
2146
2149
|
...init
|
|
2147
2150
|
} = {}) {
|
|
2148
|
-
return
|
|
2151
|
+
return chunkNESKUIRE_cjs.createUIMessageStreamResponse({
|
|
2149
2152
|
stream: this.toUIMessageStream({
|
|
2150
2153
|
generateMessageId,
|
|
2151
2154
|
originalMessages,
|
|
@@ -2175,10 +2178,10 @@ var AISDKV5OutputStream = class {
|
|
|
2175
2178
|
originalMessages,
|
|
2176
2179
|
responseMessageId: generateMessageId
|
|
2177
2180
|
}) : void 0;
|
|
2178
|
-
return
|
|
2181
|
+
return chunkNESKUIRE_cjs.createUIMessageStream({
|
|
2179
2182
|
onError,
|
|
2180
2183
|
onFinish,
|
|
2181
|
-
generateId: () => responseMessageId ?? generateMessageId?.() ??
|
|
2184
|
+
generateId: () => responseMessageId ?? generateMessageId?.() ?? chunkFVQTJUBD_cjs.generateId(),
|
|
2182
2185
|
execute: async ({ writer }) => {
|
|
2183
2186
|
for await (const part of this.fullStream) {
|
|
2184
2187
|
const messageMetadataValue = messageMetadata?.({ part });
|
|
@@ -2394,6 +2397,8 @@ var AISDKV5OutputStream = class {
|
|
|
2394
2397
|
return this.#modelOutput.object;
|
|
2395
2398
|
}
|
|
2396
2399
|
};
|
|
2400
|
+
|
|
2401
|
+
// src/stream/base/schema.ts
|
|
2397
2402
|
function asJsonSchema(schema) {
|
|
2398
2403
|
if (!schema) {
|
|
2399
2404
|
return void 0;
|
|
@@ -2401,7 +2406,7 @@ function asJsonSchema(schema) {
|
|
|
2401
2406
|
if (schema && typeof schema === "object" && !schema.safeParse && !schema.jsonSchema) {
|
|
2402
2407
|
return schema;
|
|
2403
2408
|
}
|
|
2404
|
-
return
|
|
2409
|
+
return chunkFVQTJUBD_cjs.asSchema(schema).jsonSchema;
|
|
2405
2410
|
}
|
|
2406
2411
|
function getTransformedSchema(schema) {
|
|
2407
2412
|
let jsonSchema2;
|
|
@@ -2544,7 +2549,7 @@ var BaseFormatHandler = class {
|
|
|
2544
2549
|
} else {
|
|
2545
2550
|
return {
|
|
2546
2551
|
success: false,
|
|
2547
|
-
error: new
|
|
2552
|
+
error: new chunkHWMMIRIF_cjs.MastraError(
|
|
2548
2553
|
{
|
|
2549
2554
|
domain: "AGENT" /* AGENT */,
|
|
2550
2555
|
category: "SYSTEM" /* SYSTEM */,
|
|
@@ -2569,7 +2574,7 @@ ${z4__default.default.prettifyError(result.error)}
|
|
|
2569
2574
|
}
|
|
2570
2575
|
try {
|
|
2571
2576
|
if (typeof this.schema === "object" && !this.schema.jsonSchema) {
|
|
2572
|
-
const result = await safeValidateTypes({ value, schema:
|
|
2577
|
+
const result = await safeValidateTypes({ value, schema: chunkFVQTJUBD_cjs.jsonSchema(this.schema) });
|
|
2573
2578
|
return result;
|
|
2574
2579
|
} else if (this.schema.jsonSchema) {
|
|
2575
2580
|
const result = await safeValidateTypes({
|
|
@@ -2624,10 +2629,10 @@ var ObjectFormatHandler = class extends BaseFormatHandler {
|
|
|
2624
2629
|
previousObject
|
|
2625
2630
|
}) {
|
|
2626
2631
|
const processedAccumulatedText = this.preprocessText(accumulatedText);
|
|
2627
|
-
const { value: currentObjectJson, state } = await
|
|
2632
|
+
const { value: currentObjectJson, state } = await chunkNESKUIRE_cjs.parsePartialJson(processedAccumulatedText);
|
|
2628
2633
|
if (this.validatePartialChunks && this.partialSchema) {
|
|
2629
2634
|
const result = this.partialSchema?.safeParse(currentObjectJson);
|
|
2630
|
-
if (result.success && result.data && result.data !== void 0 && !
|
|
2635
|
+
if (result.success && result.data && result.data !== void 0 && !chunkNESKUIRE_cjs.isDeepEqualData(previousObject, result.data)) {
|
|
2631
2636
|
return {
|
|
2632
2637
|
shouldEmit: true,
|
|
2633
2638
|
emitValue: result.data,
|
|
@@ -2636,7 +2641,7 @@ var ObjectFormatHandler = class extends BaseFormatHandler {
|
|
|
2636
2641
|
}
|
|
2637
2642
|
return { shouldEmit: false };
|
|
2638
2643
|
}
|
|
2639
|
-
if (currentObjectJson !== void 0 && currentObjectJson !== null && typeof currentObjectJson === "object" && !
|
|
2644
|
+
if (currentObjectJson !== void 0 && currentObjectJson !== null && typeof currentObjectJson === "object" && !chunkNESKUIRE_cjs.isDeepEqualData(previousObject, currentObjectJson)) {
|
|
2640
2645
|
return {
|
|
2641
2646
|
shouldEmit: ["successful-parse", "repaired-parse"].includes(state),
|
|
2642
2647
|
emitValue: currentObjectJson,
|
|
@@ -2653,7 +2658,7 @@ var ObjectFormatHandler = class extends BaseFormatHandler {
|
|
|
2653
2658
|
};
|
|
2654
2659
|
}
|
|
2655
2660
|
const rawValue = this.preprocessText(finalRawValue);
|
|
2656
|
-
const { value } = await
|
|
2661
|
+
const { value } = await chunkNESKUIRE_cjs.parsePartialJson(rawValue);
|
|
2657
2662
|
return this.validateValue(value);
|
|
2658
2663
|
}
|
|
2659
2664
|
};
|
|
@@ -2668,8 +2673,8 @@ var ArrayFormatHandler = class extends BaseFormatHandler {
|
|
|
2668
2673
|
previousObject
|
|
2669
2674
|
}) {
|
|
2670
2675
|
const processedAccumulatedText = this.preprocessText(accumulatedText);
|
|
2671
|
-
const { value: currentObjectJson, state: parseState } = await
|
|
2672
|
-
if (currentObjectJson !== void 0 && !
|
|
2676
|
+
const { value: currentObjectJson, state: parseState } = await chunkNESKUIRE_cjs.parsePartialJson(processedAccumulatedText);
|
|
2677
|
+
if (currentObjectJson !== void 0 && !chunkNESKUIRE_cjs.isDeepEqualData(previousObject, currentObjectJson)) {
|
|
2673
2678
|
const rawElements = currentObjectJson?.elements || [];
|
|
2674
2679
|
const filteredElements = [];
|
|
2675
2680
|
for (let i = 0; i < rawElements.length; i++) {
|
|
@@ -2695,7 +2700,7 @@ var ArrayFormatHandler = class extends BaseFormatHandler {
|
|
|
2695
2700
|
};
|
|
2696
2701
|
}
|
|
2697
2702
|
}
|
|
2698
|
-
if (!
|
|
2703
|
+
if (!chunkNESKUIRE_cjs.isDeepEqualData(this.textPreviousFilteredArray, filteredElements)) {
|
|
2699
2704
|
this.textPreviousFilteredArray = [...filteredElements];
|
|
2700
2705
|
return {
|
|
2701
2706
|
shouldEmit: true,
|
|
@@ -2733,10 +2738,10 @@ var EnumFormatHandler = class extends BaseFormatHandler {
|
|
|
2733
2738
|
}
|
|
2734
2739
|
let enumValues;
|
|
2735
2740
|
if (this.isZodSchema(this.schema)) {
|
|
2736
|
-
const wrappedSchema =
|
|
2741
|
+
const wrappedSchema = chunkFVQTJUBD_cjs.asSchema(this.schema);
|
|
2737
2742
|
enumValues = wrappedSchema.jsonSchema?.enum;
|
|
2738
2743
|
} else if (typeof this.schema === "object" && !this.schema.jsonSchema) {
|
|
2739
|
-
const wrappedSchema =
|
|
2744
|
+
const wrappedSchema = chunkFVQTJUBD_cjs.jsonSchema(this.schema);
|
|
2740
2745
|
enumValues = wrappedSchema.jsonSchema?.enum;
|
|
2741
2746
|
} else {
|
|
2742
2747
|
enumValues = this.schema.jsonSchema?.enum;
|
|
@@ -2756,8 +2761,8 @@ var EnumFormatHandler = class extends BaseFormatHandler {
|
|
|
2756
2761
|
previousObject
|
|
2757
2762
|
}) {
|
|
2758
2763
|
const processedAccumulatedText = this.preprocessText(accumulatedText);
|
|
2759
|
-
const { value: currentObjectJson } = await
|
|
2760
|
-
if (currentObjectJson !== void 0 && currentObjectJson !== null && typeof currentObjectJson === "object" && !Array.isArray(currentObjectJson) && "result" in currentObjectJson && typeof currentObjectJson.result === "string" && !
|
|
2764
|
+
const { value: currentObjectJson } = await chunkNESKUIRE_cjs.parsePartialJson(processedAccumulatedText);
|
|
2765
|
+
if (currentObjectJson !== void 0 && currentObjectJson !== null && typeof currentObjectJson === "object" && !Array.isArray(currentObjectJson) && "result" in currentObjectJson && typeof currentObjectJson.result === "string" && !chunkNESKUIRE_cjs.isDeepEqualData(previousObject, currentObjectJson)) {
|
|
2761
2766
|
const partialResult = currentObjectJson.result;
|
|
2762
2767
|
const bestMatch = this.findBestEnumMatch(partialResult);
|
|
2763
2768
|
if (partialResult.length > 0 && bestMatch && bestMatch !== this.textPreviousEnumResult) {
|
|
@@ -2773,7 +2778,7 @@ var EnumFormatHandler = class extends BaseFormatHandler {
|
|
|
2773
2778
|
}
|
|
2774
2779
|
async validateAndTransformFinal(rawFinalValue) {
|
|
2775
2780
|
const processedValue = this.preprocessText(rawFinalValue);
|
|
2776
|
-
const { value } = await
|
|
2781
|
+
const { value } = await chunkNESKUIRE_cjs.parsePartialJson(processedValue);
|
|
2777
2782
|
if (!(typeof value === "object" && value !== null && "result" in value)) {
|
|
2778
2783
|
return {
|
|
2779
2784
|
success: false,
|
|
@@ -3425,7 +3430,7 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
3425
3430
|
);
|
|
3426
3431
|
const responseMessages = self.messageList.get.response.aiV4.core();
|
|
3427
3432
|
const lastResponseMessage = responseMessages[responseMessages.length - 1];
|
|
3428
|
-
const outputText = lastResponseMessage ?
|
|
3433
|
+
const outputText = lastResponseMessage ? chunkX6IBA7FP_cjs.MessageList.coreContentToString(lastResponseMessage.content) : "";
|
|
3429
3434
|
if (lastStep && outputText && outputText !== originalText) {
|
|
3430
3435
|
lastStep.text = outputText;
|
|
3431
3436
|
}
|
|
@@ -3455,7 +3460,7 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
3455
3460
|
self.#delayedPromises.finishReason.resolve("other");
|
|
3456
3461
|
self.#delayedPromises.text.resolve("");
|
|
3457
3462
|
} else {
|
|
3458
|
-
self.#error =
|
|
3463
|
+
self.#error = chunkHWMMIRIF_cjs.getErrorFromUnknown(error2, {
|
|
3459
3464
|
fallbackMessage: "Unknown error in stream"
|
|
3460
3465
|
});
|
|
3461
3466
|
self.#delayedPromises.finishReason.resolve("error");
|
|
@@ -3528,7 +3533,7 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
3528
3533
|
}
|
|
3529
3534
|
break;
|
|
3530
3535
|
case "error":
|
|
3531
|
-
const error =
|
|
3536
|
+
const error = chunkHWMMIRIF_cjs.getErrorFromUnknown(chunk.payload.error, {
|
|
3532
3537
|
fallbackMessage: "Unknown error chunk in stream"
|
|
3533
3538
|
});
|
|
3534
3539
|
self.#error = error;
|
|
@@ -4619,59 +4624,89 @@ function runScorer({
|
|
|
4619
4624
|
function isV2Model(model) {
|
|
4620
4625
|
return model.specificationVersion === "v2";
|
|
4621
4626
|
}
|
|
4622
|
-
var
|
|
4623
|
-
|
|
4624
|
-
|
|
4627
|
+
var EventEmitterPubSub = class extends chunk4D4KB75Y_cjs.PubSub {
|
|
4628
|
+
emitter;
|
|
4629
|
+
constructor(existingEmitter) {
|
|
4630
|
+
super();
|
|
4631
|
+
this.emitter = existingEmitter ?? new EventEmitter2__default.default();
|
|
4632
|
+
}
|
|
4633
|
+
async publish(topic, event) {
|
|
4634
|
+
const id = crypto.randomUUID();
|
|
4635
|
+
const createdAt = /* @__PURE__ */ new Date();
|
|
4636
|
+
this.emitter.emit(topic, {
|
|
4637
|
+
...event,
|
|
4638
|
+
id,
|
|
4639
|
+
createdAt
|
|
4640
|
+
});
|
|
4641
|
+
}
|
|
4642
|
+
async subscribe(topic, cb) {
|
|
4643
|
+
this.emitter.on(topic, cb);
|
|
4644
|
+
}
|
|
4645
|
+
async unsubscribe(topic, cb) {
|
|
4646
|
+
this.emitter.off(topic, cb);
|
|
4647
|
+
}
|
|
4648
|
+
async flush() {
|
|
4649
|
+
}
|
|
4650
|
+
/**
|
|
4651
|
+
* Clean up all listeners during graceful shutdown.
|
|
4652
|
+
*/
|
|
4653
|
+
async close() {
|
|
4654
|
+
this.emitter.removeAllListeners();
|
|
4655
|
+
}
|
|
4656
|
+
};
|
|
4657
|
+
var TextPartSchema = z8.z.object({
|
|
4658
|
+
type: z8.z.literal("text"),
|
|
4659
|
+
text: z8.z.string()
|
|
4625
4660
|
}).passthrough();
|
|
4626
|
-
var ImagePartSchema =
|
|
4627
|
-
type:
|
|
4628
|
-
image:
|
|
4629
|
-
mimeType:
|
|
4661
|
+
var ImagePartSchema = z8.z.object({
|
|
4662
|
+
type: z8.z.literal("image"),
|
|
4663
|
+
image: z8.z.union([z8.z.string(), z8.z.instanceof(URL), z8.z.instanceof(Uint8Array)]),
|
|
4664
|
+
mimeType: z8.z.string().optional()
|
|
4630
4665
|
}).passthrough();
|
|
4631
|
-
var FilePartSchema =
|
|
4632
|
-
type:
|
|
4633
|
-
data:
|
|
4634
|
-
mimeType:
|
|
4666
|
+
var FilePartSchema = z8.z.object({
|
|
4667
|
+
type: z8.z.literal("file"),
|
|
4668
|
+
data: z8.z.union([z8.z.string(), z8.z.instanceof(URL), z8.z.instanceof(Uint8Array)]),
|
|
4669
|
+
mimeType: z8.z.string()
|
|
4635
4670
|
}).passthrough();
|
|
4636
|
-
var ToolInvocationPartSchema =
|
|
4637
|
-
type:
|
|
4638
|
-
toolInvocation:
|
|
4639
|
-
toolCallId:
|
|
4640
|
-
toolName:
|
|
4641
|
-
args:
|
|
4642
|
-
state:
|
|
4643
|
-
result:
|
|
4671
|
+
var ToolInvocationPartSchema = z8.z.object({
|
|
4672
|
+
type: z8.z.literal("tool-invocation"),
|
|
4673
|
+
toolInvocation: z8.z.object({
|
|
4674
|
+
toolCallId: z8.z.string(),
|
|
4675
|
+
toolName: z8.z.string(),
|
|
4676
|
+
args: z8.z.unknown(),
|
|
4677
|
+
state: z8.z.enum(["partial-call", "call", "result"]),
|
|
4678
|
+
result: z8.z.unknown().optional()
|
|
4644
4679
|
})
|
|
4645
4680
|
}).passthrough();
|
|
4646
|
-
var ReasoningPartSchema =
|
|
4647
|
-
type:
|
|
4648
|
-
reasoning:
|
|
4649
|
-
details:
|
|
4650
|
-
|
|
4651
|
-
type:
|
|
4652
|
-
text:
|
|
4653
|
-
data:
|
|
4681
|
+
var ReasoningPartSchema = z8.z.object({
|
|
4682
|
+
type: z8.z.literal("reasoning"),
|
|
4683
|
+
reasoning: z8.z.string(),
|
|
4684
|
+
details: z8.z.array(
|
|
4685
|
+
z8.z.object({
|
|
4686
|
+
type: z8.z.enum(["text", "redacted"]),
|
|
4687
|
+
text: z8.z.string().optional(),
|
|
4688
|
+
data: z8.z.string().optional()
|
|
4654
4689
|
})
|
|
4655
4690
|
)
|
|
4656
4691
|
}).passthrough();
|
|
4657
|
-
var SourcePartSchema =
|
|
4658
|
-
type:
|
|
4659
|
-
source:
|
|
4660
|
-
sourceType:
|
|
4661
|
-
id:
|
|
4662
|
-
url:
|
|
4663
|
-
title:
|
|
4692
|
+
var SourcePartSchema = z8.z.object({
|
|
4693
|
+
type: z8.z.literal("source"),
|
|
4694
|
+
source: z8.z.object({
|
|
4695
|
+
sourceType: z8.z.string(),
|
|
4696
|
+
id: z8.z.string(),
|
|
4697
|
+
url: z8.z.string().optional(),
|
|
4698
|
+
title: z8.z.string().optional()
|
|
4664
4699
|
})
|
|
4665
4700
|
}).passthrough();
|
|
4666
|
-
var StepStartPartSchema =
|
|
4667
|
-
type:
|
|
4701
|
+
var StepStartPartSchema = z8.z.object({
|
|
4702
|
+
type: z8.z.literal("step-start")
|
|
4668
4703
|
}).passthrough();
|
|
4669
|
-
var DataPartSchema =
|
|
4670
|
-
type:
|
|
4671
|
-
id:
|
|
4672
|
-
data:
|
|
4704
|
+
var DataPartSchema = z8.z.object({
|
|
4705
|
+
type: z8.z.string().refine((t) => t.startsWith("data-"), { message: 'Type must start with "data-"' }),
|
|
4706
|
+
id: z8.z.string().optional(),
|
|
4707
|
+
data: z8.z.unknown()
|
|
4673
4708
|
}).passthrough();
|
|
4674
|
-
var MessagePartSchema =
|
|
4709
|
+
var MessagePartSchema = z8.z.union([
|
|
4675
4710
|
TextPartSchema,
|
|
4676
4711
|
ImagePartSchema,
|
|
4677
4712
|
FilePartSchema,
|
|
@@ -4681,153 +4716,153 @@ var MessagePartSchema = z7.z.union([
|
|
|
4681
4716
|
StepStartPartSchema,
|
|
4682
4717
|
DataPartSchema
|
|
4683
4718
|
]);
|
|
4684
|
-
var MessageContentSchema =
|
|
4719
|
+
var MessageContentSchema = z8.z.object({
|
|
4685
4720
|
/** Format version - 2 corresponds to AI SDK v4 UIMessage format */
|
|
4686
|
-
format:
|
|
4721
|
+
format: z8.z.literal(2),
|
|
4687
4722
|
/** Array of message parts (text, images, tool calls, etc.) */
|
|
4688
|
-
parts:
|
|
4723
|
+
parts: z8.z.array(MessagePartSchema),
|
|
4689
4724
|
/** Legacy content field for backwards compatibility */
|
|
4690
|
-
content:
|
|
4725
|
+
content: z8.z.string().optional(),
|
|
4691
4726
|
/** Additional metadata */
|
|
4692
|
-
metadata:
|
|
4727
|
+
metadata: z8.z.record(z8.z.unknown()).optional(),
|
|
4693
4728
|
/** Provider-specific metadata */
|
|
4694
|
-
providerMetadata:
|
|
4729
|
+
providerMetadata: z8.z.record(z8.z.unknown()).optional()
|
|
4695
4730
|
});
|
|
4696
|
-
var ProcessorMessageContentSchema =
|
|
4731
|
+
var ProcessorMessageContentSchema = z8.z.object({
|
|
4697
4732
|
/** Format version - 2 corresponds to AI SDK v4 UIMessage format */
|
|
4698
|
-
format:
|
|
4733
|
+
format: z8.z.literal(2),
|
|
4699
4734
|
/** Array of message parts (text, images, tool calls, etc.) */
|
|
4700
|
-
parts:
|
|
4735
|
+
parts: z8.z.array(MessagePartSchema),
|
|
4701
4736
|
/** Legacy content field for backwards compatibility */
|
|
4702
|
-
content:
|
|
4737
|
+
content: z8.z.string().optional(),
|
|
4703
4738
|
/** Additional metadata */
|
|
4704
|
-
metadata:
|
|
4739
|
+
metadata: z8.z.record(z8.z.unknown()).optional(),
|
|
4705
4740
|
/** Provider-specific metadata */
|
|
4706
|
-
providerMetadata:
|
|
4741
|
+
providerMetadata: z8.z.record(z8.z.unknown()).optional()
|
|
4707
4742
|
}).passthrough();
|
|
4708
|
-
var ProcessorMessageSchema =
|
|
4743
|
+
var ProcessorMessageSchema = z8.z.object({
|
|
4709
4744
|
/** Unique message identifier */
|
|
4710
|
-
id:
|
|
4745
|
+
id: z8.z.string(),
|
|
4711
4746
|
/** Message role */
|
|
4712
|
-
role:
|
|
4747
|
+
role: z8.z.enum(["user", "assistant", "system", "tool"]),
|
|
4713
4748
|
/** When the message was created */
|
|
4714
|
-
createdAt:
|
|
4749
|
+
createdAt: z8.z.coerce.date(),
|
|
4715
4750
|
/** Thread identifier for conversation grouping */
|
|
4716
|
-
threadId:
|
|
4751
|
+
threadId: z8.z.string().optional(),
|
|
4717
4752
|
/** Resource identifier */
|
|
4718
|
-
resourceId:
|
|
4753
|
+
resourceId: z8.z.string().optional(),
|
|
4719
4754
|
/** Message type */
|
|
4720
|
-
type:
|
|
4755
|
+
type: z8.z.string().optional(),
|
|
4721
4756
|
/** Message content with parts */
|
|
4722
4757
|
content: ProcessorMessageContentSchema
|
|
4723
4758
|
}).passthrough();
|
|
4724
|
-
var messageListSchema =
|
|
4725
|
-
var messagesSchema =
|
|
4726
|
-
var SystemMessageTextPartSchema =
|
|
4727
|
-
type:
|
|
4728
|
-
text:
|
|
4759
|
+
var messageListSchema = z8.z.custom();
|
|
4760
|
+
var messagesSchema = z8.z.array(ProcessorMessageSchema);
|
|
4761
|
+
var SystemMessageTextPartSchema = z8.z.object({
|
|
4762
|
+
type: z8.z.literal("text"),
|
|
4763
|
+
text: z8.z.string()
|
|
4729
4764
|
}).passthrough();
|
|
4730
|
-
|
|
4731
|
-
role:
|
|
4732
|
-
content:
|
|
4765
|
+
z8.z.object({
|
|
4766
|
+
role: z8.z.literal("system"),
|
|
4767
|
+
content: z8.z.union([z8.z.string(), z8.z.array(SystemMessageTextPartSchema)]),
|
|
4733
4768
|
/** Optional experimental provider-specific extensions */
|
|
4734
|
-
experimental_providerMetadata:
|
|
4769
|
+
experimental_providerMetadata: z8.z.record(z8.z.unknown()).optional()
|
|
4735
4770
|
}).passthrough();
|
|
4736
|
-
var CoreMessageSchema =
|
|
4737
|
-
role:
|
|
4738
|
-
content:
|
|
4771
|
+
var CoreMessageSchema = z8.z.object({
|
|
4772
|
+
role: z8.z.enum(["system", "user", "assistant", "tool"]),
|
|
4773
|
+
content: z8.z.unknown()
|
|
4739
4774
|
}).passthrough();
|
|
4740
|
-
var systemMessagesSchema =
|
|
4741
|
-
var toolCallSchema =
|
|
4742
|
-
toolName:
|
|
4743
|
-
toolCallId:
|
|
4744
|
-
args:
|
|
4775
|
+
var systemMessagesSchema = z8.z.array(CoreMessageSchema);
|
|
4776
|
+
var toolCallSchema = z8.z.object({
|
|
4777
|
+
toolName: z8.z.string(),
|
|
4778
|
+
toolCallId: z8.z.string(),
|
|
4779
|
+
args: z8.z.unknown()
|
|
4745
4780
|
});
|
|
4746
|
-
var retryCountSchema =
|
|
4747
|
-
var ProcessorInputPhaseSchema =
|
|
4748
|
-
phase:
|
|
4781
|
+
var retryCountSchema = z8.z.number().optional();
|
|
4782
|
+
var ProcessorInputPhaseSchema = z8.z.object({
|
|
4783
|
+
phase: z8.z.literal("input"),
|
|
4749
4784
|
messages: messagesSchema,
|
|
4750
4785
|
messageList: messageListSchema,
|
|
4751
4786
|
systemMessages: systemMessagesSchema.optional(),
|
|
4752
4787
|
retryCount: retryCountSchema
|
|
4753
4788
|
});
|
|
4754
|
-
var ProcessorInputStepPhaseSchema =
|
|
4755
|
-
phase:
|
|
4789
|
+
var ProcessorInputStepPhaseSchema = z8.z.object({
|
|
4790
|
+
phase: z8.z.literal("inputStep"),
|
|
4756
4791
|
messages: messagesSchema,
|
|
4757
4792
|
messageList: messageListSchema,
|
|
4758
|
-
stepNumber:
|
|
4793
|
+
stepNumber: z8.z.number().describe("The current step number (0-indexed)"),
|
|
4759
4794
|
systemMessages: systemMessagesSchema.optional(),
|
|
4760
4795
|
retryCount: retryCountSchema,
|
|
4761
4796
|
// Model and tools configuration (can be modified by processors)
|
|
4762
|
-
model:
|
|
4763
|
-
tools:
|
|
4764
|
-
toolChoice:
|
|
4765
|
-
activeTools:
|
|
4766
|
-
providerOptions:
|
|
4767
|
-
modelSettings:
|
|
4768
|
-
structuredOutput:
|
|
4769
|
-
steps:
|
|
4797
|
+
model: z8.z.custom().optional().describe("Current model for this step"),
|
|
4798
|
+
tools: z8.z.custom().optional().describe("Current tools available for this step"),
|
|
4799
|
+
toolChoice: z8.z.custom().optional().describe("Current tool choice setting"),
|
|
4800
|
+
activeTools: z8.z.array(z8.z.string()).optional().describe("Currently active tools"),
|
|
4801
|
+
providerOptions: z8.z.custom().optional().describe("Provider-specific options"),
|
|
4802
|
+
modelSettings: z8.z.custom().optional().describe("Model settings (temperature, etc.)"),
|
|
4803
|
+
structuredOutput: z8.z.custom().optional().describe("Structured output configuration"),
|
|
4804
|
+
steps: z8.z.custom().optional().describe("Results from previous steps")
|
|
4770
4805
|
});
|
|
4771
|
-
var ProcessorOutputStreamPhaseSchema =
|
|
4772
|
-
phase:
|
|
4773
|
-
part:
|
|
4774
|
-
streamParts:
|
|
4775
|
-
state:
|
|
4806
|
+
var ProcessorOutputStreamPhaseSchema = z8.z.object({
|
|
4807
|
+
phase: z8.z.literal("outputStream"),
|
|
4808
|
+
part: z8.z.unknown().nullable().describe("The current chunk being processed. Can be null to skip."),
|
|
4809
|
+
streamParts: z8.z.array(z8.z.unknown()).describe("All chunks seen so far"),
|
|
4810
|
+
state: z8.z.record(z8.z.unknown()).describe("Mutable state object that persists across chunks"),
|
|
4776
4811
|
messageList: messageListSchema.optional(),
|
|
4777
4812
|
retryCount: retryCountSchema
|
|
4778
4813
|
});
|
|
4779
|
-
var ProcessorOutputResultPhaseSchema =
|
|
4780
|
-
phase:
|
|
4814
|
+
var ProcessorOutputResultPhaseSchema = z8.z.object({
|
|
4815
|
+
phase: z8.z.literal("outputResult"),
|
|
4781
4816
|
messages: messagesSchema,
|
|
4782
4817
|
messageList: messageListSchema,
|
|
4783
4818
|
retryCount: retryCountSchema
|
|
4784
4819
|
});
|
|
4785
|
-
var ProcessorOutputStepPhaseSchema =
|
|
4786
|
-
phase:
|
|
4820
|
+
var ProcessorOutputStepPhaseSchema = z8.z.object({
|
|
4821
|
+
phase: z8.z.literal("outputStep"),
|
|
4787
4822
|
messages: messagesSchema,
|
|
4788
4823
|
messageList: messageListSchema,
|
|
4789
|
-
stepNumber:
|
|
4790
|
-
finishReason:
|
|
4791
|
-
toolCalls:
|
|
4792
|
-
text:
|
|
4824
|
+
stepNumber: z8.z.number().describe("The current step number (0-indexed)"),
|
|
4825
|
+
finishReason: z8.z.string().optional().describe("The finish reason from the LLM (stop, tool-use, length, etc.)"),
|
|
4826
|
+
toolCalls: z8.z.array(toolCallSchema).optional().describe("Tool calls made in this step (if any)"),
|
|
4827
|
+
text: z8.z.string().optional().describe("Generated text from this step"),
|
|
4793
4828
|
systemMessages: systemMessagesSchema.optional(),
|
|
4794
4829
|
retryCount: retryCountSchema
|
|
4795
4830
|
});
|
|
4796
|
-
var ProcessorStepInputSchema =
|
|
4831
|
+
var ProcessorStepInputSchema = z8.z.discriminatedUnion("phase", [
|
|
4797
4832
|
ProcessorInputPhaseSchema,
|
|
4798
4833
|
ProcessorInputStepPhaseSchema,
|
|
4799
4834
|
ProcessorOutputStreamPhaseSchema,
|
|
4800
4835
|
ProcessorOutputResultPhaseSchema,
|
|
4801
4836
|
ProcessorOutputStepPhaseSchema
|
|
4802
4837
|
]);
|
|
4803
|
-
var ProcessorStepOutputSchema =
|
|
4838
|
+
var ProcessorStepOutputSchema = z8.z.object({
|
|
4804
4839
|
// Phase field
|
|
4805
|
-
phase:
|
|
4840
|
+
phase: z8.z.enum(["input", "inputStep", "outputStream", "outputResult", "outputStep"]),
|
|
4806
4841
|
// Message-based fields (used by most phases)
|
|
4807
4842
|
messages: messagesSchema.optional(),
|
|
4808
4843
|
messageList: messageListSchema.optional(),
|
|
4809
4844
|
systemMessages: systemMessagesSchema.optional(),
|
|
4810
4845
|
// Step-based fields
|
|
4811
|
-
stepNumber:
|
|
4846
|
+
stepNumber: z8.z.number().optional(),
|
|
4812
4847
|
// Stream-based fields
|
|
4813
|
-
part:
|
|
4814
|
-
streamParts:
|
|
4815
|
-
state:
|
|
4848
|
+
part: z8.z.unknown().nullable().optional(),
|
|
4849
|
+
streamParts: z8.z.array(z8.z.unknown()).optional(),
|
|
4850
|
+
state: z8.z.record(z8.z.unknown()).optional(),
|
|
4816
4851
|
// Output step fields
|
|
4817
|
-
finishReason:
|
|
4818
|
-
toolCalls:
|
|
4819
|
-
text:
|
|
4852
|
+
finishReason: z8.z.string().optional(),
|
|
4853
|
+
toolCalls: z8.z.array(toolCallSchema).optional(),
|
|
4854
|
+
text: z8.z.string().optional(),
|
|
4820
4855
|
// Retry count
|
|
4821
|
-
retryCount:
|
|
4856
|
+
retryCount: z8.z.number().optional(),
|
|
4822
4857
|
// Model and tools configuration (for inputStep phase)
|
|
4823
|
-
model:
|
|
4824
|
-
tools:
|
|
4825
|
-
toolChoice:
|
|
4826
|
-
activeTools:
|
|
4827
|
-
providerOptions:
|
|
4828
|
-
modelSettings:
|
|
4829
|
-
structuredOutput:
|
|
4830
|
-
steps:
|
|
4858
|
+
model: z8.z.custom().optional(),
|
|
4859
|
+
tools: z8.z.custom().optional(),
|
|
4860
|
+
toolChoice: z8.z.custom().optional(),
|
|
4861
|
+
activeTools: z8.z.array(z8.z.string()).optional(),
|
|
4862
|
+
providerOptions: z8.z.custom().optional(),
|
|
4863
|
+
modelSettings: z8.z.custom().optional(),
|
|
4864
|
+
structuredOutput: z8.z.custom().optional(),
|
|
4865
|
+
steps: z8.z.custom().optional()
|
|
4831
4866
|
});
|
|
4832
4867
|
var ProcessorStepSchema = ProcessorStepInputSchema;
|
|
4833
4868
|
|
|
@@ -4846,6 +4881,43 @@ var ExecutionEngine = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
4846
4881
|
getLogger() {
|
|
4847
4882
|
return this.logger;
|
|
4848
4883
|
}
|
|
4884
|
+
/**
|
|
4885
|
+
* Invokes the onFinish and onError lifecycle callbacks if they are defined.
|
|
4886
|
+
* Errors in callbacks are caught and logged, not propagated.
|
|
4887
|
+
* @param result The workflow result containing status, result, error, steps, and tripwire info
|
|
4888
|
+
*/
|
|
4889
|
+
async invokeLifecycleCallbacks(result) {
|
|
4890
|
+
const { onFinish, onError } = this.options;
|
|
4891
|
+
if (onFinish) {
|
|
4892
|
+
try {
|
|
4893
|
+
await Promise.resolve(
|
|
4894
|
+
onFinish({
|
|
4895
|
+
status: result.status,
|
|
4896
|
+
result: result.result,
|
|
4897
|
+
error: result.error,
|
|
4898
|
+
steps: result.steps,
|
|
4899
|
+
tripwire: result.tripwire
|
|
4900
|
+
})
|
|
4901
|
+
);
|
|
4902
|
+
} catch (err) {
|
|
4903
|
+
this.logger.error("Error in onFinish callback", { error: err });
|
|
4904
|
+
}
|
|
4905
|
+
}
|
|
4906
|
+
if (onError && (result.status === "failed" || result.status === "tripwire")) {
|
|
4907
|
+
try {
|
|
4908
|
+
await Promise.resolve(
|
|
4909
|
+
onError({
|
|
4910
|
+
status: result.status,
|
|
4911
|
+
error: result.error,
|
|
4912
|
+
steps: result.steps,
|
|
4913
|
+
tripwire: result.tripwire
|
|
4914
|
+
})
|
|
4915
|
+
);
|
|
4916
|
+
} catch (err) {
|
|
4917
|
+
this.logger.error("Error in onError callback", { error: err });
|
|
4918
|
+
}
|
|
4919
|
+
}
|
|
4920
|
+
}
|
|
4849
4921
|
};
|
|
4850
4922
|
|
|
4851
4923
|
// src/workflows/step.ts
|
|
@@ -4878,7 +4950,16 @@ async function validateStepInput({
|
|
|
4878
4950
|
if (!validatedInput.success) {
|
|
4879
4951
|
const errors = getZodErrors(validatedInput.error);
|
|
4880
4952
|
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
4881
|
-
validationError = new
|
|
4953
|
+
validationError = new chunkHWMMIRIF_cjs.MastraError(
|
|
4954
|
+
{
|
|
4955
|
+
id: "WORKFLOW_STEP_INPUT_VALIDATION_FAILED",
|
|
4956
|
+
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
4957
|
+
category: "USER" /* USER */,
|
|
4958
|
+
text: "Step input validation failed: \n" + errorMessages
|
|
4959
|
+
},
|
|
4960
|
+
// keep the original zod error as the cause for consumers
|
|
4961
|
+
validatedInput.error
|
|
4962
|
+
);
|
|
4882
4963
|
} else {
|
|
4883
4964
|
const isEmptyData = radash.isEmpty(validatedInput.data);
|
|
4884
4965
|
inputData = isEmptyData ? prevOutput : validatedInput.data;
|
|
@@ -4897,7 +4978,16 @@ async function validateStepResumeData({ resumeData, step }) {
|
|
|
4897
4978
|
if (!validatedResumeData.success) {
|
|
4898
4979
|
const errors = getZodErrors(validatedResumeData.error);
|
|
4899
4980
|
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
4900
|
-
validationError = new
|
|
4981
|
+
validationError = new chunkHWMMIRIF_cjs.MastraError(
|
|
4982
|
+
{
|
|
4983
|
+
id: "WORKFLOW_STEP_RESUME_DATA_VALIDATION_FAILED",
|
|
4984
|
+
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
4985
|
+
category: "USER" /* USER */,
|
|
4986
|
+
text: "Step resume data validation failed: \n" + errorMessages
|
|
4987
|
+
},
|
|
4988
|
+
// keep the original zod error as the cause for consumers
|
|
4989
|
+
validatedResumeData.error
|
|
4990
|
+
);
|
|
4901
4991
|
} else {
|
|
4902
4992
|
resumeData = validatedResumeData.data;
|
|
4903
4993
|
}
|
|
@@ -4919,7 +5009,16 @@ async function validateStepSuspendData({
|
|
|
4919
5009
|
if (!validatedSuspendData.success) {
|
|
4920
5010
|
const errors = getZodErrors(validatedSuspendData.error);
|
|
4921
5011
|
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
4922
|
-
validationError = new
|
|
5012
|
+
validationError = new chunkHWMMIRIF_cjs.MastraError(
|
|
5013
|
+
{
|
|
5014
|
+
id: "WORKFLOW_STEP_SUSPEND_DATA_VALIDATION_FAILED",
|
|
5015
|
+
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
5016
|
+
category: "USER" /* USER */,
|
|
5017
|
+
text: "Step suspend data validation failed: \n" + errorMessages
|
|
5018
|
+
},
|
|
5019
|
+
// keep the original zod error as the cause for consumers
|
|
5020
|
+
validatedSuspendData.error
|
|
5021
|
+
);
|
|
4923
5022
|
} else {
|
|
4924
5023
|
suspendData = validatedSuspendData.data;
|
|
4925
5024
|
}
|
|
@@ -5062,7 +5161,7 @@ var createTimeTravelExecutionParams = (params) => {
|
|
|
5062
5161
|
result = void 0;
|
|
5063
5162
|
}
|
|
5064
5163
|
if (result) {
|
|
5065
|
-
const formattedResult =
|
|
5164
|
+
const formattedResult = chunkMLKE7HRS_cjs.removeUndefinedValues(result);
|
|
5066
5165
|
stepResults[stepId] = formattedResult;
|
|
5067
5166
|
}
|
|
5068
5167
|
});
|
|
@@ -5083,6 +5182,16 @@ var createTimeTravelExecutionParams = (params) => {
|
|
|
5083
5182
|
};
|
|
5084
5183
|
return timeTravelData;
|
|
5085
5184
|
};
|
|
5185
|
+
function hydrateSerializedStepErrors(steps) {
|
|
5186
|
+
if (steps) {
|
|
5187
|
+
for (const step of Object.values(steps)) {
|
|
5188
|
+
if (step.status === "failed" && "error" in step && step.error) {
|
|
5189
|
+
step.error = chunkHWMMIRIF_cjs.getErrorFromUnknown(step.error, { serializeStack: false });
|
|
5190
|
+
}
|
|
5191
|
+
}
|
|
5192
|
+
}
|
|
5193
|
+
return steps;
|
|
5194
|
+
}
|
|
5086
5195
|
|
|
5087
5196
|
// src/workflows/handlers/control-flow.ts
|
|
5088
5197
|
async function executeParallel(engine, params) {
|
|
@@ -5099,7 +5208,7 @@ async function executeParallel(engine, params) {
|
|
|
5099
5208
|
timeTravel,
|
|
5100
5209
|
executionContext,
|
|
5101
5210
|
tracingContext,
|
|
5102
|
-
|
|
5211
|
+
pubsub,
|
|
5103
5212
|
abortController,
|
|
5104
5213
|
requestContext,
|
|
5105
5214
|
outputWriter,
|
|
@@ -5172,7 +5281,7 @@ async function executeParallel(engine, params) {
|
|
|
5172
5281
|
tracingContext: {
|
|
5173
5282
|
currentSpan: parallelSpan
|
|
5174
5283
|
},
|
|
5175
|
-
|
|
5284
|
+
pubsub,
|
|
5176
5285
|
abortController,
|
|
5177
5286
|
requestContext,
|
|
5178
5287
|
outputWriter,
|
|
@@ -5211,9 +5320,7 @@ async function executeParallel(engine, params) {
|
|
|
5211
5320
|
};
|
|
5212
5321
|
}
|
|
5213
5322
|
if (execResults.status === "failed") {
|
|
5214
|
-
parallelSpan?.error({
|
|
5215
|
-
error: new Error(execResults.error)
|
|
5216
|
-
});
|
|
5323
|
+
parallelSpan?.error({ error: execResults.error });
|
|
5217
5324
|
} else {
|
|
5218
5325
|
parallelSpan?.end({
|
|
5219
5326
|
output: execResults.output || execResults
|
|
@@ -5235,7 +5342,7 @@ async function executeConditional(engine, params) {
|
|
|
5235
5342
|
timeTravel,
|
|
5236
5343
|
executionContext,
|
|
5237
5344
|
tracingContext,
|
|
5238
|
-
|
|
5345
|
+
pubsub,
|
|
5239
5346
|
abortController,
|
|
5240
5347
|
requestContext,
|
|
5241
5348
|
outputWriter,
|
|
@@ -5282,8 +5389,8 @@ async function executeConditional(engine, params) {
|
|
|
5282
5389
|
abort: () => {
|
|
5283
5390
|
abortController?.abort();
|
|
5284
5391
|
},
|
|
5285
|
-
[
|
|
5286
|
-
[
|
|
5392
|
+
[chunkL3NKIMF5_cjs.PUBSUB_SYMBOL]: pubsub,
|
|
5393
|
+
[chunkL3NKIMF5_cjs.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
5287
5394
|
engine: engine.getEngineContext(),
|
|
5288
5395
|
abortSignal: abortController?.signal,
|
|
5289
5396
|
writer: new chunkKJBMTK5B_cjs.ToolStream(
|
|
@@ -5312,18 +5419,20 @@ async function executeConditional(engine, params) {
|
|
|
5312
5419
|
});
|
|
5313
5420
|
return result;
|
|
5314
5421
|
} catch (e) {
|
|
5315
|
-
const
|
|
5316
|
-
|
|
5422
|
+
const errorInstance = chunkHWMMIRIF_cjs.getErrorFromUnknown(e, { serializeStack: false });
|
|
5423
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError(
|
|
5317
5424
|
{
|
|
5318
5425
|
id: "WORKFLOW_CONDITION_EVALUATION_FAILED",
|
|
5319
|
-
domain: "MASTRA_WORKFLOW"
|
|
5320
|
-
category: "USER"
|
|
5426
|
+
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
5427
|
+
category: "USER" /* USER */,
|
|
5321
5428
|
details: { workflowId, runId }
|
|
5322
5429
|
},
|
|
5323
|
-
|
|
5430
|
+
errorInstance
|
|
5324
5431
|
);
|
|
5432
|
+
engine.getLogger()?.trackException(mastraError);
|
|
5433
|
+
engine.getLogger()?.error("Error evaluating condition: " + errorInstance.stack);
|
|
5325
5434
|
evalSpan?.error({
|
|
5326
|
-
error,
|
|
5435
|
+
error: mastraError,
|
|
5327
5436
|
attributes: {
|
|
5328
5437
|
result: false
|
|
5329
5438
|
}
|
|
@@ -5375,7 +5484,7 @@ async function executeConditional(engine, params) {
|
|
|
5375
5484
|
tracingContext: {
|
|
5376
5485
|
currentSpan: conditionalSpan
|
|
5377
5486
|
},
|
|
5378
|
-
|
|
5487
|
+
pubsub,
|
|
5379
5488
|
abortController,
|
|
5380
5489
|
requestContext,
|
|
5381
5490
|
outputWriter,
|
|
@@ -5415,9 +5524,7 @@ async function executeConditional(engine, params) {
|
|
|
5415
5524
|
};
|
|
5416
5525
|
}
|
|
5417
5526
|
if (execResults.status === "failed") {
|
|
5418
|
-
conditionalSpan?.error({
|
|
5419
|
-
error: new Error(execResults.error)
|
|
5420
|
-
});
|
|
5527
|
+
conditionalSpan?.error({ error: execResults.error });
|
|
5421
5528
|
} else {
|
|
5422
5529
|
conditionalSpan?.end({
|
|
5423
5530
|
output: execResults.output || execResults
|
|
@@ -5438,7 +5545,7 @@ async function executeLoop(engine, params) {
|
|
|
5438
5545
|
timeTravel,
|
|
5439
5546
|
executionContext,
|
|
5440
5547
|
tracingContext,
|
|
5441
|
-
|
|
5548
|
+
pubsub,
|
|
5442
5549
|
abortController,
|
|
5443
5550
|
requestContext,
|
|
5444
5551
|
outputWriter,
|
|
@@ -5478,7 +5585,7 @@ async function executeLoop(engine, params) {
|
|
|
5478
5585
|
tracingContext: {
|
|
5479
5586
|
currentSpan: loopSpan
|
|
5480
5587
|
},
|
|
5481
|
-
|
|
5588
|
+
pubsub,
|
|
5482
5589
|
abortController,
|
|
5483
5590
|
requestContext,
|
|
5484
5591
|
outputWriter,
|
|
@@ -5505,7 +5612,7 @@ async function executeLoop(engine, params) {
|
|
|
5505
5612
|
const evalSpan = loopSpan?.createChildSpan({
|
|
5506
5613
|
type: "workflow_conditional_eval" /* WORKFLOW_CONDITIONAL_EVAL */,
|
|
5507
5614
|
name: `condition: '${entry.loopType}'`,
|
|
5508
|
-
input:
|
|
5615
|
+
input: chunkMLKE7HRS_cjs.selectFields(result.output, ["stepResult", "output.text", "output.object", "messages"]),
|
|
5509
5616
|
attributes: {
|
|
5510
5617
|
conditionIndex: iteration
|
|
5511
5618
|
},
|
|
@@ -5532,8 +5639,8 @@ async function executeLoop(engine, params) {
|
|
|
5532
5639
|
abort: () => {
|
|
5533
5640
|
abortController?.abort();
|
|
5534
5641
|
},
|
|
5535
|
-
[
|
|
5536
|
-
[
|
|
5642
|
+
[chunkL3NKIMF5_cjs.PUBSUB_SYMBOL]: pubsub,
|
|
5643
|
+
[chunkL3NKIMF5_cjs.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
5537
5644
|
engine: engine.getEngineContext(),
|
|
5538
5645
|
abortSignal: abortController?.signal,
|
|
5539
5646
|
writer: new chunkKJBMTK5B_cjs.ToolStream(
|
|
@@ -5579,7 +5686,7 @@ async function executeForeach(engine, params) {
|
|
|
5579
5686
|
timeTravel,
|
|
5580
5687
|
executionContext,
|
|
5581
5688
|
tracingContext,
|
|
5582
|
-
|
|
5689
|
+
pubsub,
|
|
5583
5690
|
abortController,
|
|
5584
5691
|
requestContext,
|
|
5585
5692
|
outputWriter,
|
|
@@ -5607,12 +5714,16 @@ async function executeForeach(engine, params) {
|
|
|
5607
5714
|
},
|
|
5608
5715
|
tracingPolicy: engine.options?.tracingPolicy
|
|
5609
5716
|
});
|
|
5610
|
-
await
|
|
5611
|
-
type: "
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5717
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
5718
|
+
type: "watch",
|
|
5719
|
+
runId,
|
|
5720
|
+
data: {
|
|
5721
|
+
type: "workflow-step-start",
|
|
5722
|
+
payload: {
|
|
5723
|
+
id: step.id,
|
|
5724
|
+
...stepInfo,
|
|
5725
|
+
status: "running"
|
|
5726
|
+
}
|
|
5616
5727
|
}
|
|
5617
5728
|
});
|
|
5618
5729
|
const prevPayload = stepResults[step.id];
|
|
@@ -5651,7 +5762,7 @@ async function executeForeach(engine, params) {
|
|
|
5651
5762
|
resume: resumeToUse,
|
|
5652
5763
|
prevOutput: item,
|
|
5653
5764
|
tracingContext: { currentSpan: loopSpan },
|
|
5654
|
-
|
|
5765
|
+
pubsub,
|
|
5655
5766
|
abortController,
|
|
5656
5767
|
requestContext,
|
|
5657
5768
|
skipEmits: true,
|
|
@@ -5671,18 +5782,26 @@ async function executeForeach(engine, params) {
|
|
|
5671
5782
|
if (execResults.status === "suspended") {
|
|
5672
5783
|
foreachIndexObj[i + resultIndex] = execResults;
|
|
5673
5784
|
} else {
|
|
5674
|
-
await
|
|
5675
|
-
type: "
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5785
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
5786
|
+
type: "watch",
|
|
5787
|
+
runId,
|
|
5788
|
+
data: {
|
|
5789
|
+
type: "workflow-step-result",
|
|
5790
|
+
payload: {
|
|
5791
|
+
id: step.id,
|
|
5792
|
+
...execResults
|
|
5793
|
+
}
|
|
5679
5794
|
}
|
|
5680
5795
|
});
|
|
5681
|
-
await
|
|
5682
|
-
type: "
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
|
|
5796
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
5797
|
+
type: "watch",
|
|
5798
|
+
runId,
|
|
5799
|
+
data: {
|
|
5800
|
+
type: "workflow-step-finish",
|
|
5801
|
+
payload: {
|
|
5802
|
+
id: step.id,
|
|
5803
|
+
metadata: {}
|
|
5804
|
+
}
|
|
5686
5805
|
}
|
|
5687
5806
|
});
|
|
5688
5807
|
return result;
|
|
@@ -5701,11 +5820,15 @@ async function executeForeach(engine, params) {
|
|
|
5701
5820
|
if (Object.keys(foreachIndexObj).length > 0) {
|
|
5702
5821
|
const suspendedIndices = Object.keys(foreachIndexObj).map(Number);
|
|
5703
5822
|
const foreachIndex = suspendedIndices[0];
|
|
5704
|
-
await
|
|
5705
|
-
type: "
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5823
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
5824
|
+
type: "watch",
|
|
5825
|
+
runId,
|
|
5826
|
+
data: {
|
|
5827
|
+
type: "workflow-step-suspended",
|
|
5828
|
+
payload: {
|
|
5829
|
+
id: step.id,
|
|
5830
|
+
...foreachIndexObj[foreachIndex]
|
|
5831
|
+
}
|
|
5709
5832
|
}
|
|
5710
5833
|
});
|
|
5711
5834
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
@@ -5727,20 +5850,28 @@ async function executeForeach(engine, params) {
|
|
|
5727
5850
|
};
|
|
5728
5851
|
}
|
|
5729
5852
|
}
|
|
5730
|
-
await
|
|
5731
|
-
type: "
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5853
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
5854
|
+
type: "watch",
|
|
5855
|
+
runId,
|
|
5856
|
+
data: {
|
|
5857
|
+
type: "workflow-step-result",
|
|
5858
|
+
payload: {
|
|
5859
|
+
id: step.id,
|
|
5860
|
+
status: "success",
|
|
5861
|
+
output: results,
|
|
5862
|
+
endedAt: Date.now()
|
|
5863
|
+
}
|
|
5737
5864
|
}
|
|
5738
5865
|
});
|
|
5739
|
-
await
|
|
5740
|
-
type: "
|
|
5741
|
-
|
|
5742
|
-
|
|
5743
|
-
|
|
5866
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
5867
|
+
type: "watch",
|
|
5868
|
+
runId,
|
|
5869
|
+
data: {
|
|
5870
|
+
type: "workflow-step-finish",
|
|
5871
|
+
payload: {
|
|
5872
|
+
id: step.id,
|
|
5873
|
+
metadata: {}
|
|
5874
|
+
}
|
|
5744
5875
|
}
|
|
5745
5876
|
});
|
|
5746
5877
|
loopSpan?.end({
|
|
@@ -5817,7 +5948,7 @@ async function executeEntry(engine, params) {
|
|
|
5817
5948
|
resume,
|
|
5818
5949
|
executionContext,
|
|
5819
5950
|
tracingContext,
|
|
5820
|
-
|
|
5951
|
+
pubsub,
|
|
5821
5952
|
abortController,
|
|
5822
5953
|
requestContext,
|
|
5823
5954
|
outputWriter,
|
|
@@ -5840,7 +5971,7 @@ async function executeEntry(engine, params) {
|
|
|
5840
5971
|
resume,
|
|
5841
5972
|
prevOutput,
|
|
5842
5973
|
tracingContext,
|
|
5843
|
-
|
|
5974
|
+
pubsub,
|
|
5844
5975
|
abortController,
|
|
5845
5976
|
requestContext,
|
|
5846
5977
|
outputWriter,
|
|
@@ -5873,7 +6004,7 @@ async function executeEntry(engine, params) {
|
|
|
5873
6004
|
state: executionContext.state
|
|
5874
6005
|
},
|
|
5875
6006
|
tracingContext,
|
|
5876
|
-
|
|
6007
|
+
pubsub,
|
|
5877
6008
|
abortController,
|
|
5878
6009
|
requestContext,
|
|
5879
6010
|
outputWriter,
|
|
@@ -5943,7 +6074,7 @@ async function executeEntry(engine, params) {
|
|
|
5943
6074
|
resume,
|
|
5944
6075
|
executionContext,
|
|
5945
6076
|
tracingContext,
|
|
5946
|
-
|
|
6077
|
+
pubsub,
|
|
5947
6078
|
abortController,
|
|
5948
6079
|
requestContext,
|
|
5949
6080
|
outputWriter,
|
|
@@ -5962,7 +6093,7 @@ async function executeEntry(engine, params) {
|
|
|
5962
6093
|
resume,
|
|
5963
6094
|
executionContext,
|
|
5964
6095
|
tracingContext,
|
|
5965
|
-
|
|
6096
|
+
pubsub,
|
|
5966
6097
|
abortController,
|
|
5967
6098
|
requestContext,
|
|
5968
6099
|
outputWriter,
|
|
@@ -5981,7 +6112,7 @@ async function executeEntry(engine, params) {
|
|
|
5981
6112
|
resume,
|
|
5982
6113
|
executionContext,
|
|
5983
6114
|
tracingContext,
|
|
5984
|
-
|
|
6115
|
+
pubsub,
|
|
5985
6116
|
abortController,
|
|
5986
6117
|
requestContext,
|
|
5987
6118
|
outputWriter,
|
|
@@ -6001,7 +6132,7 @@ async function executeEntry(engine, params) {
|
|
|
6001
6132
|
resume,
|
|
6002
6133
|
executionContext,
|
|
6003
6134
|
tracingContext,
|
|
6004
|
-
|
|
6135
|
+
pubsub,
|
|
6005
6136
|
abortController,
|
|
6006
6137
|
requestContext,
|
|
6007
6138
|
outputWriter,
|
|
@@ -6012,13 +6143,17 @@ async function executeEntry(engine, params) {
|
|
|
6012
6143
|
const startedAt = Date.now();
|
|
6013
6144
|
const sleepWaitingOperationId = `workflow.${workflowId}.run.${runId}.sleep.${entry.id}.waiting_ev`;
|
|
6014
6145
|
await engine.wrapDurableOperation(sleepWaitingOperationId, async () => {
|
|
6015
|
-
await
|
|
6016
|
-
type: "
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6146
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6147
|
+
type: "watch",
|
|
6148
|
+
runId,
|
|
6149
|
+
data: {
|
|
6150
|
+
type: "workflow-step-waiting",
|
|
6151
|
+
payload: {
|
|
6152
|
+
id: entry.id,
|
|
6153
|
+
payload: prevOutput,
|
|
6154
|
+
startedAt,
|
|
6155
|
+
status: "waiting"
|
|
6156
|
+
}
|
|
6022
6157
|
}
|
|
6023
6158
|
});
|
|
6024
6159
|
});
|
|
@@ -6049,7 +6184,7 @@ async function executeEntry(engine, params) {
|
|
|
6049
6184
|
resume,
|
|
6050
6185
|
executionContext,
|
|
6051
6186
|
tracingContext,
|
|
6052
|
-
|
|
6187
|
+
pubsub,
|
|
6053
6188
|
abortController,
|
|
6054
6189
|
requestContext,
|
|
6055
6190
|
outputWriter
|
|
@@ -6075,20 +6210,28 @@ async function executeEntry(engine, params) {
|
|
|
6075
6210
|
stepResults[entry.id] = { ...stepInfo, status: "success", output: prevOutput };
|
|
6076
6211
|
const sleepResultOperationId = `workflow.${workflowId}.run.${runId}.sleep.${entry.id}.result_ev`;
|
|
6077
6212
|
await engine.wrapDurableOperation(sleepResultOperationId, async () => {
|
|
6078
|
-
await
|
|
6079
|
-
type: "
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6213
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6214
|
+
type: "watch",
|
|
6215
|
+
runId,
|
|
6216
|
+
data: {
|
|
6217
|
+
type: "workflow-step-result",
|
|
6218
|
+
payload: {
|
|
6219
|
+
id: entry.id,
|
|
6220
|
+
endedAt,
|
|
6221
|
+
status: "success",
|
|
6222
|
+
output: prevOutput
|
|
6223
|
+
}
|
|
6085
6224
|
}
|
|
6086
6225
|
});
|
|
6087
|
-
await
|
|
6088
|
-
type: "
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
|
|
6226
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6227
|
+
type: "watch",
|
|
6228
|
+
runId,
|
|
6229
|
+
data: {
|
|
6230
|
+
type: "workflow-step-finish",
|
|
6231
|
+
payload: {
|
|
6232
|
+
id: entry.id,
|
|
6233
|
+
metadata: {}
|
|
6234
|
+
}
|
|
6092
6235
|
}
|
|
6093
6236
|
});
|
|
6094
6237
|
});
|
|
@@ -6096,13 +6239,17 @@ async function executeEntry(engine, params) {
|
|
|
6096
6239
|
const startedAt = Date.now();
|
|
6097
6240
|
const sleepUntilWaitingOperationId = `workflow.${workflowId}.run.${runId}.sleepUntil.${entry.id}.waiting_ev`;
|
|
6098
6241
|
await engine.wrapDurableOperation(sleepUntilWaitingOperationId, async () => {
|
|
6099
|
-
await
|
|
6100
|
-
type: "
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6242
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6243
|
+
type: "watch",
|
|
6244
|
+
runId,
|
|
6245
|
+
data: {
|
|
6246
|
+
type: "workflow-step-waiting",
|
|
6247
|
+
payload: {
|
|
6248
|
+
id: entry.id,
|
|
6249
|
+
payload: prevOutput,
|
|
6250
|
+
startedAt,
|
|
6251
|
+
status: "waiting"
|
|
6252
|
+
}
|
|
6106
6253
|
}
|
|
6107
6254
|
});
|
|
6108
6255
|
});
|
|
@@ -6133,7 +6280,7 @@ async function executeEntry(engine, params) {
|
|
|
6133
6280
|
resume,
|
|
6134
6281
|
executionContext,
|
|
6135
6282
|
tracingContext,
|
|
6136
|
-
|
|
6283
|
+
pubsub,
|
|
6137
6284
|
abortController,
|
|
6138
6285
|
requestContext,
|
|
6139
6286
|
outputWriter
|
|
@@ -6159,20 +6306,28 @@ async function executeEntry(engine, params) {
|
|
|
6159
6306
|
stepResults[entry.id] = { ...stepInfo, status: "success", output: prevOutput };
|
|
6160
6307
|
const sleepUntilResultOperationId = `workflow.${workflowId}.run.${runId}.sleepUntil.${entry.id}.result_ev`;
|
|
6161
6308
|
await engine.wrapDurableOperation(sleepUntilResultOperationId, async () => {
|
|
6162
|
-
await
|
|
6163
|
-
type: "
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6309
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6310
|
+
type: "watch",
|
|
6311
|
+
runId,
|
|
6312
|
+
data: {
|
|
6313
|
+
type: "workflow-step-result",
|
|
6314
|
+
payload: {
|
|
6315
|
+
id: entry.id,
|
|
6316
|
+
endedAt,
|
|
6317
|
+
status: "success",
|
|
6318
|
+
output: prevOutput
|
|
6319
|
+
}
|
|
6169
6320
|
}
|
|
6170
6321
|
});
|
|
6171
|
-
await
|
|
6172
|
-
type: "
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6322
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6323
|
+
type: "watch",
|
|
6324
|
+
runId,
|
|
6325
|
+
data: {
|
|
6326
|
+
type: "workflow-step-finish",
|
|
6327
|
+
payload: {
|
|
6328
|
+
id: entry.id,
|
|
6329
|
+
metadata: {}
|
|
6330
|
+
}
|
|
6176
6331
|
}
|
|
6177
6332
|
});
|
|
6178
6333
|
});
|
|
@@ -6194,9 +6349,10 @@ async function executeEntry(engine, params) {
|
|
|
6194
6349
|
requestContext
|
|
6195
6350
|
});
|
|
6196
6351
|
if (execResults.status === "canceled") {
|
|
6197
|
-
await
|
|
6198
|
-
type: "
|
|
6199
|
-
|
|
6352
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6353
|
+
type: "watch",
|
|
6354
|
+
runId,
|
|
6355
|
+
data: { type: "workflow-canceled", payload: {} }
|
|
6200
6356
|
});
|
|
6201
6357
|
}
|
|
6202
6358
|
return {
|
|
@@ -6213,7 +6369,7 @@ async function executeSleep(engine, params) {
|
|
|
6213
6369
|
entry,
|
|
6214
6370
|
prevOutput,
|
|
6215
6371
|
stepResults,
|
|
6216
|
-
|
|
6372
|
+
pubsub,
|
|
6217
6373
|
abortController,
|
|
6218
6374
|
requestContext,
|
|
6219
6375
|
executionContext,
|
|
@@ -6257,8 +6413,8 @@ async function executeSleep(engine, params) {
|
|
|
6257
6413
|
abort: () => {
|
|
6258
6414
|
abortController?.abort();
|
|
6259
6415
|
},
|
|
6260
|
-
[
|
|
6261
|
-
[
|
|
6416
|
+
[chunkL3NKIMF5_cjs.PUBSUB_SYMBOL]: pubsub,
|
|
6417
|
+
[chunkL3NKIMF5_cjs.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
6262
6418
|
engine: engine.getEngineContext(),
|
|
6263
6419
|
abortSignal: abortController?.signal,
|
|
6264
6420
|
writer: new chunkKJBMTK5B_cjs.ToolStream(
|
|
@@ -6293,7 +6449,7 @@ async function executeSleepUntil(engine, params) {
|
|
|
6293
6449
|
entry,
|
|
6294
6450
|
prevOutput,
|
|
6295
6451
|
stepResults,
|
|
6296
|
-
|
|
6452
|
+
pubsub,
|
|
6297
6453
|
abortController,
|
|
6298
6454
|
requestContext,
|
|
6299
6455
|
executionContext,
|
|
@@ -6338,8 +6494,8 @@ async function executeSleepUntil(engine, params) {
|
|
|
6338
6494
|
abort: () => {
|
|
6339
6495
|
abortController?.abort();
|
|
6340
6496
|
},
|
|
6341
|
-
[
|
|
6342
|
-
[
|
|
6497
|
+
[chunkL3NKIMF5_cjs.PUBSUB_SYMBOL]: pubsub,
|
|
6498
|
+
[chunkL3NKIMF5_cjs.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
6343
6499
|
engine: engine.getEngineContext(),
|
|
6344
6500
|
abortSignal: abortController?.signal,
|
|
6345
6501
|
writer: new chunkKJBMTK5B_cjs.ToolStream(
|
|
@@ -6385,7 +6541,7 @@ async function executeStep(engine, params) {
|
|
|
6385
6541
|
resume,
|
|
6386
6542
|
timeTravel,
|
|
6387
6543
|
prevOutput,
|
|
6388
|
-
|
|
6544
|
+
pubsub,
|
|
6389
6545
|
abortController,
|
|
6390
6546
|
requestContext,
|
|
6391
6547
|
skipEmits = false,
|
|
@@ -6445,7 +6601,7 @@ async function executeStep(engine, params) {
|
|
|
6445
6601
|
await engine.onStepExecutionStart({
|
|
6446
6602
|
step,
|
|
6447
6603
|
inputData,
|
|
6448
|
-
|
|
6604
|
+
pubsub,
|
|
6449
6605
|
executionContext,
|
|
6450
6606
|
stepCallId,
|
|
6451
6607
|
stepInfo,
|
|
@@ -6474,7 +6630,7 @@ async function executeStep(engine, params) {
|
|
|
6474
6630
|
timeTravel,
|
|
6475
6631
|
prevOutput,
|
|
6476
6632
|
inputData,
|
|
6477
|
-
|
|
6633
|
+
pubsub,
|
|
6478
6634
|
startedAt: startTime ?? Date.now(),
|
|
6479
6635
|
abortController,
|
|
6480
6636
|
requestContext,
|
|
@@ -6596,8 +6752,8 @@ async function executeStep(engine, params) {
|
|
|
6596
6752
|
nestedStepResults: timeTravel?.nestedStepResults,
|
|
6597
6753
|
resumeData: timeTravel?.resumeData
|
|
6598
6754
|
} : void 0,
|
|
6599
|
-
[
|
|
6600
|
-
[
|
|
6755
|
+
[chunkL3NKIMF5_cjs.PUBSUB_SYMBOL]: pubsub,
|
|
6756
|
+
[chunkL3NKIMF5_cjs.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
6601
6757
|
engine: engine.getEngineContext(),
|
|
6602
6758
|
abortSignal: abortController?.signal,
|
|
6603
6759
|
writer: new chunkKJBMTK5B_cjs.ToolStream(
|
|
@@ -6668,7 +6824,8 @@ async function executeStep(engine, params) {
|
|
|
6668
6824
|
stepId: step.id,
|
|
6669
6825
|
stepCallId,
|
|
6670
6826
|
execResults: { ...stepInfo, ...execResults },
|
|
6671
|
-
|
|
6827
|
+
pubsub,
|
|
6828
|
+
runId
|
|
6672
6829
|
});
|
|
6673
6830
|
});
|
|
6674
6831
|
}
|
|
@@ -6699,9 +6856,9 @@ async function runScorersForStep(params) {
|
|
|
6699
6856
|
scorersToUse = await scorersToUse({
|
|
6700
6857
|
requestContext
|
|
6701
6858
|
});
|
|
6702
|
-
} catch (
|
|
6703
|
-
|
|
6704
|
-
|
|
6859
|
+
} catch (e) {
|
|
6860
|
+
const errorInstance = chunkHWMMIRIF_cjs.getErrorFromUnknown(e, { serializeStack: false });
|
|
6861
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError(
|
|
6705
6862
|
{
|
|
6706
6863
|
id: "WORKFLOW_FAILED_TO_FETCH_SCORERS",
|
|
6707
6864
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
@@ -6712,8 +6869,10 @@ async function runScorersForStep(params) {
|
|
|
6712
6869
|
stepId
|
|
6713
6870
|
}
|
|
6714
6871
|
},
|
|
6715
|
-
|
|
6872
|
+
errorInstance
|
|
6716
6873
|
);
|
|
6874
|
+
engine.getLogger()?.trackException(mastraError);
|
|
6875
|
+
engine.getLogger()?.error("Error fetching scorers: " + errorInstance?.stack);
|
|
6717
6876
|
}
|
|
6718
6877
|
}
|
|
6719
6878
|
if (!disableScorers && scorersToUse && Object.keys(scorersToUse || {}).length > 0) {
|
|
@@ -6738,42 +6897,30 @@ async function runScorersForStep(params) {
|
|
|
6738
6897
|
}
|
|
6739
6898
|
}
|
|
6740
6899
|
async function emitStepResultEvents(params) {
|
|
6741
|
-
const { stepId, stepCallId, execResults,
|
|
6900
|
+
const { stepId, stepCallId, execResults, pubsub, runId } = params;
|
|
6742
6901
|
const payloadBase = stepCallId ? { id: stepId, stepCallId } : { id: stepId };
|
|
6743
6902
|
if (execResults.status === "suspended") {
|
|
6744
|
-
await
|
|
6745
|
-
type: "
|
|
6746
|
-
|
|
6903
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6904
|
+
type: "watch",
|
|
6905
|
+
runId,
|
|
6906
|
+
data: { type: "workflow-step-suspended", payload: { ...payloadBase, ...execResults } }
|
|
6747
6907
|
});
|
|
6748
6908
|
} else {
|
|
6749
|
-
await
|
|
6750
|
-
type: "
|
|
6751
|
-
|
|
6909
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6910
|
+
type: "watch",
|
|
6911
|
+
runId,
|
|
6912
|
+
data: { type: "workflow-step-result", payload: { ...payloadBase, ...execResults } }
|
|
6752
6913
|
});
|
|
6753
|
-
await
|
|
6754
|
-
type: "
|
|
6755
|
-
|
|
6914
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
6915
|
+
type: "watch",
|
|
6916
|
+
runId,
|
|
6917
|
+
data: { type: "workflow-step-finish", payload: { ...payloadBase, metadata: {} } }
|
|
6756
6918
|
});
|
|
6757
6919
|
}
|
|
6758
6920
|
}
|
|
6759
6921
|
|
|
6760
6922
|
// src/workflows/default.ts
|
|
6761
6923
|
var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
6762
|
-
/**
|
|
6763
|
-
* Preprocesses an error caught during workflow execution.
|
|
6764
|
-
*
|
|
6765
|
-
* - Wraps a non-MastraError exception
|
|
6766
|
-
* - Logs error details
|
|
6767
|
-
*/
|
|
6768
|
-
preprocessExecutionError(e, errorDefinition, logPrefix) {
|
|
6769
|
-
const error = e instanceof chunkTWH4PTDG_cjs.MastraError ? e : new chunkTWH4PTDG_cjs.MastraError(errorDefinition, e);
|
|
6770
|
-
if (!(e instanceof chunkTWH4PTDG_cjs.MastraError) && e instanceof Error && e.stack) {
|
|
6771
|
-
error.stack = e.stack;
|
|
6772
|
-
}
|
|
6773
|
-
this.logger?.trackException(error);
|
|
6774
|
-
this.logger?.error(logPrefix + error?.stack);
|
|
6775
|
-
return error;
|
|
6776
|
-
}
|
|
6777
6924
|
/**
|
|
6778
6925
|
* The retryCounts map is used to keep track of the retry count for each step.
|
|
6779
6926
|
* The step id is used as the key and the retry count is the value.
|
|
@@ -6880,12 +7027,16 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
6880
7027
|
return this.wrapDurableOperation(params.operationId, async () => {
|
|
6881
7028
|
const startedAt = Date.now();
|
|
6882
7029
|
if (!params.skipEmits) {
|
|
6883
|
-
await params.
|
|
6884
|
-
type: "
|
|
6885
|
-
|
|
6886
|
-
|
|
6887
|
-
|
|
6888
|
-
|
|
7030
|
+
await params.pubsub.publish(`workflow.events.v2.${params.executionContext.runId}`, {
|
|
7031
|
+
type: "watch",
|
|
7032
|
+
runId: params.executionContext.runId,
|
|
7033
|
+
data: {
|
|
7034
|
+
type: "workflow-step-start",
|
|
7035
|
+
payload: {
|
|
7036
|
+
id: params.step.id,
|
|
7037
|
+
stepCallId: params.stepCallId,
|
|
7038
|
+
...params.stepInfo
|
|
7039
|
+
}
|
|
6889
7040
|
}
|
|
6890
7041
|
});
|
|
6891
7042
|
}
|
|
@@ -6925,29 +7076,30 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
6925
7076
|
return { ok: true, result };
|
|
6926
7077
|
} catch (e) {
|
|
6927
7078
|
if (i === params.retries) {
|
|
6928
|
-
const
|
|
6929
|
-
|
|
7079
|
+
const errorInstance = chunkHWMMIRIF_cjs.getErrorFromUnknown(e, {
|
|
7080
|
+
serializeStack: false,
|
|
7081
|
+
fallbackMessage: "Unknown step execution error"
|
|
7082
|
+
});
|
|
7083
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError(
|
|
6930
7084
|
{
|
|
6931
7085
|
id: "WORKFLOW_STEP_INVOKE_FAILED",
|
|
6932
7086
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
6933
7087
|
category: "USER" /* USER */,
|
|
6934
7088
|
details: { workflowId: params.workflowId, runId: params.runId, stepId }
|
|
6935
7089
|
},
|
|
6936
|
-
|
|
7090
|
+
errorInstance
|
|
6937
7091
|
);
|
|
7092
|
+
this.logger?.trackException(mastraError);
|
|
7093
|
+
this.logger?.error(`Error executing step ${stepId}: ` + errorInstance?.stack);
|
|
6938
7094
|
params.stepSpan?.error({
|
|
6939
|
-
error:
|
|
7095
|
+
error: mastraError,
|
|
6940
7096
|
attributes: { status: "failed" }
|
|
6941
7097
|
});
|
|
6942
|
-
const errorInstance = chunkTWH4PTDG_cjs.getErrorFromUnknown(processedError, {
|
|
6943
|
-
includeStack: false,
|
|
6944
|
-
fallbackMessage: "Unknown step execution error"
|
|
6945
|
-
});
|
|
6946
7098
|
return {
|
|
6947
7099
|
ok: false,
|
|
6948
7100
|
error: {
|
|
6949
7101
|
status: "failed",
|
|
6950
|
-
error:
|
|
7102
|
+
error: errorInstance,
|
|
6951
7103
|
endedAt: Date.now(),
|
|
6952
7104
|
// Preserve TripWire data as plain object for proper serialization
|
|
6953
7105
|
tripwire: e instanceof TripWire ? {
|
|
@@ -6961,7 +7113,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
6961
7113
|
}
|
|
6962
7114
|
}
|
|
6963
7115
|
}
|
|
6964
|
-
return { ok: false, error: { status: "failed", error: "Unknown error", endedAt: Date.now() } };
|
|
7116
|
+
return { ok: false, error: { status: "failed", error: new Error("Unknown error"), endedAt: Date.now() } };
|
|
6965
7117
|
}
|
|
6966
7118
|
/**
|
|
6967
7119
|
* Format an error for the workflow result.
|
|
@@ -6970,13 +7122,13 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
6970
7122
|
formatResultError(error, lastOutput) {
|
|
6971
7123
|
const outputError = lastOutput?.error;
|
|
6972
7124
|
const errorSource = error || outputError;
|
|
6973
|
-
const errorInstance =
|
|
6974
|
-
|
|
7125
|
+
const errorInstance = chunkHWMMIRIF_cjs.getErrorFromUnknown(errorSource, {
|
|
7126
|
+
serializeStack: false,
|
|
6975
7127
|
fallbackMessage: "Unknown workflow error"
|
|
6976
7128
|
});
|
|
6977
|
-
return
|
|
7129
|
+
return errorInstance.toJSON();
|
|
6978
7130
|
}
|
|
6979
|
-
async fmtReturnValue(
|
|
7131
|
+
async fmtReturnValue(_pubsub, stepResults, lastOutput, error) {
|
|
6980
7132
|
const base = {
|
|
6981
7133
|
status: lastOutput.status,
|
|
6982
7134
|
steps: stepResults,
|
|
@@ -7001,14 +7153,18 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7001
7153
|
base.error = this.formatResultError(error, lastOutput);
|
|
7002
7154
|
}
|
|
7003
7155
|
} else if (lastOutput.status === "suspended") {
|
|
7156
|
+
const suspendPayload = {};
|
|
7004
7157
|
const suspendedStepIds = Object.entries(stepResults).flatMap(([stepId, stepResult]) => {
|
|
7005
7158
|
if (stepResult?.status === "suspended") {
|
|
7006
|
-
const
|
|
7159
|
+
const { __workflow_meta, ...rest } = stepResult?.suspendPayload ?? {};
|
|
7160
|
+
suspendPayload[stepId] = rest;
|
|
7161
|
+
const nestedPath = __workflow_meta?.path;
|
|
7007
7162
|
return nestedPath ? [[stepId, ...nestedPath]] : [[stepId]];
|
|
7008
7163
|
}
|
|
7009
7164
|
return [];
|
|
7010
7165
|
});
|
|
7011
7166
|
base.suspended = suspendedStepIds;
|
|
7167
|
+
base.suspendPayload = suspendPayload;
|
|
7012
7168
|
}
|
|
7013
7169
|
return base;
|
|
7014
7170
|
}
|
|
@@ -7085,7 +7241,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7085
7241
|
const steps = graph.steps;
|
|
7086
7242
|
this.retryCounts.clear();
|
|
7087
7243
|
if (steps.length === 0) {
|
|
7088
|
-
const empty_graph_error = new
|
|
7244
|
+
const empty_graph_error = new chunkHWMMIRIF_cjs.MastraError({
|
|
7089
7245
|
id: "WORKFLOW_EXECUTE_EMPTY_GRAPH",
|
|
7090
7246
|
text: "Workflow must have at least one step",
|
|
7091
7247
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
@@ -7140,7 +7296,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7140
7296
|
currentSpan: workflowSpan
|
|
7141
7297
|
},
|
|
7142
7298
|
abortController: params.abortController,
|
|
7143
|
-
|
|
7299
|
+
pubsub: params.pubsub,
|
|
7144
7300
|
requestContext: currentRequestContext,
|
|
7145
7301
|
outputWriter: params.outputWriter,
|
|
7146
7302
|
disableScorers
|
|
@@ -7154,7 +7310,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7154
7310
|
if (lastOutput.result.status === "bailed") {
|
|
7155
7311
|
lastOutput.result.status = "success";
|
|
7156
7312
|
}
|
|
7157
|
-
const result2 = await this.fmtReturnValue(params.
|
|
7313
|
+
const result2 = await this.fmtReturnValue(params.pubsub, stepResults, lastOutput.result);
|
|
7158
7314
|
await this.persistStepUpdate({
|
|
7159
7315
|
workflowId,
|
|
7160
7316
|
runId,
|
|
@@ -7182,6 +7338,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7182
7338
|
}
|
|
7183
7339
|
});
|
|
7184
7340
|
}
|
|
7341
|
+
await this.invokeLifecycleCallbacks(result2);
|
|
7185
7342
|
return {
|
|
7186
7343
|
...result2,
|
|
7187
7344
|
...lastOutput.result.status === "suspended" && params.outputOptions?.includeResumeLabels ? { resumeLabels: lastOutput.mutableContext.resumeLabels } : {},
|
|
@@ -7189,7 +7346,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7189
7346
|
};
|
|
7190
7347
|
}
|
|
7191
7348
|
}
|
|
7192
|
-
const result = await this.fmtReturnValue(params.
|
|
7349
|
+
const result = await this.fmtReturnValue(params.pubsub, stepResults, lastOutput.result);
|
|
7193
7350
|
await this.persistStepUpdate({
|
|
7194
7351
|
workflowId,
|
|
7195
7352
|
runId,
|
|
@@ -7208,6 +7365,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7208
7365
|
status: result.status
|
|
7209
7366
|
}
|
|
7210
7367
|
});
|
|
7368
|
+
await this.invokeLifecycleCallbacks(result);
|
|
7211
7369
|
if (params.outputOptions?.includeState) {
|
|
7212
7370
|
return { ...result, state: lastState };
|
|
7213
7371
|
}
|
|
@@ -7269,13 +7427,13 @@ function mapVariable(config) {
|
|
|
7269
7427
|
}
|
|
7270
7428
|
function createStep(params, agentOptions) {
|
|
7271
7429
|
if (params instanceof Agent) {
|
|
7272
|
-
const outputSchema = agentOptions?.structuredOutput?.schema ??
|
|
7430
|
+
const outputSchema = agentOptions?.structuredOutput?.schema ?? z8.z.object({ text: z8.z.string() });
|
|
7273
7431
|
return {
|
|
7274
7432
|
id: params.id,
|
|
7275
7433
|
description: params.getDescription(),
|
|
7276
7434
|
// @ts-ignore
|
|
7277
|
-
inputSchema:
|
|
7278
|
-
prompt:
|
|
7435
|
+
inputSchema: z8.z.object({
|
|
7436
|
+
prompt: z8.z.string()
|
|
7279
7437
|
// resourceId: z.string().optional(),
|
|
7280
7438
|
// threadId: z.string().optional(),
|
|
7281
7439
|
}),
|
|
@@ -7283,8 +7441,9 @@ function createStep(params, agentOptions) {
|
|
|
7283
7441
|
outputSchema,
|
|
7284
7442
|
execute: async ({
|
|
7285
7443
|
inputData,
|
|
7286
|
-
|
|
7287
|
-
[
|
|
7444
|
+
runId,
|
|
7445
|
+
[chunkL3NKIMF5_cjs.PUBSUB_SYMBOL]: pubsub,
|
|
7446
|
+
[chunkL3NKIMF5_cjs.STREAM_FORMAT_SYMBOL]: streamFormat,
|
|
7288
7447
|
requestContext,
|
|
7289
7448
|
tracingContext,
|
|
7290
7449
|
abortSignal,
|
|
@@ -7339,9 +7498,10 @@ function createStep(params, agentOptions) {
|
|
|
7339
7498
|
}
|
|
7340
7499
|
let tripwireChunk = null;
|
|
7341
7500
|
if (streamFormat === "legacy") {
|
|
7342
|
-
await
|
|
7343
|
-
type: "
|
|
7344
|
-
|
|
7501
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
7502
|
+
type: "watch",
|
|
7503
|
+
runId,
|
|
7504
|
+
data: { type: "tool-call-streaming-start", ...toolData ?? {} }
|
|
7345
7505
|
});
|
|
7346
7506
|
for await (const chunk of stream) {
|
|
7347
7507
|
if (chunk.type === "tripwire") {
|
|
@@ -7349,16 +7509,17 @@ function createStep(params, agentOptions) {
|
|
|
7349
7509
|
break;
|
|
7350
7510
|
}
|
|
7351
7511
|
if (chunk.type === "text-delta") {
|
|
7352
|
-
await
|
|
7353
|
-
type: "
|
|
7354
|
-
|
|
7355
|
-
argsTextDelta: chunk.textDelta
|
|
7512
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
7513
|
+
type: "watch",
|
|
7514
|
+
runId,
|
|
7515
|
+
data: { type: "tool-call-delta", ...toolData ?? {}, argsTextDelta: chunk.textDelta }
|
|
7356
7516
|
});
|
|
7357
7517
|
}
|
|
7358
7518
|
}
|
|
7359
|
-
await
|
|
7360
|
-
type: "
|
|
7361
|
-
|
|
7519
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
7520
|
+
type: "watch",
|
|
7521
|
+
runId,
|
|
7522
|
+
data: { type: "tool-call-streaming-finish", ...toolData ?? {} }
|
|
7362
7523
|
});
|
|
7363
7524
|
} else {
|
|
7364
7525
|
for await (const chunk of stream) {
|
|
@@ -7392,7 +7553,7 @@ function createStep(params, agentOptions) {
|
|
|
7392
7553
|
component: params.component
|
|
7393
7554
|
};
|
|
7394
7555
|
}
|
|
7395
|
-
if (params instanceof
|
|
7556
|
+
if (params instanceof chunkZ55SJVEC_cjs.Tool) {
|
|
7396
7557
|
if (!params.inputSchema || !params.outputSchema) {
|
|
7397
7558
|
throw new Error("Tool must have input and output schemas defined");
|
|
7398
7559
|
}
|
|
@@ -7486,7 +7647,7 @@ function createStep(params, agentOptions) {
|
|
|
7486
7647
|
phase,
|
|
7487
7648
|
// Auto-create MessageList from messages if not provided
|
|
7488
7649
|
// This enables running processor workflows from the UI where messageList can't be serialized
|
|
7489
|
-
messageList: messageList ?? (Array.isArray(messages) ? new
|
|
7650
|
+
messageList: messageList ?? (Array.isArray(messages) ? new chunkX6IBA7FP_cjs.MessageList().add(messages, "input").addSystem(systemMessages ?? []) : void 0),
|
|
7490
7651
|
stepNumber,
|
|
7491
7652
|
systemMessages,
|
|
7492
7653
|
streamParts,
|
|
@@ -7509,7 +7670,7 @@ function createStep(params, agentOptions) {
|
|
|
7509
7670
|
case "input": {
|
|
7510
7671
|
if (processor.processInput) {
|
|
7511
7672
|
if (!passThrough.messageList) {
|
|
7512
|
-
throw new
|
|
7673
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
7513
7674
|
category: "USER" /* USER */,
|
|
7514
7675
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
7515
7676
|
id: "PROCESSOR_MISSING_MESSAGE_LIST",
|
|
@@ -7539,9 +7700,9 @@ function createStep(params, agentOptions) {
|
|
|
7539
7700
|
}
|
|
7540
7701
|
}
|
|
7541
7702
|
};
|
|
7542
|
-
if (result instanceof
|
|
7703
|
+
if (result instanceof chunkX6IBA7FP_cjs.MessageList) {
|
|
7543
7704
|
if (result !== passThrough.messageList) {
|
|
7544
|
-
throw new
|
|
7705
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
7545
7706
|
category: "USER" /* USER */,
|
|
7546
7707
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
7547
7708
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -7573,7 +7734,7 @@ function createStep(params, agentOptions) {
|
|
|
7573
7734
|
case "inputStep": {
|
|
7574
7735
|
if (processor.processInputStep) {
|
|
7575
7736
|
if (!passThrough.messageList) {
|
|
7576
|
-
throw new
|
|
7737
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
7577
7738
|
category: "USER" /* USER */,
|
|
7578
7739
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
7579
7740
|
id: "PROCESSOR_MISSING_MESSAGE_LIST",
|
|
@@ -7635,7 +7796,7 @@ function createStep(params, agentOptions) {
|
|
|
7635
7796
|
case "outputResult": {
|
|
7636
7797
|
if (processor.processOutputResult) {
|
|
7637
7798
|
if (!passThrough.messageList) {
|
|
7638
|
-
throw new
|
|
7799
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
7639
7800
|
category: "USER" /* USER */,
|
|
7640
7801
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
7641
7802
|
id: "PROCESSOR_MISSING_MESSAGE_LIST",
|
|
@@ -7664,9 +7825,9 @@ function createStep(params, agentOptions) {
|
|
|
7664
7825
|
}
|
|
7665
7826
|
}
|
|
7666
7827
|
};
|
|
7667
|
-
if (result instanceof
|
|
7828
|
+
if (result instanceof chunkX6IBA7FP_cjs.MessageList) {
|
|
7668
7829
|
if (result !== passThrough.messageList) {
|
|
7669
|
-
throw new
|
|
7830
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
7670
7831
|
category: "USER" /* USER */,
|
|
7671
7832
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
7672
7833
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -7698,7 +7859,7 @@ function createStep(params, agentOptions) {
|
|
|
7698
7859
|
case "outputStep": {
|
|
7699
7860
|
if (processor.processOutputStep) {
|
|
7700
7861
|
if (!passThrough.messageList) {
|
|
7701
|
-
throw new
|
|
7862
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
7702
7863
|
category: "USER" /* USER */,
|
|
7703
7864
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
7704
7865
|
id: "PROCESSOR_MISSING_MESSAGE_LIST",
|
|
@@ -7732,9 +7893,9 @@ function createStep(params, agentOptions) {
|
|
|
7732
7893
|
}
|
|
7733
7894
|
}
|
|
7734
7895
|
};
|
|
7735
|
-
if (result instanceof
|
|
7896
|
+
if (result instanceof chunkX6IBA7FP_cjs.MessageList) {
|
|
7736
7897
|
if (result !== passThrough.messageList) {
|
|
7737
|
-
throw new
|
|
7898
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
7738
7899
|
category: "USER" /* USER */,
|
|
7739
7900
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
7740
7901
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -7799,7 +7960,7 @@ function cloneStep(step, opts) {
|
|
|
7799
7960
|
};
|
|
7800
7961
|
}
|
|
7801
7962
|
function isProcessor(obj) {
|
|
7802
|
-
return obj !== null && typeof obj === "object" && "id" in obj && typeof obj.id === "string" && !(obj instanceof Agent) && !(obj instanceof
|
|
7963
|
+
return obj !== null && typeof obj === "object" && "id" in obj && typeof obj.id === "string" && !(obj instanceof Agent) && !(obj instanceof chunkZ55SJVEC_cjs.Tool) && (typeof obj.processInput === "function" || typeof obj.processInputStep === "function" || typeof obj.processOutputStream === "function" || typeof obj.processOutputResult === "function" || typeof obj.processOutputStep === "function");
|
|
7803
7964
|
}
|
|
7804
7965
|
function createWorkflow(params) {
|
|
7805
7966
|
return new Workflow(params);
|
|
@@ -7868,7 +8029,9 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
7868
8029
|
this.#options = {
|
|
7869
8030
|
validateInputs: options.validateInputs ?? true,
|
|
7870
8031
|
shouldPersistSnapshot: options.shouldPersistSnapshot ?? (() => true),
|
|
7871
|
-
tracingPolicy: options.tracingPolicy
|
|
8032
|
+
tracingPolicy: options.tracingPolicy,
|
|
8033
|
+
onFinish: options.onFinish,
|
|
8034
|
+
onError: options.onError
|
|
7872
8035
|
};
|
|
7873
8036
|
if (!executionEngine) {
|
|
7874
8037
|
this.executionEngine = new DefaultExecutionEngine({
|
|
@@ -7935,8 +8098,8 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
7935
8098
|
this.serializedStepFlow.push(serializedOpts);
|
|
7936
8099
|
this.steps[id] = createStep({
|
|
7937
8100
|
id,
|
|
7938
|
-
inputSchema:
|
|
7939
|
-
outputSchema:
|
|
8101
|
+
inputSchema: z8.z.object({}),
|
|
8102
|
+
outputSchema: z8.z.object({}),
|
|
7940
8103
|
execute: async () => {
|
|
7941
8104
|
return {};
|
|
7942
8105
|
}
|
|
@@ -7956,8 +8119,8 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
7956
8119
|
this.serializedStepFlow.push(serializedOpts);
|
|
7957
8120
|
this.steps[id] = createStep({
|
|
7958
8121
|
id,
|
|
7959
|
-
inputSchema:
|
|
7960
|
-
outputSchema:
|
|
8122
|
+
inputSchema: z8.z.object({}),
|
|
8123
|
+
outputSchema: z8.z.object({}),
|
|
7961
8124
|
execute: async () => {
|
|
7962
8125
|
return {};
|
|
7963
8126
|
}
|
|
@@ -7968,7 +8131,7 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
7968
8131
|
* @deprecated waitForEvent has been removed. Please use suspend/resume instead.
|
|
7969
8132
|
*/
|
|
7970
8133
|
waitForEvent(_event, _step, _opts) {
|
|
7971
|
-
throw new
|
|
8134
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
7972
8135
|
id: "WORKFLOW_WAIT_FOR_EVENT_REMOVED",
|
|
7973
8136
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
7974
8137
|
category: "USER" /* USER */,
|
|
@@ -7979,8 +8142,8 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
7979
8142
|
if (typeof mappingConfig === "function") {
|
|
7980
8143
|
const mappingStep2 = createStep({
|
|
7981
8144
|
id: stepOptions?.id || `mapping_${this.#mastra?.generateId() || crypto2.randomUUID()}`,
|
|
7982
|
-
inputSchema:
|
|
7983
|
-
outputSchema:
|
|
8145
|
+
inputSchema: z8.z.object({}),
|
|
8146
|
+
outputSchema: z8.z.object({}),
|
|
7984
8147
|
execute: mappingConfig
|
|
7985
8148
|
});
|
|
7986
8149
|
this.stepFlow.push({ type: "step", step: mappingStep2 });
|
|
@@ -7988,7 +8151,7 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
7988
8151
|
type: "step",
|
|
7989
8152
|
step: {
|
|
7990
8153
|
id: mappingStep2.id,
|
|
7991
|
-
mapConfig: mappingConfig.toString()
|
|
8154
|
+
mapConfig: mappingConfig.toString()?.length > 1e3 ? mappingConfig.toString().slice(0, 1e3) + "...\n}" : mappingConfig.toString()
|
|
7992
8155
|
}
|
|
7993
8156
|
});
|
|
7994
8157
|
return this;
|
|
@@ -8017,8 +8180,8 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8017
8180
|
);
|
|
8018
8181
|
const mappingStep = createStep({
|
|
8019
8182
|
id: stepOptions?.id || `mapping_${this.#mastra?.generateId() || crypto2.randomUUID()}`,
|
|
8020
|
-
inputSchema:
|
|
8021
|
-
outputSchema:
|
|
8183
|
+
inputSchema: z8.z.any(),
|
|
8184
|
+
outputSchema: z8.z.any(),
|
|
8022
8185
|
execute: async (ctx) => {
|
|
8023
8186
|
const { getStepResult: getStepResult2, getInitData, requestContext } = ctx;
|
|
8024
8187
|
const result = {};
|
|
@@ -8060,7 +8223,7 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8060
8223
|
type: "step",
|
|
8061
8224
|
step: {
|
|
8062
8225
|
id: mappingStep.id,
|
|
8063
|
-
mapConfig: JSON.stringify(newMappingConfig, null, 2)
|
|
8226
|
+
mapConfig: JSON.stringify(newMappingConfig, null, 2)?.length > 1e3 ? JSON.stringify(newMappingConfig, null, 2).slice(0, 1e3) + "...\n}" : JSON.stringify(newMappingConfig, null, 2)
|
|
8064
8227
|
}
|
|
8065
8228
|
});
|
|
8066
8229
|
return this;
|
|
@@ -8309,7 +8472,7 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8309
8472
|
restart,
|
|
8310
8473
|
resume,
|
|
8311
8474
|
timeTravel,
|
|
8312
|
-
[
|
|
8475
|
+
[chunkL3NKIMF5_cjs.PUBSUB_SYMBOL]: pubsub,
|
|
8313
8476
|
mastra,
|
|
8314
8477
|
requestContext,
|
|
8315
8478
|
abort,
|
|
@@ -8344,7 +8507,11 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8344
8507
|
await run.cancel();
|
|
8345
8508
|
});
|
|
8346
8509
|
const unwatch = run.watch((event) => {
|
|
8347
|
-
|
|
8510
|
+
void pubsub.publish("nested-watch", {
|
|
8511
|
+
type: "nested-watch",
|
|
8512
|
+
runId: run.runId,
|
|
8513
|
+
data: { event, workflowId: this.id }
|
|
8514
|
+
});
|
|
8348
8515
|
});
|
|
8349
8516
|
if (retryCount && retryCount > 0 && isResume && requestContext) {
|
|
8350
8517
|
requestContext.set("__mastraWorflowInputData", inputData);
|
|
@@ -8541,7 +8708,7 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8541
8708
|
};
|
|
8542
8709
|
var Run = class {
|
|
8543
8710
|
#abortController;
|
|
8544
|
-
|
|
8711
|
+
pubsub;
|
|
8545
8712
|
/**
|
|
8546
8713
|
* Unique identifier for this workflow
|
|
8547
8714
|
*/
|
|
@@ -8611,7 +8778,7 @@ var Run = class {
|
|
|
8611
8778
|
this.executionEngine = params.executionEngine;
|
|
8612
8779
|
this.executionGraph = params.executionGraph;
|
|
8613
8780
|
this.#mastra = params.mastra;
|
|
8614
|
-
this.
|
|
8781
|
+
this.pubsub = new EventEmitterPubSub();
|
|
8615
8782
|
this.retryConfig = params.retryConfig;
|
|
8616
8783
|
this.cleanup = params.cleanup;
|
|
8617
8784
|
this.disableScorers = params.disableScorers;
|
|
@@ -8630,10 +8797,22 @@ var Run = class {
|
|
|
8630
8797
|
return this.#abortController;
|
|
8631
8798
|
}
|
|
8632
8799
|
/**
|
|
8633
|
-
* Cancels the workflow execution
|
|
8800
|
+
* Cancels the workflow execution.
|
|
8801
|
+
* This aborts any running execution and updates the workflow status to 'canceled' in storage.
|
|
8634
8802
|
*/
|
|
8635
8803
|
async cancel() {
|
|
8636
|
-
this.abortController
|
|
8804
|
+
this.abortController.abort();
|
|
8805
|
+
this.workflowRunStatus = "canceled";
|
|
8806
|
+
try {
|
|
8807
|
+
await this.mastra?.getStorage()?.updateWorkflowState({
|
|
8808
|
+
workflowName: this.workflowId,
|
|
8809
|
+
runId: this.runId,
|
|
8810
|
+
opts: {
|
|
8811
|
+
status: "canceled"
|
|
8812
|
+
}
|
|
8813
|
+
});
|
|
8814
|
+
} catch {
|
|
8815
|
+
}
|
|
8637
8816
|
}
|
|
8638
8817
|
async _validateInput(inputData) {
|
|
8639
8818
|
let inputDataToUse = inputData;
|
|
@@ -8734,20 +8913,7 @@ var Run = class {
|
|
|
8734
8913
|
serializedStepGraph: this.serializedStepGraph,
|
|
8735
8914
|
input: inputDataToUse,
|
|
8736
8915
|
initialState: initialStateToUse,
|
|
8737
|
-
|
|
8738
|
-
emit: async (event, data) => {
|
|
8739
|
-
this.emitter.emit(event, data);
|
|
8740
|
-
},
|
|
8741
|
-
on: (event, callback) => {
|
|
8742
|
-
this.emitter.on(event, callback);
|
|
8743
|
-
},
|
|
8744
|
-
off: (event, callback) => {
|
|
8745
|
-
this.emitter.off(event, callback);
|
|
8746
|
-
},
|
|
8747
|
-
once: (event, callback) => {
|
|
8748
|
-
this.emitter.once(event, callback);
|
|
8749
|
-
}
|
|
8750
|
-
},
|
|
8916
|
+
pubsub: this.pubsub,
|
|
8751
8917
|
retryConfig: this.retryConfig,
|
|
8752
8918
|
requestContext: requestContext ?? new chunkUVHSM2GU_cjs.RequestContext(),
|
|
8753
8919
|
abortController: this.abortController,
|
|
@@ -8770,6 +8936,19 @@ var Run = class {
|
|
|
8770
8936
|
async start(args) {
|
|
8771
8937
|
return this._start(args);
|
|
8772
8938
|
}
|
|
8939
|
+
/**
|
|
8940
|
+
* Starts the workflow execution without waiting for completion (fire-and-forget).
|
|
8941
|
+
* Returns immediately with the runId. The workflow executes in the background.
|
|
8942
|
+
* Use this when you don't need to wait for the result or want to avoid polling failures.
|
|
8943
|
+
* @param args The input data and configuration for the workflow
|
|
8944
|
+
* @returns A promise that resolves immediately with the runId
|
|
8945
|
+
*/
|
|
8946
|
+
async startAsync(args) {
|
|
8947
|
+
this._start(args).catch((err) => {
|
|
8948
|
+
console.error(`[Workflow ${this.workflowId}] Background execution failed:`, err);
|
|
8949
|
+
});
|
|
8950
|
+
return { runId: this.runId };
|
|
8951
|
+
}
|
|
8773
8952
|
/**
|
|
8774
8953
|
* Starts the workflow execution with the provided input as a stream
|
|
8775
8954
|
* @param input The input data for the workflow
|
|
@@ -8804,9 +8983,10 @@ var Run = class {
|
|
|
8804
8983
|
}
|
|
8805
8984
|
});
|
|
8806
8985
|
this.closeStreamAction = async () => {
|
|
8807
|
-
this.
|
|
8808
|
-
type: "
|
|
8809
|
-
|
|
8986
|
+
await this.pubsub.publish(`workflow.events.v2.${this.runId}`, {
|
|
8987
|
+
type: "watch",
|
|
8988
|
+
runId: this.runId,
|
|
8989
|
+
data: { type: "workflow-finish", payload: { runId: this.runId } }
|
|
8810
8990
|
});
|
|
8811
8991
|
unwatch();
|
|
8812
8992
|
await Promise.all(this.#observerHandlers.map((handler) => handler()));
|
|
@@ -8819,9 +8999,10 @@ var Run = class {
|
|
|
8819
8999
|
writer.releaseLock();
|
|
8820
9000
|
}
|
|
8821
9001
|
};
|
|
8822
|
-
this.
|
|
8823
|
-
type: "
|
|
8824
|
-
|
|
9002
|
+
void this.pubsub.publish(`workflow.events.v2.${this.runId}`, {
|
|
9003
|
+
type: "watch",
|
|
9004
|
+
runId: this.runId,
|
|
9005
|
+
data: { type: "workflow-start", payload: { runId: this.runId } }
|
|
8825
9006
|
});
|
|
8826
9007
|
this.executionResults = this._start({
|
|
8827
9008
|
inputData,
|
|
@@ -8957,7 +9138,9 @@ var Run = class {
|
|
|
8957
9138
|
self.closeStreamAction = async () => {
|
|
8958
9139
|
unwatch();
|
|
8959
9140
|
try {
|
|
8960
|
-
|
|
9141
|
+
if (controller.desiredSize !== null) {
|
|
9142
|
+
controller.close();
|
|
9143
|
+
}
|
|
8961
9144
|
} catch (err) {
|
|
8962
9145
|
console.error("Error closing stream:", err);
|
|
8963
9146
|
}
|
|
@@ -8970,7 +9153,11 @@ var Run = class {
|
|
|
8970
9153
|
initialState,
|
|
8971
9154
|
outputOptions,
|
|
8972
9155
|
outputWriter: async (chunk) => {
|
|
8973
|
-
void self.
|
|
9156
|
+
void self.pubsub.publish(`workflow.events.v2.${self.runId}`, {
|
|
9157
|
+
type: "watch",
|
|
9158
|
+
runId: self.runId,
|
|
9159
|
+
data: chunk
|
|
9160
|
+
});
|
|
8974
9161
|
}
|
|
8975
9162
|
});
|
|
8976
9163
|
let executionResults;
|
|
@@ -9068,7 +9255,9 @@ var Run = class {
|
|
|
9068
9255
|
self.closeStreamAction = async () => {
|
|
9069
9256
|
unwatch();
|
|
9070
9257
|
try {
|
|
9071
|
-
|
|
9258
|
+
if (controller.desiredSize !== null) {
|
|
9259
|
+
controller.close();
|
|
9260
|
+
}
|
|
9072
9261
|
} catch (err) {
|
|
9073
9262
|
console.error("Error closing stream:", err);
|
|
9074
9263
|
}
|
|
@@ -9113,20 +9302,29 @@ var Run = class {
|
|
|
9113
9302
|
* @internal
|
|
9114
9303
|
*/
|
|
9115
9304
|
watch(cb) {
|
|
9116
|
-
const
|
|
9117
|
-
event
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
|
|
9122
|
-
|
|
9123
|
-
|
|
9305
|
+
const wrappedCb = (event) => {
|
|
9306
|
+
if (event.runId === this.runId) {
|
|
9307
|
+
cb(event.data);
|
|
9308
|
+
}
|
|
9309
|
+
};
|
|
9310
|
+
const nestedWatchCb = (event) => {
|
|
9311
|
+
if (event.runId === this.runId) {
|
|
9312
|
+
const { event: nestedEvent, workflowId } = event.data;
|
|
9313
|
+
void this.pubsub.publish(`workflow.events.v2.${this.runId}`, {
|
|
9314
|
+
type: "watch",
|
|
9315
|
+
runId: this.runId,
|
|
9316
|
+
data: {
|
|
9317
|
+
...nestedEvent,
|
|
9318
|
+
...nestedEvent.payload?.id ? { payload: { ...nestedEvent.payload, id: `${workflowId}.${nestedEvent.payload.id}` } } : {}
|
|
9319
|
+
}
|
|
9320
|
+
});
|
|
9321
|
+
}
|
|
9124
9322
|
};
|
|
9125
|
-
this.
|
|
9126
|
-
this.
|
|
9323
|
+
void this.pubsub.subscribe(`workflow.events.v2.${this.runId}`, wrappedCb);
|
|
9324
|
+
void this.pubsub.subscribe("nested-watch", nestedWatchCb);
|
|
9127
9325
|
return () => {
|
|
9128
|
-
this.
|
|
9129
|
-
this.
|
|
9326
|
+
void this.pubsub.unsubscribe(`workflow.events.v2.${this.runId}`, wrappedCb);
|
|
9327
|
+
void this.pubsub.unsubscribe("nested-watch", nestedWatchCb);
|
|
9130
9328
|
};
|
|
9131
9329
|
}
|
|
9132
9330
|
/**
|
|
@@ -9254,21 +9452,7 @@ var Run = class {
|
|
|
9254
9452
|
label: params.label
|
|
9255
9453
|
},
|
|
9256
9454
|
format: params.format,
|
|
9257
|
-
|
|
9258
|
-
emit: (event, data) => {
|
|
9259
|
-
this.emitter.emit(event, data);
|
|
9260
|
-
return Promise.resolve();
|
|
9261
|
-
},
|
|
9262
|
-
on: (event, callback) => {
|
|
9263
|
-
this.emitter.on(event, callback);
|
|
9264
|
-
},
|
|
9265
|
-
off: (event, callback) => {
|
|
9266
|
-
this.emitter.off(event, callback);
|
|
9267
|
-
},
|
|
9268
|
-
once: (event, callback) => {
|
|
9269
|
-
this.emitter.once(event, callback);
|
|
9270
|
-
}
|
|
9271
|
-
},
|
|
9455
|
+
pubsub: this.pubsub,
|
|
9272
9456
|
requestContext: requestContextToUse,
|
|
9273
9457
|
abortController: this.abortController,
|
|
9274
9458
|
workflowSpan,
|
|
@@ -9368,20 +9552,7 @@ var Run = class {
|
|
|
9368
9552
|
graph: this.executionGraph,
|
|
9369
9553
|
serializedStepGraph: this.serializedStepGraph,
|
|
9370
9554
|
restart: restartData,
|
|
9371
|
-
|
|
9372
|
-
emit: async (event, data) => {
|
|
9373
|
-
this.emitter.emit(event, data);
|
|
9374
|
-
},
|
|
9375
|
-
on: (event, callback) => {
|
|
9376
|
-
this.emitter.on(event, callback);
|
|
9377
|
-
},
|
|
9378
|
-
off: (event, callback) => {
|
|
9379
|
-
this.emitter.off(event, callback);
|
|
9380
|
-
},
|
|
9381
|
-
once: (event, callback) => {
|
|
9382
|
-
this.emitter.once(event, callback);
|
|
9383
|
-
}
|
|
9384
|
-
},
|
|
9555
|
+
pubsub: this.pubsub,
|
|
9385
9556
|
retryConfig: this.retryConfig,
|
|
9386
9557
|
requestContext: requestContextToUse,
|
|
9387
9558
|
abortController: this.abortController,
|
|
@@ -9474,20 +9645,7 @@ var Run = class {
|
|
|
9474
9645
|
graph: this.executionGraph,
|
|
9475
9646
|
timeTravel: timeTravelData,
|
|
9476
9647
|
serializedStepGraph: this.serializedStepGraph,
|
|
9477
|
-
|
|
9478
|
-
emit: async (event, data) => {
|
|
9479
|
-
this.emitter.emit(event, data);
|
|
9480
|
-
},
|
|
9481
|
-
on: (event, callback) => {
|
|
9482
|
-
this.emitter.on(event, callback);
|
|
9483
|
-
},
|
|
9484
|
-
off: (event, callback) => {
|
|
9485
|
-
this.emitter.off(event, callback);
|
|
9486
|
-
},
|
|
9487
|
-
once: (event, callback) => {
|
|
9488
|
-
this.emitter.once(event, callback);
|
|
9489
|
-
}
|
|
9490
|
-
},
|
|
9648
|
+
pubsub: this.pubsub,
|
|
9491
9649
|
retryConfig: this.retryConfig,
|
|
9492
9650
|
requestContext: requestContextToUse,
|
|
9493
9651
|
abortController: this.abortController,
|
|
@@ -9535,7 +9693,9 @@ var Run = class {
|
|
|
9535
9693
|
self.closeStreamAction = async () => {
|
|
9536
9694
|
unwatch();
|
|
9537
9695
|
try {
|
|
9538
|
-
|
|
9696
|
+
if (controller.desiredSize !== null) {
|
|
9697
|
+
controller.close();
|
|
9698
|
+
}
|
|
9539
9699
|
} catch (err) {
|
|
9540
9700
|
console.error("Error closing stream:", err);
|
|
9541
9701
|
}
|
|
@@ -9586,80 +9746,80 @@ var Run = class {
|
|
|
9586
9746
|
return this.executionResults ?? this.streamOutput?.result;
|
|
9587
9747
|
}
|
|
9588
9748
|
};
|
|
9589
|
-
var languageModelUsageSchema =
|
|
9590
|
-
inputTokens:
|
|
9591
|
-
outputTokens:
|
|
9592
|
-
totalTokens:
|
|
9593
|
-
reasoningTokens:
|
|
9594
|
-
cachedInputTokens:
|
|
9749
|
+
var languageModelUsageSchema = z8__default.default.object({
|
|
9750
|
+
inputTokens: z8__default.default.number(),
|
|
9751
|
+
outputTokens: z8__default.default.number(),
|
|
9752
|
+
totalTokens: z8__default.default.number(),
|
|
9753
|
+
reasoningTokens: z8__default.default.number().optional(),
|
|
9754
|
+
cachedInputTokens: z8__default.default.number().optional()
|
|
9595
9755
|
});
|
|
9596
|
-
var llmIterationStepResultSchema =
|
|
9597
|
-
reason:
|
|
9598
|
-
warnings:
|
|
9599
|
-
isContinued:
|
|
9600
|
-
logprobs:
|
|
9756
|
+
var llmIterationStepResultSchema = z8__default.default.object({
|
|
9757
|
+
reason: z8__default.default.string(),
|
|
9758
|
+
warnings: z8__default.default.array(z8__default.default.any()),
|
|
9759
|
+
isContinued: z8__default.default.boolean(),
|
|
9760
|
+
logprobs: z8__default.default.any().optional(),
|
|
9601
9761
|
totalUsage: languageModelUsageSchema.optional(),
|
|
9602
|
-
headers:
|
|
9603
|
-
messageId:
|
|
9604
|
-
request:
|
|
9762
|
+
headers: z8__default.default.record(z8__default.default.string()).optional(),
|
|
9763
|
+
messageId: z8__default.default.string().optional(),
|
|
9764
|
+
request: z8__default.default.record(z8__default.default.any()).optional()
|
|
9605
9765
|
});
|
|
9606
|
-
var llmIterationOutputSchema =
|
|
9607
|
-
messageId:
|
|
9608
|
-
messages:
|
|
9609
|
-
all:
|
|
9766
|
+
var llmIterationOutputSchema = z8__default.default.object({
|
|
9767
|
+
messageId: z8__default.default.string(),
|
|
9768
|
+
messages: z8__default.default.object({
|
|
9769
|
+
all: z8__default.default.array(z8__default.default.any()),
|
|
9610
9770
|
// ModelMessage[] but too complex to validate at runtime
|
|
9611
|
-
user:
|
|
9612
|
-
nonUser:
|
|
9771
|
+
user: z8__default.default.array(z8__default.default.any()),
|
|
9772
|
+
nonUser: z8__default.default.array(z8__default.default.any())
|
|
9613
9773
|
}),
|
|
9614
|
-
output:
|
|
9615
|
-
text:
|
|
9616
|
-
reasoning:
|
|
9617
|
-
reasoningText:
|
|
9618
|
-
files:
|
|
9774
|
+
output: z8__default.default.object({
|
|
9775
|
+
text: z8__default.default.string().optional(),
|
|
9776
|
+
reasoning: z8__default.default.array(z8__default.default.any()).optional(),
|
|
9777
|
+
reasoningText: z8__default.default.string().optional(),
|
|
9778
|
+
files: z8__default.default.array(z8__default.default.any()).optional(),
|
|
9619
9779
|
// GeneratedFile[]
|
|
9620
|
-
toolCalls:
|
|
9780
|
+
toolCalls: z8__default.default.array(z8__default.default.any()).optional(),
|
|
9621
9781
|
// TypedToolCall[]
|
|
9622
|
-
toolResults:
|
|
9782
|
+
toolResults: z8__default.default.array(z8__default.default.any()).optional(),
|
|
9623
9783
|
// TypedToolResult[]
|
|
9624
|
-
sources:
|
|
9784
|
+
sources: z8__default.default.array(z8__default.default.any()).optional(),
|
|
9625
9785
|
// LanguageModelV2Source[]
|
|
9626
|
-
staticToolCalls:
|
|
9627
|
-
dynamicToolCalls:
|
|
9628
|
-
staticToolResults:
|
|
9629
|
-
dynamicToolResults:
|
|
9786
|
+
staticToolCalls: z8__default.default.array(z8__default.default.any()).optional(),
|
|
9787
|
+
dynamicToolCalls: z8__default.default.array(z8__default.default.any()).optional(),
|
|
9788
|
+
staticToolResults: z8__default.default.array(z8__default.default.any()).optional(),
|
|
9789
|
+
dynamicToolResults: z8__default.default.array(z8__default.default.any()).optional(),
|
|
9630
9790
|
usage: languageModelUsageSchema,
|
|
9631
|
-
steps:
|
|
9791
|
+
steps: z8__default.default.array(z8__default.default.any())
|
|
9632
9792
|
// StepResult[]
|
|
9633
9793
|
}),
|
|
9634
|
-
metadata:
|
|
9635
|
-
id:
|
|
9636
|
-
model:
|
|
9637
|
-
modelId:
|
|
9638
|
-
modelMetadata:
|
|
9639
|
-
modelId:
|
|
9640
|
-
modelVersion:
|
|
9641
|
-
modelProvider:
|
|
9794
|
+
metadata: z8__default.default.object({
|
|
9795
|
+
id: z8__default.default.string().optional(),
|
|
9796
|
+
model: z8__default.default.string().optional(),
|
|
9797
|
+
modelId: z8__default.default.string().optional(),
|
|
9798
|
+
modelMetadata: z8__default.default.object({
|
|
9799
|
+
modelId: z8__default.default.string(),
|
|
9800
|
+
modelVersion: z8__default.default.string(),
|
|
9801
|
+
modelProvider: z8__default.default.string()
|
|
9642
9802
|
}).optional(),
|
|
9643
|
-
timestamp:
|
|
9644
|
-
providerMetadata:
|
|
9645
|
-
headers:
|
|
9646
|
-
request:
|
|
9803
|
+
timestamp: z8__default.default.date().optional(),
|
|
9804
|
+
providerMetadata: z8__default.default.record(z8__default.default.any()).optional(),
|
|
9805
|
+
headers: z8__default.default.record(z8__default.default.string()).optional(),
|
|
9806
|
+
request: z8__default.default.record(z8__default.default.any()).optional()
|
|
9647
9807
|
}),
|
|
9648
9808
|
stepResult: llmIterationStepResultSchema,
|
|
9649
|
-
processorRetryCount:
|
|
9650
|
-
processorRetryFeedback:
|
|
9809
|
+
processorRetryCount: z8__default.default.number().optional(),
|
|
9810
|
+
processorRetryFeedback: z8__default.default.string().optional()
|
|
9651
9811
|
});
|
|
9652
|
-
var toolCallInputSchema =
|
|
9653
|
-
toolCallId:
|
|
9654
|
-
toolName:
|
|
9655
|
-
args:
|
|
9656
|
-
providerMetadata:
|
|
9657
|
-
providerExecuted:
|
|
9658
|
-
output:
|
|
9812
|
+
var toolCallInputSchema = z8__default.default.object({
|
|
9813
|
+
toolCallId: z8__default.default.string(),
|
|
9814
|
+
toolName: z8__default.default.string(),
|
|
9815
|
+
args: z8__default.default.record(z8__default.default.any()),
|
|
9816
|
+
providerMetadata: z8__default.default.record(z8__default.default.any()).optional(),
|
|
9817
|
+
providerExecuted: z8__default.default.boolean().optional(),
|
|
9818
|
+
output: z8__default.default.any().optional()
|
|
9659
9819
|
});
|
|
9660
9820
|
var toolCallOutputSchema = toolCallInputSchema.extend({
|
|
9661
|
-
result:
|
|
9662
|
-
error:
|
|
9821
|
+
result: z8__default.default.any(),
|
|
9822
|
+
error: z8__default.default.any().optional()
|
|
9663
9823
|
});
|
|
9664
9824
|
|
|
9665
9825
|
// src/processors/processors/prepare-step.ts
|
|
@@ -9712,10 +9872,10 @@ var AISDKV5InputStream = class extends MastraModelInput {
|
|
|
9712
9872
|
constructor({
|
|
9713
9873
|
component,
|
|
9714
9874
|
name,
|
|
9715
|
-
generateId:
|
|
9875
|
+
generateId: generateId2
|
|
9716
9876
|
}) {
|
|
9717
9877
|
super({ component, name });
|
|
9718
|
-
this.#generateId =
|
|
9878
|
+
this.#generateId = generateId2 ?? chunkFVQTJUBD_cjs.generateId;
|
|
9719
9879
|
}
|
|
9720
9880
|
async transform({
|
|
9721
9881
|
runId,
|
|
@@ -9767,12 +9927,12 @@ function execute({
|
|
|
9767
9927
|
headers,
|
|
9768
9928
|
shouldThrowError,
|
|
9769
9929
|
methodType,
|
|
9770
|
-
generateId:
|
|
9930
|
+
generateId: generateId2
|
|
9771
9931
|
}) {
|
|
9772
9932
|
const v5 = new AISDKV5InputStream({
|
|
9773
9933
|
component: "LLM",
|
|
9774
9934
|
name: model.modelId,
|
|
9775
|
-
generateId:
|
|
9935
|
+
generateId: generateId2
|
|
9776
9936
|
});
|
|
9777
9937
|
const toolsAndToolChoice = prepareToolsAndToolChoice({
|
|
9778
9938
|
tools,
|
|
@@ -9783,13 +9943,13 @@ function execute({
|
|
|
9783
9943
|
const responseFormat = structuredOutput?.schema ? getResponseFormat(structuredOutput?.schema) : void 0;
|
|
9784
9944
|
let prompt = inputMessages;
|
|
9785
9945
|
if (structuredOutputMode === "direct" && responseFormat?.type === "json" && structuredOutput?.jsonPromptInjection) {
|
|
9786
|
-
prompt =
|
|
9946
|
+
prompt = chunkX6IBA7FP_cjs.injectJsonInstructionIntoMessages({
|
|
9787
9947
|
messages: inputMessages,
|
|
9788
9948
|
schema: responseFormat.schema
|
|
9789
9949
|
});
|
|
9790
9950
|
}
|
|
9791
9951
|
if (structuredOutputMode === "processor" && responseFormat?.type === "json" && responseFormat?.schema) {
|
|
9792
|
-
prompt =
|
|
9952
|
+
prompt = chunkX6IBA7FP_cjs.injectJsonInstructionIntoMessages({
|
|
9793
9953
|
messages: inputMessages,
|
|
9794
9954
|
schema: responseFormat.schema,
|
|
9795
9955
|
schemaPrefix: `Your response will be processed by another agent to extract structured data. Please ensure your response contains comprehensive information for all the following fields that will be extracted:
|
|
@@ -9833,7 +9993,7 @@ You don't need to format your response as JSON unless the user asks you to. Just
|
|
|
9833
9993
|
retries: modelSettings?.maxRetries ?? 2,
|
|
9834
9994
|
signal: abortSignal,
|
|
9835
9995
|
shouldRetry(context) {
|
|
9836
|
-
if (
|
|
9996
|
+
if (chunkFVQTJUBD_cjs.APICallError.isInstance(context.error)) {
|
|
9837
9997
|
return context.error.isRetryable;
|
|
9838
9998
|
}
|
|
9839
9999
|
return true;
|
|
@@ -10055,10 +10215,10 @@ async function processOutputStream({
|
|
|
10055
10215
|
break;
|
|
10056
10216
|
}
|
|
10057
10217
|
case "tool-call-input-streaming-start": {
|
|
10058
|
-
const
|
|
10059
|
-
if (
|
|
10218
|
+
const tool2 = tools?.[chunk.payload.toolName] || Object.values(tools || {})?.find((tool3) => `id` in tool3 && tool3.id === chunk.payload.toolName);
|
|
10219
|
+
if (tool2 && "onInputStart" in tool2) {
|
|
10060
10220
|
try {
|
|
10061
|
-
await
|
|
10221
|
+
await tool2?.onInputStart?.({
|
|
10062
10222
|
toolCallId: chunk.payload.toolCallId,
|
|
10063
10223
|
messages: messageList.get.input.aiV5.model(),
|
|
10064
10224
|
abortSignal: options?.abortSignal
|
|
@@ -10073,10 +10233,10 @@ async function processOutputStream({
|
|
|
10073
10233
|
break;
|
|
10074
10234
|
}
|
|
10075
10235
|
case "tool-call-delta": {
|
|
10076
|
-
const
|
|
10077
|
-
if (
|
|
10236
|
+
const tool2 = tools?.[chunk.payload.toolName || ""] || Object.values(tools || {})?.find((tool3) => `id` in tool3 && tool3.id === chunk.payload.toolName);
|
|
10237
|
+
if (tool2 && "onInputDelta" in tool2) {
|
|
10078
10238
|
try {
|
|
10079
|
-
await
|
|
10239
|
+
await tool2?.onInputDelta?.({
|
|
10080
10240
|
inputTextDelta: chunk.payload.argsTextDelta,
|
|
10081
10241
|
toolCallId: chunk.payload.toolCallId,
|
|
10082
10242
|
messages: messageList.get.input.aiV5.model(),
|
|
@@ -10230,7 +10390,7 @@ async function processOutputStream({
|
|
|
10230
10390
|
});
|
|
10231
10391
|
break;
|
|
10232
10392
|
case "error":
|
|
10233
|
-
if (
|
|
10393
|
+
if (chunkX6IBA7FP_cjs.isAbortError(chunk.payload.error) && options?.abortSignal?.aborted) {
|
|
10234
10394
|
break;
|
|
10235
10395
|
}
|
|
10236
10396
|
runState.setState({
|
|
@@ -10242,7 +10402,7 @@ async function processOutputStream({
|
|
|
10242
10402
|
reason: "error"
|
|
10243
10403
|
}
|
|
10244
10404
|
});
|
|
10245
|
-
const error =
|
|
10405
|
+
const error = chunkHWMMIRIF_cjs.getErrorFromUnknown(chunk.payload.error, {
|
|
10246
10406
|
fallbackMessage: "Unknown error in agent stream"
|
|
10247
10407
|
});
|
|
10248
10408
|
controller.enqueue({ ...chunk, payload: { ...chunk.payload, error } });
|
|
@@ -10336,6 +10496,7 @@ function createLLMExecutionStep({
|
|
|
10336
10496
|
requestContext,
|
|
10337
10497
|
methodType,
|
|
10338
10498
|
modelSpanTracker,
|
|
10499
|
+
autoResumeSuspendedTools,
|
|
10339
10500
|
maxProcessorRetries
|
|
10340
10501
|
}) {
|
|
10341
10502
|
const initialSystemMessages = messageList.getAllSystemMessages();
|
|
@@ -10406,7 +10567,33 @@ function createLLMExecutionStep({
|
|
|
10406
10567
|
downloadConcurrency,
|
|
10407
10568
|
supportedUrls: currentStep.model?.supportedUrls
|
|
10408
10569
|
};
|
|
10409
|
-
|
|
10570
|
+
let inputMessages = await messageList.get.all.aiV5.llmPrompt(messageListPromptArgs);
|
|
10571
|
+
if (autoResumeSuspendedTools) {
|
|
10572
|
+
const messages2 = messageList.get.all.db();
|
|
10573
|
+
const assistantMessages = [...messages2].reverse().filter((message) => message.role === "assistant");
|
|
10574
|
+
const suspendedToolsMessage = assistantMessages.find(
|
|
10575
|
+
(message) => message.content.metadata?.suspendedTools || message.content.metadata?.pendingToolApprovals
|
|
10576
|
+
);
|
|
10577
|
+
if (suspendedToolsMessage) {
|
|
10578
|
+
const metadata = suspendedToolsMessage.content.metadata;
|
|
10579
|
+
const suspendedToolObj = metadata?.suspendedTools || metadata?.pendingToolApprovals;
|
|
10580
|
+
const suspendedTools = Object.values(suspendedToolObj);
|
|
10581
|
+
if (suspendedTools.length > 0) {
|
|
10582
|
+
inputMessages = inputMessages.map((message, index) => {
|
|
10583
|
+
if (message.role === "system" && index === 0) {
|
|
10584
|
+
message.content = message.content + `
|
|
10585
|
+
|
|
10586
|
+
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.
|
|
10587
|
+
resumeData can not be an empty object nor null/undefined.
|
|
10588
|
+
When you find that and call that tool, add the resumeData to the tool call arguments/input.
|
|
10589
|
+
Also, add the runId of the suspended tool as suspendedToolRunId to the tool call arguments/input.
|
|
10590
|
+
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.`;
|
|
10591
|
+
}
|
|
10592
|
+
return message;
|
|
10593
|
+
});
|
|
10594
|
+
}
|
|
10595
|
+
}
|
|
10596
|
+
}
|
|
10410
10597
|
switch (currentStep.model.specificationVersion) {
|
|
10411
10598
|
case "v2": {
|
|
10412
10599
|
modelResult = chunk72YCRTEX_cjs.executeWithContextSync({
|
|
@@ -10496,7 +10683,7 @@ function createLLMExecutionStep({
|
|
|
10496
10683
|
});
|
|
10497
10684
|
} catch (error) {
|
|
10498
10685
|
console.error("Error in LLM Execution Step", error);
|
|
10499
|
-
if (
|
|
10686
|
+
if (chunkX6IBA7FP_cjs.isAbortError(error) && options?.abortSignal?.aborted) {
|
|
10500
10687
|
await options?.onAbort?.({
|
|
10501
10688
|
steps: inputData?.output?.steps ?? []
|
|
10502
10689
|
});
|
|
@@ -10767,11 +10954,11 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
|
|
|
10767
10954
|
}
|
|
10768
10955
|
return createStep({
|
|
10769
10956
|
id: "llmExecutionMappingStep",
|
|
10770
|
-
inputSchema:
|
|
10957
|
+
inputSchema: z8__default.default.array(toolCallOutputSchema),
|
|
10771
10958
|
outputSchema: llmIterationOutputSchema,
|
|
10772
10959
|
execute: async ({ inputData, getStepResult: getStepResult2, bail }) => {
|
|
10773
10960
|
const initialResult = getStepResult2(llmExecutionStep);
|
|
10774
|
-
if (inputData?.
|
|
10961
|
+
if (inputData?.some((toolCall) => toolCall?.result === void 0)) {
|
|
10775
10962
|
const errorResults = inputData.filter((toolCall) => toolCall?.error);
|
|
10776
10963
|
const toolResultMessageId = rest.experimental_generateMessageId?.() || _internal?.generateId?.();
|
|
10777
10964
|
if (errorResults?.length) {
|
|
@@ -10816,7 +11003,14 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
|
|
|
10816
11003
|
if (initialResult.stepResult.reason !== "retry") {
|
|
10817
11004
|
initialResult.stepResult.isContinued = false;
|
|
10818
11005
|
}
|
|
10819
|
-
return bail(
|
|
11006
|
+
return bail({
|
|
11007
|
+
...initialResult,
|
|
11008
|
+
messages: {
|
|
11009
|
+
all: rest.messageList.get.all.aiV5.model(),
|
|
11010
|
+
user: rest.messageList.get.input.aiV5.model(),
|
|
11011
|
+
nonUser: rest.messageList.get.response.aiV5.model()
|
|
11012
|
+
}
|
|
11013
|
+
});
|
|
10820
11014
|
}
|
|
10821
11015
|
if (inputData?.length) {
|
|
10822
11016
|
for (const toolCall of inputData) {
|
|
@@ -10874,11 +11068,10 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
|
|
|
10874
11068
|
}
|
|
10875
11069
|
};
|
|
10876
11070
|
}
|
|
11071
|
+
return initialResult;
|
|
10877
11072
|
}
|
|
10878
11073
|
});
|
|
10879
11074
|
}
|
|
10880
|
-
|
|
10881
|
-
// src/loop/workflows/agentic-execution/tool-call-step.ts
|
|
10882
11075
|
function createToolCallStep({
|
|
10883
11076
|
tools,
|
|
10884
11077
|
messageList,
|
|
@@ -10894,28 +11087,39 @@ function createToolCallStep({
|
|
|
10894
11087
|
id: "toolCallStep",
|
|
10895
11088
|
inputSchema: toolCallInputSchema,
|
|
10896
11089
|
outputSchema: toolCallOutputSchema,
|
|
10897
|
-
execute: async ({ inputData, suspend, resumeData, requestContext }) => {
|
|
11090
|
+
execute: async ({ inputData, suspend, resumeData: workflowResumeData, requestContext }) => {
|
|
10898
11091
|
const stepTools = _internal?.stepTools || tools;
|
|
10899
|
-
const
|
|
10900
|
-
const
|
|
11092
|
+
const tool2 = stepTools?.[inputData.toolName] || Object.values(stepTools || {})?.find((t) => `id` in t && t.id === inputData.toolName);
|
|
11093
|
+
const addToolMetadata = ({
|
|
11094
|
+
toolCallId,
|
|
11095
|
+
toolName,
|
|
11096
|
+
args,
|
|
11097
|
+
suspendPayload,
|
|
11098
|
+
resumeSchema,
|
|
11099
|
+
type
|
|
11100
|
+
}) => {
|
|
11101
|
+
const metadataKey = type === "suspension" ? "suspendedTools" : "pendingToolApprovals";
|
|
10901
11102
|
const responseMessages = messageList.get.response.db();
|
|
10902
11103
|
const lastAssistantMessage = [...responseMessages].reverse().find((msg) => msg.role === "assistant");
|
|
10903
11104
|
if (lastAssistantMessage) {
|
|
10904
11105
|
const content = lastAssistantMessage.content;
|
|
10905
11106
|
if (!content) return;
|
|
10906
11107
|
const metadata = typeof lastAssistantMessage.content.metadata === "object" && lastAssistantMessage.content.metadata !== null ? lastAssistantMessage.content.metadata : {};
|
|
10907
|
-
metadata
|
|
10908
|
-
metadata
|
|
11108
|
+
metadata[metadataKey] = metadata[metadataKey] || {};
|
|
11109
|
+
metadata[metadataKey][toolName] = {
|
|
11110
|
+
toolCallId,
|
|
10909
11111
|
toolName,
|
|
10910
11112
|
args,
|
|
10911
|
-
type
|
|
10912
|
-
runId
|
|
11113
|
+
type,
|
|
11114
|
+
runId,
|
|
10913
11115
|
// Store the runId so we can resume after page refresh
|
|
11116
|
+
...type === "suspension" ? { suspendPayload } : {},
|
|
11117
|
+
resumeSchema
|
|
10914
11118
|
};
|
|
10915
11119
|
lastAssistantMessage.content.metadata = metadata;
|
|
10916
11120
|
}
|
|
10917
11121
|
};
|
|
10918
|
-
const
|
|
11122
|
+
const removeToolMetadata = async (toolName, type) => {
|
|
10919
11123
|
const { saveQueueManager, memoryConfig, threadId } = _internal || {};
|
|
10920
11124
|
if (!saveQueueManager || !threadId) {
|
|
10921
11125
|
return;
|
|
@@ -10926,24 +11130,25 @@ function createToolCallStep({
|
|
|
10926
11130
|
const metadata = typeof content.metadata === "object" && content.metadata !== null ? content.metadata : void 0;
|
|
10927
11131
|
return metadata;
|
|
10928
11132
|
};
|
|
11133
|
+
const metadataKey = type === "suspension" ? "suspendedTools" : "pendingToolApprovals";
|
|
10929
11134
|
const allMessages = messageList.get.all.db();
|
|
10930
11135
|
const lastAssistantMessage = [...allMessages].reverse().find((msg) => {
|
|
10931
11136
|
const metadata = getMetadata(msg);
|
|
10932
|
-
const
|
|
10933
|
-
return !!
|
|
11137
|
+
const suspendedTools = metadata?.[metadataKey];
|
|
11138
|
+
return !!suspendedTools?.[toolName];
|
|
10934
11139
|
});
|
|
10935
11140
|
if (lastAssistantMessage) {
|
|
10936
11141
|
const metadata = getMetadata(lastAssistantMessage);
|
|
10937
|
-
const
|
|
10938
|
-
if (
|
|
10939
|
-
delete
|
|
10940
|
-
if (metadata && Object.keys(
|
|
10941
|
-
delete metadata
|
|
11142
|
+
const suspendedTools = metadata?.[metadataKey];
|
|
11143
|
+
if (suspendedTools && typeof suspendedTools === "object") {
|
|
11144
|
+
delete suspendedTools[toolName];
|
|
11145
|
+
if (metadata && Object.keys(suspendedTools).length === 0) {
|
|
11146
|
+
delete metadata[metadataKey];
|
|
10942
11147
|
}
|
|
10943
11148
|
try {
|
|
10944
11149
|
await saveQueueManager.flushMessages(messageList, threadId, memoryConfig);
|
|
10945
11150
|
} catch (error) {
|
|
10946
|
-
console.error("Error removing tool
|
|
11151
|
+
console.error("Error removing tool suspension metadata:", error);
|
|
10947
11152
|
}
|
|
10948
11153
|
}
|
|
10949
11154
|
}
|
|
@@ -10976,12 +11181,12 @@ function createToolCallStep({
|
|
|
10976
11181
|
result: inputData.output
|
|
10977
11182
|
};
|
|
10978
11183
|
}
|
|
10979
|
-
if (!
|
|
11184
|
+
if (!tool2) {
|
|
10980
11185
|
throw new Error(`Tool ${inputData.toolName} not found`);
|
|
10981
11186
|
}
|
|
10982
|
-
if (
|
|
11187
|
+
if (tool2 && "onInputAvailable" in tool2) {
|
|
10983
11188
|
try {
|
|
10984
|
-
await
|
|
11189
|
+
await tool2?.onInputAvailable?.({
|
|
10985
11190
|
toolCallId: inputData.toolCallId,
|
|
10986
11191
|
input: inputData.args,
|
|
10987
11192
|
messages: messageList.get.input.aiV5.model(),
|
|
@@ -10991,12 +11196,21 @@ function createToolCallStep({
|
|
|
10991
11196
|
console.error("Error calling onInputAvailable", error);
|
|
10992
11197
|
}
|
|
10993
11198
|
}
|
|
10994
|
-
if (!
|
|
11199
|
+
if (!tool2.execute) {
|
|
10995
11200
|
return inputData;
|
|
10996
11201
|
}
|
|
10997
11202
|
try {
|
|
10998
11203
|
const requireToolApproval = requestContext.get("__mastra_requireToolApproval");
|
|
10999
|
-
|
|
11204
|
+
let resumeDataFromArgs = void 0;
|
|
11205
|
+
let args = inputData.args;
|
|
11206
|
+
if (typeof inputData.args === "object" && inputData.args !== null) {
|
|
11207
|
+
const { resumeData: resumeDataFromInput, ...argsFromInput } = inputData.args;
|
|
11208
|
+
args = argsFromInput;
|
|
11209
|
+
resumeDataFromArgs = resumeDataFromInput;
|
|
11210
|
+
}
|
|
11211
|
+
const resumeData = resumeDataFromArgs ?? workflowResumeData;
|
|
11212
|
+
const isResumeToolCall = !!resumeDataFromArgs;
|
|
11213
|
+
if (requireToolApproval || tool2.requireApproval) {
|
|
11000
11214
|
if (!resumeData) {
|
|
11001
11215
|
controller.enqueue({
|
|
11002
11216
|
type: "tool-call-approval",
|
|
@@ -11008,7 +11222,17 @@ function createToolCallStep({
|
|
|
11008
11222
|
args: inputData.args
|
|
11009
11223
|
}
|
|
11010
11224
|
});
|
|
11011
|
-
|
|
11225
|
+
addToolMetadata({
|
|
11226
|
+
toolCallId: inputData.toolCallId,
|
|
11227
|
+
toolName: inputData.toolName,
|
|
11228
|
+
args: inputData.args,
|
|
11229
|
+
type: "approval",
|
|
11230
|
+
resumeSchema: z8__default.default.object({
|
|
11231
|
+
approved: z8__default.default.boolean().describe(
|
|
11232
|
+
"Controls if the tool call is approved or not, should be true when approved and false when declined"
|
|
11233
|
+
)
|
|
11234
|
+
})
|
|
11235
|
+
});
|
|
11012
11236
|
await flushMessagesBeforeSuspension();
|
|
11013
11237
|
return suspend(
|
|
11014
11238
|
{
|
|
@@ -11024,7 +11248,7 @@ function createToolCallStep({
|
|
|
11024
11248
|
}
|
|
11025
11249
|
);
|
|
11026
11250
|
} else {
|
|
11027
|
-
await
|
|
11251
|
+
await removeToolMetadata(inputData.toolName, "approval");
|
|
11028
11252
|
if (!resumeData.approved) {
|
|
11029
11253
|
return {
|
|
11030
11254
|
result: "Tool call was not approved by the user",
|
|
@@ -11032,6 +11256,8 @@ function createToolCallStep({
|
|
|
11032
11256
|
};
|
|
11033
11257
|
}
|
|
11034
11258
|
}
|
|
11259
|
+
} else if (isResumeToolCall) {
|
|
11260
|
+
await removeToolMetadata(inputData.toolName, "suspension");
|
|
11035
11261
|
}
|
|
11036
11262
|
const toolOptions = {
|
|
11037
11263
|
abortSignal: options?.abortSignal,
|
|
@@ -11040,18 +11266,33 @@ function createToolCallStep({
|
|
|
11040
11266
|
outputWriter,
|
|
11041
11267
|
// Pass current step span as parent for tool call spans
|
|
11042
11268
|
tracingContext: modelSpanTracker?.getTracingContext(),
|
|
11043
|
-
suspend: async (suspendPayload) => {
|
|
11269
|
+
suspend: async (suspendPayload, options2) => {
|
|
11044
11270
|
controller.enqueue({
|
|
11045
11271
|
type: "tool-call-suspended",
|
|
11046
11272
|
runId,
|
|
11047
11273
|
from: "AGENT" /* AGENT */,
|
|
11048
|
-
payload: {
|
|
11274
|
+
payload: {
|
|
11275
|
+
toolCallId: inputData.toolCallId,
|
|
11276
|
+
toolName: inputData.toolName,
|
|
11277
|
+
suspendPayload,
|
|
11278
|
+
args: inputData.args
|
|
11279
|
+
}
|
|
11280
|
+
});
|
|
11281
|
+
addToolMetadata({
|
|
11282
|
+
toolCallId: inputData.toolCallId,
|
|
11283
|
+
toolName: inputData.toolName,
|
|
11284
|
+
args,
|
|
11285
|
+
suspendPayload,
|
|
11286
|
+
type: "suspension",
|
|
11287
|
+
resumeSchema: options2?.resumeSchema
|
|
11049
11288
|
});
|
|
11050
11289
|
await flushMessagesBeforeSuspension();
|
|
11051
11290
|
return await suspend(
|
|
11052
11291
|
{
|
|
11053
11292
|
toolCallSuspended: suspendPayload,
|
|
11054
|
-
__streamState: streamState.serialize()
|
|
11293
|
+
__streamState: streamState.serialize(),
|
|
11294
|
+
toolName: inputData.toolName,
|
|
11295
|
+
resumeLabel: options2?.resumeLabel
|
|
11055
11296
|
},
|
|
11056
11297
|
{
|
|
11057
11298
|
resumeLabel: inputData.toolCallId
|
|
@@ -11060,10 +11301,10 @@ function createToolCallStep({
|
|
|
11060
11301
|
},
|
|
11061
11302
|
resumeData
|
|
11062
11303
|
};
|
|
11063
|
-
const result = await
|
|
11064
|
-
if (
|
|
11304
|
+
const result = await tool2.execute(args, toolOptions);
|
|
11305
|
+
if (tool2 && "onOutput" in tool2 && typeof tool2.onOutput === "function") {
|
|
11065
11306
|
try {
|
|
11066
|
-
await
|
|
11307
|
+
await tool2.onOutput({
|
|
11067
11308
|
toolCallId: inputData.toolCallId,
|
|
11068
11309
|
toolName: inputData.toolName,
|
|
11069
11310
|
output: result,
|
|
@@ -11103,6 +11344,25 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
|
|
|
11103
11344
|
},
|
|
11104
11345
|
llmExecutionStep
|
|
11105
11346
|
);
|
|
11347
|
+
let toolCallConcurrency = 10;
|
|
11348
|
+
if (rest?.toolCallConcurrency) {
|
|
11349
|
+
toolCallConcurrency = rest.toolCallConcurrency > 0 ? rest.toolCallConcurrency : 10;
|
|
11350
|
+
}
|
|
11351
|
+
const hasRequireToolApproval = !!rest.requireToolApproval;
|
|
11352
|
+
let hasSuspendSchema = false;
|
|
11353
|
+
let hasRequireApproval = false;
|
|
11354
|
+
if (rest.tools) {
|
|
11355
|
+
for (const tool2 of Object.values(rest.tools)) {
|
|
11356
|
+
if (tool2?.hasSuspendSchema) {
|
|
11357
|
+
hasSuspendSchema = true;
|
|
11358
|
+
}
|
|
11359
|
+
if (tool2?.requireApproval) {
|
|
11360
|
+
hasRequireApproval = true;
|
|
11361
|
+
}
|
|
11362
|
+
if (hasSuspendSchema || hasRequireApproval) break;
|
|
11363
|
+
}
|
|
11364
|
+
}
|
|
11365
|
+
const sequentialExecutionRequired = hasRequireToolApproval || hasSuspendSchema || hasRequireApproval;
|
|
11106
11366
|
return createWorkflow({
|
|
11107
11367
|
id: "executionWorkflow",
|
|
11108
11368
|
inputSchema: llmIterationOutputSchema,
|
|
@@ -11132,7 +11392,7 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
|
|
|
11132
11392
|
return typedInputData.output.toolCalls || [];
|
|
11133
11393
|
},
|
|
11134
11394
|
{ id: "map-tool-calls" }
|
|
11135
|
-
).foreach(toolCallStep, { concurrency:
|
|
11395
|
+
).foreach(toolCallStep, { concurrency: sequentialExecutionRequired ? 1 : toolCallConcurrency }).then(llmMappingStep).commit();
|
|
11136
11396
|
}
|
|
11137
11397
|
|
|
11138
11398
|
// src/loop/workflows/agentic-loop/index.ts
|
|
@@ -11265,6 +11525,7 @@ function workflowLoopStream({
|
|
|
11265
11525
|
streamState,
|
|
11266
11526
|
agentId,
|
|
11267
11527
|
toolCallId,
|
|
11528
|
+
toolCallConcurrency,
|
|
11268
11529
|
...rest
|
|
11269
11530
|
}) {
|
|
11270
11531
|
return new web.ReadableStream({
|
|
@@ -11282,7 +11543,9 @@ function workflowLoopStream({
|
|
|
11282
11543
|
format: 2,
|
|
11283
11544
|
parts: [dataPart]
|
|
11284
11545
|
},
|
|
11285
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
11546
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
11547
|
+
threadId: _internal?.threadId,
|
|
11548
|
+
resourceId: _internal?.resourceId
|
|
11286
11549
|
};
|
|
11287
11550
|
messageList.add(message, "response");
|
|
11288
11551
|
}
|
|
@@ -11302,6 +11565,8 @@ function workflowLoopStream({
|
|
|
11302
11565
|
startTimestamp,
|
|
11303
11566
|
streamState,
|
|
11304
11567
|
agentId,
|
|
11568
|
+
requireToolApproval,
|
|
11569
|
+
toolCallConcurrency,
|
|
11305
11570
|
...rest
|
|
11306
11571
|
});
|
|
11307
11572
|
if (rest.mastra) {
|
|
@@ -11332,7 +11597,8 @@ function workflowLoopStream({
|
|
|
11332
11597
|
runId,
|
|
11333
11598
|
from: "AGENT" /* AGENT */,
|
|
11334
11599
|
payload: {
|
|
11335
|
-
id: agentId
|
|
11600
|
+
id: agentId,
|
|
11601
|
+
messageId
|
|
11336
11602
|
}
|
|
11337
11603
|
});
|
|
11338
11604
|
}
|
|
@@ -11354,18 +11620,7 @@ function workflowLoopStream({
|
|
|
11354
11620
|
});
|
|
11355
11621
|
if (executionResult.status !== "success") {
|
|
11356
11622
|
if (executionResult.status === "failed") {
|
|
11357
|
-
|
|
11358
|
-
if (typeof executionResult.error === "string") {
|
|
11359
|
-
const prependedErrorString = "Error: ";
|
|
11360
|
-
if (executionResult.error.startsWith(`${prependedErrorString}${prependedErrorString}`)) {
|
|
11361
|
-
executionResultError = executionResult.error.substring(
|
|
11362
|
-
`${prependedErrorString}${prependedErrorString}`.length
|
|
11363
|
-
);
|
|
11364
|
-
} else if (executionResult.error.startsWith(prependedErrorString)) {
|
|
11365
|
-
executionResultError = executionResult.error.substring(prependedErrorString.length);
|
|
11366
|
-
}
|
|
11367
|
-
}
|
|
11368
|
-
const error = chunkTWH4PTDG_cjs.getErrorFromUnknown(executionResultError, {
|
|
11623
|
+
const error = chunkHWMMIRIF_cjs.getErrorFromUnknown(executionResult.error, {
|
|
11369
11624
|
fallbackMessage: "Unknown error in agent workflow stream"
|
|
11370
11625
|
});
|
|
11371
11626
|
controller.enqueue({
|
|
@@ -11378,9 +11633,13 @@ function workflowLoopStream({
|
|
|
11378
11633
|
await rest.options?.onError?.({ error });
|
|
11379
11634
|
}
|
|
11380
11635
|
}
|
|
11636
|
+
if (executionResult.status !== "suspended") {
|
|
11637
|
+
await agenticLoopWorkflow.deleteWorkflowRunById(runId);
|
|
11638
|
+
}
|
|
11381
11639
|
controller.close();
|
|
11382
11640
|
return;
|
|
11383
11641
|
}
|
|
11642
|
+
await agenticLoopWorkflow.deleteWorkflowRunById(runId);
|
|
11384
11643
|
controller.enqueue({
|
|
11385
11644
|
type: "finish",
|
|
11386
11645
|
runId,
|
|
@@ -11415,13 +11674,14 @@ function loop({
|
|
|
11415
11674
|
returnScorerData,
|
|
11416
11675
|
requireToolApproval,
|
|
11417
11676
|
agentId,
|
|
11677
|
+
toolCallConcurrency,
|
|
11418
11678
|
...rest
|
|
11419
11679
|
}) {
|
|
11420
11680
|
let loggerToUse = logger || new chunkAF74UXR5_cjs.ConsoleLogger({
|
|
11421
11681
|
level: "debug"
|
|
11422
11682
|
});
|
|
11423
11683
|
if (models.length === 0 || !models[0]) {
|
|
11424
|
-
const mastraError = new
|
|
11684
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
11425
11685
|
id: "LOOP_MODELS_EMPTY",
|
|
11426
11686
|
domain: "LLM" /* LLM */,
|
|
11427
11687
|
category: "USER" /* USER */
|
|
@@ -11437,7 +11697,7 @@ function loop({
|
|
|
11437
11697
|
}
|
|
11438
11698
|
const internalToUse = {
|
|
11439
11699
|
now: _internal?.now || (() => Date.now()),
|
|
11440
|
-
generateId: _internal?.generateId || (() =>
|
|
11700
|
+
generateId: _internal?.generateId || (() => chunkFVQTJUBD_cjs.generateId()),
|
|
11441
11701
|
currentDate: _internal?.currentDate || (() => /* @__PURE__ */ new Date()),
|
|
11442
11702
|
saveQueueManager: _internal?.saveQueueManager,
|
|
11443
11703
|
memoryConfig: _internal?.memoryConfig,
|
|
@@ -11471,6 +11731,7 @@ function loop({
|
|
|
11471
11731
|
messageId,
|
|
11472
11732
|
agentId,
|
|
11473
11733
|
requireToolApproval,
|
|
11734
|
+
toolCallConcurrency,
|
|
11474
11735
|
streamState: {
|
|
11475
11736
|
serialize: serializeStreamState,
|
|
11476
11737
|
deserialize: deserializeStreamState
|
|
@@ -11537,7 +11798,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
11537
11798
|
}
|
|
11538
11799
|
}
|
|
11539
11800
|
if (models.length === 0 || !models[0]) {
|
|
11540
|
-
const mastraError = new
|
|
11801
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
11541
11802
|
id: "LLM_LOOP_MODELS_EMPTY",
|
|
11542
11803
|
domain: "LLM" /* LLM */,
|
|
11543
11804
|
category: "USER" /* USER */
|
|
@@ -11613,7 +11874,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
11613
11874
|
stream({
|
|
11614
11875
|
resumeContext,
|
|
11615
11876
|
runId,
|
|
11616
|
-
stopWhen =
|
|
11877
|
+
stopWhen = chunkNESKUIRE_cjs.stepCountIs(5),
|
|
11617
11878
|
maxSteps,
|
|
11618
11879
|
tools = {},
|
|
11619
11880
|
modelSettings,
|
|
@@ -11629,6 +11890,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
11629
11890
|
tracingContext,
|
|
11630
11891
|
messageList,
|
|
11631
11892
|
requireToolApproval,
|
|
11893
|
+
toolCallConcurrency,
|
|
11632
11894
|
_internal,
|
|
11633
11895
|
agentId,
|
|
11634
11896
|
agentName,
|
|
@@ -11636,11 +11898,12 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
11636
11898
|
requestContext,
|
|
11637
11899
|
methodType,
|
|
11638
11900
|
includeRawChunks,
|
|
11901
|
+
autoResumeSuspendedTools,
|
|
11639
11902
|
maxProcessorRetries
|
|
11640
11903
|
}) {
|
|
11641
11904
|
let stopWhenToUse;
|
|
11642
11905
|
if (maxSteps && typeof maxSteps === "number") {
|
|
11643
|
-
stopWhenToUse =
|
|
11906
|
+
stopWhenToUse = chunkNESKUIRE_cjs.stepCountIs(maxSteps);
|
|
11644
11907
|
} else {
|
|
11645
11908
|
stopWhenToUse = stopWhen;
|
|
11646
11909
|
}
|
|
@@ -11695,11 +11958,13 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
11695
11958
|
returnScorerData,
|
|
11696
11959
|
modelSpanTracker,
|
|
11697
11960
|
requireToolApproval,
|
|
11961
|
+
toolCallConcurrency,
|
|
11698
11962
|
agentId,
|
|
11699
11963
|
agentName,
|
|
11700
11964
|
requestContext,
|
|
11701
11965
|
methodType,
|
|
11702
11966
|
includeRawChunks,
|
|
11967
|
+
autoResumeSuspendedTools,
|
|
11703
11968
|
maxProcessorRetries,
|
|
11704
11969
|
options: {
|
|
11705
11970
|
...options,
|
|
@@ -11707,7 +11972,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
11707
11972
|
try {
|
|
11708
11973
|
await options?.onStepFinish?.({ ...props, runId });
|
|
11709
11974
|
} catch (e) {
|
|
11710
|
-
const mastraError = new
|
|
11975
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError(
|
|
11711
11976
|
{
|
|
11712
11977
|
id: "LLM_STREAM_ON_STEP_FINISH_CALLBACK_EXECUTION_FAILED",
|
|
11713
11978
|
domain: "LLM" /* LLM */,
|
|
@@ -11741,7 +12006,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
11741
12006
|
const remainingTokens = parseInt(props?.response?.headers?.["x-ratelimit-remaining-tokens"] ?? "", 10);
|
|
11742
12007
|
if (!isNaN(remainingTokens) && remainingTokens > 0 && remainingTokens < 2e3) {
|
|
11743
12008
|
this.logger.warn("Rate limit approaching, waiting 10 seconds", { runId });
|
|
11744
|
-
await
|
|
12009
|
+
await chunkMLKE7HRS_cjs.delay(10 * 1e3);
|
|
11745
12010
|
}
|
|
11746
12011
|
},
|
|
11747
12012
|
onFinish: async (props) => {
|
|
@@ -11766,7 +12031,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
11766
12031
|
try {
|
|
11767
12032
|
await options?.onFinish?.({ ...props, runId });
|
|
11768
12033
|
} catch (e) {
|
|
11769
|
-
const mastraError = new
|
|
12034
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError(
|
|
11770
12035
|
{
|
|
11771
12036
|
id: "LLM_STREAM_ON_FINISH_CALLBACK_EXECUTION_FAILED",
|
|
11772
12037
|
domain: "LLM" /* LLM */,
|
|
@@ -11804,7 +12069,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
11804
12069
|
};
|
|
11805
12070
|
return loop(loopOptions);
|
|
11806
12071
|
} catch (e) {
|
|
11807
|
-
const mastraError = new
|
|
12072
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError(
|
|
11808
12073
|
{
|
|
11809
12074
|
id: "LLM_STREAM_TEXT_AI_SDK_EXECUTION_FAILED",
|
|
11810
12075
|
domain: "LLM" /* LLM */,
|
|
@@ -11824,7 +12089,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
11824
12089
|
}
|
|
11825
12090
|
}
|
|
11826
12091
|
};
|
|
11827
|
-
var PRIMITIVE_TYPES =
|
|
12092
|
+
var PRIMITIVE_TYPES = z8__default.default.enum(["agent", "workflow", "none", "tool"]);
|
|
11828
12093
|
|
|
11829
12094
|
// src/loop/network/index.ts
|
|
11830
12095
|
async function getRoutingAgent({ requestContext, agent }) {
|
|
@@ -11843,9 +12108,9 @@ async function getRoutingAgent({ requestContext, agent }) {
|
|
|
11843
12108
|
)}`;
|
|
11844
12109
|
}).join("\n");
|
|
11845
12110
|
const memoryTools = await memoryToUse?.listTools?.();
|
|
11846
|
-
const toolList = Object.entries({ ...toolsToUse, ...memoryTools }).map(([name,
|
|
11847
|
-
return ` - **${name}**: ${
|
|
11848
|
-
chunk4WQYXT2I_cjs.zodToJsonSchema(
|
|
12111
|
+
const toolList = Object.entries({ ...toolsToUse, ...memoryTools }).map(([name, tool2]) => {
|
|
12112
|
+
return ` - **${name}**: ${tool2.description}, input schema: ${JSON.stringify(
|
|
12113
|
+
chunk4WQYXT2I_cjs.zodToJsonSchema(tool2.inputSchema || z8__default.default.object({}))
|
|
11849
12114
|
)}`;
|
|
11850
12115
|
}).join("\n");
|
|
11851
12116
|
const instructions = `
|
|
@@ -11916,7 +12181,7 @@ async function prepareMemoryStep({
|
|
|
11916
12181
|
messages,
|
|
11917
12182
|
routingAgent,
|
|
11918
12183
|
requestContext,
|
|
11919
|
-
generateId:
|
|
12184
|
+
generateId: generateId2,
|
|
11920
12185
|
tracingContext,
|
|
11921
12186
|
memoryConfig
|
|
11922
12187
|
}) {
|
|
@@ -11938,7 +12203,7 @@ async function prepareMemoryStep({
|
|
|
11938
12203
|
memory.saveMessages({
|
|
11939
12204
|
messages: [
|
|
11940
12205
|
{
|
|
11941
|
-
id:
|
|
12206
|
+
id: generateId2(),
|
|
11942
12207
|
type: "text",
|
|
11943
12208
|
role: "user",
|
|
11944
12209
|
content: { parts: [{ type: "text", text: messages }], format: 2 },
|
|
@@ -11951,7 +12216,7 @@ async function prepareMemoryStep({
|
|
|
11951
12216
|
);
|
|
11952
12217
|
}
|
|
11953
12218
|
} else {
|
|
11954
|
-
const messageList = new
|
|
12219
|
+
const messageList = new chunkX6IBA7FP_cjs.MessageList({
|
|
11955
12220
|
threadId: thread?.id,
|
|
11956
12221
|
resourceId: thread?.resourceId
|
|
11957
12222
|
});
|
|
@@ -12005,43 +12270,43 @@ async function createNetworkLoop({
|
|
|
12005
12270
|
requestContext,
|
|
12006
12271
|
runId,
|
|
12007
12272
|
agent,
|
|
12008
|
-
generateId:
|
|
12273
|
+
generateId: generateId2,
|
|
12009
12274
|
routingAgentOptions
|
|
12010
12275
|
}) {
|
|
12011
12276
|
const routingStep = createStep({
|
|
12012
12277
|
id: "routing-agent-step",
|
|
12013
|
-
inputSchema:
|
|
12014
|
-
task:
|
|
12015
|
-
primitiveId:
|
|
12278
|
+
inputSchema: z8__default.default.object({
|
|
12279
|
+
task: z8__default.default.string(),
|
|
12280
|
+
primitiveId: z8__default.default.string(),
|
|
12016
12281
|
primitiveType: PRIMITIVE_TYPES,
|
|
12017
|
-
result:
|
|
12018
|
-
iteration:
|
|
12019
|
-
threadId:
|
|
12020
|
-
threadResourceId:
|
|
12021
|
-
isOneOff:
|
|
12022
|
-
verboseIntrospection:
|
|
12282
|
+
result: z8__default.default.string().optional(),
|
|
12283
|
+
iteration: z8__default.default.number(),
|
|
12284
|
+
threadId: z8__default.default.string().optional(),
|
|
12285
|
+
threadResourceId: z8__default.default.string().optional(),
|
|
12286
|
+
isOneOff: z8__default.default.boolean(),
|
|
12287
|
+
verboseIntrospection: z8__default.default.boolean()
|
|
12023
12288
|
}),
|
|
12024
|
-
outputSchema:
|
|
12025
|
-
task:
|
|
12026
|
-
primitiveId:
|
|
12289
|
+
outputSchema: z8__default.default.object({
|
|
12290
|
+
task: z8__default.default.string(),
|
|
12291
|
+
primitiveId: z8__default.default.string(),
|
|
12027
12292
|
primitiveType: PRIMITIVE_TYPES,
|
|
12028
|
-
prompt:
|
|
12029
|
-
result:
|
|
12030
|
-
isComplete:
|
|
12031
|
-
selectionReason:
|
|
12032
|
-
iteration:
|
|
12293
|
+
prompt: z8__default.default.string(),
|
|
12294
|
+
result: z8__default.default.string(),
|
|
12295
|
+
isComplete: z8__default.default.boolean().optional(),
|
|
12296
|
+
selectionReason: z8__default.default.string(),
|
|
12297
|
+
iteration: z8__default.default.number()
|
|
12033
12298
|
}),
|
|
12034
12299
|
execute: async ({ inputData, getInitData, writer }) => {
|
|
12035
12300
|
const initData = await getInitData();
|
|
12036
|
-
const completionSchema =
|
|
12037
|
-
isComplete:
|
|
12038
|
-
finalResult:
|
|
12039
|
-
completionReason:
|
|
12301
|
+
const completionSchema = z8__default.default.object({
|
|
12302
|
+
isComplete: z8__default.default.boolean(),
|
|
12303
|
+
finalResult: z8__default.default.string(),
|
|
12304
|
+
completionReason: z8__default.default.string()
|
|
12040
12305
|
});
|
|
12041
12306
|
const routingAgent = await getRoutingAgent({ requestContext, agent });
|
|
12042
12307
|
let completionResult;
|
|
12043
12308
|
const iterationCount = (inputData.iteration ?? -1) + 1;
|
|
12044
|
-
const stepId =
|
|
12309
|
+
const stepId = generateId2();
|
|
12045
12310
|
await writer.write({
|
|
12046
12311
|
type: "routing-agent-start",
|
|
12047
12312
|
payload: {
|
|
@@ -12177,7 +12442,7 @@ async function createNetworkLoop({
|
|
|
12177
12442
|
await memory?.saveMessages({
|
|
12178
12443
|
messages: [
|
|
12179
12444
|
{
|
|
12180
|
-
id:
|
|
12445
|
+
id: generateId2(),
|
|
12181
12446
|
type: "text",
|
|
12182
12447
|
role: "assistant",
|
|
12183
12448
|
content: {
|
|
@@ -12237,11 +12502,11 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12237
12502
|
];
|
|
12238
12503
|
const options = {
|
|
12239
12504
|
structuredOutput: {
|
|
12240
|
-
schema:
|
|
12241
|
-
primitiveId:
|
|
12505
|
+
schema: z8__default.default.object({
|
|
12506
|
+
primitiveId: z8__default.default.string().describe("The id of the primitive to be called"),
|
|
12242
12507
|
primitiveType: PRIMITIVE_TYPES.describe("The type of the primitive to be called"),
|
|
12243
|
-
prompt:
|
|
12244
|
-
selectionReason:
|
|
12508
|
+
prompt: z8__default.default.string().describe("The json string or text value to be sent to the primitive"),
|
|
12509
|
+
selectionReason: z8__default.default.string().describe("The reason you picked the primitive")
|
|
12245
12510
|
})
|
|
12246
12511
|
},
|
|
12247
12512
|
requestContext,
|
|
@@ -12285,29 +12550,29 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12285
12550
|
});
|
|
12286
12551
|
const agentStep = createStep({
|
|
12287
12552
|
id: "agent-execution-step",
|
|
12288
|
-
inputSchema:
|
|
12289
|
-
task:
|
|
12290
|
-
primitiveId:
|
|
12553
|
+
inputSchema: z8__default.default.object({
|
|
12554
|
+
task: z8__default.default.string(),
|
|
12555
|
+
primitiveId: z8__default.default.string(),
|
|
12291
12556
|
primitiveType: PRIMITIVE_TYPES,
|
|
12292
|
-
prompt:
|
|
12293
|
-
result:
|
|
12294
|
-
isComplete:
|
|
12295
|
-
selectionReason:
|
|
12296
|
-
iteration:
|
|
12557
|
+
prompt: z8__default.default.string(),
|
|
12558
|
+
result: z8__default.default.string(),
|
|
12559
|
+
isComplete: z8__default.default.boolean().optional(),
|
|
12560
|
+
selectionReason: z8__default.default.string(),
|
|
12561
|
+
iteration: z8__default.default.number()
|
|
12297
12562
|
}),
|
|
12298
|
-
outputSchema:
|
|
12299
|
-
task:
|
|
12300
|
-
primitiveId:
|
|
12563
|
+
outputSchema: z8__default.default.object({
|
|
12564
|
+
task: z8__default.default.string(),
|
|
12565
|
+
primitiveId: z8__default.default.string(),
|
|
12301
12566
|
primitiveType: PRIMITIVE_TYPES,
|
|
12302
|
-
result:
|
|
12303
|
-
isComplete:
|
|
12304
|
-
iteration:
|
|
12567
|
+
result: z8__default.default.string(),
|
|
12568
|
+
isComplete: z8__default.default.boolean().optional(),
|
|
12569
|
+
iteration: z8__default.default.number()
|
|
12305
12570
|
}),
|
|
12306
12571
|
execute: async ({ inputData, writer, getInitData }) => {
|
|
12307
12572
|
const agentsMap = await agent.listAgents({ requestContext });
|
|
12308
12573
|
const agentForStep = agentsMap[inputData.primitiveId];
|
|
12309
12574
|
if (!agentForStep) {
|
|
12310
|
-
const mastraError = new
|
|
12575
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
12311
12576
|
id: "AGENT_NETWORK_AGENT_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
12312
12577
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
12313
12578
|
category: "USER" /* USER */,
|
|
@@ -12316,7 +12581,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12316
12581
|
throw mastraError;
|
|
12317
12582
|
}
|
|
12318
12583
|
const agentId = agentForStep.id;
|
|
12319
|
-
const stepId =
|
|
12584
|
+
const stepId = generateId2();
|
|
12320
12585
|
await writer.write({
|
|
12321
12586
|
type: "agent-execution-start",
|
|
12322
12587
|
payload: {
|
|
@@ -12357,7 +12622,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12357
12622
|
await memory?.saveMessages({
|
|
12358
12623
|
messages: [
|
|
12359
12624
|
{
|
|
12360
|
-
id:
|
|
12625
|
+
id: generateId2(),
|
|
12361
12626
|
type: "text",
|
|
12362
12627
|
role: "assistant",
|
|
12363
12628
|
content: {
|
|
@@ -12370,7 +12635,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12370
12635
|
primitiveType: inputData.primitiveType,
|
|
12371
12636
|
primitiveId: inputData.primitiveId,
|
|
12372
12637
|
input: inputData.prompt,
|
|
12373
|
-
finalResult: { text: await result.text,
|
|
12638
|
+
finalResult: { text: await result.text, messages }
|
|
12374
12639
|
})
|
|
12375
12640
|
}
|
|
12376
12641
|
],
|
|
@@ -12411,30 +12676,30 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12411
12676
|
});
|
|
12412
12677
|
const workflowStep = createStep({
|
|
12413
12678
|
id: "workflow-execution-step",
|
|
12414
|
-
inputSchema:
|
|
12415
|
-
task:
|
|
12416
|
-
primitiveId:
|
|
12679
|
+
inputSchema: z8__default.default.object({
|
|
12680
|
+
task: z8__default.default.string(),
|
|
12681
|
+
primitiveId: z8__default.default.string(),
|
|
12417
12682
|
primitiveType: PRIMITIVE_TYPES,
|
|
12418
|
-
prompt:
|
|
12419
|
-
result:
|
|
12420
|
-
isComplete:
|
|
12421
|
-
selectionReason:
|
|
12422
|
-
iteration:
|
|
12683
|
+
prompt: z8__default.default.string(),
|
|
12684
|
+
result: z8__default.default.string(),
|
|
12685
|
+
isComplete: z8__default.default.boolean().optional(),
|
|
12686
|
+
selectionReason: z8__default.default.string(),
|
|
12687
|
+
iteration: z8__default.default.number()
|
|
12423
12688
|
}),
|
|
12424
|
-
outputSchema:
|
|
12425
|
-
task:
|
|
12426
|
-
primitiveId:
|
|
12689
|
+
outputSchema: z8__default.default.object({
|
|
12690
|
+
task: z8__default.default.string(),
|
|
12691
|
+
primitiveId: z8__default.default.string(),
|
|
12427
12692
|
primitiveType: PRIMITIVE_TYPES,
|
|
12428
|
-
result:
|
|
12429
|
-
isComplete:
|
|
12430
|
-
iteration:
|
|
12693
|
+
result: z8__default.default.string(),
|
|
12694
|
+
isComplete: z8__default.default.boolean().optional(),
|
|
12695
|
+
iteration: z8__default.default.number()
|
|
12431
12696
|
}),
|
|
12432
12697
|
execute: async ({ inputData, writer, getInitData }) => {
|
|
12433
12698
|
const workflowsMap = await agent.listWorkflows({ requestContext });
|
|
12434
12699
|
const workflowId = inputData.primitiveId;
|
|
12435
12700
|
const wf = workflowsMap[workflowId];
|
|
12436
12701
|
if (!wf) {
|
|
12437
|
-
const mastraError = new
|
|
12702
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
12438
12703
|
id: "AGENT_NETWORK_WORKFLOW_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
12439
12704
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
12440
12705
|
category: "USER" /* USER */,
|
|
@@ -12446,7 +12711,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12446
12711
|
try {
|
|
12447
12712
|
input = JSON.parse(inputData.prompt);
|
|
12448
12713
|
} catch (e) {
|
|
12449
|
-
const mastraError = new
|
|
12714
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError(
|
|
12450
12715
|
{
|
|
12451
12716
|
id: "WORKFLOW_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
12452
12717
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
@@ -12457,7 +12722,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12457
12722
|
);
|
|
12458
12723
|
throw mastraError;
|
|
12459
12724
|
}
|
|
12460
|
-
const stepId =
|
|
12725
|
+
const stepId = generateId2();
|
|
12461
12726
|
const run = await wf.createRun({ runId });
|
|
12462
12727
|
const toolData = {
|
|
12463
12728
|
workflowId: wf.id,
|
|
@@ -12510,7 +12775,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12510
12775
|
await memory?.saveMessages({
|
|
12511
12776
|
messages: [
|
|
12512
12777
|
{
|
|
12513
|
-
id:
|
|
12778
|
+
id: generateId2(),
|
|
12514
12779
|
type: "text",
|
|
12515
12780
|
role: "assistant",
|
|
12516
12781
|
content: { parts: [{ type: "text", text: finalResult }], format: 2 },
|
|
@@ -12545,23 +12810,23 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12545
12810
|
});
|
|
12546
12811
|
const toolStep = createStep({
|
|
12547
12812
|
id: "tool-execution-step",
|
|
12548
|
-
inputSchema:
|
|
12549
|
-
task:
|
|
12550
|
-
primitiveId:
|
|
12813
|
+
inputSchema: z8__default.default.object({
|
|
12814
|
+
task: z8__default.default.string(),
|
|
12815
|
+
primitiveId: z8__default.default.string(),
|
|
12551
12816
|
primitiveType: PRIMITIVE_TYPES,
|
|
12552
|
-
prompt:
|
|
12553
|
-
result:
|
|
12554
|
-
isComplete:
|
|
12555
|
-
selectionReason:
|
|
12556
|
-
iteration:
|
|
12817
|
+
prompt: z8__default.default.string(),
|
|
12818
|
+
result: z8__default.default.string(),
|
|
12819
|
+
isComplete: z8__default.default.boolean().optional(),
|
|
12820
|
+
selectionReason: z8__default.default.string(),
|
|
12821
|
+
iteration: z8__default.default.number()
|
|
12557
12822
|
}),
|
|
12558
|
-
outputSchema:
|
|
12559
|
-
task:
|
|
12560
|
-
primitiveId:
|
|
12823
|
+
outputSchema: z8__default.default.object({
|
|
12824
|
+
task: z8__default.default.string(),
|
|
12825
|
+
primitiveId: z8__default.default.string(),
|
|
12561
12826
|
primitiveType: PRIMITIVE_TYPES,
|
|
12562
|
-
result:
|
|
12563
|
-
isComplete:
|
|
12564
|
-
iteration:
|
|
12827
|
+
result: z8__default.default.string(),
|
|
12828
|
+
isComplete: z8__default.default.boolean().optional(),
|
|
12829
|
+
iteration: z8__default.default.number()
|
|
12565
12830
|
}),
|
|
12566
12831
|
execute: async ({ inputData, getInitData, writer }) => {
|
|
12567
12832
|
const initData = await getInitData();
|
|
@@ -12569,9 +12834,9 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12569
12834
|
const memory = await agent.getMemory({ requestContext });
|
|
12570
12835
|
const memoryTools = await memory?.listTools?.();
|
|
12571
12836
|
const toolsMap = { ...agentTools, ...memoryTools };
|
|
12572
|
-
let
|
|
12573
|
-
if (!
|
|
12574
|
-
const mastraError = new
|
|
12837
|
+
let tool2 = toolsMap[inputData.primitiveId];
|
|
12838
|
+
if (!tool2) {
|
|
12839
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
12575
12840
|
id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
12576
12841
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
12577
12842
|
category: "USER" /* USER */,
|
|
@@ -12579,8 +12844,8 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12579
12844
|
});
|
|
12580
12845
|
throw mastraError;
|
|
12581
12846
|
}
|
|
12582
|
-
if (!
|
|
12583
|
-
const mastraError = new
|
|
12847
|
+
if (!tool2.execute) {
|
|
12848
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
12584
12849
|
id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
12585
12850
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
12586
12851
|
category: "USER" /* USER */,
|
|
@@ -12588,12 +12853,12 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12588
12853
|
});
|
|
12589
12854
|
throw mastraError;
|
|
12590
12855
|
}
|
|
12591
|
-
const toolId =
|
|
12856
|
+
const toolId = tool2.id;
|
|
12592
12857
|
let inputDataToUse;
|
|
12593
12858
|
try {
|
|
12594
12859
|
inputDataToUse = JSON.parse(inputData.prompt);
|
|
12595
12860
|
} catch (e) {
|
|
12596
|
-
const mastraError = new
|
|
12861
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError(
|
|
12597
12862
|
{
|
|
12598
12863
|
id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
12599
12864
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
@@ -12604,7 +12869,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12604
12869
|
);
|
|
12605
12870
|
throw mastraError;
|
|
12606
12871
|
}
|
|
12607
|
-
const toolCallId =
|
|
12872
|
+
const toolCallId = generateId2();
|
|
12608
12873
|
await writer?.write({
|
|
12609
12874
|
type: "tool-execution-start",
|
|
12610
12875
|
payload: {
|
|
@@ -12619,7 +12884,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12619
12884
|
from: "NETWORK" /* NETWORK */,
|
|
12620
12885
|
runId
|
|
12621
12886
|
});
|
|
12622
|
-
const finalResult = await
|
|
12887
|
+
const finalResult = await tool2.execute(
|
|
12623
12888
|
inputDataToUse,
|
|
12624
12889
|
{
|
|
12625
12890
|
requestContext,
|
|
@@ -12641,7 +12906,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12641
12906
|
await memory?.saveMessages({
|
|
12642
12907
|
messages: [
|
|
12643
12908
|
{
|
|
12644
|
-
id:
|
|
12909
|
+
id: generateId2(),
|
|
12645
12910
|
type: "text",
|
|
12646
12911
|
role: "assistant",
|
|
12647
12912
|
content: {
|
|
@@ -12687,21 +12952,21 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12687
12952
|
});
|
|
12688
12953
|
const finishStep = createStep({
|
|
12689
12954
|
id: "finish-step",
|
|
12690
|
-
inputSchema:
|
|
12691
|
-
task:
|
|
12692
|
-
primitiveId:
|
|
12955
|
+
inputSchema: z8__default.default.object({
|
|
12956
|
+
task: z8__default.default.string(),
|
|
12957
|
+
primitiveId: z8__default.default.string(),
|
|
12693
12958
|
primitiveType: PRIMITIVE_TYPES,
|
|
12694
|
-
prompt:
|
|
12695
|
-
result:
|
|
12696
|
-
isComplete:
|
|
12697
|
-
selectionReason:
|
|
12698
|
-
iteration:
|
|
12959
|
+
prompt: z8__default.default.string(),
|
|
12960
|
+
result: z8__default.default.string(),
|
|
12961
|
+
isComplete: z8__default.default.boolean().optional(),
|
|
12962
|
+
selectionReason: z8__default.default.string(),
|
|
12963
|
+
iteration: z8__default.default.number()
|
|
12699
12964
|
}),
|
|
12700
|
-
outputSchema:
|
|
12701
|
-
task:
|
|
12702
|
-
result:
|
|
12703
|
-
isComplete:
|
|
12704
|
-
iteration:
|
|
12965
|
+
outputSchema: z8__default.default.object({
|
|
12966
|
+
task: z8__default.default.string(),
|
|
12967
|
+
result: z8__default.default.string(),
|
|
12968
|
+
isComplete: z8__default.default.boolean(),
|
|
12969
|
+
iteration: z8__default.default.number()
|
|
12705
12970
|
}),
|
|
12706
12971
|
execute: async ({ inputData, writer }) => {
|
|
12707
12972
|
let endResult = inputData.result;
|
|
@@ -12726,29 +12991,29 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12726
12991
|
});
|
|
12727
12992
|
const networkWorkflow = createWorkflow({
|
|
12728
12993
|
id: "Agent-Network-Outer-Workflow",
|
|
12729
|
-
inputSchema:
|
|
12730
|
-
task:
|
|
12731
|
-
primitiveId:
|
|
12994
|
+
inputSchema: z8__default.default.object({
|
|
12995
|
+
task: z8__default.default.string(),
|
|
12996
|
+
primitiveId: z8__default.default.string(),
|
|
12732
12997
|
primitiveType: PRIMITIVE_TYPES,
|
|
12733
|
-
result:
|
|
12734
|
-
iteration:
|
|
12735
|
-
threadId:
|
|
12736
|
-
threadResourceId:
|
|
12737
|
-
isOneOff:
|
|
12738
|
-
verboseIntrospection:
|
|
12998
|
+
result: z8__default.default.string().optional(),
|
|
12999
|
+
iteration: z8__default.default.number(),
|
|
13000
|
+
threadId: z8__default.default.string().optional(),
|
|
13001
|
+
threadResourceId: z8__default.default.string().optional(),
|
|
13002
|
+
isOneOff: z8__default.default.boolean(),
|
|
13003
|
+
verboseIntrospection: z8__default.default.boolean()
|
|
12739
13004
|
}),
|
|
12740
|
-
outputSchema:
|
|
12741
|
-
task:
|
|
12742
|
-
primitiveId:
|
|
13005
|
+
outputSchema: z8__default.default.object({
|
|
13006
|
+
task: z8__default.default.string(),
|
|
13007
|
+
primitiveId: z8__default.default.string(),
|
|
12743
13008
|
primitiveType: PRIMITIVE_TYPES,
|
|
12744
|
-
prompt:
|
|
12745
|
-
result:
|
|
12746
|
-
isComplete:
|
|
12747
|
-
completionReason:
|
|
12748
|
-
iteration:
|
|
12749
|
-
threadId:
|
|
12750
|
-
threadResourceId:
|
|
12751
|
-
isOneOff:
|
|
13009
|
+
prompt: z8__default.default.string(),
|
|
13010
|
+
result: z8__default.default.string(),
|
|
13011
|
+
isComplete: z8__default.default.boolean().optional(),
|
|
13012
|
+
completionReason: z8__default.default.string().optional(),
|
|
13013
|
+
iteration: z8__default.default.number(),
|
|
13014
|
+
threadId: z8__default.default.string().optional(),
|
|
13015
|
+
threadResourceId: z8__default.default.string().optional(),
|
|
13016
|
+
isOneOff: z8__default.default.boolean()
|
|
12752
13017
|
}),
|
|
12753
13018
|
options: {
|
|
12754
13019
|
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
|
|
@@ -12810,7 +13075,7 @@ async function networkLoop({
|
|
|
12810
13075
|
runId,
|
|
12811
13076
|
routingAgent,
|
|
12812
13077
|
routingAgentOptions,
|
|
12813
|
-
generateId:
|
|
13078
|
+
generateId: generateId2,
|
|
12814
13079
|
maxIterations,
|
|
12815
13080
|
threadId,
|
|
12816
13081
|
resourceId,
|
|
@@ -12818,7 +13083,7 @@ async function networkLoop({
|
|
|
12818
13083
|
}) {
|
|
12819
13084
|
const memoryToUse = await routingAgent.getMemory({ requestContext });
|
|
12820
13085
|
if (!memoryToUse) {
|
|
12821
|
-
throw new
|
|
13086
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
12822
13087
|
id: "AGENT_NETWORK_MEMORY_REQUIRED",
|
|
12823
13088
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
12824
13089
|
category: "USER" /* USER */,
|
|
@@ -12835,7 +13100,7 @@ async function networkLoop({
|
|
|
12835
13100
|
runId,
|
|
12836
13101
|
agent: routingAgent,
|
|
12837
13102
|
routingAgentOptions: routingAgentOptionsWithoutMemory,
|
|
12838
|
-
generateId:
|
|
13103
|
+
generateId: generateId2
|
|
12839
13104
|
});
|
|
12840
13105
|
const finalStep = createStep({
|
|
12841
13106
|
id: "final-step",
|
|
@@ -12857,26 +13122,26 @@ async function networkLoop({
|
|
|
12857
13122
|
});
|
|
12858
13123
|
const mainWorkflow = createWorkflow({
|
|
12859
13124
|
id: "agent-loop-main-workflow",
|
|
12860
|
-
inputSchema:
|
|
12861
|
-
iteration:
|
|
12862
|
-
task:
|
|
12863
|
-
primitiveId:
|
|
13125
|
+
inputSchema: z8__default.default.object({
|
|
13126
|
+
iteration: z8__default.default.number(),
|
|
13127
|
+
task: z8__default.default.string(),
|
|
13128
|
+
primitiveId: z8__default.default.string(),
|
|
12864
13129
|
primitiveType: PRIMITIVE_TYPES,
|
|
12865
|
-
result:
|
|
12866
|
-
threadId:
|
|
12867
|
-
threadResourceId:
|
|
12868
|
-
isOneOff:
|
|
12869
|
-
verboseIntrospection:
|
|
13130
|
+
result: z8__default.default.string().optional(),
|
|
13131
|
+
threadId: z8__default.default.string().optional(),
|
|
13132
|
+
threadResourceId: z8__default.default.string().optional(),
|
|
13133
|
+
isOneOff: z8__default.default.boolean(),
|
|
13134
|
+
verboseIntrospection: z8__default.default.boolean()
|
|
12870
13135
|
}),
|
|
12871
|
-
outputSchema:
|
|
12872
|
-
task:
|
|
12873
|
-
primitiveId:
|
|
13136
|
+
outputSchema: z8__default.default.object({
|
|
13137
|
+
task: z8__default.default.string(),
|
|
13138
|
+
primitiveId: z8__default.default.string(),
|
|
12874
13139
|
primitiveType: PRIMITIVE_TYPES,
|
|
12875
|
-
prompt:
|
|
12876
|
-
result:
|
|
12877
|
-
isComplete:
|
|
12878
|
-
completionReason:
|
|
12879
|
-
iteration:
|
|
13140
|
+
prompt: z8__default.default.string(),
|
|
13141
|
+
result: z8__default.default.string(),
|
|
13142
|
+
isComplete: z8__default.default.boolean().optional(),
|
|
13143
|
+
completionReason: z8__default.default.string().optional(),
|
|
13144
|
+
iteration: z8__default.default.number()
|
|
12880
13145
|
}),
|
|
12881
13146
|
options: {
|
|
12882
13147
|
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
|
|
@@ -12894,7 +13159,7 @@ async function networkLoop({
|
|
|
12894
13159
|
resourceId: resourceId || networkName,
|
|
12895
13160
|
messages,
|
|
12896
13161
|
routingAgent,
|
|
12897
|
-
generateId:
|
|
13162
|
+
generateId: generateId2,
|
|
12898
13163
|
tracingContext: routingAgentOptions?.tracingContext,
|
|
12899
13164
|
memoryConfig: routingAgentMemoryOptions?.options
|
|
12900
13165
|
});
|
|
@@ -12920,12 +13185,12 @@ async function networkLoop({
|
|
|
12920
13185
|
}
|
|
12921
13186
|
|
|
12922
13187
|
// src/agent/agent-legacy.ts
|
|
12923
|
-
var import_fast_deep_equal =
|
|
13188
|
+
var import_fast_deep_equal = chunk6SZKM6EC_cjs.__toESM(require_fast_deep_equal(), 1);
|
|
12924
13189
|
|
|
12925
13190
|
// src/agent/utils.ts
|
|
12926
13191
|
async function tryGenerateWithJsonFallback(agent, prompt, options) {
|
|
12927
13192
|
if (!options.structuredOutput?.schema) {
|
|
12928
|
-
throw new
|
|
13193
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
12929
13194
|
id: "STRUCTURED_OUTPUT_OPTIONS_REQUIRED",
|
|
12930
13195
|
domain: "AGENT" /* AGENT */,
|
|
12931
13196
|
category: "USER" /* USER */,
|
|
@@ -12944,7 +13209,7 @@ async function tryGenerateWithJsonFallback(agent, prompt, options) {
|
|
|
12944
13209
|
}
|
|
12945
13210
|
async function tryStreamWithJsonFallback(agent, prompt, options) {
|
|
12946
13211
|
if (!options.structuredOutput?.schema) {
|
|
12947
|
-
throw new
|
|
13212
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
12948
13213
|
id: "STRUCTURED_OUTPUT_OPTIONS_REQUIRED",
|
|
12949
13214
|
domain: "AGENT" /* AGENT */,
|
|
12950
13215
|
category: "USER" /* USER */,
|
|
@@ -12955,7 +13220,7 @@ async function tryStreamWithJsonFallback(agent, prompt, options) {
|
|
|
12955
13220
|
const result = await agent.stream(prompt, options);
|
|
12956
13221
|
const object = await result.object;
|
|
12957
13222
|
if (!object) {
|
|
12958
|
-
throw new
|
|
13223
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
12959
13224
|
id: "STRUCTURED_OUTPUT_OBJECT_UNDEFINED",
|
|
12960
13225
|
domain: "AGENT" /* AGENT */,
|
|
12961
13226
|
category: "USER" /* USER */,
|
|
@@ -13066,7 +13331,7 @@ var AgentLegacyHandler = class {
|
|
|
13066
13331
|
methodType: methodType === "generate" ? "generateLegacy" : "streamLegacy",
|
|
13067
13332
|
memoryConfig
|
|
13068
13333
|
});
|
|
13069
|
-
let messageList = new
|
|
13334
|
+
let messageList = new chunkX6IBA7FP_cjs.MessageList({
|
|
13070
13335
|
threadId,
|
|
13071
13336
|
resourceId,
|
|
13072
13337
|
generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
|
|
@@ -13091,7 +13356,7 @@ var AgentLegacyHandler = class {
|
|
|
13091
13356
|
};
|
|
13092
13357
|
}
|
|
13093
13358
|
if (!threadId || !resourceId) {
|
|
13094
|
-
const mastraError = new
|
|
13359
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
13095
13360
|
id: "AGENT_MEMORY_MISSING_RESOURCE_ID",
|
|
13096
13361
|
domain: "AGENT" /* AGENT */,
|
|
13097
13362
|
category: "USER" /* USER */,
|
|
@@ -13197,7 +13462,7 @@ var AgentLegacyHandler = class {
|
|
|
13197
13462
|
result: resToLog,
|
|
13198
13463
|
threadId
|
|
13199
13464
|
});
|
|
13200
|
-
const messageListResponses = new
|
|
13465
|
+
const messageListResponses = new chunkX6IBA7FP_cjs.MessageList({
|
|
13201
13466
|
threadId,
|
|
13202
13467
|
resourceId,
|
|
13203
13468
|
generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
|
|
@@ -13267,11 +13532,11 @@ var AgentLegacyHandler = class {
|
|
|
13267
13532
|
await Promise.all(promises);
|
|
13268
13533
|
}
|
|
13269
13534
|
} catch (e) {
|
|
13270
|
-
if (e instanceof
|
|
13535
|
+
if (e instanceof chunkHWMMIRIF_cjs.MastraError) {
|
|
13271
13536
|
agentSpan?.error({ error: e });
|
|
13272
13537
|
throw e;
|
|
13273
13538
|
}
|
|
13274
|
-
const mastraError = new
|
|
13539
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError(
|
|
13275
13540
|
{
|
|
13276
13541
|
id: "AGENT_MEMORY_PERSIST_RESPONSE_MESSAGES_FAILED",
|
|
13277
13542
|
domain: "AGENT" /* AGENT */,
|
|
@@ -13473,7 +13738,7 @@ var AgentLegacyHandler = class {
|
|
|
13473
13738
|
*/
|
|
13474
13739
|
async generateLegacy(messages, generateOptions = {}) {
|
|
13475
13740
|
if ("structuredOutput" in generateOptions && generateOptions.structuredOutput) {
|
|
13476
|
-
throw new
|
|
13741
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
13477
13742
|
id: "AGENT_GENERATE_LEGACY_STRUCTURED_OUTPUT_NOT_SUPPORTED",
|
|
13478
13743
|
domain: "AGENT" /* AGENT */,
|
|
13479
13744
|
category: "USER" /* USER */,
|
|
@@ -13495,7 +13760,7 @@ var AgentLegacyHandler = class {
|
|
|
13495
13760
|
this.capabilities.logger.error("V2 models are not supported for generateLegacy. Please use generate instead.", {
|
|
13496
13761
|
modelId: llm.getModel().modelId
|
|
13497
13762
|
});
|
|
13498
|
-
throw new
|
|
13763
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
13499
13764
|
id: "AGENT_GENERATE_V2_MODEL_NOT_SUPPORTED",
|
|
13500
13765
|
domain: "AGENT" /* AGENT */,
|
|
13501
13766
|
category: "USER" /* USER */,
|
|
@@ -13715,7 +13980,7 @@ var AgentLegacyHandler = class {
|
|
|
13715
13980
|
this.capabilities.logger.error("V2 models are not supported for streamLegacy. Please use stream instead.", {
|
|
13716
13981
|
modelId: llm.getModel().modelId
|
|
13717
13982
|
});
|
|
13718
|
-
throw new
|
|
13983
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
13719
13984
|
id: "AGENT_STREAM_V2_MODEL_NOT_SUPPORTED",
|
|
13720
13985
|
domain: "AGENT" /* AGENT */,
|
|
13721
13986
|
category: "USER" /* USER */,
|
|
@@ -13999,7 +14264,7 @@ function getModelMethodFromAgentMethod(methodType) {
|
|
|
13999
14264
|
} else if (methodType === "stream" || methodType === "streamLegacy") {
|
|
14000
14265
|
return "stream";
|
|
14001
14266
|
} else {
|
|
14002
|
-
throw new
|
|
14267
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
14003
14268
|
id: "INVALID_METHOD_TYPE",
|
|
14004
14269
|
domain: "AGENT" /* AGENT */,
|
|
14005
14270
|
category: "USER" /* USER */
|
|
@@ -14161,42 +14426,42 @@ function createMapResultsStep({
|
|
|
14161
14426
|
}
|
|
14162
14427
|
|
|
14163
14428
|
// src/agent/workflows/prepare-stream/prepare-memory-step.ts
|
|
14164
|
-
var import_fast_deep_equal2 =
|
|
14165
|
-
var coreToolSchema =
|
|
14166
|
-
id:
|
|
14167
|
-
description:
|
|
14168
|
-
parameters:
|
|
14169
|
-
|
|
14429
|
+
var import_fast_deep_equal2 = chunk6SZKM6EC_cjs.__toESM(require_fast_deep_equal(), 1);
|
|
14430
|
+
var coreToolSchema = z8.z.object({
|
|
14431
|
+
id: z8.z.string().optional(),
|
|
14432
|
+
description: z8.z.string().optional(),
|
|
14433
|
+
parameters: z8.z.union([
|
|
14434
|
+
z8.z.record(z8.z.string(), z8.z.any()),
|
|
14170
14435
|
// JSON Schema as object
|
|
14171
|
-
|
|
14436
|
+
z8.z.any()
|
|
14172
14437
|
// Zod schema or other schema types - validated at tool execution
|
|
14173
14438
|
]),
|
|
14174
|
-
outputSchema:
|
|
14175
|
-
execute:
|
|
14176
|
-
type:
|
|
14177
|
-
args:
|
|
14439
|
+
outputSchema: z8.z.union([z8.z.record(z8.z.string(), z8.z.any()), z8.z.any()]).optional(),
|
|
14440
|
+
execute: z8.z.function(z8.z.tuple([z8.z.any(), z8.z.any()]), z8.z.promise(z8.z.any())).optional(),
|
|
14441
|
+
type: z8.z.union([z8.z.literal("function"), z8.z.literal("provider-defined"), z8.z.undefined()]).optional(),
|
|
14442
|
+
args: z8.z.record(z8.z.string(), z8.z.any()).optional()
|
|
14178
14443
|
});
|
|
14179
|
-
var storageThreadSchema =
|
|
14180
|
-
id:
|
|
14181
|
-
title:
|
|
14182
|
-
resourceId:
|
|
14183
|
-
createdAt:
|
|
14184
|
-
updatedAt:
|
|
14185
|
-
metadata:
|
|
14444
|
+
var storageThreadSchema = z8.z.object({
|
|
14445
|
+
id: z8.z.string(),
|
|
14446
|
+
title: z8.z.string().optional(),
|
|
14447
|
+
resourceId: z8.z.string(),
|
|
14448
|
+
createdAt: z8.z.date(),
|
|
14449
|
+
updatedAt: z8.z.date(),
|
|
14450
|
+
metadata: z8.z.record(z8.z.string(), z8.z.any()).optional()
|
|
14186
14451
|
});
|
|
14187
|
-
var prepareToolsStepOutputSchema =
|
|
14188
|
-
convertedTools:
|
|
14452
|
+
var prepareToolsStepOutputSchema = z8.z.object({
|
|
14453
|
+
convertedTools: z8.z.record(z8.z.string(), coreToolSchema)
|
|
14189
14454
|
});
|
|
14190
|
-
var prepareMemoryStepOutputSchema =
|
|
14191
|
-
threadExists:
|
|
14455
|
+
var prepareMemoryStepOutputSchema = z8.z.object({
|
|
14456
|
+
threadExists: z8.z.boolean(),
|
|
14192
14457
|
thread: storageThreadSchema.optional(),
|
|
14193
|
-
messageList:
|
|
14458
|
+
messageList: z8.z.instanceof(chunkX6IBA7FP_cjs.MessageList),
|
|
14194
14459
|
/** Tripwire data when input processor triggered abort */
|
|
14195
|
-
tripwire:
|
|
14196
|
-
reason:
|
|
14197
|
-
retry:
|
|
14198
|
-
metadata:
|
|
14199
|
-
processorId:
|
|
14460
|
+
tripwire: z8.z.object({
|
|
14461
|
+
reason: z8.z.string(),
|
|
14462
|
+
retry: z8.z.boolean().optional(),
|
|
14463
|
+
metadata: z8.z.unknown().optional(),
|
|
14464
|
+
processorId: z8.z.string().optional()
|
|
14200
14465
|
}).optional()
|
|
14201
14466
|
});
|
|
14202
14467
|
|
|
@@ -14224,11 +14489,11 @@ function createPrepareMemoryStep({
|
|
|
14224
14489
|
}) {
|
|
14225
14490
|
return createStep({
|
|
14226
14491
|
id: "prepare-memory-step",
|
|
14227
|
-
inputSchema:
|
|
14492
|
+
inputSchema: z8.z.object({}),
|
|
14228
14493
|
outputSchema: prepareMemoryStepOutputSchema,
|
|
14229
14494
|
execute: async ({ tracingContext }) => {
|
|
14230
14495
|
const thread = threadFromArgs;
|
|
14231
|
-
const messageList = new
|
|
14496
|
+
const messageList = new chunkX6IBA7FP_cjs.MessageList({
|
|
14232
14497
|
threadId: thread?.id,
|
|
14233
14498
|
resourceId,
|
|
14234
14499
|
generateMessageId: capabilities.generateMessageId,
|
|
@@ -14254,7 +14519,7 @@ function createPrepareMemoryStep({
|
|
|
14254
14519
|
};
|
|
14255
14520
|
}
|
|
14256
14521
|
if (!thread?.id || !resourceId) {
|
|
14257
|
-
const mastraError = new
|
|
14522
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
14258
14523
|
id: "AGENT_MEMORY_MISSING_RESOURCE_ID",
|
|
14259
14524
|
domain: "AGENT" /* AGENT */,
|
|
14260
14525
|
category: "USER" /* USER */,
|
|
@@ -14334,7 +14599,7 @@ function createPrepareToolsStep({
|
|
|
14334
14599
|
}) {
|
|
14335
14600
|
return createStep({
|
|
14336
14601
|
id: "prepare-tools-step",
|
|
14337
|
-
inputSchema:
|
|
14602
|
+
inputSchema: z8.z.object({}),
|
|
14338
14603
|
outputSchema: prepareToolsStepOutputSchema,
|
|
14339
14604
|
execute: async () => {
|
|
14340
14605
|
const toolEnhancements = [
|
|
@@ -14359,7 +14624,8 @@ function createPrepareToolsStep({
|
|
|
14359
14624
|
tracingContext: { currentSpan: agentSpan },
|
|
14360
14625
|
outputWriter: options.outputWriter,
|
|
14361
14626
|
methodType,
|
|
14362
|
-
memoryConfig: options.memory?.options
|
|
14627
|
+
memoryConfig: options.memory?.options,
|
|
14628
|
+
autoResumeSuspendedTools: options.autoResumeSuspendedTools
|
|
14363
14629
|
});
|
|
14364
14630
|
return {
|
|
14365
14631
|
convertedTools
|
|
@@ -14372,6 +14638,7 @@ function createStreamStep({
|
|
|
14372
14638
|
runId,
|
|
14373
14639
|
returnScorerData,
|
|
14374
14640
|
requireToolApproval,
|
|
14641
|
+
toolCallConcurrency,
|
|
14375
14642
|
resumeContext,
|
|
14376
14643
|
agentId,
|
|
14377
14644
|
agentName,
|
|
@@ -14380,15 +14647,16 @@ function createStreamStep({
|
|
|
14380
14647
|
saveQueueManager,
|
|
14381
14648
|
memoryConfig,
|
|
14382
14649
|
memory,
|
|
14383
|
-
resourceId
|
|
14650
|
+
resourceId,
|
|
14651
|
+
autoResumeSuspendedTools
|
|
14384
14652
|
}) {
|
|
14385
14653
|
return createStep({
|
|
14386
14654
|
id: "stream-text-step",
|
|
14387
|
-
inputSchema:
|
|
14655
|
+
inputSchema: z8.z.any(),
|
|
14388
14656
|
// tried to type this in various ways but it's too complex
|
|
14389
|
-
outputSchema:
|
|
14390
|
-
|
|
14391
|
-
|
|
14657
|
+
outputSchema: z8.z.union([
|
|
14658
|
+
z8.z.instanceof(MastraModelOutput),
|
|
14659
|
+
z8.z.instanceof(AISDKV5OutputStream)
|
|
14392
14660
|
]),
|
|
14393
14661
|
execute: async ({ inputData, tracingContext }) => {
|
|
14394
14662
|
const validatedInputData = inputData;
|
|
@@ -14405,6 +14673,7 @@ function createStreamStep({
|
|
|
14405
14673
|
returnScorerData,
|
|
14406
14674
|
tracingContext,
|
|
14407
14675
|
requireToolApproval,
|
|
14676
|
+
toolCallConcurrency,
|
|
14408
14677
|
resumeContext,
|
|
14409
14678
|
_internal: {
|
|
14410
14679
|
generateId: capabilities.generateMessageId,
|
|
@@ -14417,7 +14686,8 @@ function createStreamStep({
|
|
|
14417
14686
|
agentId,
|
|
14418
14687
|
agentName,
|
|
14419
14688
|
toolCallId,
|
|
14420
|
-
methodType: modelMethodType
|
|
14689
|
+
methodType: modelMethodType,
|
|
14690
|
+
autoResumeSuspendedTools
|
|
14421
14691
|
});
|
|
14422
14692
|
return streamResult;
|
|
14423
14693
|
}
|
|
@@ -14440,6 +14710,7 @@ function createPrepareStreamWorkflow({
|
|
|
14440
14710
|
returnScorerData,
|
|
14441
14711
|
saveQueueManager,
|
|
14442
14712
|
requireToolApproval,
|
|
14713
|
+
toolCallConcurrency,
|
|
14443
14714
|
resumeContext,
|
|
14444
14715
|
agentId,
|
|
14445
14716
|
agentName,
|
|
@@ -14472,6 +14743,7 @@ function createPrepareStreamWorkflow({
|
|
|
14472
14743
|
runId,
|
|
14473
14744
|
returnScorerData,
|
|
14474
14745
|
requireToolApproval,
|
|
14746
|
+
toolCallConcurrency,
|
|
14475
14747
|
resumeContext,
|
|
14476
14748
|
agentId,
|
|
14477
14749
|
agentName,
|
|
@@ -14480,7 +14752,8 @@ function createPrepareStreamWorkflow({
|
|
|
14480
14752
|
saveQueueManager,
|
|
14481
14753
|
memoryConfig,
|
|
14482
14754
|
memory,
|
|
14483
|
-
resourceId
|
|
14755
|
+
resourceId,
|
|
14756
|
+
autoResumeSuspendedTools: options.autoResumeSuspendedTools
|
|
14484
14757
|
});
|
|
14485
14758
|
const mapResultsStep = createMapResultsStep({
|
|
14486
14759
|
capabilities,
|
|
@@ -14496,10 +14769,10 @@ function createPrepareStreamWorkflow({
|
|
|
14496
14769
|
});
|
|
14497
14770
|
return createWorkflow({
|
|
14498
14771
|
id: "execution-workflow",
|
|
14499
|
-
inputSchema:
|
|
14500
|
-
outputSchema:
|
|
14501
|
-
|
|
14502
|
-
|
|
14772
|
+
inputSchema: z8.z.object({}),
|
|
14773
|
+
outputSchema: z8.z.union([
|
|
14774
|
+
z8.z.instanceof(MastraModelOutput),
|
|
14775
|
+
z8.z.instanceof(AISDKV5OutputStream)
|
|
14503
14776
|
]),
|
|
14504
14777
|
steps: [prepareToolsStep, prepareMemoryStep2, streamStep],
|
|
14505
14778
|
options: {
|
|
@@ -14570,7 +14843,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
14570
14843
|
this.#description = config.description;
|
|
14571
14844
|
this.#options = config.options;
|
|
14572
14845
|
if (!config.model) {
|
|
14573
|
-
const mastraError = new
|
|
14846
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
14574
14847
|
id: "AGENT_CONSTRUCTOR_MODEL_REQUIRED",
|
|
14575
14848
|
domain: "AGENT" /* AGENT */,
|
|
14576
14849
|
category: "USER" /* USER */,
|
|
@@ -14585,7 +14858,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
14585
14858
|
}
|
|
14586
14859
|
if (Array.isArray(config.model)) {
|
|
14587
14860
|
if (config.model.length === 0) {
|
|
14588
|
-
const mastraError = new
|
|
14861
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
14589
14862
|
id: "AGENT_CONSTRUCTOR_MODEL_ARRAY_EMPTY",
|
|
14590
14863
|
domain: "AGENT" /* AGENT */,
|
|
14591
14864
|
category: "USER" /* USER */,
|
|
@@ -14637,7 +14910,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
14637
14910
|
this.#voice?.addInstructions(config.instructions);
|
|
14638
14911
|
}
|
|
14639
14912
|
} else {
|
|
14640
|
-
this.#voice = new
|
|
14913
|
+
this.#voice = new chunkH4VUIOWU_cjs.DefaultVoice();
|
|
14641
14914
|
}
|
|
14642
14915
|
if (config.inputProcessors) {
|
|
14643
14916
|
this.#inputProcessors = config.inputProcessors;
|
|
@@ -14667,7 +14940,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
14667
14940
|
const agentsToUse = this.#agents ? typeof this.#agents === "function" ? this.#agents({ requestContext }) : this.#agents : {};
|
|
14668
14941
|
return resolveMaybePromise(agentsToUse, (agents) => {
|
|
14669
14942
|
if (!agents) {
|
|
14670
|
-
const mastraError = new
|
|
14943
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
14671
14944
|
id: "AGENT_GET_AGENTS_FUNCTION_EMPTY_RETURN",
|
|
14672
14945
|
domain: "AGENT" /* AGENT */,
|
|
14673
14946
|
category: "USER" /* USER */,
|
|
@@ -14734,7 +15007,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
14734
15007
|
id: workflowId,
|
|
14735
15008
|
inputSchema: ProcessorStepSchema,
|
|
14736
15009
|
outputSchema: ProcessorStepSchema,
|
|
14737
|
-
type: "processor"
|
|
15010
|
+
type: "processor",
|
|
15011
|
+
options: { validateInputs: false }
|
|
14738
15012
|
});
|
|
14739
15013
|
for (const processorOrWorkflow of validProcessors) {
|
|
14740
15014
|
const step = isProcessorWorkflow(processorOrWorkflow) ? processorOrWorkflow : createStep(processorOrWorkflow);
|
|
@@ -14841,7 +15115,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
14841
15115
|
const result = this.#memory({ requestContext, mastra: this.#mastra });
|
|
14842
15116
|
resolvedMemory = await Promise.resolve(result);
|
|
14843
15117
|
if (!resolvedMemory) {
|
|
14844
|
-
const mastraError = new
|
|
15118
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
14845
15119
|
id: "AGENT_GET_MEMORY_FUNCTION_EMPTY_RETURN",
|
|
14846
15120
|
domain: "AGENT" /* AGENT */,
|
|
14847
15121
|
category: "USER" /* USER */,
|
|
@@ -14868,7 +15142,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
14868
15142
|
}
|
|
14869
15143
|
get voice() {
|
|
14870
15144
|
if (typeof this.#instructions === "function") {
|
|
14871
|
-
const mastraError = new
|
|
15145
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
14872
15146
|
id: "AGENT_VOICE_INCOMPATIBLE_WITH_FUNCTION_INSTRUCTIONS",
|
|
14873
15147
|
domain: "AGENT" /* AGENT */,
|
|
14874
15148
|
category: "USER" /* USER */,
|
|
@@ -14918,7 +15192,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
14918
15192
|
const result = this.#scorers({ requestContext, mastra: this.#mastra });
|
|
14919
15193
|
return resolveMaybePromise(result, (scorers) => {
|
|
14920
15194
|
if (!scorers) {
|
|
14921
|
-
const mastraError = new
|
|
15195
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
14922
15196
|
id: "AGENT_GET_SCORERS_FUNCTION_EMPTY_RETURN",
|
|
14923
15197
|
domain: "AGENT" /* AGENT */,
|
|
14924
15198
|
category: "USER" /* USER */,
|
|
@@ -14952,7 +15226,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
14952
15226
|
voice?.addInstructions(this.#convertInstructionsToString(instructions));
|
|
14953
15227
|
return voice;
|
|
14954
15228
|
} else {
|
|
14955
|
-
return new
|
|
15229
|
+
return new chunkH4VUIOWU_cjs.DefaultVoice();
|
|
14956
15230
|
}
|
|
14957
15231
|
}
|
|
14958
15232
|
/**
|
|
@@ -14970,7 +15244,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
14970
15244
|
const result = this.#instructions({ requestContext, mastra: this.#mastra });
|
|
14971
15245
|
return resolveMaybePromise(result, (instructions) => {
|
|
14972
15246
|
if (!instructions) {
|
|
14973
|
-
const mastraError = new
|
|
15247
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
14974
15248
|
id: "AGENT_GET_INSTRUCTIONS_FUNCTION_EMPTY_RETURN",
|
|
14975
15249
|
domain: "AGENT" /* AGENT */,
|
|
14976
15250
|
category: "USER" /* USER */,
|
|
@@ -15075,7 +15349,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15075
15349
|
const result = this.#defaultGenerateOptionsLegacy({ requestContext, mastra: this.#mastra });
|
|
15076
15350
|
return resolveMaybePromise(result, (options) => {
|
|
15077
15351
|
if (!options) {
|
|
15078
|
-
const mastraError = new
|
|
15352
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
15079
15353
|
id: "AGENT_GET_DEFAULT_GENERATE_OPTIONS_FUNCTION_EMPTY_RETURN",
|
|
15080
15354
|
domain: "AGENT" /* AGENT */,
|
|
15081
15355
|
category: "USER" /* USER */,
|
|
@@ -15110,7 +15384,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15110
15384
|
const result = this.#defaultStreamOptionsLegacy({ requestContext, mastra: this.#mastra });
|
|
15111
15385
|
return resolveMaybePromise(result, (options) => {
|
|
15112
15386
|
if (!options) {
|
|
15113
|
-
const mastraError = new
|
|
15387
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
15114
15388
|
id: "AGENT_GET_DEFAULT_STREAM_OPTIONS_FUNCTION_EMPTY_RETURN",
|
|
15115
15389
|
domain: "AGENT" /* AGENT */,
|
|
15116
15390
|
category: "USER" /* USER */,
|
|
@@ -15145,7 +15419,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15145
15419
|
const result = this.#defaultOptions({ requestContext, mastra: this.#mastra });
|
|
15146
15420
|
return resolveMaybePromise(result, (options) => {
|
|
15147
15421
|
if (!options) {
|
|
15148
|
-
const mastraError = new
|
|
15422
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
15149
15423
|
id: "AGENT_GET_DEFAULT_OPTIONS_FUNCTION_EMPTY_RETURN",
|
|
15150
15424
|
domain: "AGENT" /* AGENT */,
|
|
15151
15425
|
category: "USER" /* USER */,
|
|
@@ -15173,12 +15447,12 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15173
15447
|
*/
|
|
15174
15448
|
listTools({ requestContext = new chunkUVHSM2GU_cjs.RequestContext() } = {}) {
|
|
15175
15449
|
if (typeof this.#tools !== "function") {
|
|
15176
|
-
return
|
|
15450
|
+
return chunkMLKE7HRS_cjs.ensureToolProperties(this.#tools);
|
|
15177
15451
|
}
|
|
15178
15452
|
const result = this.#tools({ requestContext, mastra: this.#mastra });
|
|
15179
15453
|
return resolveMaybePromise(result, (tools) => {
|
|
15180
15454
|
if (!tools) {
|
|
15181
|
-
const mastraError = new
|
|
15455
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
15182
15456
|
id: "AGENT_GET_TOOLS_FUNCTION_EMPTY_RETURN",
|
|
15183
15457
|
domain: "AGENT" /* AGENT */,
|
|
15184
15458
|
category: "USER" /* USER */,
|
|
@@ -15191,7 +15465,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15191
15465
|
this.logger.error(mastraError.toString());
|
|
15192
15466
|
throw mastraError;
|
|
15193
15467
|
}
|
|
15194
|
-
return
|
|
15468
|
+
return chunkMLKE7HRS_cjs.ensureToolProperties(tools);
|
|
15195
15469
|
});
|
|
15196
15470
|
}
|
|
15197
15471
|
/**
|
|
@@ -15223,7 +15497,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15223
15497
|
});
|
|
15224
15498
|
});
|
|
15225
15499
|
} else {
|
|
15226
|
-
llm = new
|
|
15500
|
+
llm = new chunkSZYSDJTN_cjs.MastraLLMV1({
|
|
15227
15501
|
model: resolvedModel,
|
|
15228
15502
|
mastra: this.#mastra,
|
|
15229
15503
|
options: { tracingPolicy: this.#options?.tracingPolicy }
|
|
@@ -15248,9 +15522,9 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15248
15522
|
*/
|
|
15249
15523
|
async resolveModelConfig(modelConfig, requestContext) {
|
|
15250
15524
|
try {
|
|
15251
|
-
return await
|
|
15525
|
+
return await chunkMXBVP7HX_cjs.resolveModelConfig(modelConfig, requestContext, this.#mastra);
|
|
15252
15526
|
} catch (error) {
|
|
15253
|
-
const mastraError = new
|
|
15527
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
15254
15528
|
id: "AGENT_GET_MODEL_MISSING_MODEL_INSTANCE",
|
|
15255
15529
|
domain: "AGENT" /* AGENT */,
|
|
15256
15530
|
category: "USER" /* USER */,
|
|
@@ -15284,7 +15558,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15284
15558
|
} = {}) {
|
|
15285
15559
|
if (!Array.isArray(modelConfig)) return this.resolveModelConfig(modelConfig, requestContext);
|
|
15286
15560
|
if (modelConfig.length === 0 || !modelConfig[0]) {
|
|
15287
|
-
const mastraError = new
|
|
15561
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
15288
15562
|
id: "AGENT_GET_MODEL_MISSING_MODEL_INSTANCE",
|
|
15289
15563
|
domain: "AGENT" /* AGENT */,
|
|
15290
15564
|
category: "USER" /* USER */,
|
|
@@ -15401,14 +15675,14 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15401
15675
|
__registerMastra(mastra) {
|
|
15402
15676
|
this.#mastra = mastra;
|
|
15403
15677
|
if (this.#tools && typeof this.#tools === "object") {
|
|
15404
|
-
Object.entries(this.#tools).forEach(([key,
|
|
15678
|
+
Object.entries(this.#tools).forEach(([key, tool2]) => {
|
|
15405
15679
|
try {
|
|
15406
|
-
if (
|
|
15407
|
-
const toolKey = typeof
|
|
15408
|
-
mastra.addTool(
|
|
15680
|
+
if (tool2 && typeof tool2 === "object" && "id" in tool2) {
|
|
15681
|
+
const toolKey = typeof tool2.id === "string" ? tool2.id : key;
|
|
15682
|
+
mastra.addTool(tool2, toolKey);
|
|
15409
15683
|
}
|
|
15410
15684
|
} catch (error) {
|
|
15411
|
-
if (error instanceof
|
|
15685
|
+
if (error instanceof chunkHWMMIRIF_cjs.MastraError && error.id !== "MASTRA_ADD_TOOL_DUPLICATE_KEY") {
|
|
15412
15686
|
throw error;
|
|
15413
15687
|
}
|
|
15414
15688
|
}
|
|
@@ -15419,7 +15693,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15419
15693
|
try {
|
|
15420
15694
|
mastra.addProcessor(processor);
|
|
15421
15695
|
} catch (error) {
|
|
15422
|
-
if (error instanceof
|
|
15696
|
+
if (error instanceof chunkHWMMIRIF_cjs.MastraError && error.id !== "MASTRA_ADD_PROCESSOR_DUPLICATE_KEY") {
|
|
15423
15697
|
throw error;
|
|
15424
15698
|
}
|
|
15425
15699
|
}
|
|
@@ -15430,7 +15704,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15430
15704
|
try {
|
|
15431
15705
|
mastra.addProcessor(processor);
|
|
15432
15706
|
} catch (error) {
|
|
15433
|
-
if (error instanceof
|
|
15707
|
+
if (error instanceof chunkHWMMIRIF_cjs.MastraError && error.id !== "MASTRA_ADD_PROCESSOR_DUPLICATE_KEY") {
|
|
15434
15708
|
throw error;
|
|
15435
15709
|
}
|
|
15436
15710
|
}
|
|
@@ -15454,7 +15728,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15454
15728
|
instructions
|
|
15455
15729
|
}) {
|
|
15456
15730
|
const llm = await this.getLLM({ requestContext, model });
|
|
15457
|
-
const normMessage = new
|
|
15731
|
+
const normMessage = new chunkX6IBA7FP_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
|
|
15458
15732
|
if (!normMessage) {
|
|
15459
15733
|
throw new Error(`Could not generate title from input ${JSON.stringify(message)}`);
|
|
15460
15734
|
}
|
|
@@ -15477,7 +15751,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15477
15751
|
const systemInstructions = await this.resolveTitleInstructions(requestContext, instructions);
|
|
15478
15752
|
let text = "";
|
|
15479
15753
|
if (llm.getModel().specificationVersion === "v2") {
|
|
15480
|
-
const messageList = new
|
|
15754
|
+
const messageList = new chunkX6IBA7FP_cjs.MessageList().add(
|
|
15481
15755
|
[
|
|
15482
15756
|
{
|
|
15483
15757
|
role: "system",
|
|
@@ -15530,7 +15804,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15530
15804
|
async genTitle(userMessage, requestContext, tracingContext, model, instructions) {
|
|
15531
15805
|
try {
|
|
15532
15806
|
if (userMessage) {
|
|
15533
|
-
const normMessage = new
|
|
15807
|
+
const normMessage = new chunkX6IBA7FP_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
|
|
15534
15808
|
if (normMessage) {
|
|
15535
15809
|
return await this.generateTitleFromUserMessage({
|
|
15536
15810
|
message: normMessage,
|
|
@@ -15561,7 +15835,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15561
15835
|
requestContext,
|
|
15562
15836
|
tracingContext,
|
|
15563
15837
|
mastraProxy,
|
|
15564
|
-
memoryConfig
|
|
15838
|
+
memoryConfig,
|
|
15839
|
+
autoResumeSuspendedTools
|
|
15565
15840
|
}) {
|
|
15566
15841
|
let convertedMemoryTools = {};
|
|
15567
15842
|
if (this._agentNetworkAppend) {
|
|
@@ -15577,8 +15852,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15577
15852
|
runId
|
|
15578
15853
|
}
|
|
15579
15854
|
);
|
|
15580
|
-
for (const [toolName,
|
|
15581
|
-
const toolObj =
|
|
15855
|
+
for (const [toolName, tool2] of Object.entries(memoryTools)) {
|
|
15856
|
+
const toolObj = tool2;
|
|
15582
15857
|
const options = {
|
|
15583
15858
|
name: toolName,
|
|
15584
15859
|
runId,
|
|
@@ -15594,7 +15869,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15594
15869
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
15595
15870
|
requireApproval: toolObj.requireApproval
|
|
15596
15871
|
};
|
|
15597
|
-
const convertedToCoreTool =
|
|
15872
|
+
const convertedToCoreTool = chunkMLKE7HRS_cjs.makeCoreTool(toolObj, options, void 0, autoResumeSuspendedTools);
|
|
15598
15873
|
convertedMemoryTools[toolName] = convertedToCoreTool;
|
|
15599
15874
|
}
|
|
15600
15875
|
}
|
|
@@ -15627,7 +15902,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15627
15902
|
processorId: error.processorId
|
|
15628
15903
|
};
|
|
15629
15904
|
} else {
|
|
15630
|
-
throw new
|
|
15905
|
+
throw new chunkHWMMIRIF_cjs.MastraError(
|
|
15631
15906
|
{
|
|
15632
15907
|
id: "AGENT_INPUT_PROCESSOR_ERROR",
|
|
15633
15908
|
domain: "AGENT" /* AGENT */,
|
|
@@ -15720,7 +15995,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15720
15995
|
requestContext,
|
|
15721
15996
|
tracingContext,
|
|
15722
15997
|
mastraProxy,
|
|
15723
|
-
outputWriter
|
|
15998
|
+
outputWriter,
|
|
15999
|
+
autoResumeSuspendedTools
|
|
15724
16000
|
}) {
|
|
15725
16001
|
let toolsForRequest = {};
|
|
15726
16002
|
this.logger.debug(`[Agents:${this.name}] - Assembling assigned tools`, { runId, threadId, resourceId });
|
|
@@ -15728,8 +16004,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15728
16004
|
const assignedTools = await this.listTools({ requestContext });
|
|
15729
16005
|
const assignedToolEntries = Object.entries(assignedTools || {});
|
|
15730
16006
|
const assignedCoreToolEntries = await Promise.all(
|
|
15731
|
-
assignedToolEntries.map(async ([k,
|
|
15732
|
-
if (!
|
|
16007
|
+
assignedToolEntries.map(async ([k, tool2]) => {
|
|
16008
|
+
if (!tool2) {
|
|
15733
16009
|
return;
|
|
15734
16010
|
}
|
|
15735
16011
|
const options = {
|
|
@@ -15746,9 +16022,9 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15746
16022
|
model: await this.getModel({ requestContext }),
|
|
15747
16023
|
outputWriter,
|
|
15748
16024
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
15749
|
-
requireApproval:
|
|
16025
|
+
requireApproval: tool2.requireApproval
|
|
15750
16026
|
};
|
|
15751
|
-
return [k,
|
|
16027
|
+
return [k, chunkMLKE7HRS_cjs.makeCoreTool(tool2, options, void 0, autoResumeSuspendedTools)];
|
|
15752
16028
|
})
|
|
15753
16029
|
);
|
|
15754
16030
|
const assignedToolEntriesConverted = Object.fromEntries(
|
|
@@ -15770,7 +16046,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15770
16046
|
toolsets,
|
|
15771
16047
|
requestContext,
|
|
15772
16048
|
tracingContext,
|
|
15773
|
-
mastraProxy
|
|
16049
|
+
mastraProxy,
|
|
16050
|
+
autoResumeSuspendedTools
|
|
15774
16051
|
}) {
|
|
15775
16052
|
let toolsForRequest = {};
|
|
15776
16053
|
const memory = await this.getMemory({ requestContext });
|
|
@@ -15780,8 +16057,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15780
16057
|
runId
|
|
15781
16058
|
});
|
|
15782
16059
|
for (const toolset of toolsFromToolsets) {
|
|
15783
|
-
for (const [toolName,
|
|
15784
|
-
const toolObj =
|
|
16060
|
+
for (const [toolName, tool2] of Object.entries(toolset)) {
|
|
16061
|
+
const toolObj = tool2;
|
|
15785
16062
|
const options = {
|
|
15786
16063
|
name: toolName,
|
|
15787
16064
|
runId,
|
|
@@ -15797,7 +16074,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15797
16074
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
15798
16075
|
requireApproval: toolObj.requireApproval
|
|
15799
16076
|
};
|
|
15800
|
-
const convertedToCoreTool =
|
|
16077
|
+
const convertedToCoreTool = chunkMLKE7HRS_cjs.makeCoreTool(toolObj, options, "toolset", autoResumeSuspendedTools);
|
|
15801
16078
|
toolsForRequest[toolName] = convertedToCoreTool;
|
|
15802
16079
|
}
|
|
15803
16080
|
}
|
|
@@ -15815,7 +16092,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15815
16092
|
requestContext,
|
|
15816
16093
|
tracingContext,
|
|
15817
16094
|
mastraProxy,
|
|
15818
|
-
clientTools
|
|
16095
|
+
clientTools,
|
|
16096
|
+
autoResumeSuspendedTools
|
|
15819
16097
|
}) {
|
|
15820
16098
|
let toolsForRequest = {};
|
|
15821
16099
|
const memory = await this.getMemory({ requestContext });
|
|
@@ -15824,8 +16102,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15824
16102
|
this.logger.debug(`[Agent:${this.name}] - Adding client tools ${Object.keys(clientTools || {}).join(", ")}`, {
|
|
15825
16103
|
runId
|
|
15826
16104
|
});
|
|
15827
|
-
for (const [toolName,
|
|
15828
|
-
const { execute: execute2, ...rest } =
|
|
16105
|
+
for (const [toolName, tool2] of clientToolsForInput) {
|
|
16106
|
+
const { execute: execute2, ...rest } = tool2;
|
|
15829
16107
|
const options = {
|
|
15830
16108
|
name: toolName,
|
|
15831
16109
|
runId,
|
|
@@ -15839,9 +16117,9 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15839
16117
|
tracingContext,
|
|
15840
16118
|
model: await this.getModel({ requestContext }),
|
|
15841
16119
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
15842
|
-
requireApproval:
|
|
16120
|
+
requireApproval: tool2.requireApproval
|
|
15843
16121
|
};
|
|
15844
|
-
const convertedToCoreTool =
|
|
16122
|
+
const convertedToCoreTool = chunkMLKE7HRS_cjs.makeCoreTool(rest, options, "client-tool", autoResumeSuspendedTools);
|
|
15845
16123
|
toolsForRequest[toolName] = convertedToCoreTool;
|
|
15846
16124
|
}
|
|
15847
16125
|
}
|
|
@@ -15857,28 +16135,29 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15857
16135
|
resourceId,
|
|
15858
16136
|
requestContext,
|
|
15859
16137
|
tracingContext,
|
|
15860
|
-
methodType
|
|
16138
|
+
methodType,
|
|
16139
|
+
autoResumeSuspendedTools
|
|
15861
16140
|
}) {
|
|
15862
16141
|
const convertedAgentTools = {};
|
|
15863
16142
|
const agents = await this.listAgents({ requestContext });
|
|
15864
16143
|
if (Object.keys(agents).length > 0) {
|
|
15865
16144
|
for (const [agentName, agent] of Object.entries(agents)) {
|
|
15866
|
-
const agentInputSchema =
|
|
15867
|
-
prompt:
|
|
15868
|
-
threadId:
|
|
15869
|
-
resourceId:
|
|
15870
|
-
instructions:
|
|
15871
|
-
maxSteps:
|
|
16145
|
+
const agentInputSchema = z8.z.object({
|
|
16146
|
+
prompt: z8.z.string().describe("The prompt to send to the agent"),
|
|
16147
|
+
threadId: z8.z.string().optional().describe("Thread ID for conversation continuity for memory messages"),
|
|
16148
|
+
resourceId: z8.z.string().optional().describe("Resource/user identifier for memory messages"),
|
|
16149
|
+
instructions: z8.z.string().optional().describe("Custom instructions to override agent defaults"),
|
|
16150
|
+
maxSteps: z8.z.number().min(3).optional().describe("Maximum number of execution steps for the sub-agent")
|
|
15872
16151
|
// using minimum of 3 to ensure if the agent has a tool call, the llm gets executed again after the tool call step, using the tool call result
|
|
15873
16152
|
// to return a proper llm response
|
|
15874
16153
|
});
|
|
15875
|
-
const agentOutputSchema =
|
|
15876
|
-
text:
|
|
15877
|
-
subAgentThreadId:
|
|
15878
|
-
subAgentResourceId:
|
|
16154
|
+
const agentOutputSchema = z8.z.object({
|
|
16155
|
+
text: z8.z.string().describe("The response from the agent"),
|
|
16156
|
+
subAgentThreadId: z8.z.string().describe("The thread ID of the agent").optional(),
|
|
16157
|
+
subAgentResourceId: z8.z.string().describe("The resource ID of the agent").optional()
|
|
15879
16158
|
});
|
|
15880
16159
|
const modelVersion = (await agent.getModel({ requestContext })).specificationVersion;
|
|
15881
|
-
const toolObj =
|
|
16160
|
+
const toolObj = chunkZ55SJVEC_cjs.createTool({
|
|
15882
16161
|
id: `agent-${agentName}`,
|
|
15883
16162
|
description: agent.getDescription() || `Agent: ${agentName}`,
|
|
15884
16163
|
inputSchema: agentInputSchema,
|
|
@@ -15974,7 +16253,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15974
16253
|
}
|
|
15975
16254
|
return result;
|
|
15976
16255
|
} catch (err) {
|
|
15977
|
-
const mastraError = new
|
|
16256
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError(
|
|
15978
16257
|
{
|
|
15979
16258
|
id: "AGENT_AGENT_TOOL_EXECUTION_FAILED",
|
|
15980
16259
|
domain: "AGENT" /* AGENT */,
|
|
@@ -16010,7 +16289,12 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16010
16289
|
tracingContext,
|
|
16011
16290
|
tracingPolicy: this.#options?.tracingPolicy
|
|
16012
16291
|
};
|
|
16013
|
-
convertedAgentTools[`agent-${agentName}`] =
|
|
16292
|
+
convertedAgentTools[`agent-${agentName}`] = chunkMLKE7HRS_cjs.makeCoreTool(
|
|
16293
|
+
toolObj,
|
|
16294
|
+
options,
|
|
16295
|
+
void 0,
|
|
16296
|
+
autoResumeSuspendedTools
|
|
16297
|
+
);
|
|
16014
16298
|
}
|
|
16015
16299
|
}
|
|
16016
16300
|
return convertedAgentTools;
|
|
@@ -16025,28 +16309,29 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16025
16309
|
resourceId,
|
|
16026
16310
|
requestContext,
|
|
16027
16311
|
tracingContext,
|
|
16028
|
-
methodType
|
|
16312
|
+
methodType,
|
|
16313
|
+
autoResumeSuspendedTools
|
|
16029
16314
|
}) {
|
|
16030
16315
|
const convertedWorkflowTools = {};
|
|
16031
16316
|
const workflows = await this.listWorkflows({ requestContext });
|
|
16032
16317
|
if (Object.keys(workflows).length > 0) {
|
|
16033
16318
|
for (const [workflowName, workflow] of Object.entries(workflows)) {
|
|
16034
|
-
const extendedInputSchema =
|
|
16319
|
+
const extendedInputSchema = z8.z.object({
|
|
16035
16320
|
inputData: workflow.inputSchema,
|
|
16036
16321
|
...workflow.stateSchema ? { initialState: workflow.stateSchema } : {}
|
|
16037
16322
|
});
|
|
16038
|
-
const toolObj =
|
|
16323
|
+
const toolObj = chunkZ55SJVEC_cjs.createTool({
|
|
16039
16324
|
id: `workflow-${workflowName}`,
|
|
16040
16325
|
description: workflow.description || `Workflow: ${workflowName}`,
|
|
16041
16326
|
inputSchema: extendedInputSchema,
|
|
16042
|
-
outputSchema:
|
|
16043
|
-
|
|
16327
|
+
outputSchema: z8.z.union([
|
|
16328
|
+
z8.z.object({
|
|
16044
16329
|
result: workflow.outputSchema,
|
|
16045
|
-
runId:
|
|
16330
|
+
runId: z8.z.string().describe("Unique identifier for the workflow run")
|
|
16046
16331
|
}),
|
|
16047
|
-
|
|
16048
|
-
runId:
|
|
16049
|
-
error:
|
|
16332
|
+
z8.z.object({
|
|
16333
|
+
runId: z8.z.string().describe("Unique identifier for the workflow run"),
|
|
16334
|
+
error: z8.z.string().describe("Error message if workflow execution failed")
|
|
16050
16335
|
})
|
|
16051
16336
|
]),
|
|
16052
16337
|
mastra: this.#mastra,
|
|
@@ -16054,16 +16339,17 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16054
16339
|
// current tool span onto the workflow to maintain continuity of the trace
|
|
16055
16340
|
execute: async (inputData, context) => {
|
|
16056
16341
|
try {
|
|
16342
|
+
const { initialState, inputData: workflowInputData, suspendedToolRunId } = inputData;
|
|
16343
|
+
const runIdToUse = suspendedToolRunId ?? runId;
|
|
16057
16344
|
this.logger.debug(`[Agent:${this.name}] - Executing workflow as tool ${workflowName}`, {
|
|
16058
16345
|
name: workflowName,
|
|
16059
16346
|
description: workflow.description,
|
|
16060
16347
|
args: inputData,
|
|
16061
|
-
runId,
|
|
16348
|
+
runId: runIdToUse,
|
|
16062
16349
|
threadId,
|
|
16063
16350
|
resourceId
|
|
16064
16351
|
});
|
|
16065
|
-
const run = await workflow.createRun({ runId });
|
|
16066
|
-
const { initialState, inputData: workflowInputData } = inputData;
|
|
16352
|
+
const run = await workflow.createRun({ runId: runIdToUse });
|
|
16067
16353
|
const { resumeData, suspend } = context?.agent ?? {};
|
|
16068
16354
|
let result = void 0;
|
|
16069
16355
|
if (methodType === "generate" || methodType === "generateLegacy") {
|
|
@@ -16122,10 +16408,24 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16122
16408
|
} else if (result?.status === "suspended") {
|
|
16123
16409
|
const suspendedStep = result?.suspended?.[0]?.[0];
|
|
16124
16410
|
const suspendPayload = result?.steps?.[suspendedStep]?.suspendPayload;
|
|
16411
|
+
const suspendedStepIds = result?.suspended?.map((stepPath) => stepPath.join("."));
|
|
16412
|
+
const firstSuspendedStepPath = [...result?.suspended?.[0] ?? []];
|
|
16413
|
+
let wflowStep = workflow;
|
|
16414
|
+
while (firstSuspendedStepPath.length > 0) {
|
|
16415
|
+
const key = firstSuspendedStepPath.shift();
|
|
16416
|
+
if (key) {
|
|
16417
|
+
if (!workflow.steps[key]) {
|
|
16418
|
+
this.logger.warn(`Suspended step '${key}' not found in workflow '${workflowName}'`);
|
|
16419
|
+
break;
|
|
16420
|
+
}
|
|
16421
|
+
wflowStep = workflow.steps[key];
|
|
16422
|
+
}
|
|
16423
|
+
}
|
|
16424
|
+
const resumeSchema = wflowStep?.resumeSchema;
|
|
16125
16425
|
if (suspendPayload?.__workflow_meta) {
|
|
16126
16426
|
delete suspendPayload.__workflow_meta;
|
|
16127
16427
|
}
|
|
16128
|
-
return suspend?.(suspendPayload);
|
|
16428
|
+
return suspend?.(suspendPayload, { resumeLabel: suspendedStepIds, resumeSchema });
|
|
16129
16429
|
} else {
|
|
16130
16430
|
return {
|
|
16131
16431
|
error: `Workflow should never reach this path, workflow returned no status`,
|
|
@@ -16133,14 +16433,14 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16133
16433
|
};
|
|
16134
16434
|
}
|
|
16135
16435
|
} catch (err) {
|
|
16136
|
-
const mastraError = new
|
|
16436
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError(
|
|
16137
16437
|
{
|
|
16138
16438
|
id: "AGENT_WORKFLOW_TOOL_EXECUTION_FAILED",
|
|
16139
16439
|
domain: "AGENT" /* AGENT */,
|
|
16140
16440
|
category: "USER" /* USER */,
|
|
16141
16441
|
details: {
|
|
16142
16442
|
agentName: this.name,
|
|
16143
|
-
runId: runId || "",
|
|
16443
|
+
runId: inputData.suspendedToolRunId || runId || "",
|
|
16144
16444
|
threadId: threadId || "",
|
|
16145
16445
|
resourceId: resourceId || ""
|
|
16146
16446
|
},
|
|
@@ -16168,7 +16468,12 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16168
16468
|
tracingContext,
|
|
16169
16469
|
tracingPolicy: this.#options?.tracingPolicy
|
|
16170
16470
|
};
|
|
16171
|
-
convertedWorkflowTools[`workflow-${workflowName}`] =
|
|
16471
|
+
convertedWorkflowTools[`workflow-${workflowName}`] = chunkMLKE7HRS_cjs.makeCoreTool(
|
|
16472
|
+
toolObj,
|
|
16473
|
+
options,
|
|
16474
|
+
void 0,
|
|
16475
|
+
autoResumeSuspendedTools
|
|
16476
|
+
);
|
|
16172
16477
|
}
|
|
16173
16478
|
}
|
|
16174
16479
|
return convertedWorkflowTools;
|
|
@@ -16187,12 +16492,13 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16187
16492
|
tracingContext,
|
|
16188
16493
|
outputWriter,
|
|
16189
16494
|
methodType,
|
|
16190
|
-
memoryConfig
|
|
16495
|
+
memoryConfig,
|
|
16496
|
+
autoResumeSuspendedTools
|
|
16191
16497
|
}) {
|
|
16192
16498
|
let mastraProxy = void 0;
|
|
16193
16499
|
const logger = this.logger;
|
|
16194
16500
|
if (this.#mastra) {
|
|
16195
|
-
mastraProxy =
|
|
16501
|
+
mastraProxy = chunkMLKE7HRS_cjs.createMastraProxy({ mastra: this.#mastra, logger });
|
|
16196
16502
|
}
|
|
16197
16503
|
const assignedTools = await this.listAssignedTools({
|
|
16198
16504
|
runId,
|
|
@@ -16201,7 +16507,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16201
16507
|
requestContext,
|
|
16202
16508
|
tracingContext,
|
|
16203
16509
|
mastraProxy,
|
|
16204
|
-
outputWriter
|
|
16510
|
+
outputWriter,
|
|
16511
|
+
autoResumeSuspendedTools
|
|
16205
16512
|
});
|
|
16206
16513
|
const memoryTools = await this.listMemoryTools({
|
|
16207
16514
|
runId,
|
|
@@ -16210,7 +16517,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16210
16517
|
requestContext,
|
|
16211
16518
|
tracingContext,
|
|
16212
16519
|
mastraProxy,
|
|
16213
|
-
memoryConfig
|
|
16520
|
+
memoryConfig,
|
|
16521
|
+
autoResumeSuspendedTools
|
|
16214
16522
|
});
|
|
16215
16523
|
const toolsetTools = await this.listToolsets({
|
|
16216
16524
|
runId,
|
|
@@ -16219,7 +16527,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16219
16527
|
requestContext,
|
|
16220
16528
|
tracingContext,
|
|
16221
16529
|
mastraProxy,
|
|
16222
|
-
toolsets
|
|
16530
|
+
toolsets,
|
|
16531
|
+
autoResumeSuspendedTools
|
|
16223
16532
|
});
|
|
16224
16533
|
const clientSideTools = await this.listClientTools({
|
|
16225
16534
|
runId,
|
|
@@ -16228,7 +16537,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16228
16537
|
requestContext,
|
|
16229
16538
|
tracingContext,
|
|
16230
16539
|
mastraProxy,
|
|
16231
|
-
clientTools
|
|
16540
|
+
clientTools,
|
|
16541
|
+
autoResumeSuspendedTools
|
|
16232
16542
|
});
|
|
16233
16543
|
const agentTools = await this.listAgentTools({
|
|
16234
16544
|
runId,
|
|
@@ -16236,7 +16546,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16236
16546
|
threadId,
|
|
16237
16547
|
requestContext,
|
|
16238
16548
|
methodType,
|
|
16239
|
-
tracingContext
|
|
16549
|
+
tracingContext,
|
|
16550
|
+
autoResumeSuspendedTools
|
|
16240
16551
|
});
|
|
16241
16552
|
const workflowTools = await this.listWorkflowTools({
|
|
16242
16553
|
runId,
|
|
@@ -16244,7 +16555,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16244
16555
|
threadId,
|
|
16245
16556
|
requestContext,
|
|
16246
16557
|
methodType,
|
|
16247
|
-
tracingContext
|
|
16558
|
+
tracingContext,
|
|
16559
|
+
autoResumeSuspendedTools
|
|
16248
16560
|
});
|
|
16249
16561
|
return this.formatTools({
|
|
16250
16562
|
...assignedTools,
|
|
@@ -16270,7 +16582,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16270
16582
|
}
|
|
16271
16583
|
newKey = newKey.slice(0, 63);
|
|
16272
16584
|
if (tools[newKey]) {
|
|
16273
|
-
const mastraError = new
|
|
16585
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
16274
16586
|
id: "AGENT_TOOL_NAME_COLLISION",
|
|
16275
16587
|
domain: "AGENT" /* AGENT */,
|
|
16276
16588
|
category: "USER" /* USER */,
|
|
@@ -16374,7 +16686,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16374
16686
|
if (typeof scorerObject.scorer === "string") {
|
|
16375
16687
|
try {
|
|
16376
16688
|
if (!this.#mastra) {
|
|
16377
|
-
throw new
|
|
16689
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
16378
16690
|
id: "AGENT_GENEREATE_SCORER_NOT_FOUND",
|
|
16379
16691
|
domain: "AGENT" /* AGENT */,
|
|
16380
16692
|
category: "USER" /* USER */,
|
|
@@ -16391,7 +16703,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16391
16703
|
}
|
|
16392
16704
|
}
|
|
16393
16705
|
if (Object.keys(result).length === 0) {
|
|
16394
|
-
throw new
|
|
16706
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
16395
16707
|
id: "AGENT_GENEREATE_SCORER_NOT_FOUND",
|
|
16396
16708
|
domain: "AGENT" /* AGENT */,
|
|
16397
16709
|
category: "USER" /* USER */,
|
|
@@ -16409,7 +16721,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16409
16721
|
const modelToUse = model ?? this.model;
|
|
16410
16722
|
const resolvedModel = typeof modelToUse === "function" ? await modelToUse({ requestContext, mastra: this.#mastra }) : modelToUse;
|
|
16411
16723
|
if (resolvedModel?.specificationVersion !== "v2") {
|
|
16412
|
-
const mastraError = new
|
|
16724
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
16413
16725
|
id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
|
|
16414
16726
|
domain: "AGENT" /* AGENT */,
|
|
16415
16727
|
category: "USER" /* USER */,
|
|
@@ -16436,7 +16748,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16436
16748
|
this.model.map(async (modelConfig) => {
|
|
16437
16749
|
const model2 = await this.resolveModelConfig(modelConfig.model, requestContext);
|
|
16438
16750
|
if (!isV2Model(model2)) {
|
|
16439
|
-
const mastraError = new
|
|
16751
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
16440
16752
|
id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
|
|
16441
16753
|
domain: "AGENT" /* AGENT */,
|
|
16442
16754
|
category: "USER" /* USER */,
|
|
@@ -16451,7 +16763,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16451
16763
|
}
|
|
16452
16764
|
const modelId = modelConfig.id || model2.modelId;
|
|
16453
16765
|
if (!modelId) {
|
|
16454
|
-
const mastraError = new
|
|
16766
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError({
|
|
16455
16767
|
id: "AGENT_PREPARE_MODELS_MISSING_MODEL_ID",
|
|
16456
16768
|
domain: "AGENT" /* AGENT */,
|
|
16457
16769
|
category: "USER" /* USER */,
|
|
@@ -16516,7 +16828,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16516
16828
|
const targetProvider = structuredOutputModel.provider;
|
|
16517
16829
|
const targetModelId = structuredOutputModel.modelId;
|
|
16518
16830
|
if (targetProvider.includes("openai") || targetModelId.includes("openai")) {
|
|
16519
|
-
if (
|
|
16831
|
+
if (chunkMLKE7HRS_cjs.isZodType(options.structuredOutput.schema) && targetModelId) {
|
|
16520
16832
|
const modelInfo = {
|
|
16521
16833
|
provider: targetProvider,
|
|
16522
16834
|
modelId: targetModelId,
|
|
@@ -16595,6 +16907,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16595
16907
|
saveQueueManager,
|
|
16596
16908
|
returnScorerData: options.returnScorerData,
|
|
16597
16909
|
requireToolApproval: options.requireToolApproval,
|
|
16910
|
+
toolCallConcurrency: options.toolCallConcurrency,
|
|
16598
16911
|
resumeContext,
|
|
16599
16912
|
agentId: this.id,
|
|
16600
16913
|
agentName: this.name,
|
|
@@ -16710,10 +17023,10 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16710
17023
|
}
|
|
16711
17024
|
}
|
|
16712
17025
|
} catch (e) {
|
|
16713
|
-
if (e instanceof
|
|
17026
|
+
if (e instanceof chunkHWMMIRIF_cjs.MastraError) {
|
|
16714
17027
|
throw e;
|
|
16715
17028
|
}
|
|
16716
|
-
const mastraError = new
|
|
17029
|
+
const mastraError = new chunkHWMMIRIF_cjs.MastraError(
|
|
16717
17030
|
{
|
|
16718
17031
|
id: "AGENT_MEMORY_PERSIST_RESPONSE_MESSAGES_FAILED",
|
|
16719
17032
|
domain: "AGENT" /* AGENT */,
|
|
@@ -16792,6 +17105,10 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16792
17105
|
async network(messages, options) {
|
|
16793
17106
|
const runId = options?.runId || this.#mastra?.generateId() || crypto2.randomUUID();
|
|
16794
17107
|
const requestContextToUse = options?.requestContext || new chunkUVHSM2GU_cjs.RequestContext();
|
|
17108
|
+
const resourceIdFromContext = requestContextToUse.get(chunkUVHSM2GU_cjs.MASTRA_RESOURCE_ID_KEY);
|
|
17109
|
+
const threadIdFromContext = requestContextToUse.get(chunkUVHSM2GU_cjs.MASTRA_THREAD_ID_KEY);
|
|
17110
|
+
const threadId = threadIdFromContext || (typeof options?.memory?.thread === "string" ? options?.memory?.thread : options?.memory?.thread?.id);
|
|
17111
|
+
const resourceId = resourceIdFromContext || options?.memory?.resource;
|
|
16795
17112
|
return await networkLoop({
|
|
16796
17113
|
networkName: this.name,
|
|
16797
17114
|
requestContext: requestContextToUse,
|
|
@@ -16804,8 +17121,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16804
17121
|
generateId: () => this.#mastra?.generateId() || crypto2.randomUUID(),
|
|
16805
17122
|
maxIterations: options?.maxSteps || 1,
|
|
16806
17123
|
messages,
|
|
16807
|
-
threadId
|
|
16808
|
-
resourceId
|
|
17124
|
+
threadId,
|
|
17125
|
+
resourceId
|
|
16809
17126
|
});
|
|
16810
17127
|
}
|
|
16811
17128
|
async generate(messages, options) {
|
|
@@ -16823,7 +17140,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16823
17140
|
if (modelInfo.specificationVersion !== "v2") {
|
|
16824
17141
|
const modelId = modelInfo.modelId || "unknown";
|
|
16825
17142
|
const provider = modelInfo.provider || "unknown";
|
|
16826
|
-
throw new
|
|
17143
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
16827
17144
|
id: "AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED",
|
|
16828
17145
|
domain: "AGENT" /* AGENT */,
|
|
16829
17146
|
category: "USER" /* USER */,
|
|
@@ -16846,7 +17163,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16846
17163
|
const result = await this.#execute(executeOptions);
|
|
16847
17164
|
if (result.status !== "success") {
|
|
16848
17165
|
if (result.status === "failed") {
|
|
16849
|
-
throw new
|
|
17166
|
+
throw new chunkHWMMIRIF_cjs.MastraError(
|
|
16850
17167
|
{
|
|
16851
17168
|
id: "AGENT_GENERATE_FAILED",
|
|
16852
17169
|
domain: "AGENT" /* AGENT */,
|
|
@@ -16856,7 +17173,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16856
17173
|
result.error
|
|
16857
17174
|
);
|
|
16858
17175
|
}
|
|
16859
|
-
throw new
|
|
17176
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
16860
17177
|
id: "AGENT_GENERATE_UNKNOWN_ERROR",
|
|
16861
17178
|
domain: "AGENT" /* AGENT */,
|
|
16862
17179
|
category: "USER" /* USER */,
|
|
@@ -16885,7 +17202,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16885
17202
|
if (modelInfo.specificationVersion !== "v2") {
|
|
16886
17203
|
const modelId = modelInfo.modelId || "unknown";
|
|
16887
17204
|
const provider = modelInfo.provider || "unknown";
|
|
16888
|
-
throw new
|
|
17205
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
16889
17206
|
id: "AGENT_STREAM_V1_MODEL_NOT_SUPPORTED",
|
|
16890
17207
|
domain: "AGENT" /* AGENT */,
|
|
16891
17208
|
category: "USER" /* USER */,
|
|
@@ -16908,7 +17225,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16908
17225
|
const result = await this.#execute(executeOptions);
|
|
16909
17226
|
if (result.status !== "success") {
|
|
16910
17227
|
if (result.status === "failed") {
|
|
16911
|
-
throw new
|
|
17228
|
+
throw new chunkHWMMIRIF_cjs.MastraError(
|
|
16912
17229
|
{
|
|
16913
17230
|
id: "AGENT_STREAM_FAILED",
|
|
16914
17231
|
domain: "AGENT" /* AGENT */,
|
|
@@ -16918,7 +17235,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16918
17235
|
result.error
|
|
16919
17236
|
);
|
|
16920
17237
|
}
|
|
16921
|
-
throw new
|
|
17238
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
16922
17239
|
id: "AGENT_STREAM_UNKNOWN_ERROR",
|
|
16923
17240
|
domain: "AGENT" /* AGENT */,
|
|
16924
17241
|
category: "USER" /* USER */,
|
|
@@ -16952,7 +17269,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16952
17269
|
requestContext: mergedStreamOptions.requestContext
|
|
16953
17270
|
});
|
|
16954
17271
|
if (llm.getModel().specificationVersion !== "v2") {
|
|
16955
|
-
throw new
|
|
17272
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
16956
17273
|
id: "AGENT_STREAM_V1_MODEL_NOT_SUPPORTED",
|
|
16957
17274
|
domain: "AGENT" /* AGENT */,
|
|
16958
17275
|
category: "USER" /* USER */,
|
|
@@ -16974,7 +17291,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16974
17291
|
});
|
|
16975
17292
|
if (result.status !== "success") {
|
|
16976
17293
|
if (result.status === "failed") {
|
|
16977
|
-
throw new
|
|
17294
|
+
throw new chunkHWMMIRIF_cjs.MastraError(
|
|
16978
17295
|
{
|
|
16979
17296
|
id: "AGENT_STREAM_FAILED",
|
|
16980
17297
|
domain: "AGENT" /* AGENT */,
|
|
@@ -16984,7 +17301,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16984
17301
|
result.error
|
|
16985
17302
|
);
|
|
16986
17303
|
}
|
|
16987
|
-
throw new
|
|
17304
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
16988
17305
|
id: "AGENT_STREAM_UNKNOWN_ERROR",
|
|
16989
17306
|
domain: "AGENT" /* AGENT */,
|
|
16990
17307
|
category: "USER" /* USER */,
|
|
@@ -17181,14 +17498,14 @@ var ModerationProcessor = class _ModerationProcessor {
|
|
|
17181
17498
|
const prompt = this.createModerationPrompt(content, isStream);
|
|
17182
17499
|
try {
|
|
17183
17500
|
const model = await this.moderationAgent.getModel();
|
|
17184
|
-
const schema =
|
|
17185
|
-
category_scores:
|
|
17186
|
-
|
|
17187
|
-
category:
|
|
17188
|
-
score:
|
|
17501
|
+
const schema = z8__default.default.object({
|
|
17502
|
+
category_scores: z8__default.default.array(
|
|
17503
|
+
z8__default.default.object({
|
|
17504
|
+
category: z8__default.default.enum(this.categories).describe("The moderation category being evaluated"),
|
|
17505
|
+
score: z8__default.default.number().min(0).max(1).describe("Confidence score between 0 and 1 indicating how strongly the content matches this category")
|
|
17189
17506
|
})
|
|
17190
17507
|
).describe("Array of flagged categories with their confidence scores").nullable(),
|
|
17191
|
-
reason:
|
|
17508
|
+
reason: z8__default.default.string().describe("Brief explanation of why content was flagged").nullable()
|
|
17192
17509
|
});
|
|
17193
17510
|
let response;
|
|
17194
17511
|
if (model.specificationVersion === "v2") {
|
|
@@ -17396,19 +17713,19 @@ var PromptInjectionDetector = class _PromptInjectionDetector {
|
|
|
17396
17713
|
try {
|
|
17397
17714
|
const model = await this.detectionAgent.getModel();
|
|
17398
17715
|
let response;
|
|
17399
|
-
const baseSchema =
|
|
17400
|
-
categories:
|
|
17401
|
-
|
|
17402
|
-
type:
|
|
17403
|
-
score:
|
|
17716
|
+
const baseSchema = z8__default.default.object({
|
|
17717
|
+
categories: z8__default.default.array(
|
|
17718
|
+
z8__default.default.object({
|
|
17719
|
+
type: z8__default.default.enum(this.detectionTypes).describe("The type of attack detected from the list of detection types"),
|
|
17720
|
+
score: z8__default.default.number().min(0).max(1).describe("Confidence level between 0 and 1 indicating how certain the detection is")
|
|
17404
17721
|
})
|
|
17405
17722
|
).nullable(),
|
|
17406
|
-
reason:
|
|
17723
|
+
reason: z8__default.default.string().describe("The reason for the detection").nullable()
|
|
17407
17724
|
});
|
|
17408
17725
|
let schema = baseSchema;
|
|
17409
17726
|
if (this.strategy === "rewrite") {
|
|
17410
17727
|
schema = baseSchema.extend({
|
|
17411
|
-
rewritten_content:
|
|
17728
|
+
rewritten_content: z8__default.default.string().describe("The rewritten content that neutralizes the attack while preserving any legitimate user intent").nullable()
|
|
17412
17729
|
});
|
|
17413
17730
|
}
|
|
17414
17731
|
if (model.specificationVersion === "v2") {
|
|
@@ -17636,27 +17953,27 @@ var PIIDetector = class _PIIDetector {
|
|
|
17636
17953
|
const prompt = this.createDetectionPrompt(content);
|
|
17637
17954
|
try {
|
|
17638
17955
|
const model = await this.detectionAgent.getModel();
|
|
17639
|
-
const baseDetectionSchema =
|
|
17640
|
-
type:
|
|
17641
|
-
value:
|
|
17642
|
-
confidence:
|
|
17643
|
-
start:
|
|
17644
|
-
end:
|
|
17956
|
+
const baseDetectionSchema = z8__default.default.object({
|
|
17957
|
+
type: z8__default.default.string().describe("Type of PII detected"),
|
|
17958
|
+
value: z8__default.default.string().describe("The actual PII value found"),
|
|
17959
|
+
confidence: z8__default.default.number().min(0).max(1).describe("Confidence of this detection"),
|
|
17960
|
+
start: z8__default.default.number().describe("Start position in the text"),
|
|
17961
|
+
end: z8__default.default.number().describe("End position in the text")
|
|
17645
17962
|
});
|
|
17646
17963
|
const detectionSchema = this.strategy === "redact" ? baseDetectionSchema.extend({
|
|
17647
|
-
redacted_value:
|
|
17964
|
+
redacted_value: z8__default.default.string().describe("Redacted version of the value").nullable()
|
|
17648
17965
|
}) : baseDetectionSchema;
|
|
17649
|
-
const baseSchema =
|
|
17650
|
-
categories:
|
|
17651
|
-
|
|
17652
|
-
type:
|
|
17653
|
-
score:
|
|
17966
|
+
const baseSchema = z8__default.default.object({
|
|
17967
|
+
categories: z8__default.default.array(
|
|
17968
|
+
z8__default.default.object({
|
|
17969
|
+
type: z8__default.default.enum(this.detectionTypes).describe("The type of PII detected from the list of detection types"),
|
|
17970
|
+
score: z8__default.default.number().min(0).max(1).describe("Confidence level between 0 and 1 indicating how certain the detection is")
|
|
17654
17971
|
})
|
|
17655
17972
|
).describe("Array of detected PII types with their confidence scores").nullable(),
|
|
17656
|
-
detections:
|
|
17973
|
+
detections: z8__default.default.array(detectionSchema).describe("Array of specific PII detections with locations").nullable()
|
|
17657
17974
|
});
|
|
17658
17975
|
const schema = this.strategy === "redact" ? baseSchema.extend({
|
|
17659
|
-
redacted_content:
|
|
17976
|
+
redacted_content: z8__default.default.string().describe("The content with all PII redacted according to the redaction method").nullable()
|
|
17660
17977
|
}) : baseSchema;
|
|
17661
17978
|
let response;
|
|
17662
17979
|
if (model.specificationVersion === "v2") {
|
|
@@ -18114,12 +18431,12 @@ var LanguageDetector = class _LanguageDetector {
|
|
|
18114
18431
|
try {
|
|
18115
18432
|
const model = await this.detectionAgent.getModel();
|
|
18116
18433
|
let response;
|
|
18117
|
-
const baseSchema =
|
|
18118
|
-
iso_code:
|
|
18119
|
-
confidence:
|
|
18434
|
+
const baseSchema = z8__default.default.object({
|
|
18435
|
+
iso_code: z8__default.default.string().describe("ISO language code").nullable(),
|
|
18436
|
+
confidence: z8__default.default.number().min(0).max(1).describe("Detection confidence").nullable()
|
|
18120
18437
|
});
|
|
18121
18438
|
const schema = this.strategy === "translate" ? baseSchema.extend({
|
|
18122
|
-
translated_text:
|
|
18439
|
+
translated_text: z8__default.default.string().describe("Translated text").nullable()
|
|
18123
18440
|
}) : baseSchema;
|
|
18124
18441
|
if (model.specificationVersion === "v2") {
|
|
18125
18442
|
response = await this.detectionAgent.generate(prompt, {
|
|
@@ -18782,22 +19099,22 @@ var SystemPromptScrubber = class {
|
|
|
18782
19099
|
try {
|
|
18783
19100
|
const model = await this.detectionAgent.getModel();
|
|
18784
19101
|
let result;
|
|
18785
|
-
const baseDetectionSchema =
|
|
18786
|
-
type:
|
|
18787
|
-
value:
|
|
18788
|
-
confidence:
|
|
18789
|
-
start:
|
|
18790
|
-
end:
|
|
19102
|
+
const baseDetectionSchema = z8.z.object({
|
|
19103
|
+
type: z8.z.string().describe("Type of system prompt detected"),
|
|
19104
|
+
value: z8.z.string().describe("The detected content"),
|
|
19105
|
+
confidence: z8.z.number().min(0).max(1).describe("Confidence score"),
|
|
19106
|
+
start: z8.z.number().describe("Start position in text"),
|
|
19107
|
+
end: z8.z.number().describe("End position in text")
|
|
18791
19108
|
});
|
|
18792
19109
|
const detectionSchema = this.strategy === "redact" ? baseDetectionSchema.extend({
|
|
18793
|
-
redacted_value:
|
|
19110
|
+
redacted_value: z8.z.string().describe("Redacted value if available").nullable()
|
|
18794
19111
|
}) : baseDetectionSchema;
|
|
18795
|
-
const baseSchema =
|
|
18796
|
-
detections:
|
|
18797
|
-
reason:
|
|
19112
|
+
const baseSchema = z8.z.object({
|
|
19113
|
+
detections: z8.z.array(detectionSchema).describe("Array of system prompt detections").nullable(),
|
|
19114
|
+
reason: z8.z.string().describe("Reason for detection").nullable()
|
|
18798
19115
|
});
|
|
18799
19116
|
const schema = this.strategy === "redact" ? baseSchema.extend({
|
|
18800
|
-
redacted_content:
|
|
19117
|
+
redacted_content: z8.z.string().describe("Redacted content").nullable()
|
|
18801
19118
|
}) : baseSchema;
|
|
18802
19119
|
if (model.specificationVersion === "v2") {
|
|
18803
19120
|
result = await this.detectionAgent.generate(text, {
|
|
@@ -19368,7 +19685,7 @@ var SemanticRecall = class {
|
|
|
19368
19685
|
*/
|
|
19369
19686
|
formatCrossThreadMessages(messages, currentThreadId) {
|
|
19370
19687
|
let result = ``;
|
|
19371
|
-
const v1Messages = new
|
|
19688
|
+
const v1Messages = new chunkX6IBA7FP_cjs.MessageList().add(messages, "memory").get.all.v1();
|
|
19372
19689
|
let lastYmd = null;
|
|
19373
19690
|
for (const msg of v1Messages) {
|
|
19374
19691
|
const date = msg.createdAt;
|
|
@@ -19773,7 +20090,7 @@ https://mastra.ai/en/docs/memory/semantic-recall`
|
|
|
19773
20090
|
);
|
|
19774
20091
|
}
|
|
19775
20092
|
if (typeof config.embedder === "string") {
|
|
19776
|
-
this.embedder = new
|
|
20093
|
+
this.embedder = new chunkMXBVP7HX_cjs.ModelRouterEmbeddingModel(config.embedder);
|
|
19777
20094
|
} else {
|
|
19778
20095
|
this.embedder = config.embedder;
|
|
19779
20096
|
}
|
|
@@ -19869,7 +20186,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
19869
20186
|
"The threads.generateTitle option has been moved. Use the top-level generateTitle option instead."
|
|
19870
20187
|
);
|
|
19871
20188
|
}
|
|
19872
|
-
const mergedConfig =
|
|
20189
|
+
const mergedConfig = chunkMLKE7HRS_cjs.deepMerge(this.threadConfig, config || {});
|
|
19873
20190
|
if (typeof config?.workingMemory === "object" && config.workingMemory?.schema && typeof mergedConfig.workingMemory === "object") {
|
|
19874
20191
|
mergedConfig.workingMemory.schema = config.workingMemory.schema;
|
|
19875
20192
|
}
|
|
@@ -19938,7 +20255,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
19938
20255
|
const isWorkingMemoryEnabled = typeof effectiveConfig.workingMemory === "object" && effectiveConfig.workingMemory.enabled !== false;
|
|
19939
20256
|
if (isWorkingMemoryEnabled) {
|
|
19940
20257
|
if (!this.storage?.stores?.memory)
|
|
19941
|
-
throw new
|
|
20258
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
19942
20259
|
category: "USER",
|
|
19943
20260
|
domain: "STORAGE" /* STORAGE */,
|
|
19944
20261
|
id: "WORKING_MEMORY_MISSING_STORAGE_ADAPTER",
|
|
@@ -19967,7 +20284,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
19967
20284
|
const lastMessages = effectiveConfig.lastMessages;
|
|
19968
20285
|
if (lastMessages) {
|
|
19969
20286
|
if (!this.storage?.stores?.memory)
|
|
19970
|
-
throw new
|
|
20287
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
19971
20288
|
category: "USER",
|
|
19972
20289
|
domain: "STORAGE" /* STORAGE */,
|
|
19973
20290
|
id: "MESSAGE_HISTORY_MISSING_STORAGE_ADAPTER",
|
|
@@ -19985,21 +20302,21 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
19985
20302
|
}
|
|
19986
20303
|
if (effectiveConfig.semanticRecall) {
|
|
19987
20304
|
if (!this.storage?.stores?.memory)
|
|
19988
|
-
throw new
|
|
20305
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
19989
20306
|
category: "USER",
|
|
19990
20307
|
domain: "STORAGE" /* STORAGE */,
|
|
19991
20308
|
id: "SEMANTIC_RECALL_MISSING_STORAGE_ADAPTER",
|
|
19992
20309
|
text: "Using Mastra Memory semantic recall requires a storage adapter but no attached adapter was detected."
|
|
19993
20310
|
});
|
|
19994
20311
|
if (!this.vector)
|
|
19995
|
-
throw new
|
|
20312
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
19996
20313
|
category: "USER",
|
|
19997
20314
|
domain: "MASTRA_VECTOR" /* MASTRA_VECTOR */,
|
|
19998
20315
|
id: "SEMANTIC_RECALL_MISSING_VECTOR_ADAPTER",
|
|
19999
20316
|
text: "Using Mastra Memory semantic recall requires a vector adapter but no attached adapter was detected."
|
|
20000
20317
|
});
|
|
20001
20318
|
if (!this.embedder)
|
|
20002
|
-
throw new
|
|
20319
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
20003
20320
|
category: "USER",
|
|
20004
20321
|
domain: "MASTRA_VECTOR" /* MASTRA_VECTOR */,
|
|
20005
20322
|
id: "SEMANTIC_RECALL_MISSING_EMBEDDER",
|
|
@@ -20038,21 +20355,21 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20038
20355
|
}
|
|
20039
20356
|
if (effectiveConfig.semanticRecall) {
|
|
20040
20357
|
if (!this.storage?.stores?.memory)
|
|
20041
|
-
throw new
|
|
20358
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
20042
20359
|
category: "USER",
|
|
20043
20360
|
domain: "STORAGE" /* STORAGE */,
|
|
20044
20361
|
id: "SEMANTIC_RECALL_MISSING_STORAGE_ADAPTER",
|
|
20045
20362
|
text: "Using Mastra Memory semantic recall requires a storage adapter but no attached adapter was detected."
|
|
20046
20363
|
});
|
|
20047
20364
|
if (!this.vector)
|
|
20048
|
-
throw new
|
|
20365
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
20049
20366
|
category: "USER",
|
|
20050
20367
|
domain: "MASTRA_VECTOR" /* MASTRA_VECTOR */,
|
|
20051
20368
|
id: "SEMANTIC_RECALL_MISSING_VECTOR_ADAPTER",
|
|
20052
20369
|
text: "Using Mastra Memory semantic recall requires a vector adapter but no attached adapter was detected."
|
|
20053
20370
|
});
|
|
20054
20371
|
if (!this.embedder)
|
|
20055
|
-
throw new
|
|
20372
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
20056
20373
|
category: "USER",
|
|
20057
20374
|
domain: "MASTRA_VECTOR" /* MASTRA_VECTOR */,
|
|
20058
20375
|
id: "SEMANTIC_RECALL_MISSING_EMBEDDER",
|
|
@@ -20076,7 +20393,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20076
20393
|
const lastMessages = effectiveConfig.lastMessages;
|
|
20077
20394
|
if (lastMessages) {
|
|
20078
20395
|
if (!this.storage?.stores?.memory)
|
|
20079
|
-
throw new
|
|
20396
|
+
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
20080
20397
|
category: "USER",
|
|
20081
20398
|
domain: "STORAGE" /* STORAGE */,
|
|
20082
20399
|
id: "MESSAGE_HISTORY_MISSING_STORAGE_ADAPTER",
|
|
@@ -20095,7 +20412,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20095
20412
|
return processors;
|
|
20096
20413
|
}
|
|
20097
20414
|
};
|
|
20098
|
-
var isZodObject = (v) => v instanceof
|
|
20415
|
+
var isZodObject = (v) => v instanceof z8.ZodObject;
|
|
20099
20416
|
var MockMemory = class extends MastraMemory {
|
|
20100
20417
|
constructor({
|
|
20101
20418
|
storage,
|
|
@@ -20105,7 +20422,7 @@ var MockMemory = class extends MastraMemory {
|
|
|
20105
20422
|
} = {}) {
|
|
20106
20423
|
super({
|
|
20107
20424
|
name: "mock",
|
|
20108
|
-
storage: storage || new
|
|
20425
|
+
storage: storage || new chunkLGB4VNZI_cjs.InMemoryStore(),
|
|
20109
20426
|
options: {
|
|
20110
20427
|
workingMemory: enableWorkingMemory ? { enabled: true, template: workingMemoryTemplate } : void 0,
|
|
20111
20428
|
lastMessages: enableMessageHistory ? 10 : void 0
|
|
@@ -20166,10 +20483,10 @@ var MockMemory = class extends MastraMemory {
|
|
|
20166
20483
|
}
|
|
20167
20484
|
listTools(_config) {
|
|
20168
20485
|
return {
|
|
20169
|
-
updateWorkingMemory:
|
|
20486
|
+
updateWorkingMemory: chunkZ55SJVEC_cjs.createTool({
|
|
20170
20487
|
id: "update-working-memory",
|
|
20171
20488
|
description: `Update the working memory with new information. Any data not included will be overwritten.`,
|
|
20172
|
-
inputSchema:
|
|
20489
|
+
inputSchema: z8__default.default.object({ memory: z8__default.default.string() }),
|
|
20173
20490
|
execute: async (inputData, context) => {
|
|
20174
20491
|
const threadId = context?.agent?.threadId;
|
|
20175
20492
|
const resourceId = context?.agent?.resourceId;
|
|
@@ -20283,6 +20600,7 @@ exports.Agent = Agent;
|
|
|
20283
20600
|
exports.BatchPartsProcessor = BatchPartsProcessor;
|
|
20284
20601
|
exports.ChunkFrom = ChunkFrom;
|
|
20285
20602
|
exports.DefaultExecutionEngine = DefaultExecutionEngine;
|
|
20603
|
+
exports.EventEmitterPubSub = EventEmitterPubSub;
|
|
20286
20604
|
exports.ExecutionEngine = ExecutionEngine;
|
|
20287
20605
|
exports.FilePartSchema = FilePartSchema;
|
|
20288
20606
|
exports.ImagePartSchema = ImagePartSchema;
|
|
@@ -20340,6 +20658,7 @@ exports.getResumeLabelsByStepId = getResumeLabelsByStepId;
|
|
|
20340
20658
|
exports.getStepIds = getStepIds;
|
|
20341
20659
|
exports.getStepResult = getStepResult;
|
|
20342
20660
|
exports.getZodErrors = getZodErrors;
|
|
20661
|
+
exports.hydrateSerializedStepErrors = hydrateSerializedStepErrors;
|
|
20343
20662
|
exports.isProcessor = isProcessor;
|
|
20344
20663
|
exports.isProcessorWorkflow = isProcessorWorkflow;
|
|
20345
20664
|
exports.loop = loop;
|
|
@@ -20354,5 +20673,5 @@ exports.validateStepInput = validateStepInput;
|
|
|
20354
20673
|
exports.validateStepResumeData = validateStepResumeData;
|
|
20355
20674
|
exports.validateStepStateData = validateStepStateData;
|
|
20356
20675
|
exports.validateStepSuspendData = validateStepSuspendData;
|
|
20357
|
-
//# sourceMappingURL=chunk-
|
|
20358
|
-
//# sourceMappingURL=chunk-
|
|
20676
|
+
//# sourceMappingURL=chunk-R5AJGM55.cjs.map
|
|
20677
|
+
//# sourceMappingURL=chunk-R5AJGM55.cjs.map
|