@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
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { DefaultVoice } from './chunk-QQIBOVFQ.js';
|
|
2
2
|
import { STREAM_FORMAT_SYMBOL, EMITTER_SYMBOL } from './chunk-NLNKQD2T.js';
|
|
3
3
|
import { InstrumentClass, Telemetry } from './chunk-TLJPVRO5.js';
|
|
4
|
-
import { MastraLLMV1 } from './chunk-
|
|
5
|
-
import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-
|
|
4
|
+
import { MastraLLMV1 } from './chunk-BQ43NQXK.js';
|
|
5
|
+
import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-YI3AIJJL.js';
|
|
6
6
|
import { executeHook } from './chunk-TTELJD4F.js';
|
|
7
|
-
import { ensureToolProperties, makeCoreTool, createMastraProxy, delay } from './chunk-
|
|
7
|
+
import { ensureToolProperties, makeCoreTool, createMastraProxy, delay } from './chunk-TDLB5JKT.js';
|
|
8
8
|
import { RuntimeContext } from './chunk-HLRWYUFN.js';
|
|
9
9
|
import { ToolStream } from './chunk-YW7UILPE.js';
|
|
10
10
|
import { createTool, Tool } from './chunk-BJGHUKKM.js';
|
|
11
|
-
import { getOrCreateSpan, wrapMastra, selectFields } from './chunk-
|
|
11
|
+
import { getOrCreateSpan, wrapMastra, selectFields } from './chunk-2NKNTPFR.js';
|
|
12
12
|
import { MastraError } from './chunk-MCOVMKIS.js';
|
|
13
13
|
import { MastraBase } from './chunk-6GF5M4GX.js';
|
|
14
14
|
import { ConsoleLogger, RegisteredLogger } from './chunk-X3GXU6TZ.js';
|
|
@@ -2213,7 +2213,8 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
2213
2213
|
} = chunk.payload.metadata;
|
|
2214
2214
|
response = {
|
|
2215
2215
|
...otherMetadata,
|
|
2216
|
-
messages: messageList.get.response.aiV5.model()
|
|
2216
|
+
messages: messageList.get.response.aiV5.model(),
|
|
2217
|
+
uiMessages: messageList.get.response.aiV5.ui()
|
|
2217
2218
|
};
|
|
2218
2219
|
}
|
|
2219
2220
|
this.populateUsageCount(chunk.payload.output.usage);
|
|
@@ -2240,7 +2241,8 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
2240
2241
|
} = chunk.payload.metadata;
|
|
2241
2242
|
response = {
|
|
2242
2243
|
...otherMetadata,
|
|
2243
|
-
messages: messageList.get.response.aiV5.model()
|
|
2244
|
+
messages: messageList.get.response.aiV5.model(),
|
|
2245
|
+
uiMessages: messageList.get.response.aiV5.ui()
|
|
2244
2246
|
};
|
|
2245
2247
|
}
|
|
2246
2248
|
} else {
|
|
@@ -2595,7 +2597,6 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
2595
2597
|
scoringData
|
|
2596
2598
|
} : {})
|
|
2597
2599
|
};
|
|
2598
|
-
fullOutput.response.messages = this.messageList.get.response.aiV5.model();
|
|
2599
2600
|
return fullOutput;
|
|
2600
2601
|
}
|
|
2601
2602
|
/**
|
|
@@ -3089,7 +3090,9 @@ var toolCallInputSchema = z.object({
|
|
|
3089
3090
|
toolCallId: z.string(),
|
|
3090
3091
|
toolName: z.string(),
|
|
3091
3092
|
args: z.any(),
|
|
3092
|
-
providerMetadata: z.any()
|
|
3093
|
+
providerMetadata: z.any(),
|
|
3094
|
+
providerExecuted: z.boolean().optional(),
|
|
3095
|
+
output: z.any().optional()
|
|
3093
3096
|
});
|
|
3094
3097
|
var toolCallOutputSchema = toolCallInputSchema.extend({
|
|
3095
3098
|
result: z.any(),
|
|
@@ -3610,6 +3613,32 @@ function createToolCallStep({
|
|
|
3610
3613
|
execute: async ({
|
|
3611
3614
|
inputData
|
|
3612
3615
|
}) => {
|
|
3616
|
+
if (inputData.providerExecuted) {
|
|
3617
|
+
const tracer2 = getTracer({
|
|
3618
|
+
isEnabled: telemetry_settings?.isEnabled,
|
|
3619
|
+
tracer: telemetry_settings?.tracer
|
|
3620
|
+
});
|
|
3621
|
+
const span2 = tracer2.startSpan("mastra.stream.toolCall").setAttributes({
|
|
3622
|
+
...assembleOperationName({
|
|
3623
|
+
operationId: "mastra.stream.toolCall",
|
|
3624
|
+
telemetry: telemetry_settings
|
|
3625
|
+
}),
|
|
3626
|
+
"stream.toolCall.toolName": inputData.toolName,
|
|
3627
|
+
"stream.toolCall.toolCallId": inputData.toolCallId,
|
|
3628
|
+
"stream.toolCall.args": JSON.stringify(inputData.args),
|
|
3629
|
+
"stream.toolCall.providerExecuted": true
|
|
3630
|
+
});
|
|
3631
|
+
if (inputData.output) {
|
|
3632
|
+
span2.setAttributes({
|
|
3633
|
+
"stream.toolCall.result": JSON.stringify(inputData.output)
|
|
3634
|
+
});
|
|
3635
|
+
}
|
|
3636
|
+
span2.end();
|
|
3637
|
+
return {
|
|
3638
|
+
...inputData,
|
|
3639
|
+
result: inputData.output
|
|
3640
|
+
};
|
|
3641
|
+
}
|
|
3613
3642
|
const tool = tools?.[inputData.toolName] || Object.values(tools || {})?.find(tool2 => `id` in tool2 && tool2.id === inputData.toolName);
|
|
3614
3643
|
if (!tool) {
|
|
3615
3644
|
throw new Error(`Tool ${inputData.toolName} not found`);
|
|
@@ -3751,7 +3780,8 @@ function createOuterLLMWorkflow({
|
|
|
3751
3780
|
toolCallId: toolCall.toolCallId,
|
|
3752
3781
|
toolName: toolCall.toolName,
|
|
3753
3782
|
result: toolCall.result,
|
|
3754
|
-
providerMetadata: toolCall.providerMetadata
|
|
3783
|
+
providerMetadata: toolCall.providerMetadata,
|
|
3784
|
+
providerExecuted: toolCall.providerExecuted
|
|
3755
3785
|
}
|
|
3756
3786
|
};
|
|
3757
3787
|
rest.controller.enqueue(chunk);
|
|
@@ -4130,7 +4160,6 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
4130
4160
|
}];
|
|
4131
4161
|
}
|
|
4132
4162
|
stream({
|
|
4133
|
-
messages,
|
|
4134
4163
|
stopWhen = stepCountIs(5),
|
|
4135
4164
|
maxSteps,
|
|
4136
4165
|
tools = {},
|
|
@@ -4145,7 +4174,9 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
4145
4174
|
outputProcessors,
|
|
4146
4175
|
returnScorerData,
|
|
4147
4176
|
providerOptions,
|
|
4148
|
-
tracingContext
|
|
4177
|
+
tracingContext,
|
|
4178
|
+
messageList,
|
|
4179
|
+
_internal
|
|
4149
4180
|
// ...rest
|
|
4150
4181
|
}) {
|
|
4151
4182
|
let stopWhenToUse;
|
|
@@ -4154,6 +4185,7 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
4154
4185
|
} else {
|
|
4155
4186
|
stopWhenToUse = stopWhen;
|
|
4156
4187
|
}
|
|
4188
|
+
const messages = messageList.get.all.aiV5.model();
|
|
4157
4189
|
const model = this.#model;
|
|
4158
4190
|
this.logger.debug(`[LLM] - Streaming text`, {
|
|
4159
4191
|
runId,
|
|
@@ -4177,11 +4209,6 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
4177
4209
|
}
|
|
4178
4210
|
});
|
|
4179
4211
|
try {
|
|
4180
|
-
const messageList = new MessageList({
|
|
4181
|
-
threadId,
|
|
4182
|
-
resourceId
|
|
4183
|
-
});
|
|
4184
|
-
messageList.add(messages, "input");
|
|
4185
4212
|
const loopOptions = {
|
|
4186
4213
|
messageList,
|
|
4187
4214
|
model: this.#model,
|
|
@@ -4194,6 +4221,7 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
4194
4221
|
...this.experimental_telemetry,
|
|
4195
4222
|
...telemetry_settings
|
|
4196
4223
|
},
|
|
4224
|
+
_internal,
|
|
4197
4225
|
output,
|
|
4198
4226
|
outputProcessors,
|
|
4199
4227
|
returnScorerData,
|
|
@@ -4313,14 +4341,18 @@ var StructuredOutputProcessor = class {
|
|
|
4313
4341
|
structuringAgent;
|
|
4314
4342
|
errorStrategy;
|
|
4315
4343
|
fallbackValue;
|
|
4316
|
-
constructor(options) {
|
|
4344
|
+
constructor(options, fallbackModel) {
|
|
4317
4345
|
this.schema = options.schema;
|
|
4318
4346
|
this.errorStrategy = options.errorStrategy ?? "strict";
|
|
4319
4347
|
this.fallbackValue = options.fallbackValue;
|
|
4348
|
+
const modelToUse = options.model || fallbackModel;
|
|
4349
|
+
if (!modelToUse) {
|
|
4350
|
+
throw new Error("StructuredOutputProcessor requires a model to be provided either in options or as fallback");
|
|
4351
|
+
}
|
|
4320
4352
|
this.structuringAgent = new Agent({
|
|
4321
4353
|
name: "structured-output-structurer",
|
|
4322
4354
|
instructions: options.instructions || this.generateInstructions(),
|
|
4323
|
-
model:
|
|
4355
|
+
model: modelToUse
|
|
4324
4356
|
});
|
|
4325
4357
|
}
|
|
4326
4358
|
async processOutputResult(args) {
|
|
@@ -9512,16 +9544,17 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
9512
9544
|
const systemInstructions = await this.resolveTitleInstructions(runtimeContext, instructions);
|
|
9513
9545
|
let text = "";
|
|
9514
9546
|
if (llm.getModel().specificationVersion === "v2") {
|
|
9547
|
+
const messageList = new MessageList().add([{
|
|
9548
|
+
role: "system",
|
|
9549
|
+
content: systemInstructions
|
|
9550
|
+
}], "system").add([{
|
|
9551
|
+
role: "user",
|
|
9552
|
+
content: JSON.stringify(partsToGen)
|
|
9553
|
+
}], "input");
|
|
9515
9554
|
const result = llm.stream({
|
|
9516
9555
|
runtimeContext,
|
|
9517
9556
|
tracingContext,
|
|
9518
|
-
|
|
9519
|
-
role: "system",
|
|
9520
|
-
content: systemInstructions
|
|
9521
|
-
}, {
|
|
9522
|
-
role: "user",
|
|
9523
|
-
content: JSON.stringify(partsToGen)
|
|
9524
|
-
}]
|
|
9557
|
+
messageList
|
|
9525
9558
|
});
|
|
9526
9559
|
text = await result.text;
|
|
9527
9560
|
} else {
|
|
@@ -9977,7 +10010,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
9977
10010
|
threadId,
|
|
9978
10011
|
resourceId
|
|
9979
10012
|
});
|
|
9980
|
-
const run = workflow.
|
|
10013
|
+
const run = await workflow.createRunAsync();
|
|
9981
10014
|
let result;
|
|
9982
10015
|
if (methodType === "generate") {
|
|
9983
10016
|
result = await run.start({
|
|
@@ -10001,6 +10034,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
10001
10034
|
const streamResult = run.streamVNext({
|
|
10002
10035
|
inputData: context,
|
|
10003
10036
|
runtimeContext,
|
|
10037
|
+
tracingContext: innerTracingContext,
|
|
10004
10038
|
format
|
|
10005
10039
|
});
|
|
10006
10040
|
if (writer) {
|
|
@@ -10507,14 +10541,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10507
10541
|
}];
|
|
10508
10542
|
}
|
|
10509
10543
|
if (responseMessages) {
|
|
10510
|
-
|
|
10511
|
-
const {
|
|
10512
|
-
id,
|
|
10513
|
-
...messageWithoutId
|
|
10514
|
-
} = m;
|
|
10515
|
-
return messageWithoutId;
|
|
10516
|
-
});
|
|
10517
|
-
messageList.add(messagesWithoutIds, "response");
|
|
10544
|
+
messageList.add(responseMessages, "response");
|
|
10518
10545
|
}
|
|
10519
10546
|
if (!threadExists) {
|
|
10520
10547
|
await memory.createThread({
|
|
@@ -11013,12 +11040,12 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
11013
11040
|
resourceId,
|
|
11014
11041
|
runId,
|
|
11015
11042
|
runtimeContext,
|
|
11016
|
-
writableStream: options.writableStream,
|
|
11017
|
-
methodType,
|
|
11018
|
-
format,
|
|
11019
11043
|
tracingContext: {
|
|
11020
11044
|
currentSpan: agentAISpan
|
|
11021
|
-
}
|
|
11045
|
+
},
|
|
11046
|
+
writableStream: options.writableStream,
|
|
11047
|
+
methodType,
|
|
11048
|
+
format
|
|
11022
11049
|
});
|
|
11023
11050
|
return {
|
|
11024
11051
|
convertedTools
|
|
@@ -11029,7 +11056,6 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
11029
11056
|
id: "prepare-memory-step",
|
|
11030
11057
|
inputSchema: z$1.any(),
|
|
11031
11058
|
outputSchema: z$1.object({
|
|
11032
|
-
messageObjects: z$1.array(z$1.any()),
|
|
11033
11059
|
threadExists: z$1.boolean(),
|
|
11034
11060
|
thread: z$1.any(),
|
|
11035
11061
|
messageList: z$1.any(),
|
|
@@ -11061,7 +11087,6 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
11061
11087
|
messageList
|
|
11062
11088
|
});
|
|
11063
11089
|
return {
|
|
11064
|
-
messageObjects: messageList.get.all.prompt(),
|
|
11065
11090
|
threadExists: false,
|
|
11066
11091
|
thread: void 0,
|
|
11067
11092
|
messageList,
|
|
@@ -11206,12 +11231,11 @@ the following messages are from ${ymd}
|
|
|
11206
11231
|
generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
|
|
11207
11232
|
// @ts-ignore Flag for agent network messages
|
|
11208
11233
|
_agentNetworkAppend: this._agentNetworkAppend
|
|
11209
|
-
}).addSystem(instructions || `${this.instructions}.`).addSystem(memorySystemMessage).add(options.context || [], "context").add(processedMemoryMessages, "memory").add(messageList.get.input.v2(), "user")
|
|
11234
|
+
}).addSystem(instructions || `${this.instructions}.`).addSystem(memorySystemMessage).add(options.context || [], "context").add(processedMemoryMessages, "memory").add(messageList.get.input.v2(), "user");
|
|
11210
11235
|
return {
|
|
11211
11236
|
thread: threadObject,
|
|
11212
|
-
messageList,
|
|
11237
|
+
messageList: processedList,
|
|
11213
11238
|
// add old processed messages + new input messages
|
|
11214
|
-
messageObjects: processedList,
|
|
11215
11239
|
...(tripwireTriggered && {
|
|
11216
11240
|
tripwire: true,
|
|
11217
11241
|
tripwireReason
|
|
@@ -11238,7 +11262,10 @@ the following messages are from ${ymd}
|
|
|
11238
11262
|
...inputData,
|
|
11239
11263
|
outputProcessors,
|
|
11240
11264
|
returnScorerData: options.returnScorerData,
|
|
11241
|
-
tracingContext
|
|
11265
|
+
tracingContext,
|
|
11266
|
+
_internal: {
|
|
11267
|
+
generateId: inputData.experimental_generateMessageId || this.#mastra?.generateId?.bind(this.#mastra)
|
|
11268
|
+
}
|
|
11242
11269
|
});
|
|
11243
11270
|
if (format === "aisdk") {
|
|
11244
11271
|
return streamResult.aisdk.v5;
|
|
@@ -11258,7 +11285,6 @@ the following messages are from ${ymd}
|
|
|
11258
11285
|
}) => {
|
|
11259
11286
|
const result2 = {
|
|
11260
11287
|
...options,
|
|
11261
|
-
messages: inputData["prepare-memory-step"].messageObjects,
|
|
11262
11288
|
tools: inputData["prepare-tools-step"].convertedTools,
|
|
11263
11289
|
runId,
|
|
11264
11290
|
temperature: options.modelSettings?.temperature,
|
|
@@ -11353,11 +11379,13 @@ the following messages are from ${ymd}
|
|
|
11353
11379
|
runtimeContext: result2.runtimeContext
|
|
11354
11380
|
}) : this.#outputProcessors : []);
|
|
11355
11381
|
if (options.structuredOutput) {
|
|
11356
|
-
const
|
|
11382
|
+
const agentModel = await this.getModel({
|
|
11383
|
+
runtimeContext: result2.runtimeContext
|
|
11384
|
+
});
|
|
11385
|
+
const structuredProcessor = new StructuredOutputProcessor(options.structuredOutput, agentModel);
|
|
11357
11386
|
effectiveOutputProcessors = effectiveOutputProcessors ? [...effectiveOutputProcessors, structuredProcessor] : [structuredProcessor];
|
|
11358
11387
|
}
|
|
11359
11388
|
const loopOptions = {
|
|
11360
|
-
messages: result2.messages,
|
|
11361
11389
|
runtimeContext: result2.runtimeContext,
|
|
11362
11390
|
tracingContext: {
|
|
11363
11391
|
currentSpan: agentAISpan
|
|
@@ -11381,7 +11409,6 @@ the following messages are from ${ymd}
|
|
|
11381
11409
|
return;
|
|
11382
11410
|
}
|
|
11383
11411
|
const messageList = inputData["prepare-memory-step"].messageList;
|
|
11384
|
-
messageList.add(payload.response.messages, "response");
|
|
11385
11412
|
try {
|
|
11386
11413
|
const outputText = messageList.get.all.core().map(m => m.content).join("\n");
|
|
11387
11414
|
await this.#executeOnFinish({
|
|
@@ -11410,17 +11437,25 @@ the following messages are from ${ymd}
|
|
|
11410
11437
|
await options?.onFinish?.({
|
|
11411
11438
|
...result2,
|
|
11412
11439
|
runId,
|
|
11413
|
-
messages: messageList.get.response.aiV5.model()
|
|
11440
|
+
messages: messageList.get.response.aiV5.model(),
|
|
11441
|
+
usage: payload.usage,
|
|
11442
|
+
totalUsage: payload.totalUsage
|
|
11414
11443
|
});
|
|
11415
11444
|
},
|
|
11416
|
-
onStepFinish: result2.onStepFinish
|
|
11445
|
+
onStepFinish: result2.onStepFinish,
|
|
11446
|
+
onChunk: options.onChunk,
|
|
11447
|
+
onError: options.onError,
|
|
11448
|
+
onAbort: options.onAbort,
|
|
11449
|
+
activeTools: options.activeTools,
|
|
11450
|
+
abortSignal: options.abortSignal
|
|
11417
11451
|
},
|
|
11418
11452
|
output: options.output,
|
|
11419
11453
|
outputProcessors: effectiveOutputProcessors,
|
|
11420
11454
|
modelSettings: {
|
|
11421
11455
|
temperature: 0,
|
|
11422
11456
|
...(options.modelSettings || {})
|
|
11423
|
-
}
|
|
11457
|
+
},
|
|
11458
|
+
messageList: inputData["prepare-memory-step"].messageList
|
|
11424
11459
|
};
|
|
11425
11460
|
return loopOptions;
|
|
11426
11461
|
}).then(streamStep).commit();
|
|
@@ -11497,14 +11532,8 @@ the following messages are from ${ymd}
|
|
|
11497
11532
|
}];
|
|
11498
11533
|
}
|
|
11499
11534
|
if (responseMessages) {
|
|
11500
|
-
const
|
|
11501
|
-
|
|
11502
|
-
id,
|
|
11503
|
-
...messageWithoutId
|
|
11504
|
-
} = m;
|
|
11505
|
-
return messageWithoutId;
|
|
11506
|
-
}).filter(m => m.role !== "user");
|
|
11507
|
-
messageList.add(messagesWithoutIds, "response");
|
|
11535
|
+
const filteredMessages = responseMessages.filter(m => m.role !== "user");
|
|
11536
|
+
messageList.add(filteredMessages, "response");
|
|
11508
11537
|
}
|
|
11509
11538
|
if (!threadExists) {
|
|
11510
11539
|
await memory.createThread({
|
|
@@ -11654,7 +11683,8 @@ the following messages are from ${ymd}
|
|
|
11654
11683
|
});
|
|
11655
11684
|
const mergedGenerateOptions = {
|
|
11656
11685
|
...defaultGenerateOptions,
|
|
11657
|
-
...generateOptions
|
|
11686
|
+
...generateOptions,
|
|
11687
|
+
experimental_generateMessageId: defaultGenerateOptions.experimental_generateMessageId || this.#mastra?.generateId?.bind(this.#mastra)
|
|
11658
11688
|
};
|
|
11659
11689
|
const {
|
|
11660
11690
|
llm,
|
|
@@ -11721,7 +11751,10 @@ the following messages are from ${ymd}
|
|
|
11721
11751
|
};
|
|
11722
11752
|
let finalOutputProcessors = mergedGenerateOptions.outputProcessors;
|
|
11723
11753
|
if (mergedGenerateOptions.structuredOutput) {
|
|
11724
|
-
const
|
|
11754
|
+
const agentModel = await this.getModel({
|
|
11755
|
+
runtimeContext: mergedGenerateOptions.runtimeContext
|
|
11756
|
+
});
|
|
11757
|
+
const structuredProcessor = new StructuredOutputProcessor(mergedGenerateOptions.structuredOutput, agentModel);
|
|
11725
11758
|
finalOutputProcessors = finalOutputProcessors ? [...finalOutputProcessors, structuredProcessor] : [structuredProcessor];
|
|
11726
11759
|
}
|
|
11727
11760
|
if (!output || experimental_output) {
|
|
@@ -11905,7 +11938,8 @@ the following messages are from ${ymd}
|
|
|
11905
11938
|
const mergedStreamOptions = {
|
|
11906
11939
|
...defaultStreamOptions,
|
|
11907
11940
|
...streamOptions,
|
|
11908
|
-
onFinish: this.#mergeOnFinishWithTelemetry(streamOptions, defaultStreamOptions)
|
|
11941
|
+
onFinish: this.#mergeOnFinishWithTelemetry(streamOptions, defaultStreamOptions),
|
|
11942
|
+
experimental_generateMessageId: defaultStreamOptions.experimental_generateMessageId || this.#mastra?.generateId?.bind(this.#mastra)
|
|
11909
11943
|
};
|
|
11910
11944
|
const {
|
|
11911
11945
|
llm,
|
|
@@ -12287,9 +12321,9 @@ var MastraWorkflowStream = class extends ReadableStream$1 {
|
|
|
12287
12321
|
deferredPromise.reject = reject;
|
|
12288
12322
|
});
|
|
12289
12323
|
const updateUsageCount = usage => {
|
|
12290
|
-
this.#usageCount.promptTokens += parseInt(usage
|
|
12291
|
-
this.#usageCount.completionTokens += parseInt(usage
|
|
12292
|
-
this.#usageCount.totalTokens += parseInt(usage
|
|
12324
|
+
this.#usageCount.promptTokens += parseInt(usage?.promptTokens?.toString() ?? "0", 10);
|
|
12325
|
+
this.#usageCount.completionTokens += parseInt(usage?.completionTokens?.toString() ?? "0", 10);
|
|
12326
|
+
this.#usageCount.totalTokens += parseInt(usage?.totalTokens?.toString() ?? "0", 10);
|
|
12293
12327
|
};
|
|
12294
12328
|
super({
|
|
12295
12329
|
start: async controller => {
|
|
@@ -12297,7 +12331,9 @@ var MastraWorkflowStream = class extends ReadableStream$1 {
|
|
|
12297
12331
|
write: chunk => {
|
|
12298
12332
|
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") {
|
|
12299
12333
|
const finishPayload = chunk.payload?.output.payload;
|
|
12300
|
-
|
|
12334
|
+
if (finishPayload) {
|
|
12335
|
+
updateUsageCount(finishPayload.usage);
|
|
12336
|
+
}
|
|
12301
12337
|
}
|
|
12302
12338
|
controller.enqueue(chunk);
|
|
12303
12339
|
}
|
|
@@ -12309,9 +12345,14 @@ var MastraWorkflowStream = class extends ReadableStream$1 {
|
|
|
12309
12345
|
payload: {}
|
|
12310
12346
|
});
|
|
12311
12347
|
const stream = await createStream(writer);
|
|
12348
|
+
let workflowStatus = "success";
|
|
12312
12349
|
for await (const chunk of stream) {
|
|
12313
|
-
if (chunk.type === "step-finish") {
|
|
12350
|
+
if (chunk.type === "step-finish" && chunk.payload.usage) {
|
|
12314
12351
|
updateUsageCount(chunk.payload.usage);
|
|
12352
|
+
} else if (chunk.type === "workflow-canceled") {
|
|
12353
|
+
workflowStatus = "canceled";
|
|
12354
|
+
} else if (chunk.type === "workflow-step-result" && chunk.payload.status === "failed") {
|
|
12355
|
+
workflowStatus = "failed";
|
|
12315
12356
|
}
|
|
12316
12357
|
controller.enqueue(chunk);
|
|
12317
12358
|
}
|
|
@@ -12320,9 +12361,7 @@ var MastraWorkflowStream = class extends ReadableStream$1 {
|
|
|
12320
12361
|
runId: run.runId,
|
|
12321
12362
|
from: "WORKFLOW" /* WORKFLOW */,
|
|
12322
12363
|
payload: {
|
|
12323
|
-
|
|
12324
|
-
reason: "stop"
|
|
12325
|
-
},
|
|
12364
|
+
workflowStatus,
|
|
12326
12365
|
output: {
|
|
12327
12366
|
usage: this.#usageCount
|
|
12328
12367
|
},
|
|
@@ -14456,6 +14495,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14456
14495
|
workflowStatus: execResults.status === "success" ? "running" : execResults.status,
|
|
14457
14496
|
runtimeContext
|
|
14458
14497
|
});
|
|
14498
|
+
if (execResults.status === "canceled") {
|
|
14499
|
+
await emitter.emit("watch-v2", {
|
|
14500
|
+
type: "workflow-canceled",
|
|
14501
|
+
payload: {}
|
|
14502
|
+
});
|
|
14503
|
+
}
|
|
14459
14504
|
return {
|
|
14460
14505
|
result: execResults,
|
|
14461
14506
|
stepResults,
|
|
@@ -15160,6 +15205,8 @@ var Workflow = class extends MastraBase {
|
|
|
15160
15205
|
}
|
|
15161
15206
|
return scorers;
|
|
15162
15207
|
}
|
|
15208
|
+
// This method should only be called internally for nested workflow execution, as well as from mastra server handlers
|
|
15209
|
+
// To run a workflow use `.createRunAsync` and then `.start` or `.resume`
|
|
15163
15210
|
async execute({
|
|
15164
15211
|
runId,
|
|
15165
15212
|
inputData,
|
|
@@ -15593,12 +15640,13 @@ var Run = class {
|
|
|
15593
15640
|
streamVNext({
|
|
15594
15641
|
inputData,
|
|
15595
15642
|
runtimeContext,
|
|
15643
|
+
tracingContext,
|
|
15596
15644
|
format
|
|
15597
15645
|
} = {}) {
|
|
15598
15646
|
this.closeStreamAction = async () => {};
|
|
15599
15647
|
return new MastraWorkflowStream({
|
|
15600
15648
|
run: this,
|
|
15601
|
-
createStream:
|
|
15649
|
+
createStream: () => {
|
|
15602
15650
|
const {
|
|
15603
15651
|
readable,
|
|
15604
15652
|
writable
|
|
@@ -15616,7 +15664,7 @@ var Run = class {
|
|
|
15616
15664
|
return;
|
|
15617
15665
|
}
|
|
15618
15666
|
isWriting = true;
|
|
15619
|
-
let watchWriter =
|
|
15667
|
+
let watchWriter = writable.getWriter();
|
|
15620
15668
|
try {
|
|
15621
15669
|
for (const chunk of chunkToWrite) {
|
|
15622
15670
|
await watchWriter.write(chunk);
|
|
@@ -15654,6 +15702,7 @@ var Run = class {
|
|
|
15654
15702
|
const executionResults = this._start({
|
|
15655
15703
|
inputData,
|
|
15656
15704
|
runtimeContext,
|
|
15705
|
+
tracingContext,
|
|
15657
15706
|
writableStream: writable,
|
|
15658
15707
|
format
|
|
15659
15708
|
}).then(result => {
|
|
@@ -15893,5 +15942,5 @@ function deepMergeWorkflowState(a, b) {
|
|
|
15893
15942
|
}
|
|
15894
15943
|
|
|
15895
15944
|
export { AISDKV5OutputStream, Agent, DefaultExecutionEngine, ExecutionEngine, LanguageDetector, LanguageDetectorInputProcessor, LegacyStep, LegacyWorkflow, MastraModelOutput, ModerationInputProcessor, ModerationProcessor, PIIDetector, PIIDetectorInputProcessor, PromptInjectionDetector, PromptInjectionDetectorInputProcessor, Run, StructuredOutputProcessor, TripWire, UnicodeNormalizer, UnicodeNormalizerInputProcessor, WhenConditionReturnValue, Workflow, agentToStep, cloneStep, cloneWorkflow, createStep, createWorkflow, getActivePathsAndStatus, getResultActivePaths, getStepResult, getSuspendedPaths, isAgent, isConditionalKey, isErrorEvent, isFinalState, isLimboState, isTransitionEvent, isVariableReference, isWorkflow, loop, mapVariable, mergeChildValue, recursivelyCheckForFinalState, resolveVariables, updateStepInHierarchy, workflowToStep };
|
|
15896
|
-
//# sourceMappingURL=chunk-
|
|
15897
|
-
//# sourceMappingURL=chunk-
|
|
15945
|
+
//# sourceMappingURL=chunk-ZGSS7RCP.js.map
|
|
15946
|
+
//# sourceMappingURL=chunk-ZGSS7RCP.js.map
|