@mastra/core 1.0.0-beta.1 → 1.0.0-beta.3
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 +171 -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.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-3PSWNGBF.js +3 -0
- package/dist/{chunk-ZV5CC35D.js.map → chunk-3PSWNGBF.js.map} +1 -1
- package/dist/{chunk-IQO7ANVS.cjs → chunk-3VOUB4ZU.cjs} +10 -9
- package/dist/chunk-3VOUB4ZU.cjs.map +1 -0
- package/dist/{chunk-H6CZGPZD.js → chunk-4DWZ4Z6H.js} +157 -24
- package/dist/chunk-4DWZ4Z6H.js.map +1 -0
- package/dist/{chunk-ET6UOTTU.cjs → chunk-4IKJAKCD.cjs} +40 -4
- package/dist/chunk-4IKJAKCD.cjs.map +1 -0
- package/dist/{chunk-MA7TEM62.cjs → chunk-4RSHBKDJ.cjs} +244 -4
- package/dist/chunk-4RSHBKDJ.cjs.map +1 -0
- package/dist/{chunk-MV7KHWUT.js → chunk-5CWWU22H.js} +25 -4
- package/dist/chunk-5CWWU22H.js.map +1 -0
- package/dist/{chunk-JV2KH24V.js → chunk-BAMR7HKO.js} +18 -13
- package/dist/chunk-BAMR7HKO.js.map +1 -0
- package/dist/{chunk-JUBFO5J3.js → chunk-CKGIPST2.js} +829 -92
- package/dist/chunk-CKGIPST2.js.map +1 -0
- package/dist/{chunk-4CDL2QJT.js → chunk-D6EDHNGV.js} +53 -16
- package/dist/chunk-D6EDHNGV.js.map +1 -0
- package/dist/{chunk-CD56CXVE.cjs → chunk-EZVRSZMK.cjs} +13 -12
- package/dist/chunk-EZVRSZMK.cjs.map +1 -0
- package/dist/{chunk-ECFXGXWO.cjs → chunk-G36A2JRR.cjs} +18 -13
- package/dist/chunk-G36A2JRR.cjs.map +1 -0
- package/dist/{chunk-VOQ3ULMT.js → chunk-G3OOCXAI.js} +243 -3
- package/dist/chunk-G3OOCXAI.js.map +1 -0
- package/dist/{chunk-I4CXL4SR.js → chunk-GRGPQ32U.js} +5 -4
- package/dist/chunk-GRGPQ32U.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-GGYKYORQ.cjs → chunk-JTXVR2RA.cjs} +27 -6
- package/dist/chunk-JTXVR2RA.cjs.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-KOSW5PP5.js} +8 -2
- package/dist/chunk-KOSW5PP5.js.map +1 -0
- package/dist/chunk-MCUX2D5Q.js +420 -0
- package/dist/chunk-MCUX2D5Q.js.map +1 -0
- package/dist/chunk-N4SJ4YX7.cjs +424 -0
- package/dist/chunk-N4SJ4YX7.cjs.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-CINNK34N.js → chunk-OQF4H5Y2.js} +6 -5
- package/dist/chunk-OQF4H5Y2.js.map +1 -0
- package/dist/{chunk-MSWTA73A.cjs → chunk-OWX2PUFH.cjs} +866 -126
- package/dist/chunk-OWX2PUFH.cjs.map +1 -0
- package/dist/chunk-PE3V7GUL.cjs +4 -0
- package/dist/{chunk-LJFJTTZQ.cjs.map → chunk-PE3V7GUL.cjs.map} +1 -1
- package/dist/{chunk-HDJFSJCK.js → chunk-T3WZCEC4.js} +4 -3
- package/dist/chunk-T3WZCEC4.js.map +1 -0
- package/dist/{chunk-W7UH2PWL.js → chunk-VU6DVS7J.js} +179 -282
- package/dist/chunk-VU6DVS7J.js.map +1 -0
- package/dist/{chunk-DNEURYF3.cjs → chunk-VZGBVYXA.cjs} +175 -42
- package/dist/chunk-VZGBVYXA.cjs.map +1 -0
- package/dist/{chunk-2ZVKF4HP.cjs → chunk-XRIVPHXV.cjs} +184 -285
- package/dist/chunk-XRIVPHXV.cjs.map +1 -0
- package/dist/{chunk-LWBQ4P4N.cjs → chunk-YQ7NLZZ3.cjs} +54 -53
- package/dist/chunk-YQ7NLZZ3.cjs.map +1 -0
- package/dist/{chunk-CB575O6L.cjs → chunk-ZPMFINU2.cjs} +8 -2
- package/dist/chunk-ZPMFINU2.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-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-GCVENVWA.js +3 -0
- package/dist/{models-dev-DNBKXHT4.js.map → models-dev-GCVENVWA.js.map} +1 -1
- package/dist/models-dev-TIBJR6IG.cjs +12 -0
- package/dist/{models-dev-YBEEQIX6.cjs.map → models-dev-TIBJR6IG.cjs.map} +1 -1
- package/dist/netlify-NTSNNT6F.cjs +12 -0
- package/dist/{netlify-GWNGSIRZ.cjs.map → netlify-NTSNNT6F.cjs.map} +1 -1
- package/dist/netlify-O5NJW7CF.js +3 -0
- package/dist/{netlify-7G2L5VSH.js.map → netlify-O5NJW7CF.js.map} +1 -1
- package/dist/processors/index.cjs +11 -11
- package/dist/processors/index.js +1 -1
- package/dist/provider-registry-74GMFZKT.js +3 -0
- package/dist/provider-registry-74GMFZKT.js.map +1 -0
- package/dist/provider-registry-BZP3DIIV.cjs +40 -0
- package/dist/provider-registry-BZP3DIIV.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/index.cjs +2 -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 +2 -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/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 +2 -2
- package/dist/test-utils/llm-mock.js +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/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/step-executor.d.ts.map +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 +2 -1
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +64 -7
- 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 +109 -40
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +12 -20
- package/src/llm/model/provider-types.generated.d.ts +56 -7
- 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-CB575O6L.cjs.map +0 -1
- package/dist/chunk-CD56CXVE.cjs.map +0 -1
- package/dist/chunk-CINNK34N.js.map +0 -1
- package/dist/chunk-DNEURYF3.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-H6CZGPZD.js.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-JUBFO5J3.js.map +0 -1
- package/dist/chunk-JV2KH24V.js.map +0 -1
- package/dist/chunk-LJFJTTZQ.cjs +0 -4
- package/dist/chunk-LWBQ4P4N.cjs.map +0 -1
- package/dist/chunk-MA7TEM62.cjs.map +0 -1
- package/dist/chunk-MSWTA73A.cjs.map +0 -1
- package/dist/chunk-MV7KHWUT.js.map +0 -1
- package/dist/chunk-VOQ3ULMT.js.map +0 -1
- package/dist/chunk-W7UH2PWL.js.map +0 -1
- package/dist/chunk-WM6CK2F3.cjs.map +0 -1
- package/dist/chunk-ZV5CC35D.js +0 -3
- 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
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
var chunkQUKUN6NR_cjs = require('./chunk-QUKUN6NR.cjs');
|
|
4
4
|
var chunkABJOUEVA_cjs = require('./chunk-ABJOUEVA.cjs');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
5
|
+
var chunkG36A2JRR_cjs = require('./chunk-G36A2JRR.cjs');
|
|
6
|
+
var chunkN4SJ4YX7_cjs = require('./chunk-N4SJ4YX7.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');
|
|
@@ -543,6 +543,11 @@ function runScorer({
|
|
|
543
543
|
chunkMR7ZWBL6_cjs.executeHook("onScorerRun" /* ON_SCORER_RUN */, payload);
|
|
544
544
|
}
|
|
545
545
|
|
|
546
|
+
// src/llm/model/is-v2-model.ts
|
|
547
|
+
function isV2Model(model) {
|
|
548
|
+
return model.specificationVersion === "v2";
|
|
549
|
+
}
|
|
550
|
+
|
|
546
551
|
// src/stream/base/consume-stream.ts
|
|
547
552
|
async function consumeStream2({
|
|
548
553
|
stream,
|
|
@@ -599,7 +604,7 @@ var WorkflowRunOutput = class {
|
|
|
599
604
|
this.workflowId = workflowId;
|
|
600
605
|
this.#baseStream = stream;
|
|
601
606
|
stream.pipeTo(
|
|
602
|
-
new WritableStream({
|
|
607
|
+
new web.WritableStream({
|
|
603
608
|
start() {
|
|
604
609
|
const chunk = {
|
|
605
610
|
type: "workflow-start",
|
|
@@ -727,7 +732,7 @@ var WorkflowRunOutput = class {
|
|
|
727
732
|
};
|
|
728
733
|
const self = this;
|
|
729
734
|
stream.pipeTo(
|
|
730
|
-
new WritableStream({
|
|
735
|
+
new web.WritableStream({
|
|
731
736
|
start() {
|
|
732
737
|
const chunk = {
|
|
733
738
|
type: "workflow-start",
|
|
@@ -962,6 +967,24 @@ async function validateStepInput({
|
|
|
962
967
|
}
|
|
963
968
|
return { inputData, validationError };
|
|
964
969
|
}
|
|
970
|
+
async function validateStepResumeData({ resumeData, step }) {
|
|
971
|
+
if (!resumeData) {
|
|
972
|
+
return { resumeData: void 0, validationError: void 0 };
|
|
973
|
+
}
|
|
974
|
+
let validationError;
|
|
975
|
+
const resumeSchema = step.resumeSchema;
|
|
976
|
+
if (resumeSchema) {
|
|
977
|
+
const validatedResumeData = await resumeSchema.safeParseAsync(resumeData);
|
|
978
|
+
if (!validatedResumeData.success) {
|
|
979
|
+
const errors = getZodErrors(validatedResumeData.error);
|
|
980
|
+
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
981
|
+
validationError = new Error("Step resume data validation failed: \n" + errorMessages);
|
|
982
|
+
} else {
|
|
983
|
+
resumeData = validatedResumeData.data;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
return { resumeData, validationError };
|
|
987
|
+
}
|
|
965
988
|
function getResumeLabelsByStepId(resumeLabels, stepId) {
|
|
966
989
|
return Object.entries(resumeLabels).filter(([_, value]) => value.stepId === stepId).reduce(
|
|
967
990
|
(acc, [key, value]) => {
|
|
@@ -992,6 +1015,111 @@ function createDeprecationProxy(params, {
|
|
|
992
1015
|
}
|
|
993
1016
|
});
|
|
994
1017
|
}
|
|
1018
|
+
var getStepIds = (entry) => {
|
|
1019
|
+
if (entry.type === "step" || entry.type === "foreach" || entry.type === "loop") {
|
|
1020
|
+
return [entry.step.id];
|
|
1021
|
+
}
|
|
1022
|
+
if (entry.type === "parallel" || entry.type === "conditional") {
|
|
1023
|
+
return entry.steps.map((s) => s.step.id);
|
|
1024
|
+
}
|
|
1025
|
+
if (entry.type === "sleep" || entry.type === "sleepUntil") {
|
|
1026
|
+
return [entry.id];
|
|
1027
|
+
}
|
|
1028
|
+
return [];
|
|
1029
|
+
};
|
|
1030
|
+
var createTimeTravelExecutionParams = (params) => {
|
|
1031
|
+
const { steps, inputData, resumeData, context, nestedStepsContext, snapshot, initialState, graph } = params;
|
|
1032
|
+
const firstStepId = steps[0];
|
|
1033
|
+
let executionPath = [];
|
|
1034
|
+
const stepResults = {};
|
|
1035
|
+
const snapshotContext = snapshot.context;
|
|
1036
|
+
for (const [index, entry] of graph.steps.entries()) {
|
|
1037
|
+
const currentExecPathLength = executionPath.length;
|
|
1038
|
+
if (currentExecPathLength > 0 && !resumeData) {
|
|
1039
|
+
break;
|
|
1040
|
+
}
|
|
1041
|
+
const stepIds = getStepIds(entry);
|
|
1042
|
+
if (stepIds.includes(firstStepId)) {
|
|
1043
|
+
const innerExecutionPath = stepIds?.length > 1 ? [stepIds?.findIndex((s) => s === firstStepId)] : [];
|
|
1044
|
+
executionPath = [index, ...innerExecutionPath];
|
|
1045
|
+
}
|
|
1046
|
+
const prevStep = graph.steps[index - 1];
|
|
1047
|
+
let stepPayload = void 0;
|
|
1048
|
+
if (prevStep) {
|
|
1049
|
+
const prevStepIds = getStepIds(prevStep);
|
|
1050
|
+
if (prevStepIds.length > 0) {
|
|
1051
|
+
if (prevStepIds.length === 1) {
|
|
1052
|
+
stepPayload = stepResults?.[prevStepIds[0]]?.output ?? {};
|
|
1053
|
+
} else {
|
|
1054
|
+
stepPayload = prevStepIds.reduce(
|
|
1055
|
+
(acc, stepId) => {
|
|
1056
|
+
acc[stepId] = stepResults?.[stepId]?.output ?? {};
|
|
1057
|
+
return acc;
|
|
1058
|
+
},
|
|
1059
|
+
{}
|
|
1060
|
+
);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
if (index === 0 && stepIds.includes(firstStepId)) {
|
|
1065
|
+
stepResults.input = context?.[firstStepId]?.payload ?? inputData ?? snapshotContext?.input;
|
|
1066
|
+
} else if (index === 0) {
|
|
1067
|
+
stepResults.input = stepIds?.reduce((acc, stepId) => {
|
|
1068
|
+
if (acc) return acc;
|
|
1069
|
+
return context?.[stepId]?.payload ?? snapshotContext?.[stepId]?.payload;
|
|
1070
|
+
}, null) ?? snapshotContext?.input ?? {};
|
|
1071
|
+
}
|
|
1072
|
+
let stepOutput = void 0;
|
|
1073
|
+
const nextStep = graph.steps[index + 1];
|
|
1074
|
+
if (nextStep) {
|
|
1075
|
+
const nextStepIds = getStepIds(nextStep);
|
|
1076
|
+
if (nextStepIds.length > 0 && inputData && nextStepIds.includes(firstStepId) && steps.length === 1) {
|
|
1077
|
+
stepOutput = inputData;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
stepIds.forEach((stepId) => {
|
|
1081
|
+
let result;
|
|
1082
|
+
const stepContext = context?.[stepId] ?? snapshotContext[stepId];
|
|
1083
|
+
const defaultStepStatus = steps?.includes(stepId) ? "running" : "success";
|
|
1084
|
+
const status = ["failed", "canceled"].includes(stepContext?.status) ? defaultStepStatus : stepContext?.status ?? defaultStepStatus;
|
|
1085
|
+
const isCompleteStatus = ["success", "failed", "canceled"].includes(status);
|
|
1086
|
+
result = {
|
|
1087
|
+
status,
|
|
1088
|
+
payload: context?.[stepId]?.payload ?? stepPayload ?? snapshotContext[stepId]?.payload ?? {},
|
|
1089
|
+
output: isCompleteStatus ? context?.[stepId]?.output ?? stepOutput ?? snapshotContext[stepId]?.output ?? {} : void 0,
|
|
1090
|
+
resumePayload: stepContext?.resumePayload,
|
|
1091
|
+
suspendPayload: stepContext?.suspendPayload,
|
|
1092
|
+
suspendOutput: stepContext?.suspendOutput,
|
|
1093
|
+
startedAt: stepContext?.startedAt ?? Date.now(),
|
|
1094
|
+
endedAt: isCompleteStatus ? stepContext?.endedAt ?? Date.now() : void 0,
|
|
1095
|
+
suspendedAt: stepContext?.suspendedAt,
|
|
1096
|
+
resumedAt: stepContext?.resumedAt
|
|
1097
|
+
};
|
|
1098
|
+
if (currentExecPathLength > 0 && (!snapshotContext[stepId] || snapshotContext[stepId] && snapshotContext[stepId].status !== "suspended")) {
|
|
1099
|
+
result = void 0;
|
|
1100
|
+
}
|
|
1101
|
+
if (result) {
|
|
1102
|
+
const formattedResult = chunkHBJPYQRN_cjs.removeUndefinedValues(result);
|
|
1103
|
+
stepResults[stepId] = formattedResult;
|
|
1104
|
+
}
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
if (!executionPath.length) {
|
|
1108
|
+
throw new Error(
|
|
1109
|
+
`Time travel target step not found in execution graph: '${steps?.join(".")}'. Verify the step id/path.`
|
|
1110
|
+
);
|
|
1111
|
+
}
|
|
1112
|
+
const timeTravelData = {
|
|
1113
|
+
inputData,
|
|
1114
|
+
executionPath,
|
|
1115
|
+
steps,
|
|
1116
|
+
stepResults,
|
|
1117
|
+
nestedStepResults: nestedStepsContext,
|
|
1118
|
+
state: initialState ?? snapshot.value ?? {},
|
|
1119
|
+
resumeData
|
|
1120
|
+
};
|
|
1121
|
+
return timeTravelData;
|
|
1122
|
+
};
|
|
995
1123
|
|
|
996
1124
|
// src/workflows/default.ts
|
|
997
1125
|
var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
@@ -1078,7 +1206,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1078
1206
|
resume,
|
|
1079
1207
|
retryConfig,
|
|
1080
1208
|
workflowSpan,
|
|
1081
|
-
disableScorers
|
|
1209
|
+
disableScorers,
|
|
1210
|
+
restart,
|
|
1211
|
+
timeTravel
|
|
1082
1212
|
} = params;
|
|
1083
1213
|
const { attempts = 0, delay: delay2 = 0 } = retryConfig ?? {};
|
|
1084
1214
|
const steps = graph.steps;
|
|
@@ -1094,19 +1224,26 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1094
1224
|
throw empty_graph_error;
|
|
1095
1225
|
}
|
|
1096
1226
|
let startIdx = 0;
|
|
1097
|
-
if (
|
|
1227
|
+
if (timeTravel) {
|
|
1228
|
+
startIdx = timeTravel.executionPath[0];
|
|
1229
|
+
timeTravel.executionPath.shift();
|
|
1230
|
+
} else if (restart) {
|
|
1231
|
+
startIdx = restart.activePaths[0];
|
|
1232
|
+
restart.activePaths.shift();
|
|
1233
|
+
} else if (resume?.resumePath) {
|
|
1098
1234
|
startIdx = resume.resumePath[0];
|
|
1099
1235
|
resume.resumePath.shift();
|
|
1100
1236
|
}
|
|
1101
|
-
const stepResults = resume?.stepResults || { input };
|
|
1237
|
+
const stepResults = timeTravel?.stepResults || restart?.stepResults || resume?.stepResults || { input };
|
|
1102
1238
|
let lastOutput;
|
|
1103
|
-
let lastState = initialState ?? {};
|
|
1239
|
+
let lastState = timeTravel?.state ?? restart?.state ?? initialState ?? {};
|
|
1104
1240
|
for (let i = startIdx; i < steps.length; i++) {
|
|
1105
1241
|
const entry = steps[i];
|
|
1106
1242
|
const executionContext = {
|
|
1107
1243
|
workflowId,
|
|
1108
1244
|
runId,
|
|
1109
1245
|
executionPath: [i],
|
|
1246
|
+
activeStepsPath: {},
|
|
1110
1247
|
suspendedPaths: {},
|
|
1111
1248
|
resumeLabels: {},
|
|
1112
1249
|
retryConfig: { attempts, delay: delay2 },
|
|
@@ -1124,6 +1261,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1124
1261
|
prevStep: steps[i - 1],
|
|
1125
1262
|
stepResults,
|
|
1126
1263
|
resume,
|
|
1264
|
+
timeTravel,
|
|
1265
|
+
restart,
|
|
1127
1266
|
tracingContext: {
|
|
1128
1267
|
currentSpan: workflowSpan
|
|
1129
1268
|
},
|
|
@@ -1413,7 +1552,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1413
1552
|
step,
|
|
1414
1553
|
stepResults,
|
|
1415
1554
|
executionContext,
|
|
1555
|
+
restart,
|
|
1416
1556
|
resume,
|
|
1557
|
+
timeTravel,
|
|
1417
1558
|
prevOutput,
|
|
1418
1559
|
emitter,
|
|
1419
1560
|
abortController,
|
|
@@ -1425,22 +1566,38 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1425
1566
|
tracingContext,
|
|
1426
1567
|
iterationCount
|
|
1427
1568
|
}) {
|
|
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
1569
|
const stepCallId = crypto2.randomUUID();
|
|
1431
1570
|
const { inputData, validationError } = await validateStepInput({
|
|
1432
1571
|
prevOutput,
|
|
1433
1572
|
step,
|
|
1434
|
-
validateInputs: this.options?.validateInputs ??
|
|
1573
|
+
validateInputs: this.options?.validateInputs ?? true
|
|
1574
|
+
});
|
|
1575
|
+
const { resumeData: timeTravelResumeData, validationError: timeTravelResumeValidationError } = await validateStepResumeData({
|
|
1576
|
+
resumeData: timeTravel?.stepResults[step.id]?.status === "suspended" ? timeTravel?.resumeData : void 0,
|
|
1577
|
+
step
|
|
1435
1578
|
});
|
|
1579
|
+
let resumeDataToUse;
|
|
1580
|
+
if (timeTravelResumeData && !timeTravelResumeValidationError) {
|
|
1581
|
+
resumeDataToUse = timeTravelResumeData;
|
|
1582
|
+
} else if (timeTravelResumeData && timeTravelResumeValidationError) {
|
|
1583
|
+
this.logger.warn("Time travel resume data validation failed", {
|
|
1584
|
+
stepId: step.id,
|
|
1585
|
+
error: timeTravelResumeValidationError.message
|
|
1586
|
+
});
|
|
1587
|
+
} else if (resume?.steps[0] === step.id) {
|
|
1588
|
+
resumeDataToUse = resume?.resumePayload;
|
|
1589
|
+
}
|
|
1590
|
+
const startTime = resumeDataToUse ? void 0 : Date.now();
|
|
1591
|
+
const resumeTime = resumeDataToUse ? Date.now() : void 0;
|
|
1436
1592
|
const stepInfo = {
|
|
1437
1593
|
...stepResults[step.id],
|
|
1438
|
-
...
|
|
1594
|
+
...resumeDataToUse ? { resumePayload: resumeDataToUse } : { payload: inputData },
|
|
1439
1595
|
...startTime ? { startedAt: startTime } : {},
|
|
1440
1596
|
...resumeTime ? { resumedAt: resumeTime } : {},
|
|
1441
1597
|
status: "running",
|
|
1442
1598
|
...iterationCount ? { metadata: { iterationCount } } : {}
|
|
1443
1599
|
};
|
|
1600
|
+
executionContext.activeStepsPath[step.id] = executionContext.executionPath;
|
|
1444
1601
|
const stepSpan = tracingContext.currentSpan?.createChildSpan({
|
|
1445
1602
|
name: `workflow step: '${step.id}'`,
|
|
1446
1603
|
type: "workflow_step" /* WORKFLOW_STEP */,
|
|
@@ -1495,6 +1652,10 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1495
1652
|
throw validationError;
|
|
1496
1653
|
}
|
|
1497
1654
|
const retryCount = this.getOrGenerateRetryCount(step.id);
|
|
1655
|
+
let timeTravelSteps = [];
|
|
1656
|
+
if (timeTravel && timeTravel.steps.length > 0) {
|
|
1657
|
+
timeTravelSteps = timeTravel.steps[0] === step.id ? timeTravel.steps.slice(1) : [];
|
|
1658
|
+
}
|
|
1498
1659
|
const result = await runStep({
|
|
1499
1660
|
runId,
|
|
1500
1661
|
resourceId,
|
|
@@ -1507,7 +1668,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1507
1668
|
executionContext.state = state;
|
|
1508
1669
|
},
|
|
1509
1670
|
retryCount,
|
|
1510
|
-
resumeData:
|
|
1671
|
+
resumeData: resumeDataToUse,
|
|
1511
1672
|
tracingContext: { currentSpan: stepSpan },
|
|
1512
1673
|
getInitData: () => stepResults?.input,
|
|
1513
1674
|
getStepResult: getStepResult.bind(this, stepResults),
|
|
@@ -1540,6 +1701,15 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1540
1701
|
label: resume?.label,
|
|
1541
1702
|
forEachIndex: resume?.forEachIndex
|
|
1542
1703
|
} : void 0,
|
|
1704
|
+
// Only pass restart data if this step is part of activeStepsPath
|
|
1705
|
+
// This prevents pending nested workflows from trying to restart instead of start
|
|
1706
|
+
restart: !!restart?.activeStepsPath?.[step.id],
|
|
1707
|
+
timeTravel: timeTravelSteps.length > 0 ? {
|
|
1708
|
+
inputData: timeTravel?.inputData,
|
|
1709
|
+
steps: timeTravelSteps,
|
|
1710
|
+
nestedStepResults: timeTravel?.nestedStepResults,
|
|
1711
|
+
resumeData: timeTravel?.resumeData
|
|
1712
|
+
} : void 0,
|
|
1543
1713
|
[chunkABJOUEVA_cjs.EMITTER_SYMBOL]: emitter,
|
|
1544
1714
|
[chunkABJOUEVA_cjs.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1545
1715
|
engine: {},
|
|
@@ -1571,7 +1741,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1571
1741
|
});
|
|
1572
1742
|
}
|
|
1573
1743
|
if (suspended) {
|
|
1574
|
-
execResults = {
|
|
1744
|
+
execResults = {
|
|
1745
|
+
status: "suspended",
|
|
1746
|
+
suspendPayload: suspended.payload,
|
|
1747
|
+
...result ? { suspendOutput: result } : {},
|
|
1748
|
+
suspendedAt: Date.now()
|
|
1749
|
+
};
|
|
1575
1750
|
} else if (bailed) {
|
|
1576
1751
|
execResults = { status: "bailed", output: bailed.payload, endedAt: Date.now() };
|
|
1577
1752
|
} else {
|
|
@@ -1606,6 +1781,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1606
1781
|
};
|
|
1607
1782
|
}
|
|
1608
1783
|
}
|
|
1784
|
+
delete executionContext.activeStepsPath[step.id];
|
|
1609
1785
|
if (!skipEmits) {
|
|
1610
1786
|
if (execResults.status === "suspended") {
|
|
1611
1787
|
await emitter.emit("watch", {
|
|
@@ -1709,6 +1885,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1709
1885
|
serializedStepGraph,
|
|
1710
1886
|
stepResults,
|
|
1711
1887
|
resume,
|
|
1888
|
+
restart,
|
|
1889
|
+
timeTravel,
|
|
1712
1890
|
executionContext,
|
|
1713
1891
|
tracingContext,
|
|
1714
1892
|
emitter,
|
|
@@ -1728,22 +1906,38 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1728
1906
|
tracingPolicy: this.options?.tracingPolicy
|
|
1729
1907
|
});
|
|
1730
1908
|
const prevOutput = this.getStepOutput(stepResults, prevStep);
|
|
1731
|
-
for (const step of entry.steps) {
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
...resumeTime ? { resumePayload: resume?.resumePayload } : { payload: prevOutput },
|
|
1739
|
-
...startTime ? { startedAt: startTime } : {},
|
|
1740
|
-
...resumeTime ? { resumedAt: resumeTime } : {}
|
|
1741
|
-
};
|
|
1909
|
+
for (const [stepIndex, step] of entry.steps.entries()) {
|
|
1910
|
+
let makeStepRunning = true;
|
|
1911
|
+
if (restart) {
|
|
1912
|
+
makeStepRunning = !!restart.activeStepsPath[step.step.id];
|
|
1913
|
+
}
|
|
1914
|
+
if (timeTravel && timeTravel.executionPath.length > 0) {
|
|
1915
|
+
makeStepRunning = timeTravel.steps[0] === step.step.id;
|
|
1742
1916
|
}
|
|
1917
|
+
if (!makeStepRunning) {
|
|
1918
|
+
continue;
|
|
1919
|
+
}
|
|
1920
|
+
const startTime = resume?.steps[0] === step.step.id ? void 0 : Date.now();
|
|
1921
|
+
const resumeTime = resume?.steps[0] === step.step.id ? Date.now() : void 0;
|
|
1922
|
+
stepResults[step.step.id] = {
|
|
1923
|
+
...stepResults[step.step.id],
|
|
1924
|
+
status: "running",
|
|
1925
|
+
...resumeTime ? { resumePayload: resume?.resumePayload } : { payload: prevOutput },
|
|
1926
|
+
...startTime ? { startedAt: startTime } : {},
|
|
1927
|
+
...resumeTime ? { resumedAt: resumeTime } : {}
|
|
1928
|
+
};
|
|
1929
|
+
executionContext.activeStepsPath[step.step.id] = [...executionContext.executionPath, stepIndex];
|
|
1930
|
+
}
|
|
1931
|
+
if (timeTravel && timeTravel.executionPath.length > 0) {
|
|
1932
|
+
timeTravel.executionPath.shift();
|
|
1743
1933
|
}
|
|
1744
1934
|
let execResults;
|
|
1745
1935
|
const results = await Promise.all(
|
|
1746
1936
|
entry.steps.map(async (step, i) => {
|
|
1937
|
+
const currStepResult = stepResults[step.step.id];
|
|
1938
|
+
if (currStepResult && currStepResult.status !== "running") {
|
|
1939
|
+
return currStepResult;
|
|
1940
|
+
}
|
|
1747
1941
|
const result = await this.executeStep({
|
|
1748
1942
|
workflowId,
|
|
1749
1943
|
runId,
|
|
@@ -1752,8 +1946,11 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1752
1946
|
prevOutput,
|
|
1753
1947
|
stepResults,
|
|
1754
1948
|
serializedStepGraph,
|
|
1949
|
+
restart,
|
|
1950
|
+
timeTravel,
|
|
1755
1951
|
resume,
|
|
1756
1952
|
executionContext: {
|
|
1953
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
1757
1954
|
workflowId,
|
|
1758
1955
|
runId,
|
|
1759
1956
|
executionPath: [...executionContext.executionPath, i],
|
|
@@ -1780,7 +1977,11 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1780
1977
|
if (hasFailed) {
|
|
1781
1978
|
execResults = { status: "failed", error: hasFailed.error };
|
|
1782
1979
|
} else if (hasSuspended) {
|
|
1783
|
-
execResults = {
|
|
1980
|
+
execResults = {
|
|
1981
|
+
status: "suspended",
|
|
1982
|
+
suspendPayload: hasSuspended.suspendPayload,
|
|
1983
|
+
...hasSuspended.suspendOutput ? { suspendOutput: hasSuspended.suspendOutput } : {}
|
|
1984
|
+
};
|
|
1784
1985
|
} else if (abortController?.signal?.aborted) {
|
|
1785
1986
|
execResults = { status: "canceled" };
|
|
1786
1987
|
} else {
|
|
@@ -1814,6 +2015,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1814
2015
|
serializedStepGraph,
|
|
1815
2016
|
stepResults,
|
|
1816
2017
|
resume,
|
|
2018
|
+
restart,
|
|
2019
|
+
timeTravel,
|
|
1817
2020
|
executionContext,
|
|
1818
2021
|
tracingContext,
|
|
1819
2022
|
emitter,
|
|
@@ -1929,7 +2132,13 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1929
2132
|
const results = await Promise.all(
|
|
1930
2133
|
stepsToRun.map(async (step, index) => {
|
|
1931
2134
|
const currStepResult = stepResults[step.step.id];
|
|
1932
|
-
|
|
2135
|
+
const isRestartStep = restart ? !!restart.activeStepsPath[step.step.id] : void 0;
|
|
2136
|
+
if (currStepResult && timeTravel && timeTravel.executionPath.length > 0) {
|
|
2137
|
+
if (timeTravel.steps[0] !== step.step.id) {
|
|
2138
|
+
return currStepResult;
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
if (currStepResult && ["success", "failed"].includes(currStepResult.status) && isRestartStep === void 0) {
|
|
1933
2142
|
return currStepResult;
|
|
1934
2143
|
}
|
|
1935
2144
|
const result = await this.executeStep({
|
|
@@ -1941,10 +2150,13 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1941
2150
|
stepResults,
|
|
1942
2151
|
serializedStepGraph,
|
|
1943
2152
|
resume,
|
|
2153
|
+
restart,
|
|
2154
|
+
timeTravel,
|
|
1944
2155
|
executionContext: {
|
|
1945
2156
|
workflowId,
|
|
1946
2157
|
runId,
|
|
1947
2158
|
executionPath: [...executionContext.executionPath, index],
|
|
2159
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
1948
2160
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1949
2161
|
resumeLabels: executionContext.resumeLabels,
|
|
1950
2162
|
retryConfig: executionContext.retryConfig,
|
|
@@ -1968,7 +2180,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1968
2180
|
if (hasFailed) {
|
|
1969
2181
|
execResults = { status: "failed", error: hasFailed.error };
|
|
1970
2182
|
} else if (hasSuspended) {
|
|
1971
|
-
execResults = {
|
|
2183
|
+
execResults = {
|
|
2184
|
+
status: "suspended",
|
|
2185
|
+
suspendPayload: hasSuspended.suspendPayload,
|
|
2186
|
+
...hasSuspended.suspendOutput ? { suspendOutput: hasSuspended.suspendOutput } : {},
|
|
2187
|
+
suspendedAt: hasSuspended.suspendedAt
|
|
2188
|
+
};
|
|
1972
2189
|
} else if (abortController?.signal?.aborted) {
|
|
1973
2190
|
execResults = { status: "canceled" };
|
|
1974
2191
|
} else {
|
|
@@ -2001,6 +2218,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2001
2218
|
prevOutput,
|
|
2002
2219
|
stepResults,
|
|
2003
2220
|
resume,
|
|
2221
|
+
restart,
|
|
2222
|
+
timeTravel,
|
|
2004
2223
|
executionContext,
|
|
2005
2224
|
tracingContext,
|
|
2006
2225
|
emitter,
|
|
@@ -2026,6 +2245,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2026
2245
|
const prevPayload = stepResults[step.id]?.payload;
|
|
2027
2246
|
let result = { status: "success", output: prevPayload ?? prevOutput };
|
|
2028
2247
|
let currentResume = resume;
|
|
2248
|
+
let currentRestart = restart;
|
|
2249
|
+
let currentTimeTravel = timeTravel;
|
|
2029
2250
|
do {
|
|
2030
2251
|
result = await this.executeStep({
|
|
2031
2252
|
workflowId,
|
|
@@ -2034,7 +2255,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2034
2255
|
step,
|
|
2035
2256
|
stepResults,
|
|
2036
2257
|
executionContext,
|
|
2258
|
+
restart: currentRestart,
|
|
2037
2259
|
resume: currentResume,
|
|
2260
|
+
timeTravel: currentTimeTravel,
|
|
2038
2261
|
prevOutput: result.output,
|
|
2039
2262
|
tracingContext: {
|
|
2040
2263
|
currentSpan: loopSpan
|
|
@@ -2047,6 +2270,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2047
2270
|
serializedStepGraph,
|
|
2048
2271
|
iterationCount: iteration + 1
|
|
2049
2272
|
});
|
|
2273
|
+
currentRestart = void 0;
|
|
2274
|
+
currentTimeTravel = void 0;
|
|
2050
2275
|
if (currentResume && result.status !== "suspended") {
|
|
2051
2276
|
currentResume = void 0;
|
|
2052
2277
|
}
|
|
@@ -2061,7 +2286,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2061
2286
|
const evalSpan = loopSpan?.createChildSpan({
|
|
2062
2287
|
type: "workflow_conditional_eval" /* WORKFLOW_CONDITIONAL_EVAL */,
|
|
2063
2288
|
name: `condition: '${entry.loopType}'`,
|
|
2064
|
-
input:
|
|
2289
|
+
input: chunkHBJPYQRN_cjs.selectFields(result.output, ["stepResult", "output.text", "output.object", "messages"]),
|
|
2065
2290
|
attributes: {
|
|
2066
2291
|
conditionIndex: iteration
|
|
2067
2292
|
},
|
|
@@ -2134,7 +2359,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2134
2359
|
entry,
|
|
2135
2360
|
prevOutput,
|
|
2136
2361
|
stepResults,
|
|
2362
|
+
restart,
|
|
2137
2363
|
resume,
|
|
2364
|
+
timeTravel,
|
|
2138
2365
|
executionContext,
|
|
2139
2366
|
tracingContext,
|
|
2140
2367
|
emitter,
|
|
@@ -2203,6 +2430,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2203
2430
|
resourceId,
|
|
2204
2431
|
step,
|
|
2205
2432
|
stepResults,
|
|
2433
|
+
restart,
|
|
2434
|
+
timeTravel,
|
|
2206
2435
|
executionContext: { ...executionContext, foreachIndex: k },
|
|
2207
2436
|
resume: resumeToUse,
|
|
2208
2437
|
prevOutput: item,
|
|
@@ -2267,6 +2496,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2267
2496
|
...stepInfo,
|
|
2268
2497
|
suspendedAt: Date.now(),
|
|
2269
2498
|
status: "suspended",
|
|
2499
|
+
...foreachIndexObj[foreachIndex].suspendOutput ? { suspendOutput: foreachIndexObj[foreachIndex].suspendOutput } : {},
|
|
2270
2500
|
suspendPayload: {
|
|
2271
2501
|
...foreachIndexObj[foreachIndex].suspendPayload,
|
|
2272
2502
|
__workflow_meta: {
|
|
@@ -2335,7 +2565,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2335
2565
|
status: workflowStatus,
|
|
2336
2566
|
value: executionContext.state,
|
|
2337
2567
|
context: stepResults,
|
|
2338
|
-
activePaths:
|
|
2568
|
+
activePaths: executionContext.executionPath,
|
|
2569
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
2339
2570
|
serializedStepGraph,
|
|
2340
2571
|
suspendedPaths: executionContext.suspendedPaths,
|
|
2341
2572
|
waitingPaths: {},
|
|
@@ -2356,6 +2587,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2356
2587
|
prevStep,
|
|
2357
2588
|
serializedStepGraph,
|
|
2358
2589
|
stepResults,
|
|
2590
|
+
restart,
|
|
2591
|
+
timeTravel,
|
|
2359
2592
|
resume,
|
|
2360
2593
|
executionContext,
|
|
2361
2594
|
tracingContext,
|
|
@@ -2376,6 +2609,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2376
2609
|
step,
|
|
2377
2610
|
stepResults,
|
|
2378
2611
|
executionContext,
|
|
2612
|
+
timeTravel,
|
|
2613
|
+
restart,
|
|
2379
2614
|
resume,
|
|
2380
2615
|
prevOutput,
|
|
2381
2616
|
tracingContext,
|
|
@@ -2404,6 +2639,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2404
2639
|
suspendedPaths: executionContext.suspendedPaths,
|
|
2405
2640
|
resumeLabels: executionContext.resumeLabels,
|
|
2406
2641
|
retryConfig: executionContext.retryConfig,
|
|
2642
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
2407
2643
|
state: executionContext.state
|
|
2408
2644
|
},
|
|
2409
2645
|
tracingContext,
|
|
@@ -2483,6 +2719,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2483
2719
|
prevStep,
|
|
2484
2720
|
stepResults,
|
|
2485
2721
|
serializedStepGraph,
|
|
2722
|
+
timeTravel,
|
|
2723
|
+
restart,
|
|
2486
2724
|
resume,
|
|
2487
2725
|
executionContext,
|
|
2488
2726
|
tracingContext,
|
|
@@ -2500,6 +2738,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2500
2738
|
prevOutput,
|
|
2501
2739
|
stepResults,
|
|
2502
2740
|
serializedStepGraph,
|
|
2741
|
+
timeTravel,
|
|
2742
|
+
restart,
|
|
2503
2743
|
resume,
|
|
2504
2744
|
executionContext,
|
|
2505
2745
|
tracingContext,
|
|
@@ -2517,6 +2757,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2517
2757
|
prevStep,
|
|
2518
2758
|
prevOutput,
|
|
2519
2759
|
stepResults,
|
|
2760
|
+
timeTravel,
|
|
2761
|
+
restart,
|
|
2520
2762
|
resume,
|
|
2521
2763
|
executionContext,
|
|
2522
2764
|
tracingContext,
|
|
@@ -2535,6 +2777,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2535
2777
|
prevStep,
|
|
2536
2778
|
prevOutput,
|
|
2537
2779
|
stepResults,
|
|
2780
|
+
timeTravel,
|
|
2781
|
+
restart,
|
|
2538
2782
|
resume,
|
|
2539
2783
|
executionContext,
|
|
2540
2784
|
tracingContext,
|
|
@@ -2556,6 +2800,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2556
2800
|
status: "waiting"
|
|
2557
2801
|
}
|
|
2558
2802
|
});
|
|
2803
|
+
stepResults[entry.id] = {
|
|
2804
|
+
status: "waiting",
|
|
2805
|
+
payload: prevOutput,
|
|
2806
|
+
startedAt
|
|
2807
|
+
};
|
|
2808
|
+
executionContext.activeStepsPath[entry.id] = executionContext.executionPath;
|
|
2559
2809
|
await this.persistStepUpdate({
|
|
2560
2810
|
workflowId,
|
|
2561
2811
|
runId,
|
|
@@ -2582,6 +2832,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2582
2832
|
requestContext,
|
|
2583
2833
|
writableStream
|
|
2584
2834
|
});
|
|
2835
|
+
delete executionContext.activeStepsPath[entry.id];
|
|
2585
2836
|
await this.persistStepUpdate({
|
|
2586
2837
|
workflowId,
|
|
2587
2838
|
runId,
|
|
@@ -2627,6 +2878,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2627
2878
|
status: "waiting"
|
|
2628
2879
|
}
|
|
2629
2880
|
});
|
|
2881
|
+
stepResults[entry.id] = {
|
|
2882
|
+
status: "waiting",
|
|
2883
|
+
payload: prevOutput,
|
|
2884
|
+
startedAt
|
|
2885
|
+
};
|
|
2886
|
+
executionContext.activeStepsPath[entry.id] = executionContext.executionPath;
|
|
2630
2887
|
await this.persistStepUpdate({
|
|
2631
2888
|
workflowId,
|
|
2632
2889
|
runId,
|
|
@@ -2653,6 +2910,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2653
2910
|
requestContext,
|
|
2654
2911
|
writableStream
|
|
2655
2912
|
});
|
|
2913
|
+
delete executionContext.activeStepsPath[entry.id];
|
|
2656
2914
|
await this.persistStepUpdate({
|
|
2657
2915
|
workflowId,
|
|
2658
2916
|
runId,
|
|
@@ -2813,7 +3071,7 @@ function createStep(params, agentOptions) {
|
|
|
2813
3071
|
component: params.component
|
|
2814
3072
|
};
|
|
2815
3073
|
}
|
|
2816
|
-
if (params instanceof
|
|
3074
|
+
if (params instanceof chunk4IKJAKCD_cjs.Tool) {
|
|
2817
3075
|
if (!params.inputSchema || !params.outputSchema) {
|
|
2818
3076
|
throw new Error("Tool must have input and output schemas defined");
|
|
2819
3077
|
}
|
|
@@ -2873,8 +3131,12 @@ function cloneStep(step, opts) {
|
|
|
2873
3131
|
description: step.description,
|
|
2874
3132
|
inputSchema: step.inputSchema,
|
|
2875
3133
|
outputSchema: step.outputSchema,
|
|
3134
|
+
suspendSchema: step.suspendSchema,
|
|
3135
|
+
resumeSchema: step.resumeSchema,
|
|
3136
|
+
stateSchema: step.stateSchema,
|
|
2876
3137
|
execute: step.execute,
|
|
2877
3138
|
retries: step.retries,
|
|
3139
|
+
scorers: step.scorers,
|
|
2878
3140
|
component: step.component
|
|
2879
3141
|
};
|
|
2880
3142
|
}
|
|
@@ -2887,7 +3149,8 @@ function cloneWorkflow(workflow, opts) {
|
|
|
2887
3149
|
inputSchema: workflow.inputSchema,
|
|
2888
3150
|
outputSchema: workflow.outputSchema,
|
|
2889
3151
|
steps: workflow.stepDefs,
|
|
2890
|
-
mastra: workflow.mastra
|
|
3152
|
+
mastra: workflow.mastra,
|
|
3153
|
+
options: workflow.options
|
|
2891
3154
|
});
|
|
2892
3155
|
wf.setStepFlow(workflow.stepGraph);
|
|
2893
3156
|
wf.commit();
|
|
@@ -2901,6 +3164,9 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
2901
3164
|
stateSchema;
|
|
2902
3165
|
steps;
|
|
2903
3166
|
stepDefs;
|
|
3167
|
+
engineType = "default";
|
|
3168
|
+
#nestedWorkflowInput;
|
|
3169
|
+
committed = false;
|
|
2904
3170
|
stepFlow;
|
|
2905
3171
|
serializedStepFlow;
|
|
2906
3172
|
executionEngine;
|
|
@@ -2935,7 +3201,7 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
2935
3201
|
this.steps = {};
|
|
2936
3202
|
this.stepDefs = steps;
|
|
2937
3203
|
this.#options = {
|
|
2938
|
-
validateInputs: options.validateInputs ??
|
|
3204
|
+
validateInputs: options.validateInputs ?? true,
|
|
2939
3205
|
shouldPersistSnapshot: options.shouldPersistSnapshot ?? (() => true),
|
|
2940
3206
|
tracingPolicy: options.tracingPolicy
|
|
2941
3207
|
};
|
|
@@ -2947,6 +3213,7 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
2947
3213
|
} else {
|
|
2948
3214
|
this.executionEngine = executionEngine;
|
|
2949
3215
|
}
|
|
3216
|
+
this.engineType = "default";
|
|
2950
3217
|
this.#runs = /* @__PURE__ */ new Map();
|
|
2951
3218
|
}
|
|
2952
3219
|
get runs() {
|
|
@@ -3265,6 +3532,7 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
3265
3532
|
*/
|
|
3266
3533
|
commit() {
|
|
3267
3534
|
this.executionGraph = this.buildExecutionGraph();
|
|
3535
|
+
this.committed = true;
|
|
3268
3536
|
return this;
|
|
3269
3537
|
}
|
|
3270
3538
|
get stepGraph() {
|
|
@@ -3305,7 +3573,8 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
3305
3573
|
cleanup: () => this.#runs.delete(runIdToUse),
|
|
3306
3574
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
3307
3575
|
workflowSteps: this.steps,
|
|
3308
|
-
validateInputs: this.#options?.validateInputs
|
|
3576
|
+
validateInputs: this.#options?.validateInputs,
|
|
3577
|
+
workflowEngineType: this.engineType
|
|
3309
3578
|
});
|
|
3310
3579
|
this.#runs.set(runIdToUse, run);
|
|
3311
3580
|
const shouldPersistSnapshot = this.#options.shouldPersistSnapshot({
|
|
@@ -3322,8 +3591,9 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
3322
3591
|
runId: runIdToUse,
|
|
3323
3592
|
status: "pending",
|
|
3324
3593
|
value: {},
|
|
3325
|
-
context: {},
|
|
3594
|
+
context: this.#nestedWorkflowInput ? { input: this.#nestedWorkflowInput } : {},
|
|
3326
3595
|
activePaths: [],
|
|
3596
|
+
activeStepsPath: {},
|
|
3327
3597
|
serializedStepGraph: this.serializedStepGraph,
|
|
3328
3598
|
suspendedPaths: {},
|
|
3329
3599
|
resumeLabels: {},
|
|
@@ -3367,7 +3637,9 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
3367
3637
|
state,
|
|
3368
3638
|
setState,
|
|
3369
3639
|
suspend,
|
|
3640
|
+
restart,
|
|
3370
3641
|
resume,
|
|
3642
|
+
timeTravel,
|
|
3371
3643
|
[chunkABJOUEVA_cjs.EMITTER_SYMBOL]: emitter,
|
|
3372
3644
|
mastra,
|
|
3373
3645
|
requestContext,
|
|
@@ -3379,17 +3651,20 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
3379
3651
|
validateInputs
|
|
3380
3652
|
}) {
|
|
3381
3653
|
this.__registerMastra(mastra);
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
}
|
|
3654
|
+
const effectiveValidateInputs = validateInputs ?? this.#options.validateInputs ?? true;
|
|
3655
|
+
this.#options = {
|
|
3656
|
+
...this.#options || {},
|
|
3657
|
+
validateInputs: effectiveValidateInputs
|
|
3658
|
+
};
|
|
3388
3659
|
this.executionEngine.options = {
|
|
3389
3660
|
...this.executionEngine.options || {},
|
|
3390
|
-
validateInputs:
|
|
3661
|
+
validateInputs: effectiveValidateInputs
|
|
3391
3662
|
};
|
|
3392
3663
|
const isResume = !!(resume?.steps && resume.steps.length > 0) || !!resume?.label || !!(resume?.steps && resume.steps.length === 0 && (!retryCount || retryCount === 0));
|
|
3664
|
+
if (!restart && !isResume) {
|
|
3665
|
+
this.#nestedWorkflowInput = inputData;
|
|
3666
|
+
}
|
|
3667
|
+
const isTimeTravel = !!(timeTravel && timeTravel.steps.length > 0);
|
|
3393
3668
|
const run = isResume ? await this.createRun({ runId: resume.runId }) : await this.createRun({ runId });
|
|
3394
3669
|
const nestedAbortCb = () => {
|
|
3395
3670
|
abort();
|
|
@@ -3405,21 +3680,41 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
3405
3680
|
if (retryCount && retryCount > 0 && isResume && requestContext) {
|
|
3406
3681
|
requestContext.set("__mastraWorflowInputData", inputData);
|
|
3407
3682
|
}
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
})
|
|
3683
|
+
let res;
|
|
3684
|
+
if (isTimeTravel) {
|
|
3685
|
+
res = await run.timeTravel({
|
|
3686
|
+
inputData: timeTravel?.inputData,
|
|
3687
|
+
resumeData: timeTravel?.resumeData,
|
|
3688
|
+
initialState: state,
|
|
3689
|
+
step: timeTravel?.steps,
|
|
3690
|
+
context: timeTravel?.nestedStepResults?.[this.id] ?? {},
|
|
3691
|
+
nestedStepsContext: timeTravel?.nestedStepResults,
|
|
3692
|
+
requestContext,
|
|
3693
|
+
tracingContext,
|
|
3694
|
+
writableStream: writer,
|
|
3695
|
+
outputOptions: { includeState: true, includeResumeLabels: true }
|
|
3696
|
+
});
|
|
3697
|
+
} else if (restart) {
|
|
3698
|
+
res = await run.restart({ requestContext, tracingContext, writableStream: writer });
|
|
3699
|
+
} else if (isResume) {
|
|
3700
|
+
res = await run.resume({
|
|
3701
|
+
resumeData,
|
|
3702
|
+
step: resume.steps?.length > 0 ? resume.steps : void 0,
|
|
3703
|
+
requestContext,
|
|
3704
|
+
tracingContext,
|
|
3705
|
+
outputOptions: { includeState: true, includeResumeLabels: true },
|
|
3706
|
+
label: resume.label
|
|
3707
|
+
});
|
|
3708
|
+
} else {
|
|
3709
|
+
res = await run.start({
|
|
3710
|
+
inputData,
|
|
3711
|
+
requestContext,
|
|
3712
|
+
tracingContext,
|
|
3713
|
+
writableStream: writer,
|
|
3714
|
+
initialState: state,
|
|
3715
|
+
outputOptions: { includeState: true, includeResumeLabels: true }
|
|
3716
|
+
});
|
|
3717
|
+
}
|
|
3423
3718
|
unwatch();
|
|
3424
3719
|
const suspendedSteps = Object.entries(res.steps).filter(([_stepName, stepResult]) => {
|
|
3425
3720
|
const stepRes = stepResult;
|
|
@@ -3455,6 +3750,35 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
3455
3750
|
}
|
|
3456
3751
|
return storage.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
|
|
3457
3752
|
}
|
|
3753
|
+
async listActiveWorkflowRuns() {
|
|
3754
|
+
const runningRuns = await this.listWorkflowRuns({ status: "running" });
|
|
3755
|
+
const waitingRuns = await this.listWorkflowRuns({ status: "waiting" });
|
|
3756
|
+
return {
|
|
3757
|
+
runs: [...runningRuns.runs, ...waitingRuns.runs],
|
|
3758
|
+
total: runningRuns.total + waitingRuns.total
|
|
3759
|
+
};
|
|
3760
|
+
}
|
|
3761
|
+
async restartAllActiveWorkflowRuns() {
|
|
3762
|
+
if (this.engineType !== "default") {
|
|
3763
|
+
this.logger.debug(`Cannot restart active workflow runs for ${this.engineType} engine`);
|
|
3764
|
+
return;
|
|
3765
|
+
}
|
|
3766
|
+
const activeRuns = await this.listActiveWorkflowRuns();
|
|
3767
|
+
if (activeRuns.runs.length > 0) {
|
|
3768
|
+
this.logger.debug(
|
|
3769
|
+
`Restarting ${activeRuns.runs.length} active workflow run${activeRuns.runs.length > 1 ? "s" : ""}`
|
|
3770
|
+
);
|
|
3771
|
+
}
|
|
3772
|
+
for (const runSnapshot of activeRuns.runs) {
|
|
3773
|
+
try {
|
|
3774
|
+
const run = await this.createRun({ runId: runSnapshot.runId });
|
|
3775
|
+
await run.restart();
|
|
3776
|
+
this.logger.debug(`Restarted ${this.id} workflow run ${runSnapshot.runId}`);
|
|
3777
|
+
} catch (error) {
|
|
3778
|
+
this.logger.error(`Failed to restart ${this.id} workflow run ${runSnapshot.runId}: ${error}`);
|
|
3779
|
+
}
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3458
3782
|
async getWorkflowRunById(runId) {
|
|
3459
3783
|
const storage = this.#mastra?.getStorage();
|
|
3460
3784
|
if (!storage) {
|
|
@@ -3530,7 +3854,9 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
3530
3854
|
result: snapshot.result,
|
|
3531
3855
|
error: snapshot.error,
|
|
3532
3856
|
payload: snapshot.context?.input,
|
|
3533
|
-
steps: fullSteps
|
|
3857
|
+
steps: fullSteps,
|
|
3858
|
+
activeStepsPath: snapshot.activeStepsPath,
|
|
3859
|
+
serializedStepGraph: snapshot.serializedStepGraph
|
|
3534
3860
|
};
|
|
3535
3861
|
}
|
|
3536
3862
|
};
|
|
@@ -3582,6 +3908,7 @@ var Run = class {
|
|
|
3582
3908
|
*/
|
|
3583
3909
|
workflowSteps;
|
|
3584
3910
|
workflowRunStatus;
|
|
3911
|
+
workflowEngineType;
|
|
3585
3912
|
/**
|
|
3586
3913
|
* The storage for this run
|
|
3587
3914
|
*/
|
|
@@ -3613,6 +3940,7 @@ var Run = class {
|
|
|
3613
3940
|
this.validateInputs = params.validateInputs;
|
|
3614
3941
|
this.stateSchema = params.stateSchema;
|
|
3615
3942
|
this.workflowRunStatus = "pending";
|
|
3943
|
+
this.workflowEngineType = params.workflowEngineType;
|
|
3616
3944
|
}
|
|
3617
3945
|
get abortController() {
|
|
3618
3946
|
if (!this.#abortController) {
|
|
@@ -3685,6 +4013,20 @@ var Run = class {
|
|
|
3685
4013
|
}
|
|
3686
4014
|
return resumeDataToUse;
|
|
3687
4015
|
}
|
|
4016
|
+
async _validateTimetravelInputData(inputData, step) {
|
|
4017
|
+
let inputDataToUse = inputData;
|
|
4018
|
+
if (step && step.inputSchema && this.validateInputs) {
|
|
4019
|
+
const inputSchema = step.inputSchema;
|
|
4020
|
+
const validatedInputData = await inputSchema.safeParseAsync(inputData);
|
|
4021
|
+
if (!validatedInputData.success) {
|
|
4022
|
+
const errors = getZodErrors(validatedInputData.error);
|
|
4023
|
+
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
4024
|
+
throw new Error("Invalid inputData: \n" + errorMessages);
|
|
4025
|
+
}
|
|
4026
|
+
inputDataToUse = validatedInputData.data;
|
|
4027
|
+
}
|
|
4028
|
+
return inputDataToUse;
|
|
4029
|
+
}
|
|
3688
4030
|
async _start({
|
|
3689
4031
|
inputData,
|
|
3690
4032
|
initialState,
|
|
@@ -4110,6 +4452,13 @@ var Run = class {
|
|
|
4110
4452
|
async resume(params) {
|
|
4111
4453
|
return this._resume(params);
|
|
4112
4454
|
}
|
|
4455
|
+
/**
|
|
4456
|
+
* Restarts the workflow execution that was previously active
|
|
4457
|
+
* @returns A promise that resolves to the workflow output
|
|
4458
|
+
*/
|
|
4459
|
+
async restart(args = {}) {
|
|
4460
|
+
return this._restart(args);
|
|
4461
|
+
}
|
|
4113
4462
|
async _resume(params) {
|
|
4114
4463
|
const snapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
4115
4464
|
workflowName: this.workflowId,
|
|
@@ -4177,7 +4526,7 @@ var Run = class {
|
|
|
4177
4526
|
params.requestContext.delete("__mastraWorflowInputData");
|
|
4178
4527
|
}
|
|
4179
4528
|
const stepResults = { ...snapshot?.context ?? {}, input: requestContextInput ?? snapshot?.context?.input };
|
|
4180
|
-
|
|
4529
|
+
const requestContextToUse = params.requestContext ?? new chunkJ7O6WENZ_cjs.RequestContext();
|
|
4181
4530
|
Object.entries(snapshot?.requestContext ?? {}).forEach(([key, value]) => {
|
|
4182
4531
|
if (!requestContextToUse.has(key)) {
|
|
4183
4532
|
requestContextToUse.set(key, value);
|
|
@@ -4253,6 +4602,298 @@ var Run = class {
|
|
|
4253
4602
|
return result;
|
|
4254
4603
|
});
|
|
4255
4604
|
}
|
|
4605
|
+
async _restart({
|
|
4606
|
+
requestContext,
|
|
4607
|
+
writableStream,
|
|
4608
|
+
tracingContext,
|
|
4609
|
+
tracingOptions
|
|
4610
|
+
}) {
|
|
4611
|
+
if (this.workflowEngineType !== "default") {
|
|
4612
|
+
throw new Error(`restart() is not supported on ${this.workflowEngineType} workflows`);
|
|
4613
|
+
}
|
|
4614
|
+
const snapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
4615
|
+
workflowName: this.workflowId,
|
|
4616
|
+
runId: this.runId
|
|
4617
|
+
});
|
|
4618
|
+
let nestedWorkflowPending = false;
|
|
4619
|
+
if (!snapshot) {
|
|
4620
|
+
throw new Error(`Snapshot not found for run ${this.runId}`);
|
|
4621
|
+
}
|
|
4622
|
+
if (snapshot.status !== "running" && snapshot.status !== "waiting") {
|
|
4623
|
+
if (snapshot.status === "pending" && !!snapshot.context.input) {
|
|
4624
|
+
nestedWorkflowPending = true;
|
|
4625
|
+
} else {
|
|
4626
|
+
throw new Error("This workflow run was not active");
|
|
4627
|
+
}
|
|
4628
|
+
}
|
|
4629
|
+
let nestedWorkflowActiveStepsPath = {};
|
|
4630
|
+
const firstEntry = this.executionGraph.steps[0];
|
|
4631
|
+
if (firstEntry.type === "step" || firstEntry.type === "foreach" || firstEntry.type === "loop") {
|
|
4632
|
+
nestedWorkflowActiveStepsPath = {
|
|
4633
|
+
[firstEntry.step.id]: [0]
|
|
4634
|
+
};
|
|
4635
|
+
} else if (firstEntry.type === "sleep" || firstEntry.type === "sleepUntil") {
|
|
4636
|
+
nestedWorkflowActiveStepsPath = {
|
|
4637
|
+
[firstEntry.id]: [0]
|
|
4638
|
+
};
|
|
4639
|
+
} else if (firstEntry.type === "conditional" || firstEntry.type === "parallel") {
|
|
4640
|
+
nestedWorkflowActiveStepsPath = firstEntry.steps.reduce(
|
|
4641
|
+
(acc, step) => {
|
|
4642
|
+
acc[step.step.id] = [0];
|
|
4643
|
+
return acc;
|
|
4644
|
+
},
|
|
4645
|
+
{}
|
|
4646
|
+
);
|
|
4647
|
+
}
|
|
4648
|
+
const restartData = {
|
|
4649
|
+
activePaths: nestedWorkflowPending ? [0] : snapshot.activePaths,
|
|
4650
|
+
activeStepsPath: nestedWorkflowPending ? nestedWorkflowActiveStepsPath : snapshot.activeStepsPath,
|
|
4651
|
+
stepResults: snapshot.context,
|
|
4652
|
+
state: snapshot.value
|
|
4653
|
+
};
|
|
4654
|
+
const requestContextToUse = requestContext ?? new chunkJ7O6WENZ_cjs.RequestContext();
|
|
4655
|
+
for (const [key, value] of Object.entries(snapshot.requestContext ?? {})) {
|
|
4656
|
+
if (!requestContextToUse.has(key)) {
|
|
4657
|
+
requestContextToUse.set(key, value);
|
|
4658
|
+
}
|
|
4659
|
+
}
|
|
4660
|
+
const workflowSpan = chunkE7K4FTLN_cjs.getOrCreateSpan({
|
|
4661
|
+
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
4662
|
+
name: `workflow run: '${this.workflowId}'`,
|
|
4663
|
+
attributes: {
|
|
4664
|
+
workflowId: this.workflowId
|
|
4665
|
+
},
|
|
4666
|
+
metadata: {
|
|
4667
|
+
resourceId: this.resourceId,
|
|
4668
|
+
runId: this.runId
|
|
4669
|
+
},
|
|
4670
|
+
tracingPolicy: this.tracingPolicy,
|
|
4671
|
+
tracingOptions,
|
|
4672
|
+
tracingContext,
|
|
4673
|
+
requestContext: requestContextToUse,
|
|
4674
|
+
mastra: this.#mastra
|
|
4675
|
+
});
|
|
4676
|
+
const traceId = workflowSpan?.externalTraceId;
|
|
4677
|
+
const result = await this.executionEngine.execute({
|
|
4678
|
+
workflowId: this.workflowId,
|
|
4679
|
+
runId: this.runId,
|
|
4680
|
+
resourceId: this.resourceId,
|
|
4681
|
+
disableScorers: this.disableScorers,
|
|
4682
|
+
graph: this.executionGraph,
|
|
4683
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
4684
|
+
restart: restartData,
|
|
4685
|
+
emitter: {
|
|
4686
|
+
emit: async (event, data) => {
|
|
4687
|
+
this.emitter.emit(event, data);
|
|
4688
|
+
},
|
|
4689
|
+
on: (event, callback) => {
|
|
4690
|
+
this.emitter.on(event, callback);
|
|
4691
|
+
},
|
|
4692
|
+
off: (event, callback) => {
|
|
4693
|
+
this.emitter.off(event, callback);
|
|
4694
|
+
},
|
|
4695
|
+
once: (event, callback) => {
|
|
4696
|
+
this.emitter.once(event, callback);
|
|
4697
|
+
}
|
|
4698
|
+
},
|
|
4699
|
+
retryConfig: this.retryConfig,
|
|
4700
|
+
requestContext: requestContextToUse,
|
|
4701
|
+
abortController: this.abortController,
|
|
4702
|
+
writableStream,
|
|
4703
|
+
workflowSpan
|
|
4704
|
+
});
|
|
4705
|
+
if (result.status !== "suspended") {
|
|
4706
|
+
this.cleanup?.();
|
|
4707
|
+
}
|
|
4708
|
+
result.traceId = traceId;
|
|
4709
|
+
return result;
|
|
4710
|
+
}
|
|
4711
|
+
async _timeTravel({
|
|
4712
|
+
inputData,
|
|
4713
|
+
resumeData,
|
|
4714
|
+
initialState,
|
|
4715
|
+
step: stepParam,
|
|
4716
|
+
context,
|
|
4717
|
+
nestedStepsContext,
|
|
4718
|
+
requestContext,
|
|
4719
|
+
writableStream,
|
|
4720
|
+
tracingContext,
|
|
4721
|
+
tracingOptions,
|
|
4722
|
+
outputOptions
|
|
4723
|
+
}) {
|
|
4724
|
+
if (!stepParam || Array.isArray(stepParam) && stepParam.length === 0) {
|
|
4725
|
+
throw new Error("Step is required and must be a valid step or array of steps");
|
|
4726
|
+
}
|
|
4727
|
+
const snapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
4728
|
+
workflowName: this.workflowId,
|
|
4729
|
+
runId: this.runId
|
|
4730
|
+
});
|
|
4731
|
+
if (!snapshot) {
|
|
4732
|
+
throw new Error(`Snapshot not found for run ${this.runId}`);
|
|
4733
|
+
}
|
|
4734
|
+
if (snapshot.status === "running") {
|
|
4735
|
+
throw new Error("This workflow run is still running, cannot time travel");
|
|
4736
|
+
}
|
|
4737
|
+
let steps;
|
|
4738
|
+
let newStepParam = stepParam;
|
|
4739
|
+
if (typeof stepParam === "string") {
|
|
4740
|
+
newStepParam = stepParam.split(".");
|
|
4741
|
+
}
|
|
4742
|
+
steps = (Array.isArray(newStepParam) ? newStepParam : [newStepParam]).map(
|
|
4743
|
+
(step) => typeof step === "string" ? step : step?.id
|
|
4744
|
+
);
|
|
4745
|
+
let inputDataToUse = inputData;
|
|
4746
|
+
if (inputDataToUse && steps.length === 1) {
|
|
4747
|
+
inputDataToUse = await this._validateTimetravelInputData(inputData, this.workflowSteps[steps[0]]);
|
|
4748
|
+
}
|
|
4749
|
+
const timeTravelData = createTimeTravelExecutionParams({
|
|
4750
|
+
steps,
|
|
4751
|
+
inputData: inputDataToUse,
|
|
4752
|
+
resumeData,
|
|
4753
|
+
context,
|
|
4754
|
+
nestedStepsContext,
|
|
4755
|
+
snapshot,
|
|
4756
|
+
initialState,
|
|
4757
|
+
graph: this.executionGraph
|
|
4758
|
+
});
|
|
4759
|
+
const requestContextToUse = requestContext ?? new chunkJ7O6WENZ_cjs.RequestContext();
|
|
4760
|
+
for (const [key, value] of Object.entries(snapshot.requestContext ?? {})) {
|
|
4761
|
+
if (!requestContextToUse.has(key)) {
|
|
4762
|
+
requestContextToUse.set(key, value);
|
|
4763
|
+
}
|
|
4764
|
+
}
|
|
4765
|
+
const workflowSpan = chunkE7K4FTLN_cjs.getOrCreateSpan({
|
|
4766
|
+
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
4767
|
+
name: `workflow run: '${this.workflowId}'`,
|
|
4768
|
+
input: inputData,
|
|
4769
|
+
attributes: {
|
|
4770
|
+
workflowId: this.workflowId
|
|
4771
|
+
},
|
|
4772
|
+
metadata: {
|
|
4773
|
+
resourceId: this.resourceId,
|
|
4774
|
+
runId: this.runId
|
|
4775
|
+
},
|
|
4776
|
+
tracingPolicy: this.tracingPolicy,
|
|
4777
|
+
tracingOptions,
|
|
4778
|
+
tracingContext,
|
|
4779
|
+
requestContext: requestContextToUse,
|
|
4780
|
+
mastra: this.#mastra
|
|
4781
|
+
});
|
|
4782
|
+
const traceId = workflowSpan?.externalTraceId;
|
|
4783
|
+
const result = await this.executionEngine.execute({
|
|
4784
|
+
workflowId: this.workflowId,
|
|
4785
|
+
runId: this.runId,
|
|
4786
|
+
resourceId: this.resourceId,
|
|
4787
|
+
disableScorers: this.disableScorers,
|
|
4788
|
+
graph: this.executionGraph,
|
|
4789
|
+
timeTravel: timeTravelData,
|
|
4790
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
4791
|
+
emitter: {
|
|
4792
|
+
emit: async (event, data) => {
|
|
4793
|
+
this.emitter.emit(event, data);
|
|
4794
|
+
},
|
|
4795
|
+
on: (event, callback) => {
|
|
4796
|
+
this.emitter.on(event, callback);
|
|
4797
|
+
},
|
|
4798
|
+
off: (event, callback) => {
|
|
4799
|
+
this.emitter.off(event, callback);
|
|
4800
|
+
},
|
|
4801
|
+
once: (event, callback) => {
|
|
4802
|
+
this.emitter.once(event, callback);
|
|
4803
|
+
}
|
|
4804
|
+
},
|
|
4805
|
+
retryConfig: this.retryConfig,
|
|
4806
|
+
requestContext: requestContextToUse,
|
|
4807
|
+
abortController: this.abortController,
|
|
4808
|
+
writableStream,
|
|
4809
|
+
workflowSpan,
|
|
4810
|
+
outputOptions
|
|
4811
|
+
});
|
|
4812
|
+
if (result.status !== "suspended") {
|
|
4813
|
+
this.cleanup?.();
|
|
4814
|
+
}
|
|
4815
|
+
result.traceId = traceId;
|
|
4816
|
+
return result;
|
|
4817
|
+
}
|
|
4818
|
+
async timeTravel(args) {
|
|
4819
|
+
return this._timeTravel(args);
|
|
4820
|
+
}
|
|
4821
|
+
timeTravelStream({
|
|
4822
|
+
inputData,
|
|
4823
|
+
resumeData,
|
|
4824
|
+
initialState,
|
|
4825
|
+
step,
|
|
4826
|
+
context,
|
|
4827
|
+
nestedStepsContext,
|
|
4828
|
+
requestContext,
|
|
4829
|
+
tracingContext,
|
|
4830
|
+
tracingOptions,
|
|
4831
|
+
outputOptions
|
|
4832
|
+
}) {
|
|
4833
|
+
this.closeStreamAction = async () => {
|
|
4834
|
+
};
|
|
4835
|
+
const self = this;
|
|
4836
|
+
const stream = new web.ReadableStream({
|
|
4837
|
+
async start(controller) {
|
|
4838
|
+
const unwatch = self.watch(async ({ type, from = "WORKFLOW" /* WORKFLOW */, payload }) => {
|
|
4839
|
+
controller.enqueue({
|
|
4840
|
+
type,
|
|
4841
|
+
runId: self.runId,
|
|
4842
|
+
from,
|
|
4843
|
+
payload: {
|
|
4844
|
+
stepName: payload.id,
|
|
4845
|
+
...payload
|
|
4846
|
+
}
|
|
4847
|
+
});
|
|
4848
|
+
});
|
|
4849
|
+
self.closeStreamAction = async () => {
|
|
4850
|
+
unwatch();
|
|
4851
|
+
try {
|
|
4852
|
+
await controller.close();
|
|
4853
|
+
} catch (err) {
|
|
4854
|
+
console.error("Error closing stream:", err);
|
|
4855
|
+
}
|
|
4856
|
+
};
|
|
4857
|
+
const executionResultsPromise = self._timeTravel({
|
|
4858
|
+
inputData,
|
|
4859
|
+
step,
|
|
4860
|
+
context,
|
|
4861
|
+
nestedStepsContext,
|
|
4862
|
+
resumeData,
|
|
4863
|
+
initialState,
|
|
4864
|
+
requestContext,
|
|
4865
|
+
tracingContext,
|
|
4866
|
+
tracingOptions,
|
|
4867
|
+
writableStream: new web.WritableStream({
|
|
4868
|
+
write(chunk) {
|
|
4869
|
+
controller.enqueue(chunk);
|
|
4870
|
+
}
|
|
4871
|
+
}),
|
|
4872
|
+
outputOptions
|
|
4873
|
+
});
|
|
4874
|
+
self.executionResults = executionResultsPromise;
|
|
4875
|
+
let executionResults;
|
|
4876
|
+
try {
|
|
4877
|
+
executionResults = await executionResultsPromise;
|
|
4878
|
+
self.closeStreamAction?.().catch(() => {
|
|
4879
|
+
});
|
|
4880
|
+
if (self.streamOutput) {
|
|
4881
|
+
self.streamOutput.updateResults(executionResults);
|
|
4882
|
+
}
|
|
4883
|
+
} catch (err) {
|
|
4884
|
+
self.streamOutput?.rejectResults(err);
|
|
4885
|
+
self.closeStreamAction?.().catch(() => {
|
|
4886
|
+
});
|
|
4887
|
+
}
|
|
4888
|
+
}
|
|
4889
|
+
});
|
|
4890
|
+
this.streamOutput = new WorkflowRunOutput({
|
|
4891
|
+
runId: this.runId,
|
|
4892
|
+
workflowId: this.workflowId,
|
|
4893
|
+
stream
|
|
4894
|
+
});
|
|
4895
|
+
return this.streamOutput;
|
|
4896
|
+
}
|
|
4256
4897
|
/**
|
|
4257
4898
|
* @access private
|
|
4258
4899
|
* @returns The execution results of the workflow run
|
|
@@ -4715,7 +5356,7 @@ function convertMastraChunkToAISDKv5({
|
|
|
4715
5356
|
if (mode === "generate") {
|
|
4716
5357
|
return {
|
|
4717
5358
|
type: "file",
|
|
4718
|
-
file: new
|
|
5359
|
+
file: new chunkG36A2JRR_cjs.DefaultGeneratedFile({
|
|
4719
5360
|
data: chunk.payload.data,
|
|
4720
5361
|
mediaType: chunk.payload.mimeType
|
|
4721
5362
|
})
|
|
@@ -4723,7 +5364,7 @@ function convertMastraChunkToAISDKv5({
|
|
|
4723
5364
|
}
|
|
4724
5365
|
return {
|
|
4725
5366
|
type: "file",
|
|
4726
|
-
file: new
|
|
5367
|
+
file: new chunkG36A2JRR_cjs.DefaultGeneratedFileWithType({
|
|
4727
5368
|
data: chunk.payload.data,
|
|
4728
5369
|
mediaType: chunk.payload.mimeType
|
|
4729
5370
|
})
|
|
@@ -4878,7 +5519,8 @@ function execute({
|
|
|
4878
5519
|
modelSettings,
|
|
4879
5520
|
structuredOutput,
|
|
4880
5521
|
headers,
|
|
4881
|
-
shouldThrowError
|
|
5522
|
+
shouldThrowError,
|
|
5523
|
+
methodType
|
|
4882
5524
|
}) {
|
|
4883
5525
|
const v5 = new AISDKV5InputStream({
|
|
4884
5526
|
component: "LLM",
|
|
@@ -4926,7 +5568,8 @@ You don't need to format your response as JSON unless the user asks you to. Just
|
|
|
4926
5568
|
const pRetry = await import('p-retry');
|
|
4927
5569
|
return await pRetry.default(
|
|
4928
5570
|
async () => {
|
|
4929
|
-
const
|
|
5571
|
+
const fn = (methodType === "stream" ? model.doStream : model.doGenerate).bind(model);
|
|
5572
|
+
const streamResult = await fn({
|
|
4930
5573
|
...toolsAndToolChoice,
|
|
4931
5574
|
prompt,
|
|
4932
5575
|
providerOptions: providerOptionsToUse,
|
|
@@ -4950,10 +5593,6 @@ You don't need to format your response as JSON unless the user asks you to. Just
|
|
|
4950
5593
|
}
|
|
4951
5594
|
);
|
|
4952
5595
|
} catch (error) {
|
|
4953
|
-
const abortSignal = options?.abortSignal;
|
|
4954
|
-
if (providerUtilsV5.isAbortError(error) && abortSignal?.aborted) {
|
|
4955
|
-
console.error("Abort error", error);
|
|
4956
|
-
}
|
|
4957
5596
|
if (shouldThrowError) {
|
|
4958
5597
|
throw error;
|
|
4959
5598
|
}
|
|
@@ -5425,7 +6064,8 @@ function createLLMExecutionStep({
|
|
|
5425
6064
|
headers,
|
|
5426
6065
|
downloadRetries,
|
|
5427
6066
|
downloadConcurrency,
|
|
5428
|
-
processorStates
|
|
6067
|
+
processorStates,
|
|
6068
|
+
methodType
|
|
5429
6069
|
}) {
|
|
5430
6070
|
return createStep({
|
|
5431
6071
|
id: "llm-execution",
|
|
@@ -5475,7 +6115,7 @@ function createLLMExecutionStep({
|
|
|
5475
6115
|
}
|
|
5476
6116
|
if (prepareStepResult.messages) {
|
|
5477
6117
|
const newMessages = prepareStepResult.messages;
|
|
5478
|
-
const newMessageList = new
|
|
6118
|
+
const newMessageList = new chunkG36A2JRR_cjs.MessageList();
|
|
5479
6119
|
for (const message of newMessages) {
|
|
5480
6120
|
if (message.role === "system") {
|
|
5481
6121
|
newMessageList.addSystem(message);
|
|
@@ -5504,6 +6144,7 @@ function createLLMExecutionStep({
|
|
|
5504
6144
|
includeRawChunks,
|
|
5505
6145
|
structuredOutput,
|
|
5506
6146
|
headers,
|
|
6147
|
+
methodType,
|
|
5507
6148
|
onResult: ({
|
|
5508
6149
|
warnings: warningsFromStream,
|
|
5509
6150
|
request: requestFromStream,
|
|
@@ -5964,7 +6605,8 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
|
|
|
5964
6605
|
// VNext execution as internal
|
|
5965
6606
|
internal: 1 /* WORKFLOW */
|
|
5966
6607
|
},
|
|
5967
|
-
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended"
|
|
6608
|
+
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
|
|
6609
|
+
validateInputs: false
|
|
5968
6610
|
}
|
|
5969
6611
|
}).then(llmExecutionStep).map(
|
|
5970
6612
|
async ({ inputData }) => {
|
|
@@ -6004,7 +6646,8 @@ function createAgenticLoopWorkflow(params) {
|
|
|
6004
6646
|
},
|
|
6005
6647
|
shouldPersistSnapshot: (params2) => {
|
|
6006
6648
|
return params2.workflowStatus === "suspended";
|
|
6007
|
-
}
|
|
6649
|
+
},
|
|
6650
|
+
validateInputs: false
|
|
6008
6651
|
}
|
|
6009
6652
|
}).dowhile(agenticExecutionWorkflow, async ({ inputData }) => {
|
|
6010
6653
|
const typedInputData = inputData;
|
|
@@ -6095,7 +6738,7 @@ function workflowLoopStream({
|
|
|
6095
6738
|
}) {
|
|
6096
6739
|
return new web.ReadableStream({
|
|
6097
6740
|
start: async (controller) => {
|
|
6098
|
-
const writer = new WritableStream({
|
|
6741
|
+
const writer = new web.WritableStream({
|
|
6099
6742
|
write: (chunk) => {
|
|
6100
6743
|
controller.enqueue(chunk);
|
|
6101
6744
|
}
|
|
@@ -6414,7 +7057,8 @@ var MastraLLMVNext = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
6414
7057
|
requireToolApproval,
|
|
6415
7058
|
_internal,
|
|
6416
7059
|
agentId,
|
|
6417
|
-
toolCallId
|
|
7060
|
+
toolCallId,
|
|
7061
|
+
methodType
|
|
6418
7062
|
}) {
|
|
6419
7063
|
let stopWhenToUse;
|
|
6420
7064
|
if (maxSteps && typeof maxSteps === "number") {
|
|
@@ -6471,6 +7115,7 @@ var MastraLLMVNext = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
6471
7115
|
modelSpanTracker,
|
|
6472
7116
|
requireToolApproval,
|
|
6473
7117
|
agentId,
|
|
7118
|
+
methodType,
|
|
6474
7119
|
options: {
|
|
6475
7120
|
...options,
|
|
6476
7121
|
onStepFinish: async (props) => {
|
|
@@ -6510,7 +7155,7 @@ var MastraLLMVNext = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
6510
7155
|
});
|
|
6511
7156
|
if (props?.response?.headers?.["x-ratelimit-remaining-tokens"] && parseInt(props?.response?.headers?.["x-ratelimit-remaining-tokens"], 10) < 2e3) {
|
|
6512
7157
|
this.logger.warn("Rate limit approaching, waiting 10 seconds", { runId });
|
|
6513
|
-
await
|
|
7158
|
+
await chunkHBJPYQRN_cjs.delay(10 * 1e3);
|
|
6514
7159
|
}
|
|
6515
7160
|
},
|
|
6516
7161
|
onFinish: async (props) => {
|
|
@@ -6814,7 +7459,7 @@ async function prepareMemoryStep({
|
|
|
6814
7459
|
);
|
|
6815
7460
|
}
|
|
6816
7461
|
} else {
|
|
6817
|
-
const messageList = new
|
|
7462
|
+
const messageList = new chunkG36A2JRR_cjs.MessageList({
|
|
6818
7463
|
threadId: thread?.id,
|
|
6819
7464
|
resourceId: thread?.resourceId
|
|
6820
7465
|
});
|
|
@@ -7579,7 +8224,8 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
7579
8224
|
isOneOff: z5__default.default.boolean()
|
|
7580
8225
|
}),
|
|
7581
8226
|
options: {
|
|
7582
|
-
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended"
|
|
8227
|
+
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
|
|
8228
|
+
validateInputs: false
|
|
7583
8229
|
}
|
|
7584
8230
|
});
|
|
7585
8231
|
networkWorkflow.then(routingStep).branch([
|
|
@@ -7706,7 +8352,8 @@ async function networkLoop({
|
|
|
7706
8352
|
iteration: z5__default.default.number()
|
|
7707
8353
|
}),
|
|
7708
8354
|
options: {
|
|
7709
|
-
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended"
|
|
8355
|
+
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
|
|
8356
|
+
validateInputs: false
|
|
7710
8357
|
}
|
|
7711
8358
|
}).dountil(networkWorkflow, async ({ inputData }) => {
|
|
7712
8359
|
return inputData.isComplete || inputData.iteration >= maxIterations;
|
|
@@ -8264,7 +8911,7 @@ var AgentLegacyHandler = class {
|
|
|
8264
8911
|
writableStream,
|
|
8265
8912
|
methodType: methodType === "generate" ? "generateLegacy" : "streamLegacy"
|
|
8266
8913
|
});
|
|
8267
|
-
const messageList = new
|
|
8914
|
+
const messageList = new chunkG36A2JRR_cjs.MessageList({
|
|
8268
8915
|
threadId,
|
|
8269
8916
|
resourceId,
|
|
8270
8917
|
generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
|
|
@@ -8345,7 +8992,7 @@ var AgentLegacyHandler = class {
|
|
|
8345
8992
|
existingThread || hasResourceScopeSemanticRecall ? this.capabilities.getMemoryMessages({
|
|
8346
8993
|
resourceId,
|
|
8347
8994
|
threadId: threadObject.id,
|
|
8348
|
-
vectorMessageSearch: new
|
|
8995
|
+
vectorMessageSearch: new chunkG36A2JRR_cjs.MessageList().add(messages, `user`).getLatestUserContent() || "",
|
|
8349
8996
|
memoryConfig,
|
|
8350
8997
|
requestContext
|
|
8351
8998
|
}) : { messages: [] },
|
|
@@ -8367,7 +9014,7 @@ The following messages were remembered from a different conversation:
|
|
|
8367
9014
|
<remembered_from_other_conversation>
|
|
8368
9015
|
${(() => {
|
|
8369
9016
|
let result = ``;
|
|
8370
|
-
const messages2 = new
|
|
9017
|
+
const messages2 = new chunkG36A2JRR_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
|
|
8371
9018
|
let lastYmd = null;
|
|
8372
9019
|
for (const msg of messages2) {
|
|
8373
9020
|
const date = msg.createdAt;
|
|
@@ -8418,7 +9065,7 @@ the following messages are from ${ymd}
|
|
|
8418
9065
|
systemMessage,
|
|
8419
9066
|
memorySystemMessage: memorySystemMessage || void 0
|
|
8420
9067
|
});
|
|
8421
|
-
const processedList = new
|
|
9068
|
+
const processedList = new chunkG36A2JRR_cjs.MessageList({
|
|
8422
9069
|
threadId: threadObject.id,
|
|
8423
9070
|
resourceId,
|
|
8424
9071
|
generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
|
|
@@ -8474,7 +9121,7 @@ the following messages are from ${ymd}
|
|
|
8474
9121
|
result: resToLog,
|
|
8475
9122
|
threadId
|
|
8476
9123
|
});
|
|
8477
|
-
const messageListResponses = new
|
|
9124
|
+
const messageListResponses = new chunkG36A2JRR_cjs.MessageList({
|
|
8478
9125
|
threadId,
|
|
8479
9126
|
resourceId,
|
|
8480
9127
|
generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
|
|
@@ -8834,7 +9481,7 @@ the following messages are from ${ymd}
|
|
|
8834
9481
|
requestContext: mergedGenerateOptions.requestContext || new chunkJ7O6WENZ_cjs.RequestContext(),
|
|
8835
9482
|
tracingContext,
|
|
8836
9483
|
outputProcessorOverrides: finalOutputProcessors,
|
|
8837
|
-
messageList: new
|
|
9484
|
+
messageList: new chunkG36A2JRR_cjs.MessageList({
|
|
8838
9485
|
threadId: llmOptions.threadId || "",
|
|
8839
9486
|
resourceId: llmOptions.resourceId || ""
|
|
8840
9487
|
}).add(
|
|
@@ -8924,7 +9571,7 @@ the following messages are from ${ymd}
|
|
|
8924
9571
|
const outputProcessorResult = await this.capabilities.__runOutputProcessors({
|
|
8925
9572
|
requestContext: mergedGenerateOptions.requestContext || new chunkJ7O6WENZ_cjs.RequestContext(),
|
|
8926
9573
|
tracingContext,
|
|
8927
|
-
messageList: new
|
|
9574
|
+
messageList: new chunkG36A2JRR_cjs.MessageList({
|
|
8928
9575
|
threadId: llmOptions.threadId || "",
|
|
8929
9576
|
resourceId: llmOptions.resourceId || ""
|
|
8930
9577
|
}).add(
|
|
@@ -9134,6 +9781,21 @@ the following messages are from ${ymd}
|
|
|
9134
9781
|
}
|
|
9135
9782
|
};
|
|
9136
9783
|
|
|
9784
|
+
// src/llm/model/model-method-from-agent.ts
|
|
9785
|
+
function getModelMethodFromAgentMethod(methodType) {
|
|
9786
|
+
if (methodType === "generate" || methodType === "generateLegacy") {
|
|
9787
|
+
return "generate";
|
|
9788
|
+
} else if (methodType === "stream" || methodType === "streamLegacy") {
|
|
9789
|
+
return "stream";
|
|
9790
|
+
} else {
|
|
9791
|
+
throw new chunkTWH4PTDG_cjs.MastraError({
|
|
9792
|
+
id: "INVALID_METHOD_TYPE",
|
|
9793
|
+
domain: "AGENT" /* AGENT */,
|
|
9794
|
+
category: "USER" /* USER */
|
|
9795
|
+
});
|
|
9796
|
+
}
|
|
9797
|
+
}
|
|
9798
|
+
|
|
9137
9799
|
// src/processors/processors/unicode-normalizer.ts
|
|
9138
9800
|
var UnicodeNormalizer = class {
|
|
9139
9801
|
id = "unicode-normalizer";
|
|
@@ -11132,7 +11794,8 @@ function createMapResultsStep({
|
|
|
11132
11794
|
memoryConfig,
|
|
11133
11795
|
saveQueueManager,
|
|
11134
11796
|
agentSpan,
|
|
11135
|
-
agentId
|
|
11797
|
+
agentId,
|
|
11798
|
+
methodType
|
|
11136
11799
|
}) {
|
|
11137
11800
|
return async ({
|
|
11138
11801
|
inputData,
|
|
@@ -11197,7 +11860,9 @@ function createMapResultsStep({
|
|
|
11197
11860
|
effectiveOutputProcessors = effectiveOutputProcessors ? [...effectiveOutputProcessors, structuredProcessor] : [structuredProcessor];
|
|
11198
11861
|
}
|
|
11199
11862
|
const messageList = memoryData.messageList;
|
|
11863
|
+
const modelMethodType = getModelMethodFromAgentMethod(methodType);
|
|
11200
11864
|
const loopOptions = {
|
|
11865
|
+
methodType: modelMethodType,
|
|
11201
11866
|
agentId,
|
|
11202
11867
|
requestContext: result.requestContext,
|
|
11203
11868
|
tracingContext: { currentSpan: agentSpan },
|
|
@@ -11301,7 +11966,7 @@ var prepareToolsStepOutputSchema = z5.z.object({
|
|
|
11301
11966
|
var prepareMemoryStepOutputSchema = z5.z.object({
|
|
11302
11967
|
threadExists: z5.z.boolean(),
|
|
11303
11968
|
thread: storageThreadSchema.optional(),
|
|
11304
|
-
messageList: z5.z.instanceof(
|
|
11969
|
+
messageList: z5.z.instanceof(chunkG36A2JRR_cjs.MessageList),
|
|
11305
11970
|
tripwire: z5.z.boolean().optional(),
|
|
11306
11971
|
tripwireReason: z5.z.string().optional()
|
|
11307
11972
|
});
|
|
@@ -11334,7 +11999,7 @@ function createPrepareMemoryStep({
|
|
|
11334
11999
|
outputSchema: prepareMemoryStepOutputSchema,
|
|
11335
12000
|
execute: async ({ tracingContext }) => {
|
|
11336
12001
|
const thread = threadFromArgs;
|
|
11337
|
-
const messageList = new
|
|
12002
|
+
const messageList = new chunkG36A2JRR_cjs.MessageList({
|
|
11338
12003
|
threadId: thread?.id,
|
|
11339
12004
|
resourceId,
|
|
11340
12005
|
generateMessageId: capabilities.generateMessageId,
|
|
@@ -11415,7 +12080,7 @@ function createPrepareMemoryStep({
|
|
|
11415
12080
|
existingThread || hasResourceScopeSemanticRecall ? capabilities.getMemoryMessages({
|
|
11416
12081
|
resourceId,
|
|
11417
12082
|
threadId: threadObject.id,
|
|
11418
|
-
vectorMessageSearch: new
|
|
12083
|
+
vectorMessageSearch: new chunkG36A2JRR_cjs.MessageList().add(options.messages, `user`).getLatestUserContent() || "",
|
|
11419
12084
|
memoryConfig,
|
|
11420
12085
|
requestContext
|
|
11421
12086
|
}) : { messages: [] },
|
|
@@ -11441,7 +12106,7 @@ The following messages were remembered from a different conversation:
|
|
|
11441
12106
|
<remembered_from_other_conversation>
|
|
11442
12107
|
${(() => {
|
|
11443
12108
|
let result = ``;
|
|
11444
|
-
const messages = new
|
|
12109
|
+
const messages = new chunkG36A2JRR_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
|
|
11445
12110
|
let lastYmd = null;
|
|
11446
12111
|
for (const msg of messages) {
|
|
11447
12112
|
const date = msg.createdAt;
|
|
@@ -11488,7 +12153,7 @@ the following messages are from ${ymd}
|
|
|
11488
12153
|
systemMessage,
|
|
11489
12154
|
memorySystemMessage: memorySystemMessage || void 0
|
|
11490
12155
|
});
|
|
11491
|
-
const processedList = new
|
|
12156
|
+
const processedList = new chunkG36A2JRR_cjs.MessageList({
|
|
11492
12157
|
threadId: threadObject.id,
|
|
11493
12158
|
resourceId,
|
|
11494
12159
|
generateMessageId: capabilities.generateMessageId,
|
|
@@ -11563,7 +12228,8 @@ function createStreamStep({
|
|
|
11563
12228
|
requireToolApproval,
|
|
11564
12229
|
resumeContext,
|
|
11565
12230
|
agentId,
|
|
11566
|
-
toolCallId
|
|
12231
|
+
toolCallId,
|
|
12232
|
+
methodType
|
|
11567
12233
|
}) {
|
|
11568
12234
|
return createStep({
|
|
11569
12235
|
id: "stream-text-step",
|
|
@@ -11581,6 +12247,7 @@ function createStreamStep({
|
|
|
11581
12247
|
const processors = validatedInputData.outputProcessors || (capabilities.outputProcessors ? typeof capabilities.outputProcessors === "function" ? await capabilities.outputProcessors({
|
|
11582
12248
|
requestContext: validatedInputData.requestContext || new chunkJ7O6WENZ_cjs.RequestContext()
|
|
11583
12249
|
}) : capabilities.outputProcessors : []);
|
|
12250
|
+
const modelMethodType = getModelMethodFromAgentMethod(methodType);
|
|
11584
12251
|
const streamResult = capabilities.llm.stream({
|
|
11585
12252
|
...validatedInputData,
|
|
11586
12253
|
outputProcessors: processors,
|
|
@@ -11592,7 +12259,8 @@ function createStreamStep({
|
|
|
11592
12259
|
generateId: capabilities.generateMessageId
|
|
11593
12260
|
},
|
|
11594
12261
|
agentId,
|
|
11595
|
-
toolCallId
|
|
12262
|
+
toolCallId,
|
|
12263
|
+
methodType: modelMethodType
|
|
11596
12264
|
});
|
|
11597
12265
|
return streamResult;
|
|
11598
12266
|
}
|
|
@@ -11648,7 +12316,8 @@ function createPrepareStreamWorkflow({
|
|
|
11648
12316
|
requireToolApproval,
|
|
11649
12317
|
resumeContext,
|
|
11650
12318
|
agentId,
|
|
11651
|
-
toolCallId
|
|
12319
|
+
toolCallId,
|
|
12320
|
+
methodType
|
|
11652
12321
|
});
|
|
11653
12322
|
const mapResultsStep = createMapResultsStep({
|
|
11654
12323
|
capabilities,
|
|
@@ -11660,7 +12329,8 @@ function createPrepareStreamWorkflow({
|
|
|
11660
12329
|
memoryConfig,
|
|
11661
12330
|
saveQueueManager,
|
|
11662
12331
|
agentSpan,
|
|
11663
|
-
agentId
|
|
12332
|
+
agentId,
|
|
12333
|
+
methodType
|
|
11664
12334
|
});
|
|
11665
12335
|
return createWorkflow({
|
|
11666
12336
|
id: "execution-workflow",
|
|
@@ -11673,7 +12343,8 @@ function createPrepareStreamWorkflow({
|
|
|
11673
12343
|
options: {
|
|
11674
12344
|
tracingPolicy: {
|
|
11675
12345
|
internal: 1 /* WORKFLOW */
|
|
11676
|
-
}
|
|
12346
|
+
},
|
|
12347
|
+
validateInputs: false
|
|
11677
12348
|
}
|
|
11678
12349
|
}).parallel([prepareToolsStep, prepareMemoryStep2]).map(mapResultsStep).then(streamStep).commit();
|
|
11679
12350
|
}
|
|
@@ -12271,7 +12942,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12271
12942
|
*/
|
|
12272
12943
|
listTools({ requestContext = new chunkJ7O6WENZ_cjs.RequestContext() } = {}) {
|
|
12273
12944
|
if (typeof this.#tools !== "function") {
|
|
12274
|
-
return
|
|
12945
|
+
return chunkHBJPYQRN_cjs.ensureToolProperties(this.#tools);
|
|
12275
12946
|
}
|
|
12276
12947
|
const result = this.#tools({ requestContext, mastra: this.#mastra });
|
|
12277
12948
|
return resolveMaybePromise(result, (tools) => {
|
|
@@ -12289,7 +12960,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12289
12960
|
this.logger.error(mastraError.toString());
|
|
12290
12961
|
throw mastraError;
|
|
12291
12962
|
}
|
|
12292
|
-
return
|
|
12963
|
+
return chunkHBJPYQRN_cjs.ensureToolProperties(tools);
|
|
12293
12964
|
});
|
|
12294
12965
|
}
|
|
12295
12966
|
/**
|
|
@@ -12321,7 +12992,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12321
12992
|
});
|
|
12322
12993
|
});
|
|
12323
12994
|
} else {
|
|
12324
|
-
llm = new
|
|
12995
|
+
llm = new chunkO6NA3Z43_cjs.MastraLLMV1({
|
|
12325
12996
|
model: resolvedModel,
|
|
12326
12997
|
mastra: this.#mastra,
|
|
12327
12998
|
options: { tracingPolicy: this.#options?.tracingPolicy }
|
|
@@ -12346,7 +13017,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12346
13017
|
*/
|
|
12347
13018
|
async resolveModelConfig(modelConfig, requestContext) {
|
|
12348
13019
|
try {
|
|
12349
|
-
return await
|
|
13020
|
+
return await chunkN4SJ4YX7_cjs.resolveModelConfig(modelConfig, requestContext, this.#mastra);
|
|
12350
13021
|
} catch (error) {
|
|
12351
13022
|
const mastraError = new chunkTWH4PTDG_cjs.MastraError({
|
|
12352
13023
|
id: "AGENT_GET_MODEL_MISSING_MODEL_INSTANCE",
|
|
@@ -12552,7 +13223,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12552
13223
|
instructions
|
|
12553
13224
|
}) {
|
|
12554
13225
|
const llm = await this.getLLM({ requestContext, model });
|
|
12555
|
-
const normMessage = new
|
|
13226
|
+
const normMessage = new chunkG36A2JRR_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
|
|
12556
13227
|
if (!normMessage) {
|
|
12557
13228
|
throw new Error(`Could not generate title from input ${JSON.stringify(message)}`);
|
|
12558
13229
|
}
|
|
@@ -12575,7 +13246,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12575
13246
|
const systemInstructions = await this.resolveTitleInstructions(requestContext, instructions);
|
|
12576
13247
|
let text = "";
|
|
12577
13248
|
if (llm.getModel().specificationVersion === "v2") {
|
|
12578
|
-
const messageList = new
|
|
13249
|
+
const messageList = new chunkG36A2JRR_cjs.MessageList().add(
|
|
12579
13250
|
[
|
|
12580
13251
|
{
|
|
12581
13252
|
role: "system",
|
|
@@ -12593,6 +13264,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12593
13264
|
"input"
|
|
12594
13265
|
);
|
|
12595
13266
|
const result = llm.stream({
|
|
13267
|
+
methodType: "generate",
|
|
12596
13268
|
requestContext,
|
|
12597
13269
|
tracingContext,
|
|
12598
13270
|
messageList,
|
|
@@ -12626,7 +13298,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12626
13298
|
async genTitle(userMessage, requestContext, tracingContext, model, instructions) {
|
|
12627
13299
|
try {
|
|
12628
13300
|
if (userMessage) {
|
|
12629
|
-
const normMessage = new
|
|
13301
|
+
const normMessage = new chunkG36A2JRR_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
|
|
12630
13302
|
if (normMessage) {
|
|
12631
13303
|
return await this.generateTitleFromUserMessage({
|
|
12632
13304
|
message: normMessage,
|
|
@@ -12688,7 +13360,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12688
13360
|
model: await this.getModel({ requestContext }),
|
|
12689
13361
|
tracingPolicy: this.#options?.tracingPolicy
|
|
12690
13362
|
};
|
|
12691
|
-
const convertedToCoreTool =
|
|
13363
|
+
const convertedToCoreTool = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options);
|
|
12692
13364
|
convertedMemoryTools[toolName] = convertedToCoreTool;
|
|
12693
13365
|
}
|
|
12694
13366
|
}
|
|
@@ -12838,7 +13510,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12838
13510
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
12839
13511
|
requireApproval: tool.requireApproval
|
|
12840
13512
|
};
|
|
12841
|
-
return [k,
|
|
13513
|
+
return [k, chunkHBJPYQRN_cjs.makeCoreTool(tool, options)];
|
|
12842
13514
|
})
|
|
12843
13515
|
);
|
|
12844
13516
|
const assignedToolEntriesConverted = Object.fromEntries(
|
|
@@ -12886,7 +13558,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12886
13558
|
model: await this.getModel({ requestContext }),
|
|
12887
13559
|
tracingPolicy: this.#options?.tracingPolicy
|
|
12888
13560
|
};
|
|
12889
|
-
const convertedToCoreTool =
|
|
13561
|
+
const convertedToCoreTool = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options, "toolset");
|
|
12890
13562
|
toolsForRequest[toolName] = convertedToCoreTool;
|
|
12891
13563
|
}
|
|
12892
13564
|
}
|
|
@@ -12929,7 +13601,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12929
13601
|
model: await this.getModel({ requestContext }),
|
|
12930
13602
|
tracingPolicy: this.#options?.tracingPolicy
|
|
12931
13603
|
};
|
|
12932
|
-
const convertedToCoreTool =
|
|
13604
|
+
const convertedToCoreTool = chunkHBJPYQRN_cjs.makeCoreTool(rest, options, "client-tool");
|
|
12933
13605
|
toolsForRequest[toolName] = convertedToCoreTool;
|
|
12934
13606
|
}
|
|
12935
13607
|
}
|
|
@@ -12960,7 +13632,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12960
13632
|
subAgentResourceId: z5.z.string().describe("The resource ID of the agent").optional()
|
|
12961
13633
|
});
|
|
12962
13634
|
const modelVersion = (await agent.getModel()).specificationVersion;
|
|
12963
|
-
const toolObj =
|
|
13635
|
+
const toolObj = chunk4IKJAKCD_cjs.createTool({
|
|
12964
13636
|
id: `agent-${agentName}`,
|
|
12965
13637
|
description: `Agent: ${agentName}`,
|
|
12966
13638
|
inputSchema: agentInputSchema,
|
|
@@ -12980,12 +13652,24 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
12980
13652
|
});
|
|
12981
13653
|
let result;
|
|
12982
13654
|
if ((methodType === "generate" || methodType === "generateLegacy") && modelVersion === "v2") {
|
|
13655
|
+
if (!agent.hasOwnMemory() && this.#memory) {
|
|
13656
|
+
agent.__setMemory(this.#memory);
|
|
13657
|
+
}
|
|
13658
|
+
const subAgentThreadId = crypto2.randomUUID();
|
|
13659
|
+
const slugify = await import('@sindresorhus/slugify');
|
|
13660
|
+
const subAgentResourceId = `${slugify.default(this.id)}-${agentName}`;
|
|
12983
13661
|
const generateResult = await agent.generate(inputData.prompt, {
|
|
12984
13662
|
requestContext,
|
|
12985
|
-
tracingContext: context?.tracingContext
|
|
13663
|
+
tracingContext: context?.tracingContext,
|
|
13664
|
+
...resourceId && threadId ? {
|
|
13665
|
+
memory: {
|
|
13666
|
+
resource: subAgentResourceId,
|
|
13667
|
+
thread: subAgentThreadId
|
|
13668
|
+
}
|
|
13669
|
+
} : {}
|
|
12986
13670
|
});
|
|
12987
|
-
result = { text: generateResult.text };
|
|
12988
|
-
} else if (
|
|
13671
|
+
result = { text: generateResult.text, subAgentThreadId, subAgentResourceId };
|
|
13672
|
+
} else if (methodType === "generate" && modelVersion === "v1") {
|
|
12989
13673
|
const generateResult = await agent.generateLegacy(inputData.prompt, {
|
|
12990
13674
|
requestContext,
|
|
12991
13675
|
tracingContext: context?.tracingContext
|
|
@@ -13072,7 +13756,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13072
13756
|
tracingContext,
|
|
13073
13757
|
tracingPolicy: this.#options?.tracingPolicy
|
|
13074
13758
|
};
|
|
13075
|
-
convertedAgentTools[`agent-${agentName}`] =
|
|
13759
|
+
convertedAgentTools[`agent-${agentName}`] = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options);
|
|
13076
13760
|
}
|
|
13077
13761
|
}
|
|
13078
13762
|
return convertedAgentTools;
|
|
@@ -13093,11 +13777,11 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13093
13777
|
const workflows = await this.listWorkflows({ requestContext });
|
|
13094
13778
|
if (Object.keys(workflows).length > 0) {
|
|
13095
13779
|
for (const [workflowName, workflow] of Object.entries(workflows)) {
|
|
13096
|
-
const toolObj =
|
|
13780
|
+
const toolObj = chunk4IKJAKCD_cjs.createTool({
|
|
13097
13781
|
id: `workflow-${workflowName}`,
|
|
13098
13782
|
description: workflow.description || `Workflow: ${workflowName}`,
|
|
13099
13783
|
inputSchema: workflow.inputSchema,
|
|
13100
|
-
outputSchema: workflow.outputSchema,
|
|
13784
|
+
outputSchema: z5.z.object({ result: workflow.outputSchema, runId: z5.z.string() }),
|
|
13101
13785
|
mastra: this.#mastra,
|
|
13102
13786
|
// BREAKING CHANGE v1.0: New tool signature - first param is inputData, second is context
|
|
13103
13787
|
// manually wrap workflow tools with tracing, so that we can pass the
|
|
@@ -13144,7 +13828,8 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13144
13828
|
}
|
|
13145
13829
|
result = await streamResult.result;
|
|
13146
13830
|
}
|
|
13147
|
-
|
|
13831
|
+
const workflowOutput = result?.result || result;
|
|
13832
|
+
return { result: workflowOutput, runId: run.runId };
|
|
13148
13833
|
} catch (err) {
|
|
13149
13834
|
const mastraError = new chunkTWH4PTDG_cjs.MastraError(
|
|
13150
13835
|
{
|
|
@@ -13181,7 +13866,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13181
13866
|
tracingContext,
|
|
13182
13867
|
tracingPolicy: this.#options?.tracingPolicy
|
|
13183
13868
|
};
|
|
13184
|
-
convertedWorkflowTools[`workflow-${workflowName}`] =
|
|
13869
|
+
convertedWorkflowTools[`workflow-${workflowName}`] = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options);
|
|
13185
13870
|
}
|
|
13186
13871
|
}
|
|
13187
13872
|
return convertedWorkflowTools;
|
|
@@ -13204,7 +13889,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13204
13889
|
let mastraProxy = void 0;
|
|
13205
13890
|
const logger = this.logger;
|
|
13206
13891
|
if (this.#mastra) {
|
|
13207
|
-
mastraProxy =
|
|
13892
|
+
mastraProxy = chunkHBJPYQRN_cjs.createMastraProxy({ mastra: this.#mastra, logger });
|
|
13208
13893
|
}
|
|
13209
13894
|
const assignedTools = await this.listAssignedTools({
|
|
13210
13895
|
runId,
|
|
@@ -13424,7 +14109,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13424
14109
|
if (model || !Array.isArray(this.model)) {
|
|
13425
14110
|
const modelToUse = model ?? this.model;
|
|
13426
14111
|
const resolvedModel = typeof modelToUse === "function" ? await modelToUse({ requestContext, mastra: this.#mastra }) : modelToUse;
|
|
13427
|
-
if (resolvedModel
|
|
14112
|
+
if (resolvedModel?.specificationVersion !== "v2") {
|
|
13428
14113
|
const mastraError = new chunkTWH4PTDG_cjs.MastraError({
|
|
13429
14114
|
id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
|
|
13430
14115
|
domain: "AGENT" /* AGENT */,
|
|
@@ -13441,6 +14126,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13441
14126
|
return [
|
|
13442
14127
|
{
|
|
13443
14128
|
id: "main",
|
|
14129
|
+
// TODO fix type check
|
|
13444
14130
|
model: resolvedModel,
|
|
13445
14131
|
maxRetries: this.maxRetries ?? 0,
|
|
13446
14132
|
enabled: true
|
|
@@ -13450,7 +14136,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13450
14136
|
const models = await Promise.all(
|
|
13451
14137
|
this.model.map(async (modelConfig) => {
|
|
13452
14138
|
const model2 = await this.resolveModelConfig(modelConfig.model, requestContext);
|
|
13453
|
-
if (model2
|
|
14139
|
+
if (!isV2Model(model2)) {
|
|
13454
14140
|
const mastraError = new chunkTWH4PTDG_cjs.MastraError({
|
|
13455
14141
|
id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
|
|
13456
14142
|
domain: "AGENT" /* AGENT */,
|
|
@@ -13797,8 +14483,59 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
13797
14483
|
});
|
|
13798
14484
|
}
|
|
13799
14485
|
async generate(messages, options) {
|
|
13800
|
-
const
|
|
13801
|
-
|
|
14486
|
+
const defaultOptions = await this.getDefaultOptions({
|
|
14487
|
+
requestContext: options?.requestContext
|
|
14488
|
+
});
|
|
14489
|
+
const mergedOptions = {
|
|
14490
|
+
...defaultOptions,
|
|
14491
|
+
...options ?? {}
|
|
14492
|
+
};
|
|
14493
|
+
const llm = await this.getLLM({
|
|
14494
|
+
requestContext: mergedOptions.requestContext
|
|
14495
|
+
});
|
|
14496
|
+
const modelInfo = llm.getModel();
|
|
14497
|
+
if (modelInfo.specificationVersion !== "v2") {
|
|
14498
|
+
const modelId = modelInfo.modelId || "unknown";
|
|
14499
|
+
const provider = modelInfo.provider || "unknown";
|
|
14500
|
+
throw new chunkTWH4PTDG_cjs.MastraError({
|
|
14501
|
+
id: "AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED",
|
|
14502
|
+
domain: "AGENT" /* AGENT */,
|
|
14503
|
+
category: "USER" /* USER */,
|
|
14504
|
+
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.`,
|
|
14505
|
+
details: {
|
|
14506
|
+
agentName: this.name,
|
|
14507
|
+
modelId,
|
|
14508
|
+
provider,
|
|
14509
|
+
specificationVersion: modelInfo.specificationVersion
|
|
14510
|
+
}
|
|
14511
|
+
});
|
|
14512
|
+
}
|
|
14513
|
+
const executeOptions = {
|
|
14514
|
+
...mergedOptions,
|
|
14515
|
+
messages,
|
|
14516
|
+
methodType: "generate"
|
|
14517
|
+
};
|
|
14518
|
+
const result = await this.#execute(executeOptions);
|
|
14519
|
+
if (result.status !== "success") {
|
|
14520
|
+
if (result.status === "failed") {
|
|
14521
|
+
throw new chunkTWH4PTDG_cjs.MastraError(
|
|
14522
|
+
{
|
|
14523
|
+
id: "AGENT_GENERATE_FAILED",
|
|
14524
|
+
domain: "AGENT" /* AGENT */,
|
|
14525
|
+
category: "USER" /* USER */
|
|
14526
|
+
},
|
|
14527
|
+
// pass original error to preserve stack trace
|
|
14528
|
+
result.error
|
|
14529
|
+
);
|
|
14530
|
+
}
|
|
14531
|
+
throw new chunkTWH4PTDG_cjs.MastraError({
|
|
14532
|
+
id: "AGENT_GENERATE_UNKNOWN_ERROR",
|
|
14533
|
+
domain: "AGENT" /* AGENT */,
|
|
14534
|
+
category: "USER" /* USER */,
|
|
14535
|
+
text: "An unknown error occurred while streaming"
|
|
14536
|
+
});
|
|
14537
|
+
}
|
|
14538
|
+
const fullOutput = await result.result.getFullOutput();
|
|
13802
14539
|
const error = fullOutput.error;
|
|
13803
14540
|
if (fullOutput.finishReason === "error" && error) {
|
|
13804
14541
|
throw error;
|
|
@@ -15187,7 +15924,7 @@ var MastraModelOutput = class extends chunkKEXGB7FK_cjs.MastraBase {
|
|
|
15187
15924
|
self.messageList,
|
|
15188
15925
|
options.tracingContext
|
|
15189
15926
|
);
|
|
15190
|
-
const outputText = self.messageList.get.response.aiV4.core().map((m) =>
|
|
15927
|
+
const outputText = self.messageList.get.response.aiV4.core().map((m) => chunkG36A2JRR_cjs.MessageList.coreContentToString(m.content)).join("\n");
|
|
15191
15928
|
self.#delayedPromises.text.resolve(outputText);
|
|
15192
15929
|
self.#delayedPromises.finishReason.resolve(self.#finishReason);
|
|
15193
15930
|
if (chunk.payload.metadata) {
|
|
@@ -15810,8 +16547,10 @@ exports.convertFullStreamChunkToUIMessageStream = convertFullStreamChunkToUIMess
|
|
|
15810
16547
|
exports.convertMastraChunkToAISDKv5 = convertMastraChunkToAISDKv5;
|
|
15811
16548
|
exports.createDeprecationProxy = createDeprecationProxy;
|
|
15812
16549
|
exports.createStep = createStep;
|
|
16550
|
+
exports.createTimeTravelExecutionParams = createTimeTravelExecutionParams;
|
|
15813
16551
|
exports.createWorkflow = createWorkflow;
|
|
15814
16552
|
exports.getResumeLabelsByStepId = getResumeLabelsByStepId;
|
|
16553
|
+
exports.getStepIds = getStepIds;
|
|
15815
16554
|
exports.getStepResult = getStepResult;
|
|
15816
16555
|
exports.getZodErrors = getZodErrors;
|
|
15817
16556
|
exports.loop = loop;
|
|
@@ -15821,5 +16560,6 @@ exports.runCountDeprecationMessage = runCountDeprecationMessage;
|
|
|
15821
16560
|
exports.tryGenerateWithJsonFallback = tryGenerateWithJsonFallback;
|
|
15822
16561
|
exports.tryStreamWithJsonFallback = tryStreamWithJsonFallback;
|
|
15823
16562
|
exports.validateStepInput = validateStepInput;
|
|
15824
|
-
|
|
15825
|
-
//# sourceMappingURL=chunk-
|
|
16563
|
+
exports.validateStepResumeData = validateStepResumeData;
|
|
16564
|
+
//# sourceMappingURL=chunk-OWX2PUFH.cjs.map
|
|
16565
|
+
//# sourceMappingURL=chunk-OWX2PUFH.cjs.map
|