@mastra/core 0.15.3-alpha.4 → 0.15.3-alpha.6
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 +3215 -0
- package/dist/agent/agent.types.d.ts +1 -0
- package/dist/agent/agent.types.d.ts.map +1 -1
- package/dist/agent/index.cjs +11 -11
- package/dist/agent/index.d.ts +2 -1
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -2
- package/dist/agent/input-processor/index.cjs +6 -6
- package/dist/agent/input-processor/index.js +1 -1
- package/dist/agent/message-list/prompt/convert-to-mastra-v1.d.ts.map +1 -1
- package/dist/ai-tracing/exporters/default.d.ts.map +1 -1
- package/dist/ai-tracing/index.cjs +30 -30
- package/dist/ai-tracing/index.js +1 -1
- package/dist/{chunk-KUNWELBC.cjs → chunk-25VRTGOH.cjs} +311 -161
- package/dist/chunk-25VRTGOH.cjs.map +1 -0
- package/dist/{chunk-XM2ASGWH.js → chunk-4VU6A5XE.js} +3 -3
- package/dist/{chunk-XM2ASGWH.js.map → chunk-4VU6A5XE.js.map} +1 -1
- package/dist/{chunk-FQRDHVZC.cjs → chunk-5KIEN3HX.cjs} +4 -4
- package/dist/{chunk-FQRDHVZC.cjs.map → chunk-5KIEN3HX.cjs.map} +1 -1
- package/dist/{chunk-VVTB47UG.cjs → chunk-626FLQPT.cjs} +4 -4
- package/dist/{chunk-VVTB47UG.cjs.map → chunk-626FLQPT.cjs.map} +1 -1
- package/dist/{chunk-W5CF7DLB.cjs → chunk-6C6CR7JZ.cjs} +87 -47
- package/dist/chunk-6C6CR7JZ.cjs.map +1 -0
- package/dist/{chunk-YVIYEC6R.js → chunk-7S5FYPH7.js} +5 -5
- package/dist/{chunk-YVIYEC6R.js.map → chunk-7S5FYPH7.js.map} +1 -1
- package/dist/{chunk-5CJDO3UO.cjs → chunk-AAJF7WLJ.cjs} +3 -4
- package/dist/chunk-AAJF7WLJ.cjs.map +1 -0
- package/dist/{chunk-NMDRUT3Q.cjs → chunk-AWES6LTC.cjs} +4 -4
- package/dist/{chunk-NMDRUT3Q.cjs.map → chunk-AWES6LTC.cjs.map} +1 -1
- package/dist/{chunk-F4SQXAXR.js → chunk-BGE27UEX.js} +3 -4
- package/dist/chunk-BGE27UEX.js.map +1 -0
- package/dist/chunk-GXSERFAG.js +3 -0
- package/dist/{chunk-ZPQQN52E.js.map → chunk-GXSERFAG.js.map} +1 -1
- package/dist/{chunk-CKM2ESZF.js → chunk-HGYL2SSF.js} +14 -24
- package/dist/chunk-HGYL2SSF.js.map +1 -0
- package/dist/{chunk-P2IJ74UW.js → chunk-IH5UAO56.js} +280 -130
- package/dist/chunk-IH5UAO56.js.map +1 -0
- package/dist/{chunk-DZADAEAF.cjs → chunk-IQ5ISXGO.cjs} +14 -14
- package/dist/{chunk-DZADAEAF.cjs.map → chunk-IQ5ISXGO.cjs.map} +1 -1
- package/dist/{chunk-YAWYQH3N.js → chunk-JWURNPTP.js} +3 -3
- package/dist/{chunk-YAWYQH3N.js.map → chunk-JWURNPTP.js.map} +1 -1
- package/dist/{chunk-F2CAC2R2.cjs → chunk-MNDKBEEQ.cjs} +14 -24
- package/dist/chunk-MNDKBEEQ.cjs.map +1 -0
- package/dist/{chunk-OFPVAPUH.js → chunk-NHAHPLS5.js} +83 -43
- package/dist/chunk-NHAHPLS5.js.map +1 -0
- package/dist/{chunk-XPFWOBV4.js → chunk-POFCBVHG.js} +3 -3
- package/dist/{chunk-XPFWOBV4.js.map → chunk-POFCBVHG.js.map} +1 -1
- package/dist/{chunk-76MWMAR7.js → chunk-R7K2QO7M.js} +3 -2
- package/dist/chunk-R7K2QO7M.js.map +1 -0
- package/dist/{chunk-I7OAONIW.cjs → chunk-UFCYMOYH.cjs} +12 -2
- package/dist/chunk-UFCYMOYH.cjs.map +1 -0
- package/dist/{chunk-J35ULAQT.js → chunk-VZS4UVKF.js} +3 -3
- package/dist/{chunk-J35ULAQT.js.map → chunk-VZS4UVKF.js.map} +1 -1
- package/dist/{chunk-FBBP67MQ.cjs → chunk-VZYIKGJ6.cjs} +4 -4
- package/dist/{chunk-FBBP67MQ.cjs.map → chunk-VZYIKGJ6.cjs.map} +1 -1
- package/dist/{chunk-LOYT3WUA.js → chunk-WEPWZHE4.js} +12 -2
- package/dist/chunk-WEPWZHE4.js.map +1 -0
- package/dist/chunk-X4RMXTXF.cjs +4 -0
- package/dist/{chunk-F37IQKBQ.cjs.map → chunk-X4RMXTXF.cjs.map} +1 -1
- package/dist/{chunk-ZOU4K5MI.cjs → chunk-Z637KSJF.cjs} +3 -2
- package/dist/chunk-Z637KSJF.cjs.map +1 -0
- package/dist/index.cjs +30 -30
- package/dist/index.js +8 -8
- package/dist/llm/model/model.d.ts.map +1 -1
- package/dist/llm/model/model.loop.d.ts +1 -1
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/model.loop.types.d.ts +1 -0
- package/dist/llm/model/model.loop.types.d.ts.map +1 -1
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/loop.d.ts +1 -1
- package/dist/loop/loop.d.ts.map +1 -1
- package/dist/loop/types.d.ts +2 -0
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflow/llm-execution.d.ts.map +1 -1
- package/dist/loop/workflow/stream.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +4 -4
- package/dist/memory/index.js +1 -1
- package/dist/network/index.cjs +2 -2
- package/dist/network/index.js +1 -1
- package/dist/network/vNext/index.cjs +17 -17
- package/dist/network/vNext/index.cjs.map +1 -1
- package/dist/network/vNext/index.d.ts.map +1 -1
- package/dist/network/vNext/index.js +3 -3
- package/dist/network/vNext/index.js.map +1 -1
- package/dist/processors/index.cjs +8 -8
- package/dist/processors/index.js +2 -2
- package/dist/relevance/index.cjs +4 -4
- package/dist/relevance/index.js +1 -1
- package/dist/scores/index.cjs +5 -5
- package/dist/scores/index.js +1 -1
- package/dist/server/index.cjs +2 -2
- package/dist/server/index.js +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 +13 -14
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.js +11 -12
- package/dist/storage/index.js.map +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts +6 -0
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +3 -3
- package/dist/stream/index.js +1 -1
- package/dist/stream/types.d.ts +2 -1
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/telemetry/index.cjs +7 -7
- package/dist/telemetry/index.js +1 -1
- package/dist/telemetry/telemetry.decorators.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 -0
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tts/index.cjs +2 -2
- package/dist/tts/index.js +1 -1
- package/dist/voice/index.cjs +4 -4
- package/dist/voice/index.js +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/index.cjs +10 -10
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/legacy/index.cjs +22 -22
- package/dist/workflows/legacy/index.js +1 -1
- package/dist/workflows/types.d.ts +64 -9
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +8 -3
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +12 -2
- package/dist/chunk-5CJDO3UO.cjs.map +0 -1
- package/dist/chunk-76MWMAR7.js.map +0 -1
- package/dist/chunk-CKM2ESZF.js.map +0 -1
- package/dist/chunk-F2CAC2R2.cjs.map +0 -1
- package/dist/chunk-F37IQKBQ.cjs +0 -4
- package/dist/chunk-F4SQXAXR.js.map +0 -1
- package/dist/chunk-I7OAONIW.cjs.map +0 -1
- package/dist/chunk-KUNWELBC.cjs.map +0 -1
- package/dist/chunk-LOYT3WUA.js.map +0 -1
- package/dist/chunk-OFPVAPUH.js.map +0 -1
- package/dist/chunk-P2IJ74UW.js.map +0 -1
- package/dist/chunk-W5CF7DLB.cjs.map +0 -1
- package/dist/chunk-ZOU4K5MI.cjs.map +0 -1
- package/dist/chunk-ZPQQN52E.js +0 -3
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { DefaultVoice } from './chunk-
|
|
1
|
+
import { DefaultVoice } from './chunk-4VU6A5XE.js';
|
|
2
2
|
import { EMITTER_SYMBOL } from './chunk-GK5V7YTQ.js';
|
|
3
|
-
import { InstrumentClass, Telemetry } from './chunk-
|
|
4
|
-
import { MastraLLMV1 } from './chunk-
|
|
5
|
-
import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-
|
|
3
|
+
import { InstrumentClass, Telemetry } from './chunk-R7K2QO7M.js';
|
|
4
|
+
import { MastraLLMV1 } from './chunk-HGYL2SSF.js';
|
|
5
|
+
import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-BGE27UEX.js';
|
|
6
6
|
import { executeHook } from './chunk-TTELJD4F.js';
|
|
7
7
|
import { ensureToolProperties, makeCoreTool, createMastraProxy, delay } from './chunk-WWQ3QRPF.js';
|
|
8
8
|
import { RuntimeContext } from './chunk-HLRWYUFN.js';
|
|
9
9
|
import { ToolStream } from './chunk-YW7UILPE.js';
|
|
10
|
-
import { Tool } from './chunk-BJGHUKKM.js';
|
|
11
|
-
import { getOrCreateSpan, wrapMastra, selectFields } from './chunk-
|
|
10
|
+
import { createTool, Tool } from './chunk-BJGHUKKM.js';
|
|
11
|
+
import { getOrCreateSpan, wrapMastra, selectFields } from './chunk-WEPWZHE4.js';
|
|
12
12
|
import { MastraError } from './chunk-MCOVMKIS.js';
|
|
13
13
|
import { MastraBase } from './chunk-6GF5M4GX.js';
|
|
14
14
|
import { ConsoleLogger, RegisteredLogger } from './chunk-X3GXU6TZ.js';
|
|
@@ -2023,6 +2023,7 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
2023
2023
|
reasoningDetails: new DelayedPromise()
|
|
2024
2024
|
};
|
|
2025
2025
|
#streamConsumed = false;
|
|
2026
|
+
#returnScorerData = false;
|
|
2026
2027
|
/**
|
|
2027
2028
|
* Unique identifier for this execution run.
|
|
2028
2029
|
*/
|
|
@@ -2047,6 +2048,7 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
2047
2048
|
name: "MastraModelOutput"
|
|
2048
2049
|
});
|
|
2049
2050
|
this.#options = options;
|
|
2051
|
+
this.#returnScorerData = !!options.returnScorerData;
|
|
2050
2052
|
this.runId = options.runId;
|
|
2051
2053
|
if (options.outputProcessors?.length) {
|
|
2052
2054
|
this.processorRunner = new ProcessorRunner({
|
|
@@ -2526,6 +2528,18 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
2526
2528
|
throw error;
|
|
2527
2529
|
}
|
|
2528
2530
|
});
|
|
2531
|
+
let scoringData;
|
|
2532
|
+
if (this.#returnScorerData) {
|
|
2533
|
+
scoringData = {
|
|
2534
|
+
input: {
|
|
2535
|
+
inputMessages: this.messageList.getPersisted.input.ui(),
|
|
2536
|
+
rememberedMessages: this.messageList.getPersisted.remembered.ui(),
|
|
2537
|
+
systemMessages: this.messageList.getSystemMessages(),
|
|
2538
|
+
taggedSystemMessages: this.messageList.getPersisted.taggedSystemMessages
|
|
2539
|
+
},
|
|
2540
|
+
output: this.messageList.getPersisted.response.ui()
|
|
2541
|
+
};
|
|
2542
|
+
}
|
|
2529
2543
|
const fullOutput = {
|
|
2530
2544
|
text: await this.text,
|
|
2531
2545
|
usage: await this.usage,
|
|
@@ -2545,7 +2559,10 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
2545
2559
|
object: await this.object,
|
|
2546
2560
|
error: this.error,
|
|
2547
2561
|
tripwire: this.#tripwire,
|
|
2548
|
-
tripwireReason: this.#tripwireReason
|
|
2562
|
+
tripwireReason: this.#tripwireReason,
|
|
2563
|
+
...(scoringData ? {
|
|
2564
|
+
scoringData
|
|
2565
|
+
} : {})
|
|
2549
2566
|
};
|
|
2550
2567
|
fullOutput.response.messages = this.messageList.get.response.aiV5.model();
|
|
2551
2568
|
return fullOutput;
|
|
@@ -3069,7 +3086,16 @@ async function processOutputStream({
|
|
|
3069
3086
|
reasoningDeltas: []
|
|
3070
3087
|
});
|
|
3071
3088
|
}
|
|
3072
|
-
if (chunk.type !== "text-delta" && chunk.type !== "tool-call" &&
|
|
3089
|
+
if (chunk.type !== "text-delta" && chunk.type !== "tool-call" &&
|
|
3090
|
+
// not 100% sure about this being the right fix.
|
|
3091
|
+
// basically for some llm providers they add response-metadata after each text-delta
|
|
3092
|
+
// we then flush the chunks by calling messageList.add (a few lines down)
|
|
3093
|
+
// this results in a bunch of weird separated text chunks on the message instead of combined chunks
|
|
3094
|
+
// easiest solution here is to just not flush for response-metadata
|
|
3095
|
+
// BUT does this cause other issues?
|
|
3096
|
+
// Alternative solution: in message list allow combining text deltas together when the message source is "response" and the text parts are directly next to each other
|
|
3097
|
+
// simple solution for now is to not flush text deltas on response-metadata
|
|
3098
|
+
chunk.type !== "response-metadata" && runState.state.isStreaming) {
|
|
3073
3099
|
if (runState.state.textDeltas.length) {
|
|
3074
3100
|
const textStartPayload = chunk.payload;
|
|
3075
3101
|
const providerMetadata = textStartPayload.providerMetadata ?? runState.state.providerOptions;
|
|
@@ -3750,16 +3776,6 @@ function workflowLoopStream({
|
|
|
3750
3776
|
start: async controller => {
|
|
3751
3777
|
const writer = new WritableStream({
|
|
3752
3778
|
write: chunk => {
|
|
3753
|
-
if (llmAISpan && chunk.type === "text-delta") {
|
|
3754
|
-
llmAISpan.createEventSpan({
|
|
3755
|
-
type: "llm_chunk" /* LLM_CHUNK */,
|
|
3756
|
-
name: `llm chunk: ${chunk.type}`,
|
|
3757
|
-
output: chunk.payload.text,
|
|
3758
|
-
attributes: {
|
|
3759
|
-
chunkType: chunk.type
|
|
3760
|
-
}
|
|
3761
|
-
});
|
|
3762
|
-
}
|
|
3763
3779
|
controller.enqueue(chunk);
|
|
3764
3780
|
}
|
|
3765
3781
|
});
|
|
@@ -3905,6 +3921,7 @@ function loop({
|
|
|
3905
3921
|
_internal,
|
|
3906
3922
|
mode = "stream",
|
|
3907
3923
|
outputProcessors,
|
|
3924
|
+
returnScorerData,
|
|
3908
3925
|
llmAISpan,
|
|
3909
3926
|
...rest
|
|
3910
3927
|
}) {
|
|
@@ -3984,7 +4001,8 @@ function loop({
|
|
|
3984
4001
|
onStepFinish: rest.options?.onStepFinish,
|
|
3985
4002
|
includeRawChunks: !!includeRawChunks,
|
|
3986
4003
|
output: rest.output,
|
|
3987
|
-
outputProcessors
|
|
4004
|
+
outputProcessors,
|
|
4005
|
+
returnScorerData
|
|
3988
4006
|
}
|
|
3989
4007
|
});
|
|
3990
4008
|
}
|
|
@@ -4076,6 +4094,7 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
4076
4094
|
output,
|
|
4077
4095
|
options,
|
|
4078
4096
|
outputProcessors,
|
|
4097
|
+
returnScorerData,
|
|
4079
4098
|
providerOptions,
|
|
4080
4099
|
tracingContext
|
|
4081
4100
|
// ...rest
|
|
@@ -4131,6 +4150,7 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
4131
4150
|
},
|
|
4132
4151
|
output,
|
|
4133
4152
|
outputProcessors,
|
|
4153
|
+
returnScorerData,
|
|
4134
4154
|
llmAISpan,
|
|
4135
4155
|
options: {
|
|
4136
4156
|
...options,
|
|
@@ -9879,27 +9899,31 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
9879
9899
|
threadId,
|
|
9880
9900
|
resourceId,
|
|
9881
9901
|
runtimeContext,
|
|
9902
|
+
methodType,
|
|
9882
9903
|
tracingContext
|
|
9883
9904
|
}) {
|
|
9884
|
-
|
|
9905
|
+
const convertedWorkflowTools = {};
|
|
9885
9906
|
const workflows = await this.getWorkflows({
|
|
9886
9907
|
runtimeContext
|
|
9887
9908
|
});
|
|
9888
9909
|
if (Object.keys(workflows).length > 0) {
|
|
9889
|
-
|
|
9890
|
-
|
|
9910
|
+
for (const [workflowName, workflow] of Object.entries(workflows)) {
|
|
9911
|
+
const toolObj = createTool({
|
|
9912
|
+
id: workflowName,
|
|
9891
9913
|
description: workflow.description || `Workflow: ${workflowName}`,
|
|
9892
|
-
|
|
9893
|
-
|
|
9894
|
-
|
|
9895
|
-
},
|
|
9914
|
+
inputSchema: workflow.inputSchema,
|
|
9915
|
+
outputSchema: workflow.outputSchema,
|
|
9916
|
+
mastra: this.#mastra,
|
|
9896
9917
|
// manually wrap workflow tools with ai tracing, so that we can pass the
|
|
9897
9918
|
// current tool span onto the workflow to maintain continuity of the trace
|
|
9898
|
-
execute: async
|
|
9919
|
+
execute: async ({
|
|
9920
|
+
context,
|
|
9921
|
+
writer
|
|
9922
|
+
}) => {
|
|
9899
9923
|
const toolAISpan = tracingContext.currentSpan?.createChildSpan({
|
|
9900
9924
|
type: "tool_call" /* TOOL_CALL */,
|
|
9901
9925
|
name: `tool: '${workflowName}'`,
|
|
9902
|
-
input:
|
|
9926
|
+
input: context,
|
|
9903
9927
|
attributes: {
|
|
9904
9928
|
toolId: workflowName,
|
|
9905
9929
|
toolType: "workflow"
|
|
@@ -9909,19 +9933,45 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
9909
9933
|
this.logger.debug(`[Agent:${this.name}] - Executing workflow as tool ${workflowName}`, {
|
|
9910
9934
|
name: workflowName,
|
|
9911
9935
|
description: workflow.description,
|
|
9912
|
-
args,
|
|
9936
|
+
args: context,
|
|
9913
9937
|
runId,
|
|
9914
9938
|
threadId,
|
|
9915
9939
|
resourceId
|
|
9916
9940
|
});
|
|
9917
9941
|
const run = workflow.createRun();
|
|
9918
|
-
|
|
9919
|
-
|
|
9920
|
-
|
|
9921
|
-
|
|
9922
|
-
|
|
9942
|
+
let result;
|
|
9943
|
+
if (methodType === "generate") {
|
|
9944
|
+
result = await run.start({
|
|
9945
|
+
inputData: context,
|
|
9946
|
+
runtimeContext,
|
|
9947
|
+
tracingContext: {
|
|
9948
|
+
currentSpan: toolAISpan
|
|
9949
|
+
}
|
|
9950
|
+
});
|
|
9951
|
+
} else if (methodType === "stream") {
|
|
9952
|
+
const streamResult = await run.stream({
|
|
9953
|
+
inputData: context,
|
|
9954
|
+
runtimeContext
|
|
9955
|
+
// TODO: is this forgottn?
|
|
9956
|
+
//currentSpan: toolAISpan,
|
|
9957
|
+
});
|
|
9958
|
+
if (writer) {
|
|
9959
|
+
await streamResult.stream.pipeTo(writer);
|
|
9960
|
+
} else {
|
|
9961
|
+
for await (const _chunk of streamResult.stream) {}
|
|
9923
9962
|
}
|
|
9924
|
-
|
|
9963
|
+
result = await streamResult.getWorkflowState();
|
|
9964
|
+
} else if (methodType === "streamVNext") {
|
|
9965
|
+
const streamResult = run.streamVNext({
|
|
9966
|
+
inputData: context,
|
|
9967
|
+
runtimeContext
|
|
9968
|
+
//format,
|
|
9969
|
+
});
|
|
9970
|
+
if (writer) {
|
|
9971
|
+
await streamResult.pipeTo(writer);
|
|
9972
|
+
}
|
|
9973
|
+
result = await streamResult.result;
|
|
9974
|
+
}
|
|
9925
9975
|
toolAISpan?.end({
|
|
9926
9976
|
output: result
|
|
9927
9977
|
});
|
|
@@ -9947,9 +9997,26 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
9947
9997
|
throw mastraError;
|
|
9948
9998
|
}
|
|
9949
9999
|
}
|
|
10000
|
+
});
|
|
10001
|
+
const options = {
|
|
10002
|
+
name: workflowName,
|
|
10003
|
+
runId,
|
|
10004
|
+
threadId,
|
|
10005
|
+
resourceId,
|
|
10006
|
+
logger: this.logger,
|
|
10007
|
+
mastra: this.#mastra,
|
|
10008
|
+
memory: await this.getMemory({
|
|
10009
|
+
runtimeContext
|
|
10010
|
+
}),
|
|
10011
|
+
agentName: this.name,
|
|
10012
|
+
runtimeContext,
|
|
10013
|
+
model: typeof this.model === "function" ? await this.getModel({
|
|
10014
|
+
runtimeContext
|
|
10015
|
+
}) : this.model,
|
|
10016
|
+
tracingContext
|
|
9950
10017
|
};
|
|
9951
|
-
|
|
9952
|
-
}
|
|
10018
|
+
convertedWorkflowTools[workflowName] = makeCoreTool(toolObj, options);
|
|
10019
|
+
}
|
|
9953
10020
|
}
|
|
9954
10021
|
return convertedWorkflowTools;
|
|
9955
10022
|
}
|
|
@@ -9961,7 +10028,9 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
9961
10028
|
runId,
|
|
9962
10029
|
runtimeContext,
|
|
9963
10030
|
tracingContext,
|
|
9964
|
-
writableStream
|
|
10031
|
+
writableStream,
|
|
10032
|
+
methodType,
|
|
10033
|
+
format
|
|
9965
10034
|
}) {
|
|
9966
10035
|
let mastraProxy = void 0;
|
|
9967
10036
|
const logger = this.logger;
|
|
@@ -10011,6 +10080,8 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
10011
10080
|
resourceId,
|
|
10012
10081
|
threadId,
|
|
10013
10082
|
runtimeContext,
|
|
10083
|
+
methodType,
|
|
10084
|
+
format,
|
|
10014
10085
|
tracingContext
|
|
10015
10086
|
});
|
|
10016
10087
|
return this.formatTools({
|
|
@@ -10096,6 +10167,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
10096
10167
|
runtimeContext,
|
|
10097
10168
|
saveQueueManager,
|
|
10098
10169
|
writableStream,
|
|
10170
|
+
methodType,
|
|
10099
10171
|
tracingContext
|
|
10100
10172
|
}) {
|
|
10101
10173
|
return {
|
|
@@ -10149,7 +10221,8 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
10149
10221
|
runId,
|
|
10150
10222
|
runtimeContext,
|
|
10151
10223
|
tracingContext: innerTracingContext,
|
|
10152
|
-
writableStream
|
|
10224
|
+
writableStream,
|
|
10225
|
+
methodType
|
|
10153
10226
|
});
|
|
10154
10227
|
const messageList = new MessageList({
|
|
10155
10228
|
threadId,
|
|
@@ -10627,7 +10700,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10627
10700
|
}
|
|
10628
10701
|
return result;
|
|
10629
10702
|
}
|
|
10630
|
-
async prepareLLMOptions(messages, options) {
|
|
10703
|
+
async prepareLLMOptions(messages, options, methodType) {
|
|
10631
10704
|
const {
|
|
10632
10705
|
context,
|
|
10633
10706
|
memoryOptions: memoryConfigFromArgs,
|
|
@@ -10704,6 +10777,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10704
10777
|
runtimeContext,
|
|
10705
10778
|
saveQueueManager,
|
|
10706
10779
|
writableStream,
|
|
10780
|
+
methodType,
|
|
10707
10781
|
tracingContext
|
|
10708
10782
|
});
|
|
10709
10783
|
let messageList;
|
|
@@ -10791,7 +10865,26 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10791
10865
|
}
|
|
10792
10866
|
};
|
|
10793
10867
|
}
|
|
10794
|
-
|
|
10868
|
+
/**
|
|
10869
|
+
* Merges telemetry wrapper with default onFinish callback when needed
|
|
10870
|
+
*/
|
|
10871
|
+
#mergeOnFinishWithTelemetry(streamOptions, defaultStreamOptions) {
|
|
10872
|
+
let finalOnFinish = streamOptions?.onFinish || defaultStreamOptions.onFinish;
|
|
10873
|
+
if (streamOptions?.onFinish && streamOptions.onFinish.__hasOriginalOnFinish === false && defaultStreamOptions.onFinish) {
|
|
10874
|
+
const telemetryWrapper = streamOptions.onFinish;
|
|
10875
|
+
const defaultCallback = defaultStreamOptions.onFinish;
|
|
10876
|
+
finalOnFinish = async data => {
|
|
10877
|
+
await telemetryWrapper(data);
|
|
10878
|
+
await defaultCallback(data);
|
|
10879
|
+
};
|
|
10880
|
+
}
|
|
10881
|
+
return finalOnFinish;
|
|
10882
|
+
}
|
|
10883
|
+
async #execute({
|
|
10884
|
+
methodType,
|
|
10885
|
+
format = "mastra",
|
|
10886
|
+
...options
|
|
10887
|
+
}) {
|
|
10795
10888
|
const runtimeContext = options.runtimeContext || new RuntimeContext();
|
|
10796
10889
|
const threadFromArgs = resolveThreadIdFromArgs({
|
|
10797
10890
|
threadId: options.threadId,
|
|
@@ -10886,6 +10979,8 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10886
10979
|
runId,
|
|
10887
10980
|
runtimeContext,
|
|
10888
10981
|
writableStream: options.writableStream,
|
|
10982
|
+
methodType,
|
|
10983
|
+
format,
|
|
10889
10984
|
tracingContext: {
|
|
10890
10985
|
currentSpan: agentAISpan
|
|
10891
10986
|
}
|
|
@@ -11105,9 +11200,10 @@ the following messages are from ${ymd}
|
|
|
11105
11200
|
const streamResult = llm.stream({
|
|
11106
11201
|
...inputData,
|
|
11107
11202
|
outputProcessors,
|
|
11203
|
+
returnScorerData: options.returnScorerData,
|
|
11108
11204
|
tracingContext
|
|
11109
11205
|
});
|
|
11110
|
-
if (
|
|
11206
|
+
if (format === "aisdk") {
|
|
11111
11207
|
return streamResult.aisdk.v5;
|
|
11112
11208
|
}
|
|
11113
11209
|
return streamResult;
|
|
@@ -11463,7 +11559,8 @@ the following messages are from ${ymd}
|
|
|
11463
11559
|
});
|
|
11464
11560
|
const mergedStreamOptions = {
|
|
11465
11561
|
...defaultStreamOptions,
|
|
11466
|
-
...streamOptions
|
|
11562
|
+
...streamOptions,
|
|
11563
|
+
onFinish: this.#mergeOnFinishWithTelemetry(streamOptions, defaultStreamOptions)
|
|
11467
11564
|
};
|
|
11468
11565
|
const llm = await this.getLLM({
|
|
11469
11566
|
runtimeContext: mergedStreamOptions.runtimeContext
|
|
@@ -11478,7 +11575,8 @@ the following messages are from ${ymd}
|
|
|
11478
11575
|
}
|
|
11479
11576
|
const result = await this.#execute({
|
|
11480
11577
|
...mergedStreamOptions,
|
|
11481
|
-
messages
|
|
11578
|
+
messages,
|
|
11579
|
+
methodType: "streamVNext"
|
|
11482
11580
|
});
|
|
11483
11581
|
if (result.status !== "success") {
|
|
11484
11582
|
if (result.status === "failed") {
|
|
@@ -11517,7 +11615,7 @@ the following messages are from ${ymd}
|
|
|
11517
11615
|
llm,
|
|
11518
11616
|
before,
|
|
11519
11617
|
after
|
|
11520
|
-
} = await this.prepareLLMOptions(messages, mergedGenerateOptions);
|
|
11618
|
+
} = await this.prepareLLMOptions(messages, mergedGenerateOptions, "generate");
|
|
11521
11619
|
if (llm.getModel().specificationVersion !== "v1") {
|
|
11522
11620
|
this.logger.error("V2 models are not supported for the current version of generate. Please use generateVNext instead.", {
|
|
11523
11621
|
modelId: llm.getModel().modelId
|
|
@@ -11761,13 +11859,14 @@ the following messages are from ${ymd}
|
|
|
11761
11859
|
});
|
|
11762
11860
|
const mergedStreamOptions = {
|
|
11763
11861
|
...defaultStreamOptions,
|
|
11764
|
-
...streamOptions
|
|
11862
|
+
...streamOptions,
|
|
11863
|
+
onFinish: this.#mergeOnFinishWithTelemetry(streamOptions, defaultStreamOptions)
|
|
11765
11864
|
};
|
|
11766
11865
|
const {
|
|
11767
11866
|
llm,
|
|
11768
11867
|
before,
|
|
11769
11868
|
after
|
|
11770
|
-
} = await this.prepareLLMOptions(messages, mergedStreamOptions);
|
|
11869
|
+
} = await this.prepareLLMOptions(messages, mergedStreamOptions, "stream");
|
|
11771
11870
|
if (llm.getModel().specificationVersion !== "v1") {
|
|
11772
11871
|
this.logger.error("V2 models are not supported for stream. Please use streamVNext instead.", {
|
|
11773
11872
|
modelId: llm.getModel().modelId
|
|
@@ -12159,21 +12258,20 @@ var MastraWorkflowStream = class extends ReadableStream$1 {
|
|
|
12159
12258
|
}
|
|
12160
12259
|
});
|
|
12161
12260
|
controller.enqueue({
|
|
12162
|
-
type: "start",
|
|
12261
|
+
type: "workflow-start",
|
|
12163
12262
|
runId: run.runId,
|
|
12164
12263
|
from: "WORKFLOW" /* WORKFLOW */,
|
|
12165
12264
|
payload: {}
|
|
12166
12265
|
});
|
|
12167
12266
|
const stream = await createStream(writer);
|
|
12168
12267
|
for await (const chunk of stream) {
|
|
12169
|
-
if (chunk.type === "step-
|
|
12170
|
-
|
|
12171
|
-
updateUsageCount(finishPayload.usage);
|
|
12268
|
+
if (chunk.type === "step-finish") {
|
|
12269
|
+
updateUsageCount(chunk.payload.usage);
|
|
12172
12270
|
}
|
|
12173
12271
|
controller.enqueue(chunk);
|
|
12174
12272
|
}
|
|
12175
12273
|
controller.enqueue({
|
|
12176
|
-
type: "finish",
|
|
12274
|
+
type: "workflow-finish",
|
|
12177
12275
|
runId: run.runId,
|
|
12178
12276
|
from: "WORKFLOW" /* WORKFLOW */,
|
|
12179
12277
|
payload: {
|
|
@@ -12589,7 +12687,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
12589
12687
|
engine: {},
|
|
12590
12688
|
abortSignal: abortController?.signal,
|
|
12591
12689
|
writer: new ToolStream({
|
|
12592
|
-
prefix: "step",
|
|
12690
|
+
prefix: "workflow-step",
|
|
12593
12691
|
callId: stepCallId,
|
|
12594
12692
|
name: "sleep",
|
|
12595
12693
|
runId
|
|
@@ -12668,7 +12766,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
12668
12766
|
engine: {},
|
|
12669
12767
|
abortSignal: abortController?.signal,
|
|
12670
12768
|
writer: new ToolStream({
|
|
12671
|
-
prefix: "step",
|
|
12769
|
+
prefix: "workflow-step",
|
|
12672
12770
|
callId: stepCallId,
|
|
12673
12771
|
name: "sleepUntil",
|
|
12674
12772
|
runId
|
|
@@ -12804,7 +12902,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
12804
12902
|
eventTimestamp: Date.now()
|
|
12805
12903
|
});
|
|
12806
12904
|
await emitter.emit("watch-v2", {
|
|
12807
|
-
type: "step-start",
|
|
12905
|
+
type: "workflow-step-start",
|
|
12808
12906
|
payload: {
|
|
12809
12907
|
id: step.id,
|
|
12810
12908
|
stepCallId,
|
|
@@ -12899,7 +12997,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
12899
12997
|
engine: {},
|
|
12900
12998
|
abortSignal: abortController?.signal,
|
|
12901
12999
|
writer: new ToolStream({
|
|
12902
|
-
prefix: "step",
|
|
13000
|
+
prefix: "workflow-step",
|
|
12903
13001
|
callId: stepCallId,
|
|
12904
13002
|
name: step.id,
|
|
12905
13003
|
runId
|
|
@@ -12990,7 +13088,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
12990
13088
|
});
|
|
12991
13089
|
if (execResults.status === "suspended") {
|
|
12992
13090
|
await emitter.emit("watch-v2", {
|
|
12993
|
-
type: "step-suspended",
|
|
13091
|
+
type: "workflow-step-suspended",
|
|
12994
13092
|
payload: {
|
|
12995
13093
|
id: step.id,
|
|
12996
13094
|
stepCallId,
|
|
@@ -12999,7 +13097,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
12999
13097
|
});
|
|
13000
13098
|
} else {
|
|
13001
13099
|
await emitter.emit("watch-v2", {
|
|
13002
|
-
type: "step-result",
|
|
13100
|
+
type: "workflow-step-result",
|
|
13003
13101
|
payload: {
|
|
13004
13102
|
id: step.id,
|
|
13005
13103
|
stepCallId,
|
|
@@ -13007,7 +13105,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13007
13105
|
}
|
|
13008
13106
|
});
|
|
13009
13107
|
await emitter.emit("watch-v2", {
|
|
13010
|
-
type: "step-finish",
|
|
13108
|
+
type: "workflow-step-finish",
|
|
13011
13109
|
payload: {
|
|
13012
13110
|
id: step.id,
|
|
13013
13111
|
stepCallId,
|
|
@@ -13236,7 +13334,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13236
13334
|
engine: {},
|
|
13237
13335
|
abortSignal: abortController?.signal,
|
|
13238
13336
|
writer: new ToolStream({
|
|
13239
|
-
prefix: "step",
|
|
13337
|
+
prefix: "workflow-step",
|
|
13240
13338
|
callId: randomUUID(),
|
|
13241
13339
|
name: "conditional",
|
|
13242
13340
|
runId
|
|
@@ -13470,7 +13568,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13470
13568
|
engine: {},
|
|
13471
13569
|
abortSignal: abortController?.signal,
|
|
13472
13570
|
writer: new ToolStream({
|
|
13473
|
-
prefix: "step",
|
|
13571
|
+
prefix: "workflow-step",
|
|
13474
13572
|
callId: randomUUID(),
|
|
13475
13573
|
name: "loop",
|
|
13476
13574
|
runId
|
|
@@ -13560,7 +13658,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13560
13658
|
eventTimestamp: Date.now()
|
|
13561
13659
|
});
|
|
13562
13660
|
await emitter.emit("watch-v2", {
|
|
13563
|
-
type: "step-start",
|
|
13661
|
+
type: "workflow-step-start",
|
|
13564
13662
|
payload: {
|
|
13565
13663
|
id: step.id,
|
|
13566
13664
|
...stepInfo,
|
|
@@ -13631,7 +13729,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13631
13729
|
});
|
|
13632
13730
|
if (execResults.status === "suspended") {
|
|
13633
13731
|
await emitter.emit("watch-v2", {
|
|
13634
|
-
type: "step-suspended",
|
|
13732
|
+
type: "workflow-step-suspended",
|
|
13635
13733
|
payload: {
|
|
13636
13734
|
id: step.id,
|
|
13637
13735
|
...execResults
|
|
@@ -13639,14 +13737,14 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13639
13737
|
});
|
|
13640
13738
|
} else {
|
|
13641
13739
|
await emitter.emit("watch-v2", {
|
|
13642
|
-
type: "step-result",
|
|
13740
|
+
type: "workflow-step-result",
|
|
13643
13741
|
payload: {
|
|
13644
13742
|
id: step.id,
|
|
13645
13743
|
...execResults
|
|
13646
13744
|
}
|
|
13647
13745
|
});
|
|
13648
13746
|
await emitter.emit("watch-v2", {
|
|
13649
|
-
type: "step-finish",
|
|
13747
|
+
type: "workflow-step-finish",
|
|
13650
13748
|
payload: {
|
|
13651
13749
|
id: step.id,
|
|
13652
13750
|
metadata: {}
|
|
@@ -13695,7 +13793,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13695
13793
|
eventTimestamp: Date.now()
|
|
13696
13794
|
});
|
|
13697
13795
|
await emitter.emit("watch-v2", {
|
|
13698
|
-
type: "step-result",
|
|
13796
|
+
type: "workflow-step-result",
|
|
13699
13797
|
payload: {
|
|
13700
13798
|
id: step.id,
|
|
13701
13799
|
status: "success",
|
|
@@ -13704,7 +13802,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13704
13802
|
}
|
|
13705
13803
|
});
|
|
13706
13804
|
await emitter.emit("watch-v2", {
|
|
13707
|
-
type: "step-finish",
|
|
13805
|
+
type: "workflow-step-finish",
|
|
13708
13806
|
payload: {
|
|
13709
13807
|
id: step.id,
|
|
13710
13808
|
metadata: {}
|
|
@@ -13977,7 +14075,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13977
14075
|
eventTimestamp: Date.now()
|
|
13978
14076
|
});
|
|
13979
14077
|
await emitter.emit("watch-v2", {
|
|
13980
|
-
type: "step-waiting",
|
|
14078
|
+
type: "workflow-step-waiting",
|
|
13981
14079
|
payload: {
|
|
13982
14080
|
id: entry.id,
|
|
13983
14081
|
payload: prevOutput,
|
|
@@ -14057,7 +14155,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14057
14155
|
eventTimestamp: Date.now()
|
|
14058
14156
|
});
|
|
14059
14157
|
await emitter.emit("watch-v2", {
|
|
14060
|
-
type: "step-result",
|
|
14158
|
+
type: "workflow-step-result",
|
|
14061
14159
|
payload: {
|
|
14062
14160
|
id: entry.id,
|
|
14063
14161
|
endedAt,
|
|
@@ -14066,7 +14164,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14066
14164
|
}
|
|
14067
14165
|
});
|
|
14068
14166
|
await emitter.emit("watch-v2", {
|
|
14069
|
-
type: "step-finish",
|
|
14167
|
+
type: "workflow-step-finish",
|
|
14070
14168
|
payload: {
|
|
14071
14169
|
id: entry.id,
|
|
14072
14170
|
metadata: {}
|
|
@@ -14100,7 +14198,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14100
14198
|
eventTimestamp: Date.now()
|
|
14101
14199
|
});
|
|
14102
14200
|
await emitter.emit("watch-v2", {
|
|
14103
|
-
type: "step-waiting",
|
|
14201
|
+
type: "workflow-step-waiting",
|
|
14104
14202
|
payload: {
|
|
14105
14203
|
id: entry.id,
|
|
14106
14204
|
payload: prevOutput,
|
|
@@ -14180,7 +14278,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14180
14278
|
eventTimestamp: Date.now()
|
|
14181
14279
|
});
|
|
14182
14280
|
await emitter.emit("watch-v2", {
|
|
14183
|
-
type: "step-result",
|
|
14281
|
+
type: "workflow-step-result",
|
|
14184
14282
|
payload: {
|
|
14185
14283
|
id: entry.id,
|
|
14186
14284
|
endedAt,
|
|
@@ -14189,7 +14287,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14189
14287
|
}
|
|
14190
14288
|
});
|
|
14191
14289
|
await emitter.emit("watch-v2", {
|
|
14192
|
-
type: "step-finish",
|
|
14290
|
+
type: "workflow-step-finish",
|
|
14193
14291
|
payload: {
|
|
14194
14292
|
id: entry.id,
|
|
14195
14293
|
metadata: {}
|
|
@@ -14224,7 +14322,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14224
14322
|
eventTimestamp: Date.now()
|
|
14225
14323
|
});
|
|
14226
14324
|
await emitter.emit("watch-v2", {
|
|
14227
|
-
type: "step-waiting",
|
|
14325
|
+
type: "workflow-step-waiting",
|
|
14228
14326
|
payload: {
|
|
14229
14327
|
id: entry.step.id,
|
|
14230
14328
|
payload: prevOutput,
|
|
@@ -14348,8 +14446,8 @@ function createStep(params) {
|
|
|
14348
14446
|
args: inputData
|
|
14349
14447
|
};
|
|
14350
14448
|
await emitter.emit("watch-v2", {
|
|
14351
|
-
type: "
|
|
14352
|
-
|
|
14449
|
+
type: "workflow-agent-call-start",
|
|
14450
|
+
payload: toolData
|
|
14353
14451
|
});
|
|
14354
14452
|
const {
|
|
14355
14453
|
fullStream
|
|
@@ -14366,29 +14464,12 @@ function createStep(params) {
|
|
|
14366
14464
|
return abort();
|
|
14367
14465
|
}
|
|
14368
14466
|
for await (const chunk of fullStream) {
|
|
14369
|
-
|
|
14370
|
-
case "text-delta":
|
|
14371
|
-
await emitter.emit("watch-v2", {
|
|
14372
|
-
type: "tool-call-delta",
|
|
14373
|
-
...toolData,
|
|
14374
|
-
argsTextDelta: chunk.textDelta
|
|
14375
|
-
});
|
|
14376
|
-
break;
|
|
14377
|
-
case "step-start":
|
|
14378
|
-
case "step-finish":
|
|
14379
|
-
case "finish":
|
|
14380
|
-
break;
|
|
14381
|
-
case "tool-call":
|
|
14382
|
-
case "tool-result":
|
|
14383
|
-
case "tool-call-streaming-start":
|
|
14384
|
-
case "tool-call-delta":
|
|
14385
|
-
case "source":
|
|
14386
|
-
case "file":
|
|
14387
|
-
default:
|
|
14388
|
-
await emitter.emit("watch-v2", chunk);
|
|
14389
|
-
break;
|
|
14390
|
-
}
|
|
14467
|
+
await emitter.emit("watch-v2", chunk);
|
|
14391
14468
|
}
|
|
14469
|
+
await emitter.emit("watch-v2", {
|
|
14470
|
+
type: "workflow-agent-call-finish",
|
|
14471
|
+
payload: toolData
|
|
14472
|
+
});
|
|
14392
14473
|
return {
|
|
14393
14474
|
text: await streamPromise.promise
|
|
14394
14475
|
};
|
|
@@ -14964,7 +15045,7 @@ var Workflow = class extends MastraBase {
|
|
|
14964
15045
|
cleanup: () => this.#runs.delete(runIdToUse)
|
|
14965
15046
|
});
|
|
14966
15047
|
this.#runs.set(runIdToUse, run);
|
|
14967
|
-
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse);
|
|
15048
|
+
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, false);
|
|
14968
15049
|
if (!workflowSnapshotInStorage) {
|
|
14969
15050
|
await this.mastra?.getStorage()?.persistWorkflowSnapshot({
|
|
14970
15051
|
workflowName: this.id,
|
|
@@ -15011,6 +15092,7 @@ var Workflow = class extends MastraBase {
|
|
|
15011
15092
|
return scorers;
|
|
15012
15093
|
}
|
|
15013
15094
|
async execute({
|
|
15095
|
+
runId,
|
|
15014
15096
|
inputData,
|
|
15015
15097
|
resumeData,
|
|
15016
15098
|
suspend,
|
|
@@ -15027,7 +15109,9 @@ var Workflow = class extends MastraBase {
|
|
|
15027
15109
|
const isResume = !!(resume?.steps && resume.steps.length > 0);
|
|
15028
15110
|
const run = isResume ? await this.createRunAsync({
|
|
15029
15111
|
runId: resume.runId
|
|
15030
|
-
}) : await this.createRunAsync(
|
|
15112
|
+
}) : await this.createRunAsync({
|
|
15113
|
+
runId
|
|
15114
|
+
});
|
|
15031
15115
|
const nestedAbortCb = () => {
|
|
15032
15116
|
abort();
|
|
15033
15117
|
};
|
|
@@ -15118,7 +15202,63 @@ var Workflow = class extends MastraBase {
|
|
|
15118
15202
|
workflowName: this.id
|
|
15119
15203
|
} : null);
|
|
15120
15204
|
}
|
|
15121
|
-
async
|
|
15205
|
+
async getWorkflowRunSteps({
|
|
15206
|
+
runId,
|
|
15207
|
+
workflowId
|
|
15208
|
+
}) {
|
|
15209
|
+
const storage = this.#mastra?.getStorage();
|
|
15210
|
+
if (!storage) {
|
|
15211
|
+
this.logger.debug("Cannot get workflow run steps. Mastra storage is not initialized");
|
|
15212
|
+
return {};
|
|
15213
|
+
}
|
|
15214
|
+
const run = await storage.getWorkflowRunById({
|
|
15215
|
+
runId,
|
|
15216
|
+
workflowName: workflowId
|
|
15217
|
+
});
|
|
15218
|
+
let snapshot = run?.snapshot;
|
|
15219
|
+
if (!snapshot) {
|
|
15220
|
+
return {};
|
|
15221
|
+
}
|
|
15222
|
+
if (typeof snapshot === "string") {
|
|
15223
|
+
try {
|
|
15224
|
+
snapshot = JSON.parse(snapshot);
|
|
15225
|
+
} catch (e) {
|
|
15226
|
+
this.logger.debug("Cannot get workflow run execution result. Snapshot is not a valid JSON string", e);
|
|
15227
|
+
return {};
|
|
15228
|
+
}
|
|
15229
|
+
}
|
|
15230
|
+
const {
|
|
15231
|
+
serializedStepGraph,
|
|
15232
|
+
context
|
|
15233
|
+
} = snapshot;
|
|
15234
|
+
const {
|
|
15235
|
+
input,
|
|
15236
|
+
...steps
|
|
15237
|
+
} = context;
|
|
15238
|
+
let finalSteps = {};
|
|
15239
|
+
for (const step of Object.keys(steps)) {
|
|
15240
|
+
const stepGraph = serializedStepGraph.find(stepGraph2 => stepGraph2?.step?.id === step);
|
|
15241
|
+
finalSteps[step] = steps[step];
|
|
15242
|
+
if (stepGraph && stepGraph?.step?.component === "WORKFLOW") {
|
|
15243
|
+
const nestedSteps = await this.getWorkflowRunSteps({
|
|
15244
|
+
runId,
|
|
15245
|
+
workflowId: step
|
|
15246
|
+
});
|
|
15247
|
+
if (nestedSteps) {
|
|
15248
|
+
const updatedNestedSteps = Object.entries(nestedSteps).reduce((acc, [key, value]) => {
|
|
15249
|
+
acc[`${step}.${key}`] = value;
|
|
15250
|
+
return acc;
|
|
15251
|
+
}, {});
|
|
15252
|
+
finalSteps = {
|
|
15253
|
+
...finalSteps,
|
|
15254
|
+
...updatedNestedSteps
|
|
15255
|
+
};
|
|
15256
|
+
}
|
|
15257
|
+
}
|
|
15258
|
+
}
|
|
15259
|
+
return finalSteps;
|
|
15260
|
+
}
|
|
15261
|
+
async getWorkflowRunExecutionResult(runId, withNestedWorkflows = true) {
|
|
15122
15262
|
const storage = this.#mastra?.getStorage();
|
|
15123
15263
|
if (!storage) {
|
|
15124
15264
|
this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
|
|
@@ -15140,12 +15280,16 @@ var Workflow = class extends MastraBase {
|
|
|
15140
15280
|
return null;
|
|
15141
15281
|
}
|
|
15142
15282
|
}
|
|
15283
|
+
const fullSteps = withNestedWorkflows ? await this.getWorkflowRunSteps({
|
|
15284
|
+
runId,
|
|
15285
|
+
workflowId: this.id
|
|
15286
|
+
}) : snapshot.context;
|
|
15143
15287
|
return {
|
|
15144
15288
|
status: snapshot.status,
|
|
15145
15289
|
result: snapshot.result,
|
|
15146
15290
|
error: snapshot.error,
|
|
15147
15291
|
payload: snapshot.context?.input,
|
|
15148
|
-
steps:
|
|
15292
|
+
steps: fullSteps
|
|
15149
15293
|
};
|
|
15150
15294
|
}
|
|
15151
15295
|
};
|
|
@@ -15274,15 +15418,43 @@ var Run = class {
|
|
|
15274
15418
|
readable,
|
|
15275
15419
|
writable
|
|
15276
15420
|
} = new TransformStream();
|
|
15421
|
+
let currentToolData = void 0;
|
|
15277
15422
|
const writer = writable.getWriter();
|
|
15278
15423
|
const unwatch = this.watch(async event => {
|
|
15424
|
+
if (event.type === "workflow-agent-call-start") {
|
|
15425
|
+
currentToolData = {
|
|
15426
|
+
name: event.payload.name,
|
|
15427
|
+
args: event.payload.args
|
|
15428
|
+
};
|
|
15429
|
+
await writer.write({
|
|
15430
|
+
...event.payload,
|
|
15431
|
+
type: "tool-call-streaming-start"
|
|
15432
|
+
});
|
|
15433
|
+
return;
|
|
15434
|
+
}
|
|
15279
15435
|
try {
|
|
15280
|
-
|
|
15436
|
+
if (event.type === "workflow-agent-call-finish") {
|
|
15437
|
+
return;
|
|
15438
|
+
} else if (!event.type.startsWith("workflow-")) {
|
|
15439
|
+
if (event.type === "text-delta") {
|
|
15440
|
+
await writer.write({
|
|
15441
|
+
type: "tool-call-delta",
|
|
15442
|
+
...(currentToolData ?? {}),
|
|
15443
|
+
argsTextDelta: event.textDelta
|
|
15444
|
+
});
|
|
15445
|
+
}
|
|
15446
|
+
return;
|
|
15447
|
+
}
|
|
15448
|
+
const e = {
|
|
15449
|
+
...event,
|
|
15450
|
+
type: event.type.replace("workflow-", "")
|
|
15451
|
+
};
|
|
15452
|
+
await writer.write(e);
|
|
15281
15453
|
} catch {}
|
|
15282
15454
|
}, "watch-v2");
|
|
15283
15455
|
this.closeStreamAction = async () => {
|
|
15284
15456
|
this.emitter.emit("watch-v2", {
|
|
15285
|
-
type: "finish",
|
|
15457
|
+
type: "workflow-finish",
|
|
15286
15458
|
payload: {
|
|
15287
15459
|
runId: this.runId
|
|
15288
15460
|
}
|
|
@@ -15297,7 +15469,7 @@ var Run = class {
|
|
|
15297
15469
|
}
|
|
15298
15470
|
};
|
|
15299
15471
|
this.emitter.emit("watch-v2", {
|
|
15300
|
-
type: "start",
|
|
15472
|
+
type: "workflow-start",
|
|
15301
15473
|
payload: {
|
|
15302
15474
|
runId: this.runId
|
|
15303
15475
|
}
|
|
@@ -15370,35 +15542,13 @@ var Run = class {
|
|
|
15370
15542
|
type,
|
|
15371
15543
|
payload
|
|
15372
15544
|
}) => {
|
|
15373
|
-
let newPayload = payload;
|
|
15374
|
-
if (type === "step-start") {
|
|
15375
|
-
const {
|
|
15376
|
-
payload: args,
|
|
15377
|
-
id,
|
|
15378
|
-
...rest
|
|
15379
|
-
} = newPayload;
|
|
15380
|
-
newPayload = {
|
|
15381
|
-
args,
|
|
15382
|
-
...rest
|
|
15383
|
-
};
|
|
15384
|
-
} else if (type === "step-result") {
|
|
15385
|
-
const {
|
|
15386
|
-
output,
|
|
15387
|
-
id,
|
|
15388
|
-
...rest
|
|
15389
|
-
} = newPayload;
|
|
15390
|
-
newPayload = {
|
|
15391
|
-
result: output,
|
|
15392
|
-
...rest
|
|
15393
|
-
};
|
|
15394
|
-
}
|
|
15395
15545
|
buffer.push({
|
|
15396
15546
|
type,
|
|
15397
15547
|
runId: this.runId,
|
|
15398
15548
|
from: "WORKFLOW" /* WORKFLOW */,
|
|
15399
15549
|
payload: {
|
|
15400
15550
|
stepName: payload.id,
|
|
15401
|
-
...
|
|
15551
|
+
...payload
|
|
15402
15552
|
}
|
|
15403
15553
|
});
|
|
15404
15554
|
await tryWrite();
|
|
@@ -15652,5 +15802,5 @@ function deepMergeWorkflowState(a, b) {
|
|
|
15652
15802
|
}
|
|
15653
15803
|
|
|
15654
15804
|
export { AISDKV5OutputStream, Agent, DefaultExecutionEngine, ExecutionEngine, LanguageDetector, LanguageDetectorInputProcessor, LegacyStep, LegacyWorkflow, MastraModelOutput, ModerationInputProcessor, ModerationProcessor, PIIDetector, PIIDetectorInputProcessor, PromptInjectionDetector, PromptInjectionDetectorInputProcessor, Run, StructuredOutputProcessor, TripWire, UnicodeNormalizer, UnicodeNormalizerInputProcessor, WhenConditionReturnValue, Workflow, agentToStep, cloneStep, cloneWorkflow, createStep, createWorkflow, getActivePathsAndStatus, getResultActivePaths, getStepResult, getSuspendedPaths, isAgent, isConditionalKey, isErrorEvent, isFinalState, isLimboState, isTransitionEvent, isVariableReference, isWorkflow, loop, mapVariable, mergeChildValue, recursivelyCheckForFinalState, resolveVariables, updateStepInHierarchy, workflowToStep };
|
|
15655
|
-
//# sourceMappingURL=chunk-
|
|
15656
|
-
//# sourceMappingURL=chunk-
|
|
15805
|
+
//# sourceMappingURL=chunk-IH5UAO56.js.map
|
|
15806
|
+
//# sourceMappingURL=chunk-IH5UAO56.js.map
|