@mastra/core 0.23.1 → 0.23.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.
- package/CHANGELOG.md +28 -0
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/index.cjs +13 -13
- package/dist/agent/index.js +2 -2
- package/dist/agent/input-processor/index.cjs +6 -6
- package/dist/agent/input-processor/index.js +1 -1
- package/dist/ai-tracing/index.cjs +36 -36
- package/dist/ai-tracing/index.d.ts +1 -1
- package/dist/ai-tracing/index.js +1 -1
- package/dist/ai-tracing/model-tracing.d.ts +63 -0
- package/dist/ai-tracing/model-tracing.d.ts.map +1 -0
- package/dist/{chunk-NVDVFJWA.js → chunk-32ZQNYMV.js} +3 -3
- package/dist/{chunk-NVDVFJWA.js.map → chunk-32ZQNYMV.js.map} +1 -1
- package/dist/{chunk-MRJUTTCU.js → chunk-455LR5KI.js} +3 -3
- package/dist/{chunk-MRJUTTCU.js.map → chunk-455LR5KI.js.map} +1 -1
- package/dist/{chunk-HANVMC6C.cjs → chunk-4PYSODHR.cjs} +12 -12
- package/dist/{chunk-HANVMC6C.cjs.map → chunk-4PYSODHR.cjs.map} +1 -1
- package/dist/{chunk-PS4ABZY7.js → chunk-6GDXSCHL.js} +5 -5
- package/dist/{chunk-PS4ABZY7.js.map → chunk-6GDXSCHL.js.map} +1 -1
- package/dist/{chunk-34WQUECJ.cjs → chunk-CE2Y5BC2.cjs} +52 -52
- package/dist/chunk-CE2Y5BC2.cjs.map +1 -0
- package/dist/{chunk-4YHU6R7W.cjs → chunk-CL6Z33KH.cjs} +18 -18
- package/dist/chunk-CL6Z33KH.cjs.map +1 -0
- package/dist/{chunk-ONKGWHY6.js → chunk-DTTOVV72.js} +194 -146
- package/dist/chunk-DTTOVV72.js.map +1 -0
- package/dist/{chunk-ZWF7AVLU.js → chunk-E3PG7G6E.js} +3 -3
- package/dist/{chunk-ZWF7AVLU.js.map → chunk-E3PG7G6E.js.map} +1 -1
- package/dist/{chunk-JZ7I64PK.js → chunk-ICGCDCJE.js} +17 -17
- package/dist/chunk-ICGCDCJE.js.map +1 -0
- package/dist/{chunk-ITCG6QJR.js → chunk-JZGCSEW5.js} +5 -5
- package/dist/{chunk-ITCG6QJR.js.map → chunk-JZGCSEW5.js.map} +1 -1
- package/dist/{chunk-HFXV34OE.js → chunk-KAEQISOW.js} +3 -3
- package/dist/{chunk-HFXV34OE.js.map → chunk-KAEQISOW.js.map} +1 -1
- package/dist/{chunk-4XE7GVZM.cjs → chunk-MCASUJWY.cjs} +35 -35
- package/dist/chunk-MCASUJWY.cjs.map +1 -0
- package/dist/{chunk-JTI6TVDV.cjs → chunk-MJMID7LX.cjs} +4 -4
- package/dist/{chunk-JTI6TVDV.cjs.map → chunk-MJMID7LX.cjs.map} +1 -1
- package/dist/{chunk-7KYNQSR4.js → chunk-N4DKYHQH.js} +15 -15
- package/dist/chunk-N4DKYHQH.js.map +1 -0
- package/dist/{chunk-QOTPNUIA.js → chunk-NNBF7NYQ.js} +4 -4
- package/dist/{chunk-QOTPNUIA.js.map → chunk-NNBF7NYQ.js.map} +1 -1
- package/dist/{chunk-A55YFHFT.js → chunk-NR77P3TK.js} +32 -32
- package/dist/chunk-NR77P3TK.js.map +1 -0
- package/dist/{chunk-DPE27ECD.cjs → chunk-NTKOVUTG.cjs} +11 -11
- package/dist/{chunk-DPE27ECD.cjs.map → chunk-NTKOVUTG.cjs.map} +1 -1
- package/dist/{chunk-5P4S4AVU.cjs → chunk-OOMWL2VB.cjs} +4 -4
- package/dist/{chunk-5P4S4AVU.cjs.map → chunk-OOMWL2VB.cjs.map} +1 -1
- package/dist/{chunk-PDST7KX7.cjs → chunk-P35FNLTQ.cjs} +194 -146
- package/dist/chunk-P35FNLTQ.cjs.map +1 -0
- package/dist/{chunk-7XAVBWZI.cjs → chunk-SKAKD7UJ.cjs} +12 -12
- package/dist/{chunk-7XAVBWZI.cjs.map → chunk-SKAKD7UJ.cjs.map} +1 -1
- package/dist/{chunk-VTNVK7HN.cjs → chunk-UZKIGB7M.cjs} +4 -4
- package/dist/{chunk-VTNVK7HN.cjs.map → chunk-UZKIGB7M.cjs.map} +1 -1
- package/dist/{chunk-TYWQLUF6.cjs → chunk-WCTRQHTG.cjs} +8 -8
- package/dist/{chunk-TYWQLUF6.cjs.map → chunk-WCTRQHTG.cjs.map} +1 -1
- package/dist/index.cjs +48 -48
- package/dist/index.js +8 -8
- package/dist/llm/index.cjs +7 -7
- package/dist/llm/index.js +1 -1
- package/dist/llm/model/model.d.ts.map +1 -1
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/provider-registry.d.ts.map +1 -1
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/loop.d.ts +1 -1
- package/dist/loop/loop.d.ts.map +1 -1
- package/dist/loop/test-utils/options.d.ts.map +1 -1
- package/dist/loop/types.d.ts +1 -2
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/stream.d.ts +1 -1
- package/dist/loop/workflows/stream.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +4 -4
- package/dist/memory/index.js +1 -1
- package/dist/processors/index.cjs +11 -11
- package/dist/processors/index.js +1 -1
- package/dist/relevance/index.cjs +4 -4
- package/dist/relevance/index.js +1 -1
- package/dist/scores/index.cjs +9 -9
- package/dist/scores/index.js +2 -2
- package/dist/scores/scoreTraces/index.cjs +8 -8
- package/dist/scores/scoreTraces/index.js +3 -3
- package/dist/storage/index.cjs +3 -3
- package/dist/storage/index.js +1 -1
- package/dist/stream/index.cjs +11 -11
- package/dist/stream/index.js +2 -2
- package/dist/test-utils/llm-mock.cjs +2 -2
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/utils.cjs +17 -17
- package/dist/utils.js +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/execution-engine.d.ts +1 -0
- package/dist/workflows/execution-engine.d.ts.map +1 -1
- package/dist/workflows/index.cjs +13 -13
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/legacy/index.cjs +22 -22
- package/dist/workflows/legacy/index.js +1 -1
- package/dist/workflows/workflow.d.ts +3 -1
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/ai-tracing/chunk-tracing.d.ts +0 -76
- package/dist/ai-tracing/chunk-tracing.d.ts.map +0 -1
- package/dist/chunk-34WQUECJ.cjs.map +0 -1
- package/dist/chunk-4XE7GVZM.cjs.map +0 -1
- package/dist/chunk-4YHU6R7W.cjs.map +0 -1
- package/dist/chunk-7KYNQSR4.js.map +0 -1
- package/dist/chunk-A55YFHFT.js.map +0 -1
- package/dist/chunk-JZ7I64PK.js.map +0 -1
- package/dist/chunk-ONKGWHY6.js.map +0 -1
- package/dist/chunk-PDST7KX7.cjs.map +0 -1
|
@@ -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
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
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
|
|
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
|
|
2585
|
-
name: `step: ${this
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
2622
|
-
this
|
|
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
|
|
2629
|
-
this
|
|
2670
|
+
#startChunkSpan(chunkType, initialData) {
|
|
2671
|
+
if (!this.#currentStepSpan) {
|
|
2672
|
+
this.#startStepSpan();
|
|
2630
2673
|
}
|
|
2631
|
-
this
|
|
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
|
|
2679
|
+
sequenceNumber: this.#chunkSequence
|
|
2637
2680
|
}
|
|
2638
2681
|
});
|
|
2639
|
-
this
|
|
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
|
|
2646
|
-
this
|
|
2687
|
+
#appendToAccumulator(field, text) {
|
|
2688
|
+
if (this.#accumulator[field] === void 0) {
|
|
2689
|
+
this.#accumulator[field] = text;
|
|
2647
2690
|
} else {
|
|
2648
|
-
this
|
|
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
|
|
2657
|
-
this
|
|
2658
|
-
output: output !== void 0 ? output : this
|
|
2698
|
+
#endChunkSpan(output) {
|
|
2699
|
+
if (!this.#currentChunkSpan) return;
|
|
2700
|
+
this.#currentChunkSpan.end({
|
|
2701
|
+
output: output !== void 0 ? output : this.#accumulator
|
|
2659
2702
|
});
|
|
2660
|
-
this
|
|
2661
|
-
this
|
|
2662
|
-
this
|
|
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
|
|
2669
|
-
this
|
|
2710
|
+
#createEventSpan(chunkType, output) {
|
|
2711
|
+
if (!this.#currentStepSpan) {
|
|
2712
|
+
this.#startStepSpan();
|
|
2670
2713
|
}
|
|
2671
|
-
const span = this
|
|
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
|
|
2719
|
+
sequenceNumber: this.#chunkSequence
|
|
2677
2720
|
},
|
|
2678
2721
|
output
|
|
2679
2722
|
});
|
|
2680
2723
|
if (span) {
|
|
2681
|
-
this
|
|
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
|
|
2730
|
+
#hasActiveChunkSpan() {
|
|
2731
|
+
return !!this.#currentChunkSpan;
|
|
2689
2732
|
}
|
|
2690
2733
|
/**
|
|
2691
2734
|
* Get the current accumulator value
|
|
2692
2735
|
*/
|
|
2693
|
-
getAccumulator() {
|
|
2694
|
-
return this
|
|
2736
|
+
#getAccumulator() {
|
|
2737
|
+
return this.#accumulator;
|
|
2695
2738
|
}
|
|
2696
2739
|
/**
|
|
2697
|
-
*
|
|
2740
|
+
* Handle text chunk spans (text-start/delta/end)
|
|
2698
2741
|
*/
|
|
2699
|
-
|
|
2700
|
-
|
|
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
|
|
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
|
|
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
|
|
2846
|
+
this.#handleReasoningChunk(chunk);
|
|
2730
2847
|
break;
|
|
2731
2848
|
case "object":
|
|
2732
2849
|
case "object-result":
|
|
2733
|
-
handleObjectChunk(chunk
|
|
2850
|
+
this.#handleObjectChunk(chunk);
|
|
2734
2851
|
break;
|
|
2735
2852
|
case "step-start":
|
|
2736
|
-
|
|
2853
|
+
this.#startStepSpan(chunk.payload);
|
|
2737
2854
|
break;
|
|
2738
2855
|
case "step-finish":
|
|
2739
|
-
|
|
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
|
-
|
|
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-
|
|
2888
|
-
//# sourceMappingURL=chunk-
|
|
2935
|
+
//# sourceMappingURL=chunk-P35FNLTQ.cjs.map
|
|
2936
|
+
//# sourceMappingURL=chunk-P35FNLTQ.cjs.map
|