@mastra/observability 1.21.0-alpha.1 → 1.21.0-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.
package/dist/index.cjs CHANGED
@@ -2845,6 +2845,26 @@ var ModelSpanTracker = class {
2845
2845
  this.#stepIndex++;
2846
2846
  }
2847
2847
  /**
2848
+ * A suspended step emits no step-finish; its suspension chunk carries the
2849
+ * step usage instead. Close MODEL_INFERENCE and MODEL_STEP with that usage so
2850
+ * the suspended call is not reported without tokens.
2851
+ */
2852
+ #endSuspendedStep(chunk) {
2853
+ if (chunk.type !== "tool-call-suspended" && chunk.type !== "tool-call-approval") return;
2854
+ const usage = chunk.payload.usage;
2855
+ if (!usage) return;
2856
+ this.#inModelResponse = false;
2857
+ this.#endStepSpan({
2858
+ output: { usage },
2859
+ stepResult: {
2860
+ reason: "suspended",
2861
+ isContinued: false,
2862
+ warnings: []
2863
+ },
2864
+ metadata: {}
2865
+ });
2866
+ }
2867
+ /**
2848
2868
  * Returns the parent span for chunks. Chunks parent under MODEL_INFERENCE
2849
2869
  * (the provider call) when available, falling back to MODEL_STEP only if
2850
2870
  * startStep() was bypassed.
@@ -3016,8 +3036,8 @@ var ModelSpanTracker = class {
3016
3036
  #handleToolApprovalChunk(chunk) {
3017
3037
  if (chunk.type !== "tool-call-approval") return;
3018
3038
  const payload = chunk.payload;
3019
- this.#ensureStepAndInference();
3020
- if (this.#chunkParent()?.createEventSpan({
3039
+ if (payload.usage || this.#currentStepSpan) this.#ensureStepAndInference();
3040
+ if ((this.#chunkParent() ?? this.#modelSpan)?.createEventSpan({
3021
3041
  name: `chunk: 'tool-call-approval'`,
3022
3042
  type: _mastra_core_observability.SpanType.MODEL_CHUNK,
3023
3043
  attributes: {
@@ -3037,6 +3057,10 @@ var ModelSpanTracker = class {
3037
3057
  wrapStream(stream) {
3038
3058
  return stream.pipeThrough(new stream_web.TransformStream({ transform: (chunk, controller) => {
3039
3059
  if ((this.#inModelResponse || this.#deferStepClose) && MODEL_RESPONSE_CHUNK_TYPES.has(chunk.type)) this.#captureCompletionStartTime();
3060
+ if (chunk.type === "tool-call-suspended" || chunk.type === "tool-call-approval") {
3061
+ if (chunk.type === "tool-call-approval") this.#handleToolApprovalChunk(chunk);
3062
+ this.#endSuspendedStep(chunk);
3063
+ }
3040
3064
  controller.enqueue(chunk);
3041
3065
  switch (chunk.type) {
3042
3066
  case "text-start":
@@ -3084,13 +3108,11 @@ var ModelSpanTracker = class {
3084
3108
  case "tripwire":
3085
3109
  case "watch":
3086
3110
  case "tool-error":
3087
- case "tool-call-suspended":
3088
3111
  case "reasoning-signature":
3089
3112
  case "redacted-reasoning":
3090
3113
  case "step-output": break;
3091
- case "tool-call-approval":
3092
- this.#handleToolApprovalChunk(chunk);
3093
- break;
3114
+ case "tool-call-suspended":
3115
+ case "tool-call-approval": break;
3094
3116
  case "tool-output": break;
3095
3117
  case "tool-result": {
3096
3118
  const { toolCallId, toolName, isError, dynamic, providerExecuted, providerMetadata, result, args: _args } = chunk.payload || {};