@mastra/core 0.14.1 → 0.14.2-alpha.0

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 (84) hide show
  1. package/dist/agent/agent.types.d.ts +32 -6
  2. package/dist/agent/agent.types.d.ts.map +1 -1
  3. package/dist/agent/index.cjs +8 -8
  4. package/dist/agent/index.d.ts +3 -2
  5. package/dist/agent/index.d.ts.map +1 -1
  6. package/dist/agent/index.js +1 -1
  7. package/dist/agent/input-processor/index.cjs +6 -6
  8. package/dist/agent/input-processor/index.js +1 -1
  9. package/dist/{chunk-DQ3LHZOM.js → chunk-5MWUQWB2.js} +287 -149
  10. package/dist/chunk-5MWUQWB2.js.map +1 -0
  11. package/dist/{chunk-KDAMOM3E.cjs → chunk-ALQ6THBK.cjs} +4 -4
  12. package/dist/chunk-ALQ6THBK.cjs.map +1 -0
  13. package/dist/{chunk-KSH7U6FI.js → chunk-LRZSTQNA.js} +4 -4
  14. package/dist/chunk-LRZSTQNA.js.map +1 -0
  15. package/dist/{chunk-MZKHQDF6.js → chunk-MZR4PZ4W.js} +3 -3
  16. package/dist/{chunk-MZKHQDF6.js.map → chunk-MZR4PZ4W.js.map} +1 -1
  17. package/dist/{chunk-W3ZR2VD3.cjs → chunk-S5555MUN.cjs} +287 -149
  18. package/dist/chunk-S5555MUN.cjs.map +1 -0
  19. package/dist/{chunk-NENZDCGX.cjs → chunk-VRCNNTII.cjs} +4 -4
  20. package/dist/{chunk-NENZDCGX.cjs.map → chunk-VRCNNTII.cjs.map} +1 -1
  21. package/dist/index.cjs +19 -19
  22. package/dist/index.d.ts +3 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +5 -5
  25. package/dist/llm/model/model.loop.d.ts +2 -3
  26. package/dist/llm/model/model.loop.d.ts.map +1 -1
  27. package/dist/llm/model/model.loop.types.d.ts +3 -3
  28. package/dist/llm/model/model.loop.types.d.ts.map +1 -1
  29. package/dist/loop/index.cjs +2 -2
  30. package/dist/loop/index.js +1 -1
  31. package/dist/loop/loop.d.ts +2 -1
  32. package/dist/loop/loop.d.ts.map +1 -1
  33. package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
  34. package/dist/loop/types.d.ts +7 -9
  35. package/dist/loop/types.d.ts.map +1 -1
  36. package/dist/loop/workflow/llm-execution.d.ts +2 -1
  37. package/dist/loop/workflow/llm-execution.d.ts.map +1 -1
  38. package/dist/loop/workflow/outer-llm-step.d.ts +2 -1
  39. package/dist/loop/workflow/outer-llm-step.d.ts.map +1 -1
  40. package/dist/loop/workflow/stream.d.ts +2 -1
  41. package/dist/loop/workflow/stream.d.ts.map +1 -1
  42. package/dist/loop/workflow/tool-call-step.d.ts +2 -1
  43. package/dist/loop/workflow/tool-call-step.d.ts.map +1 -1
  44. package/dist/memory/index.cjs +4 -4
  45. package/dist/memory/index.js +1 -1
  46. package/dist/memory/memory.d.ts +3 -3
  47. package/dist/memory/memory.d.ts.map +1 -1
  48. package/dist/network/index.cjs +2 -2
  49. package/dist/network/index.js +1 -1
  50. package/dist/network/vNext/index.cjs +12 -12
  51. package/dist/network/vNext/index.js +1 -1
  52. package/dist/processors/index.cjs +8 -8
  53. package/dist/processors/index.js +2 -2
  54. package/dist/relevance/index.cjs +4 -4
  55. package/dist/relevance/index.js +1 -1
  56. package/dist/scores/index.cjs +4 -4
  57. package/dist/scores/index.js +1 -1
  58. package/dist/stream/aisdk/v5/execute.d.ts +4 -4
  59. package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
  60. package/dist/stream/aisdk/v5/output.d.ts +41 -16
  61. package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
  62. package/dist/stream/base/output-format-handlers.d.ts +7 -7
  63. package/dist/stream/base/output-format-handlers.d.ts.map +1 -1
  64. package/dist/stream/base/output.d.ts +156 -19
  65. package/dist/stream/base/output.d.ts.map +1 -1
  66. package/dist/stream/base/schema.d.ts +15 -6
  67. package/dist/stream/base/schema.d.ts.map +1 -1
  68. package/dist/stream/index.cjs +3 -3
  69. package/dist/stream/index.js +1 -1
  70. package/dist/stream/types.d.ts +3 -3
  71. package/dist/stream/types.d.ts.map +1 -1
  72. package/dist/workflows/default.d.ts +6 -3
  73. package/dist/workflows/default.d.ts.map +1 -1
  74. package/dist/workflows/index.cjs +10 -10
  75. package/dist/workflows/index.js +1 -1
  76. package/dist/workflows/legacy/index.cjs +22 -22
  77. package/dist/workflows/legacy/index.js +1 -1
  78. package/dist/workflows/types.d.ts +17 -0
  79. package/dist/workflows/types.d.ts.map +1 -1
  80. package/package.json +2 -2
  81. package/dist/chunk-DQ3LHZOM.js.map +0 -1
  82. package/dist/chunk-KDAMOM3E.cjs.map +0 -1
  83. package/dist/chunk-KSH7U6FI.js.map +0 -1
  84. package/dist/chunk-W3ZR2VD3.cjs.map +0 -1
@@ -1390,6 +1390,9 @@ var AISDKV5OutputStream = class {
1390
1390
  get text() {
1391
1391
  return this.#modelOutput.text;
1392
1392
  }
1393
+ /**
1394
+ * Stream of valid JSON chunks. The final JSON result is validated against the output schema when the stream ends.
1395
+ */
1393
1396
  get objectStream() {
1394
1397
  return this.#modelOutput.objectStream;
1395
1398
  }
@@ -1442,16 +1445,25 @@ var AISDKV5OutputStream = class {
1442
1445
  get content() {
1443
1446
  return this.#messageList.get.response.aiV5.modelContent();
1444
1447
  }
1448
+ /**
1449
+ * Stream of only text content, compatible with streaming text responses.
1450
+ */
1445
1451
  get textStream() {
1446
1452
  return this.#modelOutput.textStream;
1447
1453
  }
1454
+ /**
1455
+ * Stream of individual array elements when output schema is an array type.
1456
+ */
1448
1457
  get elementStream() {
1449
1458
  return this.#modelOutput.elementStream;
1450
1459
  }
1460
+ /**
1461
+ * Stream of all chunks in AI SDK v5 format.
1462
+ */
1451
1463
  get fullStream() {
1452
1464
  let startEvent;
1453
1465
  let hasStarted = false;
1454
- const responseFormat = getResponseFormat(this.#options.objectOptions?.schema);
1466
+ const responseFormat = getResponseFormat(this.#options.output);
1455
1467
  const fullStream = this.#modelOutput.fullStream;
1456
1468
  const transformedStream = fullStream.pipeThrough(new TransformStream({
1457
1469
  transform(chunk, controller) {
@@ -1526,26 +1538,59 @@ var AISDKV5OutputStream = class {
1526
1538
  return this.#modelOutput.object;
1527
1539
  }
1528
1540
  };
1529
- var ObjectFormatHandler = class {
1530
- type = "object";
1541
+ var BaseFormatHandler = class {
1531
1542
  /**
1532
- * Creates an object format handler.
1533
- * @param schema - The original user-provided schema for validation
1543
+ * The user-provided schema to validate the final result against.
1534
1544
  */
1535
- constructor(schema) {
1536
- this.schema = schema ? asSchema(schema) : void 0;
1537
- }
1538
1545
  schema;
1546
+ /**
1547
+ * Whether to validate partial chunks. @planned
1548
+ */
1549
+ validatePartialChunks = false;
1550
+ /**
1551
+ * Partial schema for validating partial chunks as they are streamed. @planned
1552
+ */
1553
+ partialSchema;
1554
+ constructor(schema, options = {}) {
1555
+ if (!schema) {
1556
+ this.schema = void 0;
1557
+ } else {
1558
+ this.schema = asSchema(schema);
1559
+ }
1560
+ if (options.validatePartialChunks) {
1561
+ if (schema !== void 0 && "partial" in schema && typeof schema.partial === "function") {
1562
+ this.validatePartialChunks = true;
1563
+ this.partialSchema = schema.partial();
1564
+ }
1565
+ }
1566
+ }
1567
+ };
1568
+ var ObjectFormatHandler = class extends BaseFormatHandler {
1569
+ type = "object";
1539
1570
  async processPartialChunk({
1540
1571
  accumulatedText,
1541
1572
  previousObject
1542
1573
  }) {
1543
1574
  const {
1544
- value: currentObjectJson
1575
+ value: currentObjectJson,
1576
+ state
1545
1577
  } = await parsePartialJson(accumulatedText);
1546
- if (currentObjectJson !== void 0 && typeof currentObjectJson === "object" && !isDeepEqualData(previousObject, currentObjectJson)) {
1578
+ if (this.validatePartialChunks && this.partialSchema) {
1579
+ const result = this.partialSchema?.safeParse(currentObjectJson);
1580
+ if (result.success && result.data && result.data !== void 0 && !isDeepEqualData(previousObject, result.data)) {
1581
+ return {
1582
+ shouldEmit: true,
1583
+ emitValue: result.data,
1584
+ newPreviousResult: result.data
1585
+ };
1586
+ }
1587
+ return {
1588
+ shouldEmit: false
1589
+ };
1590
+ }
1591
+ if (currentObjectJson !== void 0 && currentObjectJson !== null && typeof currentObjectJson === "object" && !isDeepEqualData(previousObject, currentObjectJson)) {
1547
1592
  return {
1548
- shouldEmit: true,
1593
+ shouldEmit: ["successful-parse", "repaired-parse"].includes(state),
1549
1594
  emitValue: currentObjectJson,
1550
1595
  newPreviousResult: currentObjectJson
1551
1596
  };
@@ -1580,31 +1625,27 @@ var ObjectFormatHandler = class {
1580
1625
  } else {
1581
1626
  return {
1582
1627
  success: false,
1583
- error: result.error ?? new Error("Validation failed")
1628
+ error: result.error ?? new Error("Validation failed", {
1629
+ cause: result.error
1630
+ })
1584
1631
  };
1585
1632
  }
1586
1633
  } catch (error) {
1587
1634
  return {
1588
1635
  success: false,
1589
- error: error instanceof Error ? error : new Error("Validation failed")
1636
+ error: error instanceof Error ? error : new Error("Validation failed", {
1637
+ cause: error
1638
+ })
1590
1639
  };
1591
1640
  }
1592
1641
  }
1593
1642
  };
1594
- var ArrayFormatHandler = class {
1643
+ var ArrayFormatHandler = class extends BaseFormatHandler {
1595
1644
  type = "array";
1596
1645
  /** Previously filtered array to track changes */
1597
1646
  textPreviousFilteredArray = [];
1598
1647
  /** Whether we've emitted the initial empty array */
1599
1648
  hasEmittedInitialArray = false;
1600
- /**
1601
- * Creates an array format handler.
1602
- * @param schema - The original user-provided schema for validation
1603
- */
1604
- constructor(schema) {
1605
- this.schema = schema ? asSchema(schema) : void 0;
1606
- }
1607
- schema;
1608
1649
  async processPartialChunk({
1609
1650
  accumulatedText,
1610
1651
  previousObject
@@ -1679,29 +1720,43 @@ var ArrayFormatHandler = class {
1679
1720
  } else {
1680
1721
  return {
1681
1722
  success: false,
1682
- error: result.error ?? new Error("Validation failed")
1723
+ error: result.error ?? new Error("Validation failed", {
1724
+ cause: result.error
1725
+ })
1683
1726
  };
1684
1727
  }
1685
1728
  } catch (error) {
1686
1729
  return {
1687
1730
  success: false,
1688
- error: error instanceof Error ? error : new Error("Validation failed")
1731
+ error: error instanceof Error ? error : new Error("Validation failed", {
1732
+ cause: error
1733
+ })
1689
1734
  };
1690
1735
  }
1691
1736
  }
1692
1737
  };
1693
- var EnumFormatHandler = class {
1738
+ var EnumFormatHandler = class extends BaseFormatHandler {
1694
1739
  type = "enum";
1695
1740
  /** Previously emitted enum result to avoid duplicate emissions */
1696
1741
  textPreviousEnumResult;
1697
1742
  /**
1698
- * Creates an enum format handler.
1699
- * @param schema - The original schema containing enum values for partial matching
1743
+ * Finds the best matching enum value for a partial result string.
1744
+ * If multiple values match, returns the partial string. If only one matches, returns that value.
1745
+ * @param partialResult - Partial enum string from streaming
1746
+ * @returns Best matching enum value or undefined if no matches
1700
1747
  */
1701
- constructor(schema) {
1702
- this.schema = schema ? asSchema(schema) : void 0;
1748
+ findBestEnumMatch(partialResult) {
1749
+ if (!this.schema?.jsonSchema?.enum) {
1750
+ return void 0;
1751
+ }
1752
+ const enumValues = this.schema.jsonSchema.enum;
1753
+ const possibleEnumValues = enumValues.filter(value => typeof value === "string").filter(enumValue => enumValue.startsWith(partialResult));
1754
+ if (possibleEnumValues.length === 0) {
1755
+ return void 0;
1756
+ }
1757
+ const firstMatch = possibleEnumValues[0];
1758
+ return possibleEnumValues.length === 1 && firstMatch !== void 0 ? firstMatch : partialResult;
1703
1759
  }
1704
- schema;
1705
1760
  async processPartialChunk({
1706
1761
  accumulatedText,
1707
1762
  previousObject
@@ -1725,24 +1780,6 @@ var EnumFormatHandler = class {
1725
1780
  shouldEmit: false
1726
1781
  };
1727
1782
  }
1728
- /**
1729
- * Finds the best matching enum value for a partial result string.
1730
- * If multiple values match, returns the partial string. If only one matches, returns that value.
1731
- * @param partialResult - Partial enum string from streaming
1732
- * @returns Best matching enum value or undefined if no matches
1733
- */
1734
- findBestEnumMatch(partialResult) {
1735
- if (!this.schema?.jsonSchema?.enum) {
1736
- return void 0;
1737
- }
1738
- const enumValues = this.schema.jsonSchema.enum;
1739
- const possibleEnumValues = enumValues.filter(value => typeof value === "string").filter(enumValue => enumValue.startsWith(partialResult));
1740
- if (possibleEnumValues.length === 0) {
1741
- return void 0;
1742
- }
1743
- const firstMatch = possibleEnumValues[0];
1744
- return possibleEnumValues.length === 1 && firstMatch !== void 0 ? firstMatch : partialResult;
1745
- }
1746
1783
  async validateAndTransformFinal(finalValue) {
1747
1784
  if (!finalValue || typeof finalValue !== "object" || typeof finalValue.result !== "string") {
1748
1785
  return {
@@ -1807,8 +1844,12 @@ function createObjectStreamTransformer({
1807
1844
  let accumulatedText = "";
1808
1845
  let previousObject = void 0;
1809
1846
  let finishReason;
1847
+ let currentRunId;
1810
1848
  return new TransformStream({
1811
1849
  async transform(chunk, controller) {
1850
+ if (chunk.runId) {
1851
+ currentRunId = chunk.runId;
1852
+ }
1812
1853
  if (chunk.type === "finish") {
1813
1854
  finishReason = chunk.payload.stepResult.reason;
1814
1855
  controller.enqueue(chunk);
@@ -1827,8 +1868,11 @@ function createObjectStreamTransformer({
1827
1868
  if (result.shouldEmit) {
1828
1869
  previousObject = result.newPreviousResult ?? previousObject;
1829
1870
  controller.enqueue({
1871
+ from: chunk.from,
1872
+ runId: chunk.runId,
1830
1873
  type: "object",
1831
1874
  object: result.emitValue
1875
+ // TODO: handle partial runtime type validation of json chunks
1832
1876
  });
1833
1877
  }
1834
1878
  }
@@ -1845,6 +1889,8 @@ function createObjectStreamTransformer({
1845
1889
  const finalResult = await handler.validateAndTransformFinal(previousObject);
1846
1890
  if (!finalResult.success) {
1847
1891
  controller.enqueue({
1892
+ from: "AGENT" /* AGENT */,
1893
+ runId: currentRunId ?? "",
1848
1894
  type: "error",
1849
1895
  payload: {
1850
1896
  error: finalResult.error ?? new Error("Validation failed")
@@ -1856,14 +1902,14 @@ function createObjectStreamTransformer({
1856
1902
  }
1857
1903
  });
1858
1904
  }
1859
- function createJsonTextStreamTransformer(objectOptions) {
1905
+ function createJsonTextStreamTransformer(schema) {
1860
1906
  let previousArrayLength = 0;
1861
1907
  let hasStartedArray = false;
1862
1908
  let chunkCount = 0;
1863
- const outputSchema = getTransformedSchema(objectOptions?.schema);
1909
+ const outputSchema = getTransformedSchema(schema);
1864
1910
  return new TransformStream({
1865
1911
  transform(chunk, controller) {
1866
- if (chunk.type !== "object") {
1912
+ if (chunk.type !== "object" || !chunk.object) {
1867
1913
  return;
1868
1914
  }
1869
1915
  if (outputSchema?.outputFormat === "array") {
@@ -1925,7 +1971,9 @@ var MastraModelOutput = class extends MastraBase {
1925
1971
  #toolCallArgsDeltas = {};
1926
1972
  #toolCallDeltaIdNameMap = {};
1927
1973
  #toolCalls = [];
1974
+ // TODO: add type
1928
1975
  #toolResults = [];
1976
+ // TODO: add type
1929
1977
  #warnings = [];
1930
1978
  #finishReason;
1931
1979
  #request;
@@ -1939,23 +1987,38 @@ var MastraModelOutput = class extends MastraBase {
1939
1987
  warnings: new DelayedPromise(),
1940
1988
  providerMetadata: new DelayedPromise(),
1941
1989
  response: new DelayedPromise(),
1990
+ // TODO: add type
1942
1991
  request: new DelayedPromise(),
1992
+ // TODO: add type
1943
1993
  text: new DelayedPromise(),
1944
1994
  reasoning: new DelayedPromise(),
1945
1995
  reasoningText: new DelayedPromise(),
1946
1996
  sources: new DelayedPromise(),
1997
+ // TODO: add type
1947
1998
  files: new DelayedPromise(),
1999
+ // TODO: add type
1948
2000
  toolCalls: new DelayedPromise(),
2001
+ // TODO: add type
1949
2002
  toolResults: new DelayedPromise(),
2003
+ // TODO: add type
1950
2004
  steps: new DelayedPromise(),
1951
2005
  totalUsage: new DelayedPromise(),
1952
2006
  content: new DelayedPromise(),
1953
2007
  reasoningDetails: new DelayedPromise()
1954
2008
  };
1955
2009
  #streamConsumed = false;
2010
+ /**
2011
+ * Unique identifier for this execution run.
2012
+ */
1956
2013
  runId;
1957
2014
  #options;
2015
+ /**
2016
+ * The processor runner for this stream.
2017
+ */
1958
2018
  processorRunner;
2019
+ /**
2020
+ * The message list for this stream.
2021
+ */
1959
2022
  messageList;
1960
2023
  constructor({
1961
2024
  stream,
@@ -2126,7 +2189,7 @@ var MastraModelOutput = class extends MastraBase {
2126
2189
  if (messagesWithStructuredData[0] && messagesWithStructuredData[0].content.metadata?.structuredOutput) {
2127
2190
  const structuredOutput = messagesWithStructuredData[0].content.metadata.structuredOutput;
2128
2191
  self.#delayedPromises.object.resolve(structuredOutput);
2129
- } else if (!self.#options.objectOptions?.schema) {
2192
+ } else if (!self.#options.output) {
2130
2193
  self.#delayedPromises.object.resolve(void 0);
2131
2194
  }
2132
2195
  self.#delayedPromises.text.resolve(outputText);
@@ -2134,7 +2197,7 @@ var MastraModelOutput = class extends MastraBase {
2134
2197
  } else {
2135
2198
  self.#delayedPromises.text.resolve(self.#bufferedText.join(""));
2136
2199
  self.#delayedPromises.finishReason.resolve(self.#finishReason);
2137
- if (!self.#options.objectOptions?.schema) {
2200
+ if (!self.#options.output) {
2138
2201
  self.#delayedPromises.object.resolve(void 0);
2139
2202
  }
2140
2203
  }
@@ -2252,42 +2315,51 @@ var MastraModelOutput = class extends MastraBase {
2252
2315
  messageList,
2253
2316
  options: {
2254
2317
  toolCallStreaming: options?.toolCallStreaming,
2255
- objectOptions: options?.objectOptions
2318
+ output: options?.output
2256
2319
  }
2257
2320
  });
2258
2321
  }
2259
- getDelayedPromise(promise) {
2322
+ #getDelayedPromise(promise) {
2260
2323
  if (!this.#streamConsumed) {
2261
2324
  void this.consumeStream();
2262
2325
  }
2263
2326
  return promise.promise;
2264
2327
  }
2328
+ /**
2329
+ * Resolves to the complete text response after streaming completes.
2330
+ */
2265
2331
  get text() {
2266
- return this.getDelayedPromise(this.#delayedPromises.text);
2332
+ return this.#getDelayedPromise(this.#delayedPromises.text);
2267
2333
  }
2334
+ /**
2335
+ * Resolves to complete reasoning text for models that support reasoning.
2336
+ */
2268
2337
  get reasoning() {
2269
- return this.getDelayedPromise(this.#delayedPromises.reasoning);
2338
+ return this.#getDelayedPromise(this.#delayedPromises.reasoning);
2270
2339
  }
2271
2340
  get reasoningText() {
2272
- return this.getDelayedPromise(this.#delayedPromises.reasoningText);
2341
+ return this.#getDelayedPromise(this.#delayedPromises.reasoningText);
2273
2342
  }
2274
2343
  get reasoningDetails() {
2275
- return this.getDelayedPromise(this.#delayedPromises.reasoningDetails);
2344
+ return this.#getDelayedPromise(this.#delayedPromises.reasoningDetails);
2276
2345
  }
2277
2346
  get sources() {
2278
- return this.getDelayedPromise(this.#delayedPromises.sources);
2347
+ return this.#getDelayedPromise(this.#delayedPromises.sources);
2279
2348
  }
2280
2349
  get files() {
2281
- return this.getDelayedPromise(this.#delayedPromises.files);
2350
+ return this.#getDelayedPromise(this.#delayedPromises.files);
2282
2351
  }
2283
2352
  get steps() {
2284
- return this.getDelayedPromise(this.#delayedPromises.steps);
2353
+ return this.#getDelayedPromise(this.#delayedPromises.steps);
2285
2354
  }
2286
2355
  teeStream() {
2287
2356
  const [stream1, stream2] = this.#baseStream.tee();
2288
2357
  this.#baseStream = stream2;
2289
2358
  return stream1;
2290
2359
  }
2360
+ /**
2361
+ * Stream of all chunks. Provides complete control over stream processing.
2362
+ */
2291
2363
  get fullStream() {
2292
2364
  const self = this;
2293
2365
  let fullStream = this.teeStream();
@@ -2318,7 +2390,7 @@ var MastraModelOutput = class extends MastraBase {
2318
2390
  }
2319
2391
  }
2320
2392
  })).pipeThrough(createObjectStreamTransformer({
2321
- schema: self.#options.objectOptions?.schema,
2393
+ schema: self.#options.output,
2322
2394
  onFinish: data => self.#delayedPromises.object.resolve(data)
2323
2395
  })).pipeThrough(new TransformStream({
2324
2396
  transform(chunk, controller) {
@@ -2336,30 +2408,57 @@ var MastraModelOutput = class extends MastraBase {
2336
2408
  }
2337
2409
  }));
2338
2410
  }
2411
+ /**
2412
+ * Resolves to the reason generation finished.
2413
+ */
2339
2414
  get finishReason() {
2340
- return this.getDelayedPromise(this.#delayedPromises.finishReason);
2415
+ return this.#getDelayedPromise(this.#delayedPromises.finishReason);
2341
2416
  }
2417
+ /**
2418
+ * Resolves to array of all tool calls made during execution.
2419
+ */
2342
2420
  get toolCalls() {
2343
- return this.getDelayedPromise(this.#delayedPromises.toolCalls);
2421
+ return this.#getDelayedPromise(this.#delayedPromises.toolCalls);
2344
2422
  }
2423
+ /**
2424
+ * Resolves to array of all tool execution results.
2425
+ */
2345
2426
  get toolResults() {
2346
- return this.getDelayedPromise(this.#delayedPromises.toolResults);
2427
+ return this.#getDelayedPromise(this.#delayedPromises.toolResults);
2347
2428
  }
2429
+ /**
2430
+ * Resolves to token usage statistics including inputTokens, outputTokens, and totalTokens.
2431
+ */
2348
2432
  get usage() {
2349
- return this.getDelayedPromise(this.#delayedPromises.usage);
2433
+ return this.#getDelayedPromise(this.#delayedPromises.usage);
2350
2434
  }
2435
+ /**
2436
+ * Resolves to array of all warnings generated during execution.
2437
+ */
2351
2438
  get warnings() {
2352
- return this.getDelayedPromise(this.#delayedPromises.warnings);
2439
+ return this.#getDelayedPromise(this.#delayedPromises.warnings);
2353
2440
  }
2441
+ /**
2442
+ * Resolves to provider metadata generated during execution.
2443
+ */
2354
2444
  get providerMetadata() {
2355
- return this.getDelayedPromise(this.#delayedPromises.providerMetadata);
2445
+ return this.#getDelayedPromise(this.#delayedPromises.providerMetadata);
2356
2446
  }
2447
+ /**
2448
+ * Resolves to the complete response from the model.
2449
+ */
2357
2450
  get response() {
2358
- return this.getDelayedPromise(this.#delayedPromises.response);
2451
+ return this.#getDelayedPromise(this.#delayedPromises.response);
2359
2452
  }
2453
+ /**
2454
+ * Resolves to the complete request sent to the model.
2455
+ */
2360
2456
  get request() {
2361
- return this.getDelayedPromise(this.#delayedPromises.request);
2457
+ return this.#getDelayedPromise(this.#delayedPromises.request);
2362
2458
  }
2459
+ /**
2460
+ * Resolves to an error if an error occurred during streaming.
2461
+ */
2363
2462
  get error() {
2364
2463
  if (typeof this.#error === "object") {
2365
2464
  const error = new Error(this.#error.message);
@@ -2386,12 +2485,6 @@ var MastraModelOutput = class extends MastraBase {
2386
2485
  }
2387
2486
  }
2388
2487
  }
2389
- // toUIMessageStreamResponse() {
2390
- // const stream = this.teeStream()
2391
- // .pipeThrough(new JsonToSseTransformStream())
2392
- // .pipeThrough(new TextEncoderStream())
2393
- // return new Response(stream as BodyInit);
2394
- // }
2395
2488
  async consumeStream(options) {
2396
2489
  this.#streamConsumed = true;
2397
2490
  try {
@@ -2407,6 +2500,9 @@ var MastraModelOutput = class extends MastraBase {
2407
2500
  options?.onError?.(error);
2408
2501
  }
2409
2502
  }
2503
+ /**
2504
+ * Returns complete output including text, usage, tool calls, and all metadata.
2505
+ */
2410
2506
  async getFullOutput() {
2411
2507
  await this.consumeStream({
2412
2508
  onError: error => {
@@ -2438,28 +2534,53 @@ var MastraModelOutput = class extends MastraBase {
2438
2534
  fullOutput.response.messages = this.messageList.get.response.aiV5.model();
2439
2535
  return fullOutput;
2440
2536
  }
2537
+ /**
2538
+ * The tripwire flag is set when the stream is aborted due to an output processor blocking the content.
2539
+ */
2441
2540
  get tripwire() {
2442
2541
  return this.#tripwire;
2443
2542
  }
2543
+ /**
2544
+ * The reason for the tripwire.
2545
+ */
2444
2546
  get tripwireReason() {
2445
2547
  return this.#tripwireReason;
2446
2548
  }
2549
+ /**
2550
+ * The total usage of the stream.
2551
+ */
2447
2552
  get totalUsage() {
2448
- return this.getDelayedPromise(this.#delayedPromises.totalUsage);
2553
+ return this.#getDelayedPromise(this.#delayedPromises.totalUsage);
2449
2554
  }
2450
2555
  get content() {
2451
- return this.getDelayedPromise(this.#delayedPromises.content);
2556
+ return this.#getDelayedPromise(this.#delayedPromises.content);
2452
2557
  }
2558
+ /**
2559
+ * Other output stream formats.
2560
+ */
2453
2561
  get aisdk() {
2454
2562
  return {
2563
+ /**
2564
+ * The AI SDK v5 output stream format.
2565
+ */
2455
2566
  v5: this.#aisdkv5
2456
2567
  };
2457
2568
  }
2569
+ /**
2570
+ * Stream of valid JSON chunks. The final JSON result is validated against the output schema when the stream ends.
2571
+ *
2572
+ * @example
2573
+ * ```typescript
2574
+ * const stream = await agent.streamVNext("Extract data", {
2575
+ * output: z.object({ name: z.string(), age: z.number() })
2576
+ * });
2577
+ * // partial json chunks
2578
+ * for await (const data of stream.objectStream) {
2579
+ * console.log(data); // { name: 'John' }, { name: 'John', age: 30 }
2580
+ * }
2581
+ * ```
2582
+ */
2458
2583
  get objectStream() {
2459
- const self = this;
2460
- if (!self.#options.objectOptions?.schema) {
2461
- throw new Error("objectStream requires objectOptions");
2462
- }
2463
2584
  return this.fullStream.pipeThrough(new TransformStream({
2464
2585
  transform(chunk, controller) {
2465
2586
  if (chunk.type === "object") {
@@ -2468,34 +2589,31 @@ var MastraModelOutput = class extends MastraBase {
2468
2589
  }
2469
2590
  }));
2470
2591
  }
2592
+ /**
2593
+ * Stream of individual array elements when output schema is an array type.
2594
+ */
2471
2595
  get elementStream() {
2472
2596
  let publishedElements = 0;
2473
- const self = this;
2474
- if (!self.#options.objectOptions) {
2475
- throw new Error("elementStream requires objectOptions");
2476
- }
2477
2597
  return this.fullStream.pipeThrough(new TransformStream({
2478
2598
  transform(chunk, controller) {
2479
- switch (chunk.type) {
2480
- case "object":
2481
- {
2482
- const array = chunk.object;
2483
- if (Array.isArray(array)) {
2484
- for (; publishedElements < array.length; publishedElements++) {
2485
- controller.enqueue(array[publishedElements]);
2486
- }
2487
- }
2488
- break;
2599
+ if (chunk.type === "object") {
2600
+ if (Array.isArray(chunk.object)) {
2601
+ for (; publishedElements < chunk.object.length; publishedElements++) {
2602
+ controller.enqueue(chunk.object[publishedElements]);
2489
2603
  }
2604
+ }
2490
2605
  }
2491
2606
  }
2492
2607
  }));
2493
2608
  }
2609
+ /**
2610
+ * Stream of only text content, filtering out metadata and other chunk types.
2611
+ */
2494
2612
  get textStream() {
2495
2613
  const self = this;
2496
- const outputSchema = getTransformedSchema(self.#options.objectOptions?.schema);
2614
+ const outputSchema = getTransformedSchema(self.#options.output);
2497
2615
  if (outputSchema?.outputFormat === "array") {
2498
- return this.fullStream.pipeThrough(createJsonTextStreamTransformer(self.#options.objectOptions));
2616
+ return this.fullStream.pipeThrough(createJsonTextStreamTransformer(self.#options.output));
2499
2617
  }
2500
2618
  return this.teeStream().pipeThrough(new TransformStream({
2501
2619
  transform(chunk, controller) {
@@ -2505,29 +2623,47 @@ var MastraModelOutput = class extends MastraBase {
2505
2623
  }
2506
2624
  }));
2507
2625
  }
2626
+ /**
2627
+ * Resolves to the complete object response from the model. Validated against the 'output' schema when the stream ends.
2628
+ *
2629
+ * @example
2630
+ * ```typescript
2631
+ * const stream = await agent.streamVNext("Extract data", {
2632
+ * output: z.object({ name: z.string(), age: z.number() })
2633
+ * });
2634
+ * // final validated json
2635
+ * const data = await stream.object // { name: 'John', age: 30 }
2636
+ * ```
2637
+ */
2508
2638
  get object() {
2509
- if (!this.processorRunner && !this.#options.objectOptions?.schema) {
2639
+ if (!this.processorRunner && !this.#options.output) {
2510
2640
  this.#delayedPromises.object.resolve(void 0);
2511
2641
  }
2512
- return this.getDelayedPromise(this.#delayedPromises.object);
2642
+ return this.#getDelayedPromise(this.#delayedPromises.object);
2513
2643
  }
2514
2644
  // Internal methods for immediate values - used internally by Mastra (llm-execution.ts bailing on errors/abort signals with current state)
2515
2645
  // These are not part of the public API
2646
+ /** @internal */
2516
2647
  _getImmediateToolCalls() {
2517
2648
  return this.#toolCalls;
2518
2649
  }
2650
+ /** @internal */
2519
2651
  _getImmediateToolResults() {
2520
2652
  return this.#toolResults;
2521
2653
  }
2654
+ /** @internal */
2522
2655
  _getImmediateText() {
2523
2656
  return this.#bufferedText.join("");
2524
2657
  }
2658
+ /** @internal */
2525
2659
  _getImmediateUsage() {
2526
2660
  return this.#usageCount;
2527
2661
  }
2662
+ /** @internal */
2528
2663
  _getImmediateWarnings() {
2529
2664
  return this.#warnings;
2530
2665
  }
2666
+ /** @internal */
2531
2667
  _getImmediateFinishReason() {
2532
2668
  return this.#finishReason;
2533
2669
  }
@@ -2763,7 +2899,7 @@ function execute({
2763
2899
  telemetry_settings,
2764
2900
  includeRawChunks,
2765
2901
  modelSettings,
2766
- objectOptions,
2902
+ output,
2767
2903
  headers
2768
2904
  }) {
2769
2905
  const v5 = new AISDKV5InputStream({
@@ -2791,7 +2927,7 @@ function execute({
2791
2927
  providerOptions,
2792
2928
  abortSignal: options?.abortSignal,
2793
2929
  includeRawChunks,
2794
- responseFormat: objectOptions?.schema ? getResponseFormat(objectOptions?.schema) : void 0,
2930
+ responseFormat: output ? getResponseFormat(output) : void 0,
2795
2931
  ...(modelSettings ?? {}),
2796
2932
  headers
2797
2933
  });
@@ -3141,7 +3277,7 @@ function createLLMExecutionStep({
3141
3277
  options,
3142
3278
  toolCallStreaming,
3143
3279
  controller,
3144
- objectOptions,
3280
+ output,
3145
3281
  headers
3146
3282
  }) {
3147
3283
  return createStep({
@@ -3174,7 +3310,7 @@ function createLLMExecutionStep({
3174
3310
  modelSettings,
3175
3311
  telemetry_settings,
3176
3312
  includeRawChunks,
3177
- objectOptions,
3313
+ output,
3178
3314
  headers,
3179
3315
  onResult: ({
3180
3316
  warnings: warningsFromStream,
@@ -3218,7 +3354,7 @@ function createLLMExecutionStep({
3218
3354
  toolCallStreaming,
3219
3355
  telemetry_settings,
3220
3356
  includeRawChunks,
3221
- objectOptions
3357
+ output
3222
3358
  }
3223
3359
  });
3224
3360
  try {
@@ -3808,7 +3944,7 @@ function loop({
3808
3944
  onFinish: rest.options?.onFinish,
3809
3945
  onStepFinish: rest.options?.onStepFinish,
3810
3946
  includeRawChunks: !!includeRawChunks,
3811
- objectOptions: rest.objectOptions,
3947
+ output: rest.output,
3812
3948
  outputProcessors
3813
3949
  }
3814
3950
  });
@@ -3897,7 +4033,7 @@ var MastraLLMVNext = class extends MastraBase {
3897
4033
  telemetry_settings,
3898
4034
  threadId,
3899
4035
  resourceId,
3900
- objectOptions,
4036
+ output,
3901
4037
  options,
3902
4038
  outputProcessors
3903
4039
  // ...rest
@@ -3910,8 +4046,8 @@ var MastraLLMVNext = class extends MastraBase {
3910
4046
  messages,
3911
4047
  tools: Object.keys(tools || {})
3912
4048
  });
3913
- if (objectOptions?.schema) {
3914
- objectOptions.schema = this._applySchemaCompat(objectOptions.schema);
4049
+ if (output) {
4050
+ output = this._applySchemaCompat(output);
3915
4051
  }
3916
4052
  try {
3917
4053
  const messageList = new MessageList({
@@ -3930,7 +4066,7 @@ var MastraLLMVNext = class extends MastraBase {
3930
4066
  ...this.experimental_telemetry,
3931
4067
  ...telemetry_settings
3932
4068
  },
3933
- objectOptions,
4069
+ output,
3934
4070
  outputProcessors,
3935
4071
  options: {
3936
4072
  ...options,
@@ -9330,7 +9466,7 @@ var Agent = class extends (_a = MastraBase) {
9330
9466
  const systemMessages = messageList.getSystemMessages()?.map(m => m.content)?.join(`
9331
9467
  `) ?? void 0;
9332
9468
  const newMessages = messageList.get.input.v1();
9333
- const processedMemoryMessages = memory.processMessages({
9469
+ const processedMemoryMessages = await memory.processMessages({
9334
9470
  // these will be processed
9335
9471
  messages: messageList.get.remembered.v1(),
9336
9472
  // these are here for inspecting but shouldn't be returned by the processor
@@ -10126,7 +10262,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
10126
10262
  });
10127
10263
  const systemMessage = [...messageList.getSystemMessages(), ...messageList.getSystemMessages("memory")]?.map(m => m.content)?.join(`
10128
10264
  `) ?? void 0;
10129
- const processedMemoryMessages = memory.processMessages({
10265
+ const processedMemoryMessages = await memory.processMessages({
10130
10266
  // these will be processed
10131
10267
  messages: messageList.get.remembered.v1(),
10132
10268
  // these are here for inspecting but shouldn't be returned by the processor
@@ -10800,7 +10936,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
10800
10936
  });
10801
10937
  const systemMessage = [...messageList.getSystemMessages(), ...messageList.getSystemMessages("memory")]?.map(m => m.content)?.join(`
10802
10938
  `) ?? void 0;
10803
- const processedMemoryMessages = memory.processMessages({
10939
+ const processedMemoryMessages = await memory.processMessages({
10804
10940
  // these will be processed
10805
10941
  messages: messageList.get.remembered.v1(),
10806
10942
  // these are here for inspecting but shouldn't be returned by the processor
@@ -10844,12 +10980,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
10844
10980
  }) : this.#outputProcessors : []);
10845
10981
  const streamResult = llm.stream({
10846
10982
  ...inputData,
10847
- outputProcessors,
10848
- ...(inputData.output ? {
10849
- objectOptions: {
10850
- schema: inputData.output
10851
- }
10852
- } : {})
10983
+ outputProcessors
10853
10984
  });
10854
10985
  if (options.format === "aisdk") {
10855
10986
  return streamResult.aisdk.v5;
@@ -10966,7 +11097,6 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
10966
11097
  tools: result.tools,
10967
11098
  resourceId: result.resourceId,
10968
11099
  threadId: result.threadId,
10969
- output: result.output,
10970
11100
  structuredOutput: result.structuredOutput,
10971
11101
  stopWhen: result.stopWhen,
10972
11102
  options: {
@@ -11010,9 +11140,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
11010
11140
  },
11011
11141
  onStepFinish: result.onStepFinish
11012
11142
  },
11013
- objectOptions: {
11014
- schema: options.output
11015
- },
11143
+ output: options.output,
11016
11144
  outputProcessors: effectiveOutputProcessors,
11017
11145
  modelSettings: {
11018
11146
  temperature: 0,
@@ -12373,7 +12501,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
12373
12501
  abortController,
12374
12502
  runtimeContext,
12375
12503
  skipEmits = false,
12376
- writableStream
12504
+ writableStream,
12505
+ serializedStepGraph
12377
12506
  }) {
12378
12507
  const startTime = resume?.steps[0] === step.id ? void 0 : Date.now();
12379
12508
  const resumeTime = resume?.steps[0] === step.id ? Date.now() : void 0;
@@ -12390,7 +12519,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
12390
12519
  } : {}),
12391
12520
  ...(resumeTime ? {
12392
12521
  resumedAt: resumeTime
12393
- } : {})
12522
+ } : {}),
12523
+ status: "running"
12394
12524
  };
12395
12525
  const stepAISpan = executionContext.aiSpan?.createChildSpan({
12396
12526
  name: `workflow step: '${step.id}'`,
@@ -12406,7 +12536,6 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
12406
12536
  payload: {
12407
12537
  currentStep: {
12408
12538
  id: step.id,
12409
- status: "running",
12410
12539
  ...stepInfo
12411
12540
  },
12412
12541
  workflowState: {
@@ -12414,7 +12543,6 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
12414
12543
  steps: {
12415
12544
  ...stepResults,
12416
12545
  [step.id]: {
12417
- status: "running",
12418
12546
  ...stepInfo
12419
12547
  }
12420
12548
  },
@@ -12429,11 +12557,22 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
12429
12557
  payload: {
12430
12558
  id: step.id,
12431
12559
  stepCallId,
12432
- ...stepInfo,
12433
- status: "running"
12560
+ ...stepInfo
12434
12561
  }
12435
12562
  });
12436
12563
  }
12564
+ await this.persistStepUpdate({
12565
+ workflowId,
12566
+ runId,
12567
+ serializedStepGraph,
12568
+ stepResults: {
12569
+ ...stepResults,
12570
+ [step.id]: stepInfo
12571
+ },
12572
+ executionContext,
12573
+ workflowStatus: "running",
12574
+ runtimeContext
12575
+ });
12437
12576
  const _runStep = (step2, spanName, attributes) => {
12438
12577
  return async data => {
12439
12578
  const aiTracingContext = {
@@ -12859,7 +12998,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
12859
12998
  emitter,
12860
12999
  abortController,
12861
13000
  runtimeContext,
12862
- writableStream
13001
+ writableStream,
13002
+ serializedStepGraph
12863
13003
  }) {
12864
13004
  const {
12865
13005
  step,
@@ -12884,7 +13024,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
12884
13024
  emitter,
12885
13025
  abortController,
12886
13026
  runtimeContext,
12887
- writableStream
13027
+ writableStream,
13028
+ serializedStepGraph
12888
13029
  });
12889
13030
  if (currentResume && result.status !== "suspended") {
12890
13031
  currentResume = void 0;
@@ -12936,7 +13077,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
12936
13077
  emitter,
12937
13078
  abortController,
12938
13079
  runtimeContext,
12939
- writableStream
13080
+ writableStream,
13081
+ serializedStepGraph
12940
13082
  }) {
12941
13083
  const {
12942
13084
  step,
@@ -13006,7 +13148,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
13006
13148
  abortController,
13007
13149
  runtimeContext,
13008
13150
  skipEmits: true,
13009
- writableStream
13151
+ writableStream,
13152
+ serializedStepGraph
13010
13153
  });
13011
13154
  }));
13012
13155
  for (const result of itemsResults) {
@@ -13195,7 +13338,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
13195
13338
  emitter,
13196
13339
  abortController,
13197
13340
  runtimeContext,
13198
- writableStream
13341
+ writableStream,
13342
+ serializedStepGraph
13199
13343
  });
13200
13344
  } else if (resume?.resumePath?.length && entry.type === "parallel") {
13201
13345
  const idx = resume.resumePath.shift();
@@ -13323,7 +13467,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
13323
13467
  emitter,
13324
13468
  abortController,
13325
13469
  runtimeContext,
13326
- writableStream
13470
+ writableStream,
13471
+ serializedStepGraph
13327
13472
  });
13328
13473
  } else if (entry.type === "foreach") {
13329
13474
  execResults = await this.executeForeach({
@@ -13338,7 +13483,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
13338
13483
  emitter,
13339
13484
  abortController,
13340
13485
  runtimeContext,
13341
- writableStream
13486
+ writableStream,
13487
+ serializedStepGraph
13342
13488
  });
13343
13489
  } else if (entry.type === "sleep") {
13344
13490
  const startedAt = Date.now();
@@ -13636,15 +13782,6 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
13636
13782
  emitter,
13637
13783
  timeout: entry.timeout
13638
13784
  });
13639
- await this.persistStepUpdate({
13640
- workflowId,
13641
- runId,
13642
- serializedStepGraph,
13643
- stepResults,
13644
- executionContext,
13645
- workflowStatus: "running",
13646
- runtimeContext
13647
- });
13648
13785
  const {
13649
13786
  step
13650
13787
  } = entry;
@@ -13662,7 +13799,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
13662
13799
  emitter,
13663
13800
  abortController,
13664
13801
  runtimeContext,
13665
- writableStream
13802
+ writableStream,
13803
+ serializedStepGraph
13666
13804
  });
13667
13805
  } catch (error) {
13668
13806
  execResults = {
@@ -15054,5 +15192,5 @@ function deepMergeWorkflowState(a, b) {
15054
15192
  }
15055
15193
 
15056
15194
  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 };
15057
- //# sourceMappingURL=chunk-DQ3LHZOM.js.map
15058
- //# sourceMappingURL=chunk-DQ3LHZOM.js.map
15195
+ //# sourceMappingURL=chunk-5MWUQWB2.js.map
15196
+ //# sourceMappingURL=chunk-5MWUQWB2.js.map