@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,16 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkVZYIKGJ6_cjs = require('./chunk-VZYIKGJ6.cjs');
|
|
4
4
|
var chunkNFXTYMWZ_cjs = require('./chunk-NFXTYMWZ.cjs');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
5
|
+
var chunkZ637KSJF_cjs = require('./chunk-Z637KSJF.cjs');
|
|
6
|
+
var chunkMNDKBEEQ_cjs = require('./chunk-MNDKBEEQ.cjs');
|
|
7
|
+
var chunkAAJF7WLJ_cjs = require('./chunk-AAJF7WLJ.cjs');
|
|
8
8
|
var chunkTSNDVBUU_cjs = require('./chunk-TSNDVBUU.cjs');
|
|
9
9
|
var chunkLVGGMWSE_cjs = require('./chunk-LVGGMWSE.cjs');
|
|
10
10
|
var chunkGPWMM745_cjs = require('./chunk-GPWMM745.cjs');
|
|
11
11
|
var chunkS6MAHT7F_cjs = require('./chunk-S6MAHT7F.cjs');
|
|
12
12
|
var chunkABRPHTOG_cjs = require('./chunk-ABRPHTOG.cjs');
|
|
13
|
-
var
|
|
13
|
+
var chunkUFCYMOYH_cjs = require('./chunk-UFCYMOYH.cjs');
|
|
14
14
|
var chunkC73WLCY3_cjs = require('./chunk-C73WLCY3.cjs');
|
|
15
15
|
var chunkKXCUCBEI_cjs = require('./chunk-KXCUCBEI.cjs');
|
|
16
16
|
var chunkV5WKCX3G_cjs = require('./chunk-V5WKCX3G.cjs');
|
|
@@ -1173,7 +1173,7 @@ function convertMastraChunkToAISDKv5({
|
|
|
1173
1173
|
if (mode === "generate") {
|
|
1174
1174
|
return {
|
|
1175
1175
|
type: "file",
|
|
1176
|
-
file: new
|
|
1176
|
+
file: new chunkAAJF7WLJ_cjs.DefaultGeneratedFile({
|
|
1177
1177
|
data: chunk.payload.data,
|
|
1178
1178
|
mediaType: chunk.payload.mimeType
|
|
1179
1179
|
})
|
|
@@ -1181,7 +1181,7 @@ function convertMastraChunkToAISDKv5({
|
|
|
1181
1181
|
}
|
|
1182
1182
|
return {
|
|
1183
1183
|
type: "file",
|
|
1184
|
-
file: new
|
|
1184
|
+
file: new chunkAAJF7WLJ_cjs.DefaultGeneratedFileWithType({
|
|
1185
1185
|
data: chunk.payload.data,
|
|
1186
1186
|
mediaType: chunk.payload.mimeType
|
|
1187
1187
|
})
|
|
@@ -2049,6 +2049,7 @@ var MastraModelOutput = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
2049
2049
|
reasoningDetails: new DelayedPromise()
|
|
2050
2050
|
};
|
|
2051
2051
|
#streamConsumed = false;
|
|
2052
|
+
#returnScorerData = false;
|
|
2052
2053
|
/**
|
|
2053
2054
|
* Unique identifier for this execution run.
|
|
2054
2055
|
*/
|
|
@@ -2073,6 +2074,7 @@ var MastraModelOutput = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
2073
2074
|
name: "MastraModelOutput"
|
|
2074
2075
|
});
|
|
2075
2076
|
this.#options = options;
|
|
2077
|
+
this.#returnScorerData = !!options.returnScorerData;
|
|
2076
2078
|
this.runId = options.runId;
|
|
2077
2079
|
if (options.outputProcessors?.length) {
|
|
2078
2080
|
this.processorRunner = new ProcessorRunner({
|
|
@@ -2225,7 +2227,7 @@ var MastraModelOutput = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
2225
2227
|
try {
|
|
2226
2228
|
if (self.processorRunner) {
|
|
2227
2229
|
await self.processorRunner.runOutputProcessors(self.messageList);
|
|
2228
|
-
const outputText = self.messageList.get.response.aiV4.core().map(m =>
|
|
2230
|
+
const outputText = self.messageList.get.response.aiV4.core().map(m => chunkAAJF7WLJ_cjs.MessageList.coreContentToString(m.content)).join("\n");
|
|
2229
2231
|
const messages = self.messageList.get.response.v2();
|
|
2230
2232
|
const messagesWithStructuredData = messages.filter(msg => msg.content.metadata && msg.content.metadata.structuredOutput);
|
|
2231
2233
|
if (messagesWithStructuredData[0] && messagesWithStructuredData[0].content.metadata?.structuredOutput) {
|
|
@@ -2552,6 +2554,18 @@ var MastraModelOutput = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
2552
2554
|
throw error;
|
|
2553
2555
|
}
|
|
2554
2556
|
});
|
|
2557
|
+
let scoringData;
|
|
2558
|
+
if (this.#returnScorerData) {
|
|
2559
|
+
scoringData = {
|
|
2560
|
+
input: {
|
|
2561
|
+
inputMessages: this.messageList.getPersisted.input.ui(),
|
|
2562
|
+
rememberedMessages: this.messageList.getPersisted.remembered.ui(),
|
|
2563
|
+
systemMessages: this.messageList.getSystemMessages(),
|
|
2564
|
+
taggedSystemMessages: this.messageList.getPersisted.taggedSystemMessages
|
|
2565
|
+
},
|
|
2566
|
+
output: this.messageList.getPersisted.response.ui()
|
|
2567
|
+
};
|
|
2568
|
+
}
|
|
2555
2569
|
const fullOutput = {
|
|
2556
2570
|
text: await this.text,
|
|
2557
2571
|
usage: await this.usage,
|
|
@@ -2571,7 +2585,10 @@ var MastraModelOutput = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
2571
2585
|
object: await this.object,
|
|
2572
2586
|
error: this.error,
|
|
2573
2587
|
tripwire: this.#tripwire,
|
|
2574
|
-
tripwireReason: this.#tripwireReason
|
|
2588
|
+
tripwireReason: this.#tripwireReason,
|
|
2589
|
+
...(scoringData ? {
|
|
2590
|
+
scoringData
|
|
2591
|
+
} : {})
|
|
2575
2592
|
};
|
|
2576
2593
|
fullOutput.response.messages = this.messageList.get.response.aiV5.model();
|
|
2577
2594
|
return fullOutput;
|
|
@@ -3095,7 +3112,16 @@ async function processOutputStream({
|
|
|
3095
3112
|
reasoningDeltas: []
|
|
3096
3113
|
});
|
|
3097
3114
|
}
|
|
3098
|
-
if (chunk.type !== "text-delta" && chunk.type !== "tool-call" &&
|
|
3115
|
+
if (chunk.type !== "text-delta" && chunk.type !== "tool-call" &&
|
|
3116
|
+
// not 100% sure about this being the right fix.
|
|
3117
|
+
// basically for some llm providers they add response-metadata after each text-delta
|
|
3118
|
+
// we then flush the chunks by calling messageList.add (a few lines down)
|
|
3119
|
+
// this results in a bunch of weird separated text chunks on the message instead of combined chunks
|
|
3120
|
+
// easiest solution here is to just not flush for response-metadata
|
|
3121
|
+
// BUT does this cause other issues?
|
|
3122
|
+
// 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
|
|
3123
|
+
// simple solution for now is to not flush text deltas on response-metadata
|
|
3124
|
+
chunk.type !== "response-metadata" && runState.state.isStreaming) {
|
|
3099
3125
|
if (runState.state.textDeltas.length) {
|
|
3100
3126
|
const textStartPayload = chunk.payload;
|
|
3101
3127
|
const providerMetadata = textStartPayload.providerMetadata ?? runState.state.providerOptions;
|
|
@@ -3776,16 +3802,6 @@ function workflowLoopStream({
|
|
|
3776
3802
|
start: async controller => {
|
|
3777
3803
|
const writer = new WritableStream({
|
|
3778
3804
|
write: chunk => {
|
|
3779
|
-
if (llmAISpan && chunk.type === "text-delta") {
|
|
3780
|
-
llmAISpan.createEventSpan({
|
|
3781
|
-
type: "llm_chunk" /* LLM_CHUNK */,
|
|
3782
|
-
name: `llm chunk: ${chunk.type}`,
|
|
3783
|
-
output: chunk.payload.text,
|
|
3784
|
-
attributes: {
|
|
3785
|
-
chunkType: chunk.type
|
|
3786
|
-
}
|
|
3787
|
-
});
|
|
3788
|
-
}
|
|
3789
3805
|
controller.enqueue(chunk);
|
|
3790
3806
|
}
|
|
3791
3807
|
});
|
|
@@ -3931,6 +3947,7 @@ function loop({
|
|
|
3931
3947
|
_internal,
|
|
3932
3948
|
mode = "stream",
|
|
3933
3949
|
outputProcessors,
|
|
3950
|
+
returnScorerData,
|
|
3934
3951
|
llmAISpan,
|
|
3935
3952
|
...rest
|
|
3936
3953
|
}) {
|
|
@@ -4010,7 +4027,8 @@ function loop({
|
|
|
4010
4027
|
onStepFinish: rest.options?.onStepFinish,
|
|
4011
4028
|
includeRawChunks: !!includeRawChunks,
|
|
4012
4029
|
output: rest.output,
|
|
4013
|
-
outputProcessors
|
|
4030
|
+
outputProcessors,
|
|
4031
|
+
returnScorerData
|
|
4014
4032
|
}
|
|
4015
4033
|
});
|
|
4016
4034
|
}
|
|
@@ -4102,6 +4120,7 @@ var MastraLLMVNext = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
4102
4120
|
output,
|
|
4103
4121
|
options,
|
|
4104
4122
|
outputProcessors,
|
|
4123
|
+
returnScorerData,
|
|
4105
4124
|
providerOptions,
|
|
4106
4125
|
tracingContext
|
|
4107
4126
|
// ...rest
|
|
@@ -4138,7 +4157,7 @@ var MastraLLMVNext = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
4138
4157
|
}
|
|
4139
4158
|
});
|
|
4140
4159
|
try {
|
|
4141
|
-
const messageList = new
|
|
4160
|
+
const messageList = new chunkAAJF7WLJ_cjs.MessageList({
|
|
4142
4161
|
threadId,
|
|
4143
4162
|
resourceId
|
|
4144
4163
|
});
|
|
@@ -4157,6 +4176,7 @@ var MastraLLMVNext = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
4157
4176
|
},
|
|
4158
4177
|
output,
|
|
4159
4178
|
outputProcessors,
|
|
4179
|
+
returnScorerData,
|
|
4160
4180
|
llmAISpan,
|
|
4161
4181
|
options: {
|
|
4162
4182
|
...options,
|
|
@@ -8882,7 +8902,7 @@ function resolveThreadIdFromArgs(args) {
|
|
|
8882
8902
|
return void 0;
|
|
8883
8903
|
}
|
|
8884
8904
|
var _Agent_decorators, _init, _a;
|
|
8885
|
-
_Agent_decorators = [
|
|
8905
|
+
_Agent_decorators = [chunkZ637KSJF_cjs.InstrumentClass({
|
|
8886
8906
|
prefix: "agent",
|
|
8887
8907
|
excludeMethods: ["hasOwnMemory", "getMemory", "__primitive", "__registerMastra", "__registerPrimitives", "__runInputProcessors", "__runOutputProcessors", "_wrapToolsWithAITracing", "getProcessorRunner", "__setTools", "__setLogger", "__setTelemetry", "log", "getModel", "getInstructions", "getTools", "getLLM", "getWorkflows", "getDefaultGenerateOptions", "getDefaultStreamOptions", "getDescription", "getScorers", "getVoice"]
|
|
8888
8908
|
})];
|
|
@@ -8960,7 +8980,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
8960
8980
|
this.#voice?.addInstructions(config.instructions);
|
|
8961
8981
|
}
|
|
8962
8982
|
} else {
|
|
8963
|
-
this.#voice = new
|
|
8983
|
+
this.#voice = new chunkVZYIKGJ6_cjs.DefaultVoice();
|
|
8964
8984
|
}
|
|
8965
8985
|
if (config.inputProcessors) {
|
|
8966
8986
|
this.#inputProcessors = config.inputProcessors;
|
|
@@ -9110,7 +9130,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9110
9130
|
}));
|
|
9111
9131
|
return voice;
|
|
9112
9132
|
} else {
|
|
9113
|
-
return new
|
|
9133
|
+
return new chunkVZYIKGJ6_cjs.DefaultVoice();
|
|
9114
9134
|
}
|
|
9115
9135
|
}
|
|
9116
9136
|
get instructions() {
|
|
@@ -9333,7 +9353,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9333
9353
|
mastra: this.#mastra
|
|
9334
9354
|
});
|
|
9335
9355
|
} else {
|
|
9336
|
-
llm = new
|
|
9356
|
+
llm = new chunkMNDKBEEQ_cjs.MastraLLMV1({
|
|
9337
9357
|
model: resolvedModel,
|
|
9338
9358
|
mastra: this.#mastra
|
|
9339
9359
|
});
|
|
@@ -9449,7 +9469,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9449
9469
|
runtimeContext,
|
|
9450
9470
|
model
|
|
9451
9471
|
});
|
|
9452
|
-
const normMessage = new
|
|
9472
|
+
const normMessage = new chunkAAJF7WLJ_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
|
|
9453
9473
|
if (!normMessage) {
|
|
9454
9474
|
throw new Error(`Could not generate title from input ${JSON.stringify(message)}`);
|
|
9455
9475
|
}
|
|
@@ -9508,7 +9528,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9508
9528
|
async genTitle(userMessage, runtimeContext, tracingContext, model, instructions) {
|
|
9509
9529
|
try {
|
|
9510
9530
|
if (userMessage) {
|
|
9511
|
-
const normMessage = new
|
|
9531
|
+
const normMessage = new chunkAAJF7WLJ_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
|
|
9512
9532
|
if (normMessage) {
|
|
9513
9533
|
return await this.generateTitleFromUserMessage({
|
|
9514
9534
|
message: normMessage,
|
|
@@ -9534,7 +9554,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9534
9554
|
runId,
|
|
9535
9555
|
userMessages,
|
|
9536
9556
|
systemMessage,
|
|
9537
|
-
messageList = new
|
|
9557
|
+
messageList = new chunkAAJF7WLJ_cjs.MessageList({
|
|
9538
9558
|
threadId,
|
|
9539
9559
|
resourceId
|
|
9540
9560
|
}),
|
|
@@ -9589,7 +9609,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9589
9609
|
systemMessage: systemMessages,
|
|
9590
9610
|
memorySystemMessage: memorySystemMessage || void 0
|
|
9591
9611
|
});
|
|
9592
|
-
const returnList = new
|
|
9612
|
+
const returnList = new chunkAAJF7WLJ_cjs.MessageList().addSystem(systemMessages).add(processedMemoryMessages, "memory").add(newMessages, "user");
|
|
9593
9613
|
return {
|
|
9594
9614
|
threadId: thread.id,
|
|
9595
9615
|
messages: returnList.get.all.prompt()
|
|
@@ -9905,27 +9925,31 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9905
9925
|
threadId,
|
|
9906
9926
|
resourceId,
|
|
9907
9927
|
runtimeContext,
|
|
9928
|
+
methodType,
|
|
9908
9929
|
tracingContext
|
|
9909
9930
|
}) {
|
|
9910
|
-
|
|
9931
|
+
const convertedWorkflowTools = {};
|
|
9911
9932
|
const workflows = await this.getWorkflows({
|
|
9912
9933
|
runtimeContext
|
|
9913
9934
|
});
|
|
9914
9935
|
if (Object.keys(workflows).length > 0) {
|
|
9915
|
-
|
|
9916
|
-
|
|
9936
|
+
for (const [workflowName, workflow] of Object.entries(workflows)) {
|
|
9937
|
+
const toolObj = chunkABRPHTOG_cjs.createTool({
|
|
9938
|
+
id: workflowName,
|
|
9917
9939
|
description: workflow.description || `Workflow: ${workflowName}`,
|
|
9918
|
-
|
|
9919
|
-
|
|
9920
|
-
|
|
9921
|
-
},
|
|
9940
|
+
inputSchema: workflow.inputSchema,
|
|
9941
|
+
outputSchema: workflow.outputSchema,
|
|
9942
|
+
mastra: this.#mastra,
|
|
9922
9943
|
// manually wrap workflow tools with ai tracing, so that we can pass the
|
|
9923
9944
|
// current tool span onto the workflow to maintain continuity of the trace
|
|
9924
|
-
execute: async
|
|
9945
|
+
execute: async ({
|
|
9946
|
+
context,
|
|
9947
|
+
writer
|
|
9948
|
+
}) => {
|
|
9925
9949
|
const toolAISpan = tracingContext.currentSpan?.createChildSpan({
|
|
9926
9950
|
type: "tool_call" /* TOOL_CALL */,
|
|
9927
9951
|
name: `tool: '${workflowName}'`,
|
|
9928
|
-
input:
|
|
9952
|
+
input: context,
|
|
9929
9953
|
attributes: {
|
|
9930
9954
|
toolId: workflowName,
|
|
9931
9955
|
toolType: "workflow"
|
|
@@ -9935,19 +9959,45 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9935
9959
|
this.logger.debug(`[Agent:${this.name}] - Executing workflow as tool ${workflowName}`, {
|
|
9936
9960
|
name: workflowName,
|
|
9937
9961
|
description: workflow.description,
|
|
9938
|
-
args,
|
|
9962
|
+
args: context,
|
|
9939
9963
|
runId,
|
|
9940
9964
|
threadId,
|
|
9941
9965
|
resourceId
|
|
9942
9966
|
});
|
|
9943
9967
|
const run = workflow.createRun();
|
|
9944
|
-
|
|
9945
|
-
|
|
9946
|
-
|
|
9947
|
-
|
|
9948
|
-
|
|
9968
|
+
let result;
|
|
9969
|
+
if (methodType === "generate") {
|
|
9970
|
+
result = await run.start({
|
|
9971
|
+
inputData: context,
|
|
9972
|
+
runtimeContext,
|
|
9973
|
+
tracingContext: {
|
|
9974
|
+
currentSpan: toolAISpan
|
|
9975
|
+
}
|
|
9976
|
+
});
|
|
9977
|
+
} else if (methodType === "stream") {
|
|
9978
|
+
const streamResult = await run.stream({
|
|
9979
|
+
inputData: context,
|
|
9980
|
+
runtimeContext
|
|
9981
|
+
// TODO: is this forgottn?
|
|
9982
|
+
//currentSpan: toolAISpan,
|
|
9983
|
+
});
|
|
9984
|
+
if (writer) {
|
|
9985
|
+
await streamResult.stream.pipeTo(writer);
|
|
9986
|
+
} else {
|
|
9987
|
+
for await (const _chunk of streamResult.stream) {}
|
|
9949
9988
|
}
|
|
9950
|
-
|
|
9989
|
+
result = await streamResult.getWorkflowState();
|
|
9990
|
+
} else if (methodType === "streamVNext") {
|
|
9991
|
+
const streamResult = run.streamVNext({
|
|
9992
|
+
inputData: context,
|
|
9993
|
+
runtimeContext
|
|
9994
|
+
//format,
|
|
9995
|
+
});
|
|
9996
|
+
if (writer) {
|
|
9997
|
+
await streamResult.pipeTo(writer);
|
|
9998
|
+
}
|
|
9999
|
+
result = await streamResult.result;
|
|
10000
|
+
}
|
|
9951
10001
|
toolAISpan?.end({
|
|
9952
10002
|
output: result
|
|
9953
10003
|
});
|
|
@@ -9973,9 +10023,26 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9973
10023
|
throw mastraError;
|
|
9974
10024
|
}
|
|
9975
10025
|
}
|
|
10026
|
+
});
|
|
10027
|
+
const options = {
|
|
10028
|
+
name: workflowName,
|
|
10029
|
+
runId,
|
|
10030
|
+
threadId,
|
|
10031
|
+
resourceId,
|
|
10032
|
+
logger: this.logger,
|
|
10033
|
+
mastra: this.#mastra,
|
|
10034
|
+
memory: await this.getMemory({
|
|
10035
|
+
runtimeContext
|
|
10036
|
+
}),
|
|
10037
|
+
agentName: this.name,
|
|
10038
|
+
runtimeContext,
|
|
10039
|
+
model: typeof this.model === "function" ? await this.getModel({
|
|
10040
|
+
runtimeContext
|
|
10041
|
+
}) : this.model,
|
|
10042
|
+
tracingContext
|
|
9976
10043
|
};
|
|
9977
|
-
|
|
9978
|
-
}
|
|
10044
|
+
convertedWorkflowTools[workflowName] = chunkLVGGMWSE_cjs.makeCoreTool(toolObj, options);
|
|
10045
|
+
}
|
|
9979
10046
|
}
|
|
9980
10047
|
return convertedWorkflowTools;
|
|
9981
10048
|
}
|
|
@@ -9987,7 +10054,9 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9987
10054
|
runId,
|
|
9988
10055
|
runtimeContext,
|
|
9989
10056
|
tracingContext,
|
|
9990
|
-
writableStream
|
|
10057
|
+
writableStream,
|
|
10058
|
+
methodType,
|
|
10059
|
+
format
|
|
9991
10060
|
}) {
|
|
9992
10061
|
let mastraProxy = void 0;
|
|
9993
10062
|
const logger = this.logger;
|
|
@@ -10037,6 +10106,8 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
10037
10106
|
resourceId,
|
|
10038
10107
|
threadId,
|
|
10039
10108
|
runtimeContext,
|
|
10109
|
+
methodType,
|
|
10110
|
+
format,
|
|
10040
10111
|
tracingContext
|
|
10041
10112
|
});
|
|
10042
10113
|
return this.formatTools({
|
|
@@ -10122,6 +10193,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
10122
10193
|
runtimeContext,
|
|
10123
10194
|
saveQueueManager,
|
|
10124
10195
|
writableStream,
|
|
10196
|
+
methodType,
|
|
10125
10197
|
tracingContext
|
|
10126
10198
|
}) {
|
|
10127
10199
|
return {
|
|
@@ -10131,7 +10203,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
10131
10203
|
runId
|
|
10132
10204
|
});
|
|
10133
10205
|
}
|
|
10134
|
-
const agentAISpan =
|
|
10206
|
+
const agentAISpan = chunkUFCYMOYH_cjs.getOrCreateSpan({
|
|
10135
10207
|
type: "agent_run" /* AGENT_RUN */,
|
|
10136
10208
|
name: `agent run: '${this.id}'`,
|
|
10137
10209
|
input: messages,
|
|
@@ -10175,9 +10247,10 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
10175
10247
|
runId,
|
|
10176
10248
|
runtimeContext,
|
|
10177
10249
|
tracingContext: innerTracingContext,
|
|
10178
|
-
writableStream
|
|
10250
|
+
writableStream,
|
|
10251
|
+
methodType
|
|
10179
10252
|
});
|
|
10180
|
-
const messageList = new
|
|
10253
|
+
const messageList = new chunkAAJF7WLJ_cjs.MessageList({
|
|
10181
10254
|
threadId,
|
|
10182
10255
|
resourceId,
|
|
10183
10256
|
generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
|
|
@@ -10265,7 +10338,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
10265
10338
|
let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread ? this.getMemoryMessages({
|
|
10266
10339
|
resourceId,
|
|
10267
10340
|
threadId: threadObject.id,
|
|
10268
|
-
vectorMessageSearch: new
|
|
10341
|
+
vectorMessageSearch: new chunkAAJF7WLJ_cjs.MessageList().add(messages, `user`).getLatestUserContent() || "",
|
|
10269
10342
|
memoryConfig,
|
|
10270
10343
|
runtimeContext
|
|
10271
10344
|
}) : [], memory.getSystemMessage({
|
|
@@ -10288,7 +10361,7 @@ The following messages were remembered from a different conversation:
|
|
|
10288
10361
|
<remembered_from_other_conversation>
|
|
10289
10362
|
${(() => {
|
|
10290
10363
|
let result = ``;
|
|
10291
|
-
const messages2 = new
|
|
10364
|
+
const messages2 = new chunkAAJF7WLJ_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
|
|
10292
10365
|
let lastYmd = null;
|
|
10293
10366
|
for (const msg of messages2) {
|
|
10294
10367
|
const date = msg.createdAt;
|
|
@@ -10341,7 +10414,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10341
10414
|
systemMessage,
|
|
10342
10415
|
memorySystemMessage: memorySystemMessage || void 0
|
|
10343
10416
|
});
|
|
10344
|
-
const processedList = new
|
|
10417
|
+
const processedList = new chunkAAJF7WLJ_cjs.MessageList({
|
|
10345
10418
|
threadId: threadObject.id,
|
|
10346
10419
|
resourceId,
|
|
10347
10420
|
generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
|
|
@@ -10397,7 +10470,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10397
10470
|
result: resToLog,
|
|
10398
10471
|
threadId
|
|
10399
10472
|
});
|
|
10400
|
-
const messageListResponses = new
|
|
10473
|
+
const messageListResponses = new chunkAAJF7WLJ_cjs.MessageList({
|
|
10401
10474
|
threadId,
|
|
10402
10475
|
resourceId,
|
|
10403
10476
|
generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
|
|
@@ -10653,7 +10726,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10653
10726
|
}
|
|
10654
10727
|
return result;
|
|
10655
10728
|
}
|
|
10656
|
-
async prepareLLMOptions(messages, options) {
|
|
10729
|
+
async prepareLLMOptions(messages, options, methodType) {
|
|
10657
10730
|
const {
|
|
10658
10731
|
context,
|
|
10659
10732
|
memoryOptions: memoryConfigFromArgs,
|
|
@@ -10686,7 +10759,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10686
10759
|
const llm = await this.getLLM({
|
|
10687
10760
|
runtimeContext
|
|
10688
10761
|
});
|
|
10689
|
-
const activeSpan =
|
|
10762
|
+
const activeSpan = chunkZ637KSJF_cjs.Telemetry.getActiveSpan();
|
|
10690
10763
|
const baggageEntries = {};
|
|
10691
10764
|
if (threadFromArgs?.id) {
|
|
10692
10765
|
if (activeSpan) {
|
|
@@ -10705,7 +10778,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10705
10778
|
};
|
|
10706
10779
|
}
|
|
10707
10780
|
if (Object.keys(baggageEntries).length > 0) {
|
|
10708
|
-
|
|
10781
|
+
chunkZ637KSJF_cjs.Telemetry.setBaggage(baggageEntries);
|
|
10709
10782
|
}
|
|
10710
10783
|
const memory = await this.getMemory({
|
|
10711
10784
|
runtimeContext
|
|
@@ -10730,6 +10803,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10730
10803
|
runtimeContext,
|
|
10731
10804
|
saveQueueManager,
|
|
10732
10805
|
writableStream,
|
|
10806
|
+
methodType,
|
|
10733
10807
|
tracingContext
|
|
10734
10808
|
});
|
|
10735
10809
|
let messageList;
|
|
@@ -10817,7 +10891,26 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10817
10891
|
}
|
|
10818
10892
|
};
|
|
10819
10893
|
}
|
|
10820
|
-
|
|
10894
|
+
/**
|
|
10895
|
+
* Merges telemetry wrapper with default onFinish callback when needed
|
|
10896
|
+
*/
|
|
10897
|
+
#mergeOnFinishWithTelemetry(streamOptions, defaultStreamOptions) {
|
|
10898
|
+
let finalOnFinish = streamOptions?.onFinish || defaultStreamOptions.onFinish;
|
|
10899
|
+
if (streamOptions?.onFinish && streamOptions.onFinish.__hasOriginalOnFinish === false && defaultStreamOptions.onFinish) {
|
|
10900
|
+
const telemetryWrapper = streamOptions.onFinish;
|
|
10901
|
+
const defaultCallback = defaultStreamOptions.onFinish;
|
|
10902
|
+
finalOnFinish = async data => {
|
|
10903
|
+
await telemetryWrapper(data);
|
|
10904
|
+
await defaultCallback(data);
|
|
10905
|
+
};
|
|
10906
|
+
}
|
|
10907
|
+
return finalOnFinish;
|
|
10908
|
+
}
|
|
10909
|
+
async #execute({
|
|
10910
|
+
methodType,
|
|
10911
|
+
format = "mastra",
|
|
10912
|
+
...options
|
|
10913
|
+
}) {
|
|
10821
10914
|
const runtimeContext = options.runtimeContext || new chunkGPWMM745_cjs.RuntimeContext();
|
|
10822
10915
|
const threadFromArgs = resolveThreadIdFromArgs({
|
|
10823
10916
|
threadId: options.threadId,
|
|
@@ -10835,7 +10928,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10835
10928
|
const instructions = options.instructions || (await this.getInstructions({
|
|
10836
10929
|
runtimeContext
|
|
10837
10930
|
}));
|
|
10838
|
-
const agentAISpan =
|
|
10931
|
+
const agentAISpan = chunkUFCYMOYH_cjs.getOrCreateSpan({
|
|
10839
10932
|
type: "agent_run" /* AGENT_RUN */,
|
|
10840
10933
|
name: `agent run: '${this.id}'`,
|
|
10841
10934
|
input: options.messages,
|
|
@@ -10851,7 +10944,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10851
10944
|
tracingContext: options.tracingContext,
|
|
10852
10945
|
runtimeContext
|
|
10853
10946
|
});
|
|
10854
|
-
const activeSpan =
|
|
10947
|
+
const activeSpan = chunkZ637KSJF_cjs.Telemetry.getActiveSpan();
|
|
10855
10948
|
const baggageEntries = {};
|
|
10856
10949
|
if (threadFromArgs?.id) {
|
|
10857
10950
|
if (activeSpan) {
|
|
@@ -10870,7 +10963,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10870
10963
|
};
|
|
10871
10964
|
}
|
|
10872
10965
|
if (Object.keys(baggageEntries).length > 0) {
|
|
10873
|
-
|
|
10966
|
+
chunkZ637KSJF_cjs.Telemetry.setBaggage(baggageEntries);
|
|
10874
10967
|
}
|
|
10875
10968
|
const memory = await this.getMemory({
|
|
10876
10969
|
runtimeContext
|
|
@@ -10912,6 +11005,8 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10912
11005
|
runId,
|
|
10913
11006
|
runtimeContext,
|
|
10914
11007
|
writableStream: options.writableStream,
|
|
11008
|
+
methodType,
|
|
11009
|
+
format,
|
|
10915
11010
|
tracingContext: {
|
|
10916
11011
|
currentSpan: agentAISpan
|
|
10917
11012
|
}
|
|
@@ -10936,7 +11031,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10936
11031
|
tracingContext
|
|
10937
11032
|
}) => {
|
|
10938
11033
|
const thread = threadFromArgs;
|
|
10939
|
-
const messageList = new
|
|
11034
|
+
const messageList = new chunkAAJF7WLJ_cjs.MessageList({
|
|
10940
11035
|
threadId: thread?.id,
|
|
10941
11036
|
resourceId,
|
|
10942
11037
|
generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
|
|
@@ -11019,7 +11114,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
11019
11114
|
let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread ? this.getMemoryMessages({
|
|
11020
11115
|
resourceId,
|
|
11021
11116
|
threadId: threadObject.id,
|
|
11022
|
-
vectorMessageSearch: new
|
|
11117
|
+
vectorMessageSearch: new chunkAAJF7WLJ_cjs.MessageList().add(options.messages, `user`).getLatestUserContent() || "",
|
|
11023
11118
|
memoryConfig,
|
|
11024
11119
|
runtimeContext
|
|
11025
11120
|
}) : [], memory.getSystemMessage({
|
|
@@ -11042,7 +11137,7 @@ The following messages were remembered from a different conversation:
|
|
|
11042
11137
|
<remembered_from_other_conversation>
|
|
11043
11138
|
${(() => {
|
|
11044
11139
|
let result2 = ``;
|
|
11045
|
-
const messages = new
|
|
11140
|
+
const messages = new chunkAAJF7WLJ_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
|
|
11046
11141
|
let lastYmd = null;
|
|
11047
11142
|
for (const msg of messages) {
|
|
11048
11143
|
const date = msg.createdAt;
|
|
@@ -11094,7 +11189,7 @@ the following messages are from ${ymd}
|
|
|
11094
11189
|
systemMessage,
|
|
11095
11190
|
memorySystemMessage: memorySystemMessage || void 0
|
|
11096
11191
|
});
|
|
11097
|
-
const processedList = new
|
|
11192
|
+
const processedList = new chunkAAJF7WLJ_cjs.MessageList({
|
|
11098
11193
|
threadId: threadObject.id,
|
|
11099
11194
|
resourceId,
|
|
11100
11195
|
generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
|
|
@@ -11131,9 +11226,10 @@ the following messages are from ${ymd}
|
|
|
11131
11226
|
const streamResult = llm.stream({
|
|
11132
11227
|
...inputData,
|
|
11133
11228
|
outputProcessors,
|
|
11229
|
+
returnScorerData: options.returnScorerData,
|
|
11134
11230
|
tracingContext
|
|
11135
11231
|
});
|
|
11136
|
-
if (
|
|
11232
|
+
if (format === "aisdk") {
|
|
11137
11233
|
return streamResult.aisdk.v5;
|
|
11138
11234
|
}
|
|
11139
11235
|
return streamResult;
|
|
@@ -11489,7 +11585,8 @@ the following messages are from ${ymd}
|
|
|
11489
11585
|
});
|
|
11490
11586
|
const mergedStreamOptions = {
|
|
11491
11587
|
...defaultStreamOptions,
|
|
11492
|
-
...streamOptions
|
|
11588
|
+
...streamOptions,
|
|
11589
|
+
onFinish: this.#mergeOnFinishWithTelemetry(streamOptions, defaultStreamOptions)
|
|
11493
11590
|
};
|
|
11494
11591
|
const llm = await this.getLLM({
|
|
11495
11592
|
runtimeContext: mergedStreamOptions.runtimeContext
|
|
@@ -11504,7 +11601,8 @@ the following messages are from ${ymd}
|
|
|
11504
11601
|
}
|
|
11505
11602
|
const result = await this.#execute({
|
|
11506
11603
|
...mergedStreamOptions,
|
|
11507
|
-
messages
|
|
11604
|
+
messages,
|
|
11605
|
+
methodType: "streamVNext"
|
|
11508
11606
|
});
|
|
11509
11607
|
if (result.status !== "success") {
|
|
11510
11608
|
if (result.status === "failed") {
|
|
@@ -11543,7 +11641,7 @@ the following messages are from ${ymd}
|
|
|
11543
11641
|
llm,
|
|
11544
11642
|
before,
|
|
11545
11643
|
after
|
|
11546
|
-
} = await this.prepareLLMOptions(messages, mergedGenerateOptions);
|
|
11644
|
+
} = await this.prepareLLMOptions(messages, mergedGenerateOptions, "generate");
|
|
11547
11645
|
if (llm.getModel().specificationVersion !== "v1") {
|
|
11548
11646
|
this.logger.error("V2 models are not supported for the current version of generate. Please use generateVNext instead.", {
|
|
11549
11647
|
modelId: llm.getModel().modelId
|
|
@@ -11617,7 +11715,7 @@ the following messages are from ${ymd}
|
|
|
11617
11715
|
runtimeContext: mergedGenerateOptions.runtimeContext || new chunkGPWMM745_cjs.RuntimeContext(),
|
|
11618
11716
|
tracingContext,
|
|
11619
11717
|
outputProcessorOverrides: finalOutputProcessors,
|
|
11620
|
-
messageList: new
|
|
11718
|
+
messageList: new chunkAAJF7WLJ_cjs.MessageList({
|
|
11621
11719
|
threadId: llmOptions.threadId || "",
|
|
11622
11720
|
resourceId: llmOptions.resourceId || ""
|
|
11623
11721
|
}).add({
|
|
@@ -11710,7 +11808,7 @@ the following messages are from ${ymd}
|
|
|
11710
11808
|
const outputProcessorResult = await this.__runOutputProcessors({
|
|
11711
11809
|
runtimeContext: mergedGenerateOptions.runtimeContext || new chunkGPWMM745_cjs.RuntimeContext(),
|
|
11712
11810
|
tracingContext,
|
|
11713
|
-
messageList: new
|
|
11811
|
+
messageList: new chunkAAJF7WLJ_cjs.MessageList({
|
|
11714
11812
|
threadId: llmOptions.threadId || "",
|
|
11715
11813
|
resourceId: llmOptions.resourceId || ""
|
|
11716
11814
|
}).add({
|
|
@@ -11787,13 +11885,14 @@ the following messages are from ${ymd}
|
|
|
11787
11885
|
});
|
|
11788
11886
|
const mergedStreamOptions = {
|
|
11789
11887
|
...defaultStreamOptions,
|
|
11790
|
-
...streamOptions
|
|
11888
|
+
...streamOptions,
|
|
11889
|
+
onFinish: this.#mergeOnFinishWithTelemetry(streamOptions, defaultStreamOptions)
|
|
11791
11890
|
};
|
|
11792
11891
|
const {
|
|
11793
11892
|
llm,
|
|
11794
11893
|
before,
|
|
11795
11894
|
after
|
|
11796
|
-
} = await this.prepareLLMOptions(messages, mergedStreamOptions);
|
|
11895
|
+
} = await this.prepareLLMOptions(messages, mergedStreamOptions, "stream");
|
|
11797
11896
|
if (llm.getModel().specificationVersion !== "v1") {
|
|
11798
11897
|
this.logger.error("V2 models are not supported for stream. Please use streamVNext instead.", {
|
|
11799
11898
|
modelId: llm.getModel().modelId
|
|
@@ -12185,21 +12284,20 @@ var MastraWorkflowStream = class extends web.ReadableStream {
|
|
|
12185
12284
|
}
|
|
12186
12285
|
});
|
|
12187
12286
|
controller.enqueue({
|
|
12188
|
-
type: "start",
|
|
12287
|
+
type: "workflow-start",
|
|
12189
12288
|
runId: run.runId,
|
|
12190
12289
|
from: "WORKFLOW" /* WORKFLOW */,
|
|
12191
12290
|
payload: {}
|
|
12192
12291
|
});
|
|
12193
12292
|
const stream = await createStream(writer);
|
|
12194
12293
|
for await (const chunk of stream) {
|
|
12195
|
-
if (chunk.type === "step-
|
|
12196
|
-
|
|
12197
|
-
updateUsageCount(finishPayload.usage);
|
|
12294
|
+
if (chunk.type === "step-finish") {
|
|
12295
|
+
updateUsageCount(chunk.payload.usage);
|
|
12198
12296
|
}
|
|
12199
12297
|
controller.enqueue(chunk);
|
|
12200
12298
|
}
|
|
12201
12299
|
controller.enqueue({
|
|
12202
|
-
type: "finish",
|
|
12300
|
+
type: "workflow-finish",
|
|
12203
12301
|
runId: run.runId,
|
|
12204
12302
|
from: "WORKFLOW" /* WORKFLOW */,
|
|
12205
12303
|
payload: {
|
|
@@ -12374,7 +12472,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
12374
12472
|
} = retryConfig ?? {};
|
|
12375
12473
|
const steps = graph.steps;
|
|
12376
12474
|
this.runCounts.clear();
|
|
12377
|
-
const workflowAISpan =
|
|
12475
|
+
const workflowAISpan = chunkUFCYMOYH_cjs.getOrCreateSpan({
|
|
12378
12476
|
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
12379
12477
|
name: `workflow run: '${workflowId}'`,
|
|
12380
12478
|
input,
|
|
@@ -12615,7 +12713,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
12615
12713
|
engine: {},
|
|
12616
12714
|
abortSignal: abortController?.signal,
|
|
12617
12715
|
writer: new chunkS6MAHT7F_cjs.ToolStream({
|
|
12618
|
-
prefix: "step",
|
|
12716
|
+
prefix: "workflow-step",
|
|
12619
12717
|
callId: stepCallId,
|
|
12620
12718
|
name: "sleep",
|
|
12621
12719
|
runId
|
|
@@ -12694,7 +12792,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
12694
12792
|
engine: {},
|
|
12695
12793
|
abortSignal: abortController?.signal,
|
|
12696
12794
|
writer: new chunkS6MAHT7F_cjs.ToolStream({
|
|
12697
|
-
prefix: "step",
|
|
12795
|
+
prefix: "workflow-step",
|
|
12698
12796
|
callId: stepCallId,
|
|
12699
12797
|
name: "sleepUntil",
|
|
12700
12798
|
runId
|
|
@@ -12830,7 +12928,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
12830
12928
|
eventTimestamp: Date.now()
|
|
12831
12929
|
});
|
|
12832
12930
|
await emitter.emit("watch-v2", {
|
|
12833
|
-
type: "step-start",
|
|
12931
|
+
type: "workflow-step-start",
|
|
12834
12932
|
payload: {
|
|
12835
12933
|
id: step.id,
|
|
12836
12934
|
stepCallId,
|
|
@@ -12882,7 +12980,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
12882
12980
|
const result = await runStep({
|
|
12883
12981
|
runId,
|
|
12884
12982
|
workflowId,
|
|
12885
|
-
mastra: this.mastra ?
|
|
12983
|
+
mastra: this.mastra ? chunkUFCYMOYH_cjs.wrapMastra(this.mastra, innerTracingContext) : void 0,
|
|
12886
12984
|
runtimeContext,
|
|
12887
12985
|
inputData: prevOutput,
|
|
12888
12986
|
runCount: this.getOrGenerateRunCount(step.id),
|
|
@@ -12925,7 +13023,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
12925
13023
|
engine: {},
|
|
12926
13024
|
abortSignal: abortController?.signal,
|
|
12927
13025
|
writer: new chunkS6MAHT7F_cjs.ToolStream({
|
|
12928
|
-
prefix: "step",
|
|
13026
|
+
prefix: "workflow-step",
|
|
12929
13027
|
callId: stepCallId,
|
|
12930
13028
|
name: step.id,
|
|
12931
13029
|
runId
|
|
@@ -13016,7 +13114,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13016
13114
|
});
|
|
13017
13115
|
if (execResults.status === "suspended") {
|
|
13018
13116
|
await emitter.emit("watch-v2", {
|
|
13019
|
-
type: "step-suspended",
|
|
13117
|
+
type: "workflow-step-suspended",
|
|
13020
13118
|
payload: {
|
|
13021
13119
|
id: step.id,
|
|
13022
13120
|
stepCallId,
|
|
@@ -13025,7 +13123,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13025
13123
|
});
|
|
13026
13124
|
} else {
|
|
13027
13125
|
await emitter.emit("watch-v2", {
|
|
13028
|
-
type: "step-result",
|
|
13126
|
+
type: "workflow-step-result",
|
|
13029
13127
|
payload: {
|
|
13030
13128
|
id: step.id,
|
|
13031
13129
|
stepCallId,
|
|
@@ -13033,7 +13131,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13033
13131
|
}
|
|
13034
13132
|
});
|
|
13035
13133
|
await emitter.emit("watch-v2", {
|
|
13036
|
-
type: "step-finish",
|
|
13134
|
+
type: "workflow-step-finish",
|
|
13037
13135
|
payload: {
|
|
13038
13136
|
id: step.id,
|
|
13039
13137
|
stepCallId,
|
|
@@ -13262,7 +13360,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13262
13360
|
engine: {},
|
|
13263
13361
|
abortSignal: abortController?.signal,
|
|
13264
13362
|
writer: new chunkS6MAHT7F_cjs.ToolStream({
|
|
13265
|
-
prefix: "step",
|
|
13363
|
+
prefix: "workflow-step",
|
|
13266
13364
|
callId: crypto2.randomUUID(),
|
|
13267
13365
|
name: "conditional",
|
|
13268
13366
|
runId
|
|
@@ -13464,7 +13562,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13464
13562
|
const evalSpan = loopSpan?.createChildSpan({
|
|
13465
13563
|
type: "workflow_conditional_eval" /* WORKFLOW_CONDITIONAL_EVAL */,
|
|
13466
13564
|
name: `condition: ${entry.loopType}`,
|
|
13467
|
-
input:
|
|
13565
|
+
input: chunkUFCYMOYH_cjs.selectFields(result.output, ["stepResult", "output.text", "output.object", "messages"]),
|
|
13468
13566
|
attributes: {
|
|
13469
13567
|
conditionIndex: iteration
|
|
13470
13568
|
}
|
|
@@ -13496,7 +13594,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13496
13594
|
engine: {},
|
|
13497
13595
|
abortSignal: abortController?.signal,
|
|
13498
13596
|
writer: new chunkS6MAHT7F_cjs.ToolStream({
|
|
13499
|
-
prefix: "step",
|
|
13597
|
+
prefix: "workflow-step",
|
|
13500
13598
|
callId: crypto2.randomUUID(),
|
|
13501
13599
|
name: "loop",
|
|
13502
13600
|
runId
|
|
@@ -13586,7 +13684,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13586
13684
|
eventTimestamp: Date.now()
|
|
13587
13685
|
});
|
|
13588
13686
|
await emitter.emit("watch-v2", {
|
|
13589
|
-
type: "step-start",
|
|
13687
|
+
type: "workflow-step-start",
|
|
13590
13688
|
payload: {
|
|
13591
13689
|
id: step.id,
|
|
13592
13690
|
...stepInfo,
|
|
@@ -13657,7 +13755,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13657
13755
|
});
|
|
13658
13756
|
if (execResults.status === "suspended") {
|
|
13659
13757
|
await emitter.emit("watch-v2", {
|
|
13660
|
-
type: "step-suspended",
|
|
13758
|
+
type: "workflow-step-suspended",
|
|
13661
13759
|
payload: {
|
|
13662
13760
|
id: step.id,
|
|
13663
13761
|
...execResults
|
|
@@ -13665,14 +13763,14 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13665
13763
|
});
|
|
13666
13764
|
} else {
|
|
13667
13765
|
await emitter.emit("watch-v2", {
|
|
13668
|
-
type: "step-result",
|
|
13766
|
+
type: "workflow-step-result",
|
|
13669
13767
|
payload: {
|
|
13670
13768
|
id: step.id,
|
|
13671
13769
|
...execResults
|
|
13672
13770
|
}
|
|
13673
13771
|
});
|
|
13674
13772
|
await emitter.emit("watch-v2", {
|
|
13675
|
-
type: "step-finish",
|
|
13773
|
+
type: "workflow-step-finish",
|
|
13676
13774
|
payload: {
|
|
13677
13775
|
id: step.id,
|
|
13678
13776
|
metadata: {}
|
|
@@ -13721,7 +13819,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13721
13819
|
eventTimestamp: Date.now()
|
|
13722
13820
|
});
|
|
13723
13821
|
await emitter.emit("watch-v2", {
|
|
13724
|
-
type: "step-result",
|
|
13822
|
+
type: "workflow-step-result",
|
|
13725
13823
|
payload: {
|
|
13726
13824
|
id: step.id,
|
|
13727
13825
|
status: "success",
|
|
@@ -13730,7 +13828,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13730
13828
|
}
|
|
13731
13829
|
});
|
|
13732
13830
|
await emitter.emit("watch-v2", {
|
|
13733
|
-
type: "step-finish",
|
|
13831
|
+
type: "workflow-step-finish",
|
|
13734
13832
|
payload: {
|
|
13735
13833
|
id: step.id,
|
|
13736
13834
|
metadata: {}
|
|
@@ -14003,7 +14101,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14003
14101
|
eventTimestamp: Date.now()
|
|
14004
14102
|
});
|
|
14005
14103
|
await emitter.emit("watch-v2", {
|
|
14006
|
-
type: "step-waiting",
|
|
14104
|
+
type: "workflow-step-waiting",
|
|
14007
14105
|
payload: {
|
|
14008
14106
|
id: entry.id,
|
|
14009
14107
|
payload: prevOutput,
|
|
@@ -14083,7 +14181,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14083
14181
|
eventTimestamp: Date.now()
|
|
14084
14182
|
});
|
|
14085
14183
|
await emitter.emit("watch-v2", {
|
|
14086
|
-
type: "step-result",
|
|
14184
|
+
type: "workflow-step-result",
|
|
14087
14185
|
payload: {
|
|
14088
14186
|
id: entry.id,
|
|
14089
14187
|
endedAt,
|
|
@@ -14092,7 +14190,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14092
14190
|
}
|
|
14093
14191
|
});
|
|
14094
14192
|
await emitter.emit("watch-v2", {
|
|
14095
|
-
type: "step-finish",
|
|
14193
|
+
type: "workflow-step-finish",
|
|
14096
14194
|
payload: {
|
|
14097
14195
|
id: entry.id,
|
|
14098
14196
|
metadata: {}
|
|
@@ -14126,7 +14224,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14126
14224
|
eventTimestamp: Date.now()
|
|
14127
14225
|
});
|
|
14128
14226
|
await emitter.emit("watch-v2", {
|
|
14129
|
-
type: "step-waiting",
|
|
14227
|
+
type: "workflow-step-waiting",
|
|
14130
14228
|
payload: {
|
|
14131
14229
|
id: entry.id,
|
|
14132
14230
|
payload: prevOutput,
|
|
@@ -14206,7 +14304,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14206
14304
|
eventTimestamp: Date.now()
|
|
14207
14305
|
});
|
|
14208
14306
|
await emitter.emit("watch-v2", {
|
|
14209
|
-
type: "step-result",
|
|
14307
|
+
type: "workflow-step-result",
|
|
14210
14308
|
payload: {
|
|
14211
14309
|
id: entry.id,
|
|
14212
14310
|
endedAt,
|
|
@@ -14215,7 +14313,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14215
14313
|
}
|
|
14216
14314
|
});
|
|
14217
14315
|
await emitter.emit("watch-v2", {
|
|
14218
|
-
type: "step-finish",
|
|
14316
|
+
type: "workflow-step-finish",
|
|
14219
14317
|
payload: {
|
|
14220
14318
|
id: entry.id,
|
|
14221
14319
|
metadata: {}
|
|
@@ -14250,7 +14348,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14250
14348
|
eventTimestamp: Date.now()
|
|
14251
14349
|
});
|
|
14252
14350
|
await emitter.emit("watch-v2", {
|
|
14253
|
-
type: "step-waiting",
|
|
14351
|
+
type: "workflow-step-waiting",
|
|
14254
14352
|
payload: {
|
|
14255
14353
|
id: entry.step.id,
|
|
14256
14354
|
payload: prevOutput,
|
|
@@ -14374,8 +14472,8 @@ function createStep(params) {
|
|
|
14374
14472
|
args: inputData
|
|
14375
14473
|
};
|
|
14376
14474
|
await emitter.emit("watch-v2", {
|
|
14377
|
-
type: "
|
|
14378
|
-
|
|
14475
|
+
type: "workflow-agent-call-start",
|
|
14476
|
+
payload: toolData
|
|
14379
14477
|
});
|
|
14380
14478
|
const {
|
|
14381
14479
|
fullStream
|
|
@@ -14392,29 +14490,12 @@ function createStep(params) {
|
|
|
14392
14490
|
return abort();
|
|
14393
14491
|
}
|
|
14394
14492
|
for await (const chunk of fullStream) {
|
|
14395
|
-
|
|
14396
|
-
case "text-delta":
|
|
14397
|
-
await emitter.emit("watch-v2", {
|
|
14398
|
-
type: "tool-call-delta",
|
|
14399
|
-
...toolData,
|
|
14400
|
-
argsTextDelta: chunk.textDelta
|
|
14401
|
-
});
|
|
14402
|
-
break;
|
|
14403
|
-
case "step-start":
|
|
14404
|
-
case "step-finish":
|
|
14405
|
-
case "finish":
|
|
14406
|
-
break;
|
|
14407
|
-
case "tool-call":
|
|
14408
|
-
case "tool-result":
|
|
14409
|
-
case "tool-call-streaming-start":
|
|
14410
|
-
case "tool-call-delta":
|
|
14411
|
-
case "source":
|
|
14412
|
-
case "file":
|
|
14413
|
-
default:
|
|
14414
|
-
await emitter.emit("watch-v2", chunk);
|
|
14415
|
-
break;
|
|
14416
|
-
}
|
|
14493
|
+
await emitter.emit("watch-v2", chunk);
|
|
14417
14494
|
}
|
|
14495
|
+
await emitter.emit("watch-v2", {
|
|
14496
|
+
type: "workflow-agent-call-finish",
|
|
14497
|
+
payload: toolData
|
|
14498
|
+
});
|
|
14418
14499
|
return {
|
|
14419
14500
|
text: await streamPromise.promise
|
|
14420
14501
|
};
|
|
@@ -14990,7 +15071,7 @@ var Workflow = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
14990
15071
|
cleanup: () => this.#runs.delete(runIdToUse)
|
|
14991
15072
|
});
|
|
14992
15073
|
this.#runs.set(runIdToUse, run);
|
|
14993
|
-
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse);
|
|
15074
|
+
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, false);
|
|
14994
15075
|
if (!workflowSnapshotInStorage) {
|
|
14995
15076
|
await this.mastra?.getStorage()?.persistWorkflowSnapshot({
|
|
14996
15077
|
workflowName: this.id,
|
|
@@ -15037,6 +15118,7 @@ var Workflow = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
15037
15118
|
return scorers;
|
|
15038
15119
|
}
|
|
15039
15120
|
async execute({
|
|
15121
|
+
runId,
|
|
15040
15122
|
inputData,
|
|
15041
15123
|
resumeData,
|
|
15042
15124
|
suspend,
|
|
@@ -15053,7 +15135,9 @@ var Workflow = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
15053
15135
|
const isResume = !!(resume?.steps && resume.steps.length > 0);
|
|
15054
15136
|
const run = isResume ? await this.createRunAsync({
|
|
15055
15137
|
runId: resume.runId
|
|
15056
|
-
}) : await this.createRunAsync(
|
|
15138
|
+
}) : await this.createRunAsync({
|
|
15139
|
+
runId
|
|
15140
|
+
});
|
|
15057
15141
|
const nestedAbortCb = () => {
|
|
15058
15142
|
abort();
|
|
15059
15143
|
};
|
|
@@ -15144,7 +15228,63 @@ var Workflow = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
15144
15228
|
workflowName: this.id
|
|
15145
15229
|
} : null);
|
|
15146
15230
|
}
|
|
15147
|
-
async
|
|
15231
|
+
async getWorkflowRunSteps({
|
|
15232
|
+
runId,
|
|
15233
|
+
workflowId
|
|
15234
|
+
}) {
|
|
15235
|
+
const storage = this.#mastra?.getStorage();
|
|
15236
|
+
if (!storage) {
|
|
15237
|
+
this.logger.debug("Cannot get workflow run steps. Mastra storage is not initialized");
|
|
15238
|
+
return {};
|
|
15239
|
+
}
|
|
15240
|
+
const run = await storage.getWorkflowRunById({
|
|
15241
|
+
runId,
|
|
15242
|
+
workflowName: workflowId
|
|
15243
|
+
});
|
|
15244
|
+
let snapshot = run?.snapshot;
|
|
15245
|
+
if (!snapshot) {
|
|
15246
|
+
return {};
|
|
15247
|
+
}
|
|
15248
|
+
if (typeof snapshot === "string") {
|
|
15249
|
+
try {
|
|
15250
|
+
snapshot = JSON.parse(snapshot);
|
|
15251
|
+
} catch (e) {
|
|
15252
|
+
this.logger.debug("Cannot get workflow run execution result. Snapshot is not a valid JSON string", e);
|
|
15253
|
+
return {};
|
|
15254
|
+
}
|
|
15255
|
+
}
|
|
15256
|
+
const {
|
|
15257
|
+
serializedStepGraph,
|
|
15258
|
+
context
|
|
15259
|
+
} = snapshot;
|
|
15260
|
+
const {
|
|
15261
|
+
input,
|
|
15262
|
+
...steps
|
|
15263
|
+
} = context;
|
|
15264
|
+
let finalSteps = {};
|
|
15265
|
+
for (const step of Object.keys(steps)) {
|
|
15266
|
+
const stepGraph = serializedStepGraph.find(stepGraph2 => stepGraph2?.step?.id === step);
|
|
15267
|
+
finalSteps[step] = steps[step];
|
|
15268
|
+
if (stepGraph && stepGraph?.step?.component === "WORKFLOW") {
|
|
15269
|
+
const nestedSteps = await this.getWorkflowRunSteps({
|
|
15270
|
+
runId,
|
|
15271
|
+
workflowId: step
|
|
15272
|
+
});
|
|
15273
|
+
if (nestedSteps) {
|
|
15274
|
+
const updatedNestedSteps = Object.entries(nestedSteps).reduce((acc, [key, value]) => {
|
|
15275
|
+
acc[`${step}.${key}`] = value;
|
|
15276
|
+
return acc;
|
|
15277
|
+
}, {});
|
|
15278
|
+
finalSteps = {
|
|
15279
|
+
...finalSteps,
|
|
15280
|
+
...updatedNestedSteps
|
|
15281
|
+
};
|
|
15282
|
+
}
|
|
15283
|
+
}
|
|
15284
|
+
}
|
|
15285
|
+
return finalSteps;
|
|
15286
|
+
}
|
|
15287
|
+
async getWorkflowRunExecutionResult(runId, withNestedWorkflows = true) {
|
|
15148
15288
|
const storage = this.#mastra?.getStorage();
|
|
15149
15289
|
if (!storage) {
|
|
15150
15290
|
this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
|
|
@@ -15166,12 +15306,16 @@ var Workflow = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
15166
15306
|
return null;
|
|
15167
15307
|
}
|
|
15168
15308
|
}
|
|
15309
|
+
const fullSteps = withNestedWorkflows ? await this.getWorkflowRunSteps({
|
|
15310
|
+
runId,
|
|
15311
|
+
workflowId: this.id
|
|
15312
|
+
}) : snapshot.context;
|
|
15169
15313
|
return {
|
|
15170
15314
|
status: snapshot.status,
|
|
15171
15315
|
result: snapshot.result,
|
|
15172
15316
|
error: snapshot.error,
|
|
15173
15317
|
payload: snapshot.context?.input,
|
|
15174
|
-
steps:
|
|
15318
|
+
steps: fullSteps
|
|
15175
15319
|
};
|
|
15176
15320
|
}
|
|
15177
15321
|
};
|
|
@@ -15300,15 +15444,43 @@ var Run = class {
|
|
|
15300
15444
|
readable,
|
|
15301
15445
|
writable
|
|
15302
15446
|
} = new web.TransformStream();
|
|
15447
|
+
let currentToolData = void 0;
|
|
15303
15448
|
const writer = writable.getWriter();
|
|
15304
15449
|
const unwatch = this.watch(async event => {
|
|
15450
|
+
if (event.type === "workflow-agent-call-start") {
|
|
15451
|
+
currentToolData = {
|
|
15452
|
+
name: event.payload.name,
|
|
15453
|
+
args: event.payload.args
|
|
15454
|
+
};
|
|
15455
|
+
await writer.write({
|
|
15456
|
+
...event.payload,
|
|
15457
|
+
type: "tool-call-streaming-start"
|
|
15458
|
+
});
|
|
15459
|
+
return;
|
|
15460
|
+
}
|
|
15305
15461
|
try {
|
|
15306
|
-
|
|
15462
|
+
if (event.type === "workflow-agent-call-finish") {
|
|
15463
|
+
return;
|
|
15464
|
+
} else if (!event.type.startsWith("workflow-")) {
|
|
15465
|
+
if (event.type === "text-delta") {
|
|
15466
|
+
await writer.write({
|
|
15467
|
+
type: "tool-call-delta",
|
|
15468
|
+
...(currentToolData ?? {}),
|
|
15469
|
+
argsTextDelta: event.textDelta
|
|
15470
|
+
});
|
|
15471
|
+
}
|
|
15472
|
+
return;
|
|
15473
|
+
}
|
|
15474
|
+
const e = {
|
|
15475
|
+
...event,
|
|
15476
|
+
type: event.type.replace("workflow-", "")
|
|
15477
|
+
};
|
|
15478
|
+
await writer.write(e);
|
|
15307
15479
|
} catch {}
|
|
15308
15480
|
}, "watch-v2");
|
|
15309
15481
|
this.closeStreamAction = async () => {
|
|
15310
15482
|
this.emitter.emit("watch-v2", {
|
|
15311
|
-
type: "finish",
|
|
15483
|
+
type: "workflow-finish",
|
|
15312
15484
|
payload: {
|
|
15313
15485
|
runId: this.runId
|
|
15314
15486
|
}
|
|
@@ -15323,7 +15495,7 @@ var Run = class {
|
|
|
15323
15495
|
}
|
|
15324
15496
|
};
|
|
15325
15497
|
this.emitter.emit("watch-v2", {
|
|
15326
|
-
type: "start",
|
|
15498
|
+
type: "workflow-start",
|
|
15327
15499
|
payload: {
|
|
15328
15500
|
runId: this.runId
|
|
15329
15501
|
}
|
|
@@ -15396,35 +15568,13 @@ var Run = class {
|
|
|
15396
15568
|
type,
|
|
15397
15569
|
payload
|
|
15398
15570
|
}) => {
|
|
15399
|
-
let newPayload = payload;
|
|
15400
|
-
if (type === "step-start") {
|
|
15401
|
-
const {
|
|
15402
|
-
payload: args,
|
|
15403
|
-
id,
|
|
15404
|
-
...rest
|
|
15405
|
-
} = newPayload;
|
|
15406
|
-
newPayload = {
|
|
15407
|
-
args,
|
|
15408
|
-
...rest
|
|
15409
|
-
};
|
|
15410
|
-
} else if (type === "step-result") {
|
|
15411
|
-
const {
|
|
15412
|
-
output,
|
|
15413
|
-
id,
|
|
15414
|
-
...rest
|
|
15415
|
-
} = newPayload;
|
|
15416
|
-
newPayload = {
|
|
15417
|
-
result: output,
|
|
15418
|
-
...rest
|
|
15419
|
-
};
|
|
15420
|
-
}
|
|
15421
15571
|
buffer.push({
|
|
15422
15572
|
type,
|
|
15423
15573
|
runId: this.runId,
|
|
15424
15574
|
from: "WORKFLOW" /* WORKFLOW */,
|
|
15425
15575
|
payload: {
|
|
15426
15576
|
stepName: payload.id,
|
|
15427
|
-
...
|
|
15577
|
+
...payload
|
|
15428
15578
|
}
|
|
15429
15579
|
});
|
|
15430
15580
|
await tryWrite();
|
|
@@ -15722,5 +15872,5 @@ exports.recursivelyCheckForFinalState = recursivelyCheckForFinalState;
|
|
|
15722
15872
|
exports.resolveVariables = resolveVariables;
|
|
15723
15873
|
exports.updateStepInHierarchy = updateStepInHierarchy;
|
|
15724
15874
|
exports.workflowToStep = workflowToStep;
|
|
15725
|
-
//# sourceMappingURL=chunk-
|
|
15726
|
-
//# sourceMappingURL=chunk-
|
|
15875
|
+
//# sourceMappingURL=chunk-25VRTGOH.cjs.map
|
|
15876
|
+
//# sourceMappingURL=chunk-25VRTGOH.cjs.map
|