@mastra/core 0.16.1-alpha.0 → 0.16.1-alpha.1

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.
Files changed (110) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/agent/index.cjs +11 -11
  3. package/dist/agent/index.d.ts.map +1 -1
  4. package/dist/agent/index.js +2 -2
  5. package/dist/agent/input-processor/index.cjs +6 -6
  6. package/dist/agent/input-processor/index.js +1 -1
  7. package/dist/agent/message-list/index.d.ts.map +1 -1
  8. package/dist/agent/message-list/prompt/image-utils.d.ts +30 -0
  9. package/dist/agent/message-list/prompt/image-utils.d.ts.map +1 -1
  10. package/dist/agent/types.d.ts +2 -2
  11. package/dist/agent/types.d.ts.map +1 -1
  12. package/dist/ai-tracing/context.d.ts +7 -13
  13. package/dist/ai-tracing/context.d.ts.map +1 -1
  14. package/dist/ai-tracing/index.cjs +32 -36
  15. package/dist/ai-tracing/index.js +1 -1
  16. package/dist/{chunk-WEPWZHE4.js → chunk-2NKNTPFR.js} +49 -5
  17. package/dist/chunk-2NKNTPFR.js.map +1 -0
  18. package/dist/{chunk-4FWIB47J.cjs → chunk-2PWFUEQA.cjs} +4 -4
  19. package/dist/{chunk-4FWIB47J.cjs.map → chunk-2PWFUEQA.cjs.map} +1 -1
  20. package/dist/{chunk-2QDX6OPE.js → chunk-BQ43NQXK.js} +3 -3
  21. package/dist/{chunk-2QDX6OPE.js.map → chunk-BQ43NQXK.js.map} +1 -1
  22. package/dist/{chunk-IUF2ESZH.cjs → chunk-C3R2Q3NN.cjs} +89 -61
  23. package/dist/chunk-C3R2Q3NN.cjs.map +1 -0
  24. package/dist/{chunk-KT4WNDGP.cjs → chunk-D3UG2YLU.cjs} +110 -31
  25. package/dist/chunk-D3UG2YLU.cjs.map +1 -0
  26. package/dist/{chunk-H33WOKEO.js → chunk-DUABZASJ.js} +4 -4
  27. package/dist/{chunk-H33WOKEO.js.map → chunk-DUABZASJ.js.map} +1 -1
  28. package/dist/{chunk-LGJCH6XF.cjs → chunk-DYLYA6HQ.cjs} +12 -12
  29. package/dist/{chunk-LGJCH6XF.cjs.map → chunk-DYLYA6HQ.cjs.map} +1 -1
  30. package/dist/{chunk-N3HXDMF2.js → chunk-GJKJXY3K.js} +3 -3
  31. package/dist/{chunk-N3HXDMF2.js.map → chunk-GJKJXY3K.js.map} +1 -1
  32. package/dist/{chunk-Y6MXP3EN.cjs → chunk-IMDDMIVR.cjs} +6 -6
  33. package/dist/{chunk-Y6MXP3EN.cjs.map → chunk-IMDDMIVR.cjs.map} +1 -1
  34. package/dist/{chunk-6FVCJBBG.cjs → chunk-KB4IEMPV.cjs} +5 -3
  35. package/dist/chunk-KB4IEMPV.cjs.map +1 -0
  36. package/dist/{chunk-G7YM2FA2.cjs → chunk-LZWM7RVY.cjs} +7 -7
  37. package/dist/{chunk-G7YM2FA2.cjs.map → chunk-LZWM7RVY.cjs.map} +1 -1
  38. package/dist/{chunk-YUJ7GETS.js → chunk-OF4TXRIV.js} +3 -3
  39. package/dist/{chunk-YUJ7GETS.js.map → chunk-OF4TXRIV.js.map} +1 -1
  40. package/dist/{chunk-OE3SL5VG.cjs → chunk-SJO2HEVU.cjs} +6 -6
  41. package/dist/{chunk-OE3SL5VG.cjs.map → chunk-SJO2HEVU.cjs.map} +1 -1
  42. package/dist/{chunk-ULA3AGAI.js → chunk-TDLB5JKT.js} +5 -3
  43. package/dist/chunk-TDLB5JKT.js.map +1 -0
  44. package/dist/{chunk-WW62UQPE.js → chunk-U2RCB3FQ.js} +5 -5
  45. package/dist/{chunk-WW62UQPE.js.map → chunk-U2RCB3FQ.js.map} +1 -1
  46. package/dist/{chunk-RT2ETR6A.js → chunk-U3OYPZHX.js} +3 -3
  47. package/dist/{chunk-RT2ETR6A.js.map → chunk-U3OYPZHX.js.map} +1 -1
  48. package/dist/{chunk-UFCYMOYH.cjs → chunk-UGCG7DI3.cjs} +49 -6
  49. package/dist/chunk-UGCG7DI3.cjs.map +1 -0
  50. package/dist/{chunk-MW4CYUSP.js → chunk-UM4XJM3Y.js} +53 -25
  51. package/dist/chunk-UM4XJM3Y.js.map +1 -0
  52. package/dist/{chunk-VMV5VND5.cjs → chunk-WGX5V6DE.cjs} +7 -7
  53. package/dist/{chunk-VMV5VND5.cjs.map → chunk-WGX5V6DE.cjs.map} +1 -1
  54. package/dist/{chunk-4BQBSBQP.js → chunk-YI3AIJJL.js} +109 -30
  55. package/dist/chunk-YI3AIJJL.js.map +1 -0
  56. package/dist/index.cjs +38 -38
  57. package/dist/index.js +7 -7
  58. package/dist/loop/index.cjs +2 -2
  59. package/dist/loop/index.js +1 -1
  60. package/dist/mastra/index.cjs +2 -2
  61. package/dist/mastra/index.js +1 -1
  62. package/dist/memory/index.cjs +4 -4
  63. package/dist/memory/index.js +1 -1
  64. package/dist/network/index.cjs +2 -2
  65. package/dist/network/index.js +1 -1
  66. package/dist/network/vNext/index.cjs +14 -14
  67. package/dist/network/vNext/index.js +2 -2
  68. package/dist/processors/index.cjs +8 -8
  69. package/dist/processors/index.js +2 -2
  70. package/dist/processors/processors/structured-output.d.ts +2 -1
  71. package/dist/processors/processors/structured-output.d.ts.map +1 -1
  72. package/dist/relevance/index.cjs +4 -4
  73. package/dist/relevance/index.js +1 -1
  74. package/dist/scores/index.cjs +8 -8
  75. package/dist/scores/index.js +1 -1
  76. package/dist/storage/domains/observability/inmemory.d.ts.map +1 -1
  77. package/dist/storage/index.cjs +5 -3
  78. package/dist/storage/index.cjs.map +1 -1
  79. package/dist/storage/index.js +3 -1
  80. package/dist/storage/index.js.map +1 -1
  81. package/dist/storage/types.d.ts +2 -0
  82. package/dist/storage/types.d.ts.map +1 -1
  83. package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
  84. package/dist/stream/index.cjs +3 -3
  85. package/dist/stream/index.js +1 -1
  86. package/dist/test-utils/llm-mock.cjs +2 -2
  87. package/dist/test-utils/llm-mock.js +1 -1
  88. package/dist/tools/tool-builder/builder.d.ts.map +1 -1
  89. package/dist/utils.cjs +17 -17
  90. package/dist/utils.js +1 -1
  91. package/dist/workflows/default.d.ts.map +1 -1
  92. package/dist/workflows/evented/index.cjs +10 -10
  93. package/dist/workflows/evented/index.js +1 -1
  94. package/dist/workflows/index.cjs +10 -10
  95. package/dist/workflows/index.js +1 -1
  96. package/dist/workflows/legacy/index.cjs +22 -22
  97. package/dist/workflows/legacy/index.js +1 -1
  98. package/dist/workflows/types.d.ts +3 -0
  99. package/dist/workflows/types.d.ts.map +1 -1
  100. package/dist/workflows/workflow.d.ts +2 -1
  101. package/dist/workflows/workflow.d.ts.map +1 -1
  102. package/package.json +1 -1
  103. package/dist/chunk-4BQBSBQP.js.map +0 -1
  104. package/dist/chunk-6FVCJBBG.cjs.map +0 -1
  105. package/dist/chunk-IUF2ESZH.cjs.map +0 -1
  106. package/dist/chunk-KT4WNDGP.cjs.map +0 -1
  107. package/dist/chunk-MW4CYUSP.js.map +0 -1
  108. package/dist/chunk-UFCYMOYH.cjs.map +0 -1
  109. package/dist/chunk-ULA3AGAI.js.map +0 -1
  110. 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 chunkOE3SL5VG_cjs = require('./chunk-OE3SL5VG.cjs');
7
- var chunkKT4WNDGP_cjs = require('./chunk-KT4WNDGP.cjs');
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 chunk6FVCJBBG_cjs = require('./chunk-6FVCJBBG.cjs');
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 chunkUFCYMOYH_cjs = require('./chunk-UFCYMOYH.cjs');
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 chunkKT4WNDGP_cjs.DefaultGeneratedFile({
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 chunkKT4WNDGP_cjs.DefaultGeneratedFileWithType({
1184
+ file: new chunkD3UG2YLU_cjs.DefaultGeneratedFileWithType({
1185
1185
  data: chunk.payload.data,
1186
1186
  mediaType: chunk.payload.mimeType
1187
1187
  })
@@ -2247,7 +2247,7 @@ var MastraModelOutput = class extends chunkKXCUCBEI_cjs.MastraBase {
2247
2247
  try {
2248
2248
  if (self.processorRunner) {
2249
2249
  self.messageList = await self.processorRunner.runOutputProcessors(self.messageList);
2250
- const outputText = self.messageList.get.response.aiV4.core().map(m => chunkKT4WNDGP_cjs.MessageList.coreContentToString(m.content)).join("\n");
2250
+ const outputText = self.messageList.get.response.aiV4.core().map(m => chunkD3UG2YLU_cjs.MessageList.coreContentToString(m.content)).join("\n");
2251
2251
  const messages = self.messageList.get.response.v2();
2252
2252
  const messagesWithStructuredData = messages.filter(msg => msg.content.metadata && msg.content.metadata.structuredOutput);
2253
2253
  if (messagesWithStructuredData[0] && messagesWithStructuredData[0].content.metadata?.structuredOutput) {
@@ -4203,7 +4203,7 @@ var MastraLLMVNext = class extends chunkKXCUCBEI_cjs.MastraBase {
4203
4203
  }
4204
4204
  });
4205
4205
  try {
4206
- const messageList = new chunkKT4WNDGP_cjs.MessageList({
4206
+ const messageList = new chunkD3UG2YLU_cjs.MessageList({
4207
4207
  threadId,
4208
4208
  resourceId
4209
4209
  });
@@ -4264,7 +4264,7 @@ var MastraLLMVNext = class extends chunkKXCUCBEI_cjs.MastraBase {
4264
4264
  this.logger.warn("Rate limit approaching, waiting 10 seconds", {
4265
4265
  runId
4266
4266
  });
4267
- await chunk6FVCJBBG_cjs.delay(10 * 1e3);
4267
+ await chunkKB4IEMPV_cjs.delay(10 * 1e3);
4268
4268
  }
4269
4269
  },
4270
4270
  onFinish: async props => {
@@ -4339,14 +4339,18 @@ var StructuredOutputProcessor = class {
4339
4339
  structuringAgent;
4340
4340
  errorStrategy;
4341
4341
  fallbackValue;
4342
- constructor(options) {
4342
+ constructor(options, fallbackModel) {
4343
4343
  this.schema = options.schema;
4344
4344
  this.errorStrategy = options.errorStrategy ?? "strict";
4345
4345
  this.fallbackValue = options.fallbackValue;
4346
+ const modelToUse = options.model || fallbackModel;
4347
+ if (!modelToUse) {
4348
+ throw new Error("StructuredOutputProcessor requires a model to be provided either in options or as fallback");
4349
+ }
4346
4350
  this.structuringAgent = new exports.Agent({
4347
4351
  name: "structured-output-structurer",
4348
4352
  instructions: options.instructions || this.generateInstructions(),
4349
- model: options.model
4353
+ model: modelToUse
4350
4354
  });
4351
4355
  }
4352
4356
  async processOutputResult(args) {
@@ -5159,7 +5163,7 @@ var Machine = class extends EventEmitter__default.default {
5159
5163
  const logger = this.logger;
5160
5164
  let mastraProxy = void 0;
5161
5165
  if (this.#mastra) {
5162
- mastraProxy = chunk6FVCJBBG_cjs.createMastraProxy({
5166
+ mastraProxy = chunkKB4IEMPV_cjs.createMastraProxy({
5163
5167
  mastra: this.#mastra,
5164
5168
  logger
5165
5169
  });
@@ -9328,13 +9332,13 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9328
9332
  this.logger.error(mastraError.toString());
9329
9333
  throw mastraError;
9330
9334
  }
9331
- return chunk6FVCJBBG_cjs.ensureToolProperties(this.#tools);
9335
+ return chunkKB4IEMPV_cjs.ensureToolProperties(this.#tools);
9332
9336
  }
9333
9337
  getTools({
9334
9338
  runtimeContext = new chunkGPWMM745_cjs.RuntimeContext()
9335
9339
  } = {}) {
9336
9340
  if (typeof this.#tools !== "function") {
9337
- return chunk6FVCJBBG_cjs.ensureToolProperties(this.#tools);
9341
+ return chunkKB4IEMPV_cjs.ensureToolProperties(this.#tools);
9338
9342
  }
9339
9343
  const result = this.#tools({
9340
9344
  runtimeContext,
@@ -9355,7 +9359,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9355
9359
  this.logger.error(mastraError.toString());
9356
9360
  throw mastraError;
9357
9361
  }
9358
- return chunk6FVCJBBG_cjs.ensureToolProperties(tools);
9362
+ return chunkKB4IEMPV_cjs.ensureToolProperties(tools);
9359
9363
  });
9360
9364
  }
9361
9365
  get llm() {
@@ -9399,7 +9403,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9399
9403
  mastra: this.#mastra
9400
9404
  });
9401
9405
  } else {
9402
- llm = new chunkOE3SL5VG_cjs.MastraLLMV1({
9406
+ llm = new chunkSJO2HEVU_cjs.MastraLLMV1({
9403
9407
  model: resolvedModel,
9404
9408
  mastra: this.#mastra
9405
9409
  });
@@ -9515,7 +9519,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9515
9519
  runtimeContext,
9516
9520
  model
9517
9521
  });
9518
- const normMessage = new chunkKT4WNDGP_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
9522
+ const normMessage = new chunkD3UG2YLU_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
9519
9523
  if (!normMessage) {
9520
9524
  throw new Error(`Could not generate title from input ${JSON.stringify(message)}`);
9521
9525
  }
@@ -9574,7 +9578,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9574
9578
  async genTitle(userMessage, runtimeContext, tracingContext, model, instructions) {
9575
9579
  try {
9576
9580
  if (userMessage) {
9577
- const normMessage = new chunkKT4WNDGP_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
9581
+ const normMessage = new chunkD3UG2YLU_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
9578
9582
  if (normMessage) {
9579
9583
  return await this.generateTitleFromUserMessage({
9580
9584
  message: normMessage,
@@ -9600,7 +9604,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9600
9604
  runId,
9601
9605
  userMessages,
9602
9606
  systemMessage,
9603
- messageList = new chunkKT4WNDGP_cjs.MessageList({
9607
+ messageList = new chunkD3UG2YLU_cjs.MessageList({
9604
9608
  threadId,
9605
9609
  resourceId
9606
9610
  }),
@@ -9655,7 +9659,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9655
9659
  systemMessage: systemMessages,
9656
9660
  memorySystemMessage: memorySystemMessage || void 0
9657
9661
  });
9658
- const returnList = new chunkKT4WNDGP_cjs.MessageList().addSystem(systemMessages).add(processedMemoryMessages, "memory").add(newMessages, "user");
9662
+ const returnList = new chunkD3UG2YLU_cjs.MessageList().addSystem(systemMessages).add(processedMemoryMessages, "memory").add(newMessages, "user");
9659
9663
  return {
9660
9664
  threadId: thread.id,
9661
9665
  messages: returnList.get.all.prompt()
@@ -9700,7 +9704,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9700
9704
  runtimeContext
9701
9705
  }) : this.model
9702
9706
  };
9703
- const convertedToCoreTool = chunk6FVCJBBG_cjs.makeCoreTool(toolObj, options);
9707
+ const convertedToCoreTool = chunkKB4IEMPV_cjs.makeCoreTool(toolObj, options);
9704
9708
  convertedMemoryTools[toolName] = convertedToCoreTool;
9705
9709
  }
9706
9710
  }
@@ -9871,7 +9875,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9871
9875
  }) : this.model,
9872
9876
  writableStream
9873
9877
  };
9874
- return [k, chunk6FVCJBBG_cjs.makeCoreTool(tool, options)];
9878
+ return [k, chunkKB4IEMPV_cjs.makeCoreTool(tool, options)];
9875
9879
  }));
9876
9880
  const assignedToolEntriesConverted = Object.fromEntries(assignedCoreToolEntries.filter(entry => Boolean(entry)));
9877
9881
  toolsForRequest = {
@@ -9915,7 +9919,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9915
9919
  runtimeContext
9916
9920
  }) : this.model
9917
9921
  };
9918
- const convertedToCoreTool = chunk6FVCJBBG_cjs.makeCoreTool(toolObj, options, "toolset");
9922
+ const convertedToCoreTool = chunkKB4IEMPV_cjs.makeCoreTool(toolObj, options, "toolset");
9919
9923
  toolsForRequest[toolName] = convertedToCoreTool;
9920
9924
  }
9921
9925
  }
@@ -9960,7 +9964,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9960
9964
  runtimeContext
9961
9965
  }) : this.model
9962
9966
  };
9963
- const convertedToCoreTool = chunk6FVCJBBG_cjs.makeCoreTool(rest, options, "client-tool");
9967
+ const convertedToCoreTool = chunkKB4IEMPV_cjs.makeCoreTool(rest, options, "client-tool");
9964
9968
  toolsForRequest[toolName] = convertedToCoreTool;
9965
9969
  }
9966
9970
  }
@@ -10027,6 +10031,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
10027
10031
  const streamResult = run.streamVNext({
10028
10032
  inputData: context,
10029
10033
  runtimeContext,
10034
+ tracingContext: innerTracingContext,
10030
10035
  format
10031
10036
  });
10032
10037
  if (writer) {
@@ -10074,7 +10079,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
10074
10079
  }) : this.model,
10075
10080
  tracingContext
10076
10081
  };
10077
- convertedWorkflowTools[workflowName] = chunk6FVCJBBG_cjs.makeCoreTool(toolObj, options);
10082
+ convertedWorkflowTools[workflowName] = chunkKB4IEMPV_cjs.makeCoreTool(toolObj, options);
10078
10083
  }
10079
10084
  }
10080
10085
  return convertedWorkflowTools;
@@ -10094,7 +10099,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
10094
10099
  let mastraProxy = void 0;
10095
10100
  const logger = this.logger;
10096
10101
  if (this.#mastra) {
10097
- mastraProxy = chunk6FVCJBBG_cjs.createMastraProxy({
10102
+ mastraProxy = chunkKB4IEMPV_cjs.createMastraProxy({
10098
10103
  mastra: this.#mastra,
10099
10104
  logger
10100
10105
  });
@@ -10236,7 +10241,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
10236
10241
  runId
10237
10242
  });
10238
10243
  }
10239
- const agentAISpan = chunkUFCYMOYH_cjs.getOrCreateSpan({
10244
+ const agentAISpan = chunkUGCG7DI3_cjs.getOrCreateSpan({
10240
10245
  type: "agent_run" /* AGENT_RUN */,
10241
10246
  name: `agent run: '${this.id}'`,
10242
10247
  input: messages,
@@ -10283,7 +10288,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
10283
10288
  writableStream,
10284
10289
  methodType
10285
10290
  });
10286
- const messageList = new chunkKT4WNDGP_cjs.MessageList({
10291
+ const messageList = new chunkD3UG2YLU_cjs.MessageList({
10287
10292
  threadId,
10288
10293
  resourceId,
10289
10294
  generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
@@ -10373,7 +10378,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
10373
10378
  let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread || hasResourceScopeSemanticRecall ? this.getMemoryMessages({
10374
10379
  resourceId,
10375
10380
  threadId: threadObject.id,
10376
- vectorMessageSearch: new chunkKT4WNDGP_cjs.MessageList().add(messages, `user`).getLatestUserContent() || "",
10381
+ vectorMessageSearch: new chunkD3UG2YLU_cjs.MessageList().add(messages, `user`).getLatestUserContent() || "",
10377
10382
  memoryConfig,
10378
10383
  runtimeContext
10379
10384
  }) : [], memory.getSystemMessage({
@@ -10396,7 +10401,7 @@ The following messages were remembered from a different conversation:
10396
10401
  <remembered_from_other_conversation>
10397
10402
  ${(() => {
10398
10403
  let result = ``;
10399
- const messages2 = new chunkKT4WNDGP_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
10404
+ const messages2 = new chunkD3UG2YLU_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
10400
10405
  let lastYmd = null;
10401
10406
  for (const msg of messages2) {
10402
10407
  const date = msg.createdAt;
@@ -10449,7 +10454,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
10449
10454
  systemMessage,
10450
10455
  memorySystemMessage: memorySystemMessage || void 0
10451
10456
  });
10452
- const processedList = new chunkKT4WNDGP_cjs.MessageList({
10457
+ const processedList = new chunkD3UG2YLU_cjs.MessageList({
10453
10458
  threadId: threadObject.id,
10454
10459
  resourceId,
10455
10460
  generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
@@ -10505,7 +10510,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
10505
10510
  result: resToLog,
10506
10511
  threadId
10507
10512
  });
10508
- const messageListResponses = new chunkKT4WNDGP_cjs.MessageList({
10513
+ const messageListResponses = new chunkD3UG2YLU_cjs.MessageList({
10509
10514
  threadId,
10510
10515
  resourceId,
10511
10516
  generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
@@ -10963,7 +10968,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
10963
10968
  const instructions = options.instructions || (await this.getInstructions({
10964
10969
  runtimeContext
10965
10970
  }));
10966
- const agentAISpan = chunkUFCYMOYH_cjs.getOrCreateSpan({
10971
+ const agentAISpan = chunkUGCG7DI3_cjs.getOrCreateSpan({
10967
10972
  type: "agent_run" /* AGENT_RUN */,
10968
10973
  name: `agent run: '${this.id}'`,
10969
10974
  input: options.messages,
@@ -11039,12 +11044,12 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
11039
11044
  resourceId,
11040
11045
  runId,
11041
11046
  runtimeContext,
11042
- writableStream: options.writableStream,
11043
- methodType,
11044
- format,
11045
11047
  tracingContext: {
11046
11048
  currentSpan: agentAISpan
11047
- }
11049
+ },
11050
+ writableStream: options.writableStream,
11051
+ methodType,
11052
+ format
11048
11053
  });
11049
11054
  return {
11050
11055
  convertedTools
@@ -11066,7 +11071,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
11066
11071
  tracingContext
11067
11072
  }) => {
11068
11073
  const thread = threadFromArgs;
11069
- const messageList = new chunkKT4WNDGP_cjs.MessageList({
11074
+ const messageList = new chunkD3UG2YLU_cjs.MessageList({
11070
11075
  threadId: thread?.id,
11071
11076
  resourceId,
11072
11077
  generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
@@ -11151,7 +11156,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
11151
11156
  let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread || hasResourceScopeSemanticRecall ? this.getMemoryMessages({
11152
11157
  resourceId,
11153
11158
  threadId: threadObject.id,
11154
- vectorMessageSearch: new chunkKT4WNDGP_cjs.MessageList().add(options.messages, `user`).getLatestUserContent() || "",
11159
+ vectorMessageSearch: new chunkD3UG2YLU_cjs.MessageList().add(options.messages, `user`).getLatestUserContent() || "",
11155
11160
  memoryConfig,
11156
11161
  runtimeContext
11157
11162
  }) : [], memory.getSystemMessage({
@@ -11174,7 +11179,7 @@ The following messages were remembered from a different conversation:
11174
11179
  <remembered_from_other_conversation>
11175
11180
  ${(() => {
11176
11181
  let result2 = ``;
11177
- const messages = new chunkKT4WNDGP_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
11182
+ const messages = new chunkD3UG2YLU_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
11178
11183
  let lastYmd = null;
11179
11184
  for (const msg of messages) {
11180
11185
  const date = msg.createdAt;
@@ -11226,7 +11231,7 @@ the following messages are from ${ymd}
11226
11231
  systemMessage,
11227
11232
  memorySystemMessage: memorySystemMessage || void 0
11228
11233
  });
11229
- const processedList = new chunkKT4WNDGP_cjs.MessageList({
11234
+ const processedList = new chunkD3UG2YLU_cjs.MessageList({
11230
11235
  threadId: threadObject.id,
11231
11236
  resourceId,
11232
11237
  generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
@@ -11379,7 +11384,10 @@ the following messages are from ${ymd}
11379
11384
  runtimeContext: result2.runtimeContext
11380
11385
  }) : this.#outputProcessors : []);
11381
11386
  if (options.structuredOutput) {
11382
- const structuredProcessor = new StructuredOutputProcessor(options.structuredOutput);
11387
+ const agentModel = await this.getModel({
11388
+ runtimeContext: result2.runtimeContext
11389
+ });
11390
+ const structuredProcessor = new StructuredOutputProcessor(options.structuredOutput, agentModel);
11383
11391
  effectiveOutputProcessors = effectiveOutputProcessors ? [...effectiveOutputProcessors, structuredProcessor] : [structuredProcessor];
11384
11392
  }
11385
11393
  const loopOptions = {
@@ -11436,7 +11444,9 @@ the following messages are from ${ymd}
11436
11444
  await options?.onFinish?.({
11437
11445
  ...result2,
11438
11446
  runId,
11439
- messages: messageList.get.response.aiV5.model()
11447
+ messages: messageList.get.response.aiV5.model(),
11448
+ usage: payload.usage,
11449
+ totalUsage: payload.totalUsage
11440
11450
  });
11441
11451
  },
11442
11452
  onStepFinish: result2.onStepFinish
@@ -11747,7 +11757,10 @@ the following messages are from ${ymd}
11747
11757
  };
11748
11758
  let finalOutputProcessors = mergedGenerateOptions.outputProcessors;
11749
11759
  if (mergedGenerateOptions.structuredOutput) {
11750
- const structuredProcessor = new StructuredOutputProcessor(mergedGenerateOptions.structuredOutput);
11760
+ const agentModel = await this.getModel({
11761
+ runtimeContext: mergedGenerateOptions.runtimeContext
11762
+ });
11763
+ const structuredProcessor = new StructuredOutputProcessor(mergedGenerateOptions.structuredOutput, agentModel);
11751
11764
  finalOutputProcessors = finalOutputProcessors ? [...finalOutputProcessors, structuredProcessor] : [structuredProcessor];
11752
11765
  }
11753
11766
  if (!output || experimental_output) {
@@ -11760,7 +11773,7 @@ the following messages are from ${ymd}
11760
11773
  runtimeContext: mergedGenerateOptions.runtimeContext || new chunkGPWMM745_cjs.RuntimeContext(),
11761
11774
  tracingContext,
11762
11775
  outputProcessorOverrides: finalOutputProcessors,
11763
- messageList: new chunkKT4WNDGP_cjs.MessageList({
11776
+ messageList: new chunkD3UG2YLU_cjs.MessageList({
11764
11777
  threadId: llmOptions.threadId || "",
11765
11778
  resourceId: llmOptions.resourceId || ""
11766
11779
  }).add({
@@ -11853,7 +11866,7 @@ the following messages are from ${ymd}
11853
11866
  const outputProcessorResult = await this.__runOutputProcessors({
11854
11867
  runtimeContext: mergedGenerateOptions.runtimeContext || new chunkGPWMM745_cjs.RuntimeContext(),
11855
11868
  tracingContext,
11856
- messageList: new chunkKT4WNDGP_cjs.MessageList({
11869
+ messageList: new chunkD3UG2YLU_cjs.MessageList({
11857
11870
  threadId: llmOptions.threadId || "",
11858
11871
  resourceId: llmOptions.resourceId || ""
11859
11872
  }).add({
@@ -12313,9 +12326,9 @@ var MastraWorkflowStream = class extends web.ReadableStream {
12313
12326
  deferredPromise.reject = reject;
12314
12327
  });
12315
12328
  const updateUsageCount = usage => {
12316
- this.#usageCount.promptTokens += parseInt(usage.promptTokens?.toString() ?? "0", 10);
12317
- this.#usageCount.completionTokens += parseInt(usage.completionTokens?.toString() ?? "0", 10);
12318
- this.#usageCount.totalTokens += parseInt(usage.totalTokens?.toString() ?? "0", 10);
12329
+ this.#usageCount.promptTokens += parseInt(usage?.promptTokens?.toString() ?? "0", 10);
12330
+ this.#usageCount.completionTokens += parseInt(usage?.completionTokens?.toString() ?? "0", 10);
12331
+ this.#usageCount.totalTokens += parseInt(usage?.totalTokens?.toString() ?? "0", 10);
12319
12332
  };
12320
12333
  super({
12321
12334
  start: async controller => {
@@ -12323,7 +12336,9 @@ var MastraWorkflowStream = class extends web.ReadableStream {
12323
12336
  write: chunk => {
12324
12337
  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
12338
  const finishPayload = chunk.payload?.output.payload;
12326
- updateUsageCount(finishPayload.usage);
12339
+ if (finishPayload) {
12340
+ updateUsageCount(finishPayload.usage);
12341
+ }
12327
12342
  }
12328
12343
  controller.enqueue(chunk);
12329
12344
  }
@@ -12335,9 +12350,14 @@ var MastraWorkflowStream = class extends web.ReadableStream {
12335
12350
  payload: {}
12336
12351
  });
12337
12352
  const stream = await createStream(writer);
12353
+ let workflowStatus = "success";
12338
12354
  for await (const chunk of stream) {
12339
- if (chunk.type === "step-finish") {
12355
+ if (chunk.type === "step-finish" && chunk.payload.usage) {
12340
12356
  updateUsageCount(chunk.payload.usage);
12357
+ } else if (chunk.type === "workflow-canceled") {
12358
+ workflowStatus = "canceled";
12359
+ } else if (chunk.type === "workflow-step-result" && chunk.payload.status === "failed") {
12360
+ workflowStatus = "failed";
12341
12361
  }
12342
12362
  controller.enqueue(chunk);
12343
12363
  }
@@ -12346,9 +12366,7 @@ var MastraWorkflowStream = class extends web.ReadableStream {
12346
12366
  runId: run.runId,
12347
12367
  from: "WORKFLOW" /* WORKFLOW */,
12348
12368
  payload: {
12349
- stepResult: {
12350
- reason: "stop"
12351
- },
12369
+ workflowStatus,
12352
12370
  output: {
12353
12371
  usage: this.#usageCount
12354
12372
  },
@@ -12517,7 +12535,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
12517
12535
  } = retryConfig ?? {};
12518
12536
  const steps = graph.steps;
12519
12537
  this.runCounts.clear();
12520
- const workflowAISpan = chunkUFCYMOYH_cjs.getOrCreateSpan({
12538
+ const workflowAISpan = chunkUGCG7DI3_cjs.getOrCreateSpan({
12521
12539
  type: "workflow_run" /* WORKFLOW_RUN */,
12522
12540
  name: `workflow run: '${workflowId}'`,
12523
12541
  input,
@@ -13030,7 +13048,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
13030
13048
  const result = await runStep({
13031
13049
  runId,
13032
13050
  workflowId,
13033
- mastra: this.mastra ? chunkUFCYMOYH_cjs.wrapMastra(this.mastra, innerTracingContext) : void 0,
13051
+ mastra: this.mastra ? chunkUGCG7DI3_cjs.wrapMastra(this.mastra, innerTracingContext) : void 0,
13034
13052
  runtimeContext,
13035
13053
  inputData: prevOutput,
13036
13054
  runCount: this.getOrGenerateRunCount(step.id),
@@ -13614,7 +13632,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
13614
13632
  const evalSpan = loopSpan?.createChildSpan({
13615
13633
  type: "workflow_conditional_eval" /* WORKFLOW_CONDITIONAL_EVAL */,
13616
13634
  name: `condition: ${entry.loopType}`,
13617
- input: chunkUFCYMOYH_cjs.selectFields(result.output, ["stepResult", "output.text", "output.object", "messages"]),
13635
+ input: chunkUGCG7DI3_cjs.selectFields(result.output, ["stepResult", "output.text", "output.object", "messages"]),
13618
13636
  attributes: {
13619
13637
  conditionIndex: iteration
13620
13638
  }
@@ -14482,6 +14500,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
14482
14500
  workflowStatus: execResults.status === "success" ? "running" : execResults.status,
14483
14501
  runtimeContext
14484
14502
  });
14503
+ if (execResults.status === "canceled") {
14504
+ await emitter.emit("watch-v2", {
14505
+ type: "workflow-canceled",
14506
+ payload: {}
14507
+ });
14508
+ }
14485
14509
  return {
14486
14510
  result: execResults,
14487
14511
  stepResults,
@@ -15186,6 +15210,8 @@ var Workflow = class extends chunkKXCUCBEI_cjs.MastraBase {
15186
15210
  }
15187
15211
  return scorers;
15188
15212
  }
15213
+ // This method should only be called internally for nested workflow execution, as well as from mastra server handlers
15214
+ // To run a workflow use `.createRunAsync` and then `.start` or `.resume`
15189
15215
  async execute({
15190
15216
  runId,
15191
15217
  inputData,
@@ -15619,12 +15645,13 @@ var Run = class {
15619
15645
  streamVNext({
15620
15646
  inputData,
15621
15647
  runtimeContext,
15648
+ tracingContext,
15622
15649
  format
15623
15650
  } = {}) {
15624
15651
  this.closeStreamAction = async () => {};
15625
15652
  return new MastraWorkflowStream({
15626
15653
  run: this,
15627
- createStream: writer => {
15654
+ createStream: () => {
15628
15655
  const {
15629
15656
  readable,
15630
15657
  writable
@@ -15642,7 +15669,7 @@ var Run = class {
15642
15669
  return;
15643
15670
  }
15644
15671
  isWriting = true;
15645
- let watchWriter = writer.getWriter();
15672
+ let watchWriter = writable.getWriter();
15646
15673
  try {
15647
15674
  for (const chunk of chunkToWrite) {
15648
15675
  await watchWriter.write(chunk);
@@ -15680,6 +15707,7 @@ var Run = class {
15680
15707
  const executionResults = this._start({
15681
15708
  inputData,
15682
15709
  runtimeContext,
15710
+ tracingContext,
15683
15711
  writableStream: writable,
15684
15712
  format
15685
15713
  }).then(result => {
@@ -15963,5 +15991,5 @@ exports.recursivelyCheckForFinalState = recursivelyCheckForFinalState;
15963
15991
  exports.resolveVariables = resolveVariables;
15964
15992
  exports.updateStepInHierarchy = updateStepInHierarchy;
15965
15993
  exports.workflowToStep = workflowToStep;
15966
- //# sourceMappingURL=chunk-IUF2ESZH.cjs.map
15967
- //# sourceMappingURL=chunk-IUF2ESZH.cjs.map
15994
+ //# sourceMappingURL=chunk-C3R2Q3NN.cjs.map
15995
+ //# sourceMappingURL=chunk-C3R2Q3NN.cjs.map