@voltagent/core 2.6.10 → 2.6.11
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.js +145 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +145 -5
- package/dist/index.mjs.map +1 -1
- package/docs/{home.md → index.md} +1 -0
- package/docs/observability-platform/mcp.md +161 -0
- package/docs/observability-platform/overview.md +2 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24925,6 +24925,41 @@ function createScorerSpanAttributes(host, descriptor, config, storagePayload, me
|
|
|
24925
24925
|
if (metrics.datasetMetadata?.datasetItemHash) {
|
|
24926
24926
|
attributes["eval.dataset.item_hash"] = metrics.datasetMetadata.datasetItemHash;
|
|
24927
24927
|
}
|
|
24928
|
+
const judgeTelemetry = extractJudgeTelemetry(metrics.combinedMetadata);
|
|
24929
|
+
if (judgeTelemetry?.modelName) {
|
|
24930
|
+
attributes["ai.model.name"] = judgeTelemetry.modelName;
|
|
24931
|
+
const provider = judgeTelemetry.modelName.includes("/") ? judgeTelemetry.modelName.split("/")[0] : void 0;
|
|
24932
|
+
if (provider) {
|
|
24933
|
+
attributes["ai.model.provider"] = provider;
|
|
24934
|
+
}
|
|
24935
|
+
}
|
|
24936
|
+
if (judgeTelemetry?.promptTokens !== void 0) {
|
|
24937
|
+
attributes["usage.prompt_tokens"] = judgeTelemetry.promptTokens;
|
|
24938
|
+
}
|
|
24939
|
+
if (judgeTelemetry?.completionTokens !== void 0) {
|
|
24940
|
+
attributes["usage.completion_tokens"] = judgeTelemetry.completionTokens;
|
|
24941
|
+
}
|
|
24942
|
+
if (judgeTelemetry?.totalTokens !== void 0) {
|
|
24943
|
+
attributes["usage.total_tokens"] = judgeTelemetry.totalTokens;
|
|
24944
|
+
}
|
|
24945
|
+
if (judgeTelemetry?.cachedTokens !== void 0) {
|
|
24946
|
+
attributes["usage.cached_tokens"] = judgeTelemetry.cachedTokens;
|
|
24947
|
+
}
|
|
24948
|
+
if (judgeTelemetry?.reasoningTokens !== void 0) {
|
|
24949
|
+
attributes["usage.reasoning_tokens"] = judgeTelemetry.reasoningTokens;
|
|
24950
|
+
}
|
|
24951
|
+
if (judgeTelemetry?.providerCost?.cost !== void 0) {
|
|
24952
|
+
attributes["usage.cost"] = judgeTelemetry.providerCost.cost;
|
|
24953
|
+
}
|
|
24954
|
+
if (judgeTelemetry?.providerCost?.upstreamInferenceCost !== void 0) {
|
|
24955
|
+
attributes["usage.cost_details.upstream_inference_cost"] = judgeTelemetry.providerCost.upstreamInferenceCost;
|
|
24956
|
+
}
|
|
24957
|
+
if (judgeTelemetry?.providerCost?.upstreamInferenceInputCost !== void 0) {
|
|
24958
|
+
attributes["usage.cost_details.upstream_inference_input_cost"] = judgeTelemetry.providerCost.upstreamInferenceInputCost;
|
|
24959
|
+
}
|
|
24960
|
+
if (judgeTelemetry?.providerCost?.upstreamInferenceOutputCost !== void 0) {
|
|
24961
|
+
attributes["usage.cost_details.upstream_inference_output_cost"] = judgeTelemetry.providerCost.upstreamInferenceOutputCost;
|
|
24962
|
+
}
|
|
24928
24963
|
if (storagePayload.userId) {
|
|
24929
24964
|
attributes["user.id"] = storagePayload.userId;
|
|
24930
24965
|
}
|
|
@@ -25807,6 +25842,64 @@ function extractErrorMessage(error) {
|
|
|
25807
25842
|
}
|
|
25808
25843
|
}
|
|
25809
25844
|
__name(extractErrorMessage, "extractErrorMessage");
|
|
25845
|
+
function extractJudgeTelemetry(metadata) {
|
|
25846
|
+
const record = isPlainRecord(metadata) ? metadata : void 0;
|
|
25847
|
+
if (!record) {
|
|
25848
|
+
return void 0;
|
|
25849
|
+
}
|
|
25850
|
+
const sources = [];
|
|
25851
|
+
if (isPlainRecord(record.voltAgent)) {
|
|
25852
|
+
sources.push(record.voltAgent);
|
|
25853
|
+
}
|
|
25854
|
+
if (isPlainRecord(record.scorer)) {
|
|
25855
|
+
sources.push(record.scorer);
|
|
25856
|
+
}
|
|
25857
|
+
if (isPlainRecord(record.payload)) {
|
|
25858
|
+
sources.push(record.payload);
|
|
25859
|
+
}
|
|
25860
|
+
for (const source of sources) {
|
|
25861
|
+
const judge = isPlainRecord(source?.judge) ? source?.judge : void 0;
|
|
25862
|
+
if (!judge) {
|
|
25863
|
+
continue;
|
|
25864
|
+
}
|
|
25865
|
+
const usage = isPlainRecord(judge.usage) ? judge.usage : void 0;
|
|
25866
|
+
const providerCost = isPlainRecord(judge.providerCost) ? judge.providerCost : void 0;
|
|
25867
|
+
const telemetry = {
|
|
25868
|
+
modelName: readString(judge.model),
|
|
25869
|
+
promptTokens: readNumber(usage?.promptTokens),
|
|
25870
|
+
completionTokens: readNumber(usage?.completionTokens),
|
|
25871
|
+
totalTokens: readNumber(usage?.totalTokens),
|
|
25872
|
+
cachedTokens: readNumber(usage?.cachedInputTokens ?? usage?.cachedTokens),
|
|
25873
|
+
reasoningTokens: readNumber(usage?.reasoningTokens),
|
|
25874
|
+
providerCost: providerCost ? {
|
|
25875
|
+
cost: readNumber(providerCost.cost),
|
|
25876
|
+
upstreamInferenceCost: readNumber(providerCost.upstreamInferenceCost),
|
|
25877
|
+
upstreamInferenceInputCost: readNumber(providerCost.upstreamInferenceInputCost),
|
|
25878
|
+
upstreamInferenceOutputCost: readNumber(providerCost.upstreamInferenceOutputCost)
|
|
25879
|
+
} : void 0
|
|
25880
|
+
};
|
|
25881
|
+
if (telemetry.modelName || telemetry.promptTokens !== void 0 || telemetry.completionTokens !== void 0 || telemetry.totalTokens !== void 0 || telemetry.cachedTokens !== void 0 || telemetry.reasoningTokens !== void 0 || telemetry.providerCost?.cost !== void 0 || telemetry.providerCost?.upstreamInferenceCost !== void 0 || telemetry.providerCost?.upstreamInferenceInputCost !== void 0 || telemetry.providerCost?.upstreamInferenceOutputCost !== void 0) {
|
|
25882
|
+
return telemetry;
|
|
25883
|
+
}
|
|
25884
|
+
}
|
|
25885
|
+
return void 0;
|
|
25886
|
+
}
|
|
25887
|
+
__name(extractJudgeTelemetry, "extractJudgeTelemetry");
|
|
25888
|
+
function readString(value) {
|
|
25889
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
25890
|
+
}
|
|
25891
|
+
__name(readString, "readString");
|
|
25892
|
+
function readNumber(value) {
|
|
25893
|
+
if (typeof value === "number") {
|
|
25894
|
+
return Number.isFinite(value) ? value : void 0;
|
|
25895
|
+
}
|
|
25896
|
+
if (typeof value === "string") {
|
|
25897
|
+
const parsed = Number(value);
|
|
25898
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
25899
|
+
}
|
|
25900
|
+
return void 0;
|
|
25901
|
+
}
|
|
25902
|
+
__name(readNumber, "readNumber");
|
|
25810
25903
|
async function invokeEvalResultCallback(host, config, result) {
|
|
25811
25904
|
if (!config.onResult) {
|
|
25812
25905
|
return;
|
|
@@ -30146,6 +30239,27 @@ var extractOpenRouterUsageCost = /* @__PURE__ */ __name((providerMetadata) => {
|
|
|
30146
30239
|
};
|
|
30147
30240
|
return Object.values(result).some((value) => value !== void 0) ? result : void 0;
|
|
30148
30241
|
}, "extractOpenRouterUsageCost");
|
|
30242
|
+
var toLanguageModelUsage = /* @__PURE__ */ __name((value) => isPlainObject(value) ? value : void 0, "toLanguageModelUsage");
|
|
30243
|
+
var extractGenerationErrorDetails = /* @__PURE__ */ __name((error) => {
|
|
30244
|
+
const metadata = isRecord4(error) && isPlainObject(error.metadata) ? error.metadata : void 0;
|
|
30245
|
+
const originalError = isRecord4(error) ? error.originalError : void 0;
|
|
30246
|
+
const usage = firstDefined(
|
|
30247
|
+
isRecord4(error) ? toLanguageModelUsage(error.usage) : void 0,
|
|
30248
|
+
metadata ? toLanguageModelUsage(metadata.usage) : void 0,
|
|
30249
|
+
isRecord4(originalError) ? toLanguageModelUsage(originalError.usage) : void 0
|
|
30250
|
+
);
|
|
30251
|
+
const providerMetadata = firstDefined(
|
|
30252
|
+
metadata?.providerMetadata,
|
|
30253
|
+
isRecord4(error) ? error.providerMetadata : void 0,
|
|
30254
|
+
isRecord4(originalError) ? originalError.providerMetadata : void 0
|
|
30255
|
+
);
|
|
30256
|
+
const finishReason = firstNonBlank(
|
|
30257
|
+
isRecord4(error) ? error.finishReason : void 0,
|
|
30258
|
+
metadata?.finishReason,
|
|
30259
|
+
isRecord4(originalError) ? originalError.finishReason : void 0
|
|
30260
|
+
);
|
|
30261
|
+
return { usage, providerMetadata, finishReason };
|
|
30262
|
+
}, "extractGenerationErrorDetails");
|
|
30149
30263
|
var isAssistantContentPart = /* @__PURE__ */ __name((value) => {
|
|
30150
30264
|
if (!isRecord4(value)) {
|
|
30151
30265
|
return false;
|
|
@@ -30705,7 +30819,7 @@ var Agent = class {
|
|
|
30705
30819
|
onStepFinish: this.createStepHandler(oc, options)
|
|
30706
30820
|
})
|
|
30707
30821
|
);
|
|
30708
|
-
this.ensureStructuredOutputGenerated({
|
|
30822
|
+
await this.ensureStructuredOutputGenerated({
|
|
30709
30823
|
result: response,
|
|
30710
30824
|
output,
|
|
30711
30825
|
tools,
|
|
@@ -30719,7 +30833,13 @@ var Agent = class {
|
|
|
30719
30833
|
});
|
|
30720
30834
|
return response;
|
|
30721
30835
|
} catch (error) {
|
|
30722
|
-
|
|
30836
|
+
const errorDetails = extractGenerationErrorDetails(error);
|
|
30837
|
+
finalizeLLMSpan(import_api16.SpanStatusCode.ERROR, {
|
|
30838
|
+
message: error.message,
|
|
30839
|
+
usage: errorDetails.usage,
|
|
30840
|
+
finishReason: errorDetails.finishReason,
|
|
30841
|
+
providerMetadata: errorDetails.providerMetadata
|
|
30842
|
+
});
|
|
30723
30843
|
throw error;
|
|
30724
30844
|
}
|
|
30725
30845
|
}, "run")
|
|
@@ -32471,7 +32591,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
32471
32591
|
toolResults: stepToolResults.length > 0 ? stepToolResults : result.toolResults ?? []
|
|
32472
32592
|
};
|
|
32473
32593
|
}
|
|
32474
|
-
ensureStructuredOutputGenerated(params) {
|
|
32594
|
+
async ensureStructuredOutputGenerated(params) {
|
|
32475
32595
|
const { result, output, tools, maxSteps } = params;
|
|
32476
32596
|
if (!output) {
|
|
32477
32597
|
return;
|
|
@@ -32488,6 +32608,13 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
32488
32608
|
const stepCount = result.steps?.length ?? 0;
|
|
32489
32609
|
const finishReason = result.finishReason ?? "unknown";
|
|
32490
32610
|
const reachedMaxSteps = stepCount >= maxSteps;
|
|
32611
|
+
const providerMetadata = result.providerMetadata;
|
|
32612
|
+
const providerUsage = result.usage ? await Promise.resolve(result.usage) : void 0;
|
|
32613
|
+
const usageForFinish = resolveFinishUsage({
|
|
32614
|
+
providerMetadata,
|
|
32615
|
+
usage: providerUsage,
|
|
32616
|
+
totalUsage: result.totalUsage
|
|
32617
|
+
});
|
|
32491
32618
|
const guidance = configuredToolCount > 0 || toolCalls.length > 0 ? "When tools are enabled, ensure the model emits a final non-tool response that matches the output schema, or split this into two calls (tools first, schema formatting second)." : "Ensure the model emits a final response that matches the requested output schema.";
|
|
32492
32619
|
const maxStepHint = reachedMaxSteps ? ` Generation stopped after ${stepCount} steps (maxSteps=${maxSteps}).` : "";
|
|
32493
32620
|
throw createVoltAgentError(
|
|
@@ -32501,7 +32628,9 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
32501
32628
|
stepCount,
|
|
32502
32629
|
maxSteps,
|
|
32503
32630
|
configuredToolCount,
|
|
32504
|
-
toolCallCount: toolCalls.length
|
|
32631
|
+
toolCallCount: toolCalls.length,
|
|
32632
|
+
usage: usageForFinish ? JSON.parse((0, import_utils33.safeStringify)(usageForFinish)) : void 0,
|
|
32633
|
+
providerMetadata: providerMetadata !== void 0 ? JSON.parse((0, import_utils33.safeStringify)(providerMetadata)) : void 0
|
|
32505
32634
|
}
|
|
32506
32635
|
}
|
|
32507
32636
|
);
|
|
@@ -35410,7 +35539,18 @@ ${retrieverContext}`;
|
|
|
35410
35539
|
if (!oc.isActive && oc.cancellationError) {
|
|
35411
35540
|
throw oc.cancellationError;
|
|
35412
35541
|
}
|
|
35413
|
-
const voltagentError = createVoltAgentError(error);
|
|
35542
|
+
const voltagentError = isVoltAgentError(error) ? error : createVoltAgentError(error);
|
|
35543
|
+
const errorDetails = extractGenerationErrorDetails(voltagentError);
|
|
35544
|
+
if (errorDetails.usage || errorDetails.providerMetadata !== void 0) {
|
|
35545
|
+
this.recordRootSpanUsageAndProviderCost(
|
|
35546
|
+
oc.traceContext,
|
|
35547
|
+
errorDetails.usage,
|
|
35548
|
+
errorDetails.providerMetadata
|
|
35549
|
+
);
|
|
35550
|
+
}
|
|
35551
|
+
if (errorDetails.finishReason) {
|
|
35552
|
+
oc.traceContext.setFinishReason(errorDetails.finishReason);
|
|
35553
|
+
}
|
|
35414
35554
|
oc.traceContext.end("error", error);
|
|
35415
35555
|
const hooks = this.getMergedHooks(options);
|
|
35416
35556
|
await hooks.onEnd?.({
|