@mastra/core 0.16.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 (143) hide show
  1. package/CHANGELOG.md +40 -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-DRMT4EQA.cjs → chunk-2PWFUEQA.cjs} +4 -4
  19. package/dist/{chunk-DRMT4EQA.cjs.map → chunk-2PWFUEQA.cjs.map} +1 -1
  20. package/dist/{chunk-3CJXUAA2.cjs → chunk-33GDW3SI.cjs} +2 -4
  21. package/dist/chunk-33GDW3SI.cjs.map +1 -0
  22. package/dist/{chunk-HGYL2SSF.js → chunk-BQ43NQXK.js} +3 -3
  23. package/dist/{chunk-HGYL2SSF.js.map → chunk-BQ43NQXK.js.map} +1 -1
  24. package/dist/{chunk-7GYN2OE3.cjs → chunk-C3R2Q3NN.cjs} +153 -101
  25. package/dist/chunk-C3R2Q3NN.cjs.map +1 -0
  26. package/dist/{chunk-JTU7FZ5O.js → chunk-CWK46GAF.js} +2 -4
  27. package/dist/chunk-CWK46GAF.js.map +1 -0
  28. package/dist/{chunk-SIKEQ32R.cjs → chunk-D3UG2YLU.cjs} +137 -33
  29. package/dist/chunk-D3UG2YLU.cjs.map +1 -0
  30. package/dist/{chunk-EU3ADOKK.js → chunk-DUABZASJ.js} +4 -4
  31. package/dist/{chunk-EU3ADOKK.js.map → chunk-DUABZASJ.js.map} +1 -1
  32. package/dist/{chunk-YEZD4ZLX.cjs → chunk-DYLYA6HQ.cjs} +12 -12
  33. package/dist/{chunk-YEZD4ZLX.cjs.map → chunk-DYLYA6HQ.cjs.map} +1 -1
  34. package/dist/{chunk-JT2QXHUD.js → chunk-GJKJXY3K.js} +3 -3
  35. package/dist/{chunk-JT2QXHUD.js.map → chunk-GJKJXY3K.js.map} +1 -1
  36. package/dist/chunk-GXSERFAG.js +3 -0
  37. package/dist/{chunk-S43VACTO.js.map → chunk-GXSERFAG.js.map} +1 -1
  38. package/dist/{chunk-TCYQAAIT.cjs → chunk-IMDDMIVR.cjs} +6 -6
  39. package/dist/{chunk-TCYQAAIT.cjs.map → chunk-IMDDMIVR.cjs.map} +1 -1
  40. package/dist/{chunk-LVGGMWSE.cjs → chunk-KB4IEMPV.cjs} +6 -4
  41. package/dist/chunk-KB4IEMPV.cjs.map +1 -0
  42. package/dist/{chunk-SLDGELU7.cjs → chunk-LZWM7RVY.cjs} +7 -7
  43. package/dist/{chunk-SLDGELU7.cjs.map → chunk-LZWM7RVY.cjs.map} +1 -1
  44. package/dist/{chunk-MMYGYTJK.js → chunk-OF4TXRIV.js} +3 -3
  45. package/dist/{chunk-MMYGYTJK.js.map → chunk-OF4TXRIV.js.map} +1 -1
  46. package/dist/{chunk-MNDKBEEQ.cjs → chunk-SJO2HEVU.cjs} +6 -6
  47. package/dist/{chunk-MNDKBEEQ.cjs.map → chunk-SJO2HEVU.cjs.map} +1 -1
  48. package/dist/{chunk-WWQ3QRPF.js → chunk-TDLB5JKT.js} +6 -4
  49. package/dist/chunk-TDLB5JKT.js.map +1 -0
  50. package/dist/{chunk-D2Y5SXZN.js → chunk-U2RCB3FQ.js} +5 -5
  51. package/dist/{chunk-D2Y5SXZN.js.map → chunk-U2RCB3FQ.js.map} +1 -1
  52. package/dist/{chunk-A5VGUE2H.js → chunk-U3OYPZHX.js} +3 -3
  53. package/dist/{chunk-A5VGUE2H.js.map → chunk-U3OYPZHX.js.map} +1 -1
  54. package/dist/{chunk-UFCYMOYH.cjs → chunk-UGCG7DI3.cjs} +49 -6
  55. package/dist/chunk-UGCG7DI3.cjs.map +1 -0
  56. package/dist/{chunk-YILDTNQM.js → chunk-UM4XJM3Y.js} +118 -66
  57. package/dist/chunk-UM4XJM3Y.js.map +1 -0
  58. package/dist/{chunk-2BFCQRWV.cjs → chunk-WGX5V6DE.cjs} +7 -7
  59. package/dist/{chunk-2BFCQRWV.cjs.map → chunk-WGX5V6DE.cjs.map} +1 -1
  60. package/dist/chunk-X4RMXTXF.cjs +4 -0
  61. package/dist/{chunk-IHVB4C5U.cjs.map → chunk-X4RMXTXF.cjs.map} +1 -1
  62. package/dist/{chunk-HF7HXOCC.js → chunk-YI3AIJJL.js} +136 -32
  63. package/dist/chunk-YI3AIJJL.js.map +1 -0
  64. package/dist/index.cjs +43 -43
  65. package/dist/index.js +9 -9
  66. package/dist/llm/model/model.loop.d.ts.map +1 -1
  67. package/dist/loop/index.cjs +2 -2
  68. package/dist/loop/index.js +1 -1
  69. package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
  70. package/dist/mastra/index.cjs +2 -2
  71. package/dist/mastra/index.js +1 -1
  72. package/dist/mcp/index.cjs +4 -0
  73. package/dist/mcp/index.cjs.map +1 -1
  74. package/dist/mcp/index.d.ts +3 -1
  75. package/dist/mcp/index.d.ts.map +1 -1
  76. package/dist/mcp/index.js +4 -0
  77. package/dist/mcp/index.js.map +1 -1
  78. package/dist/memory/index.cjs +4 -4
  79. package/dist/memory/index.js +1 -1
  80. package/dist/network/index.cjs +2 -2
  81. package/dist/network/index.js +1 -1
  82. package/dist/network/vNext/index.cjs +14 -14
  83. package/dist/network/vNext/index.js +2 -2
  84. package/dist/processors/index.cjs +8 -8
  85. package/dist/processors/index.js +2 -2
  86. package/dist/processors/processors/structured-output.d.ts +2 -1
  87. package/dist/processors/processors/structured-output.d.ts.map +1 -1
  88. package/dist/relevance/index.cjs +4 -4
  89. package/dist/relevance/index.js +1 -1
  90. package/dist/scores/index.cjs +8 -8
  91. package/dist/scores/index.js +1 -1
  92. package/dist/storage/base.d.ts.map +1 -1
  93. package/dist/storage/domains/observability/inmemory.d.ts.map +1 -1
  94. package/dist/storage/index.cjs +11 -9
  95. package/dist/storage/index.cjs.map +1 -1
  96. package/dist/storage/index.js +5 -3
  97. package/dist/storage/index.js.map +1 -1
  98. package/dist/storage/types.d.ts +2 -0
  99. package/dist/storage/types.d.ts.map +1 -1
  100. package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
  101. package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
  102. package/dist/stream/aisdk/v5/model-supports.d.ts +25 -0
  103. package/dist/stream/aisdk/v5/model-supports.d.ts.map +1 -0
  104. package/dist/stream/base/output-format-handlers.d.ts.map +1 -1
  105. package/dist/stream/index.cjs +3 -3
  106. package/dist/stream/index.js +1 -1
  107. package/dist/test-utils/llm-mock.cjs +2 -2
  108. package/dist/test-utils/llm-mock.js +1 -1
  109. package/dist/tools/index.cjs +0 -4
  110. package/dist/tools/index.d.ts +0 -1
  111. package/dist/tools/index.d.ts.map +1 -1
  112. package/dist/tools/index.js +1 -1
  113. package/dist/tools/tool-builder/builder.d.ts.map +1 -1
  114. package/dist/tools/types.d.ts +1 -1
  115. package/dist/tools/types.d.ts.map +1 -1
  116. package/dist/utils.cjs +17 -17
  117. package/dist/utils.d.ts +1 -1
  118. package/dist/utils.d.ts.map +1 -1
  119. package/dist/utils.js +1 -1
  120. package/dist/workflows/default.d.ts.map +1 -1
  121. package/dist/workflows/evented/index.cjs +10 -10
  122. package/dist/workflows/evented/index.js +1 -1
  123. package/dist/workflows/index.cjs +10 -10
  124. package/dist/workflows/index.js +1 -1
  125. package/dist/workflows/legacy/index.cjs +22 -22
  126. package/dist/workflows/legacy/index.js +1 -1
  127. package/dist/workflows/types.d.ts +3 -0
  128. package/dist/workflows/types.d.ts.map +1 -1
  129. package/dist/workflows/workflow.d.ts +4 -2
  130. package/dist/workflows/workflow.d.ts.map +1 -1
  131. package/package.json +3 -2
  132. package/dist/chunk-3CJXUAA2.cjs.map +0 -1
  133. package/dist/chunk-7GYN2OE3.cjs.map +0 -1
  134. package/dist/chunk-HF7HXOCC.js.map +0 -1
  135. package/dist/chunk-IHVB4C5U.cjs +0 -4
  136. package/dist/chunk-JTU7FZ5O.js.map +0 -1
  137. package/dist/chunk-LVGGMWSE.cjs.map +0 -1
  138. package/dist/chunk-S43VACTO.js +0 -3
  139. package/dist/chunk-SIKEQ32R.cjs.map +0 -1
  140. package/dist/chunk-UFCYMOYH.cjs.map +0 -1
  141. package/dist/chunk-WEPWZHE4.js.map +0 -1
  142. package/dist/chunk-WWQ3QRPF.js.map +0 -1
  143. package/dist/chunk-YILDTNQM.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 chunkMNDKBEEQ_cjs = require('./chunk-MNDKBEEQ.cjs');
7
- var chunkSIKEQ32R_cjs = require('./chunk-SIKEQ32R.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 chunkLVGGMWSE_cjs = require('./chunk-LVGGMWSE.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 chunkSIKEQ32R_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 chunkSIKEQ32R_cjs.DefaultGeneratedFileWithType({
1184
+ file: new chunkD3UG2YLU_cjs.DefaultGeneratedFileWithType({
1185
1185
  data: chunk.payload.data,
1186
1186
  mediaType: chunk.payload.mimeType
1187
1187
  })
@@ -1641,22 +1641,32 @@ var ObjectFormatHandler = class extends BaseFormatHandler {
1641
1641
  shouldEmit: false
1642
1642
  };
1643
1643
  }
1644
- async validateAndTransformFinal(finalValue) {
1645
- if (!finalValue) {
1644
+ async validateAndTransformFinal(finalRawValue) {
1645
+ if (!finalRawValue) {
1646
1646
  return {
1647
1647
  success: false,
1648
1648
  error: new Error("No object generated: could not parse the response.")
1649
1649
  };
1650
1650
  }
1651
+ let rawValue = finalRawValue;
1652
+ if (typeof finalRawValue === "string" && finalRawValue?.includes?.("```json")) {
1653
+ const match = finalRawValue.match(/```json\s*\n?([\s\S]*?)\n?\s*```/);
1654
+ if (match && match[1]) {
1655
+ rawValue = match[1].trim();
1656
+ }
1657
+ }
1658
+ const {
1659
+ value
1660
+ } = await aiV5.parsePartialJson(rawValue);
1651
1661
  if (!this.schema) {
1652
1662
  return {
1653
1663
  success: true,
1654
- value: finalValue
1664
+ value
1655
1665
  };
1656
1666
  }
1657
1667
  try {
1658
1668
  const result = await safeValidateTypes({
1659
- value: finalValue,
1669
+ value,
1660
1670
  schema: this.schema
1661
1671
  });
1662
1672
  if (result.success) {
@@ -1822,7 +1832,17 @@ var EnumFormatHandler = class extends BaseFormatHandler {
1822
1832
  shouldEmit: false
1823
1833
  };
1824
1834
  }
1825
- async validateAndTransformFinal(finalValue) {
1835
+ async validateAndTransformFinal(rawFinalValue) {
1836
+ const {
1837
+ value
1838
+ } = await aiV5.parsePartialJson(rawFinalValue);
1839
+ if (!(typeof value === "object" && value !== null && "result" in value)) {
1840
+ return {
1841
+ success: false,
1842
+ error: new Error("Invalid enum format: expected object with result property")
1843
+ };
1844
+ }
1845
+ const finalValue = value.result;
1826
1846
  if (!finalValue || typeof finalValue !== "object" || typeof finalValue.result !== "string") {
1827
1847
  return {
1828
1848
  success: false,
@@ -1928,7 +1948,7 @@ function createObjectStreamTransformer({
1928
1948
  onFinish(void 0);
1929
1949
  return;
1930
1950
  }
1931
- const finalResult = await handler.validateAndTransformFinal(previousObject);
1951
+ const finalResult = await handler.validateAndTransformFinal(accumulatedText);
1932
1952
  if (!finalResult.success) {
1933
1953
  controller.enqueue({
1934
1954
  from: "AGENT" /* AGENT */,
@@ -2227,7 +2247,7 @@ var MastraModelOutput = class extends chunkKXCUCBEI_cjs.MastraBase {
2227
2247
  try {
2228
2248
  if (self.processorRunner) {
2229
2249
  self.messageList = await self.processorRunner.runOutputProcessors(self.messageList);
2230
- const outputText = self.messageList.get.response.aiV4.core().map(m => chunkSIKEQ32R_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");
2231
2251
  const messages = self.messageList.get.response.v2();
2232
2252
  const messagesWithStructuredData = messages.filter(msg => msg.content.metadata && msg.content.metadata.structuredOutput);
2233
2253
  if (messagesWithStructuredData[0] && messagesWithStructuredData[0].content.metadata?.structuredOutput) {
@@ -2955,6 +2975,12 @@ var AISDKV5InputStream = class extends MastraModelInput {
2955
2975
  }
2956
2976
  };
2957
2977
 
2978
+ // src/stream/aisdk/v5/model-supports.ts
2979
+ function getModelSupport(modelId, provider) {
2980
+ return modelSupports.find(m => m.modelId === modelId && m.provider === provider);
2981
+ }
2982
+ var modelSupports = [];
2983
+
2958
2984
  // src/stream/aisdk/v5/execute.ts
2959
2985
  function execute({
2960
2986
  runId,
@@ -2986,6 +3012,16 @@ function execute({
2986
3012
  "stream.prompt.tools": toolsAndToolChoice?.tools?.map(tool => JSON.stringify(tool))
2987
3013
  });
2988
3014
  }
3015
+ const modelSupports2 = getModelSupport(model.modelId, model.provider);
3016
+ const modelSupportsResponseFormat = modelSupports2?.capabilities.responseFormat?.support === "full";
3017
+ const responseFormat = output ? getResponseFormat(output) : void 0;
3018
+ let prompt = inputMessages;
3019
+ if (output && responseFormat?.type === "json" && !modelSupportsResponseFormat) {
3020
+ prompt = providerUtilsV5.injectJsonInstructionIntoMessages({
3021
+ messages: inputMessages,
3022
+ schema: responseFormat.schema
3023
+ });
3024
+ }
2989
3025
  const stream = v5.initialize({
2990
3026
  runId,
2991
3027
  onResult,
@@ -2993,11 +3029,11 @@ function execute({
2993
3029
  try {
2994
3030
  const stream2 = await model.doStream({
2995
3031
  ...toolsAndToolChoice,
2996
- prompt: inputMessages,
3032
+ prompt,
2997
3033
  providerOptions,
2998
3034
  abortSignal: options?.abortSignal,
2999
3035
  includeRawChunks,
3000
- responseFormat: output ? getResponseFormat(output) : void 0,
3036
+ responseFormat: modelSupportsResponseFormat ? responseFormat : void 0,
3001
3037
  ...(modelSettings ?? {}),
3002
3038
  headers
3003
3039
  });
@@ -3795,7 +3831,9 @@ function createOuterLLMWorkflow({
3795
3831
  })));
3796
3832
  }
3797
3833
  return inputData.output.toolCalls || [];
3798
- }).foreach(toolCallStep).then(llmMappingStep).commit();
3834
+ }).foreach(toolCallStep, {
3835
+ concurrency: 10
3836
+ }).then(llmMappingStep).commit();
3799
3837
  }
3800
3838
 
3801
3839
  // src/loop/workflow/stream.ts
@@ -4150,9 +4188,6 @@ var MastraLLMVNext = class extends chunkKXCUCBEI_cjs.MastraBase {
4150
4188
  messages,
4151
4189
  tools: Object.keys(tools || {})
4152
4190
  });
4153
- if (output) {
4154
- output = this._applySchemaCompat(output);
4155
- }
4156
4191
  const llmAISpan = tracingContext?.currentSpan?.createChildSpan({
4157
4192
  name: `llm stream: '${model.modelId}'`,
4158
4193
  type: "llm_generation" /* LLM_GENERATION */,
@@ -4168,7 +4203,7 @@ var MastraLLMVNext = class extends chunkKXCUCBEI_cjs.MastraBase {
4168
4203
  }
4169
4204
  });
4170
4205
  try {
4171
- const messageList = new chunkSIKEQ32R_cjs.MessageList({
4206
+ const messageList = new chunkD3UG2YLU_cjs.MessageList({
4172
4207
  threadId,
4173
4208
  resourceId
4174
4209
  });
@@ -4229,7 +4264,7 @@ var MastraLLMVNext = class extends chunkKXCUCBEI_cjs.MastraBase {
4229
4264
  this.logger.warn("Rate limit approaching, waiting 10 seconds", {
4230
4265
  runId
4231
4266
  });
4232
- await chunkLVGGMWSE_cjs.delay(10 * 1e3);
4267
+ await chunkKB4IEMPV_cjs.delay(10 * 1e3);
4233
4268
  }
4234
4269
  },
4235
4270
  onFinish: async props => {
@@ -4304,14 +4339,18 @@ var StructuredOutputProcessor = class {
4304
4339
  structuringAgent;
4305
4340
  errorStrategy;
4306
4341
  fallbackValue;
4307
- constructor(options) {
4342
+ constructor(options, fallbackModel) {
4308
4343
  this.schema = options.schema;
4309
4344
  this.errorStrategy = options.errorStrategy ?? "strict";
4310
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
+ }
4311
4350
  this.structuringAgent = new exports.Agent({
4312
4351
  name: "structured-output-structurer",
4313
4352
  instructions: options.instructions || this.generateInstructions(),
4314
- model: options.model
4353
+ model: modelToUse
4315
4354
  });
4316
4355
  }
4317
4356
  async processOutputResult(args) {
@@ -5124,7 +5163,7 @@ var Machine = class extends EventEmitter__default.default {
5124
5163
  const logger = this.logger;
5125
5164
  let mastraProxy = void 0;
5126
5165
  if (this.#mastra) {
5127
- mastraProxy = chunkLVGGMWSE_cjs.createMastraProxy({
5166
+ mastraProxy = chunkKB4IEMPV_cjs.createMastraProxy({
5128
5167
  mastra: this.#mastra,
5129
5168
  logger
5130
5169
  });
@@ -9293,13 +9332,13 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9293
9332
  this.logger.error(mastraError.toString());
9294
9333
  throw mastraError;
9295
9334
  }
9296
- return chunkLVGGMWSE_cjs.ensureToolProperties(this.#tools);
9335
+ return chunkKB4IEMPV_cjs.ensureToolProperties(this.#tools);
9297
9336
  }
9298
9337
  getTools({
9299
9338
  runtimeContext = new chunkGPWMM745_cjs.RuntimeContext()
9300
9339
  } = {}) {
9301
9340
  if (typeof this.#tools !== "function") {
9302
- return chunkLVGGMWSE_cjs.ensureToolProperties(this.#tools);
9341
+ return chunkKB4IEMPV_cjs.ensureToolProperties(this.#tools);
9303
9342
  }
9304
9343
  const result = this.#tools({
9305
9344
  runtimeContext,
@@ -9320,7 +9359,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9320
9359
  this.logger.error(mastraError.toString());
9321
9360
  throw mastraError;
9322
9361
  }
9323
- return chunkLVGGMWSE_cjs.ensureToolProperties(tools);
9362
+ return chunkKB4IEMPV_cjs.ensureToolProperties(tools);
9324
9363
  });
9325
9364
  }
9326
9365
  get llm() {
@@ -9364,7 +9403,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9364
9403
  mastra: this.#mastra
9365
9404
  });
9366
9405
  } else {
9367
- llm = new chunkMNDKBEEQ_cjs.MastraLLMV1({
9406
+ llm = new chunkSJO2HEVU_cjs.MastraLLMV1({
9368
9407
  model: resolvedModel,
9369
9408
  mastra: this.#mastra
9370
9409
  });
@@ -9480,7 +9519,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9480
9519
  runtimeContext,
9481
9520
  model
9482
9521
  });
9483
- const normMessage = new chunkSIKEQ32R_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);
9484
9523
  if (!normMessage) {
9485
9524
  throw new Error(`Could not generate title from input ${JSON.stringify(message)}`);
9486
9525
  }
@@ -9539,7 +9578,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9539
9578
  async genTitle(userMessage, runtimeContext, tracingContext, model, instructions) {
9540
9579
  try {
9541
9580
  if (userMessage) {
9542
- const normMessage = new chunkSIKEQ32R_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);
9543
9582
  if (normMessage) {
9544
9583
  return await this.generateTitleFromUserMessage({
9545
9584
  message: normMessage,
@@ -9565,7 +9604,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9565
9604
  runId,
9566
9605
  userMessages,
9567
9606
  systemMessage,
9568
- messageList = new chunkSIKEQ32R_cjs.MessageList({
9607
+ messageList = new chunkD3UG2YLU_cjs.MessageList({
9569
9608
  threadId,
9570
9609
  resourceId
9571
9610
  }),
@@ -9620,7 +9659,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9620
9659
  systemMessage: systemMessages,
9621
9660
  memorySystemMessage: memorySystemMessage || void 0
9622
9661
  });
9623
- const returnList = new chunkSIKEQ32R_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");
9624
9663
  return {
9625
9664
  threadId: thread.id,
9626
9665
  messages: returnList.get.all.prompt()
@@ -9665,7 +9704,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9665
9704
  runtimeContext
9666
9705
  }) : this.model
9667
9706
  };
9668
- const convertedToCoreTool = chunkLVGGMWSE_cjs.makeCoreTool(toolObj, options);
9707
+ const convertedToCoreTool = chunkKB4IEMPV_cjs.makeCoreTool(toolObj, options);
9669
9708
  convertedMemoryTools[toolName] = convertedToCoreTool;
9670
9709
  }
9671
9710
  }
@@ -9836,7 +9875,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9836
9875
  }) : this.model,
9837
9876
  writableStream
9838
9877
  };
9839
- return [k, chunkLVGGMWSE_cjs.makeCoreTool(tool, options)];
9878
+ return [k, chunkKB4IEMPV_cjs.makeCoreTool(tool, options)];
9840
9879
  }));
9841
9880
  const assignedToolEntriesConverted = Object.fromEntries(assignedCoreToolEntries.filter(entry => Boolean(entry)));
9842
9881
  toolsForRequest = {
@@ -9880,7 +9919,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9880
9919
  runtimeContext
9881
9920
  }) : this.model
9882
9921
  };
9883
- const convertedToCoreTool = chunkLVGGMWSE_cjs.makeCoreTool(toolObj, options, "toolset");
9922
+ const convertedToCoreTool = chunkKB4IEMPV_cjs.makeCoreTool(toolObj, options, "toolset");
9884
9923
  toolsForRequest[toolName] = convertedToCoreTool;
9885
9924
  }
9886
9925
  }
@@ -9925,7 +9964,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9925
9964
  runtimeContext
9926
9965
  }) : this.model
9927
9966
  };
9928
- const convertedToCoreTool = chunkLVGGMWSE_cjs.makeCoreTool(rest, options, "client-tool");
9967
+ const convertedToCoreTool = chunkKB4IEMPV_cjs.makeCoreTool(rest, options, "client-tool");
9929
9968
  toolsForRequest[toolName] = convertedToCoreTool;
9930
9969
  }
9931
9970
  }
@@ -9936,8 +9975,8 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9936
9975
  threadId,
9937
9976
  resourceId,
9938
9977
  runtimeContext,
9939
- methodType,
9940
9978
  tracingContext,
9979
+ methodType,
9941
9980
  format
9942
9981
  }) {
9943
9982
  const convertedWorkflowTools = {};
@@ -9956,17 +9995,9 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9956
9995
  // current tool span onto the workflow to maintain continuity of the trace
9957
9996
  execute: async ({
9958
9997
  context,
9959
- writer
9998
+ writer,
9999
+ tracingContext: innerTracingContext
9960
10000
  }) => {
9961
- const toolAISpan = tracingContext.currentSpan?.createChildSpan({
9962
- type: "tool_call" /* TOOL_CALL */,
9963
- name: `tool: '${workflowName}'`,
9964
- input: context,
9965
- attributes: {
9966
- toolId: workflowName,
9967
- toolType: "workflow"
9968
- }
9969
- });
9970
10001
  try {
9971
10002
  this.logger.debug(`[Agent:${this.name}] - Executing workflow as tool ${workflowName}`, {
9972
10003
  name: workflowName,
@@ -9982,16 +10013,13 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
9982
10013
  result = await run.start({
9983
10014
  inputData: context,
9984
10015
  runtimeContext,
9985
- tracingContext: {
9986
- currentSpan: toolAISpan
9987
- }
10016
+ tracingContext: innerTracingContext
9988
10017
  });
9989
10018
  } else if (methodType === "stream") {
9990
- const streamResult = await run.stream({
10019
+ const streamResult = run.stream({
9991
10020
  inputData: context,
9992
- runtimeContext
9993
- // TODO: is this forgottn?
9994
- //currentSpan: toolAISpan,
10021
+ runtimeContext,
10022
+ tracingContext: innerTracingContext
9995
10023
  });
9996
10024
  if (writer) {
9997
10025
  await streamResult.stream.pipeTo(writer);
@@ -10003,6 +10031,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
10003
10031
  const streamResult = run.streamVNext({
10004
10032
  inputData: context,
10005
10033
  runtimeContext,
10034
+ tracingContext: innerTracingContext,
10006
10035
  format
10007
10036
  });
10008
10037
  if (writer) {
@@ -10010,9 +10039,6 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
10010
10039
  }
10011
10040
  result = await streamResult.result;
10012
10041
  }
10013
- toolAISpan?.end({
10014
- output: result
10015
- });
10016
10042
  return {
10017
10043
  result,
10018
10044
  runId: run.runId
@@ -10032,9 +10058,6 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
10032
10058
  }, err);
10033
10059
  this.logger.trackException(mastraError);
10034
10060
  this.logger.error(mastraError.toString());
10035
- toolAISpan?.error({
10036
- error: mastraError
10037
- });
10038
10061
  throw mastraError;
10039
10062
  }
10040
10063
  }
@@ -10056,7 +10079,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
10056
10079
  }) : this.model,
10057
10080
  tracingContext
10058
10081
  };
10059
- convertedWorkflowTools[workflowName] = chunkLVGGMWSE_cjs.makeCoreTool(toolObj, options);
10082
+ convertedWorkflowTools[workflowName] = chunkKB4IEMPV_cjs.makeCoreTool(toolObj, options);
10060
10083
  }
10061
10084
  }
10062
10085
  return convertedWorkflowTools;
@@ -10076,7 +10099,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
10076
10099
  let mastraProxy = void 0;
10077
10100
  const logger = this.logger;
10078
10101
  if (this.#mastra) {
10079
- mastraProxy = chunkLVGGMWSE_cjs.createMastraProxy({
10102
+ mastraProxy = chunkKB4IEMPV_cjs.createMastraProxy({
10080
10103
  mastra: this.#mastra,
10081
10104
  logger
10082
10105
  });
@@ -10218,7 +10241,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
10218
10241
  runId
10219
10242
  });
10220
10243
  }
10221
- const agentAISpan = chunkUFCYMOYH_cjs.getOrCreateSpan({
10244
+ const agentAISpan = chunkUGCG7DI3_cjs.getOrCreateSpan({
10222
10245
  type: "agent_run" /* AGENT_RUN */,
10223
10246
  name: `agent run: '${this.id}'`,
10224
10247
  input: messages,
@@ -10265,7 +10288,7 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
10265
10288
  writableStream,
10266
10289
  methodType
10267
10290
  });
10268
- const messageList = new chunkSIKEQ32R_cjs.MessageList({
10291
+ const messageList = new chunkD3UG2YLU_cjs.MessageList({
10269
10292
  threadId,
10270
10293
  resourceId,
10271
10294
  generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
@@ -10350,10 +10373,12 @@ exports.Agent = class Agent extends (_a = chunkKXCUCBEI_cjs.MastraBase) {
10350
10373
  saveThread: false
10351
10374
  });
10352
10375
  }
10353
- let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread ? this.getMemoryMessages({
10376
+ const config = memory.getMergedThreadConfig(memoryConfig || {});
10377
+ const hasResourceScopeSemanticRecall = typeof config?.semanticRecall === "object" && config?.semanticRecall?.scope === "resource";
10378
+ let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread || hasResourceScopeSemanticRecall ? this.getMemoryMessages({
10354
10379
  resourceId,
10355
10380
  threadId: threadObject.id,
10356
- vectorMessageSearch: new chunkSIKEQ32R_cjs.MessageList().add(messages, `user`).getLatestUserContent() || "",
10381
+ vectorMessageSearch: new chunkD3UG2YLU_cjs.MessageList().add(messages, `user`).getLatestUserContent() || "",
10357
10382
  memoryConfig,
10358
10383
  runtimeContext
10359
10384
  }) : [], memory.getSystemMessage({
@@ -10376,7 +10401,7 @@ The following messages were remembered from a different conversation:
10376
10401
  <remembered_from_other_conversation>
10377
10402
  ${(() => {
10378
10403
  let result = ``;
10379
- const messages2 = new chunkSIKEQ32R_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
10404
+ const messages2 = new chunkD3UG2YLU_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
10380
10405
  let lastYmd = null;
10381
10406
  for (const msg of messages2) {
10382
10407
  const date = msg.createdAt;
@@ -10429,7 +10454,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
10429
10454
  systemMessage,
10430
10455
  memorySystemMessage: memorySystemMessage || void 0
10431
10456
  });
10432
- const processedList = new chunkSIKEQ32R_cjs.MessageList({
10457
+ const processedList = new chunkD3UG2YLU_cjs.MessageList({
10433
10458
  threadId: threadObject.id,
10434
10459
  resourceId,
10435
10460
  generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
@@ -10485,7 +10510,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
10485
10510
  result: resToLog,
10486
10511
  threadId
10487
10512
  });
10488
- const messageListResponses = new chunkSIKEQ32R_cjs.MessageList({
10513
+ const messageListResponses = new chunkD3UG2YLU_cjs.MessageList({
10489
10514
  threadId,
10490
10515
  resourceId,
10491
10516
  generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
@@ -10943,7 +10968,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
10943
10968
  const instructions = options.instructions || (await this.getInstructions({
10944
10969
  runtimeContext
10945
10970
  }));
10946
- const agentAISpan = chunkUFCYMOYH_cjs.getOrCreateSpan({
10971
+ const agentAISpan = chunkUGCG7DI3_cjs.getOrCreateSpan({
10947
10972
  type: "agent_run" /* AGENT_RUN */,
10948
10973
  name: `agent run: '${this.id}'`,
10949
10974
  input: options.messages,
@@ -11019,12 +11044,12 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
11019
11044
  resourceId,
11020
11045
  runId,
11021
11046
  runtimeContext,
11022
- writableStream: options.writableStream,
11023
- methodType,
11024
- format,
11025
11047
  tracingContext: {
11026
11048
  currentSpan: agentAISpan
11027
- }
11049
+ },
11050
+ writableStream: options.writableStream,
11051
+ methodType,
11052
+ format
11028
11053
  });
11029
11054
  return {
11030
11055
  convertedTools
@@ -11046,7 +11071,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
11046
11071
  tracingContext
11047
11072
  }) => {
11048
11073
  const thread = threadFromArgs;
11049
- const messageList = new chunkSIKEQ32R_cjs.MessageList({
11074
+ const messageList = new chunkD3UG2YLU_cjs.MessageList({
11050
11075
  threadId: thread?.id,
11051
11076
  resourceId,
11052
11077
  generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
@@ -11126,10 +11151,12 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
11126
11151
  saveThread: false
11127
11152
  });
11128
11153
  }
11129
- let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread ? this.getMemoryMessages({
11154
+ const config = memory.getMergedThreadConfig(memoryConfig || {});
11155
+ const hasResourceScopeSemanticRecall = typeof config?.semanticRecall === "object" && config?.semanticRecall?.scope === "resource";
11156
+ let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread || hasResourceScopeSemanticRecall ? this.getMemoryMessages({
11130
11157
  resourceId,
11131
11158
  threadId: threadObject.id,
11132
- vectorMessageSearch: new chunkSIKEQ32R_cjs.MessageList().add(options.messages, `user`).getLatestUserContent() || "",
11159
+ vectorMessageSearch: new chunkD3UG2YLU_cjs.MessageList().add(options.messages, `user`).getLatestUserContent() || "",
11133
11160
  memoryConfig,
11134
11161
  runtimeContext
11135
11162
  }) : [], memory.getSystemMessage({
@@ -11152,7 +11179,7 @@ The following messages were remembered from a different conversation:
11152
11179
  <remembered_from_other_conversation>
11153
11180
  ${(() => {
11154
11181
  let result2 = ``;
11155
- const messages = new chunkSIKEQ32R_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
11182
+ const messages = new chunkD3UG2YLU_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
11156
11183
  let lastYmd = null;
11157
11184
  for (const msg of messages) {
11158
11185
  const date = msg.createdAt;
@@ -11204,7 +11231,7 @@ the following messages are from ${ymd}
11204
11231
  systemMessage,
11205
11232
  memorySystemMessage: memorySystemMessage || void 0
11206
11233
  });
11207
- const processedList = new chunkSIKEQ32R_cjs.MessageList({
11234
+ const processedList = new chunkD3UG2YLU_cjs.MessageList({
11208
11235
  threadId: threadObject.id,
11209
11236
  resourceId,
11210
11237
  generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
@@ -11357,7 +11384,10 @@ the following messages are from ${ymd}
11357
11384
  runtimeContext: result2.runtimeContext
11358
11385
  }) : this.#outputProcessors : []);
11359
11386
  if (options.structuredOutput) {
11360
- 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);
11361
11391
  effectiveOutputProcessors = effectiveOutputProcessors ? [...effectiveOutputProcessors, structuredProcessor] : [structuredProcessor];
11362
11392
  }
11363
11393
  const loopOptions = {
@@ -11414,7 +11444,9 @@ the following messages are from ${ymd}
11414
11444
  await options?.onFinish?.({
11415
11445
  ...result2,
11416
11446
  runId,
11417
- messages: messageList.get.response.aiV5.model()
11447
+ messages: messageList.get.response.aiV5.model(),
11448
+ usage: payload.usage,
11449
+ totalUsage: payload.totalUsage
11418
11450
  });
11419
11451
  },
11420
11452
  onStepFinish: result2.onStepFinish
@@ -11725,7 +11757,10 @@ the following messages are from ${ymd}
11725
11757
  };
11726
11758
  let finalOutputProcessors = mergedGenerateOptions.outputProcessors;
11727
11759
  if (mergedGenerateOptions.structuredOutput) {
11728
- 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);
11729
11764
  finalOutputProcessors = finalOutputProcessors ? [...finalOutputProcessors, structuredProcessor] : [structuredProcessor];
11730
11765
  }
11731
11766
  if (!output || experimental_output) {
@@ -11738,7 +11773,7 @@ the following messages are from ${ymd}
11738
11773
  runtimeContext: mergedGenerateOptions.runtimeContext || new chunkGPWMM745_cjs.RuntimeContext(),
11739
11774
  tracingContext,
11740
11775
  outputProcessorOverrides: finalOutputProcessors,
11741
- messageList: new chunkSIKEQ32R_cjs.MessageList({
11776
+ messageList: new chunkD3UG2YLU_cjs.MessageList({
11742
11777
  threadId: llmOptions.threadId || "",
11743
11778
  resourceId: llmOptions.resourceId || ""
11744
11779
  }).add({
@@ -11831,7 +11866,7 @@ the following messages are from ${ymd}
11831
11866
  const outputProcessorResult = await this.__runOutputProcessors({
11832
11867
  runtimeContext: mergedGenerateOptions.runtimeContext || new chunkGPWMM745_cjs.RuntimeContext(),
11833
11868
  tracingContext,
11834
- messageList: new chunkSIKEQ32R_cjs.MessageList({
11869
+ messageList: new chunkD3UG2YLU_cjs.MessageList({
11835
11870
  threadId: llmOptions.threadId || "",
11836
11871
  resourceId: llmOptions.resourceId || ""
11837
11872
  }).add({
@@ -12291,9 +12326,9 @@ var MastraWorkflowStream = class extends web.ReadableStream {
12291
12326
  deferredPromise.reject = reject;
12292
12327
  });
12293
12328
  const updateUsageCount = usage => {
12294
- this.#usageCount.promptTokens += parseInt(usage.promptTokens?.toString() ?? "0", 10);
12295
- this.#usageCount.completionTokens += parseInt(usage.completionTokens?.toString() ?? "0", 10);
12296
- 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);
12297
12332
  };
12298
12333
  super({
12299
12334
  start: async controller => {
@@ -12301,7 +12336,9 @@ var MastraWorkflowStream = class extends web.ReadableStream {
12301
12336
  write: chunk => {
12302
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") {
12303
12338
  const finishPayload = chunk.payload?.output.payload;
12304
- updateUsageCount(finishPayload.usage);
12339
+ if (finishPayload) {
12340
+ updateUsageCount(finishPayload.usage);
12341
+ }
12305
12342
  }
12306
12343
  controller.enqueue(chunk);
12307
12344
  }
@@ -12313,9 +12350,14 @@ var MastraWorkflowStream = class extends web.ReadableStream {
12313
12350
  payload: {}
12314
12351
  });
12315
12352
  const stream = await createStream(writer);
12353
+ let workflowStatus = "success";
12316
12354
  for await (const chunk of stream) {
12317
- if (chunk.type === "step-finish") {
12355
+ if (chunk.type === "step-finish" && chunk.payload.usage) {
12318
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";
12319
12361
  }
12320
12362
  controller.enqueue(chunk);
12321
12363
  }
@@ -12324,9 +12366,7 @@ var MastraWorkflowStream = class extends web.ReadableStream {
12324
12366
  runId: run.runId,
12325
12367
  from: "WORKFLOW" /* WORKFLOW */,
12326
12368
  payload: {
12327
- stepResult: {
12328
- reason: "stop"
12329
- },
12369
+ workflowStatus,
12330
12370
  output: {
12331
12371
  usage: this.#usageCount
12332
12372
  },
@@ -12495,7 +12535,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
12495
12535
  } = retryConfig ?? {};
12496
12536
  const steps = graph.steps;
12497
12537
  this.runCounts.clear();
12498
- const workflowAISpan = chunkUFCYMOYH_cjs.getOrCreateSpan({
12538
+ const workflowAISpan = chunkUGCG7DI3_cjs.getOrCreateSpan({
12499
12539
  type: "workflow_run" /* WORKFLOW_RUN */,
12500
12540
  name: `workflow run: '${workflowId}'`,
12501
12541
  input,
@@ -13008,7 +13048,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
13008
13048
  const result = await runStep({
13009
13049
  runId,
13010
13050
  workflowId,
13011
- mastra: this.mastra ? chunkUFCYMOYH_cjs.wrapMastra(this.mastra, innerTracingContext) : void 0,
13051
+ mastra: this.mastra ? chunkUGCG7DI3_cjs.wrapMastra(this.mastra, innerTracingContext) : void 0,
13012
13052
  runtimeContext,
13013
13053
  inputData: prevOutput,
13014
13054
  runCount: this.getOrGenerateRunCount(step.id),
@@ -13592,7 +13632,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
13592
13632
  const evalSpan = loopSpan?.createChildSpan({
13593
13633
  type: "workflow_conditional_eval" /* WORKFLOW_CONDITIONAL_EVAL */,
13594
13634
  name: `condition: ${entry.loopType}`,
13595
- 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"]),
13596
13636
  attributes: {
13597
13637
  conditionIndex: iteration
13598
13638
  }
@@ -14460,6 +14500,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
14460
14500
  workflowStatus: execResults.status === "success" ? "running" : execResults.status,
14461
14501
  runtimeContext
14462
14502
  });
14503
+ if (execResults.status === "canceled") {
14504
+ await emitter.emit("watch-v2", {
14505
+ type: "workflow-canceled",
14506
+ payload: {}
14507
+ });
14508
+ }
14463
14509
  return {
14464
14510
  result: execResults,
14465
14511
  stepResults,
@@ -15164,6 +15210,8 @@ var Workflow = class extends chunkKXCUCBEI_cjs.MastraBase {
15164
15210
  }
15165
15211
  return scorers;
15166
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`
15167
15215
  async execute({
15168
15216
  runId,
15169
15217
  inputData,
@@ -15501,7 +15549,8 @@ var Run = class {
15501
15549
  */
15502
15550
  stream({
15503
15551
  inputData,
15504
- runtimeContext
15552
+ runtimeContext,
15553
+ tracingContext
15505
15554
  } = {}) {
15506
15555
  const {
15507
15556
  readable,
@@ -15566,7 +15615,8 @@ var Run = class {
15566
15615
  this.executionResults = this._start({
15567
15616
  inputData,
15568
15617
  runtimeContext,
15569
- format: "aisdk"
15618
+ format: "aisdk",
15619
+ tracingContext
15570
15620
  }).then(result => {
15571
15621
  if (result.status !== "suspended") {
15572
15622
  this.closeStreamAction?.().catch(() => {});
@@ -15595,12 +15645,13 @@ var Run = class {
15595
15645
  streamVNext({
15596
15646
  inputData,
15597
15647
  runtimeContext,
15648
+ tracingContext,
15598
15649
  format
15599
15650
  } = {}) {
15600
15651
  this.closeStreamAction = async () => {};
15601
15652
  return new MastraWorkflowStream({
15602
15653
  run: this,
15603
- createStream: writer => {
15654
+ createStream: () => {
15604
15655
  const {
15605
15656
  readable,
15606
15657
  writable
@@ -15618,7 +15669,7 @@ var Run = class {
15618
15669
  return;
15619
15670
  }
15620
15671
  isWriting = true;
15621
- let watchWriter = writer.getWriter();
15672
+ let watchWriter = writable.getWriter();
15622
15673
  try {
15623
15674
  for (const chunk of chunkToWrite) {
15624
15675
  await watchWriter.write(chunk);
@@ -15656,6 +15707,7 @@ var Run = class {
15656
15707
  const executionResults = this._start({
15657
15708
  inputData,
15658
15709
  runtimeContext,
15710
+ tracingContext,
15659
15711
  writableStream: writable,
15660
15712
  format
15661
15713
  }).then(result => {
@@ -15939,5 +15991,5 @@ exports.recursivelyCheckForFinalState = recursivelyCheckForFinalState;
15939
15991
  exports.resolveVariables = resolveVariables;
15940
15992
  exports.updateStepInHierarchy = updateStepInHierarchy;
15941
15993
  exports.workflowToStep = workflowToStep;
15942
- //# sourceMappingURL=chunk-7GYN2OE3.cjs.map
15943
- //# sourceMappingURL=chunk-7GYN2OE3.cjs.map
15994
+ //# sourceMappingURL=chunk-C3R2Q3NN.cjs.map
15995
+ //# sourceMappingURL=chunk-C3R2Q3NN.cjs.map