@mastra/core 0.16.1-alpha.0 → 0.16.1-alpha.2
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 +30 -0
- package/dist/agent/agent.types.d.ts +10 -2
- package/dist/agent/agent.types.d.ts.map +1 -1
- package/dist/agent/index.cjs +11 -11
- 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/index.d.ts.map +1 -1
- package/dist/agent/message-list/prompt/image-utils.d.ts +30 -0
- package/dist/agent/message-list/prompt/image-utils.d.ts.map +1 -1
- package/dist/agent/test-utils.d.ts +3 -0
- package/dist/agent/test-utils.d.ts.map +1 -1
- package/dist/agent/types.d.ts +2 -2
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/ai-tracing/context.d.ts +7 -13
- package/dist/ai-tracing/context.d.ts.map +1 -1
- package/dist/ai-tracing/index.cjs +32 -36
- package/dist/ai-tracing/index.js +1 -1
- package/dist/{chunk-WEPWZHE4.js → chunk-2NKNTPFR.js} +49 -5
- package/dist/chunk-2NKNTPFR.js.map +1 -0
- package/dist/{chunk-RT2ETR6A.js → chunk-BIJYFZVF.js} +3 -3
- package/dist/{chunk-RT2ETR6A.js.map → chunk-BIJYFZVF.js.map} +1 -1
- package/dist/{chunk-2QDX6OPE.js → chunk-BQ43NQXK.js} +3 -3
- package/dist/{chunk-2QDX6OPE.js.map → chunk-BQ43NQXK.js.map} +1 -1
- package/dist/{chunk-KT4WNDGP.cjs → chunk-D3UG2YLU.cjs} +110 -31
- package/dist/chunk-D3UG2YLU.cjs.map +1 -0
- package/dist/{chunk-H33WOKEO.js → chunk-DUABZASJ.js} +4 -4
- package/dist/{chunk-H33WOKEO.js.map → chunk-DUABZASJ.js.map} +1 -1
- package/dist/{chunk-YUJ7GETS.js → chunk-HJ2UGNRG.js} +3 -3
- package/dist/{chunk-YUJ7GETS.js.map → chunk-HJ2UGNRG.js.map} +1 -1
- package/dist/{chunk-Y6MXP3EN.cjs → chunk-IMDDMIVR.cjs} +6 -6
- package/dist/{chunk-Y6MXP3EN.cjs.map → chunk-IMDDMIVR.cjs.map} +1 -1
- package/dist/{chunk-N3HXDMF2.js → chunk-IU367D3M.js} +3 -3
- package/dist/{chunk-N3HXDMF2.js.map → chunk-IU367D3M.js.map} +1 -1
- package/dist/{chunk-6FVCJBBG.cjs → chunk-KB4IEMPV.cjs} +5 -3
- package/dist/chunk-KB4IEMPV.cjs.map +1 -0
- package/dist/{chunk-G7YM2FA2.cjs → chunk-ONGPJVTY.cjs} +7 -7
- package/dist/{chunk-G7YM2FA2.cjs.map → chunk-ONGPJVTY.cjs.map} +1 -1
- package/dist/{chunk-4FWIB47J.cjs → chunk-PHS6DKEV.cjs} +4 -4
- package/dist/{chunk-4FWIB47J.cjs.map → chunk-PHS6DKEV.cjs.map} +1 -1
- package/dist/{chunk-LGJCH6XF.cjs → chunk-R467FTA7.cjs} +12 -12
- package/dist/{chunk-LGJCH6XF.cjs.map → chunk-R467FTA7.cjs.map} +1 -1
- package/dist/{chunk-OE3SL5VG.cjs → chunk-SJO2HEVU.cjs} +6 -6
- package/dist/{chunk-OE3SL5VG.cjs.map → chunk-SJO2HEVU.cjs.map} +1 -1
- package/dist/{chunk-ULA3AGAI.js → chunk-TDLB5JKT.js} +5 -3
- package/dist/chunk-TDLB5JKT.js.map +1 -0
- package/dist/{chunk-WW62UQPE.js → chunk-TOCMMZ2Y.js} +5 -5
- package/dist/{chunk-WW62UQPE.js.map → chunk-TOCMMZ2Y.js.map} +1 -1
- package/dist/{chunk-UFCYMOYH.cjs → chunk-UGCG7DI3.cjs} +49 -6
- package/dist/chunk-UGCG7DI3.cjs.map +1 -0
- package/dist/{chunk-IUF2ESZH.cjs → chunk-WJXZMK43.cjs} +158 -109
- package/dist/chunk-WJXZMK43.cjs.map +1 -0
- package/dist/{chunk-VMV5VND5.cjs → chunk-XS5PJKTF.cjs} +7 -7
- package/dist/{chunk-VMV5VND5.cjs.map → chunk-XS5PJKTF.cjs.map} +1 -1
- package/dist/{chunk-4BQBSBQP.js → chunk-YI3AIJJL.js} +109 -30
- package/dist/chunk-YI3AIJJL.js.map +1 -0
- package/dist/{chunk-MW4CYUSP.js → chunk-ZGSS7RCP.js} +123 -74
- package/dist/chunk-ZGSS7RCP.js.map +1 -0
- package/dist/index.cjs +38 -38
- package/dist/index.js +7 -7
- 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 +4 -2
- 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/test-utils/fullStream.d.ts.map +1 -1
- package/dist/loop/test-utils/generateText.d.ts.map +1 -1
- package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
- package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
- package/dist/loop/test-utils/tools.d.ts.map +1 -1
- package/dist/loop/test-utils/utils.d.ts +1 -0
- package/dist/loop/test-utils/utils.d.ts.map +1 -1
- package/dist/loop/types.d.ts +0 -1
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflow/outer-llm-step.d.ts.map +1 -1
- package/dist/loop/workflow/schema.d.ts +12 -0
- package/dist/loop/workflow/schema.d.ts.map +1 -1
- package/dist/loop/workflow/tool-call-step.d.ts +12 -0
- package/dist/loop/workflow/tool-call-step.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 +14 -14
- package/dist/network/vNext/index.js +2 -2
- package/dist/processors/index.cjs +8 -8
- package/dist/processors/index.js +2 -2
- package/dist/processors/processors/structured-output.d.ts +2 -1
- package/dist/processors/processors/structured-output.d.ts.map +1 -1
- package/dist/relevance/index.cjs +4 -4
- package/dist/relevance/index.js +1 -1
- package/dist/scores/index.cjs +8 -8
- package/dist/scores/index.js +1 -1
- package/dist/storage/domains/observability/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +5 -3
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.js +3 -1
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/types.d.ts +2 -0
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
- 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/test-utils/llm-mock.cjs +2 -2
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/utils.cjs +17 -17
- package/dist/utils.js +1 -1
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +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 +3 -0
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +2 -1
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-4BQBSBQP.js.map +0 -1
- package/dist/chunk-6FVCJBBG.cjs.map +0 -1
- package/dist/chunk-IUF2ESZH.cjs.map +0 -1
- package/dist/chunk-KT4WNDGP.cjs.map +0 -1
- package/dist/chunk-MW4CYUSP.js.map +0 -1
- package/dist/chunk-UFCYMOYH.cjs.map +0 -1
- package/dist/chunk-ULA3AGAI.js.map +0 -1
- package/dist/chunk-WEPWZHE4.js.map +0 -1
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
var chunkAHJY7RHO_cjs = require('./chunk-AHJY7RHO.cjs');
|
|
4
4
|
var chunkABJOUEVA_cjs = require('./chunk-ABJOUEVA.cjs');
|
|
5
5
|
var chunkBHB4PDNV_cjs = require('./chunk-BHB4PDNV.cjs');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var chunkSJO2HEVU_cjs = require('./chunk-SJO2HEVU.cjs');
|
|
7
|
+
var chunkD3UG2YLU_cjs = require('./chunk-D3UG2YLU.cjs');
|
|
8
8
|
var chunkTSNDVBUU_cjs = require('./chunk-TSNDVBUU.cjs');
|
|
9
|
-
var
|
|
9
|
+
var chunkKB4IEMPV_cjs = require('./chunk-KB4IEMPV.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 chunkUGCG7DI3_cjs = require('./chunk-UGCG7DI3.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 chunkD3UG2YLU_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 chunkD3UG2YLU_cjs.DefaultGeneratedFileWithType({
|
|
1185
1185
|
data: chunk.payload.data,
|
|
1186
1186
|
mediaType: chunk.payload.mimeType
|
|
1187
1187
|
})
|
|
@@ -2239,7 +2239,8 @@ var MastraModelOutput = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
2239
2239
|
} = chunk.payload.metadata;
|
|
2240
2240
|
response = {
|
|
2241
2241
|
...otherMetadata,
|
|
2242
|
-
messages: messageList.get.response.aiV5.model()
|
|
2242
|
+
messages: messageList.get.response.aiV5.model(),
|
|
2243
|
+
uiMessages: messageList.get.response.aiV5.ui()
|
|
2243
2244
|
};
|
|
2244
2245
|
}
|
|
2245
2246
|
this.populateUsageCount(chunk.payload.output.usage);
|
|
@@ -2247,7 +2248,7 @@ var MastraModelOutput = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
2247
2248
|
try {
|
|
2248
2249
|
if (self.processorRunner) {
|
|
2249
2250
|
self.messageList = await self.processorRunner.runOutputProcessors(self.messageList);
|
|
2250
|
-
const outputText = self.messageList.get.response.aiV4.core().map(m =>
|
|
2251
|
+
const outputText = self.messageList.get.response.aiV4.core().map(m => chunkD3UG2YLU_cjs.MessageList.coreContentToString(m.content)).join("\n");
|
|
2251
2252
|
const messages = self.messageList.get.response.v2();
|
|
2252
2253
|
const messagesWithStructuredData = messages.filter(msg => msg.content.metadata && msg.content.metadata.structuredOutput);
|
|
2253
2254
|
if (messagesWithStructuredData[0] && messagesWithStructuredData[0].content.metadata?.structuredOutput) {
|
|
@@ -2266,7 +2267,8 @@ var MastraModelOutput = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
2266
2267
|
} = chunk.payload.metadata;
|
|
2267
2268
|
response = {
|
|
2268
2269
|
...otherMetadata,
|
|
2269
|
-
messages: messageList.get.response.aiV5.model()
|
|
2270
|
+
messages: messageList.get.response.aiV5.model(),
|
|
2271
|
+
uiMessages: messageList.get.response.aiV5.ui()
|
|
2270
2272
|
};
|
|
2271
2273
|
}
|
|
2272
2274
|
} else {
|
|
@@ -2621,7 +2623,6 @@ var MastraModelOutput = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
2621
2623
|
scoringData
|
|
2622
2624
|
} : {})
|
|
2623
2625
|
};
|
|
2624
|
-
fullOutput.response.messages = this.messageList.get.response.aiV5.model();
|
|
2625
2626
|
return fullOutput;
|
|
2626
2627
|
}
|
|
2627
2628
|
/**
|
|
@@ -3115,7 +3116,9 @@ var toolCallInputSchema = z__default.default.object({
|
|
|
3115
3116
|
toolCallId: z__default.default.string(),
|
|
3116
3117
|
toolName: z__default.default.string(),
|
|
3117
3118
|
args: z__default.default.any(),
|
|
3118
|
-
providerMetadata: z__default.default.any()
|
|
3119
|
+
providerMetadata: z__default.default.any(),
|
|
3120
|
+
providerExecuted: z__default.default.boolean().optional(),
|
|
3121
|
+
output: z__default.default.any().optional()
|
|
3119
3122
|
});
|
|
3120
3123
|
var toolCallOutputSchema = toolCallInputSchema.extend({
|
|
3121
3124
|
result: z__default.default.any(),
|
|
@@ -3636,6 +3639,32 @@ function createToolCallStep({
|
|
|
3636
3639
|
execute: async ({
|
|
3637
3640
|
inputData
|
|
3638
3641
|
}) => {
|
|
3642
|
+
if (inputData.providerExecuted) {
|
|
3643
|
+
const tracer2 = getTracer({
|
|
3644
|
+
isEnabled: telemetry_settings?.isEnabled,
|
|
3645
|
+
tracer: telemetry_settings?.tracer
|
|
3646
|
+
});
|
|
3647
|
+
const span2 = tracer2.startSpan("mastra.stream.toolCall").setAttributes({
|
|
3648
|
+
...assembleOperationName({
|
|
3649
|
+
operationId: "mastra.stream.toolCall",
|
|
3650
|
+
telemetry: telemetry_settings
|
|
3651
|
+
}),
|
|
3652
|
+
"stream.toolCall.toolName": inputData.toolName,
|
|
3653
|
+
"stream.toolCall.toolCallId": inputData.toolCallId,
|
|
3654
|
+
"stream.toolCall.args": JSON.stringify(inputData.args),
|
|
3655
|
+
"stream.toolCall.providerExecuted": true
|
|
3656
|
+
});
|
|
3657
|
+
if (inputData.output) {
|
|
3658
|
+
span2.setAttributes({
|
|
3659
|
+
"stream.toolCall.result": JSON.stringify(inputData.output)
|
|
3660
|
+
});
|
|
3661
|
+
}
|
|
3662
|
+
span2.end();
|
|
3663
|
+
return {
|
|
3664
|
+
...inputData,
|
|
3665
|
+
result: inputData.output
|
|
3666
|
+
};
|
|
3667
|
+
}
|
|
3639
3668
|
const tool = tools?.[inputData.toolName] || Object.values(tools || {})?.find(tool2 => `id` in tool2 && tool2.id === inputData.toolName);
|
|
3640
3669
|
if (!tool) {
|
|
3641
3670
|
throw new Error(`Tool ${inputData.toolName} not found`);
|
|
@@ -3777,7 +3806,8 @@ function createOuterLLMWorkflow({
|
|
|
3777
3806
|
toolCallId: toolCall.toolCallId,
|
|
3778
3807
|
toolName: toolCall.toolName,
|
|
3779
3808
|
result: toolCall.result,
|
|
3780
|
-
providerMetadata: toolCall.providerMetadata
|
|
3809
|
+
providerMetadata: toolCall.providerMetadata,
|
|
3810
|
+
providerExecuted: toolCall.providerExecuted
|
|
3781
3811
|
}
|
|
3782
3812
|
};
|
|
3783
3813
|
rest.controller.enqueue(chunk);
|
|
@@ -4156,7 +4186,6 @@ var MastraLLMVNext = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
4156
4186
|
}];
|
|
4157
4187
|
}
|
|
4158
4188
|
stream({
|
|
4159
|
-
messages,
|
|
4160
4189
|
stopWhen = aiV5.stepCountIs(5),
|
|
4161
4190
|
maxSteps,
|
|
4162
4191
|
tools = {},
|
|
@@ -4171,7 +4200,9 @@ var MastraLLMVNext = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
4171
4200
|
outputProcessors,
|
|
4172
4201
|
returnScorerData,
|
|
4173
4202
|
providerOptions,
|
|
4174
|
-
tracingContext
|
|
4203
|
+
tracingContext,
|
|
4204
|
+
messageList,
|
|
4205
|
+
_internal
|
|
4175
4206
|
// ...rest
|
|
4176
4207
|
}) {
|
|
4177
4208
|
let stopWhenToUse;
|
|
@@ -4180,6 +4211,7 @@ var MastraLLMVNext = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
4180
4211
|
} else {
|
|
4181
4212
|
stopWhenToUse = stopWhen;
|
|
4182
4213
|
}
|
|
4214
|
+
const messages = messageList.get.all.aiV5.model();
|
|
4183
4215
|
const model = this.#model;
|
|
4184
4216
|
this.logger.debug(`[LLM] - Streaming text`, {
|
|
4185
4217
|
runId,
|
|
@@ -4203,11 +4235,6 @@ var MastraLLMVNext = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
4203
4235
|
}
|
|
4204
4236
|
});
|
|
4205
4237
|
try {
|
|
4206
|
-
const messageList = new chunkKT4WNDGP_cjs.MessageList({
|
|
4207
|
-
threadId,
|
|
4208
|
-
resourceId
|
|
4209
|
-
});
|
|
4210
|
-
messageList.add(messages, "input");
|
|
4211
4238
|
const loopOptions = {
|
|
4212
4239
|
messageList,
|
|
4213
4240
|
model: this.#model,
|
|
@@ -4220,6 +4247,7 @@ var MastraLLMVNext = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
4220
4247
|
...this.experimental_telemetry,
|
|
4221
4248
|
...telemetry_settings
|
|
4222
4249
|
},
|
|
4250
|
+
_internal,
|
|
4223
4251
|
output,
|
|
4224
4252
|
outputProcessors,
|
|
4225
4253
|
returnScorerData,
|
|
@@ -4264,7 +4292,7 @@ var MastraLLMVNext = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
4264
4292
|
this.logger.warn("Rate limit approaching, waiting 10 seconds", {
|
|
4265
4293
|
runId
|
|
4266
4294
|
});
|
|
4267
|
-
await
|
|
4295
|
+
await chunkKB4IEMPV_cjs.delay(10 * 1e3);
|
|
4268
4296
|
}
|
|
4269
4297
|
},
|
|
4270
4298
|
onFinish: async props => {
|
|
@@ -4339,14 +4367,18 @@ var StructuredOutputProcessor = class {
|
|
|
4339
4367
|
structuringAgent;
|
|
4340
4368
|
errorStrategy;
|
|
4341
4369
|
fallbackValue;
|
|
4342
|
-
constructor(options) {
|
|
4370
|
+
constructor(options, fallbackModel) {
|
|
4343
4371
|
this.schema = options.schema;
|
|
4344
4372
|
this.errorStrategy = options.errorStrategy ?? "strict";
|
|
4345
4373
|
this.fallbackValue = options.fallbackValue;
|
|
4374
|
+
const modelToUse = options.model || fallbackModel;
|
|
4375
|
+
if (!modelToUse) {
|
|
4376
|
+
throw new Error("StructuredOutputProcessor requires a model to be provided either in options or as fallback");
|
|
4377
|
+
}
|
|
4346
4378
|
this.structuringAgent = new exports.Agent({
|
|
4347
4379
|
name: "structured-output-structurer",
|
|
4348
4380
|
instructions: options.instructions || this.generateInstructions(),
|
|
4349
|
-
model:
|
|
4381
|
+
model: modelToUse
|
|
4350
4382
|
});
|
|
4351
4383
|
}
|
|
4352
4384
|
async processOutputResult(args) {
|
|
@@ -5159,7 +5191,7 @@ var Machine = class extends EventEmitter__default.default {
|
|
|
5159
5191
|
const logger = this.logger;
|
|
5160
5192
|
let mastraProxy = void 0;
|
|
5161
5193
|
if (this.#mastra) {
|
|
5162
|
-
mastraProxy =
|
|
5194
|
+
mastraProxy = chunkKB4IEMPV_cjs.createMastraProxy({
|
|
5163
5195
|
mastra: this.#mastra,
|
|
5164
5196
|
logger
|
|
5165
5197
|
});
|
|
@@ -9328,13 +9360,13 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9328
9360
|
this.logger.error(mastraError.toString());
|
|
9329
9361
|
throw mastraError;
|
|
9330
9362
|
}
|
|
9331
|
-
return
|
|
9363
|
+
return chunkKB4IEMPV_cjs.ensureToolProperties(this.#tools);
|
|
9332
9364
|
}
|
|
9333
9365
|
getTools({
|
|
9334
9366
|
runtimeContext = new chunkGPWMM745_cjs.RuntimeContext()
|
|
9335
9367
|
} = {}) {
|
|
9336
9368
|
if (typeof this.#tools !== "function") {
|
|
9337
|
-
return
|
|
9369
|
+
return chunkKB4IEMPV_cjs.ensureToolProperties(this.#tools);
|
|
9338
9370
|
}
|
|
9339
9371
|
const result = this.#tools({
|
|
9340
9372
|
runtimeContext,
|
|
@@ -9355,7 +9387,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9355
9387
|
this.logger.error(mastraError.toString());
|
|
9356
9388
|
throw mastraError;
|
|
9357
9389
|
}
|
|
9358
|
-
return
|
|
9390
|
+
return chunkKB4IEMPV_cjs.ensureToolProperties(tools);
|
|
9359
9391
|
});
|
|
9360
9392
|
}
|
|
9361
9393
|
get llm() {
|
|
@@ -9399,7 +9431,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9399
9431
|
mastra: this.#mastra
|
|
9400
9432
|
});
|
|
9401
9433
|
} else {
|
|
9402
|
-
llm = new
|
|
9434
|
+
llm = new chunkSJO2HEVU_cjs.MastraLLMV1({
|
|
9403
9435
|
model: resolvedModel,
|
|
9404
9436
|
mastra: this.#mastra
|
|
9405
9437
|
});
|
|
@@ -9515,7 +9547,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9515
9547
|
runtimeContext,
|
|
9516
9548
|
model
|
|
9517
9549
|
});
|
|
9518
|
-
const normMessage = new
|
|
9550
|
+
const normMessage = new chunkD3UG2YLU_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
|
|
9519
9551
|
if (!normMessage) {
|
|
9520
9552
|
throw new Error(`Could not generate title from input ${JSON.stringify(message)}`);
|
|
9521
9553
|
}
|
|
@@ -9538,16 +9570,17 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9538
9570
|
const systemInstructions = await this.resolveTitleInstructions(runtimeContext, instructions);
|
|
9539
9571
|
let text = "";
|
|
9540
9572
|
if (llm.getModel().specificationVersion === "v2") {
|
|
9573
|
+
const messageList = new chunkD3UG2YLU_cjs.MessageList().add([{
|
|
9574
|
+
role: "system",
|
|
9575
|
+
content: systemInstructions
|
|
9576
|
+
}], "system").add([{
|
|
9577
|
+
role: "user",
|
|
9578
|
+
content: JSON.stringify(partsToGen)
|
|
9579
|
+
}], "input");
|
|
9541
9580
|
const result = llm.stream({
|
|
9542
9581
|
runtimeContext,
|
|
9543
9582
|
tracingContext,
|
|
9544
|
-
|
|
9545
|
-
role: "system",
|
|
9546
|
-
content: systemInstructions
|
|
9547
|
-
}, {
|
|
9548
|
-
role: "user",
|
|
9549
|
-
content: JSON.stringify(partsToGen)
|
|
9550
|
-
}]
|
|
9583
|
+
messageList
|
|
9551
9584
|
});
|
|
9552
9585
|
text = await result.text;
|
|
9553
9586
|
} else {
|
|
@@ -9574,7 +9607,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9574
9607
|
async genTitle(userMessage, runtimeContext, tracingContext, model, instructions) {
|
|
9575
9608
|
try {
|
|
9576
9609
|
if (userMessage) {
|
|
9577
|
-
const normMessage = new
|
|
9610
|
+
const normMessage = new chunkD3UG2YLU_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
|
|
9578
9611
|
if (normMessage) {
|
|
9579
9612
|
return await this.generateTitleFromUserMessage({
|
|
9580
9613
|
message: normMessage,
|
|
@@ -9600,7 +9633,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9600
9633
|
runId,
|
|
9601
9634
|
userMessages,
|
|
9602
9635
|
systemMessage,
|
|
9603
|
-
messageList = new
|
|
9636
|
+
messageList = new chunkD3UG2YLU_cjs.MessageList({
|
|
9604
9637
|
threadId,
|
|
9605
9638
|
resourceId
|
|
9606
9639
|
}),
|
|
@@ -9655,7 +9688,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9655
9688
|
systemMessage: systemMessages,
|
|
9656
9689
|
memorySystemMessage: memorySystemMessage || void 0
|
|
9657
9690
|
});
|
|
9658
|
-
const returnList = new
|
|
9691
|
+
const returnList = new chunkD3UG2YLU_cjs.MessageList().addSystem(systemMessages).add(processedMemoryMessages, "memory").add(newMessages, "user");
|
|
9659
9692
|
return {
|
|
9660
9693
|
threadId: thread.id,
|
|
9661
9694
|
messages: returnList.get.all.prompt()
|
|
@@ -9700,7 +9733,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9700
9733
|
runtimeContext
|
|
9701
9734
|
}) : this.model
|
|
9702
9735
|
};
|
|
9703
|
-
const convertedToCoreTool =
|
|
9736
|
+
const convertedToCoreTool = chunkKB4IEMPV_cjs.makeCoreTool(toolObj, options);
|
|
9704
9737
|
convertedMemoryTools[toolName] = convertedToCoreTool;
|
|
9705
9738
|
}
|
|
9706
9739
|
}
|
|
@@ -9871,7 +9904,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9871
9904
|
}) : this.model,
|
|
9872
9905
|
writableStream
|
|
9873
9906
|
};
|
|
9874
|
-
return [k,
|
|
9907
|
+
return [k, chunkKB4IEMPV_cjs.makeCoreTool(tool, options)];
|
|
9875
9908
|
}));
|
|
9876
9909
|
const assignedToolEntriesConverted = Object.fromEntries(assignedCoreToolEntries.filter(entry => Boolean(entry)));
|
|
9877
9910
|
toolsForRequest = {
|
|
@@ -9915,7 +9948,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9915
9948
|
runtimeContext
|
|
9916
9949
|
}) : this.model
|
|
9917
9950
|
};
|
|
9918
|
-
const convertedToCoreTool =
|
|
9951
|
+
const convertedToCoreTool = chunkKB4IEMPV_cjs.makeCoreTool(toolObj, options, "toolset");
|
|
9919
9952
|
toolsForRequest[toolName] = convertedToCoreTool;
|
|
9920
9953
|
}
|
|
9921
9954
|
}
|
|
@@ -9960,7 +9993,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
9960
9993
|
runtimeContext
|
|
9961
9994
|
}) : this.model
|
|
9962
9995
|
};
|
|
9963
|
-
const convertedToCoreTool =
|
|
9996
|
+
const convertedToCoreTool = chunkKB4IEMPV_cjs.makeCoreTool(rest, options, "client-tool");
|
|
9964
9997
|
toolsForRequest[toolName] = convertedToCoreTool;
|
|
9965
9998
|
}
|
|
9966
9999
|
}
|
|
@@ -10003,7 +10036,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
10003
10036
|
threadId,
|
|
10004
10037
|
resourceId
|
|
10005
10038
|
});
|
|
10006
|
-
const run = workflow.
|
|
10039
|
+
const run = await workflow.createRunAsync();
|
|
10007
10040
|
let result;
|
|
10008
10041
|
if (methodType === "generate") {
|
|
10009
10042
|
result = await run.start({
|
|
@@ -10027,6 +10060,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
10027
10060
|
const streamResult = run.streamVNext({
|
|
10028
10061
|
inputData: context,
|
|
10029
10062
|
runtimeContext,
|
|
10063
|
+
tracingContext: innerTracingContext,
|
|
10030
10064
|
format
|
|
10031
10065
|
});
|
|
10032
10066
|
if (writer) {
|
|
@@ -10074,7 +10108,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
10074
10108
|
}) : this.model,
|
|
10075
10109
|
tracingContext
|
|
10076
10110
|
};
|
|
10077
|
-
convertedWorkflowTools[workflowName] =
|
|
10111
|
+
convertedWorkflowTools[workflowName] = chunkKB4IEMPV_cjs.makeCoreTool(toolObj, options);
|
|
10078
10112
|
}
|
|
10079
10113
|
}
|
|
10080
10114
|
return convertedWorkflowTools;
|
|
@@ -10094,7 +10128,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
10094
10128
|
let mastraProxy = void 0;
|
|
10095
10129
|
const logger = this.logger;
|
|
10096
10130
|
if (this.#mastra) {
|
|
10097
|
-
mastraProxy =
|
|
10131
|
+
mastraProxy = chunkKB4IEMPV_cjs.createMastraProxy({
|
|
10098
10132
|
mastra: this.#mastra,
|
|
10099
10133
|
logger
|
|
10100
10134
|
});
|
|
@@ -10236,7 +10270,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
10236
10270
|
runId
|
|
10237
10271
|
});
|
|
10238
10272
|
}
|
|
10239
|
-
const agentAISpan =
|
|
10273
|
+
const agentAISpan = chunkUGCG7DI3_cjs.getOrCreateSpan({
|
|
10240
10274
|
type: "agent_run" /* AGENT_RUN */,
|
|
10241
10275
|
name: `agent run: '${this.id}'`,
|
|
10242
10276
|
input: messages,
|
|
@@ -10283,7 +10317,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
10283
10317
|
writableStream,
|
|
10284
10318
|
methodType
|
|
10285
10319
|
});
|
|
10286
|
-
const messageList = new
|
|
10320
|
+
const messageList = new chunkD3UG2YLU_cjs.MessageList({
|
|
10287
10321
|
threadId,
|
|
10288
10322
|
resourceId,
|
|
10289
10323
|
generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
|
|
@@ -10373,7 +10407,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
|
|
|
10373
10407
|
let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread || hasResourceScopeSemanticRecall ? this.getMemoryMessages({
|
|
10374
10408
|
resourceId,
|
|
10375
10409
|
threadId: threadObject.id,
|
|
10376
|
-
vectorMessageSearch: new
|
|
10410
|
+
vectorMessageSearch: new chunkD3UG2YLU_cjs.MessageList().add(messages, `user`).getLatestUserContent() || "",
|
|
10377
10411
|
memoryConfig,
|
|
10378
10412
|
runtimeContext
|
|
10379
10413
|
}) : [], memory.getSystemMessage({
|
|
@@ -10396,7 +10430,7 @@ The following messages were remembered from a different conversation:
|
|
|
10396
10430
|
<remembered_from_other_conversation>
|
|
10397
10431
|
${(() => {
|
|
10398
10432
|
let result = ``;
|
|
10399
|
-
const messages2 = new
|
|
10433
|
+
const messages2 = new chunkD3UG2YLU_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
|
|
10400
10434
|
let lastYmd = null;
|
|
10401
10435
|
for (const msg of messages2) {
|
|
10402
10436
|
const date = msg.createdAt;
|
|
@@ -10449,7 +10483,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10449
10483
|
systemMessage,
|
|
10450
10484
|
memorySystemMessage: memorySystemMessage || void 0
|
|
10451
10485
|
});
|
|
10452
|
-
const processedList = new
|
|
10486
|
+
const processedList = new chunkD3UG2YLU_cjs.MessageList({
|
|
10453
10487
|
threadId: threadObject.id,
|
|
10454
10488
|
resourceId,
|
|
10455
10489
|
generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
|
|
@@ -10505,7 +10539,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10505
10539
|
result: resToLog,
|
|
10506
10540
|
threadId
|
|
10507
10541
|
});
|
|
10508
|
-
const messageListResponses = new
|
|
10542
|
+
const messageListResponses = new chunkD3UG2YLU_cjs.MessageList({
|
|
10509
10543
|
threadId,
|
|
10510
10544
|
resourceId,
|
|
10511
10545
|
generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
|
|
@@ -10533,14 +10567,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10533
10567
|
}];
|
|
10534
10568
|
}
|
|
10535
10569
|
if (responseMessages) {
|
|
10536
|
-
|
|
10537
|
-
const {
|
|
10538
|
-
id,
|
|
10539
|
-
...messageWithoutId
|
|
10540
|
-
} = m;
|
|
10541
|
-
return messageWithoutId;
|
|
10542
|
-
});
|
|
10543
|
-
messageList.add(messagesWithoutIds, "response");
|
|
10570
|
+
messageList.add(responseMessages, "response");
|
|
10544
10571
|
}
|
|
10545
10572
|
if (!threadExists) {
|
|
10546
10573
|
await memory.createThread({
|
|
@@ -10963,7 +10990,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10963
10990
|
const instructions = options.instructions || (await this.getInstructions({
|
|
10964
10991
|
runtimeContext
|
|
10965
10992
|
}));
|
|
10966
|
-
const agentAISpan =
|
|
10993
|
+
const agentAISpan = chunkUGCG7DI3_cjs.getOrCreateSpan({
|
|
10967
10994
|
type: "agent_run" /* AGENT_RUN */,
|
|
10968
10995
|
name: `agent run: '${this.id}'`,
|
|
10969
10996
|
input: options.messages,
|
|
@@ -11039,12 +11066,12 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
11039
11066
|
resourceId,
|
|
11040
11067
|
runId,
|
|
11041
11068
|
runtimeContext,
|
|
11042
|
-
writableStream: options.writableStream,
|
|
11043
|
-
methodType,
|
|
11044
|
-
format,
|
|
11045
11069
|
tracingContext: {
|
|
11046
11070
|
currentSpan: agentAISpan
|
|
11047
|
-
}
|
|
11071
|
+
},
|
|
11072
|
+
writableStream: options.writableStream,
|
|
11073
|
+
methodType,
|
|
11074
|
+
format
|
|
11048
11075
|
});
|
|
11049
11076
|
return {
|
|
11050
11077
|
convertedTools
|
|
@@ -11055,7 +11082,6 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
11055
11082
|
id: "prepare-memory-step",
|
|
11056
11083
|
inputSchema: z.z.any(),
|
|
11057
11084
|
outputSchema: z.z.object({
|
|
11058
|
-
messageObjects: z.z.array(z.z.any()),
|
|
11059
11085
|
threadExists: z.z.boolean(),
|
|
11060
11086
|
thread: z.z.any(),
|
|
11061
11087
|
messageList: z.z.any(),
|
|
@@ -11066,7 +11092,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
11066
11092
|
tracingContext
|
|
11067
11093
|
}) => {
|
|
11068
11094
|
const thread = threadFromArgs;
|
|
11069
|
-
const messageList = new
|
|
11095
|
+
const messageList = new chunkD3UG2YLU_cjs.MessageList({
|
|
11070
11096
|
threadId: thread?.id,
|
|
11071
11097
|
resourceId,
|
|
11072
11098
|
generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
|
|
@@ -11087,7 +11113,6 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
11087
11113
|
messageList
|
|
11088
11114
|
});
|
|
11089
11115
|
return {
|
|
11090
|
-
messageObjects: messageList.get.all.prompt(),
|
|
11091
11116
|
threadExists: false,
|
|
11092
11117
|
thread: void 0,
|
|
11093
11118
|
messageList,
|
|
@@ -11151,7 +11176,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
11151
11176
|
let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread || hasResourceScopeSemanticRecall ? this.getMemoryMessages({
|
|
11152
11177
|
resourceId,
|
|
11153
11178
|
threadId: threadObject.id,
|
|
11154
|
-
vectorMessageSearch: new
|
|
11179
|
+
vectorMessageSearch: new chunkD3UG2YLU_cjs.MessageList().add(options.messages, `user`).getLatestUserContent() || "",
|
|
11155
11180
|
memoryConfig,
|
|
11156
11181
|
runtimeContext
|
|
11157
11182
|
}) : [], memory.getSystemMessage({
|
|
@@ -11174,7 +11199,7 @@ The following messages were remembered from a different conversation:
|
|
|
11174
11199
|
<remembered_from_other_conversation>
|
|
11175
11200
|
${(() => {
|
|
11176
11201
|
let result2 = ``;
|
|
11177
|
-
const messages = new
|
|
11202
|
+
const messages = new chunkD3UG2YLU_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
|
|
11178
11203
|
let lastYmd = null;
|
|
11179
11204
|
for (const msg of messages) {
|
|
11180
11205
|
const date = msg.createdAt;
|
|
@@ -11226,18 +11251,17 @@ the following messages are from ${ymd}
|
|
|
11226
11251
|
systemMessage,
|
|
11227
11252
|
memorySystemMessage: memorySystemMessage || void 0
|
|
11228
11253
|
});
|
|
11229
|
-
const processedList = new
|
|
11254
|
+
const processedList = new chunkD3UG2YLU_cjs.MessageList({
|
|
11230
11255
|
threadId: threadObject.id,
|
|
11231
11256
|
resourceId,
|
|
11232
11257
|
generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
|
|
11233
11258
|
// @ts-ignore Flag for agent network messages
|
|
11234
11259
|
_agentNetworkAppend: this._agentNetworkAppend
|
|
11235
|
-
}).addSystem(instructions || `${this.instructions}.`).addSystem(memorySystemMessage).add(options.context || [], "context").add(processedMemoryMessages, "memory").add(messageList.get.input.v2(), "user")
|
|
11260
|
+
}).addSystem(instructions || `${this.instructions}.`).addSystem(memorySystemMessage).add(options.context || [], "context").add(processedMemoryMessages, "memory").add(messageList.get.input.v2(), "user");
|
|
11236
11261
|
return {
|
|
11237
11262
|
thread: threadObject,
|
|
11238
|
-
messageList,
|
|
11263
|
+
messageList: processedList,
|
|
11239
11264
|
// add old processed messages + new input messages
|
|
11240
|
-
messageObjects: processedList,
|
|
11241
11265
|
...(tripwireTriggered && {
|
|
11242
11266
|
tripwire: true,
|
|
11243
11267
|
tripwireReason
|
|
@@ -11264,7 +11288,10 @@ the following messages are from ${ymd}
|
|
|
11264
11288
|
...inputData,
|
|
11265
11289
|
outputProcessors,
|
|
11266
11290
|
returnScorerData: options.returnScorerData,
|
|
11267
|
-
tracingContext
|
|
11291
|
+
tracingContext,
|
|
11292
|
+
_internal: {
|
|
11293
|
+
generateId: inputData.experimental_generateMessageId || this.#mastra?.generateId?.bind(this.#mastra)
|
|
11294
|
+
}
|
|
11268
11295
|
});
|
|
11269
11296
|
if (format === "aisdk") {
|
|
11270
11297
|
return streamResult.aisdk.v5;
|
|
@@ -11284,7 +11311,6 @@ the following messages are from ${ymd}
|
|
|
11284
11311
|
}) => {
|
|
11285
11312
|
const result2 = {
|
|
11286
11313
|
...options,
|
|
11287
|
-
messages: inputData["prepare-memory-step"].messageObjects,
|
|
11288
11314
|
tools: inputData["prepare-tools-step"].convertedTools,
|
|
11289
11315
|
runId,
|
|
11290
11316
|
temperature: options.modelSettings?.temperature,
|
|
@@ -11379,11 +11405,13 @@ the following messages are from ${ymd}
|
|
|
11379
11405
|
runtimeContext: result2.runtimeContext
|
|
11380
11406
|
}) : this.#outputProcessors : []);
|
|
11381
11407
|
if (options.structuredOutput) {
|
|
11382
|
-
const
|
|
11408
|
+
const agentModel = await this.getModel({
|
|
11409
|
+
runtimeContext: result2.runtimeContext
|
|
11410
|
+
});
|
|
11411
|
+
const structuredProcessor = new StructuredOutputProcessor(options.structuredOutput, agentModel);
|
|
11383
11412
|
effectiveOutputProcessors = effectiveOutputProcessors ? [...effectiveOutputProcessors, structuredProcessor] : [structuredProcessor];
|
|
11384
11413
|
}
|
|
11385
11414
|
const loopOptions = {
|
|
11386
|
-
messages: result2.messages,
|
|
11387
11415
|
runtimeContext: result2.runtimeContext,
|
|
11388
11416
|
tracingContext: {
|
|
11389
11417
|
currentSpan: agentAISpan
|
|
@@ -11407,7 +11435,6 @@ the following messages are from ${ymd}
|
|
|
11407
11435
|
return;
|
|
11408
11436
|
}
|
|
11409
11437
|
const messageList = inputData["prepare-memory-step"].messageList;
|
|
11410
|
-
messageList.add(payload.response.messages, "response");
|
|
11411
11438
|
try {
|
|
11412
11439
|
const outputText = messageList.get.all.core().map(m => m.content).join("\n");
|
|
11413
11440
|
await this.#executeOnFinish({
|
|
@@ -11436,17 +11463,25 @@ the following messages are from ${ymd}
|
|
|
11436
11463
|
await options?.onFinish?.({
|
|
11437
11464
|
...result2,
|
|
11438
11465
|
runId,
|
|
11439
|
-
messages: messageList.get.response.aiV5.model()
|
|
11466
|
+
messages: messageList.get.response.aiV5.model(),
|
|
11467
|
+
usage: payload.usage,
|
|
11468
|
+
totalUsage: payload.totalUsage
|
|
11440
11469
|
});
|
|
11441
11470
|
},
|
|
11442
|
-
onStepFinish: result2.onStepFinish
|
|
11471
|
+
onStepFinish: result2.onStepFinish,
|
|
11472
|
+
onChunk: options.onChunk,
|
|
11473
|
+
onError: options.onError,
|
|
11474
|
+
onAbort: options.onAbort,
|
|
11475
|
+
activeTools: options.activeTools,
|
|
11476
|
+
abortSignal: options.abortSignal
|
|
11443
11477
|
},
|
|
11444
11478
|
output: options.output,
|
|
11445
11479
|
outputProcessors: effectiveOutputProcessors,
|
|
11446
11480
|
modelSettings: {
|
|
11447
11481
|
temperature: 0,
|
|
11448
11482
|
...(options.modelSettings || {})
|
|
11449
|
-
}
|
|
11483
|
+
},
|
|
11484
|
+
messageList: inputData["prepare-memory-step"].messageList
|
|
11450
11485
|
};
|
|
11451
11486
|
return loopOptions;
|
|
11452
11487
|
}).then(streamStep).commit();
|
|
@@ -11523,14 +11558,8 @@ the following messages are from ${ymd}
|
|
|
11523
11558
|
}];
|
|
11524
11559
|
}
|
|
11525
11560
|
if (responseMessages) {
|
|
11526
|
-
const
|
|
11527
|
-
|
|
11528
|
-
id,
|
|
11529
|
-
...messageWithoutId
|
|
11530
|
-
} = m;
|
|
11531
|
-
return messageWithoutId;
|
|
11532
|
-
}).filter(m => m.role !== "user");
|
|
11533
|
-
messageList.add(messagesWithoutIds, "response");
|
|
11561
|
+
const filteredMessages = responseMessages.filter(m => m.role !== "user");
|
|
11562
|
+
messageList.add(filteredMessages, "response");
|
|
11534
11563
|
}
|
|
11535
11564
|
if (!threadExists) {
|
|
11536
11565
|
await memory.createThread({
|
|
@@ -11680,7 +11709,8 @@ the following messages are from ${ymd}
|
|
|
11680
11709
|
});
|
|
11681
11710
|
const mergedGenerateOptions = {
|
|
11682
11711
|
...defaultGenerateOptions,
|
|
11683
|
-
...generateOptions
|
|
11712
|
+
...generateOptions,
|
|
11713
|
+
experimental_generateMessageId: defaultGenerateOptions.experimental_generateMessageId || this.#mastra?.generateId?.bind(this.#mastra)
|
|
11684
11714
|
};
|
|
11685
11715
|
const {
|
|
11686
11716
|
llm,
|
|
@@ -11747,7 +11777,10 @@ the following messages are from ${ymd}
|
|
|
11747
11777
|
};
|
|
11748
11778
|
let finalOutputProcessors = mergedGenerateOptions.outputProcessors;
|
|
11749
11779
|
if (mergedGenerateOptions.structuredOutput) {
|
|
11750
|
-
const
|
|
11780
|
+
const agentModel = await this.getModel({
|
|
11781
|
+
runtimeContext: mergedGenerateOptions.runtimeContext
|
|
11782
|
+
});
|
|
11783
|
+
const structuredProcessor = new StructuredOutputProcessor(mergedGenerateOptions.structuredOutput, agentModel);
|
|
11751
11784
|
finalOutputProcessors = finalOutputProcessors ? [...finalOutputProcessors, structuredProcessor] : [structuredProcessor];
|
|
11752
11785
|
}
|
|
11753
11786
|
if (!output || experimental_output) {
|
|
@@ -11760,7 +11793,7 @@ the following messages are from ${ymd}
|
|
|
11760
11793
|
runtimeContext: mergedGenerateOptions.runtimeContext || new chunkGPWMM745_cjs.RuntimeContext(),
|
|
11761
11794
|
tracingContext,
|
|
11762
11795
|
outputProcessorOverrides: finalOutputProcessors,
|
|
11763
|
-
messageList: new
|
|
11796
|
+
messageList: new chunkD3UG2YLU_cjs.MessageList({
|
|
11764
11797
|
threadId: llmOptions.threadId || "",
|
|
11765
11798
|
resourceId: llmOptions.resourceId || ""
|
|
11766
11799
|
}).add({
|
|
@@ -11853,7 +11886,7 @@ the following messages are from ${ymd}
|
|
|
11853
11886
|
const outputProcessorResult = await this.__runOutputProcessors({
|
|
11854
11887
|
runtimeContext: mergedGenerateOptions.runtimeContext || new chunkGPWMM745_cjs.RuntimeContext(),
|
|
11855
11888
|
tracingContext,
|
|
11856
|
-
messageList: new
|
|
11889
|
+
messageList: new chunkD3UG2YLU_cjs.MessageList({
|
|
11857
11890
|
threadId: llmOptions.threadId || "",
|
|
11858
11891
|
resourceId: llmOptions.resourceId || ""
|
|
11859
11892
|
}).add({
|
|
@@ -11931,7 +11964,8 @@ the following messages are from ${ymd}
|
|
|
11931
11964
|
const mergedStreamOptions = {
|
|
11932
11965
|
...defaultStreamOptions,
|
|
11933
11966
|
...streamOptions,
|
|
11934
|
-
onFinish: this.#mergeOnFinishWithTelemetry(streamOptions, defaultStreamOptions)
|
|
11967
|
+
onFinish: this.#mergeOnFinishWithTelemetry(streamOptions, defaultStreamOptions),
|
|
11968
|
+
experimental_generateMessageId: defaultStreamOptions.experimental_generateMessageId || this.#mastra?.generateId?.bind(this.#mastra)
|
|
11935
11969
|
};
|
|
11936
11970
|
const {
|
|
11937
11971
|
llm,
|
|
@@ -12313,9 +12347,9 @@ var MastraWorkflowStream = class extends web.ReadableStream {
|
|
|
12313
12347
|
deferredPromise.reject = reject;
|
|
12314
12348
|
});
|
|
12315
12349
|
const updateUsageCount = usage => {
|
|
12316
|
-
this.#usageCount.promptTokens += parseInt(usage
|
|
12317
|
-
this.#usageCount.completionTokens += parseInt(usage
|
|
12318
|
-
this.#usageCount.totalTokens += parseInt(usage
|
|
12350
|
+
this.#usageCount.promptTokens += parseInt(usage?.promptTokens?.toString() ?? "0", 10);
|
|
12351
|
+
this.#usageCount.completionTokens += parseInt(usage?.completionTokens?.toString() ?? "0", 10);
|
|
12352
|
+
this.#usageCount.totalTokens += parseInt(usage?.totalTokens?.toString() ?? "0", 10);
|
|
12319
12353
|
};
|
|
12320
12354
|
super({
|
|
12321
12355
|
start: async controller => {
|
|
@@ -12323,7 +12357,9 @@ var MastraWorkflowStream = class extends web.ReadableStream {
|
|
|
12323
12357
|
write: chunk => {
|
|
12324
12358
|
if (chunk.type === "step-output" && chunk.payload?.output?.from === "AGENT" && chunk.payload?.output?.type === "finish" || chunk.type === "step-output" && chunk.payload?.output?.from === "WORKFLOW" && chunk.payload?.output?.type === "finish") {
|
|
12325
12359
|
const finishPayload = chunk.payload?.output.payload;
|
|
12326
|
-
|
|
12360
|
+
if (finishPayload) {
|
|
12361
|
+
updateUsageCount(finishPayload.usage);
|
|
12362
|
+
}
|
|
12327
12363
|
}
|
|
12328
12364
|
controller.enqueue(chunk);
|
|
12329
12365
|
}
|
|
@@ -12335,9 +12371,14 @@ var MastraWorkflowStream = class extends web.ReadableStream {
|
|
|
12335
12371
|
payload: {}
|
|
12336
12372
|
});
|
|
12337
12373
|
const stream = await createStream(writer);
|
|
12374
|
+
let workflowStatus = "success";
|
|
12338
12375
|
for await (const chunk of stream) {
|
|
12339
|
-
if (chunk.type === "step-finish") {
|
|
12376
|
+
if (chunk.type === "step-finish" && chunk.payload.usage) {
|
|
12340
12377
|
updateUsageCount(chunk.payload.usage);
|
|
12378
|
+
} else if (chunk.type === "workflow-canceled") {
|
|
12379
|
+
workflowStatus = "canceled";
|
|
12380
|
+
} else if (chunk.type === "workflow-step-result" && chunk.payload.status === "failed") {
|
|
12381
|
+
workflowStatus = "failed";
|
|
12341
12382
|
}
|
|
12342
12383
|
controller.enqueue(chunk);
|
|
12343
12384
|
}
|
|
@@ -12346,9 +12387,7 @@ var MastraWorkflowStream = class extends web.ReadableStream {
|
|
|
12346
12387
|
runId: run.runId,
|
|
12347
12388
|
from: "WORKFLOW" /* WORKFLOW */,
|
|
12348
12389
|
payload: {
|
|
12349
|
-
|
|
12350
|
-
reason: "stop"
|
|
12351
|
-
},
|
|
12390
|
+
workflowStatus,
|
|
12352
12391
|
output: {
|
|
12353
12392
|
usage: this.#usageCount
|
|
12354
12393
|
},
|
|
@@ -12517,7 +12556,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
12517
12556
|
} = retryConfig ?? {};
|
|
12518
12557
|
const steps = graph.steps;
|
|
12519
12558
|
this.runCounts.clear();
|
|
12520
|
-
const workflowAISpan =
|
|
12559
|
+
const workflowAISpan = chunkUGCG7DI3_cjs.getOrCreateSpan({
|
|
12521
12560
|
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
12522
12561
|
name: `workflow run: '${workflowId}'`,
|
|
12523
12562
|
input,
|
|
@@ -13030,7 +13069,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13030
13069
|
const result = await runStep({
|
|
13031
13070
|
runId,
|
|
13032
13071
|
workflowId,
|
|
13033
|
-
mastra: this.mastra ?
|
|
13072
|
+
mastra: this.mastra ? chunkUGCG7DI3_cjs.wrapMastra(this.mastra, innerTracingContext) : void 0,
|
|
13034
13073
|
runtimeContext,
|
|
13035
13074
|
inputData: prevOutput,
|
|
13036
13075
|
runCount: this.getOrGenerateRunCount(step.id),
|
|
@@ -13614,7 +13653,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
13614
13653
|
const evalSpan = loopSpan?.createChildSpan({
|
|
13615
13654
|
type: "workflow_conditional_eval" /* WORKFLOW_CONDITIONAL_EVAL */,
|
|
13616
13655
|
name: `condition: ${entry.loopType}`,
|
|
13617
|
-
input:
|
|
13656
|
+
input: chunkUGCG7DI3_cjs.selectFields(result.output, ["stepResult", "output.text", "output.object", "messages"]),
|
|
13618
13657
|
attributes: {
|
|
13619
13658
|
conditionIndex: iteration
|
|
13620
13659
|
}
|
|
@@ -14482,6 +14521,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14482
14521
|
workflowStatus: execResults.status === "success" ? "running" : execResults.status,
|
|
14483
14522
|
runtimeContext
|
|
14484
14523
|
});
|
|
14524
|
+
if (execResults.status === "canceled") {
|
|
14525
|
+
await emitter.emit("watch-v2", {
|
|
14526
|
+
type: "workflow-canceled",
|
|
14527
|
+
payload: {}
|
|
14528
|
+
});
|
|
14529
|
+
}
|
|
14485
14530
|
return {
|
|
14486
14531
|
result: execResults,
|
|
14487
14532
|
stepResults,
|
|
@@ -15186,6 +15231,8 @@ var Workflow = class extends chunkKXCUCBEI_cjs.MastraBase {
|
|
|
15186
15231
|
}
|
|
15187
15232
|
return scorers;
|
|
15188
15233
|
}
|
|
15234
|
+
// This method should only be called internally for nested workflow execution, as well as from mastra server handlers
|
|
15235
|
+
// To run a workflow use `.createRunAsync` and then `.start` or `.resume`
|
|
15189
15236
|
async execute({
|
|
15190
15237
|
runId,
|
|
15191
15238
|
inputData,
|
|
@@ -15619,12 +15666,13 @@ var Run = class {
|
|
|
15619
15666
|
streamVNext({
|
|
15620
15667
|
inputData,
|
|
15621
15668
|
runtimeContext,
|
|
15669
|
+
tracingContext,
|
|
15622
15670
|
format
|
|
15623
15671
|
} = {}) {
|
|
15624
15672
|
this.closeStreamAction = async () => {};
|
|
15625
15673
|
return new MastraWorkflowStream({
|
|
15626
15674
|
run: this,
|
|
15627
|
-
createStream:
|
|
15675
|
+
createStream: () => {
|
|
15628
15676
|
const {
|
|
15629
15677
|
readable,
|
|
15630
15678
|
writable
|
|
@@ -15642,7 +15690,7 @@ var Run = class {
|
|
|
15642
15690
|
return;
|
|
15643
15691
|
}
|
|
15644
15692
|
isWriting = true;
|
|
15645
|
-
let watchWriter =
|
|
15693
|
+
let watchWriter = writable.getWriter();
|
|
15646
15694
|
try {
|
|
15647
15695
|
for (const chunk of chunkToWrite) {
|
|
15648
15696
|
await watchWriter.write(chunk);
|
|
@@ -15680,6 +15728,7 @@ var Run = class {
|
|
|
15680
15728
|
const executionResults = this._start({
|
|
15681
15729
|
inputData,
|
|
15682
15730
|
runtimeContext,
|
|
15731
|
+
tracingContext,
|
|
15683
15732
|
writableStream: writable,
|
|
15684
15733
|
format
|
|
15685
15734
|
}).then(result => {
|
|
@@ -15963,5 +16012,5 @@ exports.recursivelyCheckForFinalState = recursivelyCheckForFinalState;
|
|
|
15963
16012
|
exports.resolveVariables = resolveVariables;
|
|
15964
16013
|
exports.updateStepInHierarchy = updateStepInHierarchy;
|
|
15965
16014
|
exports.workflowToStep = workflowToStep;
|
|
15966
|
-
//# sourceMappingURL=chunk-
|
|
15967
|
-
//# sourceMappingURL=chunk-
|
|
16015
|
+
//# sourceMappingURL=chunk-WJXZMK43.cjs.map
|
|
16016
|
+
//# sourceMappingURL=chunk-WJXZMK43.cjs.map
|