@mastra/core 1.0.0-beta.2 → 1.0.0-beta.4
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 +206 -0
- package/dist/agent/agent-legacy.d.ts +2 -2
- package/dist/agent/agent-legacy.d.ts.map +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 +3 -2
- 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 +5 -0
- 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/convert-file.d.ts +1 -1
- package/dist/agent/message-list/prompt/convert-file.d.ts.map +1 -1
- package/dist/agent/message-list/prompt/download-assets.d.ts.map +1 -1
- package/dist/agent/types.d.ts +1 -0
- package/dist/agent/types.d.ts.map +1 -1
- 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/map-results-step.d.ts +3 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +2 -1
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts +2 -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/{chunk-YCVEJ3UN.cjs → chunk-2NVBZKZI.cjs} +988 -233
- package/dist/chunk-2NVBZKZI.cjs.map +1 -0
- package/dist/{chunk-SNPVZPLB.js → chunk-2OTDXX73.js} +6 -5
- package/dist/chunk-2OTDXX73.js.map +1 -0
- package/dist/chunk-3PSWNGBF.js +3 -0
- package/dist/{chunk-ZV5CC35D.js.map → chunk-3PSWNGBF.js.map} +1 -1
- package/dist/{chunk-ZGHTOYHW.js → chunk-3RW5EMSB.js} +155 -24
- package/dist/chunk-3RW5EMSB.js.map +1 -0
- package/dist/chunk-3W5RQCCY.cjs +440 -0
- package/dist/chunk-3W5RQCCY.cjs.map +1 -0
- package/dist/{chunk-ET6UOTTU.cjs → chunk-4IKJAKCD.cjs} +40 -4
- package/dist/chunk-4IKJAKCD.cjs.map +1 -0
- package/dist/{chunk-2ZVKF4HP.cjs → chunk-4RXG622P.cjs} +184 -285
- package/dist/chunk-4RXG622P.cjs.map +1 -0
- package/dist/{chunk-22443P6A.cjs → chunk-5WXEYDFI.cjs} +173 -42
- package/dist/chunk-5WXEYDFI.cjs.map +1 -0
- package/dist/{chunk-ZWNI5IWX.cjs → chunk-CYVNOIXS.cjs} +13 -12
- package/dist/chunk-CYVNOIXS.cjs.map +1 -0
- package/dist/{chunk-4CDL2QJT.js → chunk-D6EDHNGV.js} +53 -16
- package/dist/chunk-D6EDHNGV.js.map +1 -0
- package/dist/chunk-FVNT7VTO.js +436 -0
- package/dist/chunk-FVNT7VTO.js.map +1 -0
- package/dist/{chunk-WM6CK2F3.cjs → chunk-HBJPYQRN.cjs} +57 -19
- package/dist/chunk-HBJPYQRN.cjs.map +1 -0
- package/dist/{chunk-HDJFSJCK.js → chunk-IHJDOC3A.js} +35 -587
- package/dist/chunk-IHJDOC3A.js.map +1 -0
- package/dist/{chunk-QUKUN6NR.cjs → chunk-ISMGVGUM.cjs} +105 -5
- package/dist/chunk-ISMGVGUM.cjs.map +1 -0
- package/dist/{chunk-JYYQQEBH.cjs → chunk-IWB65P37.cjs} +241 -4
- package/dist/chunk-IWB65P37.cjs.map +1 -0
- package/dist/{chunk-MV7KHWUT.js → chunk-IWQDBVJK.js} +25 -4
- package/dist/chunk-IWQDBVJK.js.map +1 -0
- package/dist/{chunk-XEVG546F.js → chunk-JXESKY4A.js} +3 -3
- package/dist/{chunk-XEVG546F.js.map → chunk-JXESKY4A.js.map} +1 -1
- package/dist/{chunk-7AHYOMHJ.js → chunk-KEURQGCQ.js} +40 -5
- package/dist/chunk-KEURQGCQ.js.map +1 -0
- package/dist/{chunk-JPGVRWWL.js → chunk-MDKPL2R2.js} +470 -124
- package/dist/chunk-MDKPL2R2.js.map +1 -0
- package/dist/{chunk-UIZSWUKP.js → chunk-NZAXAFI3.js} +104 -6
- package/dist/chunk-NZAXAFI3.js.map +1 -0
- package/dist/{chunk-VOY2RXOC.cjs → chunk-O6NA3Z43.cjs} +6 -6
- package/dist/{chunk-VOY2RXOC.cjs.map → chunk-O6NA3Z43.cjs.map} +1 -1
- package/dist/chunk-PE3V7GUL.cjs +4 -0
- package/dist/{chunk-LJFJTTZQ.cjs.map → chunk-PE3V7GUL.cjs.map} +1 -1
- package/dist/{chunk-I4CXL4SR.js → chunk-RXDJL5QT.js} +5 -4
- package/dist/chunk-RXDJL5QT.js.map +1 -0
- package/dist/{chunk-LWBQ4P4N.cjs → chunk-S6OEQHEI.cjs} +62 -614
- package/dist/chunk-S6OEQHEI.cjs.map +1 -0
- package/dist/{chunk-7PO6SEJF.js → chunk-U7VECK2G.js} +240 -3
- package/dist/chunk-U7VECK2G.js.map +1 -0
- package/dist/{chunk-ECFXGXWO.cjs → chunk-VSM3NLUX.cjs} +312 -210
- package/dist/chunk-VSM3NLUX.cjs.map +1 -0
- package/dist/{chunk-IQO7ANVS.cjs → chunk-VZC4BWWH.cjs} +10 -9
- package/dist/chunk-VZC4BWWH.cjs.map +1 -0
- package/dist/{chunk-JV2KH24V.js → chunk-W3DD3XP5.js} +312 -210
- package/dist/chunk-W3DD3XP5.js.map +1 -0
- package/dist/{chunk-GGYKYORQ.cjs → chunk-WQSGX6XA.cjs} +27 -6
- package/dist/chunk-WQSGX6XA.cjs.map +1 -0
- package/dist/{chunk-W7UH2PWL.js → chunk-WTYNK7Q4.js} +179 -282
- package/dist/chunk-WTYNK7Q4.js.map +1 -0
- package/dist/{chunk-7CBEP2ZQ.js → chunk-XXBWX7DT.js} +949 -197
- package/dist/chunk-XXBWX7DT.js.map +1 -0
- package/dist/{chunk-CB575O6L.cjs → chunk-ZCVTH3CH.cjs} +470 -130
- package/dist/chunk-ZCVTH3CH.cjs.map +1 -0
- package/dist/evals/base.d.ts.map +1 -1
- package/dist/evals/index.cjs +4 -4
- package/dist/evals/index.js +1 -1
- package/dist/evals/scoreTraces/index.cjs +5 -4
- package/dist/evals/scoreTraces/index.cjs.map +1 -1
- package/dist/evals/scoreTraces/index.js +3 -2
- package/dist/evals/scoreTraces/index.js.map +1 -1
- package/dist/evals/scoreTraces/scoreTracesWorkflow.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 +26 -10
- package/dist/llm/index.d.ts +1 -0
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +5 -1
- package/dist/llm/model/aisdk/v5/model.d.ts +47 -0
- package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -0
- package/dist/llm/model/gateways/base.d.ts +8 -0
- package/dist/llm/model/gateways/base.d.ts.map +1 -1
- package/dist/llm/model/gateways/models-dev.d.ts +1 -0
- package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
- package/dist/llm/model/gateways/netlify.d.ts +2 -1
- package/dist/llm/model/gateways/netlify.d.ts.map +1 -1
- package/dist/llm/model/is-v2-model.d.ts +3 -0
- package/dist/llm/model/is-v2-model.d.ts.map +1 -0
- package/dist/llm/model/model-method-from-agent.d.ts +4 -0
- package/dist/llm/model/model-method-from-agent.d.ts.map +1 -0
- 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 +2 -0
- package/dist/llm/model/model.loop.types.d.ts.map +1 -1
- package/dist/llm/model/provider-registry.d.ts +11 -1
- package/dist/llm/model/provider-registry.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +56 -7
- package/dist/llm/model/registry-generator.d.ts.map +1 -1
- package/dist/llm/model/resolve-model.d.ts +1 -1
- package/dist/llm/model/resolve-model.d.ts.map +1 -1
- package/dist/llm/model/router.d.ts +12 -5
- package/dist/llm/model/router.d.ts.map +1 -1
- package/dist/llm/model/shared.types.d.ts +10 -4
- package/dist/llm/model/shared.types.d.ts.map +1 -1
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts +37 -0
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts.map +1 -0
- package/dist/loop/test-utils/fullStream.d.ts.map +1 -1
- package/dist/loop/test-utils/generateText.d.ts.map +1 -1
- package/dist/loop/test-utils/options.d.ts.map +1 -1
- package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
- package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
- package/dist/loop/test-utils/textStream.d.ts.map +1 -1
- package/dist/loop/test-utils/toUIMessageStream.d.ts.map +1 -1
- package/dist/loop/test-utils/tools.d.ts.map +1 -1
- package/dist/loop/test-utils/utils.d.ts +1 -1
- package/dist/loop/test-utils/utils.d.ts.map +1 -1
- package/dist/loop/types.d.ts +8 -3
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +12 -12
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +9 -9
- 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 +4 -4
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +13 -12
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/loop/workflows/run-state.d.ts +2 -2
- package/dist/loop/workflows/run-state.d.ts.map +1 -1
- package/dist/loop/workflows/schema.d.ts +4 -4
- package/dist/loop/workflows/stream.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +127 -3
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +8 -8
- package/dist/memory/index.js +4 -4
- package/dist/models-dev-6PRLJKVZ.js +3 -0
- package/dist/{models-dev-DNBKXHT4.js.map → models-dev-6PRLJKVZ.js.map} +1 -1
- package/dist/models-dev-WHMI5G6Y.cjs +12 -0
- package/dist/{models-dev-YBEEQIX6.cjs.map → models-dev-WHMI5G6Y.cjs.map} +1 -1
- package/dist/netlify-46I3SNNV.cjs +12 -0
- package/dist/{netlify-GWNGSIRZ.cjs.map → netlify-46I3SNNV.cjs.map} +1 -1
- package/dist/netlify-EBQ6YUC6.js +3 -0
- package/dist/{netlify-7G2L5VSH.js.map → netlify-EBQ6YUC6.js.map} +1 -1
- package/dist/processors/index.cjs +11 -11
- package/dist/processors/index.js +1 -1
- package/dist/provider-registry-HDG6UMUC.js +3 -0
- package/dist/provider-registry-HDG6UMUC.js.map +1 -0
- package/dist/provider-registry-RP2W4B24.cjs +40 -0
- package/dist/provider-registry-RP2W4B24.cjs.map +1 -0
- package/dist/provider-registry.json +140 -18
- package/dist/{registry-generator-MK63POJO.cjs → registry-generator-JPCV47SC.cjs} +6 -4
- package/dist/registry-generator-JPCV47SC.cjs.map +1 -0
- package/dist/{registry-generator-H4YNODDH.js → registry-generator-XD4FPZTU.js} +6 -4
- package/dist/registry-generator-XD4FPZTU.js.map +1 -0
- package/dist/relevance/index.cjs +2 -2
- package/dist/relevance/index.js +1 -1
- package/dist/server/auth.d.ts +11 -0
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/index.cjs +12 -1
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +12 -1
- package/dist/server/index.js.map +1 -1
- package/dist/storage/domains/workflows/inmemory.d.ts +1 -1
- package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +29 -29
- package/dist/storage/index.js +1 -1
- package/dist/storage/types.d.ts +2 -1
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/RunOutput.d.ts +1 -1
- package/dist/stream/RunOutput.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/execute.d.ts +6 -3
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
- package/dist/stream/base/input.d.ts +1 -1
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +11 -11
- package/dist/stream/index.js +2 -2
- package/dist/stream/types.d.ts +4 -3
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.cjs +68 -31
- package/dist/test-utils/llm-mock.cjs.map +1 -1
- package/dist/test-utils/llm-mock.d.ts +4 -2
- package/dist/test-utils/llm-mock.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.js +67 -30
- package/dist/test-utils/llm-mock.js.map +1 -1
- package/dist/tools/index.cjs +4 -4
- package/dist/tools/index.js +1 -1
- package/dist/tools/is-vercel-tool.cjs +2 -2
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/tools/types.d.ts +1 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/validation.d.ts +12 -0
- package/dist/tools/validation.d.ts.map +1 -1
- package/dist/utils.cjs +25 -21
- package/dist/utils.d.ts +4 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/voice/aisdk/index.d.ts +3 -0
- package/dist/voice/aisdk/index.d.ts.map +1 -0
- package/dist/voice/aisdk/speech.d.ts +23 -0
- package/dist/voice/aisdk/speech.d.ts.map +1 -0
- package/dist/voice/aisdk/transcription.d.ts +22 -0
- package/dist/voice/aisdk/transcription.d.ts.map +1 -0
- package/dist/voice/composite-voice.d.ts +4 -3
- package/dist/voice/composite-voice.d.ts.map +1 -1
- package/dist/voice/index.cjs +12 -4
- package/dist/voice/index.d.ts +1 -0
- package/dist/voice/index.d.ts.map +1 -1
- package/dist/voice/index.js +1 -1
- package/dist/workflows/default.d.ts +24 -8
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/execution-engine.d.ts +3 -1
- 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/workflow-event-processor/index.d.ts +5 -4
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts +1 -1
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/parallel.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/parallel.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/sleep.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/sleep.d.ts.map +1 -1
- package/dist/workflows/evented/workflow.d.ts +2 -1
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/execution-engine.d.ts +4 -2
- package/dist/workflows/execution-engine.d.ts.map +1 -1
- package/dist/workflows/index.cjs +28 -16
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts +1 -0
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +54 -2
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/utils.d.ts +20 -0
- package/dist/workflows/utils.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +108 -40
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +19 -27
- package/src/llm/model/provider-types.generated.d.ts +56 -7
- package/dist/chunk-22443P6A.cjs.map +0 -1
- package/dist/chunk-2ZVKF4HP.cjs.map +0 -1
- package/dist/chunk-4CDL2QJT.js.map +0 -1
- package/dist/chunk-7AHYOMHJ.js.map +0 -1
- package/dist/chunk-7CBEP2ZQ.js.map +0 -1
- package/dist/chunk-7PO6SEJF.js.map +0 -1
- package/dist/chunk-CB575O6L.cjs.map +0 -1
- package/dist/chunk-ECFXGXWO.cjs.map +0 -1
- package/dist/chunk-ET6UOTTU.cjs.map +0 -1
- package/dist/chunk-GGYKYORQ.cjs.map +0 -1
- package/dist/chunk-HDJFSJCK.js.map +0 -1
- package/dist/chunk-I4CXL4SR.js.map +0 -1
- package/dist/chunk-IQO7ANVS.cjs.map +0 -1
- package/dist/chunk-JPGVRWWL.js.map +0 -1
- package/dist/chunk-JV2KH24V.js.map +0 -1
- package/dist/chunk-JYYQQEBH.cjs.map +0 -1
- package/dist/chunk-LJFJTTZQ.cjs +0 -4
- package/dist/chunk-LWBQ4P4N.cjs.map +0 -1
- package/dist/chunk-MV7KHWUT.js.map +0 -1
- package/dist/chunk-QUKUN6NR.cjs.map +0 -1
- package/dist/chunk-SNPVZPLB.js.map +0 -1
- package/dist/chunk-UIZSWUKP.js.map +0 -1
- package/dist/chunk-W7UH2PWL.js.map +0 -1
- package/dist/chunk-WM6CK2F3.cjs.map +0 -1
- package/dist/chunk-YCVEJ3UN.cjs.map +0 -1
- package/dist/chunk-ZGHTOYHW.js.map +0 -1
- package/dist/chunk-ZV5CC35D.js +0 -3
- package/dist/chunk-ZWNI5IWX.cjs.map +0 -1
- package/dist/models-dev-DNBKXHT4.js +0 -3
- package/dist/models-dev-YBEEQIX6.cjs +0 -12
- package/dist/netlify-7G2L5VSH.js +0 -3
- package/dist/netlify-GWNGSIRZ.cjs +0 -12
- package/dist/registry-generator-H4YNODDH.js.map +0 -1
- package/dist/registry-generator-MK63POJO.cjs.map +0 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkISMGVGUM_cjs = require('./chunk-ISMGVGUM.cjs');
|
|
4
4
|
var chunkABJOUEVA_cjs = require('./chunk-ABJOUEVA.cjs');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
5
|
+
var chunkVSM3NLUX_cjs = require('./chunk-VSM3NLUX.cjs');
|
|
6
|
+
var chunk3W5RQCCY_cjs = require('./chunk-3W5RQCCY.cjs');
|
|
7
|
+
var chunkO6NA3Z43_cjs = require('./chunk-O6NA3Z43.cjs');
|
|
8
8
|
var chunkMR7ZWBL6_cjs = require('./chunk-MR7ZWBL6.cjs');
|
|
9
|
-
var
|
|
9
|
+
var chunkHBJPYQRN_cjs = require('./chunk-HBJPYQRN.cjs');
|
|
10
10
|
var chunkE7K4FTLN_cjs = require('./chunk-E7K4FTLN.cjs');
|
|
11
11
|
var chunkTWH4PTDG_cjs = require('./chunk-TWH4PTDG.cjs');
|
|
12
12
|
var chunkLRSB62Z6_cjs = require('./chunk-LRSB62Z6.cjs');
|
|
13
|
-
var
|
|
13
|
+
var chunk4IKJAKCD_cjs = require('./chunk-4IKJAKCD.cjs');
|
|
14
14
|
var chunkJ7O6WENZ_cjs = require('./chunk-J7O6WENZ.cjs');
|
|
15
15
|
var chunk4WQYXT2I_cjs = require('./chunk-4WQYXT2I.cjs');
|
|
16
16
|
var chunkKEXGB7FK_cjs = require('./chunk-KEXGB7FK.cjs');
|
|
@@ -449,14 +449,22 @@ function prepareToolsAndToolChoice({
|
|
|
449
449
|
inputSchema: aiV5.asSchema(sdkTool.inputSchema).jsonSchema,
|
|
450
450
|
providerOptions: sdkTool.providerOptions
|
|
451
451
|
};
|
|
452
|
-
case "provider-defined":
|
|
452
|
+
case "provider-defined": {
|
|
453
|
+
const providerId = sdkTool.id;
|
|
454
|
+
let providerToolName = name;
|
|
455
|
+
if (providerId && providerId.includes(".")) {
|
|
456
|
+
providerToolName = providerId.split(".").slice(1).join(".");
|
|
457
|
+
} else if (providerId) {
|
|
458
|
+
providerToolName = providerId;
|
|
459
|
+
}
|
|
453
460
|
return {
|
|
454
461
|
type: "provider-defined",
|
|
455
|
-
name,
|
|
462
|
+
name: providerToolName,
|
|
456
463
|
// TODO: as any seems wrong here. are there cases where we don't have an id?
|
|
457
|
-
id:
|
|
464
|
+
id: providerId,
|
|
458
465
|
args: sdkTool.args
|
|
459
466
|
};
|
|
467
|
+
}
|
|
460
468
|
default: {
|
|
461
469
|
const exhaustiveCheck = toolType;
|
|
462
470
|
throw new Error(`Unsupported tool type: ${exhaustiveCheck}`);
|
|
@@ -543,6 +551,11 @@ function runScorer({
|
|
|
543
551
|
chunkMR7ZWBL6_cjs.executeHook("onScorerRun" /* ON_SCORER_RUN */, payload);
|
|
544
552
|
}
|
|
545
553
|
|
|
554
|
+
// src/llm/model/is-v2-model.ts
|
|
555
|
+
function isV2Model(model) {
|
|
556
|
+
return model.specificationVersion === "v2";
|
|
557
|
+
}
|
|
558
|
+
|
|
546
559
|
// src/stream/base/consume-stream.ts
|
|
547
560
|
async function consumeStream2({
|
|
548
561
|
stream,
|
|
@@ -599,7 +612,7 @@ var WorkflowRunOutput = class {
|
|
|
599
612
|
this.workflowId = workflowId;
|
|
600
613
|
this.#baseStream = stream;
|
|
601
614
|
stream.pipeTo(
|
|
602
|
-
new WritableStream({
|
|
615
|
+
new web.WritableStream({
|
|
603
616
|
start() {
|
|
604
617
|
const chunk = {
|
|
605
618
|
type: "workflow-start",
|
|
@@ -727,7 +740,7 @@ var WorkflowRunOutput = class {
|
|
|
727
740
|
};
|
|
728
741
|
const self = this;
|
|
729
742
|
stream.pipeTo(
|
|
730
|
-
new WritableStream({
|
|
743
|
+
new web.WritableStream({
|
|
731
744
|
start() {
|
|
732
745
|
const chunk = {
|
|
733
746
|
type: "workflow-start",
|
|
@@ -962,6 +975,24 @@ async function validateStepInput({
|
|
|
962
975
|
}
|
|
963
976
|
return { inputData, validationError };
|
|
964
977
|
}
|
|
978
|
+
async function validateStepResumeData({ resumeData, step }) {
|
|
979
|
+
if (!resumeData) {
|
|
980
|
+
return { resumeData: void 0, validationError: void 0 };
|
|
981
|
+
}
|
|
982
|
+
let validationError;
|
|
983
|
+
const resumeSchema = step.resumeSchema;
|
|
984
|
+
if (resumeSchema) {
|
|
985
|
+
const validatedResumeData = await resumeSchema.safeParseAsync(resumeData);
|
|
986
|
+
if (!validatedResumeData.success) {
|
|
987
|
+
const errors = getZodErrors(validatedResumeData.error);
|
|
988
|
+
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
989
|
+
validationError = new Error("Step resume data validation failed: \n" + errorMessages);
|
|
990
|
+
} else {
|
|
991
|
+
resumeData = validatedResumeData.data;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
return { resumeData, validationError };
|
|
995
|
+
}
|
|
965
996
|
function getResumeLabelsByStepId(resumeLabels, stepId) {
|
|
966
997
|
return Object.entries(resumeLabels).filter(([_, value]) => value.stepId === stepId).reduce(
|
|
967
998
|
(acc, [key, value]) => {
|
|
@@ -992,6 +1023,111 @@ function createDeprecationProxy(params, {
|
|
|
992
1023
|
}
|
|
993
1024
|
});
|
|
994
1025
|
}
|
|
1026
|
+
var getStepIds = (entry) => {
|
|
1027
|
+
if (entry.type === "step" || entry.type === "foreach" || entry.type === "loop") {
|
|
1028
|
+
return [entry.step.id];
|
|
1029
|
+
}
|
|
1030
|
+
if (entry.type === "parallel" || entry.type === "conditional") {
|
|
1031
|
+
return entry.steps.map((s) => s.step.id);
|
|
1032
|
+
}
|
|
1033
|
+
if (entry.type === "sleep" || entry.type === "sleepUntil") {
|
|
1034
|
+
return [entry.id];
|
|
1035
|
+
}
|
|
1036
|
+
return [];
|
|
1037
|
+
};
|
|
1038
|
+
var createTimeTravelExecutionParams = (params) => {
|
|
1039
|
+
const { steps, inputData, resumeData, context, nestedStepsContext, snapshot, initialState, graph } = params;
|
|
1040
|
+
const firstStepId = steps[0];
|
|
1041
|
+
let executionPath = [];
|
|
1042
|
+
const stepResults = {};
|
|
1043
|
+
const snapshotContext = snapshot.context;
|
|
1044
|
+
for (const [index, entry] of graph.steps.entries()) {
|
|
1045
|
+
const currentExecPathLength = executionPath.length;
|
|
1046
|
+
if (currentExecPathLength > 0 && !resumeData) {
|
|
1047
|
+
break;
|
|
1048
|
+
}
|
|
1049
|
+
const stepIds = getStepIds(entry);
|
|
1050
|
+
if (stepIds.includes(firstStepId)) {
|
|
1051
|
+
const innerExecutionPath = stepIds?.length > 1 ? [stepIds?.findIndex((s) => s === firstStepId)] : [];
|
|
1052
|
+
executionPath = [index, ...innerExecutionPath];
|
|
1053
|
+
}
|
|
1054
|
+
const prevStep = graph.steps[index - 1];
|
|
1055
|
+
let stepPayload = void 0;
|
|
1056
|
+
if (prevStep) {
|
|
1057
|
+
const prevStepIds = getStepIds(prevStep);
|
|
1058
|
+
if (prevStepIds.length > 0) {
|
|
1059
|
+
if (prevStepIds.length === 1) {
|
|
1060
|
+
stepPayload = stepResults?.[prevStepIds[0]]?.output ?? {};
|
|
1061
|
+
} else {
|
|
1062
|
+
stepPayload = prevStepIds.reduce(
|
|
1063
|
+
(acc, stepId) => {
|
|
1064
|
+
acc[stepId] = stepResults?.[stepId]?.output ?? {};
|
|
1065
|
+
return acc;
|
|
1066
|
+
},
|
|
1067
|
+
{}
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
if (index === 0 && stepIds.includes(firstStepId)) {
|
|
1073
|
+
stepResults.input = context?.[firstStepId]?.payload ?? inputData ?? snapshotContext?.input;
|
|
1074
|
+
} else if (index === 0) {
|
|
1075
|
+
stepResults.input = stepIds?.reduce((acc, stepId) => {
|
|
1076
|
+
if (acc) return acc;
|
|
1077
|
+
return context?.[stepId]?.payload ?? snapshotContext?.[stepId]?.payload;
|
|
1078
|
+
}, null) ?? snapshotContext?.input ?? {};
|
|
1079
|
+
}
|
|
1080
|
+
let stepOutput = void 0;
|
|
1081
|
+
const nextStep = graph.steps[index + 1];
|
|
1082
|
+
if (nextStep) {
|
|
1083
|
+
const nextStepIds = getStepIds(nextStep);
|
|
1084
|
+
if (nextStepIds.length > 0 && inputData && nextStepIds.includes(firstStepId) && steps.length === 1) {
|
|
1085
|
+
stepOutput = inputData;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
stepIds.forEach((stepId) => {
|
|
1089
|
+
let result;
|
|
1090
|
+
const stepContext = context?.[stepId] ?? snapshotContext[stepId];
|
|
1091
|
+
const defaultStepStatus = steps?.includes(stepId) ? "running" : "success";
|
|
1092
|
+
const status = ["failed", "canceled"].includes(stepContext?.status) ? defaultStepStatus : stepContext?.status ?? defaultStepStatus;
|
|
1093
|
+
const isCompleteStatus = ["success", "failed", "canceled"].includes(status);
|
|
1094
|
+
result = {
|
|
1095
|
+
status,
|
|
1096
|
+
payload: context?.[stepId]?.payload ?? stepPayload ?? snapshotContext[stepId]?.payload ?? {},
|
|
1097
|
+
output: isCompleteStatus ? context?.[stepId]?.output ?? stepOutput ?? snapshotContext[stepId]?.output ?? {} : void 0,
|
|
1098
|
+
resumePayload: stepContext?.resumePayload,
|
|
1099
|
+
suspendPayload: stepContext?.suspendPayload,
|
|
1100
|
+
suspendOutput: stepContext?.suspendOutput,
|
|
1101
|
+
startedAt: stepContext?.startedAt ?? Date.now(),
|
|
1102
|
+
endedAt: isCompleteStatus ? stepContext?.endedAt ?? Date.now() : void 0,
|
|
1103
|
+
suspendedAt: stepContext?.suspendedAt,
|
|
1104
|
+
resumedAt: stepContext?.resumedAt
|
|
1105
|
+
};
|
|
1106
|
+
if (currentExecPathLength > 0 && (!snapshotContext[stepId] || snapshotContext[stepId] && snapshotContext[stepId].status !== "suspended")) {
|
|
1107
|
+
result = void 0;
|
|
1108
|
+
}
|
|
1109
|
+
if (result) {
|
|
1110
|
+
const formattedResult = chunkHBJPYQRN_cjs.removeUndefinedValues(result);
|
|
1111
|
+
stepResults[stepId] = formattedResult;
|
|
1112
|
+
}
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
if (!executionPath.length) {
|
|
1116
|
+
throw new Error(
|
|
1117
|
+
`Time travel target step not found in execution graph: '${steps?.join(".")}'. Verify the step id/path.`
|
|
1118
|
+
);
|
|
1119
|
+
}
|
|
1120
|
+
const timeTravelData = {
|
|
1121
|
+
inputData,
|
|
1122
|
+
executionPath,
|
|
1123
|
+
steps,
|
|
1124
|
+
stepResults,
|
|
1125
|
+
nestedStepResults: nestedStepsContext,
|
|
1126
|
+
state: initialState ?? snapshot.value ?? {},
|
|
1127
|
+
resumeData
|
|
1128
|
+
};
|
|
1129
|
+
return timeTravelData;
|
|
1130
|
+
};
|
|
995
1131
|
|
|
996
1132
|
// src/workflows/default.ts
|
|
997
1133
|
var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
@@ -1078,7 +1214,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1078
1214
|
resume,
|
|
1079
1215
|
retryConfig,
|
|
1080
1216
|
workflowSpan,
|
|
1081
|
-
disableScorers
|
|
1217
|
+
disableScorers,
|
|
1218
|
+
restart,
|
|
1219
|
+
timeTravel
|
|
1082
1220
|
} = params;
|
|
1083
1221
|
const { attempts = 0, delay: delay2 = 0 } = retryConfig ?? {};
|
|
1084
1222
|
const steps = graph.steps;
|
|
@@ -1094,19 +1232,26 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1094
1232
|
throw empty_graph_error;
|
|
1095
1233
|
}
|
|
1096
1234
|
let startIdx = 0;
|
|
1097
|
-
if (
|
|
1235
|
+
if (timeTravel) {
|
|
1236
|
+
startIdx = timeTravel.executionPath[0];
|
|
1237
|
+
timeTravel.executionPath.shift();
|
|
1238
|
+
} else if (restart) {
|
|
1239
|
+
startIdx = restart.activePaths[0];
|
|
1240
|
+
restart.activePaths.shift();
|
|
1241
|
+
} else if (resume?.resumePath) {
|
|
1098
1242
|
startIdx = resume.resumePath[0];
|
|
1099
1243
|
resume.resumePath.shift();
|
|
1100
1244
|
}
|
|
1101
|
-
const stepResults = resume?.stepResults || { input };
|
|
1245
|
+
const stepResults = timeTravel?.stepResults || restart?.stepResults || resume?.stepResults || { input };
|
|
1102
1246
|
let lastOutput;
|
|
1103
|
-
let lastState = initialState ?? {};
|
|
1247
|
+
let lastState = timeTravel?.state ?? restart?.state ?? initialState ?? {};
|
|
1104
1248
|
for (let i = startIdx; i < steps.length; i++) {
|
|
1105
1249
|
const entry = steps[i];
|
|
1106
1250
|
const executionContext = {
|
|
1107
1251
|
workflowId,
|
|
1108
1252
|
runId,
|
|
1109
1253
|
executionPath: [i],
|
|
1254
|
+
activeStepsPath: {},
|
|
1110
1255
|
suspendedPaths: {},
|
|
1111
1256
|
resumeLabels: {},
|
|
1112
1257
|
retryConfig: { attempts, delay: delay2 },
|
|
@@ -1124,6 +1269,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1124
1269
|
prevStep: steps[i - 1],
|
|
1125
1270
|
stepResults,
|
|
1126
1271
|
resume,
|
|
1272
|
+
timeTravel,
|
|
1273
|
+
restart,
|
|
1127
1274
|
tracingContext: {
|
|
1128
1275
|
currentSpan: workflowSpan
|
|
1129
1276
|
},
|
|
@@ -1413,7 +1560,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1413
1560
|
step,
|
|
1414
1561
|
stepResults,
|
|
1415
1562
|
executionContext,
|
|
1563
|
+
restart,
|
|
1416
1564
|
resume,
|
|
1565
|
+
timeTravel,
|
|
1417
1566
|
prevOutput,
|
|
1418
1567
|
emitter,
|
|
1419
1568
|
abortController,
|
|
@@ -1425,22 +1574,38 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1425
1574
|
tracingContext,
|
|
1426
1575
|
iterationCount
|
|
1427
1576
|
}) {
|
|
1428
|
-
const startTime = resume?.steps[0] === step.id ? void 0 : Date.now();
|
|
1429
|
-
const resumeTime = resume?.steps[0] === step.id ? Date.now() : void 0;
|
|
1430
1577
|
const stepCallId = crypto2.randomUUID();
|
|
1431
1578
|
const { inputData, validationError } = await validateStepInput({
|
|
1432
1579
|
prevOutput,
|
|
1433
1580
|
step,
|
|
1434
|
-
validateInputs: this.options?.validateInputs ??
|
|
1581
|
+
validateInputs: this.options?.validateInputs ?? true
|
|
1582
|
+
});
|
|
1583
|
+
const { resumeData: timeTravelResumeData, validationError: timeTravelResumeValidationError } = await validateStepResumeData({
|
|
1584
|
+
resumeData: timeTravel?.stepResults[step.id]?.status === "suspended" ? timeTravel?.resumeData : void 0,
|
|
1585
|
+
step
|
|
1435
1586
|
});
|
|
1587
|
+
let resumeDataToUse;
|
|
1588
|
+
if (timeTravelResumeData && !timeTravelResumeValidationError) {
|
|
1589
|
+
resumeDataToUse = timeTravelResumeData;
|
|
1590
|
+
} else if (timeTravelResumeData && timeTravelResumeValidationError) {
|
|
1591
|
+
this.logger.warn("Time travel resume data validation failed", {
|
|
1592
|
+
stepId: step.id,
|
|
1593
|
+
error: timeTravelResumeValidationError.message
|
|
1594
|
+
});
|
|
1595
|
+
} else if (resume?.steps[0] === step.id) {
|
|
1596
|
+
resumeDataToUse = resume?.resumePayload;
|
|
1597
|
+
}
|
|
1598
|
+
const startTime = resumeDataToUse ? void 0 : Date.now();
|
|
1599
|
+
const resumeTime = resumeDataToUse ? Date.now() : void 0;
|
|
1436
1600
|
const stepInfo = {
|
|
1437
1601
|
...stepResults[step.id],
|
|
1438
|
-
...
|
|
1602
|
+
...resumeDataToUse ? { resumePayload: resumeDataToUse } : { payload: inputData },
|
|
1439
1603
|
...startTime ? { startedAt: startTime } : {},
|
|
1440
1604
|
...resumeTime ? { resumedAt: resumeTime } : {},
|
|
1441
1605
|
status: "running",
|
|
1442
1606
|
...iterationCount ? { metadata: { iterationCount } } : {}
|
|
1443
1607
|
};
|
|
1608
|
+
executionContext.activeStepsPath[step.id] = executionContext.executionPath;
|
|
1444
1609
|
const stepSpan = tracingContext.currentSpan?.createChildSpan({
|
|
1445
1610
|
name: `workflow step: '${step.id}'`,
|
|
1446
1611
|
type: "workflow_step" /* WORKFLOW_STEP */,
|
|
@@ -1495,6 +1660,10 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1495
1660
|
throw validationError;
|
|
1496
1661
|
}
|
|
1497
1662
|
const retryCount = this.getOrGenerateRetryCount(step.id);
|
|
1663
|
+
let timeTravelSteps = [];
|
|
1664
|
+
if (timeTravel && timeTravel.steps.length > 0) {
|
|
1665
|
+
timeTravelSteps = timeTravel.steps[0] === step.id ? timeTravel.steps.slice(1) : [];
|
|
1666
|
+
}
|
|
1498
1667
|
const result = await runStep({
|
|
1499
1668
|
runId,
|
|
1500
1669
|
resourceId,
|
|
@@ -1507,7 +1676,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1507
1676
|
executionContext.state = state;
|
|
1508
1677
|
},
|
|
1509
1678
|
retryCount,
|
|
1510
|
-
resumeData:
|
|
1679
|
+
resumeData: resumeDataToUse,
|
|
1511
1680
|
tracingContext: { currentSpan: stepSpan },
|
|
1512
1681
|
getInitData: () => stepResults?.input,
|
|
1513
1682
|
getStepResult: getStepResult.bind(this, stepResults),
|
|
@@ -1540,6 +1709,15 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1540
1709
|
label: resume?.label,
|
|
1541
1710
|
forEachIndex: resume?.forEachIndex
|
|
1542
1711
|
} : void 0,
|
|
1712
|
+
// Only pass restart data if this step is part of activeStepsPath
|
|
1713
|
+
// This prevents pending nested workflows from trying to restart instead of start
|
|
1714
|
+
restart: !!restart?.activeStepsPath?.[step.id],
|
|
1715
|
+
timeTravel: timeTravelSteps.length > 0 ? {
|
|
1716
|
+
inputData: timeTravel?.inputData,
|
|
1717
|
+
steps: timeTravelSteps,
|
|
1718
|
+
nestedStepResults: timeTravel?.nestedStepResults,
|
|
1719
|
+
resumeData: timeTravel?.resumeData
|
|
1720
|
+
} : void 0,
|
|
1543
1721
|
[chunkABJOUEVA_cjs.EMITTER_SYMBOL]: emitter,
|
|
1544
1722
|
[chunkABJOUEVA_cjs.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1545
1723
|
engine: {},
|
|
@@ -1611,6 +1789,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1611
1789
|
};
|
|
1612
1790
|
}
|
|
1613
1791
|
}
|
|
1792
|
+
delete executionContext.activeStepsPath[step.id];
|
|
1614
1793
|
if (!skipEmits) {
|
|
1615
1794
|
if (execResults.status === "suspended") {
|
|
1616
1795
|
await emitter.emit("watch", {
|
|
@@ -1714,6 +1893,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1714
1893
|
serializedStepGraph,
|
|
1715
1894
|
stepResults,
|
|
1716
1895
|
resume,
|
|
1896
|
+
restart,
|
|
1897
|
+
timeTravel,
|
|
1717
1898
|
executionContext,
|
|
1718
1899
|
tracingContext,
|
|
1719
1900
|
emitter,
|
|
@@ -1733,22 +1914,38 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1733
1914
|
tracingPolicy: this.options?.tracingPolicy
|
|
1734
1915
|
});
|
|
1735
1916
|
const prevOutput = this.getStepOutput(stepResults, prevStep);
|
|
1736
|
-
for (const step of entry.steps) {
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
stepResults[step.step.id] = {
|
|
1741
|
-
...stepResults[step.step.id],
|
|
1742
|
-
status: "running",
|
|
1743
|
-
...resumeTime ? { resumePayload: resume?.resumePayload } : { payload: prevOutput },
|
|
1744
|
-
...startTime ? { startedAt: startTime } : {},
|
|
1745
|
-
...resumeTime ? { resumedAt: resumeTime } : {}
|
|
1746
|
-
};
|
|
1917
|
+
for (const [stepIndex, step] of entry.steps.entries()) {
|
|
1918
|
+
let makeStepRunning = true;
|
|
1919
|
+
if (restart) {
|
|
1920
|
+
makeStepRunning = !!restart.activeStepsPath[step.step.id];
|
|
1747
1921
|
}
|
|
1922
|
+
if (timeTravel && timeTravel.executionPath.length > 0) {
|
|
1923
|
+
makeStepRunning = timeTravel.steps[0] === step.step.id;
|
|
1924
|
+
}
|
|
1925
|
+
if (!makeStepRunning) {
|
|
1926
|
+
continue;
|
|
1927
|
+
}
|
|
1928
|
+
const startTime = resume?.steps[0] === step.step.id ? void 0 : Date.now();
|
|
1929
|
+
const resumeTime = resume?.steps[0] === step.step.id ? Date.now() : void 0;
|
|
1930
|
+
stepResults[step.step.id] = {
|
|
1931
|
+
...stepResults[step.step.id],
|
|
1932
|
+
status: "running",
|
|
1933
|
+
...resumeTime ? { resumePayload: resume?.resumePayload } : { payload: prevOutput },
|
|
1934
|
+
...startTime ? { startedAt: startTime } : {},
|
|
1935
|
+
...resumeTime ? { resumedAt: resumeTime } : {}
|
|
1936
|
+
};
|
|
1937
|
+
executionContext.activeStepsPath[step.step.id] = [...executionContext.executionPath, stepIndex];
|
|
1938
|
+
}
|
|
1939
|
+
if (timeTravel && timeTravel.executionPath.length > 0) {
|
|
1940
|
+
timeTravel.executionPath.shift();
|
|
1748
1941
|
}
|
|
1749
1942
|
let execResults;
|
|
1750
1943
|
const results = await Promise.all(
|
|
1751
1944
|
entry.steps.map(async (step, i) => {
|
|
1945
|
+
const currStepResult = stepResults[step.step.id];
|
|
1946
|
+
if (currStepResult && currStepResult.status !== "running") {
|
|
1947
|
+
return currStepResult;
|
|
1948
|
+
}
|
|
1752
1949
|
const result = await this.executeStep({
|
|
1753
1950
|
workflowId,
|
|
1754
1951
|
runId,
|
|
@@ -1757,8 +1954,11 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1757
1954
|
prevOutput,
|
|
1758
1955
|
stepResults,
|
|
1759
1956
|
serializedStepGraph,
|
|
1957
|
+
restart,
|
|
1958
|
+
timeTravel,
|
|
1760
1959
|
resume,
|
|
1761
1960
|
executionContext: {
|
|
1961
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
1762
1962
|
workflowId,
|
|
1763
1963
|
runId,
|
|
1764
1964
|
executionPath: [...executionContext.executionPath, i],
|
|
@@ -1823,6 +2023,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1823
2023
|
serializedStepGraph,
|
|
1824
2024
|
stepResults,
|
|
1825
2025
|
resume,
|
|
2026
|
+
restart,
|
|
2027
|
+
timeTravel,
|
|
1826
2028
|
executionContext,
|
|
1827
2029
|
tracingContext,
|
|
1828
2030
|
emitter,
|
|
@@ -1938,7 +2140,13 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1938
2140
|
const results = await Promise.all(
|
|
1939
2141
|
stepsToRun.map(async (step, index) => {
|
|
1940
2142
|
const currStepResult = stepResults[step.step.id];
|
|
1941
|
-
|
|
2143
|
+
const isRestartStep = restart ? !!restart.activeStepsPath[step.step.id] : void 0;
|
|
2144
|
+
if (currStepResult && timeTravel && timeTravel.executionPath.length > 0) {
|
|
2145
|
+
if (timeTravel.steps[0] !== step.step.id) {
|
|
2146
|
+
return currStepResult;
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
if (currStepResult && ["success", "failed"].includes(currStepResult.status) && isRestartStep === void 0) {
|
|
1942
2150
|
return currStepResult;
|
|
1943
2151
|
}
|
|
1944
2152
|
const result = await this.executeStep({
|
|
@@ -1950,10 +2158,13 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1950
2158
|
stepResults,
|
|
1951
2159
|
serializedStepGraph,
|
|
1952
2160
|
resume,
|
|
2161
|
+
restart,
|
|
2162
|
+
timeTravel,
|
|
1953
2163
|
executionContext: {
|
|
1954
2164
|
workflowId,
|
|
1955
2165
|
runId,
|
|
1956
2166
|
executionPath: [...executionContext.executionPath, index],
|
|
2167
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
1957
2168
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1958
2169
|
resumeLabels: executionContext.resumeLabels,
|
|
1959
2170
|
retryConfig: executionContext.retryConfig,
|
|
@@ -2015,6 +2226,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2015
2226
|
prevOutput,
|
|
2016
2227
|
stepResults,
|
|
2017
2228
|
resume,
|
|
2229
|
+
restart,
|
|
2230
|
+
timeTravel,
|
|
2018
2231
|
executionContext,
|
|
2019
2232
|
tracingContext,
|
|
2020
2233
|
emitter,
|
|
@@ -2040,6 +2253,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2040
2253
|
const prevPayload = stepResults[step.id]?.payload;
|
|
2041
2254
|
let result = { status: "success", output: prevPayload ?? prevOutput };
|
|
2042
2255
|
let currentResume = resume;
|
|
2256
|
+
let currentRestart = restart;
|
|
2257
|
+
let currentTimeTravel = timeTravel;
|
|
2043
2258
|
do {
|
|
2044
2259
|
result = await this.executeStep({
|
|
2045
2260
|
workflowId,
|
|
@@ -2048,7 +2263,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2048
2263
|
step,
|
|
2049
2264
|
stepResults,
|
|
2050
2265
|
executionContext,
|
|
2266
|
+
restart: currentRestart,
|
|
2051
2267
|
resume: currentResume,
|
|
2268
|
+
timeTravel: currentTimeTravel,
|
|
2052
2269
|
prevOutput: result.output,
|
|
2053
2270
|
tracingContext: {
|
|
2054
2271
|
currentSpan: loopSpan
|
|
@@ -2061,6 +2278,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2061
2278
|
serializedStepGraph,
|
|
2062
2279
|
iterationCount: iteration + 1
|
|
2063
2280
|
});
|
|
2281
|
+
currentRestart = void 0;
|
|
2282
|
+
currentTimeTravel = void 0;
|
|
2064
2283
|
if (currentResume && result.status !== "suspended") {
|
|
2065
2284
|
currentResume = void 0;
|
|
2066
2285
|
}
|
|
@@ -2075,7 +2294,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2075
2294
|
const evalSpan = loopSpan?.createChildSpan({
|
|
2076
2295
|
type: "workflow_conditional_eval" /* WORKFLOW_CONDITIONAL_EVAL */,
|
|
2077
2296
|
name: `condition: '${entry.loopType}'`,
|
|
2078
|
-
input:
|
|
2297
|
+
input: chunkHBJPYQRN_cjs.selectFields(result.output, ["stepResult", "output.text", "output.object", "messages"]),
|
|
2079
2298
|
attributes: {
|
|
2080
2299
|
conditionIndex: iteration
|
|
2081
2300
|
},
|
|
@@ -2148,7 +2367,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2148
2367
|
entry,
|
|
2149
2368
|
prevOutput,
|
|
2150
2369
|
stepResults,
|
|
2370
|
+
restart,
|
|
2151
2371
|
resume,
|
|
2372
|
+
timeTravel,
|
|
2152
2373
|
executionContext,
|
|
2153
2374
|
tracingContext,
|
|
2154
2375
|
emitter,
|
|
@@ -2217,6 +2438,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2217
2438
|
resourceId,
|
|
2218
2439
|
step,
|
|
2219
2440
|
stepResults,
|
|
2441
|
+
restart,
|
|
2442
|
+
timeTravel,
|
|
2220
2443
|
executionContext: { ...executionContext, foreachIndex: k },
|
|
2221
2444
|
resume: resumeToUse,
|
|
2222
2445
|
prevOutput: item,
|
|
@@ -2350,7 +2573,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2350
2573
|
status: workflowStatus,
|
|
2351
2574
|
value: executionContext.state,
|
|
2352
2575
|
context: stepResults,
|
|
2353
|
-
activePaths:
|
|
2576
|
+
activePaths: executionContext.executionPath,
|
|
2577
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
2354
2578
|
serializedStepGraph,
|
|
2355
2579
|
suspendedPaths: executionContext.suspendedPaths,
|
|
2356
2580
|
waitingPaths: {},
|
|
@@ -2371,6 +2595,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2371
2595
|
prevStep,
|
|
2372
2596
|
serializedStepGraph,
|
|
2373
2597
|
stepResults,
|
|
2598
|
+
restart,
|
|
2599
|
+
timeTravel,
|
|
2374
2600
|
resume,
|
|
2375
2601
|
executionContext,
|
|
2376
2602
|
tracingContext,
|
|
@@ -2391,6 +2617,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2391
2617
|
step,
|
|
2392
2618
|
stepResults,
|
|
2393
2619
|
executionContext,
|
|
2620
|
+
timeTravel,
|
|
2621
|
+
restart,
|
|
2394
2622
|
resume,
|
|
2395
2623
|
prevOutput,
|
|
2396
2624
|
tracingContext,
|
|
@@ -2419,6 +2647,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2419
2647
|
suspendedPaths: executionContext.suspendedPaths,
|
|
2420
2648
|
resumeLabels: executionContext.resumeLabels,
|
|
2421
2649
|
retryConfig: executionContext.retryConfig,
|
|
2650
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
2422
2651
|
state: executionContext.state
|
|
2423
2652
|
},
|
|
2424
2653
|
tracingContext,
|
|
@@ -2498,6 +2727,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2498
2727
|
prevStep,
|
|
2499
2728
|
stepResults,
|
|
2500
2729
|
serializedStepGraph,
|
|
2730
|
+
timeTravel,
|
|
2731
|
+
restart,
|
|
2501
2732
|
resume,
|
|
2502
2733
|
executionContext,
|
|
2503
2734
|
tracingContext,
|
|
@@ -2515,6 +2746,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2515
2746
|
prevOutput,
|
|
2516
2747
|
stepResults,
|
|
2517
2748
|
serializedStepGraph,
|
|
2749
|
+
timeTravel,
|
|
2750
|
+
restart,
|
|
2518
2751
|
resume,
|
|
2519
2752
|
executionContext,
|
|
2520
2753
|
tracingContext,
|
|
@@ -2532,6 +2765,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2532
2765
|
prevStep,
|
|
2533
2766
|
prevOutput,
|
|
2534
2767
|
stepResults,
|
|
2768
|
+
timeTravel,
|
|
2769
|
+
restart,
|
|
2535
2770
|
resume,
|
|
2536
2771
|
executionContext,
|
|
2537
2772
|
tracingContext,
|
|
@@ -2550,6 +2785,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2550
2785
|
prevStep,
|
|
2551
2786
|
prevOutput,
|
|
2552
2787
|
stepResults,
|
|
2788
|
+
timeTravel,
|
|
2789
|
+
restart,
|
|
2553
2790
|
resume,
|
|
2554
2791
|
executionContext,
|
|
2555
2792
|
tracingContext,
|
|
@@ -2571,6 +2808,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2571
2808
|
status: "waiting"
|
|
2572
2809
|
}
|
|
2573
2810
|
});
|
|
2811
|
+
stepResults[entry.id] = {
|
|
2812
|
+
status: "waiting",
|
|
2813
|
+
payload: prevOutput,
|
|
2814
|
+
startedAt
|
|
2815
|
+
};
|
|
2816
|
+
executionContext.activeStepsPath[entry.id] = executionContext.executionPath;
|
|
2574
2817
|
await this.persistStepUpdate({
|
|
2575
2818
|
workflowId,
|
|
2576
2819
|
runId,
|
|
@@ -2597,6 +2840,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2597
2840
|
requestContext,
|
|
2598
2841
|
writableStream
|
|
2599
2842
|
});
|
|
2843
|
+
delete executionContext.activeStepsPath[entry.id];
|
|
2600
2844
|
await this.persistStepUpdate({
|
|
2601
2845
|
workflowId,
|
|
2602
2846
|
runId,
|
|
@@ -2642,6 +2886,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2642
2886
|
status: "waiting"
|
|
2643
2887
|
}
|
|
2644
2888
|
});
|
|
2889
|
+
stepResults[entry.id] = {
|
|
2890
|
+
status: "waiting",
|
|
2891
|
+
payload: prevOutput,
|
|
2892
|
+
startedAt
|
|
2893
|
+
};
|
|
2894
|
+
executionContext.activeStepsPath[entry.id] = executionContext.executionPath;
|
|
2645
2895
|
await this.persistStepUpdate({
|
|
2646
2896
|
workflowId,
|
|
2647
2897
|
runId,
|
|
@@ -2668,6 +2918,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2668
2918
|
requestContext,
|
|
2669
2919
|
writableStream
|
|
2670
2920
|
});
|
|
2921
|
+
delete executionContext.activeStepsPath[entry.id];
|
|
2671
2922
|
await this.persistStepUpdate({
|
|
2672
2923
|
workflowId,
|
|
2673
2924
|
runId,
|
|
@@ -2828,7 +3079,7 @@ function createStep(params, agentOptions) {
|
|
|
2828
3079
|
component: params.component
|
|
2829
3080
|
};
|
|
2830
3081
|
}
|
|
2831
|
-
if (params instanceof
|
|
3082
|
+
if (params instanceof chunk4IKJAKCD_cjs.Tool) {
|
|
2832
3083
|
if (!params.inputSchema || !params.outputSchema) {
|
|
2833
3084
|
throw new Error("Tool must have input and output schemas defined");
|
|
2834
3085
|
}
|
|
@@ -2888,8 +3139,12 @@ function cloneStep(step, opts) {
|
|
|
2888
3139
|
description: step.description,
|
|
2889
3140
|
inputSchema: step.inputSchema,
|
|
2890
3141
|
outputSchema: step.outputSchema,
|
|
3142
|
+
suspendSchema: step.suspendSchema,
|
|
3143
|
+
resumeSchema: step.resumeSchema,
|
|
3144
|
+
stateSchema: step.stateSchema,
|
|
2891
3145
|
execute: step.execute,
|
|
2892
3146
|
retries: step.retries,
|
|
3147
|
+
scorers: step.scorers,
|
|
2893
3148
|
component: step.component
|
|
2894
3149
|
};
|
|
2895
3150
|
}
|
|
@@ -2902,7 +3157,8 @@ function cloneWorkflow(workflow, opts) {
|
|
|
2902
3157
|
inputSchema: workflow.inputSchema,
|
|
2903
3158
|
outputSchema: workflow.outputSchema,
|
|
2904
3159
|
steps: workflow.stepDefs,
|
|
2905
|
-
mastra: workflow.mastra
|
|
3160
|
+
mastra: workflow.mastra,
|
|
3161
|
+
options: workflow.options
|
|
2906
3162
|
});
|
|
2907
3163
|
wf.setStepFlow(workflow.stepGraph);
|
|
2908
3164
|
wf.commit();
|
|
@@ -2916,6 +3172,8 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
2916
3172
|
stateSchema;
|
|
2917
3173
|
steps;
|
|
2918
3174
|
stepDefs;
|
|
3175
|
+
engineType = "default";
|
|
3176
|
+
#nestedWorkflowInput;
|
|
2919
3177
|
committed = false;
|
|
2920
3178
|
stepFlow;
|
|
2921
3179
|
serializedStepFlow;
|
|
@@ -2951,7 +3209,7 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
2951
3209
|
this.steps = {};
|
|
2952
3210
|
this.stepDefs = steps;
|
|
2953
3211
|
this.#options = {
|
|
2954
|
-
validateInputs: options.validateInputs ??
|
|
3212
|
+
validateInputs: options.validateInputs ?? true,
|
|
2955
3213
|
shouldPersistSnapshot: options.shouldPersistSnapshot ?? (() => true),
|
|
2956
3214
|
tracingPolicy: options.tracingPolicy
|
|
2957
3215
|
};
|
|
@@ -2963,6 +3221,7 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
2963
3221
|
} else {
|
|
2964
3222
|
this.executionEngine = executionEngine;
|
|
2965
3223
|
}
|
|
3224
|
+
this.engineType = "default";
|
|
2966
3225
|
this.#runs = /* @__PURE__ */ new Map();
|
|
2967
3226
|
}
|
|
2968
3227
|
get runs() {
|
|
@@ -3322,7 +3581,8 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
3322
3581
|
cleanup: () => this.#runs.delete(runIdToUse),
|
|
3323
3582
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
3324
3583
|
workflowSteps: this.steps,
|
|
3325
|
-
validateInputs: this.#options?.validateInputs
|
|
3584
|
+
validateInputs: this.#options?.validateInputs,
|
|
3585
|
+
workflowEngineType: this.engineType
|
|
3326
3586
|
});
|
|
3327
3587
|
this.#runs.set(runIdToUse, run);
|
|
3328
3588
|
const shouldPersistSnapshot = this.#options.shouldPersistSnapshot({
|
|
@@ -3339,8 +3599,9 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
3339
3599
|
runId: runIdToUse,
|
|
3340
3600
|
status: "pending",
|
|
3341
3601
|
value: {},
|
|
3342
|
-
context: {},
|
|
3602
|
+
context: this.#nestedWorkflowInput ? { input: this.#nestedWorkflowInput } : {},
|
|
3343
3603
|
activePaths: [],
|
|
3604
|
+
activeStepsPath: {},
|
|
3344
3605
|
serializedStepGraph: this.serializedStepGraph,
|
|
3345
3606
|
suspendedPaths: {},
|
|
3346
3607
|
resumeLabels: {},
|
|
@@ -3384,7 +3645,9 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
3384
3645
|
state,
|
|
3385
3646
|
setState,
|
|
3386
3647
|
suspend,
|
|
3648
|
+
restart,
|
|
3387
3649
|
resume,
|
|
3650
|
+
timeTravel,
|
|
3388
3651
|
[chunkABJOUEVA_cjs.EMITTER_SYMBOL]: emitter,
|
|
3389
3652
|
mastra,
|
|
3390
3653
|
requestContext,
|
|
@@ -3396,17 +3659,20 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
3396
3659
|
validateInputs
|
|
3397
3660
|
}) {
|
|
3398
3661
|
this.__registerMastra(mastra);
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
}
|
|
3662
|
+
const effectiveValidateInputs = validateInputs ?? this.#options.validateInputs ?? true;
|
|
3663
|
+
this.#options = {
|
|
3664
|
+
...this.#options || {},
|
|
3665
|
+
validateInputs: effectiveValidateInputs
|
|
3666
|
+
};
|
|
3405
3667
|
this.executionEngine.options = {
|
|
3406
3668
|
...this.executionEngine.options || {},
|
|
3407
|
-
validateInputs:
|
|
3669
|
+
validateInputs: effectiveValidateInputs
|
|
3408
3670
|
};
|
|
3409
3671
|
const isResume = !!(resume?.steps && resume.steps.length > 0) || !!resume?.label || !!(resume?.steps && resume.steps.length === 0 && (!retryCount || retryCount === 0));
|
|
3672
|
+
if (!restart && !isResume) {
|
|
3673
|
+
this.#nestedWorkflowInput = inputData;
|
|
3674
|
+
}
|
|
3675
|
+
const isTimeTravel = !!(timeTravel && timeTravel.steps.length > 0);
|
|
3410
3676
|
const run = isResume ? await this.createRun({ runId: resume.runId }) : await this.createRun({ runId });
|
|
3411
3677
|
const nestedAbortCb = () => {
|
|
3412
3678
|
abort();
|
|
@@ -3422,21 +3688,41 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
3422
3688
|
if (retryCount && retryCount > 0 && isResume && requestContext) {
|
|
3423
3689
|
requestContext.set("__mastraWorflowInputData", inputData);
|
|
3424
3690
|
}
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
})
|
|
3691
|
+
let res;
|
|
3692
|
+
if (isTimeTravel) {
|
|
3693
|
+
res = await run.timeTravel({
|
|
3694
|
+
inputData: timeTravel?.inputData,
|
|
3695
|
+
resumeData: timeTravel?.resumeData,
|
|
3696
|
+
initialState: state,
|
|
3697
|
+
step: timeTravel?.steps,
|
|
3698
|
+
context: timeTravel?.nestedStepResults?.[this.id] ?? {},
|
|
3699
|
+
nestedStepsContext: timeTravel?.nestedStepResults,
|
|
3700
|
+
requestContext,
|
|
3701
|
+
tracingContext,
|
|
3702
|
+
writableStream: writer,
|
|
3703
|
+
outputOptions: { includeState: true, includeResumeLabels: true }
|
|
3704
|
+
});
|
|
3705
|
+
} else if (restart) {
|
|
3706
|
+
res = await run.restart({ requestContext, tracingContext, writableStream: writer });
|
|
3707
|
+
} else if (isResume) {
|
|
3708
|
+
res = await run.resume({
|
|
3709
|
+
resumeData,
|
|
3710
|
+
step: resume.steps?.length > 0 ? resume.steps : void 0,
|
|
3711
|
+
requestContext,
|
|
3712
|
+
tracingContext,
|
|
3713
|
+
outputOptions: { includeState: true, includeResumeLabels: true },
|
|
3714
|
+
label: resume.label
|
|
3715
|
+
});
|
|
3716
|
+
} else {
|
|
3717
|
+
res = await run.start({
|
|
3718
|
+
inputData,
|
|
3719
|
+
requestContext,
|
|
3720
|
+
tracingContext,
|
|
3721
|
+
writableStream: writer,
|
|
3722
|
+
initialState: state,
|
|
3723
|
+
outputOptions: { includeState: true, includeResumeLabels: true }
|
|
3724
|
+
});
|
|
3725
|
+
}
|
|
3440
3726
|
unwatch();
|
|
3441
3727
|
const suspendedSteps = Object.entries(res.steps).filter(([_stepName, stepResult]) => {
|
|
3442
3728
|
const stepRes = stepResult;
|
|
@@ -3472,6 +3758,35 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
3472
3758
|
}
|
|
3473
3759
|
return storage.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
|
|
3474
3760
|
}
|
|
3761
|
+
async listActiveWorkflowRuns() {
|
|
3762
|
+
const runningRuns = await this.listWorkflowRuns({ status: "running" });
|
|
3763
|
+
const waitingRuns = await this.listWorkflowRuns({ status: "waiting" });
|
|
3764
|
+
return {
|
|
3765
|
+
runs: [...runningRuns.runs, ...waitingRuns.runs],
|
|
3766
|
+
total: runningRuns.total + waitingRuns.total
|
|
3767
|
+
};
|
|
3768
|
+
}
|
|
3769
|
+
async restartAllActiveWorkflowRuns() {
|
|
3770
|
+
if (this.engineType !== "default") {
|
|
3771
|
+
this.logger.debug(`Cannot restart active workflow runs for ${this.engineType} engine`);
|
|
3772
|
+
return;
|
|
3773
|
+
}
|
|
3774
|
+
const activeRuns = await this.listActiveWorkflowRuns();
|
|
3775
|
+
if (activeRuns.runs.length > 0) {
|
|
3776
|
+
this.logger.debug(
|
|
3777
|
+
`Restarting ${activeRuns.runs.length} active workflow run${activeRuns.runs.length > 1 ? "s" : ""}`
|
|
3778
|
+
);
|
|
3779
|
+
}
|
|
3780
|
+
for (const runSnapshot of activeRuns.runs) {
|
|
3781
|
+
try {
|
|
3782
|
+
const run = await this.createRun({ runId: runSnapshot.runId });
|
|
3783
|
+
await run.restart();
|
|
3784
|
+
this.logger.debug(`Restarted ${this.id} workflow run ${runSnapshot.runId}`);
|
|
3785
|
+
} catch (error) {
|
|
3786
|
+
this.logger.error(`Failed to restart ${this.id} workflow run ${runSnapshot.runId}: ${error}`);
|
|
3787
|
+
}
|
|
3788
|
+
}
|
|
3789
|
+
}
|
|
3475
3790
|
async getWorkflowRunById(runId) {
|
|
3476
3791
|
const storage = this.#mastra?.getStorage();
|
|
3477
3792
|
if (!storage) {
|
|
@@ -3547,7 +3862,9 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
3547
3862
|
result: snapshot.result,
|
|
3548
3863
|
error: snapshot.error,
|
|
3549
3864
|
payload: snapshot.context?.input,
|
|
3550
|
-
steps: fullSteps
|
|
3865
|
+
steps: fullSteps,
|
|
3866
|
+
activeStepsPath: snapshot.activeStepsPath,
|
|
3867
|
+
serializedStepGraph: snapshot.serializedStepGraph
|
|
3551
3868
|
};
|
|
3552
3869
|
}
|
|
3553
3870
|
};
|
|
@@ -3599,6 +3916,7 @@ var Run = class {
|
|
|
3599
3916
|
*/
|
|
3600
3917
|
workflowSteps;
|
|
3601
3918
|
workflowRunStatus;
|
|
3919
|
+
workflowEngineType;
|
|
3602
3920
|
/**
|
|
3603
3921
|
* The storage for this run
|
|
3604
3922
|
*/
|
|
@@ -3630,6 +3948,7 @@ var Run = class {
|
|
|
3630
3948
|
this.validateInputs = params.validateInputs;
|
|
3631
3949
|
this.stateSchema = params.stateSchema;
|
|
3632
3950
|
this.workflowRunStatus = "pending";
|
|
3951
|
+
this.workflowEngineType = params.workflowEngineType;
|
|
3633
3952
|
}
|
|
3634
3953
|
get abortController() {
|
|
3635
3954
|
if (!this.#abortController) {
|
|
@@ -3702,6 +4021,20 @@ var Run = class {
|
|
|
3702
4021
|
}
|
|
3703
4022
|
return resumeDataToUse;
|
|
3704
4023
|
}
|
|
4024
|
+
async _validateTimetravelInputData(inputData, step) {
|
|
4025
|
+
let inputDataToUse = inputData;
|
|
4026
|
+
if (step && step.inputSchema && this.validateInputs) {
|
|
4027
|
+
const inputSchema = step.inputSchema;
|
|
4028
|
+
const validatedInputData = await inputSchema.safeParseAsync(inputData);
|
|
4029
|
+
if (!validatedInputData.success) {
|
|
4030
|
+
const errors = getZodErrors(validatedInputData.error);
|
|
4031
|
+
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
4032
|
+
throw new Error("Invalid inputData: \n" + errorMessages);
|
|
4033
|
+
}
|
|
4034
|
+
inputDataToUse = validatedInputData.data;
|
|
4035
|
+
}
|
|
4036
|
+
return inputDataToUse;
|
|
4037
|
+
}
|
|
3705
4038
|
async _start({
|
|
3706
4039
|
inputData,
|
|
3707
4040
|
initialState,
|
|
@@ -4127,6 +4460,13 @@ var Run = class {
|
|
|
4127
4460
|
async resume(params) {
|
|
4128
4461
|
return this._resume(params);
|
|
4129
4462
|
}
|
|
4463
|
+
/**
|
|
4464
|
+
* Restarts the workflow execution that was previously active
|
|
4465
|
+
* @returns A promise that resolves to the workflow output
|
|
4466
|
+
*/
|
|
4467
|
+
async restart(args = {}) {
|
|
4468
|
+
return this._restart(args);
|
|
4469
|
+
}
|
|
4130
4470
|
async _resume(params) {
|
|
4131
4471
|
const snapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
4132
4472
|
workflowName: this.workflowId,
|
|
@@ -4194,7 +4534,7 @@ var Run = class {
|
|
|
4194
4534
|
params.requestContext.delete("__mastraWorflowInputData");
|
|
4195
4535
|
}
|
|
4196
4536
|
const stepResults = { ...snapshot?.context ?? {}, input: requestContextInput ?? snapshot?.context?.input };
|
|
4197
|
-
|
|
4537
|
+
const requestContextToUse = params.requestContext ?? new chunkJ7O6WENZ_cjs.RequestContext();
|
|
4198
4538
|
Object.entries(snapshot?.requestContext ?? {}).forEach(([key, value]) => {
|
|
4199
4539
|
if (!requestContextToUse.has(key)) {
|
|
4200
4540
|
requestContextToUse.set(key, value);
|
|
@@ -4261,14 +4601,306 @@ var Run = class {
|
|
|
4261
4601
|
this.closeStreamAction?.().catch(() => {
|
|
4262
4602
|
});
|
|
4263
4603
|
}
|
|
4264
|
-
result.traceId = traceId;
|
|
4265
|
-
return result;
|
|
4604
|
+
result.traceId = traceId;
|
|
4605
|
+
return result;
|
|
4606
|
+
});
|
|
4607
|
+
this.executionResults = executionResultPromise;
|
|
4608
|
+
return executionResultPromise.then((result) => {
|
|
4609
|
+
this.streamOutput?.updateResults(result);
|
|
4610
|
+
return result;
|
|
4611
|
+
});
|
|
4612
|
+
}
|
|
4613
|
+
async _restart({
|
|
4614
|
+
requestContext,
|
|
4615
|
+
writableStream,
|
|
4616
|
+
tracingContext,
|
|
4617
|
+
tracingOptions
|
|
4618
|
+
}) {
|
|
4619
|
+
if (this.workflowEngineType !== "default") {
|
|
4620
|
+
throw new Error(`restart() is not supported on ${this.workflowEngineType} workflows`);
|
|
4621
|
+
}
|
|
4622
|
+
const snapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
4623
|
+
workflowName: this.workflowId,
|
|
4624
|
+
runId: this.runId
|
|
4625
|
+
});
|
|
4626
|
+
let nestedWorkflowPending = false;
|
|
4627
|
+
if (!snapshot) {
|
|
4628
|
+
throw new Error(`Snapshot not found for run ${this.runId}`);
|
|
4629
|
+
}
|
|
4630
|
+
if (snapshot.status !== "running" && snapshot.status !== "waiting") {
|
|
4631
|
+
if (snapshot.status === "pending" && !!snapshot.context.input) {
|
|
4632
|
+
nestedWorkflowPending = true;
|
|
4633
|
+
} else {
|
|
4634
|
+
throw new Error("This workflow run was not active");
|
|
4635
|
+
}
|
|
4636
|
+
}
|
|
4637
|
+
let nestedWorkflowActiveStepsPath = {};
|
|
4638
|
+
const firstEntry = this.executionGraph.steps[0];
|
|
4639
|
+
if (firstEntry.type === "step" || firstEntry.type === "foreach" || firstEntry.type === "loop") {
|
|
4640
|
+
nestedWorkflowActiveStepsPath = {
|
|
4641
|
+
[firstEntry.step.id]: [0]
|
|
4642
|
+
};
|
|
4643
|
+
} else if (firstEntry.type === "sleep" || firstEntry.type === "sleepUntil") {
|
|
4644
|
+
nestedWorkflowActiveStepsPath = {
|
|
4645
|
+
[firstEntry.id]: [0]
|
|
4646
|
+
};
|
|
4647
|
+
} else if (firstEntry.type === "conditional" || firstEntry.type === "parallel") {
|
|
4648
|
+
nestedWorkflowActiveStepsPath = firstEntry.steps.reduce(
|
|
4649
|
+
(acc, step) => {
|
|
4650
|
+
acc[step.step.id] = [0];
|
|
4651
|
+
return acc;
|
|
4652
|
+
},
|
|
4653
|
+
{}
|
|
4654
|
+
);
|
|
4655
|
+
}
|
|
4656
|
+
const restartData = {
|
|
4657
|
+
activePaths: nestedWorkflowPending ? [0] : snapshot.activePaths,
|
|
4658
|
+
activeStepsPath: nestedWorkflowPending ? nestedWorkflowActiveStepsPath : snapshot.activeStepsPath,
|
|
4659
|
+
stepResults: snapshot.context,
|
|
4660
|
+
state: snapshot.value
|
|
4661
|
+
};
|
|
4662
|
+
const requestContextToUse = requestContext ?? new chunkJ7O6WENZ_cjs.RequestContext();
|
|
4663
|
+
for (const [key, value] of Object.entries(snapshot.requestContext ?? {})) {
|
|
4664
|
+
if (!requestContextToUse.has(key)) {
|
|
4665
|
+
requestContextToUse.set(key, value);
|
|
4666
|
+
}
|
|
4667
|
+
}
|
|
4668
|
+
const workflowSpan = chunkE7K4FTLN_cjs.getOrCreateSpan({
|
|
4669
|
+
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
4670
|
+
name: `workflow run: '${this.workflowId}'`,
|
|
4671
|
+
attributes: {
|
|
4672
|
+
workflowId: this.workflowId
|
|
4673
|
+
},
|
|
4674
|
+
metadata: {
|
|
4675
|
+
resourceId: this.resourceId,
|
|
4676
|
+
runId: this.runId
|
|
4677
|
+
},
|
|
4678
|
+
tracingPolicy: this.tracingPolicy,
|
|
4679
|
+
tracingOptions,
|
|
4680
|
+
tracingContext,
|
|
4681
|
+
requestContext: requestContextToUse,
|
|
4682
|
+
mastra: this.#mastra
|
|
4683
|
+
});
|
|
4684
|
+
const traceId = workflowSpan?.externalTraceId;
|
|
4685
|
+
const result = await this.executionEngine.execute({
|
|
4686
|
+
workflowId: this.workflowId,
|
|
4687
|
+
runId: this.runId,
|
|
4688
|
+
resourceId: this.resourceId,
|
|
4689
|
+
disableScorers: this.disableScorers,
|
|
4690
|
+
graph: this.executionGraph,
|
|
4691
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
4692
|
+
restart: restartData,
|
|
4693
|
+
emitter: {
|
|
4694
|
+
emit: async (event, data) => {
|
|
4695
|
+
this.emitter.emit(event, data);
|
|
4696
|
+
},
|
|
4697
|
+
on: (event, callback) => {
|
|
4698
|
+
this.emitter.on(event, callback);
|
|
4699
|
+
},
|
|
4700
|
+
off: (event, callback) => {
|
|
4701
|
+
this.emitter.off(event, callback);
|
|
4702
|
+
},
|
|
4703
|
+
once: (event, callback) => {
|
|
4704
|
+
this.emitter.once(event, callback);
|
|
4705
|
+
}
|
|
4706
|
+
},
|
|
4707
|
+
retryConfig: this.retryConfig,
|
|
4708
|
+
requestContext: requestContextToUse,
|
|
4709
|
+
abortController: this.abortController,
|
|
4710
|
+
writableStream,
|
|
4711
|
+
workflowSpan
|
|
4712
|
+
});
|
|
4713
|
+
if (result.status !== "suspended") {
|
|
4714
|
+
this.cleanup?.();
|
|
4715
|
+
}
|
|
4716
|
+
result.traceId = traceId;
|
|
4717
|
+
return result;
|
|
4718
|
+
}
|
|
4719
|
+
async _timeTravel({
|
|
4720
|
+
inputData,
|
|
4721
|
+
resumeData,
|
|
4722
|
+
initialState,
|
|
4723
|
+
step: stepParam,
|
|
4724
|
+
context,
|
|
4725
|
+
nestedStepsContext,
|
|
4726
|
+
requestContext,
|
|
4727
|
+
writableStream,
|
|
4728
|
+
tracingContext,
|
|
4729
|
+
tracingOptions,
|
|
4730
|
+
outputOptions
|
|
4731
|
+
}) {
|
|
4732
|
+
if (!stepParam || Array.isArray(stepParam) && stepParam.length === 0) {
|
|
4733
|
+
throw new Error("Step is required and must be a valid step or array of steps");
|
|
4734
|
+
}
|
|
4735
|
+
const snapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
4736
|
+
workflowName: this.workflowId,
|
|
4737
|
+
runId: this.runId
|
|
4738
|
+
});
|
|
4739
|
+
if (!snapshot) {
|
|
4740
|
+
throw new Error(`Snapshot not found for run ${this.runId}`);
|
|
4741
|
+
}
|
|
4742
|
+
if (snapshot.status === "running") {
|
|
4743
|
+
throw new Error("This workflow run is still running, cannot time travel");
|
|
4744
|
+
}
|
|
4745
|
+
let steps;
|
|
4746
|
+
let newStepParam = stepParam;
|
|
4747
|
+
if (typeof stepParam === "string") {
|
|
4748
|
+
newStepParam = stepParam.split(".");
|
|
4749
|
+
}
|
|
4750
|
+
steps = (Array.isArray(newStepParam) ? newStepParam : [newStepParam]).map(
|
|
4751
|
+
(step) => typeof step === "string" ? step : step?.id
|
|
4752
|
+
);
|
|
4753
|
+
let inputDataToUse = inputData;
|
|
4754
|
+
if (inputDataToUse && steps.length === 1) {
|
|
4755
|
+
inputDataToUse = await this._validateTimetravelInputData(inputData, this.workflowSteps[steps[0]]);
|
|
4756
|
+
}
|
|
4757
|
+
const timeTravelData = createTimeTravelExecutionParams({
|
|
4758
|
+
steps,
|
|
4759
|
+
inputData: inputDataToUse,
|
|
4760
|
+
resumeData,
|
|
4761
|
+
context,
|
|
4762
|
+
nestedStepsContext,
|
|
4763
|
+
snapshot,
|
|
4764
|
+
initialState,
|
|
4765
|
+
graph: this.executionGraph
|
|
4766
|
+
});
|
|
4767
|
+
const requestContextToUse = requestContext ?? new chunkJ7O6WENZ_cjs.RequestContext();
|
|
4768
|
+
for (const [key, value] of Object.entries(snapshot.requestContext ?? {})) {
|
|
4769
|
+
if (!requestContextToUse.has(key)) {
|
|
4770
|
+
requestContextToUse.set(key, value);
|
|
4771
|
+
}
|
|
4772
|
+
}
|
|
4773
|
+
const workflowSpan = chunkE7K4FTLN_cjs.getOrCreateSpan({
|
|
4774
|
+
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
4775
|
+
name: `workflow run: '${this.workflowId}'`,
|
|
4776
|
+
input: inputData,
|
|
4777
|
+
attributes: {
|
|
4778
|
+
workflowId: this.workflowId
|
|
4779
|
+
},
|
|
4780
|
+
metadata: {
|
|
4781
|
+
resourceId: this.resourceId,
|
|
4782
|
+
runId: this.runId
|
|
4783
|
+
},
|
|
4784
|
+
tracingPolicy: this.tracingPolicy,
|
|
4785
|
+
tracingOptions,
|
|
4786
|
+
tracingContext,
|
|
4787
|
+
requestContext: requestContextToUse,
|
|
4788
|
+
mastra: this.#mastra
|
|
4789
|
+
});
|
|
4790
|
+
const traceId = workflowSpan?.externalTraceId;
|
|
4791
|
+
const result = await this.executionEngine.execute({
|
|
4792
|
+
workflowId: this.workflowId,
|
|
4793
|
+
runId: this.runId,
|
|
4794
|
+
resourceId: this.resourceId,
|
|
4795
|
+
disableScorers: this.disableScorers,
|
|
4796
|
+
graph: this.executionGraph,
|
|
4797
|
+
timeTravel: timeTravelData,
|
|
4798
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
4799
|
+
emitter: {
|
|
4800
|
+
emit: async (event, data) => {
|
|
4801
|
+
this.emitter.emit(event, data);
|
|
4802
|
+
},
|
|
4803
|
+
on: (event, callback) => {
|
|
4804
|
+
this.emitter.on(event, callback);
|
|
4805
|
+
},
|
|
4806
|
+
off: (event, callback) => {
|
|
4807
|
+
this.emitter.off(event, callback);
|
|
4808
|
+
},
|
|
4809
|
+
once: (event, callback) => {
|
|
4810
|
+
this.emitter.once(event, callback);
|
|
4811
|
+
}
|
|
4812
|
+
},
|
|
4813
|
+
retryConfig: this.retryConfig,
|
|
4814
|
+
requestContext: requestContextToUse,
|
|
4815
|
+
abortController: this.abortController,
|
|
4816
|
+
writableStream,
|
|
4817
|
+
workflowSpan,
|
|
4818
|
+
outputOptions
|
|
4819
|
+
});
|
|
4820
|
+
if (result.status !== "suspended") {
|
|
4821
|
+
this.cleanup?.();
|
|
4822
|
+
}
|
|
4823
|
+
result.traceId = traceId;
|
|
4824
|
+
return result;
|
|
4825
|
+
}
|
|
4826
|
+
async timeTravel(args) {
|
|
4827
|
+
return this._timeTravel(args);
|
|
4828
|
+
}
|
|
4829
|
+
timeTravelStream({
|
|
4830
|
+
inputData,
|
|
4831
|
+
resumeData,
|
|
4832
|
+
initialState,
|
|
4833
|
+
step,
|
|
4834
|
+
context,
|
|
4835
|
+
nestedStepsContext,
|
|
4836
|
+
requestContext,
|
|
4837
|
+
tracingContext,
|
|
4838
|
+
tracingOptions,
|
|
4839
|
+
outputOptions
|
|
4840
|
+
}) {
|
|
4841
|
+
this.closeStreamAction = async () => {
|
|
4842
|
+
};
|
|
4843
|
+
const self = this;
|
|
4844
|
+
const stream = new web.ReadableStream({
|
|
4845
|
+
async start(controller) {
|
|
4846
|
+
const unwatch = self.watch(async ({ type, from = "WORKFLOW" /* WORKFLOW */, payload }) => {
|
|
4847
|
+
controller.enqueue({
|
|
4848
|
+
type,
|
|
4849
|
+
runId: self.runId,
|
|
4850
|
+
from,
|
|
4851
|
+
payload: {
|
|
4852
|
+
stepName: payload.id,
|
|
4853
|
+
...payload
|
|
4854
|
+
}
|
|
4855
|
+
});
|
|
4856
|
+
});
|
|
4857
|
+
self.closeStreamAction = async () => {
|
|
4858
|
+
unwatch();
|
|
4859
|
+
try {
|
|
4860
|
+
await controller.close();
|
|
4861
|
+
} catch (err) {
|
|
4862
|
+
console.error("Error closing stream:", err);
|
|
4863
|
+
}
|
|
4864
|
+
};
|
|
4865
|
+
const executionResultsPromise = self._timeTravel({
|
|
4866
|
+
inputData,
|
|
4867
|
+
step,
|
|
4868
|
+
context,
|
|
4869
|
+
nestedStepsContext,
|
|
4870
|
+
resumeData,
|
|
4871
|
+
initialState,
|
|
4872
|
+
requestContext,
|
|
4873
|
+
tracingContext,
|
|
4874
|
+
tracingOptions,
|
|
4875
|
+
writableStream: new web.WritableStream({
|
|
4876
|
+
write(chunk) {
|
|
4877
|
+
controller.enqueue(chunk);
|
|
4878
|
+
}
|
|
4879
|
+
}),
|
|
4880
|
+
outputOptions
|
|
4881
|
+
});
|
|
4882
|
+
self.executionResults = executionResultsPromise;
|
|
4883
|
+
let executionResults;
|
|
4884
|
+
try {
|
|
4885
|
+
executionResults = await executionResultsPromise;
|
|
4886
|
+
self.closeStreamAction?.().catch(() => {
|
|
4887
|
+
});
|
|
4888
|
+
if (self.streamOutput) {
|
|
4889
|
+
self.streamOutput.updateResults(executionResults);
|
|
4890
|
+
}
|
|
4891
|
+
} catch (err) {
|
|
4892
|
+
self.streamOutput?.rejectResults(err);
|
|
4893
|
+
self.closeStreamAction?.().catch(() => {
|
|
4894
|
+
});
|
|
4895
|
+
}
|
|
4896
|
+
}
|
|
4266
4897
|
});
|
|
4267
|
-
this.
|
|
4268
|
-
|
|
4269
|
-
this.
|
|
4270
|
-
|
|
4898
|
+
this.streamOutput = new WorkflowRunOutput({
|
|
4899
|
+
runId: this.runId,
|
|
4900
|
+
workflowId: this.workflowId,
|
|
4901
|
+
stream
|
|
4271
4902
|
});
|
|
4903
|
+
return this.streamOutput;
|
|
4272
4904
|
}
|
|
4273
4905
|
/**
|
|
4274
4906
|
* @access private
|
|
@@ -4732,7 +5364,7 @@ function convertMastraChunkToAISDKv5({
|
|
|
4732
5364
|
if (mode === "generate") {
|
|
4733
5365
|
return {
|
|
4734
5366
|
type: "file",
|
|
4735
|
-
file: new
|
|
5367
|
+
file: new chunkVSM3NLUX_cjs.DefaultGeneratedFile({
|
|
4736
5368
|
data: chunk.payload.data,
|
|
4737
5369
|
mediaType: chunk.payload.mimeType
|
|
4738
5370
|
})
|
|
@@ -4740,7 +5372,7 @@ function convertMastraChunkToAISDKv5({
|
|
|
4740
5372
|
}
|
|
4741
5373
|
return {
|
|
4742
5374
|
type: "file",
|
|
4743
|
-
file: new
|
|
5375
|
+
file: new chunkVSM3NLUX_cjs.DefaultGeneratedFileWithType({
|
|
4744
5376
|
data: chunk.payload.data,
|
|
4745
5377
|
mediaType: chunk.payload.mimeType
|
|
4746
5378
|
})
|
|
@@ -4895,7 +5527,8 @@ function execute({
|
|
|
4895
5527
|
modelSettings,
|
|
4896
5528
|
structuredOutput,
|
|
4897
5529
|
headers,
|
|
4898
|
-
shouldThrowError
|
|
5530
|
+
shouldThrowError,
|
|
5531
|
+
methodType
|
|
4899
5532
|
}) {
|
|
4900
5533
|
const v5 = new AISDKV5InputStream({
|
|
4901
5534
|
component: "LLM",
|
|
@@ -4943,7 +5576,8 @@ You don't need to format your response as JSON unless the user asks you to. Just
|
|
|
4943
5576
|
const pRetry = await import('p-retry');
|
|
4944
5577
|
return await pRetry.default(
|
|
4945
5578
|
async () => {
|
|
4946
|
-
const
|
|
5579
|
+
const fn = (methodType === "stream" ? model.doStream : model.doGenerate).bind(model);
|
|
5580
|
+
const streamResult = await fn({
|
|
4947
5581
|
...toolsAndToolChoice,
|
|
4948
5582
|
prompt,
|
|
4949
5583
|
providerOptions: providerOptionsToUse,
|
|
@@ -4967,10 +5601,6 @@ You don't need to format your response as JSON unless the user asks you to. Just
|
|
|
4967
5601
|
}
|
|
4968
5602
|
);
|
|
4969
5603
|
} catch (error) {
|
|
4970
|
-
const abortSignal = options?.abortSignal;
|
|
4971
|
-
if (providerUtilsV5.isAbortError(error) && abortSignal?.aborted) {
|
|
4972
|
-
console.error("Abort error", error);
|
|
4973
|
-
}
|
|
4974
5604
|
if (shouldThrowError) {
|
|
4975
5605
|
throw error;
|
|
4976
5606
|
}
|
|
@@ -5126,23 +5756,22 @@ async function processOutputStream({
|
|
|
5126
5756
|
if (runState.state.textDeltas.length) {
|
|
5127
5757
|
const textStartPayload = chunk.payload;
|
|
5128
5758
|
const providerMetadata = textStartPayload.providerMetadata ?? runState.state.providerOptions;
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5759
|
+
const message = {
|
|
5760
|
+
id: messageId,
|
|
5761
|
+
role: "assistant",
|
|
5762
|
+
content: {
|
|
5763
|
+
format: 2,
|
|
5764
|
+
parts: [
|
|
5765
|
+
{
|
|
5135
5766
|
type: "text",
|
|
5136
5767
|
text: runState.state.textDeltas.join(""),
|
|
5137
|
-
|
|
5138
|
-
} : {
|
|
5139
|
-
type: "text",
|
|
5140
|
-
text: runState.state.textDeltas.join("")
|
|
5768
|
+
...providerMetadata ? { providerMetadata } : {}
|
|
5141
5769
|
}
|
|
5142
5770
|
]
|
|
5143
5771
|
},
|
|
5144
|
-
|
|
5145
|
-
|
|
5772
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
5773
|
+
};
|
|
5774
|
+
messageList.add(message, "response");
|
|
5146
5775
|
}
|
|
5147
5776
|
runState.setState({
|
|
5148
5777
|
isStreaming: false,
|
|
@@ -5222,20 +5851,23 @@ async function processOutputStream({
|
|
|
5222
5851
|
providerOptions: chunk.payload.providerMetadata ?? runState.state.providerOptions
|
|
5223
5852
|
});
|
|
5224
5853
|
if (Object.values(chunk.payload.providerMetadata || {}).find((v) => v?.redactedData)) {
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5854
|
+
const message = {
|
|
5855
|
+
id: messageId,
|
|
5856
|
+
role: "assistant",
|
|
5857
|
+
content: {
|
|
5858
|
+
format: 2,
|
|
5859
|
+
parts: [
|
|
5230
5860
|
{
|
|
5231
5861
|
type: "reasoning",
|
|
5232
|
-
|
|
5233
|
-
|
|
5862
|
+
reasoning: "",
|
|
5863
|
+
details: [{ type: "redacted", data: "" }],
|
|
5864
|
+
providerMetadata: chunk.payload.providerMetadata ?? runState.state.providerOptions
|
|
5234
5865
|
}
|
|
5235
5866
|
]
|
|
5236
5867
|
},
|
|
5237
|
-
|
|
5238
|
-
|
|
5868
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
5869
|
+
};
|
|
5870
|
+
messageList.add(message, "response");
|
|
5239
5871
|
if (isControllerOpen(controller)) {
|
|
5240
5872
|
controller.enqueue(chunk);
|
|
5241
5873
|
}
|
|
@@ -5261,20 +5893,23 @@ async function processOutputStream({
|
|
|
5261
5893
|
}
|
|
5262
5894
|
case "reasoning-end": {
|
|
5263
5895
|
if (runState.state.reasoningDeltas.length > 0) {
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5896
|
+
const message = {
|
|
5897
|
+
id: messageId,
|
|
5898
|
+
role: "assistant",
|
|
5899
|
+
content: {
|
|
5900
|
+
format: 2,
|
|
5901
|
+
parts: [
|
|
5269
5902
|
{
|
|
5270
5903
|
type: "reasoning",
|
|
5271
|
-
|
|
5272
|
-
|
|
5904
|
+
reasoning: "",
|
|
5905
|
+
details: [{ type: "text", text: runState.state.reasoningDeltas.join("") }],
|
|
5906
|
+
providerMetadata: chunk.payload.providerMetadata ?? runState.state.providerOptions
|
|
5273
5907
|
}
|
|
5274
5908
|
]
|
|
5275
5909
|
},
|
|
5276
|
-
|
|
5277
|
-
|
|
5910
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
5911
|
+
};
|
|
5912
|
+
messageList.add(message, "response");
|
|
5278
5913
|
}
|
|
5279
5914
|
runState.setState({
|
|
5280
5915
|
isReasoning: false,
|
|
@@ -5286,25 +5921,31 @@ async function processOutputStream({
|
|
|
5286
5921
|
break;
|
|
5287
5922
|
}
|
|
5288
5923
|
case "file":
|
|
5289
|
-
|
|
5290
|
-
{
|
|
5924
|
+
{
|
|
5925
|
+
const message = {
|
|
5291
5926
|
id: messageId,
|
|
5292
5927
|
role: "assistant",
|
|
5293
|
-
content:
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5928
|
+
content: {
|
|
5929
|
+
format: 2,
|
|
5930
|
+
parts: [
|
|
5931
|
+
{
|
|
5932
|
+
type: "file",
|
|
5933
|
+
// @ts-expect-error
|
|
5934
|
+
data: chunk.payload.data,
|
|
5935
|
+
// TODO: incorrect string type
|
|
5936
|
+
mimeType: chunk.payload.mimeType
|
|
5937
|
+
}
|
|
5938
|
+
]
|
|
5939
|
+
},
|
|
5940
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
5941
|
+
};
|
|
5942
|
+
messageList.add(message, "response");
|
|
5943
|
+
controller.enqueue(chunk);
|
|
5944
|
+
}
|
|
5304
5945
|
break;
|
|
5305
5946
|
case "source":
|
|
5306
|
-
|
|
5307
|
-
{
|
|
5947
|
+
{
|
|
5948
|
+
const message = {
|
|
5308
5949
|
id: messageId,
|
|
5309
5950
|
role: "assistant",
|
|
5310
5951
|
content: {
|
|
@@ -5323,10 +5964,10 @@ async function processOutputStream({
|
|
|
5323
5964
|
]
|
|
5324
5965
|
},
|
|
5325
5966
|
createdAt: /* @__PURE__ */ new Date()
|
|
5326
|
-
}
|
|
5327
|
-
"response"
|
|
5328
|
-
|
|
5329
|
-
|
|
5967
|
+
};
|
|
5968
|
+
messageList.add(message, "response");
|
|
5969
|
+
controller.enqueue(chunk);
|
|
5970
|
+
}
|
|
5330
5971
|
break;
|
|
5331
5972
|
case "finish":
|
|
5332
5973
|
runState.setState({
|
|
@@ -5442,7 +6083,8 @@ function createLLMExecutionStep({
|
|
|
5442
6083
|
headers,
|
|
5443
6084
|
downloadRetries,
|
|
5444
6085
|
downloadConcurrency,
|
|
5445
|
-
processorStates
|
|
6086
|
+
processorStates,
|
|
6087
|
+
methodType
|
|
5446
6088
|
}) {
|
|
5447
6089
|
return createStep({
|
|
5448
6090
|
id: "llm-execution",
|
|
@@ -5492,7 +6134,7 @@ function createLLMExecutionStep({
|
|
|
5492
6134
|
}
|
|
5493
6135
|
if (prepareStepResult.messages) {
|
|
5494
6136
|
const newMessages = prepareStepResult.messages;
|
|
5495
|
-
const newMessageList = new
|
|
6137
|
+
const newMessageList = new chunkVSM3NLUX_cjs.MessageList();
|
|
5496
6138
|
for (const message of newMessages) {
|
|
5497
6139
|
if (message.role === "system") {
|
|
5498
6140
|
newMessageList.addSystem(message);
|
|
@@ -5521,6 +6163,7 @@ function createLLMExecutionStep({
|
|
|
5521
6163
|
includeRawChunks,
|
|
5522
6164
|
structuredOutput,
|
|
5523
6165
|
headers,
|
|
6166
|
+
methodType,
|
|
5524
6167
|
onResult: ({
|
|
5525
6168
|
warnings: warningsFromStream,
|
|
5526
6169
|
request: requestFromStream,
|
|
@@ -5663,24 +6306,27 @@ function createLLMExecutionStep({
|
|
|
5663
6306
|
return chunk.payload;
|
|
5664
6307
|
});
|
|
5665
6308
|
if (toolCalls.length > 0) {
|
|
5666
|
-
const
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
6309
|
+
const message = {
|
|
6310
|
+
id: messageId,
|
|
6311
|
+
role: "assistant",
|
|
6312
|
+
content: {
|
|
6313
|
+
format: 2,
|
|
6314
|
+
parts: toolCalls.map((toolCall) => {
|
|
6315
|
+
return {
|
|
6316
|
+
type: "tool-invocation",
|
|
6317
|
+
toolInvocation: {
|
|
6318
|
+
state: "call",
|
|
6319
|
+
toolCallId: toolCall.toolCallId,
|
|
6320
|
+
toolName: toolCall.toolName,
|
|
6321
|
+
args: toolCall.args
|
|
6322
|
+
},
|
|
6323
|
+
...toolCall.providerMetadata ? { providerMetadata: toolCall.providerMetadata } : {}
|
|
6324
|
+
};
|
|
6325
|
+
})
|
|
5681
6326
|
},
|
|
5682
|
-
|
|
5683
|
-
|
|
6327
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
6328
|
+
};
|
|
6329
|
+
messageList.add(message, "response");
|
|
5684
6330
|
}
|
|
5685
6331
|
const finishReason = runState?.state?.stepResult?.reason ?? outputStream._getImmediateFinishReason();
|
|
5686
6332
|
const hasErrored = runState.state.hasErrored;
|
|
@@ -5762,24 +6408,28 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
|
|
|
5762
6408
|
};
|
|
5763
6409
|
rest.controller.enqueue(chunk);
|
|
5764
6410
|
});
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
6411
|
+
const msg = {
|
|
6412
|
+
id: toolResultMessageId || "",
|
|
6413
|
+
role: "assistant",
|
|
6414
|
+
content: {
|
|
6415
|
+
format: 2,
|
|
6416
|
+
parts: errorResults.map((toolCallErrorResult) => {
|
|
5770
6417
|
return {
|
|
5771
|
-
type: "tool-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
6418
|
+
type: "tool-invocation",
|
|
6419
|
+
toolInvocation: {
|
|
6420
|
+
state: "result",
|
|
6421
|
+
toolCallId: toolCallErrorResult.toolCallId,
|
|
6422
|
+
toolName: toolCallErrorResult.toolName,
|
|
6423
|
+
args: toolCallErrorResult.args,
|
|
6424
|
+
result: toolCallErrorResult.error?.message ?? toolCallErrorResult.error
|
|
6425
|
+
},
|
|
6426
|
+
...toolCallErrorResult.providerMetadata ? { providerMetadata: toolCallErrorResult.providerMetadata } : {}
|
|
5778
6427
|
};
|
|
5779
6428
|
})
|
|
5780
6429
|
},
|
|
5781
|
-
|
|
5782
|
-
|
|
6430
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
6431
|
+
};
|
|
6432
|
+
rest.messageList.add(msg, "response");
|
|
5783
6433
|
}
|
|
5784
6434
|
initialResult.stepResult.isContinued = false;
|
|
5785
6435
|
return bail(initialResult);
|
|
@@ -5807,24 +6457,30 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
|
|
|
5807
6457
|
})
|
|
5808
6458
|
});
|
|
5809
6459
|
}
|
|
5810
|
-
const toolResultMessageId = rest.experimental_generateMessageId?.() || _internal?.generateId?.();
|
|
5811
|
-
rest.messageList.add(
|
|
5812
|
-
{
|
|
5813
|
-
id: toolResultMessageId,
|
|
5814
|
-
role: "tool",
|
|
5815
|
-
content: inputData.map((toolCall2) => {
|
|
5816
|
-
return {
|
|
5817
|
-
type: "tool-result",
|
|
5818
|
-
args: toolCall2.args,
|
|
5819
|
-
toolCallId: toolCall2.toolCallId,
|
|
5820
|
-
toolName: toolCall2.toolName,
|
|
5821
|
-
result: toolCall2.result
|
|
5822
|
-
};
|
|
5823
|
-
})
|
|
5824
|
-
},
|
|
5825
|
-
"response"
|
|
5826
|
-
);
|
|
5827
6460
|
}
|
|
6461
|
+
const toolResultMessageId = rest.experimental_generateMessageId?.() || _internal?.generateId?.();
|
|
6462
|
+
const toolResultMessage = {
|
|
6463
|
+
id: toolResultMessageId || "",
|
|
6464
|
+
role: "assistant",
|
|
6465
|
+
content: {
|
|
6466
|
+
format: 2,
|
|
6467
|
+
parts: inputData.map((toolCall) => {
|
|
6468
|
+
return {
|
|
6469
|
+
type: "tool-invocation",
|
|
6470
|
+
toolInvocation: {
|
|
6471
|
+
state: "result",
|
|
6472
|
+
toolCallId: toolCall.toolCallId,
|
|
6473
|
+
toolName: toolCall.toolName,
|
|
6474
|
+
args: toolCall.args,
|
|
6475
|
+
result: toolCall.result
|
|
6476
|
+
},
|
|
6477
|
+
...toolCall.providerMetadata ? { providerMetadata: toolCall.providerMetadata } : {}
|
|
6478
|
+
};
|
|
6479
|
+
})
|
|
6480
|
+
},
|
|
6481
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
6482
|
+
};
|
|
6483
|
+
rest.messageList.add(toolResultMessage, "response");
|
|
5828
6484
|
return {
|
|
5829
6485
|
...initialResult,
|
|
5830
6486
|
messages: {
|
|
@@ -5981,7 +6637,8 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
|
|
|
5981
6637
|
// VNext execution as internal
|
|
5982
6638
|
internal: 1 /* WORKFLOW */
|
|
5983
6639
|
},
|
|
5984
|
-
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended"
|
|
6640
|
+
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
|
|
6641
|
+
validateInputs: false
|
|
5985
6642
|
}
|
|
5986
6643
|
}).then(llmExecutionStep).map(
|
|
5987
6644
|
async ({ inputData }) => {
|
|
@@ -6021,7 +6678,8 @@ function createAgenticLoopWorkflow(params) {
|
|
|
6021
6678
|
},
|
|
6022
6679
|
shouldPersistSnapshot: (params2) => {
|
|
6023
6680
|
return params2.workflowStatus === "suspended";
|
|
6024
|
-
}
|
|
6681
|
+
},
|
|
6682
|
+
validateInputs: false
|
|
6025
6683
|
}
|
|
6026
6684
|
}).dowhile(agenticExecutionWorkflow, async ({ inputData }) => {
|
|
6027
6685
|
const typedInputData = inputData;
|
|
@@ -6112,7 +6770,7 @@ function workflowLoopStream({
|
|
|
6112
6770
|
}) {
|
|
6113
6771
|
return new web.ReadableStream({
|
|
6114
6772
|
start: async (controller) => {
|
|
6115
|
-
const writer = new WritableStream({
|
|
6773
|
+
const writer = new web.WritableStream({
|
|
6116
6774
|
write: (chunk) => {
|
|
6117
6775
|
controller.enqueue(chunk);
|
|
6118
6776
|
}
|
|
@@ -6431,7 +7089,8 @@ var MastraLLMVNext = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
6431
7089
|
requireToolApproval,
|
|
6432
7090
|
_internal,
|
|
6433
7091
|
agentId,
|
|
6434
|
-
toolCallId
|
|
7092
|
+
toolCallId,
|
|
7093
|
+
methodType
|
|
6435
7094
|
}) {
|
|
6436
7095
|
let stopWhenToUse;
|
|
6437
7096
|
if (maxSteps && typeof maxSteps === "number") {
|
|
@@ -6488,6 +7147,7 @@ var MastraLLMVNext = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
6488
7147
|
modelSpanTracker,
|
|
6489
7148
|
requireToolApproval,
|
|
6490
7149
|
agentId,
|
|
7150
|
+
methodType,
|
|
6491
7151
|
options: {
|
|
6492
7152
|
...options,
|
|
6493
7153
|
onStepFinish: async (props) => {
|
|
@@ -6527,7 +7187,7 @@ var MastraLLMVNext = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
6527
7187
|
});
|
|
6528
7188
|
if (props?.response?.headers?.["x-ratelimit-remaining-tokens"] && parseInt(props?.response?.headers?.["x-ratelimit-remaining-tokens"], 10) < 2e3) {
|
|
6529
7189
|
this.logger.warn("Rate limit approaching, waiting 10 seconds", { runId });
|
|
6530
|
-
await
|
|
7190
|
+
await chunkHBJPYQRN_cjs.delay(10 * 1e3);
|
|
6531
7191
|
}
|
|
6532
7192
|
},
|
|
6533
7193
|
onFinish: async (props) => {
|
|
@@ -6831,7 +7491,7 @@ async function prepareMemoryStep({
|
|
|
6831
7491
|
);
|
|
6832
7492
|
}
|
|
6833
7493
|
} else {
|
|
6834
|
-
const messageList = new
|
|
7494
|
+
const messageList = new chunkVSM3NLUX_cjs.MessageList({
|
|
6835
7495
|
threadId: thread?.id,
|
|
6836
7496
|
resourceId: thread?.resourceId
|
|
6837
7497
|
});
|
|
@@ -7326,7 +7986,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
7326
7986
|
requestContext
|
|
7327
7987
|
});
|
|
7328
7988
|
let chunks = [];
|
|
7329
|
-
for await (const chunk of stream) {
|
|
7989
|
+
for await (const chunk of stream.fullStream) {
|
|
7330
7990
|
chunks.push(chunk);
|
|
7331
7991
|
await writer?.write({
|
|
7332
7992
|
type: `workflow-execution-event-${chunk.type}`,
|
|
@@ -7596,7 +8256,8 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
7596
8256
|
isOneOff: z5__default.default.boolean()
|
|
7597
8257
|
}),
|
|
7598
8258
|
options: {
|
|
7599
|
-
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended"
|
|
8259
|
+
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
|
|
8260
|
+
validateInputs: false
|
|
7600
8261
|
}
|
|
7601
8262
|
});
|
|
7602
8263
|
networkWorkflow.then(routingStep).branch([
|
|
@@ -7723,7 +8384,8 @@ async function networkLoop({
|
|
|
7723
8384
|
iteration: z5__default.default.number()
|
|
7724
8385
|
}),
|
|
7725
8386
|
options: {
|
|
7726
|
-
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended"
|
|
8387
|
+
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
|
|
8388
|
+
validateInputs: false
|
|
7727
8389
|
}
|
|
7728
8390
|
}).dountil(networkWorkflow, async ({ inputData }) => {
|
|
7729
8391
|
return inputData.isComplete || inputData.iteration >= maxIterations;
|
|
@@ -8281,7 +8943,7 @@ var AgentLegacyHandler = class {
|
|
|
8281
8943
|
writableStream,
|
|
8282
8944
|
methodType: methodType === "generate" ? "generateLegacy" : "streamLegacy"
|
|
8283
8945
|
});
|
|
8284
|
-
const messageList = new
|
|
8946
|
+
const messageList = new chunkVSM3NLUX_cjs.MessageList({
|
|
8285
8947
|
threadId,
|
|
8286
8948
|
resourceId,
|
|
8287
8949
|
generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
|
|
@@ -8362,7 +9024,7 @@ var AgentLegacyHandler = class {
|
|
|
8362
9024
|
existingThread || hasResourceScopeSemanticRecall ? this.capabilities.getMemoryMessages({
|
|
8363
9025
|
resourceId,
|
|
8364
9026
|
threadId: threadObject.id,
|
|
8365
|
-
vectorMessageSearch: new
|
|
9027
|
+
vectorMessageSearch: new chunkVSM3NLUX_cjs.MessageList().add(messages, `user`).getLatestUserContent() || "",
|
|
8366
9028
|
memoryConfig,
|
|
8367
9029
|
requestContext
|
|
8368
9030
|
}) : { messages: [] },
|
|
@@ -8384,7 +9046,7 @@ The following messages were remembered from a different conversation:
|
|
|
8384
9046
|
<remembered_from_other_conversation>
|
|
8385
9047
|
${(() => {
|
|
8386
9048
|
let result = ``;
|
|
8387
|
-
const messages2 = new
|
|
9049
|
+
const messages2 = new chunkVSM3NLUX_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
|
|
8388
9050
|
let lastYmd = null;
|
|
8389
9051
|
for (const msg of messages2) {
|
|
8390
9052
|
const date = msg.createdAt;
|
|
@@ -8435,7 +9097,7 @@ the following messages are from ${ymd}
|
|
|
8435
9097
|
systemMessage,
|
|
8436
9098
|
memorySystemMessage: memorySystemMessage || void 0
|
|
8437
9099
|
});
|
|
8438
|
-
const processedList = new
|
|
9100
|
+
const processedList = new chunkVSM3NLUX_cjs.MessageList({
|
|
8439
9101
|
threadId: threadObject.id,
|
|
8440
9102
|
resourceId,
|
|
8441
9103
|
generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
|
|
@@ -8491,7 +9153,7 @@ the following messages are from ${ymd}
|
|
|
8491
9153
|
result: resToLog,
|
|
8492
9154
|
threadId
|
|
8493
9155
|
});
|
|
8494
|
-
const messageListResponses = new
|
|
9156
|
+
const messageListResponses = new chunkVSM3NLUX_cjs.MessageList({
|
|
8495
9157
|
threadId,
|
|
8496
9158
|
resourceId,
|
|
8497
9159
|
generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
|
|
@@ -8851,7 +9513,7 @@ the following messages are from ${ymd}
|
|
|
8851
9513
|
requestContext: mergedGenerateOptions.requestContext || new chunkJ7O6WENZ_cjs.RequestContext(),
|
|
8852
9514
|
tracingContext,
|
|
8853
9515
|
outputProcessorOverrides: finalOutputProcessors,
|
|
8854
|
-
messageList: new
|
|
9516
|
+
messageList: new chunkVSM3NLUX_cjs.MessageList({
|
|
8855
9517
|
threadId: llmOptions.threadId || "",
|
|
8856
9518
|
resourceId: llmOptions.resourceId || ""
|
|
8857
9519
|
}).add(
|
|
@@ -8941,7 +9603,7 @@ the following messages are from ${ymd}
|
|
|
8941
9603
|
const outputProcessorResult = await this.capabilities.__runOutputProcessors({
|
|
8942
9604
|
requestContext: mergedGenerateOptions.requestContext || new chunkJ7O6WENZ_cjs.RequestContext(),
|
|
8943
9605
|
tracingContext,
|
|
8944
|
-
messageList: new
|
|
9606
|
+
messageList: new chunkVSM3NLUX_cjs.MessageList({
|
|
8945
9607
|
threadId: llmOptions.threadId || "",
|
|
8946
9608
|
resourceId: llmOptions.resourceId || ""
|
|
8947
9609
|
}).add(
|
|
@@ -9151,6 +9813,21 @@ the following messages are from ${ymd}
|
|
|
9151
9813
|
}
|
|
9152
9814
|
};
|
|
9153
9815
|
|
|
9816
|
+
// src/llm/model/model-method-from-agent.ts
|
|
9817
|
+
function getModelMethodFromAgentMethod(methodType) {
|
|
9818
|
+
if (methodType === "generate" || methodType === "generateLegacy") {
|
|
9819
|
+
return "generate";
|
|
9820
|
+
} else if (methodType === "stream" || methodType === "streamLegacy") {
|
|
9821
|
+
return "stream";
|
|
9822
|
+
} else {
|
|
9823
|
+
throw new chunkTWH4PTDG_cjs.MastraError({
|
|
9824
|
+
id: "INVALID_METHOD_TYPE",
|
|
9825
|
+
domain: "AGENT" /* AGENT */,
|
|
9826
|
+
category: "USER" /* USER */
|
|
9827
|
+
});
|
|
9828
|
+
}
|
|
9829
|
+
}
|
|
9830
|
+
|
|
9154
9831
|
// src/processors/processors/unicode-normalizer.ts
|
|
9155
9832
|
var UnicodeNormalizer = class {
|
|
9156
9833
|
id = "unicode-normalizer";
|
|
@@ -11149,7 +11826,8 @@ function createMapResultsStep({
|
|
|
11149
11826
|
memoryConfig,
|
|
11150
11827
|
saveQueueManager,
|
|
11151
11828
|
agentSpan,
|
|
11152
|
-
agentId
|
|
11829
|
+
agentId,
|
|
11830
|
+
methodType
|
|
11153
11831
|
}) {
|
|
11154
11832
|
return async ({
|
|
11155
11833
|
inputData,
|
|
@@ -11214,7 +11892,9 @@ function createMapResultsStep({
|
|
|
11214
11892
|
effectiveOutputProcessors = effectiveOutputProcessors ? [...effectiveOutputProcessors, structuredProcessor] : [structuredProcessor];
|
|
11215
11893
|
}
|
|
11216
11894
|
const messageList = memoryData.messageList;
|
|
11895
|
+
const modelMethodType = getModelMethodFromAgentMethod(methodType);
|
|
11217
11896
|
const loopOptions = {
|
|
11897
|
+
methodType: modelMethodType,
|
|
11218
11898
|
agentId,
|
|
11219
11899
|
requestContext: result.requestContext,
|
|
11220
11900
|
tracingContext: { currentSpan: agentSpan },
|
|
@@ -11318,7 +11998,7 @@ var prepareToolsStepOutputSchema = z5.z.object({
|
|
|
11318
11998
|
var prepareMemoryStepOutputSchema = z5.z.object({
|
|
11319
11999
|
threadExists: z5.z.boolean(),
|
|
11320
12000
|
thread: storageThreadSchema.optional(),
|
|
11321
|
-
messageList: z5.z.instanceof(
|
|
12001
|
+
messageList: z5.z.instanceof(chunkVSM3NLUX_cjs.MessageList),
|
|
11322
12002
|
tripwire: z5.z.boolean().optional(),
|
|
11323
12003
|
tripwireReason: z5.z.string().optional()
|
|
11324
12004
|
});
|
|
@@ -11351,7 +12031,7 @@ function createPrepareMemoryStep({
|
|
|
11351
12031
|
outputSchema: prepareMemoryStepOutputSchema,
|
|
11352
12032
|
execute: async ({ tracingContext }) => {
|
|
11353
12033
|
const thread = threadFromArgs;
|
|
11354
|
-
const messageList = new
|
|
12034
|
+
const messageList = new chunkVSM3NLUX_cjs.MessageList({
|
|
11355
12035
|
threadId: thread?.id,
|
|
11356
12036
|
resourceId,
|
|
11357
12037
|
generateMessageId: capabilities.generateMessageId,
|
|
@@ -11432,7 +12112,7 @@ function createPrepareMemoryStep({
|
|
|
11432
12112
|
existingThread || hasResourceScopeSemanticRecall ? capabilities.getMemoryMessages({
|
|
11433
12113
|
resourceId,
|
|
11434
12114
|
threadId: threadObject.id,
|
|
11435
|
-
vectorMessageSearch: new
|
|
12115
|
+
vectorMessageSearch: new chunkVSM3NLUX_cjs.MessageList().add(options.messages, `user`).getLatestUserContent() || "",
|
|
11436
12116
|
memoryConfig,
|
|
11437
12117
|
requestContext
|
|
11438
12118
|
}) : { messages: [] },
|
|
@@ -11458,7 +12138,7 @@ The following messages were remembered from a different conversation:
|
|
|
11458
12138
|
<remembered_from_other_conversation>
|
|
11459
12139
|
${(() => {
|
|
11460
12140
|
let result = ``;
|
|
11461
|
-
const messages = new
|
|
12141
|
+
const messages = new chunkVSM3NLUX_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
|
|
11462
12142
|
let lastYmd = null;
|
|
11463
12143
|
for (const msg of messages) {
|
|
11464
12144
|
const date = msg.createdAt;
|
|
@@ -11505,7 +12185,7 @@ the following messages are from ${ymd}
|
|
|
11505
12185
|
systemMessage,
|
|
11506
12186
|
memorySystemMessage: memorySystemMessage || void 0
|
|
11507
12187
|
});
|
|
11508
|
-
const processedList = new
|
|
12188
|
+
const processedList = new chunkVSM3NLUX_cjs.MessageList({
|
|
11509
12189
|
threadId: threadObject.id,
|
|
11510
12190
|
resourceId,
|
|
11511
12191
|
generateMessageId: capabilities.generateMessageId,
|
|
@@ -11580,7 +12260,8 @@ function createStreamStep({
|
|
|
11580
12260
|
requireToolApproval,
|
|
11581
12261
|
resumeContext,
|
|
11582
12262
|
agentId,
|
|
11583
|
-
toolCallId
|
|
12263
|
+
toolCallId,
|
|
12264
|
+
methodType
|
|
11584
12265
|
}) {
|
|
11585
12266
|
return createStep({
|
|
11586
12267
|
id: "stream-text-step",
|
|
@@ -11598,6 +12279,7 @@ function createStreamStep({
|
|
|
11598
12279
|
const processors = validatedInputData.outputProcessors || (capabilities.outputProcessors ? typeof capabilities.outputProcessors === "function" ? await capabilities.outputProcessors({
|
|
11599
12280
|
requestContext: validatedInputData.requestContext || new chunkJ7O6WENZ_cjs.RequestContext()
|
|
11600
12281
|
}) : capabilities.outputProcessors : []);
|
|
12282
|
+
const modelMethodType = getModelMethodFromAgentMethod(methodType);
|
|
11601
12283
|
const streamResult = capabilities.llm.stream({
|
|
11602
12284
|
...validatedInputData,
|
|
11603
12285
|
outputProcessors: processors,
|
|
@@ -11609,7 +12291,8 @@ function createStreamStep({
|
|
|
11609
12291
|
generateId: capabilities.generateMessageId
|
|
11610
12292
|
},
|
|
11611
12293
|
agentId,
|
|
11612
|
-
toolCallId
|
|
12294
|
+
toolCallId,
|
|
12295
|
+
methodType: modelMethodType
|
|
11613
12296
|
});
|
|
11614
12297
|
return streamResult;
|
|
11615
12298
|
}
|
|
@@ -11665,7 +12348,8 @@ function createPrepareStreamWorkflow({
|
|
|
11665
12348
|
requireToolApproval,
|
|
11666
12349
|
resumeContext,
|
|
11667
12350
|
agentId,
|
|
11668
|
-
toolCallId
|
|
12351
|
+
toolCallId,
|
|
12352
|
+
methodType
|
|
11669
12353
|
});
|
|
11670
12354
|
const mapResultsStep = createMapResultsStep({
|
|
11671
12355
|
capabilities,
|
|
@@ -11677,7 +12361,8 @@ function createPrepareStreamWorkflow({
|
|
|
11677
12361
|
memoryConfig,
|
|
11678
12362
|
saveQueueManager,
|
|
11679
12363
|
agentSpan,
|
|
11680
|
-
agentId
|
|
12364
|
+
agentId,
|
|
12365
|
+
methodType
|
|
11681
12366
|
});
|
|
11682
12367
|
return createWorkflow({
|
|
11683
12368
|
id: "execution-workflow",
|
|
@@ -11690,7 +12375,8 @@ function createPrepareStreamWorkflow({
|
|
|
11690
12375
|
options: {
|
|
11691
12376
|
tracingPolicy: {
|
|
11692
12377
|
internal: 1 /* WORKFLOW */
|
|
11693
|
-
}
|
|
12378
|
+
},
|
|
12379
|
+
validateInputs: false
|
|
11694
12380
|
}
|
|
11695
12381
|
}).parallel([prepareToolsStep, prepareMemoryStep2]).map(mapResultsStep).then(streamStep).commit();
|
|
11696
12382
|
}
|
|
@@ -11820,7 +12506,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
11820
12506
|
this.#voice?.addInstructions(config.instructions);
|
|
11821
12507
|
}
|
|
11822
12508
|
} else {
|
|
11823
|
-
this.#voice = new
|
|
12509
|
+
this.#voice = new chunkISMGVGUM_cjs.DefaultVoice();
|
|
11824
12510
|
}
|
|
11825
12511
|
if (config.inputProcessors) {
|
|
11826
12512
|
this.#inputProcessors = config.inputProcessors;
|
|
@@ -12067,7 +12753,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12067
12753
|
voice?.addInstructions(this.#convertInstructionsToString(instructions));
|
|
12068
12754
|
return voice;
|
|
12069
12755
|
} else {
|
|
12070
|
-
return new
|
|
12756
|
+
return new chunkISMGVGUM_cjs.DefaultVoice();
|
|
12071
12757
|
}
|
|
12072
12758
|
}
|
|
12073
12759
|
/**
|
|
@@ -12288,7 +12974,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12288
12974
|
*/
|
|
12289
12975
|
listTools({ requestContext = new chunkJ7O6WENZ_cjs.RequestContext() } = {}) {
|
|
12290
12976
|
if (typeof this.#tools !== "function") {
|
|
12291
|
-
return
|
|
12977
|
+
return chunkHBJPYQRN_cjs.ensureToolProperties(this.#tools);
|
|
12292
12978
|
}
|
|
12293
12979
|
const result = this.#tools({ requestContext, mastra: this.#mastra });
|
|
12294
12980
|
return resolveMaybePromise(result, (tools) => {
|
|
@@ -12306,7 +12992,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12306
12992
|
this.logger.error(mastraError.toString());
|
|
12307
12993
|
throw mastraError;
|
|
12308
12994
|
}
|
|
12309
|
-
return
|
|
12995
|
+
return chunkHBJPYQRN_cjs.ensureToolProperties(tools);
|
|
12310
12996
|
});
|
|
12311
12997
|
}
|
|
12312
12998
|
/**
|
|
@@ -12338,7 +13024,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12338
13024
|
});
|
|
12339
13025
|
});
|
|
12340
13026
|
} else {
|
|
12341
|
-
llm = new
|
|
13027
|
+
llm = new chunkO6NA3Z43_cjs.MastraLLMV1({
|
|
12342
13028
|
model: resolvedModel,
|
|
12343
13029
|
mastra: this.#mastra,
|
|
12344
13030
|
options: { tracingPolicy: this.#options?.tracingPolicy }
|
|
@@ -12363,7 +13049,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12363
13049
|
*/
|
|
12364
13050
|
async resolveModelConfig(modelConfig, requestContext) {
|
|
12365
13051
|
try {
|
|
12366
|
-
return await
|
|
13052
|
+
return await chunk3W5RQCCY_cjs.resolveModelConfig(modelConfig, requestContext, this.#mastra);
|
|
12367
13053
|
} catch (error) {
|
|
12368
13054
|
const mastraError = new chunkTWH4PTDG_cjs.MastraError({
|
|
12369
13055
|
id: "AGENT_GET_MODEL_MISSING_MODEL_INSTANCE",
|
|
@@ -12569,7 +13255,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12569
13255
|
instructions
|
|
12570
13256
|
}) {
|
|
12571
13257
|
const llm = await this.getLLM({ requestContext, model });
|
|
12572
|
-
const normMessage = new
|
|
13258
|
+
const normMessage = new chunkVSM3NLUX_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
|
|
12573
13259
|
if (!normMessage) {
|
|
12574
13260
|
throw new Error(`Could not generate title from input ${JSON.stringify(message)}`);
|
|
12575
13261
|
}
|
|
@@ -12592,7 +13278,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12592
13278
|
const systemInstructions = await this.resolveTitleInstructions(requestContext, instructions);
|
|
12593
13279
|
let text = "";
|
|
12594
13280
|
if (llm.getModel().specificationVersion === "v2") {
|
|
12595
|
-
const messageList = new
|
|
13281
|
+
const messageList = new chunkVSM3NLUX_cjs.MessageList().add(
|
|
12596
13282
|
[
|
|
12597
13283
|
{
|
|
12598
13284
|
role: "system",
|
|
@@ -12610,6 +13296,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12610
13296
|
"input"
|
|
12611
13297
|
);
|
|
12612
13298
|
const result = llm.stream({
|
|
13299
|
+
methodType: "generate",
|
|
12613
13300
|
requestContext,
|
|
12614
13301
|
tracingContext,
|
|
12615
13302
|
messageList,
|
|
@@ -12643,7 +13330,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12643
13330
|
async genTitle(userMessage, requestContext, tracingContext, model, instructions) {
|
|
12644
13331
|
try {
|
|
12645
13332
|
if (userMessage) {
|
|
12646
|
-
const normMessage = new
|
|
13333
|
+
const normMessage = new chunkVSM3NLUX_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
|
|
12647
13334
|
if (normMessage) {
|
|
12648
13335
|
return await this.generateTitleFromUserMessage({
|
|
12649
13336
|
message: normMessage,
|
|
@@ -12705,7 +13392,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12705
13392
|
model: await this.getModel({ requestContext }),
|
|
12706
13393
|
tracingPolicy: this.#options?.tracingPolicy
|
|
12707
13394
|
};
|
|
12708
|
-
const convertedToCoreTool =
|
|
13395
|
+
const convertedToCoreTool = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options);
|
|
12709
13396
|
convertedMemoryTools[toolName] = convertedToCoreTool;
|
|
12710
13397
|
}
|
|
12711
13398
|
}
|
|
@@ -12855,7 +13542,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12855
13542
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
12856
13543
|
requireApproval: tool.requireApproval
|
|
12857
13544
|
};
|
|
12858
|
-
return [k,
|
|
13545
|
+
return [k, chunkHBJPYQRN_cjs.makeCoreTool(tool, options)];
|
|
12859
13546
|
})
|
|
12860
13547
|
);
|
|
12861
13548
|
const assignedToolEntriesConverted = Object.fromEntries(
|
|
@@ -12903,7 +13590,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12903
13590
|
model: await this.getModel({ requestContext }),
|
|
12904
13591
|
tracingPolicy: this.#options?.tracingPolicy
|
|
12905
13592
|
};
|
|
12906
|
-
const convertedToCoreTool =
|
|
13593
|
+
const convertedToCoreTool = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options, "toolset");
|
|
12907
13594
|
toolsForRequest[toolName] = convertedToCoreTool;
|
|
12908
13595
|
}
|
|
12909
13596
|
}
|
|
@@ -12946,7 +13633,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12946
13633
|
model: await this.getModel({ requestContext }),
|
|
12947
13634
|
tracingPolicy: this.#options?.tracingPolicy
|
|
12948
13635
|
};
|
|
12949
|
-
const convertedToCoreTool =
|
|
13636
|
+
const convertedToCoreTool = chunkHBJPYQRN_cjs.makeCoreTool(rest, options, "client-tool");
|
|
12950
13637
|
toolsForRequest[toolName] = convertedToCoreTool;
|
|
12951
13638
|
}
|
|
12952
13639
|
}
|
|
@@ -12977,7 +13664,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12977
13664
|
subAgentResourceId: z5.z.string().describe("The resource ID of the agent").optional()
|
|
12978
13665
|
});
|
|
12979
13666
|
const modelVersion = (await agent.getModel()).specificationVersion;
|
|
12980
|
-
const toolObj =
|
|
13667
|
+
const toolObj = chunk4IKJAKCD_cjs.createTool({
|
|
12981
13668
|
id: `agent-${agentName}`,
|
|
12982
13669
|
description: `Agent: ${agentName}`,
|
|
12983
13670
|
inputSchema: agentInputSchema,
|
|
@@ -12997,12 +13684,24 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12997
13684
|
});
|
|
12998
13685
|
let result;
|
|
12999
13686
|
if ((methodType === "generate" || methodType === "generateLegacy") && modelVersion === "v2") {
|
|
13687
|
+
if (!agent.hasOwnMemory() && this.#memory) {
|
|
13688
|
+
agent.__setMemory(this.#memory);
|
|
13689
|
+
}
|
|
13690
|
+
const subAgentThreadId = crypto2.randomUUID();
|
|
13691
|
+
const slugify = await import('@sindresorhus/slugify');
|
|
13692
|
+
const subAgentResourceId = `${slugify.default(this.id)}-${agentName}`;
|
|
13000
13693
|
const generateResult = await agent.generate(inputData.prompt, {
|
|
13001
13694
|
requestContext,
|
|
13002
|
-
tracingContext: context?.tracingContext
|
|
13695
|
+
tracingContext: context?.tracingContext,
|
|
13696
|
+
...resourceId && threadId ? {
|
|
13697
|
+
memory: {
|
|
13698
|
+
resource: subAgentResourceId,
|
|
13699
|
+
thread: subAgentThreadId
|
|
13700
|
+
}
|
|
13701
|
+
} : {}
|
|
13003
13702
|
});
|
|
13004
|
-
result = { text: generateResult.text };
|
|
13005
|
-
} else if (
|
|
13703
|
+
result = { text: generateResult.text, subAgentThreadId, subAgentResourceId };
|
|
13704
|
+
} else if (methodType === "generate" && modelVersion === "v1") {
|
|
13006
13705
|
const generateResult = await agent.generateLegacy(inputData.prompt, {
|
|
13007
13706
|
requestContext,
|
|
13008
13707
|
tracingContext: context?.tracingContext
|
|
@@ -13089,7 +13788,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13089
13788
|
tracingContext,
|
|
13090
13789
|
tracingPolicy: this.#options?.tracingPolicy
|
|
13091
13790
|
};
|
|
13092
|
-
convertedAgentTools[`agent-${agentName}`] =
|
|
13791
|
+
convertedAgentTools[`agent-${agentName}`] = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options);
|
|
13093
13792
|
}
|
|
13094
13793
|
}
|
|
13095
13794
|
return convertedAgentTools;
|
|
@@ -13110,11 +13809,11 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13110
13809
|
const workflows = await this.listWorkflows({ requestContext });
|
|
13111
13810
|
if (Object.keys(workflows).length > 0) {
|
|
13112
13811
|
for (const [workflowName, workflow] of Object.entries(workflows)) {
|
|
13113
|
-
const toolObj =
|
|
13812
|
+
const toolObj = chunk4IKJAKCD_cjs.createTool({
|
|
13114
13813
|
id: `workflow-${workflowName}`,
|
|
13115
13814
|
description: workflow.description || `Workflow: ${workflowName}`,
|
|
13116
13815
|
inputSchema: workflow.inputSchema,
|
|
13117
|
-
outputSchema: workflow.outputSchema,
|
|
13816
|
+
outputSchema: z5.z.object({ result: workflow.outputSchema, runId: z5.z.string() }),
|
|
13118
13817
|
mastra: this.#mastra,
|
|
13119
13818
|
// BREAKING CHANGE v1.0: New tool signature - first param is inputData, second is context
|
|
13120
13819
|
// manually wrap workflow tools with tracing, so that we can pass the
|
|
@@ -13161,7 +13860,8 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13161
13860
|
}
|
|
13162
13861
|
result = await streamResult.result;
|
|
13163
13862
|
}
|
|
13164
|
-
|
|
13863
|
+
const workflowOutput = result?.result || result;
|
|
13864
|
+
return { result: workflowOutput, runId: run.runId };
|
|
13165
13865
|
} catch (err) {
|
|
13166
13866
|
const mastraError = new chunkTWH4PTDG_cjs.MastraError(
|
|
13167
13867
|
{
|
|
@@ -13198,7 +13898,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13198
13898
|
tracingContext,
|
|
13199
13899
|
tracingPolicy: this.#options?.tracingPolicy
|
|
13200
13900
|
};
|
|
13201
|
-
convertedWorkflowTools[`workflow-${workflowName}`] =
|
|
13901
|
+
convertedWorkflowTools[`workflow-${workflowName}`] = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options);
|
|
13202
13902
|
}
|
|
13203
13903
|
}
|
|
13204
13904
|
return convertedWorkflowTools;
|
|
@@ -13221,7 +13921,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13221
13921
|
let mastraProxy = void 0;
|
|
13222
13922
|
const logger = this.logger;
|
|
13223
13923
|
if (this.#mastra) {
|
|
13224
|
-
mastraProxy =
|
|
13924
|
+
mastraProxy = chunkHBJPYQRN_cjs.createMastraProxy({ mastra: this.#mastra, logger });
|
|
13225
13925
|
}
|
|
13226
13926
|
const assignedTools = await this.listAssignedTools({
|
|
13227
13927
|
runId,
|
|
@@ -13441,7 +14141,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13441
14141
|
if (model || !Array.isArray(this.model)) {
|
|
13442
14142
|
const modelToUse = model ?? this.model;
|
|
13443
14143
|
const resolvedModel = typeof modelToUse === "function" ? await modelToUse({ requestContext, mastra: this.#mastra }) : modelToUse;
|
|
13444
|
-
if (resolvedModel
|
|
14144
|
+
if (resolvedModel?.specificationVersion !== "v2") {
|
|
13445
14145
|
const mastraError = new chunkTWH4PTDG_cjs.MastraError({
|
|
13446
14146
|
id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
|
|
13447
14147
|
domain: "AGENT" /* AGENT */,
|
|
@@ -13458,6 +14158,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13458
14158
|
return [
|
|
13459
14159
|
{
|
|
13460
14160
|
id: "main",
|
|
14161
|
+
// TODO fix type check
|
|
13461
14162
|
model: resolvedModel,
|
|
13462
14163
|
maxRetries: this.maxRetries ?? 0,
|
|
13463
14164
|
enabled: true
|
|
@@ -13467,7 +14168,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13467
14168
|
const models = await Promise.all(
|
|
13468
14169
|
this.model.map(async (modelConfig) => {
|
|
13469
14170
|
const model2 = await this.resolveModelConfig(modelConfig.model, requestContext);
|
|
13470
|
-
if (model2
|
|
14171
|
+
if (!isV2Model(model2)) {
|
|
13471
14172
|
const mastraError = new chunkTWH4PTDG_cjs.MastraError({
|
|
13472
14173
|
id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
|
|
13473
14174
|
domain: "AGENT" /* AGENT */,
|
|
@@ -13814,8 +14515,59 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13814
14515
|
});
|
|
13815
14516
|
}
|
|
13816
14517
|
async generate(messages, options) {
|
|
13817
|
-
const
|
|
13818
|
-
|
|
14518
|
+
const defaultOptions = await this.getDefaultOptions({
|
|
14519
|
+
requestContext: options?.requestContext
|
|
14520
|
+
});
|
|
14521
|
+
const mergedOptions = {
|
|
14522
|
+
...defaultOptions,
|
|
14523
|
+
...options ?? {}
|
|
14524
|
+
};
|
|
14525
|
+
const llm = await this.getLLM({
|
|
14526
|
+
requestContext: mergedOptions.requestContext
|
|
14527
|
+
});
|
|
14528
|
+
const modelInfo = llm.getModel();
|
|
14529
|
+
if (modelInfo.specificationVersion !== "v2") {
|
|
14530
|
+
const modelId = modelInfo.modelId || "unknown";
|
|
14531
|
+
const provider = modelInfo.provider || "unknown";
|
|
14532
|
+
throw new chunkTWH4PTDG_cjs.MastraError({
|
|
14533
|
+
id: "AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED",
|
|
14534
|
+
domain: "AGENT" /* AGENT */,
|
|
14535
|
+
category: "USER" /* USER */,
|
|
14536
|
+
text: `Agent "${this.name}" is using AI SDK v4 model (${provider}:${modelId}) which is not compatible with generate(). Please use AI SDK v5 models or call the generateLegacy() method instead. See https://mastra.ai/en/docs/streaming/overview for more information.`,
|
|
14537
|
+
details: {
|
|
14538
|
+
agentName: this.name,
|
|
14539
|
+
modelId,
|
|
14540
|
+
provider,
|
|
14541
|
+
specificationVersion: modelInfo.specificationVersion
|
|
14542
|
+
}
|
|
14543
|
+
});
|
|
14544
|
+
}
|
|
14545
|
+
const executeOptions = {
|
|
14546
|
+
...mergedOptions,
|
|
14547
|
+
messages,
|
|
14548
|
+
methodType: "generate"
|
|
14549
|
+
};
|
|
14550
|
+
const result = await this.#execute(executeOptions);
|
|
14551
|
+
if (result.status !== "success") {
|
|
14552
|
+
if (result.status === "failed") {
|
|
14553
|
+
throw new chunkTWH4PTDG_cjs.MastraError(
|
|
14554
|
+
{
|
|
14555
|
+
id: "AGENT_GENERATE_FAILED",
|
|
14556
|
+
domain: "AGENT" /* AGENT */,
|
|
14557
|
+
category: "USER" /* USER */
|
|
14558
|
+
},
|
|
14559
|
+
// pass original error to preserve stack trace
|
|
14560
|
+
result.error
|
|
14561
|
+
);
|
|
14562
|
+
}
|
|
14563
|
+
throw new chunkTWH4PTDG_cjs.MastraError({
|
|
14564
|
+
id: "AGENT_GENERATE_UNKNOWN_ERROR",
|
|
14565
|
+
domain: "AGENT" /* AGENT */,
|
|
14566
|
+
category: "USER" /* USER */,
|
|
14567
|
+
text: "An unknown error occurred while streaming"
|
|
14568
|
+
});
|
|
14569
|
+
}
|
|
14570
|
+
const fullOutput = await result.result.getFullOutput();
|
|
13819
14571
|
const error = fullOutput.error;
|
|
13820
14572
|
if (fullOutput.finishReason === "error" && error) {
|
|
13821
14573
|
throw error;
|
|
@@ -15204,7 +15956,7 @@ var MastraModelOutput = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
15204
15956
|
self.messageList,
|
|
15205
15957
|
options.tracingContext
|
|
15206
15958
|
);
|
|
15207
|
-
const outputText = self.messageList.get.response.aiV4.core().map((m) =>
|
|
15959
|
+
const outputText = self.messageList.get.response.aiV4.core().map((m) => chunkVSM3NLUX_cjs.MessageList.coreContentToString(m.content)).join("\n");
|
|
15208
15960
|
self.#delayedPromises.text.resolve(outputText);
|
|
15209
15961
|
self.#delayedPromises.finishReason.resolve(self.#finishReason);
|
|
15210
15962
|
if (chunk.payload.metadata) {
|
|
@@ -15827,8 +16579,10 @@ exports.convertFullStreamChunkToUIMessageStream = convertFullStreamChunkToUIMess
|
|
|
15827
16579
|
exports.convertMastraChunkToAISDKv5 = convertMastraChunkToAISDKv5;
|
|
15828
16580
|
exports.createDeprecationProxy = createDeprecationProxy;
|
|
15829
16581
|
exports.createStep = createStep;
|
|
16582
|
+
exports.createTimeTravelExecutionParams = createTimeTravelExecutionParams;
|
|
15830
16583
|
exports.createWorkflow = createWorkflow;
|
|
15831
16584
|
exports.getResumeLabelsByStepId = getResumeLabelsByStepId;
|
|
16585
|
+
exports.getStepIds = getStepIds;
|
|
15832
16586
|
exports.getStepResult = getStepResult;
|
|
15833
16587
|
exports.getZodErrors = getZodErrors;
|
|
15834
16588
|
exports.loop = loop;
|
|
@@ -15838,5 +16592,6 @@ exports.runCountDeprecationMessage = runCountDeprecationMessage;
|
|
|
15838
16592
|
exports.tryGenerateWithJsonFallback = tryGenerateWithJsonFallback;
|
|
15839
16593
|
exports.tryStreamWithJsonFallback = tryStreamWithJsonFallback;
|
|
15840
16594
|
exports.validateStepInput = validateStepInput;
|
|
15841
|
-
|
|
15842
|
-
//# sourceMappingURL=chunk-
|
|
16595
|
+
exports.validateStepResumeData = validateStepResumeData;
|
|
16596
|
+
//# sourceMappingURL=chunk-2NVBZKZI.cjs.map
|
|
16597
|
+
//# sourceMappingURL=chunk-2NVBZKZI.cjs.map
|