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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/agent/agent.types.d.ts +10 -2
  3. package/dist/agent/agent.types.d.ts.map +1 -1
  4. package/dist/agent/index.cjs +8 -8
  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/agent/test-utils.d.ts +3 -0
  10. package/dist/agent/test-utils.d.ts.map +1 -1
  11. package/dist/{chunk-U3OYPZHX.js → chunk-BIJYFZVF.js} +3 -3
  12. package/dist/{chunk-U3OYPZHX.js.map → chunk-BIJYFZVF.js.map} +1 -1
  13. package/dist/{chunk-OF4TXRIV.js → chunk-HJ2UGNRG.js} +3 -3
  14. package/dist/{chunk-OF4TXRIV.js.map → chunk-HJ2UGNRG.js.map} +1 -1
  15. package/dist/{chunk-GJKJXY3K.js → chunk-IU367D3M.js} +3 -3
  16. package/dist/{chunk-GJKJXY3K.js.map → chunk-IU367D3M.js.map} +1 -1
  17. package/dist/{chunk-LZWM7RVY.cjs → chunk-ONGPJVTY.cjs} +7 -7
  18. package/dist/{chunk-LZWM7RVY.cjs.map → chunk-ONGPJVTY.cjs.map} +1 -1
  19. package/dist/{chunk-2PWFUEQA.cjs → chunk-PHS6DKEV.cjs} +4 -4
  20. package/dist/{chunk-2PWFUEQA.cjs.map → chunk-PHS6DKEV.cjs.map} +1 -1
  21. package/dist/{chunk-DYLYA6HQ.cjs → chunk-R467FTA7.cjs} +6 -6
  22. package/dist/{chunk-DYLYA6HQ.cjs.map → chunk-R467FTA7.cjs.map} +1 -1
  23. package/dist/{chunk-U2RCB3FQ.js → chunk-TOCMMZ2Y.js} +4 -4
  24. package/dist/{chunk-U2RCB3FQ.js.map → chunk-TOCMMZ2Y.js.map} +1 -1
  25. package/dist/{chunk-C3R2Q3NN.cjs → chunk-WJXZMK43.cjs} +72 -51
  26. package/dist/chunk-WJXZMK43.cjs.map +1 -0
  27. package/dist/{chunk-WGX5V6DE.cjs → chunk-XS5PJKTF.cjs} +7 -7
  28. package/dist/{chunk-WGX5V6DE.cjs.map → chunk-XS5PJKTF.cjs.map} +1 -1
  29. package/dist/{chunk-UM4XJM3Y.js → chunk-ZGSS7RCP.js} +72 -51
  30. package/dist/chunk-ZGSS7RCP.js.map +1 -0
  31. package/dist/index.cjs +17 -17
  32. package/dist/index.js +4 -4
  33. package/dist/llm/model/model.loop.d.ts +1 -1
  34. package/dist/llm/model/model.loop.d.ts.map +1 -1
  35. package/dist/llm/model/model.loop.types.d.ts +4 -2
  36. package/dist/llm/model/model.loop.types.d.ts.map +1 -1
  37. package/dist/loop/index.cjs +2 -2
  38. package/dist/loop/index.js +1 -1
  39. package/dist/loop/test-utils/fullStream.d.ts.map +1 -1
  40. package/dist/loop/test-utils/generateText.d.ts.map +1 -1
  41. package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
  42. package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
  43. package/dist/loop/test-utils/tools.d.ts.map +1 -1
  44. package/dist/loop/test-utils/utils.d.ts +1 -0
  45. package/dist/loop/test-utils/utils.d.ts.map +1 -1
  46. package/dist/loop/types.d.ts +0 -1
  47. package/dist/loop/types.d.ts.map +1 -1
  48. package/dist/loop/workflow/outer-llm-step.d.ts.map +1 -1
  49. package/dist/loop/workflow/schema.d.ts +12 -0
  50. package/dist/loop/workflow/schema.d.ts.map +1 -1
  51. package/dist/loop/workflow/tool-call-step.d.ts +12 -0
  52. package/dist/loop/workflow/tool-call-step.d.ts.map +1 -1
  53. package/dist/mastra/index.cjs +2 -2
  54. package/dist/mastra/index.js +1 -1
  55. package/dist/network/index.cjs +2 -2
  56. package/dist/network/index.js +1 -1
  57. package/dist/network/vNext/index.cjs +12 -12
  58. package/dist/network/vNext/index.js +1 -1
  59. package/dist/processors/index.cjs +8 -8
  60. package/dist/processors/index.js +2 -2
  61. package/dist/relevance/index.cjs +4 -4
  62. package/dist/relevance/index.js +1 -1
  63. package/dist/scores/index.cjs +8 -8
  64. package/dist/scores/index.js +1 -1
  65. package/dist/stream/base/output.d.ts.map +1 -1
  66. package/dist/stream/index.cjs +3 -3
  67. package/dist/stream/index.js +1 -1
  68. package/dist/workflows/evented/index.cjs +10 -10
  69. package/dist/workflows/evented/index.js +1 -1
  70. package/dist/workflows/index.cjs +10 -10
  71. package/dist/workflows/index.js +1 -1
  72. package/dist/workflows/legacy/index.cjs +22 -22
  73. package/dist/workflows/legacy/index.js +1 -1
  74. package/package.json +1 -1
  75. package/dist/chunk-C3R2Q3NN.cjs.map +0 -1
  76. package/dist/chunk-UM4XJM3Y.js.map +0 -1
@@ -2213,7 +2213,8 @@ var MastraModelOutput = class extends MastraBase {
2213
2213
  } = chunk.payload.metadata;
2214
2214
  response = {
2215
2215
  ...otherMetadata,
2216
- messages: messageList.get.response.aiV5.model()
2216
+ messages: messageList.get.response.aiV5.model(),
2217
+ uiMessages: messageList.get.response.aiV5.ui()
2217
2218
  };
2218
2219
  }
2219
2220
  this.populateUsageCount(chunk.payload.output.usage);
@@ -2240,7 +2241,8 @@ var MastraModelOutput = class extends MastraBase {
2240
2241
  } = chunk.payload.metadata;
2241
2242
  response = {
2242
2243
  ...otherMetadata,
2243
- messages: messageList.get.response.aiV5.model()
2244
+ messages: messageList.get.response.aiV5.model(),
2245
+ uiMessages: messageList.get.response.aiV5.ui()
2244
2246
  };
2245
2247
  }
2246
2248
  } else {
@@ -2595,7 +2597,6 @@ var MastraModelOutput = class extends MastraBase {
2595
2597
  scoringData
2596
2598
  } : {})
2597
2599
  };
2598
- fullOutput.response.messages = this.messageList.get.response.aiV5.model();
2599
2600
  return fullOutput;
2600
2601
  }
2601
2602
  /**
@@ -3089,7 +3090,9 @@ var toolCallInputSchema = z.object({
3089
3090
  toolCallId: z.string(),
3090
3091
  toolName: z.string(),
3091
3092
  args: z.any(),
3092
- providerMetadata: z.any()
3093
+ providerMetadata: z.any(),
3094
+ providerExecuted: z.boolean().optional(),
3095
+ output: z.any().optional()
3093
3096
  });
3094
3097
  var toolCallOutputSchema = toolCallInputSchema.extend({
3095
3098
  result: z.any(),
@@ -3610,6 +3613,32 @@ function createToolCallStep({
3610
3613
  execute: async ({
3611
3614
  inputData
3612
3615
  }) => {
3616
+ if (inputData.providerExecuted) {
3617
+ const tracer2 = getTracer({
3618
+ isEnabled: telemetry_settings?.isEnabled,
3619
+ tracer: telemetry_settings?.tracer
3620
+ });
3621
+ const span2 = tracer2.startSpan("mastra.stream.toolCall").setAttributes({
3622
+ ...assembleOperationName({
3623
+ operationId: "mastra.stream.toolCall",
3624
+ telemetry: telemetry_settings
3625
+ }),
3626
+ "stream.toolCall.toolName": inputData.toolName,
3627
+ "stream.toolCall.toolCallId": inputData.toolCallId,
3628
+ "stream.toolCall.args": JSON.stringify(inputData.args),
3629
+ "stream.toolCall.providerExecuted": true
3630
+ });
3631
+ if (inputData.output) {
3632
+ span2.setAttributes({
3633
+ "stream.toolCall.result": JSON.stringify(inputData.output)
3634
+ });
3635
+ }
3636
+ span2.end();
3637
+ return {
3638
+ ...inputData,
3639
+ result: inputData.output
3640
+ };
3641
+ }
3613
3642
  const tool = tools?.[inputData.toolName] || Object.values(tools || {})?.find(tool2 => `id` in tool2 && tool2.id === inputData.toolName);
3614
3643
  if (!tool) {
3615
3644
  throw new Error(`Tool ${inputData.toolName} not found`);
@@ -3751,7 +3780,8 @@ function createOuterLLMWorkflow({
3751
3780
  toolCallId: toolCall.toolCallId,
3752
3781
  toolName: toolCall.toolName,
3753
3782
  result: toolCall.result,
3754
- providerMetadata: toolCall.providerMetadata
3783
+ providerMetadata: toolCall.providerMetadata,
3784
+ providerExecuted: toolCall.providerExecuted
3755
3785
  }
3756
3786
  };
3757
3787
  rest.controller.enqueue(chunk);
@@ -4130,7 +4160,6 @@ var MastraLLMVNext = class extends MastraBase {
4130
4160
  }];
4131
4161
  }
4132
4162
  stream({
4133
- messages,
4134
4163
  stopWhen = stepCountIs(5),
4135
4164
  maxSteps,
4136
4165
  tools = {},
@@ -4145,7 +4174,9 @@ var MastraLLMVNext = class extends MastraBase {
4145
4174
  outputProcessors,
4146
4175
  returnScorerData,
4147
4176
  providerOptions,
4148
- tracingContext
4177
+ tracingContext,
4178
+ messageList,
4179
+ _internal
4149
4180
  // ...rest
4150
4181
  }) {
4151
4182
  let stopWhenToUse;
@@ -4154,6 +4185,7 @@ var MastraLLMVNext = class extends MastraBase {
4154
4185
  } else {
4155
4186
  stopWhenToUse = stopWhen;
4156
4187
  }
4188
+ const messages = messageList.get.all.aiV5.model();
4157
4189
  const model = this.#model;
4158
4190
  this.logger.debug(`[LLM] - Streaming text`, {
4159
4191
  runId,
@@ -4177,11 +4209,6 @@ var MastraLLMVNext = class extends MastraBase {
4177
4209
  }
4178
4210
  });
4179
4211
  try {
4180
- const messageList = new MessageList({
4181
- threadId,
4182
- resourceId
4183
- });
4184
- messageList.add(messages, "input");
4185
4212
  const loopOptions = {
4186
4213
  messageList,
4187
4214
  model: this.#model,
@@ -4194,6 +4221,7 @@ var MastraLLMVNext = class extends MastraBase {
4194
4221
  ...this.experimental_telemetry,
4195
4222
  ...telemetry_settings
4196
4223
  },
4224
+ _internal,
4197
4225
  output,
4198
4226
  outputProcessors,
4199
4227
  returnScorerData,
@@ -9516,16 +9544,17 @@ var Agent = class extends (_a = MastraBase) {
9516
9544
  const systemInstructions = await this.resolveTitleInstructions(runtimeContext, instructions);
9517
9545
  let text = "";
9518
9546
  if (llm.getModel().specificationVersion === "v2") {
9547
+ const messageList = new MessageList().add([{
9548
+ role: "system",
9549
+ content: systemInstructions
9550
+ }], "system").add([{
9551
+ role: "user",
9552
+ content: JSON.stringify(partsToGen)
9553
+ }], "input");
9519
9554
  const result = llm.stream({
9520
9555
  runtimeContext,
9521
9556
  tracingContext,
9522
- messages: [{
9523
- role: "system",
9524
- content: systemInstructions
9525
- }, {
9526
- role: "user",
9527
- content: JSON.stringify(partsToGen)
9528
- }]
9557
+ messageList
9529
9558
  });
9530
9559
  text = await result.text;
9531
9560
  } else {
@@ -9981,7 +10010,7 @@ var Agent = class extends (_a = MastraBase) {
9981
10010
  threadId,
9982
10011
  resourceId
9983
10012
  });
9984
- const run = workflow.createRun();
10013
+ const run = await workflow.createRunAsync();
9985
10014
  let result;
9986
10015
  if (methodType === "generate") {
9987
10016
  result = await run.start({
@@ -10512,14 +10541,7 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
10512
10541
  }];
10513
10542
  }
10514
10543
  if (responseMessages) {
10515
- const messagesWithoutIds = responseMessages.map(m => {
10516
- const {
10517
- id,
10518
- ...messageWithoutId
10519
- } = m;
10520
- return messageWithoutId;
10521
- });
10522
- messageList.add(messagesWithoutIds, "response");
10544
+ messageList.add(responseMessages, "response");
10523
10545
  }
10524
10546
  if (!threadExists) {
10525
10547
  await memory.createThread({
@@ -11034,7 +11056,6 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
11034
11056
  id: "prepare-memory-step",
11035
11057
  inputSchema: z$1.any(),
11036
11058
  outputSchema: z$1.object({
11037
- messageObjects: z$1.array(z$1.any()),
11038
11059
  threadExists: z$1.boolean(),
11039
11060
  thread: z$1.any(),
11040
11061
  messageList: z$1.any(),
@@ -11066,7 +11087,6 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
11066
11087
  messageList
11067
11088
  });
11068
11089
  return {
11069
- messageObjects: messageList.get.all.prompt(),
11070
11090
  threadExists: false,
11071
11091
  thread: void 0,
11072
11092
  messageList,
@@ -11211,12 +11231,11 @@ the following messages are from ${ymd}
11211
11231
  generateMessageId: this.#mastra?.generateId?.bind(this.#mastra),
11212
11232
  // @ts-ignore Flag for agent network messages
11213
11233
  _agentNetworkAppend: this._agentNetworkAppend
11214
- }).addSystem(instructions || `${this.instructions}.`).addSystem(memorySystemMessage).add(options.context || [], "context").add(processedMemoryMessages, "memory").add(messageList.get.input.v2(), "user").get.all.prompt();
11234
+ }).addSystem(instructions || `${this.instructions}.`).addSystem(memorySystemMessage).add(options.context || [], "context").add(processedMemoryMessages, "memory").add(messageList.get.input.v2(), "user");
11215
11235
  return {
11216
11236
  thread: threadObject,
11217
- messageList,
11237
+ messageList: processedList,
11218
11238
  // add old processed messages + new input messages
11219
- messageObjects: processedList,
11220
11239
  ...(tripwireTriggered && {
11221
11240
  tripwire: true,
11222
11241
  tripwireReason
@@ -11243,7 +11262,10 @@ the following messages are from ${ymd}
11243
11262
  ...inputData,
11244
11263
  outputProcessors,
11245
11264
  returnScorerData: options.returnScorerData,
11246
- tracingContext
11265
+ tracingContext,
11266
+ _internal: {
11267
+ generateId: inputData.experimental_generateMessageId || this.#mastra?.generateId?.bind(this.#mastra)
11268
+ }
11247
11269
  });
11248
11270
  if (format === "aisdk") {
11249
11271
  return streamResult.aisdk.v5;
@@ -11263,7 +11285,6 @@ the following messages are from ${ymd}
11263
11285
  }) => {
11264
11286
  const result2 = {
11265
11287
  ...options,
11266
- messages: inputData["prepare-memory-step"].messageObjects,
11267
11288
  tools: inputData["prepare-tools-step"].convertedTools,
11268
11289
  runId,
11269
11290
  temperature: options.modelSettings?.temperature,
@@ -11365,7 +11386,6 @@ the following messages are from ${ymd}
11365
11386
  effectiveOutputProcessors = effectiveOutputProcessors ? [...effectiveOutputProcessors, structuredProcessor] : [structuredProcessor];
11366
11387
  }
11367
11388
  const loopOptions = {
11368
- messages: result2.messages,
11369
11389
  runtimeContext: result2.runtimeContext,
11370
11390
  tracingContext: {
11371
11391
  currentSpan: agentAISpan
@@ -11389,7 +11409,6 @@ the following messages are from ${ymd}
11389
11409
  return;
11390
11410
  }
11391
11411
  const messageList = inputData["prepare-memory-step"].messageList;
11392
- messageList.add(payload.response.messages, "response");
11393
11412
  try {
11394
11413
  const outputText = messageList.get.all.core().map(m => m.content).join("\n");
11395
11414
  await this.#executeOnFinish({
@@ -11423,14 +11442,20 @@ the following messages are from ${ymd}
11423
11442
  totalUsage: payload.totalUsage
11424
11443
  });
11425
11444
  },
11426
- onStepFinish: result2.onStepFinish
11445
+ onStepFinish: result2.onStepFinish,
11446
+ onChunk: options.onChunk,
11447
+ onError: options.onError,
11448
+ onAbort: options.onAbort,
11449
+ activeTools: options.activeTools,
11450
+ abortSignal: options.abortSignal
11427
11451
  },
11428
11452
  output: options.output,
11429
11453
  outputProcessors: effectiveOutputProcessors,
11430
11454
  modelSettings: {
11431
11455
  temperature: 0,
11432
11456
  ...(options.modelSettings || {})
11433
- }
11457
+ },
11458
+ messageList: inputData["prepare-memory-step"].messageList
11434
11459
  };
11435
11460
  return loopOptions;
11436
11461
  }).then(streamStep).commit();
@@ -11507,14 +11532,8 @@ the following messages are from ${ymd}
11507
11532
  }];
11508
11533
  }
11509
11534
  if (responseMessages) {
11510
- const messagesWithoutIds = responseMessages.map(m => {
11511
- const {
11512
- id,
11513
- ...messageWithoutId
11514
- } = m;
11515
- return messageWithoutId;
11516
- }).filter(m => m.role !== "user");
11517
- messageList.add(messagesWithoutIds, "response");
11535
+ const filteredMessages = responseMessages.filter(m => m.role !== "user");
11536
+ messageList.add(filteredMessages, "response");
11518
11537
  }
11519
11538
  if (!threadExists) {
11520
11539
  await memory.createThread({
@@ -11664,7 +11683,8 @@ the following messages are from ${ymd}
11664
11683
  });
11665
11684
  const mergedGenerateOptions = {
11666
11685
  ...defaultGenerateOptions,
11667
- ...generateOptions
11686
+ ...generateOptions,
11687
+ experimental_generateMessageId: defaultGenerateOptions.experimental_generateMessageId || this.#mastra?.generateId?.bind(this.#mastra)
11668
11688
  };
11669
11689
  const {
11670
11690
  llm,
@@ -11918,7 +11938,8 @@ the following messages are from ${ymd}
11918
11938
  const mergedStreamOptions = {
11919
11939
  ...defaultStreamOptions,
11920
11940
  ...streamOptions,
11921
- onFinish: this.#mergeOnFinishWithTelemetry(streamOptions, defaultStreamOptions)
11941
+ onFinish: this.#mergeOnFinishWithTelemetry(streamOptions, defaultStreamOptions),
11942
+ experimental_generateMessageId: defaultStreamOptions.experimental_generateMessageId || this.#mastra?.generateId?.bind(this.#mastra)
11922
11943
  };
11923
11944
  const {
11924
11945
  llm,
@@ -15921,5 +15942,5 @@ function deepMergeWorkflowState(a, b) {
15921
15942
  }
15922
15943
 
15923
15944
  export { AISDKV5OutputStream, Agent, DefaultExecutionEngine, ExecutionEngine, LanguageDetector, LanguageDetectorInputProcessor, LegacyStep, LegacyWorkflow, MastraModelOutput, ModerationInputProcessor, ModerationProcessor, PIIDetector, PIIDetectorInputProcessor, PromptInjectionDetector, PromptInjectionDetectorInputProcessor, Run, StructuredOutputProcessor, TripWire, UnicodeNormalizer, UnicodeNormalizerInputProcessor, WhenConditionReturnValue, Workflow, agentToStep, cloneStep, cloneWorkflow, createStep, createWorkflow, getActivePathsAndStatus, getResultActivePaths, getStepResult, getSuspendedPaths, isAgent, isConditionalKey, isErrorEvent, isFinalState, isLimboState, isTransitionEvent, isVariableReference, isWorkflow, loop, mapVariable, mergeChildValue, recursivelyCheckForFinalState, resolveVariables, updateStepInHierarchy, workflowToStep };
15924
- //# sourceMappingURL=chunk-UM4XJM3Y.js.map
15925
- //# sourceMappingURL=chunk-UM4XJM3Y.js.map
15945
+ //# sourceMappingURL=chunk-ZGSS7RCP.js.map
15946
+ //# sourceMappingURL=chunk-ZGSS7RCP.js.map