@mastra/core 0.16.0-alpha.1 → 0.16.1-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 (117) hide show
  1. package/CHANGELOG.md +45 -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/{chunk-HGYL2SSF.js → chunk-2QDX6OPE.js} +3 -3
  9. package/dist/{chunk-HGYL2SSF.js.map → chunk-2QDX6OPE.js.map} +1 -1
  10. package/dist/{chunk-3CJXUAA2.cjs → chunk-33GDW3SI.cjs} +2 -4
  11. package/dist/chunk-33GDW3SI.cjs.map +1 -0
  12. package/dist/{chunk-HF7HXOCC.js → chunk-4BQBSBQP.js} +31 -6
  13. package/dist/chunk-4BQBSBQP.js.map +1 -0
  14. package/dist/{chunk-DRMT4EQA.cjs → chunk-4FWIB47J.cjs} +4 -4
  15. package/dist/{chunk-DRMT4EQA.cjs.map → chunk-4FWIB47J.cjs.map} +1 -1
  16. package/dist/{chunk-LVGGMWSE.cjs → chunk-6FVCJBBG.cjs} +3 -3
  17. package/dist/chunk-6FVCJBBG.cjs.map +1 -0
  18. package/dist/{chunk-JTU7FZ5O.js → chunk-CWK46GAF.js} +2 -4
  19. package/dist/chunk-CWK46GAF.js.map +1 -0
  20. package/dist/{chunk-SLDGELU7.cjs → chunk-G7YM2FA2.cjs} +7 -7
  21. package/dist/{chunk-SLDGELU7.cjs.map → chunk-G7YM2FA2.cjs.map} +1 -1
  22. package/dist/chunk-GXSERFAG.js +3 -0
  23. package/dist/{chunk-S43VACTO.js.map → chunk-GXSERFAG.js.map} +1 -1
  24. package/dist/{chunk-EU3ADOKK.js → chunk-H33WOKEO.js} +4 -4
  25. package/dist/{chunk-EU3ADOKK.js.map → chunk-H33WOKEO.js.map} +1 -1
  26. package/dist/{chunk-7GYN2OE3.cjs → chunk-IUF2ESZH.cjs} +100 -76
  27. package/dist/chunk-IUF2ESZH.cjs.map +1 -0
  28. package/dist/{chunk-SIKEQ32R.cjs → chunk-KT4WNDGP.cjs} +32 -7
  29. package/dist/chunk-KT4WNDGP.cjs.map +1 -0
  30. package/dist/{chunk-YEZD4ZLX.cjs → chunk-LGJCH6XF.cjs} +6 -6
  31. package/dist/{chunk-YEZD4ZLX.cjs.map → chunk-LGJCH6XF.cjs.map} +1 -1
  32. package/dist/{chunk-YILDTNQM.js → chunk-MW4CYUSP.js} +70 -46
  33. package/dist/chunk-MW4CYUSP.js.map +1 -0
  34. package/dist/{chunk-JT2QXHUD.js → chunk-N3HXDMF2.js} +3 -3
  35. package/dist/{chunk-JT2QXHUD.js.map → chunk-N3HXDMF2.js.map} +1 -1
  36. package/dist/{chunk-MNDKBEEQ.cjs → chunk-OE3SL5VG.cjs} +6 -6
  37. package/dist/{chunk-MNDKBEEQ.cjs.map → chunk-OE3SL5VG.cjs.map} +1 -1
  38. package/dist/{chunk-A5VGUE2H.js → chunk-RT2ETR6A.js} +3 -3
  39. package/dist/{chunk-A5VGUE2H.js.map → chunk-RT2ETR6A.js.map} +1 -1
  40. package/dist/{chunk-WWQ3QRPF.js → chunk-ULA3AGAI.js} +3 -3
  41. package/dist/chunk-ULA3AGAI.js.map +1 -0
  42. package/dist/{chunk-2BFCQRWV.cjs → chunk-VMV5VND5.cjs} +7 -7
  43. package/dist/{chunk-2BFCQRWV.cjs.map → chunk-VMV5VND5.cjs.map} +1 -1
  44. package/dist/{chunk-D2Y5SXZN.js → chunk-WW62UQPE.js} +4 -4
  45. package/dist/{chunk-D2Y5SXZN.js.map → chunk-WW62UQPE.js.map} +1 -1
  46. package/dist/chunk-X4RMXTXF.cjs +4 -0
  47. package/dist/{chunk-IHVB4C5U.cjs.map → chunk-X4RMXTXF.cjs.map} +1 -1
  48. package/dist/{chunk-TCYQAAIT.cjs → chunk-Y6MXP3EN.cjs} +6 -6
  49. package/dist/{chunk-TCYQAAIT.cjs.map → chunk-Y6MXP3EN.cjs.map} +1 -1
  50. package/dist/{chunk-MMYGYTJK.js → chunk-YUJ7GETS.js} +3 -3
  51. package/dist/{chunk-MMYGYTJK.js.map → chunk-YUJ7GETS.js.map} +1 -1
  52. package/dist/index.cjs +43 -43
  53. package/dist/index.js +9 -9
  54. package/dist/llm/model/model.loop.d.ts.map +1 -1
  55. package/dist/loop/index.cjs +2 -2
  56. package/dist/loop/index.js +1 -1
  57. package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
  58. package/dist/mastra/index.cjs +2 -2
  59. package/dist/mastra/index.js +1 -1
  60. package/dist/mcp/index.cjs +4 -0
  61. package/dist/mcp/index.cjs.map +1 -1
  62. package/dist/mcp/index.d.ts +3 -1
  63. package/dist/mcp/index.d.ts.map +1 -1
  64. package/dist/mcp/index.js +4 -0
  65. package/dist/mcp/index.js.map +1 -1
  66. package/dist/memory/index.cjs +4 -4
  67. package/dist/memory/index.js +1 -1
  68. package/dist/network/index.cjs +2 -2
  69. package/dist/network/index.js +1 -1
  70. package/dist/network/vNext/index.cjs +14 -14
  71. package/dist/network/vNext/index.js +2 -2
  72. package/dist/processors/index.cjs +8 -8
  73. package/dist/processors/index.js +2 -2
  74. package/dist/relevance/index.cjs +4 -4
  75. package/dist/relevance/index.js +1 -1
  76. package/dist/scores/index.cjs +8 -8
  77. package/dist/scores/index.js +1 -1
  78. package/dist/storage/base.d.ts.map +1 -1
  79. package/dist/storage/index.cjs +9 -9
  80. package/dist/storage/index.js +3 -3
  81. package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
  82. package/dist/stream/aisdk/v5/model-supports.d.ts +25 -0
  83. package/dist/stream/aisdk/v5/model-supports.d.ts.map +1 -0
  84. package/dist/stream/base/output-format-handlers.d.ts.map +1 -1
  85. package/dist/stream/index.cjs +3 -3
  86. package/dist/stream/index.js +1 -1
  87. package/dist/test-utils/llm-mock.cjs +2 -2
  88. package/dist/test-utils/llm-mock.js +1 -1
  89. package/dist/tools/index.cjs +0 -4
  90. package/dist/tools/index.d.ts +0 -1
  91. package/dist/tools/index.d.ts.map +1 -1
  92. package/dist/tools/index.js +1 -1
  93. package/dist/tools/types.d.ts +1 -1
  94. package/dist/tools/types.d.ts.map +1 -1
  95. package/dist/utils.cjs +17 -17
  96. package/dist/utils.d.ts +1 -1
  97. package/dist/utils.d.ts.map +1 -1
  98. package/dist/utils.js +1 -1
  99. package/dist/workflows/evented/index.cjs +10 -10
  100. package/dist/workflows/evented/index.js +1 -1
  101. package/dist/workflows/index.cjs +10 -10
  102. package/dist/workflows/index.js +1 -1
  103. package/dist/workflows/legacy/index.cjs +22 -22
  104. package/dist/workflows/legacy/index.js +1 -1
  105. package/dist/workflows/workflow.d.ts +2 -1
  106. package/dist/workflows/workflow.d.ts.map +1 -1
  107. package/package.json +5 -4
  108. package/dist/chunk-3CJXUAA2.cjs.map +0 -1
  109. package/dist/chunk-7GYN2OE3.cjs.map +0 -1
  110. package/dist/chunk-HF7HXOCC.js.map +0 -1
  111. package/dist/chunk-IHVB4C5U.cjs +0 -4
  112. package/dist/chunk-JTU7FZ5O.js.map +0 -1
  113. package/dist/chunk-LVGGMWSE.cjs.map +0 -1
  114. package/dist/chunk-S43VACTO.js +0 -3
  115. package/dist/chunk-SIKEQ32R.cjs.map +0 -1
  116. package/dist/chunk-WWQ3QRPF.js.map +0 -1
  117. package/dist/chunk-YILDTNQM.js.map +0 -1
@@ -1,10 +1,10 @@
1
1
  import { DefaultVoice } from './chunk-QQIBOVFQ.js';
2
2
  import { STREAM_FORMAT_SYMBOL, EMITTER_SYMBOL } from './chunk-NLNKQD2T.js';
3
3
  import { InstrumentClass, Telemetry } from './chunk-TLJPVRO5.js';
4
- import { MastraLLMV1 } from './chunk-HGYL2SSF.js';
5
- import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-HF7HXOCC.js';
4
+ import { MastraLLMV1 } from './chunk-2QDX6OPE.js';
5
+ import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-4BQBSBQP.js';
6
6
  import { executeHook } from './chunk-TTELJD4F.js';
7
- import { ensureToolProperties, makeCoreTool, createMastraProxy, delay } from './chunk-WWQ3QRPF.js';
7
+ import { ensureToolProperties, makeCoreTool, createMastraProxy, delay } from './chunk-ULA3AGAI.js';
8
8
  import { RuntimeContext } from './chunk-HLRWYUFN.js';
9
9
  import { ToolStream } from './chunk-YW7UILPE.js';
10
10
  import { createTool, Tool } from './chunk-BJGHUKKM.js';
@@ -22,7 +22,7 @@ import { OpenAIReasoningSchemaCompatLayer, OpenAISchemaCompatLayer, GoogleSchema
22
22
  import { createTextStreamResponse, createUIMessageStreamResponse, createUIMessageStream, consumeStream, generateId, asSchema, parsePartialJson, isDeepEqualData, tool, stepCountIs } from 'ai-v5';
23
23
  import { getErrorMessage, TypeValidationError } from '@ai-sdk/provider-v5';
24
24
  import { context, trace } from '@opentelemetry/api';
25
- import { isAbortError } from '@ai-sdk/provider-utils-v5';
25
+ import { isAbortError, injectJsonInstructionIntoMessages } from '@ai-sdk/provider-utils-v5';
26
26
  import { isAbortError as isAbortError$1 } from '@ai-sdk/provider-utils';
27
27
  import { get } from 'radash';
28
28
  import sift from 'sift';
@@ -1615,22 +1615,32 @@ var ObjectFormatHandler = class extends BaseFormatHandler {
1615
1615
  shouldEmit: false
1616
1616
  };
1617
1617
  }
1618
- async validateAndTransformFinal(finalValue) {
1619
- if (!finalValue) {
1618
+ async validateAndTransformFinal(finalRawValue) {
1619
+ if (!finalRawValue) {
1620
1620
  return {
1621
1621
  success: false,
1622
1622
  error: new Error("No object generated: could not parse the response.")
1623
1623
  };
1624
1624
  }
1625
+ let rawValue = finalRawValue;
1626
+ if (typeof finalRawValue === "string" && finalRawValue?.includes?.("```json")) {
1627
+ const match = finalRawValue.match(/```json\s*\n?([\s\S]*?)\n?\s*```/);
1628
+ if (match && match[1]) {
1629
+ rawValue = match[1].trim();
1630
+ }
1631
+ }
1632
+ const {
1633
+ value
1634
+ } = await parsePartialJson(rawValue);
1625
1635
  if (!this.schema) {
1626
1636
  return {
1627
1637
  success: true,
1628
- value: finalValue
1638
+ value
1629
1639
  };
1630
1640
  }
1631
1641
  try {
1632
1642
  const result = await safeValidateTypes({
1633
- value: finalValue,
1643
+ value,
1634
1644
  schema: this.schema
1635
1645
  });
1636
1646
  if (result.success) {
@@ -1796,7 +1806,17 @@ var EnumFormatHandler = class extends BaseFormatHandler {
1796
1806
  shouldEmit: false
1797
1807
  };
1798
1808
  }
1799
- async validateAndTransformFinal(finalValue) {
1809
+ async validateAndTransformFinal(rawFinalValue) {
1810
+ const {
1811
+ value
1812
+ } = await parsePartialJson(rawFinalValue);
1813
+ if (!(typeof value === "object" && value !== null && "result" in value)) {
1814
+ return {
1815
+ success: false,
1816
+ error: new Error("Invalid enum format: expected object with result property")
1817
+ };
1818
+ }
1819
+ const finalValue = value.result;
1800
1820
  if (!finalValue || typeof finalValue !== "object" || typeof finalValue.result !== "string") {
1801
1821
  return {
1802
1822
  success: false,
@@ -1902,7 +1922,7 @@ function createObjectStreamTransformer({
1902
1922
  onFinish(void 0);
1903
1923
  return;
1904
1924
  }
1905
- const finalResult = await handler.validateAndTransformFinal(previousObject);
1925
+ const finalResult = await handler.validateAndTransformFinal(accumulatedText);
1906
1926
  if (!finalResult.success) {
1907
1927
  controller.enqueue({
1908
1928
  from: "AGENT" /* AGENT */,
@@ -2929,6 +2949,12 @@ var AISDKV5InputStream = class extends MastraModelInput {
2929
2949
  }
2930
2950
  };
2931
2951
 
2952
+ // src/stream/aisdk/v5/model-supports.ts
2953
+ function getModelSupport(modelId, provider) {
2954
+ return modelSupports.find(m => m.modelId === modelId && m.provider === provider);
2955
+ }
2956
+ var modelSupports = [];
2957
+
2932
2958
  // src/stream/aisdk/v5/execute.ts
2933
2959
  function execute({
2934
2960
  runId,
@@ -2960,6 +2986,16 @@ function execute({
2960
2986
  "stream.prompt.tools": toolsAndToolChoice?.tools?.map(tool => JSON.stringify(tool))
2961
2987
  });
2962
2988
  }
2989
+ const modelSupports2 = getModelSupport(model.modelId, model.provider);
2990
+ const modelSupportsResponseFormat = modelSupports2?.capabilities.responseFormat?.support === "full";
2991
+ const responseFormat = output ? getResponseFormat(output) : void 0;
2992
+ let prompt = inputMessages;
2993
+ if (output && responseFormat?.type === "json" && !modelSupportsResponseFormat) {
2994
+ prompt = injectJsonInstructionIntoMessages({
2995
+ messages: inputMessages,
2996
+ schema: responseFormat.schema
2997
+ });
2998
+ }
2963
2999
  const stream = v5.initialize({
2964
3000
  runId,
2965
3001
  onResult,
@@ -2967,11 +3003,11 @@ function execute({
2967
3003
  try {
2968
3004
  const stream2 = await model.doStream({
2969
3005
  ...toolsAndToolChoice,
2970
- prompt: inputMessages,
3006
+ prompt,
2971
3007
  providerOptions,
2972
3008
  abortSignal: options?.abortSignal,
2973
3009
  includeRawChunks,
2974
- responseFormat: output ? getResponseFormat(output) : void 0,
3010
+ responseFormat: modelSupportsResponseFormat ? responseFormat : void 0,
2975
3011
  ...(modelSettings ?? {}),
2976
3012
  headers
2977
3013
  });
@@ -3769,7 +3805,9 @@ function createOuterLLMWorkflow({
3769
3805
  })));
3770
3806
  }
3771
3807
  return inputData.output.toolCalls || [];
3772
- }).foreach(toolCallStep).then(llmMappingStep).commit();
3808
+ }).foreach(toolCallStep, {
3809
+ concurrency: 10
3810
+ }).then(llmMappingStep).commit();
3773
3811
  }
3774
3812
 
3775
3813
  // src/loop/workflow/stream.ts
@@ -4124,9 +4162,6 @@ var MastraLLMVNext = class extends MastraBase {
4124
4162
  messages,
4125
4163
  tools: Object.keys(tools || {})
4126
4164
  });
4127
- if (output) {
4128
- output = this._applySchemaCompat(output);
4129
- }
4130
4165
  const llmAISpan = tracingContext?.currentSpan?.createChildSpan({
4131
4166
  name: `llm stream: '${model.modelId}'`,
4132
4167
  type: "llm_generation" /* LLM_GENERATION */,
@@ -9910,8 +9945,8 @@ var Agent = class extends (_a = MastraBase) {
9910
9945
  threadId,
9911
9946
  resourceId,
9912
9947
  runtimeContext,
9913
- methodType,
9914
9948
  tracingContext,
9949
+ methodType,
9915
9950
  format
9916
9951
  }) {
9917
9952
  const convertedWorkflowTools = {};
@@ -9930,17 +9965,9 @@ var Agent = class extends (_a = MastraBase) {
9930
9965
  // current tool span onto the workflow to maintain continuity of the trace
9931
9966
  execute: async ({
9932
9967
  context,
9933
- writer
9968
+ writer,
9969
+ tracingContext: innerTracingContext
9934
9970
  }) => {
9935
- const toolAISpan = tracingContext.currentSpan?.createChildSpan({
9936
- type: "tool_call" /* TOOL_CALL */,
9937
- name: `tool: '${workflowName}'`,
9938
- input: context,
9939
- attributes: {
9940
- toolId: workflowName,
9941
- toolType: "workflow"
9942
- }
9943
- });
9944
9971
  try {
9945
9972
  this.logger.debug(`[Agent:${this.name}] - Executing workflow as tool ${workflowName}`, {
9946
9973
  name: workflowName,
@@ -9956,16 +9983,13 @@ var Agent = class extends (_a = MastraBase) {
9956
9983
  result = await run.start({
9957
9984
  inputData: context,
9958
9985
  runtimeContext,
9959
- tracingContext: {
9960
- currentSpan: toolAISpan
9961
- }
9986
+ tracingContext: innerTracingContext
9962
9987
  });
9963
9988
  } else if (methodType === "stream") {
9964
- const streamResult = await run.stream({
9989
+ const streamResult = run.stream({
9965
9990
  inputData: context,
9966
- runtimeContext
9967
- // TODO: is this forgottn?
9968
- //currentSpan: toolAISpan,
9991
+ runtimeContext,
9992
+ tracingContext: innerTracingContext
9969
9993
  });
9970
9994
  if (writer) {
9971
9995
  await streamResult.stream.pipeTo(writer);
@@ -9984,9 +10008,6 @@ var Agent = class extends (_a = MastraBase) {
9984
10008
  }
9985
10009
  result = await streamResult.result;
9986
10010
  }
9987
- toolAISpan?.end({
9988
- output: result
9989
- });
9990
10011
  return {
9991
10012
  result,
9992
10013
  runId: run.runId
@@ -10006,9 +10027,6 @@ var Agent = class extends (_a = MastraBase) {
10006
10027
  }, err);
10007
10028
  this.logger.trackException(mastraError);
10008
10029
  this.logger.error(mastraError.toString());
10009
- toolAISpan?.error({
10010
- error: mastraError
10011
- });
10012
10030
  throw mastraError;
10013
10031
  }
10014
10032
  }
@@ -10324,7 +10342,9 @@ var Agent = class extends (_a = MastraBase) {
10324
10342
  saveThread: false
10325
10343
  });
10326
10344
  }
10327
- let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread ? this.getMemoryMessages({
10345
+ const config = memory.getMergedThreadConfig(memoryConfig || {});
10346
+ const hasResourceScopeSemanticRecall = typeof config?.semanticRecall === "object" && config?.semanticRecall?.scope === "resource";
10347
+ let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread || hasResourceScopeSemanticRecall ? this.getMemoryMessages({
10328
10348
  resourceId,
10329
10349
  threadId: threadObject.id,
10330
10350
  vectorMessageSearch: new MessageList().add(messages, `user`).getLatestUserContent() || "",
@@ -11100,7 +11120,9 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
11100
11120
  saveThread: false
11101
11121
  });
11102
11122
  }
11103
- let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread ? this.getMemoryMessages({
11123
+ const config = memory.getMergedThreadConfig(memoryConfig || {});
11124
+ const hasResourceScopeSemanticRecall = typeof config?.semanticRecall === "object" && config?.semanticRecall?.scope === "resource";
11125
+ let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread || hasResourceScopeSemanticRecall ? this.getMemoryMessages({
11104
11126
  resourceId,
11105
11127
  threadId: threadObject.id,
11106
11128
  vectorMessageSearch: new MessageList().add(options.messages, `user`).getLatestUserContent() || "",
@@ -15475,7 +15497,8 @@ var Run = class {
15475
15497
  */
15476
15498
  stream({
15477
15499
  inputData,
15478
- runtimeContext
15500
+ runtimeContext,
15501
+ tracingContext
15479
15502
  } = {}) {
15480
15503
  const {
15481
15504
  readable,
@@ -15540,7 +15563,8 @@ var Run = class {
15540
15563
  this.executionResults = this._start({
15541
15564
  inputData,
15542
15565
  runtimeContext,
15543
- format: "aisdk"
15566
+ format: "aisdk",
15567
+ tracingContext
15544
15568
  }).then(result => {
15545
15569
  if (result.status !== "suspended") {
15546
15570
  this.closeStreamAction?.().catch(() => {});
@@ -15869,5 +15893,5 @@ function deepMergeWorkflowState(a, b) {
15869
15893
  }
15870
15894
 
15871
15895
  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 };
15872
- //# sourceMappingURL=chunk-YILDTNQM.js.map
15873
- //# sourceMappingURL=chunk-YILDTNQM.js.map
15896
+ //# sourceMappingURL=chunk-MW4CYUSP.js.map
15897
+ //# sourceMappingURL=chunk-MW4CYUSP.js.map