@mastra/core 0.23.1 → 0.23.2-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 (136) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/agent/agent.d.ts.map +1 -1
  3. package/dist/agent/index.cjs +13 -13
  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/utils.d.ts.map +1 -1
  8. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
  9. package/dist/ai-tracing/index.cjs +36 -36
  10. package/dist/ai-tracing/index.d.ts +1 -1
  11. package/dist/ai-tracing/index.js +1 -1
  12. package/dist/ai-tracing/model-tracing.d.ts +63 -0
  13. package/dist/ai-tracing/model-tracing.d.ts.map +1 -0
  14. package/dist/{chunk-PDST7KX7.cjs → chunk-4JDICTTI.cjs} +196 -148
  15. package/dist/chunk-4JDICTTI.cjs.map +1 -0
  16. package/dist/{chunk-MRJUTTCU.js → chunk-5STM6FQO.js} +3 -3
  17. package/dist/{chunk-MRJUTTCU.js.map → chunk-5STM6FQO.js.map} +1 -1
  18. package/dist/{chunk-QOTPNUIA.js → chunk-6JZPTKZS.js} +4 -4
  19. package/dist/{chunk-QOTPNUIA.js.map → chunk-6JZPTKZS.js.map} +1 -1
  20. package/dist/{chunk-4YHU6R7W.cjs → chunk-CL6Z33KH.cjs} +18 -18
  21. package/dist/chunk-CL6Z33KH.cjs.map +1 -0
  22. package/dist/{chunk-JTI6TVDV.cjs → chunk-DXURMKD6.cjs} +4 -4
  23. package/dist/{chunk-JTI6TVDV.cjs.map → chunk-DXURMKD6.cjs.map} +1 -1
  24. package/dist/{chunk-4XE7GVZM.cjs → chunk-E4FTCZ22.cjs} +35 -35
  25. package/dist/chunk-E4FTCZ22.cjs.map +1 -0
  26. package/dist/{chunk-NVDVFJWA.js → chunk-E6B7LJNW.js} +4 -4
  27. package/dist/{chunk-NVDVFJWA.js.map → chunk-E6B7LJNW.js.map} +1 -1
  28. package/dist/{chunk-HFXV34OE.js → chunk-EEU36GPI.js} +3 -3
  29. package/dist/{chunk-HFXV34OE.js.map → chunk-EEU36GPI.js.map} +1 -1
  30. package/dist/{chunk-ZWF7AVLU.js → chunk-G627JTDD.js} +3 -3
  31. package/dist/{chunk-ZWF7AVLU.js.map → chunk-G627JTDD.js.map} +1 -1
  32. package/dist/{chunk-7XAVBWZI.cjs → chunk-HVAUEU7R.cjs} +13 -13
  33. package/dist/{chunk-7XAVBWZI.cjs.map → chunk-HVAUEU7R.cjs.map} +1 -1
  34. package/dist/{chunk-HANVMC6C.cjs → chunk-HWB3BXCB.cjs} +13 -13
  35. package/dist/{chunk-HANVMC6C.cjs.map → chunk-HWB3BXCB.cjs.map} +1 -1
  36. package/dist/{chunk-JZ7I64PK.js → chunk-ICGCDCJE.js} +17 -17
  37. package/dist/chunk-ICGCDCJE.js.map +1 -0
  38. package/dist/{chunk-34WQUECJ.cjs → chunk-KPJGR6YE.cjs} +87 -86
  39. package/dist/chunk-KPJGR6YE.cjs.map +1 -0
  40. package/dist/{chunk-A55YFHFT.js → chunk-KR7Z74UQ.js} +32 -32
  41. package/dist/chunk-KR7Z74UQ.js.map +1 -0
  42. package/dist/{chunk-TYWQLUF6.cjs → chunk-KYGQ36G7.cjs} +8 -8
  43. package/dist/{chunk-TYWQLUF6.cjs.map → chunk-KYGQ36G7.cjs.map} +1 -1
  44. package/dist/{chunk-5P4S4AVU.cjs → chunk-PC66YVU2.cjs} +4 -4
  45. package/dist/{chunk-5P4S4AVU.cjs.map → chunk-PC66YVU2.cjs.map} +1 -1
  46. package/dist/{chunk-ONKGWHY6.js → chunk-PC6XLPN6.js} +196 -148
  47. package/dist/chunk-PC6XLPN6.js.map +1 -0
  48. package/dist/{chunk-ITCG6QJR.js → chunk-PFRQP22W.js} +5 -5
  49. package/dist/{chunk-ITCG6QJR.js.map → chunk-PFRQP22W.js.map} +1 -1
  50. package/dist/{chunk-PS4ABZY7.js → chunk-SSUYDJ33.js} +6 -6
  51. package/dist/{chunk-PS4ABZY7.js.map → chunk-SSUYDJ33.js.map} +1 -1
  52. package/dist/{chunk-DPE27ECD.cjs → chunk-TBSOTUXP.cjs} +11 -11
  53. package/dist/{chunk-DPE27ECD.cjs.map → chunk-TBSOTUXP.cjs.map} +1 -1
  54. package/dist/{chunk-VTNVK7HN.cjs → chunk-TXXVTUOF.cjs} +4 -4
  55. package/dist/{chunk-VTNVK7HN.cjs.map → chunk-TXXVTUOF.cjs.map} +1 -1
  56. package/dist/{chunk-7KYNQSR4.js → chunk-Y2M35YNB.js} +54 -54
  57. package/dist/chunk-Y2M35YNB.js.map +1 -0
  58. package/dist/index.cjs +65 -61
  59. package/dist/index.js +9 -9
  60. package/dist/llm/index.cjs +7 -7
  61. package/dist/llm/index.js +1 -1
  62. package/dist/llm/model/model.d.ts.map +1 -1
  63. package/dist/llm/model/model.loop.d.ts.map +1 -1
  64. package/dist/llm/model/provider-registry.d.ts.map +1 -1
  65. package/dist/loop/index.cjs +2 -2
  66. package/dist/loop/index.js +1 -1
  67. package/dist/loop/loop.d.ts +1 -1
  68. package/dist/loop/loop.d.ts.map +1 -1
  69. package/dist/loop/network/index.d.ts.map +1 -1
  70. package/dist/loop/test-utils/options.d.ts.map +1 -1
  71. package/dist/loop/types.d.ts +1 -2
  72. package/dist/loop/types.d.ts.map +1 -1
  73. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
  74. package/dist/loop/workflows/stream.d.ts +1 -1
  75. package/dist/loop/workflows/stream.d.ts.map +1 -1
  76. package/dist/mastra/index.cjs +2 -2
  77. package/dist/mastra/index.js +1 -1
  78. package/dist/memory/index.cjs +4 -4
  79. package/dist/memory/index.js +1 -1
  80. package/dist/processors/index.cjs +11 -11
  81. package/dist/processors/index.js +1 -1
  82. package/dist/processors/processors/language-detector.d.ts +5 -5
  83. package/dist/processors/processors/language-detector.d.ts.map +1 -1
  84. package/dist/processors/processors/moderation.d.ts +17 -16
  85. package/dist/processors/processors/moderation.d.ts.map +1 -1
  86. package/dist/processors/processors/pii-detector.d.ts +19 -20
  87. package/dist/processors/processors/pii-detector.d.ts.map +1 -1
  88. package/dist/processors/processors/prompt-injection-detector.d.ts +20 -14
  89. package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
  90. package/dist/processors/processors/system-prompt-scrubber.d.ts +16 -6
  91. package/dist/processors/processors/system-prompt-scrubber.d.ts.map +1 -1
  92. package/dist/relevance/index.cjs +4 -4
  93. package/dist/relevance/index.js +1 -1
  94. package/dist/scores/index.cjs +9 -9
  95. package/dist/scores/index.js +2 -2
  96. package/dist/scores/scoreTraces/index.cjs +8 -8
  97. package/dist/scores/scoreTraces/index.js +3 -3
  98. package/dist/storage/index.cjs +3 -3
  99. package/dist/storage/index.js +1 -1
  100. package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
  101. package/dist/stream/RunOutput.d.ts.map +1 -1
  102. package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
  103. package/dist/stream/base/output.d.ts.map +1 -1
  104. package/dist/stream/index.cjs +11 -11
  105. package/dist/stream/index.js +2 -2
  106. package/dist/stream/types.d.ts +4 -0
  107. package/dist/stream/types.d.ts.map +1 -1
  108. package/dist/test-utils/llm-mock.cjs +2 -2
  109. package/dist/test-utils/llm-mock.js +1 -1
  110. package/dist/tools/tool-builder/builder.d.ts.map +1 -1
  111. package/dist/utils.cjs +17 -17
  112. package/dist/utils.js +1 -1
  113. package/dist/workflows/default.d.ts.map +1 -1
  114. package/dist/workflows/evented/index.cjs +10 -10
  115. package/dist/workflows/evented/index.js +1 -1
  116. package/dist/workflows/execution-engine.d.ts +1 -0
  117. package/dist/workflows/execution-engine.d.ts.map +1 -1
  118. package/dist/workflows/index.cjs +17 -13
  119. package/dist/workflows/index.js +1 -1
  120. package/dist/workflows/legacy/index.cjs +22 -22
  121. package/dist/workflows/legacy/index.js +1 -1
  122. package/dist/workflows/utils.d.ts +2 -0
  123. package/dist/workflows/utils.d.ts.map +1 -1
  124. package/dist/workflows/workflow.d.ts +3 -1
  125. package/dist/workflows/workflow.d.ts.map +1 -1
  126. package/package.json +5 -4
  127. package/dist/ai-tracing/chunk-tracing.d.ts +0 -76
  128. package/dist/ai-tracing/chunk-tracing.d.ts.map +0 -1
  129. package/dist/chunk-34WQUECJ.cjs.map +0 -1
  130. package/dist/chunk-4XE7GVZM.cjs.map +0 -1
  131. package/dist/chunk-4YHU6R7W.cjs.map +0 -1
  132. package/dist/chunk-7KYNQSR4.js.map +0 -1
  133. package/dist/chunk-A55YFHFT.js.map +0 -1
  134. package/dist/chunk-JZ7I64PK.js.map +0 -1
  135. package/dist/chunk-ONKGWHY6.js.map +0 -1
  136. package/dist/chunk-PDST7KX7.cjs.map +0 -1
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var chunkGPWMM745_cjs = require('./chunk-GPWMM745.cjs');
4
- var chunk5NTO7S5I_cjs = require('./chunk-5NTO7S5I.cjs');
5
3
  var chunkLRSB62Z6_cjs = require('./chunk-LRSB62Z6.cjs');
6
4
  var chunkVF676YCO_cjs = require('./chunk-VF676YCO.cjs');
5
+ var chunkGPWMM745_cjs = require('./chunk-GPWMM745.cjs');
6
+ var chunk5NTO7S5I_cjs = require('./chunk-5NTO7S5I.cjs');
7
7
  var chunk6VOPKVYH_cjs = require('./chunk-6VOPKVYH.cjs');
8
8
  var chunkA5KDVZDL_cjs = require('./chunk-A5KDVZDL.cjs');
9
9
  var crypto$1 = require('crypto');
@@ -507,7 +507,7 @@ var CoreToolBuilder = class extends chunk6VOPKVYH_cjs.MastraBase {
507
507
  error: `${prefix} - Failed ${toolType} execution`
508
508
  };
509
509
  }
510
- createExecute(tool, options, logType) {
510
+ createExecute(tool, options, logType, processedSchema) {
511
511
  const { logger, mastra: _mastra, memory: _memory, runtimeContext, model, ...rest } = options;
512
512
  const logModelObject = {
513
513
  modelId: model?.modelId,
@@ -572,7 +572,7 @@ var CoreToolBuilder = class extends chunk6VOPKVYH_cjs.MastraBase {
572
572
  let logger2 = options.logger || this.logger;
573
573
  try {
574
574
  logger2.debug(start, { ...rest, model: logModelObject, args });
575
- const parameters = this.getParameters();
575
+ const parameters = processedSchema || this.getParameters();
576
576
  const { data, error: error2 } = chunkVF676YCO_cjs.validateToolInput(parameters, args, options.name);
577
577
  if (error2) {
578
578
  logger2.warn(`Tool input validation failed for '${options.name}'`, {
@@ -643,18 +643,6 @@ var CoreToolBuilder = class extends chunk6VOPKVYH_cjs.MastraBase {
643
643
  if (providerTool) {
644
644
  return providerTool;
645
645
  }
646
- const definition = {
647
- type: "function",
648
- description: this.originalTool.description,
649
- parameters: this.getParameters(),
650
- outputSchema: this.getOutputSchema(),
651
- requireApproval: this.options.requireApproval,
652
- execute: this.originalTool.execute ? this.createExecute(
653
- this.originalTool,
654
- { ...this.options, description: this.originalTool.description },
655
- this.logType
656
- ) : void 0
657
- };
658
646
  const model = this.options.model;
659
647
  const schemaCompatLayers = [];
660
648
  if (model) {
@@ -673,11 +661,25 @@ var CoreToolBuilder = class extends chunk6VOPKVYH_cjs.MastraBase {
673
661
  new schemaCompat.MetaSchemaCompatLayer(modelInfo)
674
662
  );
675
663
  }
676
- const processedSchema = schemaCompat.applyCompatLayer({
677
- schema: this.getParameters(),
678
- compatLayers: schemaCompatLayers,
679
- mode: "aiSdkSchema"
680
- });
664
+ let processedZodSchema;
665
+ let processedSchema;
666
+ const originalSchema = this.getParameters();
667
+ const applicableLayer = schemaCompatLayers.find((layer) => layer.shouldApply());
668
+ if (applicableLayer && originalSchema) {
669
+ processedZodSchema = applicableLayer.processZodType(originalSchema);
670
+ processedSchema = schemaCompat.applyCompatLayer({
671
+ schema: originalSchema,
672
+ compatLayers: schemaCompatLayers,
673
+ mode: "aiSdkSchema"
674
+ });
675
+ } else {
676
+ processedZodSchema = originalSchema;
677
+ processedSchema = schemaCompat.applyCompatLayer({
678
+ schema: originalSchema,
679
+ compatLayers: schemaCompatLayers,
680
+ mode: "aiSdkSchema"
681
+ });
682
+ }
681
683
  let processedOutputSchema;
682
684
  if (this.getOutputSchema()) {
683
685
  processedOutputSchema = schemaCompat.applyCompatLayer({
@@ -686,6 +688,20 @@ var CoreToolBuilder = class extends chunk6VOPKVYH_cjs.MastraBase {
686
688
  mode: "aiSdkSchema"
687
689
  });
688
690
  }
691
+ const definition = {
692
+ type: "function",
693
+ description: this.originalTool.description,
694
+ parameters: this.getParameters(),
695
+ outputSchema: this.getOutputSchema(),
696
+ requireApproval: this.options.requireApproval,
697
+ execute: this.originalTool.execute ? this.createExecute(
698
+ this.originalTool,
699
+ { ...this.options, description: this.originalTool.description },
700
+ this.logType,
701
+ processedZodSchema
702
+ // Pass the processed Zod schema for validation
703
+ ) : void 0
704
+ };
689
705
  return {
690
706
  ...definition,
691
707
  id: "id" in this.originalTool ? this.originalTool.id : void 0,
@@ -2568,36 +2584,63 @@ function wrapRun(run, tracingContext) {
2568
2584
  }
2569
2585
  }
2570
2586
  var ModelSpanTracker = class {
2571
- modelSpan;
2572
- currentStepSpan;
2573
- currentChunkSpan;
2574
- accumulator = {};
2575
- stepIndex = 0;
2576
- chunkSequence = 0;
2587
+ #modelSpan;
2588
+ #currentStepSpan;
2589
+ #currentChunkSpan;
2590
+ #accumulator = {};
2591
+ #stepIndex = 0;
2592
+ #chunkSequence = 0;
2577
2593
  constructor(modelSpan) {
2578
- this.modelSpan = modelSpan;
2594
+ this.#modelSpan = modelSpan;
2595
+ }
2596
+ /**
2597
+ * Get the tracing context for creating child spans.
2598
+ * Returns the current step span if active, otherwise the model span.
2599
+ */
2600
+ getTracingContext() {
2601
+ return {
2602
+ currentSpan: this.#currentStepSpan ?? this.#modelSpan
2603
+ };
2604
+ }
2605
+ /**
2606
+ * Report an error on the generation span
2607
+ */
2608
+ reportGenerationError(options) {
2609
+ this.#modelSpan?.error(options);
2610
+ }
2611
+ /**
2612
+ * End the generation span
2613
+ */
2614
+ endGeneration(options) {
2615
+ this.#modelSpan?.end(options);
2616
+ }
2617
+ /**
2618
+ * Update the generation span
2619
+ */
2620
+ updateGeneration(options) {
2621
+ this.#modelSpan?.update(options);
2579
2622
  }
2580
2623
  /**
2581
2624
  * Start a new Model execution step
2582
2625
  */
2583
- startStepSpan(payload) {
2584
- this.currentStepSpan = this.modelSpan?.createChildSpan({
2585
- name: `step: ${this.stepIndex}`,
2626
+ #startStepSpan(payload) {
2627
+ this.#currentStepSpan = this.#modelSpan?.createChildSpan({
2628
+ name: `step: ${this.#stepIndex}`,
2586
2629
  type: "model_step" /* MODEL_STEP */,
2587
2630
  attributes: {
2588
- stepIndex: this.stepIndex,
2631
+ stepIndex: this.#stepIndex,
2589
2632
  ...payload?.messageId ? { messageId: payload.messageId } : {},
2590
2633
  ...payload?.warnings?.length ? { warnings: payload.warnings } : {}
2591
2634
  },
2592
2635
  input: payload?.request
2593
2636
  });
2594
- this.chunkSequence = 0;
2637
+ this.#chunkSequence = 0;
2595
2638
  }
2596
2639
  /**
2597
2640
  * End the current Model execution step with token usage, finish reason, output, and metadata
2598
2641
  */
2599
- endStepSpan(payload) {
2600
- if (!this.currentStepSpan) return;
2642
+ #endStepSpan(payload) {
2643
+ if (!this.#currentStepSpan) return;
2601
2644
  const output = payload.output;
2602
2645
  const { usage, ...otherOutput } = output;
2603
2646
  const stepResult = payload.stepResult;
@@ -2606,7 +2649,7 @@ var ModelSpanTracker = class {
2606
2649
  if (cleanMetadata?.request) {
2607
2650
  delete cleanMetadata.request;
2608
2651
  }
2609
- this.currentStepSpan.end({
2652
+ this.#currentStepSpan.end({
2610
2653
  output: otherOutput,
2611
2654
  attributes: {
2612
2655
  usage,
@@ -2618,86 +2661,161 @@ var ModelSpanTracker = class {
2618
2661
  ...cleanMetadata
2619
2662
  }
2620
2663
  });
2621
- this.currentStepSpan = void 0;
2622
- this.stepIndex++;
2664
+ this.#currentStepSpan = void 0;
2665
+ this.#stepIndex++;
2623
2666
  }
2624
2667
  /**
2625
2668
  * Create a new chunk span (for multi-part chunks like text-start/delta/end)
2626
2669
  */
2627
- startChunkSpan(chunkType, initialData) {
2628
- if (!this.currentStepSpan) {
2629
- this.startStepSpan();
2670
+ #startChunkSpan(chunkType, initialData) {
2671
+ if (!this.#currentStepSpan) {
2672
+ this.#startStepSpan();
2630
2673
  }
2631
- this.currentChunkSpan = this.currentStepSpan?.createChildSpan({
2674
+ this.#currentChunkSpan = this.#currentStepSpan?.createChildSpan({
2632
2675
  name: `chunk: '${chunkType}'`,
2633
2676
  type: "model_chunk" /* MODEL_CHUNK */,
2634
2677
  attributes: {
2635
2678
  chunkType,
2636
- sequenceNumber: this.chunkSequence
2679
+ sequenceNumber: this.#chunkSequence
2637
2680
  }
2638
2681
  });
2639
- this.accumulator = initialData || {};
2682
+ this.#accumulator = initialData || {};
2640
2683
  }
2641
2684
  /**
2642
2685
  * Append string content to a specific field in the accumulator
2643
2686
  */
2644
- appendToAccumulator(field, text) {
2645
- if (this.accumulator[field] === void 0) {
2646
- this.accumulator[field] = text;
2687
+ #appendToAccumulator(field, text) {
2688
+ if (this.#accumulator[field] === void 0) {
2689
+ this.#accumulator[field] = text;
2647
2690
  } else {
2648
- this.accumulator[field] += text;
2691
+ this.#accumulator[field] += text;
2649
2692
  }
2650
2693
  }
2651
2694
  /**
2652
2695
  * End the current chunk span.
2653
2696
  * Safe to call multiple times - will no-op if span already ended.
2654
2697
  */
2655
- endChunkSpan(output) {
2656
- if (!this.currentChunkSpan) return;
2657
- this.currentChunkSpan.end({
2658
- output: output !== void 0 ? output : this.accumulator
2698
+ #endChunkSpan(output) {
2699
+ if (!this.#currentChunkSpan) return;
2700
+ this.#currentChunkSpan.end({
2701
+ output: output !== void 0 ? output : this.#accumulator
2659
2702
  });
2660
- this.currentChunkSpan = void 0;
2661
- this.accumulator = {};
2662
- this.chunkSequence++;
2703
+ this.#currentChunkSpan = void 0;
2704
+ this.#accumulator = {};
2705
+ this.#chunkSequence++;
2663
2706
  }
2664
2707
  /**
2665
2708
  * Create an event span (for single chunks like tool-call)
2666
2709
  */
2667
- createEventSpan(chunkType, output) {
2668
- if (!this.currentStepSpan) {
2669
- this.startStepSpan();
2710
+ #createEventSpan(chunkType, output) {
2711
+ if (!this.#currentStepSpan) {
2712
+ this.#startStepSpan();
2670
2713
  }
2671
- const span = this.currentStepSpan?.createEventSpan({
2714
+ const span = this.#currentStepSpan?.createEventSpan({
2672
2715
  name: `chunk: '${chunkType}'`,
2673
2716
  type: "model_chunk" /* MODEL_CHUNK */,
2674
2717
  attributes: {
2675
2718
  chunkType,
2676
- sequenceNumber: this.chunkSequence
2719
+ sequenceNumber: this.#chunkSequence
2677
2720
  },
2678
2721
  output
2679
2722
  });
2680
2723
  if (span) {
2681
- this.chunkSequence++;
2724
+ this.#chunkSequence++;
2682
2725
  }
2683
2726
  }
2684
2727
  /**
2685
2728
  * Check if there is currently an active chunk span
2686
2729
  */
2687
- hasActiveChunkSpan() {
2688
- return !!this.currentChunkSpan;
2730
+ #hasActiveChunkSpan() {
2731
+ return !!this.#currentChunkSpan;
2689
2732
  }
2690
2733
  /**
2691
2734
  * Get the current accumulator value
2692
2735
  */
2693
- getAccumulator() {
2694
- return this.accumulator;
2736
+ #getAccumulator() {
2737
+ return this.#accumulator;
2695
2738
  }
2696
2739
  /**
2697
- * Get the current step span (for making tool calls children of steps)
2740
+ * Handle text chunk spans (text-start/delta/end)
2698
2741
  */
2699
- getCurrentStepSpan() {
2700
- return this.currentStepSpan;
2742
+ #handleTextChunk(chunk) {
2743
+ switch (chunk.type) {
2744
+ case "text-start":
2745
+ this.#startChunkSpan("text");
2746
+ break;
2747
+ case "text-delta":
2748
+ this.#appendToAccumulator("text", chunk.payload.text);
2749
+ break;
2750
+ case "text-end": {
2751
+ this.#endChunkSpan();
2752
+ break;
2753
+ }
2754
+ }
2755
+ }
2756
+ /**
2757
+ * Handle reasoning chunk spans (reasoning-start/delta/end)
2758
+ */
2759
+ #handleReasoningChunk(chunk) {
2760
+ switch (chunk.type) {
2761
+ case "reasoning-start":
2762
+ this.#startChunkSpan("reasoning");
2763
+ break;
2764
+ case "reasoning-delta":
2765
+ this.#appendToAccumulator("text", chunk.payload.text);
2766
+ break;
2767
+ case "reasoning-end": {
2768
+ this.#endChunkSpan();
2769
+ break;
2770
+ }
2771
+ }
2772
+ }
2773
+ /**
2774
+ * Handle tool call chunk spans (tool-call-input-streaming-start/delta/end, tool-call)
2775
+ */
2776
+ #handleToolCallChunk(chunk) {
2777
+ switch (chunk.type) {
2778
+ case "tool-call-input-streaming-start":
2779
+ this.#startChunkSpan("tool-call", {
2780
+ toolName: chunk.payload.toolName,
2781
+ toolCallId: chunk.payload.toolCallId
2782
+ });
2783
+ break;
2784
+ case "tool-call-delta":
2785
+ this.#appendToAccumulator("toolInput", chunk.payload.argsTextDelta);
2786
+ break;
2787
+ case "tool-call-input-streaming-end":
2788
+ case "tool-call": {
2789
+ const acc = this.#getAccumulator();
2790
+ let toolInput;
2791
+ try {
2792
+ toolInput = acc.toolInput ? JSON.parse(acc.toolInput) : {};
2793
+ } catch {
2794
+ toolInput = acc.toolInput;
2795
+ }
2796
+ this.#endChunkSpan({
2797
+ toolName: acc.toolName,
2798
+ toolCallId: acc.toolCallId,
2799
+ toolInput
2800
+ });
2801
+ break;
2802
+ }
2803
+ }
2804
+ }
2805
+ /**
2806
+ * Handle object chunk spans (object, object-result)
2807
+ */
2808
+ #handleObjectChunk(chunk) {
2809
+ switch (chunk.type) {
2810
+ case "object":
2811
+ if (!this.#hasActiveChunkSpan()) {
2812
+ this.#startChunkSpan("object");
2813
+ }
2814
+ break;
2815
+ case "object-result":
2816
+ this.#endChunkSpan(chunk.object);
2817
+ break;
2818
+ }
2701
2819
  }
2702
2820
  /**
2703
2821
  * Wraps a stream with model tracing transform to track MODEL_STEP and MODEL_CHUNK spans.
@@ -2706,37 +2824,36 @@ var ModelSpanTracker = class {
2706
2824
  * create MODEL_STEP and MODEL_CHUNK spans for each semantic unit in the stream.
2707
2825
  */
2708
2826
  wrapStream(stream) {
2709
- const tracker = this;
2710
2827
  return stream.pipeThrough(
2711
2828
  new web.TransformStream({
2712
- transform(chunk, controller) {
2829
+ transform: (chunk, controller) => {
2713
2830
  controller.enqueue(chunk);
2714
2831
  switch (chunk.type) {
2715
2832
  case "text-start":
2716
2833
  case "text-delta":
2717
2834
  case "text-end":
2718
- handleTextChunk(chunk, tracker);
2835
+ this.#handleTextChunk(chunk);
2719
2836
  break;
2720
2837
  case "tool-call-input-streaming-start":
2721
2838
  case "tool-call-delta":
2722
2839
  case "tool-call-input-streaming-end":
2723
2840
  case "tool-call":
2724
- handleToolCallChunk(chunk, tracker);
2841
+ this.#handleToolCallChunk(chunk);
2725
2842
  break;
2726
2843
  case "reasoning-start":
2727
2844
  case "reasoning-delta":
2728
2845
  case "reasoning-end":
2729
- handleReasoningChunk(chunk, tracker);
2846
+ this.#handleReasoningChunk(chunk);
2730
2847
  break;
2731
2848
  case "object":
2732
2849
  case "object-result":
2733
- handleObjectChunk(chunk, tracker);
2850
+ this.#handleObjectChunk(chunk);
2734
2851
  break;
2735
2852
  case "step-start":
2736
- tracker.startStepSpan(chunk.payload);
2853
+ this.#startStepSpan(chunk.payload);
2737
2854
  break;
2738
2855
  case "step-finish":
2739
- tracker.endStepSpan(chunk.payload);
2856
+ this.#endStepSpan(chunk.payload);
2740
2857
  break;
2741
2858
  case "raw":
2742
2859
  // Skip raw chunks as they're redundant
@@ -2754,7 +2871,7 @@ var ModelSpanTracker = class {
2754
2871
  delete outputPayload.data;
2755
2872
  }
2756
2873
  }
2757
- tracker.createEventSpan(chunk.type, outputPayload);
2874
+ this.#createEventSpan(chunk.type, outputPayload);
2758
2875
  break;
2759
2876
  }
2760
2877
  }
@@ -2763,75 +2880,6 @@ var ModelSpanTracker = class {
2763
2880
  );
2764
2881
  }
2765
2882
  };
2766
- function handleTextChunk(chunk, tracker) {
2767
- switch (chunk.type) {
2768
- case "text-start":
2769
- tracker.startChunkSpan("text");
2770
- break;
2771
- case "text-delta":
2772
- tracker.appendToAccumulator("text", chunk.payload.text);
2773
- break;
2774
- case "text-end": {
2775
- tracker.endChunkSpan();
2776
- break;
2777
- }
2778
- }
2779
- }
2780
- function handleReasoningChunk(chunk, tracker) {
2781
- switch (chunk.type) {
2782
- case "reasoning-start":
2783
- tracker.startChunkSpan("reasoning");
2784
- break;
2785
- case "reasoning-delta":
2786
- tracker.appendToAccumulator("text", chunk.payload.text);
2787
- break;
2788
- case "reasoning-end": {
2789
- tracker.endChunkSpan();
2790
- break;
2791
- }
2792
- }
2793
- }
2794
- function handleToolCallChunk(chunk, tracker) {
2795
- switch (chunk.type) {
2796
- case "tool-call-input-streaming-start":
2797
- tracker.startChunkSpan("tool-call", {
2798
- toolName: chunk.payload.toolName,
2799
- toolCallId: chunk.payload.toolCallId
2800
- });
2801
- break;
2802
- case "tool-call-delta":
2803
- tracker.appendToAccumulator("toolInput", chunk.payload.argsTextDelta);
2804
- break;
2805
- case "tool-call-input-streaming-end":
2806
- case "tool-call": {
2807
- const acc = tracker.getAccumulator();
2808
- let toolInput;
2809
- try {
2810
- toolInput = acc.toolInput ? JSON.parse(acc.toolInput) : {};
2811
- } catch {
2812
- toolInput = acc.toolInput;
2813
- }
2814
- tracker.endChunkSpan({
2815
- toolName: acc.toolName,
2816
- toolCallId: acc.toolCallId,
2817
- toolInput
2818
- });
2819
- break;
2820
- }
2821
- }
2822
- }
2823
- function handleObjectChunk(chunk, tracker) {
2824
- switch (chunk.type) {
2825
- case "object":
2826
- if (!tracker.hasActiveChunkSpan()) {
2827
- tracker.startChunkSpan("object");
2828
- }
2829
- break;
2830
- case "object-result":
2831
- tracker.endChunkSpan(chunk.object);
2832
- break;
2833
- }
2834
- }
2835
2883
 
2836
2884
  exports.AISpanType = AISpanType;
2837
2885
  exports.AITracingEventType = AITracingEventType;
@@ -2884,5 +2932,5 @@ exports.setupAITracing = setupAITracing;
2884
2932
  exports.shutdownAITracingRegistry = shutdownAITracingRegistry;
2885
2933
  exports.unregisterAITracing = unregisterAITracing;
2886
2934
  exports.wrapMastra = wrapMastra;
2887
- //# sourceMappingURL=chunk-PDST7KX7.cjs.map
2888
- //# sourceMappingURL=chunk-PDST7KX7.cjs.map
2935
+ //# sourceMappingURL=chunk-4JDICTTI.cjs.map
2936
+ //# sourceMappingURL=chunk-4JDICTTI.cjs.map