@voltagent/core 2.6.11 → 2.6.13
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 +342 -106
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +341 -105
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -287,7 +287,7 @@ __export(index_exports, {
|
|
|
287
287
|
context: () => import_api9.context,
|
|
288
288
|
convertUsage: () => convertUsage,
|
|
289
289
|
cosineSimilarity: () => cosineSimilarity,
|
|
290
|
-
createAsyncIterableStream: () =>
|
|
290
|
+
createAsyncIterableStream: () => import_utils41.createAsyncIterableStream,
|
|
291
291
|
createDefaultInputSafetyGuardrails: () => createDefaultInputSafetyGuardrails,
|
|
292
292
|
createDefaultPIIGuardrails: () => createDefaultPIIGuardrails,
|
|
293
293
|
createDefaultSafetyGuardrails: () => createDefaultSafetyGuardrails,
|
|
@@ -12693,7 +12693,7 @@ __name(createWorkflowChain, "createWorkflowChain");
|
|
|
12693
12693
|
// src/agent/agent.ts
|
|
12694
12694
|
var import_node_util = require("util");
|
|
12695
12695
|
var import_api16 = require("@opentelemetry/api");
|
|
12696
|
-
var
|
|
12696
|
+
var import_utils34 = require("@voltagent/internal/utils");
|
|
12697
12697
|
var import_ai7 = require("ai");
|
|
12698
12698
|
var import_zod7 = require("zod");
|
|
12699
12699
|
|
|
@@ -26521,6 +26521,229 @@ function addModelAttributesToSpan(span, modelName, options, defaultMaxOutputToke
|
|
|
26521
26521
|
}
|
|
26522
26522
|
__name(addModelAttributesToSpan, "addModelAttributesToSpan");
|
|
26523
26523
|
|
|
26524
|
+
// src/agent/prompt-context-usage.ts
|
|
26525
|
+
var import_utils29 = require("@voltagent/internal/utils");
|
|
26526
|
+
var ESTIMATED_CHARS_PER_TOKEN = 4;
|
|
26527
|
+
var BINARY_PART_TYPES = /* @__PURE__ */ new Set([
|
|
26528
|
+
"audio",
|
|
26529
|
+
"file",
|
|
26530
|
+
"image",
|
|
26531
|
+
"input_audio",
|
|
26532
|
+
"input_image",
|
|
26533
|
+
"media"
|
|
26534
|
+
]);
|
|
26535
|
+
var LARGE_BINARY_KEYS = /* @__PURE__ */ new Set(["audio", "base64", "bytes", "data", "image"]);
|
|
26536
|
+
var CIRCULAR_REFERENCE_PLACEHOLDER = "[circular]";
|
|
26537
|
+
function estimatePromptContextUsage(params) {
|
|
26538
|
+
let systemTokensEstimated = 0;
|
|
26539
|
+
let messageTokensEstimated = 0;
|
|
26540
|
+
let nonSystemMessageTokensEstimated = 0;
|
|
26541
|
+
let systemMessageCount = 0;
|
|
26542
|
+
for (const message of params.messages ?? []) {
|
|
26543
|
+
const serializedMessage = serializePromptMessage(message);
|
|
26544
|
+
if (!serializedMessage) {
|
|
26545
|
+
continue;
|
|
26546
|
+
}
|
|
26547
|
+
const estimatedTokens = estimateTokensFromText(serializedMessage);
|
|
26548
|
+
messageTokensEstimated += estimatedTokens;
|
|
26549
|
+
if (message.role === "system") {
|
|
26550
|
+
systemTokensEstimated += estimatedTokens;
|
|
26551
|
+
systemMessageCount += 1;
|
|
26552
|
+
continue;
|
|
26553
|
+
}
|
|
26554
|
+
nonSystemMessageTokensEstimated += estimatedTokens;
|
|
26555
|
+
}
|
|
26556
|
+
const serializedTools = Object.entries(params.tools ?? {}).map(
|
|
26557
|
+
([name, tool2]) => serializeToolDefinition(name, tool2)
|
|
26558
|
+
);
|
|
26559
|
+
const toolTokensEstimated = serializedTools.length > 0 ? estimateTokensFromText((0, import_utils29.safeStringify)(serializedTools)) : 0;
|
|
26560
|
+
const totalTokensEstimated = messageTokensEstimated + toolTokensEstimated;
|
|
26561
|
+
if (totalTokensEstimated === 0) {
|
|
26562
|
+
return void 0;
|
|
26563
|
+
}
|
|
26564
|
+
return {
|
|
26565
|
+
systemTokensEstimated,
|
|
26566
|
+
messageTokensEstimated,
|
|
26567
|
+
nonSystemMessageTokensEstimated,
|
|
26568
|
+
toolTokensEstimated,
|
|
26569
|
+
totalTokensEstimated,
|
|
26570
|
+
systemMessageCount,
|
|
26571
|
+
toolCount: serializedTools.length
|
|
26572
|
+
};
|
|
26573
|
+
}
|
|
26574
|
+
__name(estimatePromptContextUsage, "estimatePromptContextUsage");
|
|
26575
|
+
function promptContextUsageEstimateToAttributes(estimate) {
|
|
26576
|
+
return {
|
|
26577
|
+
"usage.prompt_context.system_tokens_estimated": estimate.systemTokensEstimated,
|
|
26578
|
+
"usage.prompt_context.message_tokens_estimated": estimate.messageTokensEstimated,
|
|
26579
|
+
"usage.prompt_context.non_system_message_tokens_estimated": estimate.nonSystemMessageTokensEstimated,
|
|
26580
|
+
"usage.prompt_context.tool_tokens_estimated": estimate.toolTokensEstimated,
|
|
26581
|
+
"usage.prompt_context.total_tokens_estimated": estimate.totalTokensEstimated,
|
|
26582
|
+
"usage.prompt_context.system_message_count": estimate.systemMessageCount,
|
|
26583
|
+
"usage.prompt_context.tool_count": estimate.toolCount
|
|
26584
|
+
};
|
|
26585
|
+
}
|
|
26586
|
+
__name(promptContextUsageEstimateToAttributes, "promptContextUsageEstimateToAttributes");
|
|
26587
|
+
function estimateTokensFromText(text) {
|
|
26588
|
+
if (!text) {
|
|
26589
|
+
return 0;
|
|
26590
|
+
}
|
|
26591
|
+
return Math.ceil(text.length / ESTIMATED_CHARS_PER_TOKEN);
|
|
26592
|
+
}
|
|
26593
|
+
__name(estimateTokensFromText, "estimateTokensFromText");
|
|
26594
|
+
function serializePromptMessage(message) {
|
|
26595
|
+
const content = serializePromptValue(message.content).trim();
|
|
26596
|
+
if (!content) {
|
|
26597
|
+
return "";
|
|
26598
|
+
}
|
|
26599
|
+
const role = typeof message.role === "string" ? message.role.toUpperCase() : "MESSAGE";
|
|
26600
|
+
return `${role}:
|
|
26601
|
+
${content}`;
|
|
26602
|
+
}
|
|
26603
|
+
__name(serializePromptMessage, "serializePromptMessage");
|
|
26604
|
+
function serializePromptValue(value, seen = /* @__PURE__ */ new Set()) {
|
|
26605
|
+
if (typeof value === "string") {
|
|
26606
|
+
return value;
|
|
26607
|
+
}
|
|
26608
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
26609
|
+
return String(value);
|
|
26610
|
+
}
|
|
26611
|
+
if (Array.isArray(value)) {
|
|
26612
|
+
if (seen.has(value)) {
|
|
26613
|
+
return CIRCULAR_REFERENCE_PLACEHOLDER;
|
|
26614
|
+
}
|
|
26615
|
+
seen.add(value);
|
|
26616
|
+
try {
|
|
26617
|
+
return value.map((entry) => serializePromptValue(entry, seen)).filter((entry) => entry.trim().length > 0).join("\n");
|
|
26618
|
+
} finally {
|
|
26619
|
+
seen.delete(value);
|
|
26620
|
+
}
|
|
26621
|
+
}
|
|
26622
|
+
if (!value || typeof value !== "object") {
|
|
26623
|
+
return "";
|
|
26624
|
+
}
|
|
26625
|
+
const record = value;
|
|
26626
|
+
if (seen.has(record)) {
|
|
26627
|
+
return CIRCULAR_REFERENCE_PLACEHOLDER;
|
|
26628
|
+
}
|
|
26629
|
+
seen.add(record);
|
|
26630
|
+
const type = typeof record.type === "string" ? record.type : void 0;
|
|
26631
|
+
try {
|
|
26632
|
+
if (typeof record.text === "string") {
|
|
26633
|
+
return record.text;
|
|
26634
|
+
}
|
|
26635
|
+
if (type && BINARY_PART_TYPES.has(type)) {
|
|
26636
|
+
return `[${type}]`;
|
|
26637
|
+
}
|
|
26638
|
+
if (type === "tool-call") {
|
|
26639
|
+
const toolName = typeof record.toolName === "string" ? record.toolName : "tool";
|
|
26640
|
+
const input = serializePromptValue(record.input, seen);
|
|
26641
|
+
return input ? `tool-call ${toolName}: ${input}` : `tool-call ${toolName}`;
|
|
26642
|
+
}
|
|
26643
|
+
if (type === "tool-result") {
|
|
26644
|
+
const toolName = typeof record.toolName === "string" ? record.toolName : "tool";
|
|
26645
|
+
const output = serializePromptValue(record.output, seen);
|
|
26646
|
+
return output ? `tool-result ${toolName}: ${output}` : `tool-result ${toolName}`;
|
|
26647
|
+
}
|
|
26648
|
+
if ("content" in record) {
|
|
26649
|
+
const nestedContent = serializePromptValue(record.content, seen);
|
|
26650
|
+
if (nestedContent) {
|
|
26651
|
+
return nestedContent;
|
|
26652
|
+
}
|
|
26653
|
+
}
|
|
26654
|
+
return (0, import_utils29.safeStringify)(sanitizeRecord(record));
|
|
26655
|
+
} finally {
|
|
26656
|
+
seen.delete(record);
|
|
26657
|
+
}
|
|
26658
|
+
}
|
|
26659
|
+
__name(serializePromptValue, "serializePromptValue");
|
|
26660
|
+
function sanitizeRecord(record) {
|
|
26661
|
+
return sanitizeRecordValue(record, /* @__PURE__ */ new Set());
|
|
26662
|
+
}
|
|
26663
|
+
__name(sanitizeRecord, "sanitizeRecord");
|
|
26664
|
+
function sanitizeRecordValue(record, seen) {
|
|
26665
|
+
if (seen.has(record)) {
|
|
26666
|
+
return { circular: CIRCULAR_REFERENCE_PLACEHOLDER };
|
|
26667
|
+
}
|
|
26668
|
+
seen.add(record);
|
|
26669
|
+
const sanitized = {};
|
|
26670
|
+
for (const [key, value] of Object.entries(record)) {
|
|
26671
|
+
sanitized[key] = LARGE_BINARY_KEYS.has(key) ? "[omitted]" : sanitizeValue(value, seen);
|
|
26672
|
+
}
|
|
26673
|
+
seen.delete(record);
|
|
26674
|
+
return sanitized;
|
|
26675
|
+
}
|
|
26676
|
+
__name(sanitizeRecordValue, "sanitizeRecordValue");
|
|
26677
|
+
function serializeToolDefinition(name, tool2) {
|
|
26678
|
+
if (!tool2 || typeof tool2 !== "object") {
|
|
26679
|
+
return { name };
|
|
26680
|
+
}
|
|
26681
|
+
const candidate = tool2;
|
|
26682
|
+
return {
|
|
26683
|
+
name,
|
|
26684
|
+
...typeof candidate.type === "string" ? { type: candidate.type } : {},
|
|
26685
|
+
...typeof candidate.id === "string" ? { id: candidate.id } : {},
|
|
26686
|
+
...typeof candidate.description === "string" ? { description: candidate.description } : {},
|
|
26687
|
+
...candidate.inputSchema || candidate.parameters || candidate.input_schema || candidate.schema ? {
|
|
26688
|
+
inputSchema: normalizeSchema(
|
|
26689
|
+
candidate.inputSchema ?? candidate.parameters ?? candidate.input_schema ?? candidate.schema
|
|
26690
|
+
)
|
|
26691
|
+
} : {},
|
|
26692
|
+
...candidate.outputSchema || candidate.output_schema ? {
|
|
26693
|
+
outputSchema: normalizeSchema(candidate.outputSchema ?? candidate.output_schema)
|
|
26694
|
+
} : {},
|
|
26695
|
+
...isPlainObject(candidate.args) ? { args: sanitizeRecord(candidate.args) } : {}
|
|
26696
|
+
};
|
|
26697
|
+
}
|
|
26698
|
+
__name(serializeToolDefinition, "serializeToolDefinition");
|
|
26699
|
+
function normalizeSchema(schema) {
|
|
26700
|
+
if (!schema || typeof schema !== "object") {
|
|
26701
|
+
return schema;
|
|
26702
|
+
}
|
|
26703
|
+
try {
|
|
26704
|
+
if ("_def" in schema) {
|
|
26705
|
+
return zodSchemaToJsonUI(schema);
|
|
26706
|
+
}
|
|
26707
|
+
} catch (_error) {
|
|
26708
|
+
return schema;
|
|
26709
|
+
}
|
|
26710
|
+
return schema;
|
|
26711
|
+
}
|
|
26712
|
+
__name(normalizeSchema, "normalizeSchema");
|
|
26713
|
+
function sanitizeValue(value, seen) {
|
|
26714
|
+
if (value === null || value === void 0) {
|
|
26715
|
+
return value;
|
|
26716
|
+
}
|
|
26717
|
+
if (typeof value !== "object") {
|
|
26718
|
+
return value;
|
|
26719
|
+
}
|
|
26720
|
+
if (value instanceof Date || value instanceof RegExp) {
|
|
26721
|
+
return value;
|
|
26722
|
+
}
|
|
26723
|
+
if (Array.isArray(value)) {
|
|
26724
|
+
if (seen.has(value)) {
|
|
26725
|
+
return [CIRCULAR_REFERENCE_PLACEHOLDER];
|
|
26726
|
+
}
|
|
26727
|
+
seen.add(value);
|
|
26728
|
+
const sanitized = value.map((entry) => sanitizeValue(entry, seen));
|
|
26729
|
+
seen.delete(value);
|
|
26730
|
+
return sanitized;
|
|
26731
|
+
}
|
|
26732
|
+
if (!isPlainObject(value)) {
|
|
26733
|
+
return value;
|
|
26734
|
+
}
|
|
26735
|
+
return sanitizeRecordValue(value, seen);
|
|
26736
|
+
}
|
|
26737
|
+
__name(sanitizeValue, "sanitizeValue");
|
|
26738
|
+
function isPlainObject(value) {
|
|
26739
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
26740
|
+
return false;
|
|
26741
|
+
}
|
|
26742
|
+
const prototype = Object.getPrototypeOf(value);
|
|
26743
|
+
return prototype === Object.prototype || prototype === null;
|
|
26744
|
+
}
|
|
26745
|
+
__name(isPlainObject, "isPlainObject");
|
|
26746
|
+
|
|
26524
26747
|
// src/agent/tool-input-coercion.ts
|
|
26525
26748
|
var isPathSegment = /* @__PURE__ */ __name((value) => typeof value === "string" || typeof value === "number", "isPathSegment");
|
|
26526
26749
|
var isRecord2 = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null && !Array.isArray(value), "isRecord");
|
|
@@ -26639,7 +26862,7 @@ var coerceStringifiedJsonToolArgs = /* @__PURE__ */ __name((rawArgs, issues) =>
|
|
|
26639
26862
|
var import_ts_pattern2 = require("ts-pattern");
|
|
26640
26863
|
|
|
26641
26864
|
// src/agent/apply-summarization.ts
|
|
26642
|
-
var
|
|
26865
|
+
var import_utils30 = require("@voltagent/internal/utils");
|
|
26643
26866
|
var import_ai5 = require("ai");
|
|
26644
26867
|
var SUMMARY_METADATA_KEY = "agent";
|
|
26645
26868
|
var SUMMARY_STATE_CACHE_KEY = Symbol("agentSummaryState");
|
|
@@ -26752,7 +26975,7 @@ var applySummarization = /* @__PURE__ */ __name(async ({
|
|
|
26752
26975
|
}
|
|
26753
26976
|
} catch (error) {
|
|
26754
26977
|
oc.logger.debug("[Agent] Failed to summarize conversation", {
|
|
26755
|
-
error: (0,
|
|
26978
|
+
error: (0, import_utils30.safeStringify)(error)
|
|
26756
26979
|
});
|
|
26757
26980
|
if (summarySpan) {
|
|
26758
26981
|
oc.traceContext.endChildSpan(summarySpan, "error", {
|
|
@@ -26835,7 +27058,7 @@ async function loadAgentSummaryState(agent, context8) {
|
|
|
26835
27058
|
state = readSummaryStateFromMetadata(conversation?.metadata);
|
|
26836
27059
|
} catch (error) {
|
|
26837
27060
|
context8.logger.debug("[Agent] Failed to load summary state from memory", {
|
|
26838
|
-
error: (0,
|
|
27061
|
+
error: (0, import_utils30.safeStringify)(error)
|
|
26839
27062
|
});
|
|
26840
27063
|
}
|
|
26841
27064
|
}
|
|
@@ -26865,7 +27088,7 @@ async function updateAgentSummaryState(agent, context8, updater) {
|
|
|
26865
27088
|
}
|
|
26866
27089
|
} catch (error) {
|
|
26867
27090
|
context8.logger.debug("[Agent] Failed to persist summary state", {
|
|
26868
|
-
error: (0,
|
|
27091
|
+
error: (0, import_utils30.safeStringify)(error)
|
|
26869
27092
|
});
|
|
26870
27093
|
}
|
|
26871
27094
|
}
|
|
@@ -26898,11 +27121,11 @@ function removeSystemMessagesWithMarker(messages, marker) {
|
|
|
26898
27121
|
});
|
|
26899
27122
|
}
|
|
26900
27123
|
__name(removeSystemMessagesWithMarker, "removeSystemMessagesWithMarker");
|
|
26901
|
-
function
|
|
27124
|
+
function estimateTokensFromText2(text) {
|
|
26902
27125
|
if (!text) return 0;
|
|
26903
27126
|
return Math.ceil(text.length / SUMMARY_CHAR_PER_TOKEN);
|
|
26904
27127
|
}
|
|
26905
|
-
__name(
|
|
27128
|
+
__name(estimateTokensFromText2, "estimateTokensFromText");
|
|
26906
27129
|
function summarizePartValue(value) {
|
|
26907
27130
|
if (typeof value === "string") {
|
|
26908
27131
|
return truncateText2(value, SUMMARY_MAX_PART_CHARS);
|
|
@@ -26910,7 +27133,7 @@ function summarizePartValue(value) {
|
|
|
26910
27133
|
if (value === null || value === void 0) {
|
|
26911
27134
|
return "";
|
|
26912
27135
|
}
|
|
26913
|
-
return truncateText2((0,
|
|
27136
|
+
return truncateText2((0, import_utils30.safeStringify)(value), SUMMARY_MAX_PART_CHARS);
|
|
26914
27137
|
}
|
|
26915
27138
|
__name(summarizePartValue, "summarizePartValue");
|
|
26916
27139
|
function extractSummaryText(message) {
|
|
@@ -26965,7 +27188,7 @@ function estimateTokensFromMessages(messages) {
|
|
|
26965
27188
|
for (const message of messages) {
|
|
26966
27189
|
const formatted = formatMessageForSummary(message);
|
|
26967
27190
|
if (formatted) {
|
|
26968
|
-
total +=
|
|
27191
|
+
total += estimateTokensFromText2(formatted);
|
|
26969
27192
|
}
|
|
26970
27193
|
}
|
|
26971
27194
|
return total;
|
|
@@ -28412,7 +28635,7 @@ var collapseRedundantStepStarts = /* @__PURE__ */ __name((parts) => {
|
|
|
28412
28635
|
|
|
28413
28636
|
// src/agent/middleware.ts
|
|
28414
28637
|
var import_api13 = require("@opentelemetry/api");
|
|
28415
|
-
var
|
|
28638
|
+
var import_utils31 = require("@voltagent/internal/utils");
|
|
28416
28639
|
function createInputMiddleware(options) {
|
|
28417
28640
|
return {
|
|
28418
28641
|
id: options.id,
|
|
@@ -28491,7 +28714,7 @@ function serializeMiddlewareValue(value) {
|
|
|
28491
28714
|
if (typeof value === "string") {
|
|
28492
28715
|
return value;
|
|
28493
28716
|
}
|
|
28494
|
-
return (0,
|
|
28717
|
+
return (0, import_utils31.safeStringify)(value);
|
|
28495
28718
|
}
|
|
28496
28719
|
__name(serializeMiddlewareValue, "serializeMiddlewareValue");
|
|
28497
28720
|
async function runInputMiddlewares(input, oc, middlewares, operation, agent, retryCount) {
|
|
@@ -28515,8 +28738,8 @@ async function runInputMiddlewares(input, oc, middlewares, operation, agent, ret
|
|
|
28515
28738
|
...middleware.id ? { "middleware.id": middleware.id } : {},
|
|
28516
28739
|
"middleware.name": middleware.name,
|
|
28517
28740
|
...middleware.description ? { "middleware.description": middleware.description } : {},
|
|
28518
|
-
...middleware.tags && middleware.tags.length > 0 ? { "middleware.tags": (0,
|
|
28519
|
-
...middleware.metadata ? { "middleware.metadata": (0,
|
|
28741
|
+
...middleware.tags && middleware.tags.length > 0 ? { "middleware.tags": (0, import_utils31.safeStringify)(middleware.tags) } : {},
|
|
28742
|
+
...middleware.metadata ? { "middleware.metadata": (0, import_utils31.safeStringify)(middleware.metadata) } : {},
|
|
28520
28743
|
"middleware.retry_count": retryCount,
|
|
28521
28744
|
"middleware.input.original": serializeMiddlewareValue(originalInput),
|
|
28522
28745
|
"middleware.input.current": serializeMiddlewareValue(currentInput)
|
|
@@ -28584,8 +28807,8 @@ async function runOutputMiddlewares(output, oc, middlewares, operation, agent, r
|
|
|
28584
28807
|
...middleware.id ? { "middleware.id": middleware.id } : {},
|
|
28585
28808
|
"middleware.name": middleware.name,
|
|
28586
28809
|
...middleware.description ? { "middleware.description": middleware.description } : {},
|
|
28587
|
-
...middleware.tags && middleware.tags.length > 0 ? { "middleware.tags": (0,
|
|
28588
|
-
...middleware.metadata ? { "middleware.metadata": (0,
|
|
28810
|
+
...middleware.tags && middleware.tags.length > 0 ? { "middleware.tags": (0, import_utils31.safeStringify)(middleware.tags) } : {},
|
|
28811
|
+
...middleware.metadata ? { "middleware.metadata": (0, import_utils31.safeStringify)(middleware.metadata) } : {},
|
|
28589
28812
|
"middleware.retry_count": retryCount,
|
|
28590
28813
|
"middleware.output.original": serializeMiddlewareValue(originalOutput),
|
|
28591
28814
|
"middleware.output.current": serializeMiddlewareValue(currentOutput)
|
|
@@ -28593,13 +28816,13 @@ async function runOutputMiddlewares(output, oc, middlewares, operation, agent, r
|
|
|
28593
28816
|
}
|
|
28594
28817
|
);
|
|
28595
28818
|
if (metadata?.usage !== void 0) {
|
|
28596
|
-
span.setAttribute("middleware.usage", (0,
|
|
28819
|
+
span.setAttribute("middleware.usage", (0, import_utils31.safeStringify)(metadata.usage));
|
|
28597
28820
|
}
|
|
28598
28821
|
if (metadata?.finishReason !== void 0 && metadata.finishReason !== null) {
|
|
28599
28822
|
span.setAttribute("middleware.finish_reason", metadata.finishReason);
|
|
28600
28823
|
}
|
|
28601
28824
|
if (metadata?.warnings && metadata.warnings.length > 0) {
|
|
28602
|
-
span.setAttribute("middleware.warnings", (0,
|
|
28825
|
+
span.setAttribute("middleware.warnings", (0, import_utils31.safeStringify)(metadata.warnings));
|
|
28603
28826
|
}
|
|
28604
28827
|
try {
|
|
28605
28828
|
const abort = /* @__PURE__ */ __name((reason, options) => {
|
|
@@ -28647,7 +28870,7 @@ var import_ai6 = require("ai");
|
|
|
28647
28870
|
|
|
28648
28871
|
// src/agent/streaming/output-guardrail-stream-runner.ts
|
|
28649
28872
|
var import_api14 = require("@opentelemetry/api");
|
|
28650
|
-
var
|
|
28873
|
+
var import_utils32 = require("@voltagent/internal/utils");
|
|
28651
28874
|
var isTextDelta = /* @__PURE__ */ __name((part) => part.type === "text-delta", "isTextDelta");
|
|
28652
28875
|
var extractChunkText = /* @__PURE__ */ __name((part) => {
|
|
28653
28876
|
if (!isTextDelta(part)) {
|
|
@@ -28902,8 +29125,8 @@ var OutputGuardrailStreamRunner = class {
|
|
|
28902
29125
|
"guardrail.name": guardrail.name,
|
|
28903
29126
|
...guardrail.description ? { "guardrail.description": guardrail.description } : {},
|
|
28904
29127
|
...guardrail.severity ? { "guardrail.severity": guardrail.severity } : {},
|
|
28905
|
-
...guardrail.tags && guardrail.tags.length > 0 ? { "guardrail.tags": (0,
|
|
28906
|
-
...guardrail.metadata ? { "guardrail.metadata": (0,
|
|
29128
|
+
...guardrail.tags && guardrail.tags.length > 0 ? { "guardrail.tags": (0, import_utils32.safeStringify)(guardrail.tags) } : {},
|
|
29129
|
+
...guardrail.metadata ? { "guardrail.metadata": (0, import_utils32.safeStringify)(guardrail.metadata) } : {}
|
|
28907
29130
|
}
|
|
28908
29131
|
}
|
|
28909
29132
|
);
|
|
@@ -29431,7 +29654,7 @@ __name(convertFullStreamChunkToUIMessageStream, "convertFullStreamChunkToUIMessa
|
|
|
29431
29654
|
|
|
29432
29655
|
// src/agent/subagent/index.ts
|
|
29433
29656
|
var import_api15 = require("@opentelemetry/api");
|
|
29434
|
-
var
|
|
29657
|
+
var import_utils33 = require("@voltagent/internal/utils");
|
|
29435
29658
|
var import_zod6 = require("zod");
|
|
29436
29659
|
|
|
29437
29660
|
// src/agent/subagent/types.ts
|
|
@@ -29737,7 +29960,7 @@ ${guidelinesText}
|
|
|
29737
29960
|
taskContent = `Task handed off from ${sourceAgent?.name || this.agentName} to ${targetAgent.name}:
|
|
29738
29961
|
${task}
|
|
29739
29962
|
|
|
29740
|
-
Context: ${(0,
|
|
29963
|
+
Context: ${(0, import_utils33.safeStringify)(contextObj, { indentation: 2 })}`;
|
|
29741
29964
|
}
|
|
29742
29965
|
const taskMessage = {
|
|
29743
29966
|
id: crypto.randomUUID(),
|
|
@@ -29795,7 +30018,7 @@ Context: ${(0, import_utils32.safeStringify)(contextObj, { indentation: 2 })}`;
|
|
|
29795
30018
|
options2
|
|
29796
30019
|
);
|
|
29797
30020
|
const finalObject = await response.object;
|
|
29798
|
-
finalResult = (0,
|
|
30021
|
+
finalResult = (0, import_utils33.safeStringify)(finalObject);
|
|
29799
30022
|
finalMessages = [taskMessage, this.createAssistantMessage(finalResult)];
|
|
29800
30023
|
} else if (this.isGenerateObjectConfig(targetAgentConfig)) {
|
|
29801
30024
|
const options2 = { ...baseOptions, ...targetAgentConfig.options };
|
|
@@ -29804,7 +30027,7 @@ Context: ${(0, import_utils32.safeStringify)(contextObj, { indentation: 2 })}`;
|
|
|
29804
30027
|
targetAgentConfig.schema,
|
|
29805
30028
|
options2
|
|
29806
30029
|
);
|
|
29807
|
-
finalResult = (0,
|
|
30030
|
+
finalResult = (0, import_utils33.safeStringify)(response);
|
|
29808
30031
|
usage = response.usage;
|
|
29809
30032
|
finalMessages = [taskMessage, this.createAssistantMessage(finalResult)];
|
|
29810
30033
|
} else {
|
|
@@ -30169,7 +30392,7 @@ var DEFAULT_CONVERSATION_PERSISTENCE_OPTIONS = {
|
|
|
30169
30392
|
flushOnToolResult: true
|
|
30170
30393
|
};
|
|
30171
30394
|
var isRecord4 = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null, "isRecord");
|
|
30172
|
-
var
|
|
30395
|
+
var isPlainObject2 = /* @__PURE__ */ __name((value) => isRecord4(value) && !Array.isArray(value), "isPlainObject");
|
|
30173
30396
|
var hasNonEmptyString2 = /* @__PURE__ */ __name((value) => typeof value === "string" && value.trim().length > 0, "hasNonEmptyString");
|
|
30174
30397
|
var firstNonBlank = /* @__PURE__ */ __name((...values) => {
|
|
30175
30398
|
for (const value of values) {
|
|
@@ -30209,17 +30432,17 @@ var toBoolean = /* @__PURE__ */ __name((value) => {
|
|
|
30209
30432
|
return void 0;
|
|
30210
30433
|
}, "toBoolean");
|
|
30211
30434
|
var extractOpenRouterUsageCost = /* @__PURE__ */ __name((providerMetadata) => {
|
|
30212
|
-
if (!
|
|
30435
|
+
if (!isPlainObject2(providerMetadata)) {
|
|
30213
30436
|
return void 0;
|
|
30214
30437
|
}
|
|
30215
|
-
const openRouterMetadata =
|
|
30216
|
-
const usage = openRouterMetadata &&
|
|
30438
|
+
const openRouterMetadata = isPlainObject2(providerMetadata.openrouter) ? providerMetadata.openrouter : void 0;
|
|
30439
|
+
const usage = openRouterMetadata && isPlainObject2(openRouterMetadata.usage) ? openRouterMetadata.usage : void 0;
|
|
30217
30440
|
if (!usage) {
|
|
30218
30441
|
return void 0;
|
|
30219
30442
|
}
|
|
30220
30443
|
const costDetails = firstDefined(
|
|
30221
|
-
|
|
30222
|
-
|
|
30444
|
+
isPlainObject2(usage.costDetails) ? usage.costDetails : void 0,
|
|
30445
|
+
isPlainObject2(usage.cost_details) ? usage.cost_details : void 0
|
|
30223
30446
|
);
|
|
30224
30447
|
const result = {
|
|
30225
30448
|
cost: toFiniteNumber(usage.cost),
|
|
@@ -30239,9 +30462,9 @@ var extractOpenRouterUsageCost = /* @__PURE__ */ __name((providerMetadata) => {
|
|
|
30239
30462
|
};
|
|
30240
30463
|
return Object.values(result).some((value) => value !== void 0) ? result : void 0;
|
|
30241
30464
|
}, "extractOpenRouterUsageCost");
|
|
30242
|
-
var toLanguageModelUsage = /* @__PURE__ */ __name((value) =>
|
|
30465
|
+
var toLanguageModelUsage = /* @__PURE__ */ __name((value) => isPlainObject2(value) ? value : void 0, "toLanguageModelUsage");
|
|
30243
30466
|
var extractGenerationErrorDetails = /* @__PURE__ */ __name((error) => {
|
|
30244
|
-
const metadata = isRecord4(error) &&
|
|
30467
|
+
const metadata = isRecord4(error) && isPlainObject2(error.metadata) ? error.metadata : void 0;
|
|
30245
30468
|
const originalError = isRecord4(error) ? error.originalError : void 0;
|
|
30246
30469
|
const usage = firstDefined(
|
|
30247
30470
|
isRecord4(error) ? toLanguageModelUsage(error.usage) : void 0,
|
|
@@ -30709,12 +30932,12 @@ var Agent = class {
|
|
|
30709
30932
|
);
|
|
30710
30933
|
const contextMap = Object.fromEntries(oc.context.entries());
|
|
30711
30934
|
if (Object.keys(contextMap).length > 0) {
|
|
30712
|
-
rootSpan.setAttribute("agent.context", (0,
|
|
30935
|
+
rootSpan.setAttribute("agent.context", (0, import_utils34.safeStringify)(contextMap));
|
|
30713
30936
|
}
|
|
30714
|
-
rootSpan.setAttribute("agent.messages", (0,
|
|
30715
|
-
rootSpan.setAttribute("agent.messages.ui", (0,
|
|
30937
|
+
rootSpan.setAttribute("agent.messages", (0, import_utils34.safeStringify)(messages));
|
|
30938
|
+
rootSpan.setAttribute("agent.messages.ui", (0, import_utils34.safeStringify)(uiMessages));
|
|
30716
30939
|
const agentState = this.getFullState();
|
|
30717
|
-
rootSpan.setAttribute("agent.stateSnapshot", (0,
|
|
30940
|
+
rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils34.safeStringify)(agentState));
|
|
30718
30941
|
methodLogger.debug(
|
|
30719
30942
|
buildAgentLogMessage(
|
|
30720
30943
|
this.name,
|
|
@@ -30935,7 +31158,7 @@ var Agent = class {
|
|
|
30935
31158
|
operation: "generateText",
|
|
30936
31159
|
metadata: {
|
|
30937
31160
|
finishReason: result.finishReason,
|
|
30938
|
-
usage: usageForFinish ? JSON.parse((0,
|
|
31161
|
+
usage: usageForFinish ? JSON.parse((0, import_utils34.safeStringify)(usageForFinish)) : void 0,
|
|
30939
31162
|
toolCalls: aggregatedToolCalls
|
|
30940
31163
|
}
|
|
30941
31164
|
});
|
|
@@ -31002,7 +31225,7 @@ var Agent = class {
|
|
|
31002
31225
|
maxMiddlewareRetries,
|
|
31003
31226
|
middlewareId: retryError.middlewareId ?? null,
|
|
31004
31227
|
reason: retryError.message ?? "middleware retry",
|
|
31005
|
-
metadata: retryError.metadata !== void 0 ? (0,
|
|
31228
|
+
metadata: retryError.metadata !== void 0 ? (0, import_utils34.safeStringify)(retryError.metadata) : void 0
|
|
31006
31229
|
});
|
|
31007
31230
|
this.storeMiddlewareRetryFeedback(oc, retryError.message, retryError.metadata);
|
|
31008
31231
|
middlewareRetryCount += 1;
|
|
@@ -31183,7 +31406,7 @@ var Agent = class {
|
|
|
31183
31406
|
maxMiddlewareRetries,
|
|
31184
31407
|
middlewareId: retryError.middlewareId ?? null,
|
|
31185
31408
|
reason: retryError.message ?? "middleware retry",
|
|
31186
|
-
metadata: retryError.metadata !== void 0 ? (0,
|
|
31409
|
+
metadata: retryError.metadata !== void 0 ? (0, import_utils34.safeStringify)(retryError.metadata) : void 0
|
|
31187
31410
|
});
|
|
31188
31411
|
this.storeMiddlewareRetryFeedback(oc, retryError.message, retryError.metadata);
|
|
31189
31412
|
middlewareRetryCount += 1;
|
|
@@ -31217,12 +31440,12 @@ var Agent = class {
|
|
|
31217
31440
|
);
|
|
31218
31441
|
const contextMap = Object.fromEntries(oc.context.entries());
|
|
31219
31442
|
if (Object.keys(contextMap).length > 0) {
|
|
31220
|
-
rootSpan2.setAttribute("agent.context", (0,
|
|
31443
|
+
rootSpan2.setAttribute("agent.context", (0, import_utils34.safeStringify)(contextMap));
|
|
31221
31444
|
}
|
|
31222
|
-
rootSpan2.setAttribute("agent.messages", (0,
|
|
31223
|
-
rootSpan2.setAttribute("agent.messages.ui", (0,
|
|
31445
|
+
rootSpan2.setAttribute("agent.messages", (0, import_utils34.safeStringify)(messages));
|
|
31446
|
+
rootSpan2.setAttribute("agent.messages.ui", (0, import_utils34.safeStringify)(uiMessages));
|
|
31224
31447
|
const agentState = this.getFullState();
|
|
31225
|
-
rootSpan2.setAttribute("agent.stateSnapshot", (0,
|
|
31448
|
+
rootSpan2.setAttribute("agent.stateSnapshot", (0, import_utils34.safeStringify)(agentState));
|
|
31226
31449
|
}
|
|
31227
31450
|
methodLogger.debug(
|
|
31228
31451
|
buildAgentLogMessage(
|
|
@@ -31504,7 +31727,7 @@ var Agent = class {
|
|
|
31504
31727
|
operation: "streamText",
|
|
31505
31728
|
metadata: {
|
|
31506
31729
|
finishReason: finalResult.finishReason,
|
|
31507
|
-
usage: usageForFinish ? JSON.parse((0,
|
|
31730
|
+
usage: usageForFinish ? JSON.parse((0, import_utils34.safeStringify)(usageForFinish)) : void 0,
|
|
31508
31731
|
toolCalls: finalResult.toolCalls
|
|
31509
31732
|
}
|
|
31510
31733
|
});
|
|
@@ -31891,12 +32114,12 @@ var Agent = class {
|
|
|
31891
32114
|
);
|
|
31892
32115
|
const contextMap = Object.fromEntries(oc.context.entries());
|
|
31893
32116
|
if (Object.keys(contextMap).length > 0) {
|
|
31894
|
-
rootSpan.setAttribute("agent.context", (0,
|
|
32117
|
+
rootSpan.setAttribute("agent.context", (0, import_utils34.safeStringify)(contextMap));
|
|
31895
32118
|
}
|
|
31896
|
-
rootSpan.setAttribute("agent.messages", (0,
|
|
31897
|
-
rootSpan.setAttribute("agent.messages.ui", (0,
|
|
32119
|
+
rootSpan.setAttribute("agent.messages", (0, import_utils34.safeStringify)(messages));
|
|
32120
|
+
rootSpan.setAttribute("agent.messages.ui", (0, import_utils34.safeStringify)(uiMessages));
|
|
31898
32121
|
const agentState = this.getFullState();
|
|
31899
|
-
rootSpan.setAttribute("agent.stateSnapshot", (0,
|
|
32122
|
+
rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils34.safeStringify)(agentState));
|
|
31900
32123
|
methodLogger.debug(
|
|
31901
32124
|
buildAgentLogMessage(
|
|
31902
32125
|
this.name,
|
|
@@ -32005,7 +32228,7 @@ var Agent = class {
|
|
|
32005
32228
|
parts: [
|
|
32006
32229
|
{
|
|
32007
32230
|
type: "text",
|
|
32008
|
-
text: (0,
|
|
32231
|
+
text: (0, import_utils34.safeStringify)(finalObject)
|
|
32009
32232
|
}
|
|
32010
32233
|
]
|
|
32011
32234
|
};
|
|
@@ -32013,7 +32236,7 @@ var Agent = class {
|
|
|
32013
32236
|
const step = {
|
|
32014
32237
|
id: randomUUID(),
|
|
32015
32238
|
type: "text",
|
|
32016
|
-
content: (0,
|
|
32239
|
+
content: (0, import_utils34.safeStringify)(finalObject),
|
|
32017
32240
|
role: "assistant",
|
|
32018
32241
|
usage: usageInfo
|
|
32019
32242
|
};
|
|
@@ -32027,7 +32250,7 @@ var Agent = class {
|
|
|
32027
32250
|
operation: "generateObject",
|
|
32028
32251
|
metadata: {
|
|
32029
32252
|
finishReason: result.finishReason,
|
|
32030
|
-
usage: usageForFinish ? JSON.parse((0,
|
|
32253
|
+
usage: usageForFinish ? JSON.parse((0, import_utils34.safeStringify)(usageForFinish)) : void 0,
|
|
32031
32254
|
schemaName
|
|
32032
32255
|
}
|
|
32033
32256
|
});
|
|
@@ -32086,7 +32309,7 @@ var Agent = class {
|
|
|
32086
32309
|
maxMiddlewareRetries,
|
|
32087
32310
|
middlewareId: retryError.middlewareId ?? null,
|
|
32088
32311
|
reason: retryError.message ?? "middleware retry",
|
|
32089
|
-
metadata: retryError.metadata !== void 0 ? (0,
|
|
32312
|
+
metadata: retryError.metadata !== void 0 ? (0, import_utils34.safeStringify)(retryError.metadata) : void 0
|
|
32090
32313
|
});
|
|
32091
32314
|
this.storeMiddlewareRetryFeedback(oc, retryError.message, retryError.metadata);
|
|
32092
32315
|
middlewareRetryCount += 1;
|
|
@@ -32156,7 +32379,7 @@ var Agent = class {
|
|
|
32156
32379
|
maxMiddlewareRetries,
|
|
32157
32380
|
middlewareId: retryError.middlewareId ?? null,
|
|
32158
32381
|
reason: retryError.message ?? "middleware retry",
|
|
32159
|
-
metadata: retryError.metadata !== void 0 ? (0,
|
|
32382
|
+
metadata: retryError.metadata !== void 0 ? (0, import_utils34.safeStringify)(retryError.metadata) : void 0
|
|
32160
32383
|
});
|
|
32161
32384
|
this.storeMiddlewareRetryFeedback(oc, retryError.message, retryError.metadata);
|
|
32162
32385
|
middlewareRetryCount += 1;
|
|
@@ -32187,12 +32410,12 @@ var Agent = class {
|
|
|
32187
32410
|
);
|
|
32188
32411
|
const contextMap = Object.fromEntries(oc.context.entries());
|
|
32189
32412
|
if (Object.keys(contextMap).length > 0) {
|
|
32190
|
-
rootSpan.setAttribute("agent.context", (0,
|
|
32413
|
+
rootSpan.setAttribute("agent.context", (0, import_utils34.safeStringify)(contextMap));
|
|
32191
32414
|
}
|
|
32192
|
-
rootSpan.setAttribute("agent.messages", (0,
|
|
32193
|
-
rootSpan.setAttribute("agent.messages.ui", (0,
|
|
32415
|
+
rootSpan.setAttribute("agent.messages", (0, import_utils34.safeStringify)(messages));
|
|
32416
|
+
rootSpan.setAttribute("agent.messages.ui", (0, import_utils34.safeStringify)(uiMessages));
|
|
32194
32417
|
const agentState = this.getFullState();
|
|
32195
|
-
rootSpan.setAttribute("agent.stateSnapshot", (0,
|
|
32418
|
+
rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils34.safeStringify)(agentState));
|
|
32196
32419
|
methodLogger.debug(
|
|
32197
32420
|
buildAgentLogMessage(
|
|
32198
32421
|
this.name,
|
|
@@ -32355,7 +32578,7 @@ var Agent = class {
|
|
|
32355
32578
|
parts: [
|
|
32356
32579
|
{
|
|
32357
32580
|
type: "text",
|
|
32358
|
-
text: (0,
|
|
32581
|
+
text: (0, import_utils34.safeStringify)(finalObject)
|
|
32359
32582
|
}
|
|
32360
32583
|
]
|
|
32361
32584
|
};
|
|
@@ -32363,7 +32586,7 @@ var Agent = class {
|
|
|
32363
32586
|
const step = {
|
|
32364
32587
|
id: randomUUID(),
|
|
32365
32588
|
type: "text",
|
|
32366
|
-
content: (0,
|
|
32589
|
+
content: (0, import_utils34.safeStringify)(finalObject),
|
|
32367
32590
|
role: "assistant",
|
|
32368
32591
|
usage: usageInfo
|
|
32369
32592
|
};
|
|
@@ -32410,7 +32633,7 @@ var Agent = class {
|
|
|
32410
32633
|
operation: "streamObject",
|
|
32411
32634
|
metadata: {
|
|
32412
32635
|
finishReason: finalResult.finishReason,
|
|
32413
|
-
usage: usageForFinish ? JSON.parse((0,
|
|
32636
|
+
usage: usageForFinish ? JSON.parse((0, import_utils34.safeStringify)(usageForFinish)) : void 0,
|
|
32414
32637
|
schemaName
|
|
32415
32638
|
}
|
|
32416
32639
|
});
|
|
@@ -32529,7 +32752,7 @@ var Agent = class {
|
|
|
32529
32752
|
let feedback = `[Middleware Feedback] ${baseReason} Please retry with the feedback in mind.`;
|
|
32530
32753
|
if (metadata !== void 0) {
|
|
32531
32754
|
feedback = `${feedback}
|
|
32532
|
-
Metadata: ${(0,
|
|
32755
|
+
Metadata: ${(0, import_utils34.safeStringify)(metadata)}`;
|
|
32533
32756
|
}
|
|
32534
32757
|
oc.systemContext.set(MIDDLEWARE_RETRY_FEEDBACK_KEY, feedback);
|
|
32535
32758
|
}
|
|
@@ -32629,8 +32852,8 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
32629
32852
|
maxSteps,
|
|
32630
32853
|
configuredToolCount,
|
|
32631
32854
|
toolCallCount: toolCalls.length,
|
|
32632
|
-
usage: usageForFinish ? JSON.parse((0,
|
|
32633
|
-
providerMetadata: providerMetadata !== void 0 ? JSON.parse((0,
|
|
32855
|
+
usage: usageForFinish ? JSON.parse((0, import_utils34.safeStringify)(usageForFinish)) : void 0,
|
|
32856
|
+
providerMetadata: providerMetadata !== void 0 ? JSON.parse((0, import_utils34.safeStringify)(providerMetadata)) : void 0
|
|
32634
32857
|
}
|
|
32635
32858
|
}
|
|
32636
32859
|
);
|
|
@@ -32892,7 +33115,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
32892
33115
|
for (const responseMessage of responseMessages) {
|
|
32893
33116
|
const normalizedMessage = responseMessage.role === "assistant" ? { ...responseMessage, id: fallbackAssistantMessageId } : responseMessage;
|
|
32894
33117
|
const fingerprintMessageId = normalizedMessage.role === "assistant" ? fallbackAssistantMessageId : normalizedMessage.id ?? null;
|
|
32895
|
-
const fingerprint = (0,
|
|
33118
|
+
const fingerprint = (0, import_utils34.safeStringify)({
|
|
32896
33119
|
role: normalizedMessage.role,
|
|
32897
33120
|
id: fingerprintMessageId,
|
|
32898
33121
|
content: normalizedMessage.content
|
|
@@ -32967,7 +33190,14 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
32967
33190
|
}
|
|
32968
33191
|
createLLMSpan(oc, params) {
|
|
32969
33192
|
const { label, ...spanParams } = params;
|
|
32970
|
-
const
|
|
33193
|
+
const promptContextUsageEstimate = estimatePromptContextUsage({
|
|
33194
|
+
messages: params.messages,
|
|
33195
|
+
tools: params.tools
|
|
33196
|
+
});
|
|
33197
|
+
const attributes = {
|
|
33198
|
+
...this.buildLLMSpanAttributes(spanParams),
|
|
33199
|
+
...promptContextUsageEstimate ? promptContextUsageEstimateToAttributes(promptContextUsageEstimate) : {}
|
|
33200
|
+
};
|
|
32971
33201
|
const span = oc.traceContext.createChildSpan(`llm:${params.operation}`, "llm", {
|
|
32972
33202
|
kind: import_api16.SpanKind.CLIENT,
|
|
32973
33203
|
label,
|
|
@@ -33049,12 +33279,12 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
33049
33279
|
attrs["llm.top_p"] = topP;
|
|
33050
33280
|
}
|
|
33051
33281
|
if (callOptions.stop !== void 0) {
|
|
33052
|
-
attrs["llm.stop_condition"] = (0,
|
|
33282
|
+
attrs["llm.stop_condition"] = (0, import_utils34.safeStringify)(callOptions.stop);
|
|
33053
33283
|
}
|
|
33054
33284
|
if (params.messages && params.messages.length > 0) {
|
|
33055
33285
|
attrs["llm.messages.count"] = params.messages.length;
|
|
33056
33286
|
const trimmedMessages = params.messages.slice(-10);
|
|
33057
|
-
attrs["llm.messages"] = (0,
|
|
33287
|
+
attrs["llm.messages"] = (0, import_utils34.safeStringify)(
|
|
33058
33288
|
trimmedMessages.map((msg) => ({
|
|
33059
33289
|
role: msg.role,
|
|
33060
33290
|
content: msg.content
|
|
@@ -33069,7 +33299,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
33069
33299
|
}
|
|
33070
33300
|
}
|
|
33071
33301
|
if (params.providerOptions) {
|
|
33072
|
-
attrs["llm.provider_options"] = (0,
|
|
33302
|
+
attrs["llm.provider_options"] = (0, import_utils34.safeStringify)(params.providerOptions);
|
|
33073
33303
|
}
|
|
33074
33304
|
return attrs;
|
|
33075
33305
|
}
|
|
@@ -33081,7 +33311,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
33081
33311
|
if (!normalizedUsage) {
|
|
33082
33312
|
return;
|
|
33083
33313
|
}
|
|
33084
|
-
const { promptTokens, completionTokens, totalTokens } = normalizedUsage;
|
|
33314
|
+
const { promptTokens, completionTokens, totalTokens, cachedInputTokens, reasoningTokens } = normalizedUsage;
|
|
33085
33315
|
if (promptTokens !== void 0) {
|
|
33086
33316
|
span.setAttribute("llm.usage.prompt_tokens", promptTokens);
|
|
33087
33317
|
}
|
|
@@ -33091,6 +33321,12 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
33091
33321
|
if (totalTokens !== void 0) {
|
|
33092
33322
|
span.setAttribute("llm.usage.total_tokens", totalTokens);
|
|
33093
33323
|
}
|
|
33324
|
+
if (cachedInputTokens !== void 0 && cachedInputTokens > 0) {
|
|
33325
|
+
span.setAttribute("llm.usage.cached_tokens", cachedInputTokens);
|
|
33326
|
+
}
|
|
33327
|
+
if (reasoningTokens !== void 0 && reasoningTokens > 0) {
|
|
33328
|
+
span.setAttribute("llm.usage.reasoning_tokens", reasoningTokens);
|
|
33329
|
+
}
|
|
33094
33330
|
}
|
|
33095
33331
|
recordProviderCost(span, providerMetadata) {
|
|
33096
33332
|
const openRouterUsageCost = extractOpenRouterUsageCost(providerMetadata);
|
|
@@ -33336,7 +33572,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
33336
33572
|
}
|
|
33337
33573
|
} catch (error) {
|
|
33338
33574
|
context8.logger.debug("[Memory] Failed to generate conversation title", {
|
|
33339
|
-
error: (0,
|
|
33575
|
+
error: (0, import_utils34.safeStringify)(error)
|
|
33340
33576
|
});
|
|
33341
33577
|
return null;
|
|
33342
33578
|
}
|
|
@@ -33372,7 +33608,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
33372
33608
|
attributes: {
|
|
33373
33609
|
"memory.operation": "read",
|
|
33374
33610
|
"memory.semantic": isSemanticSearch,
|
|
33375
|
-
input: (0,
|
|
33611
|
+
input: (0, import_utils34.safeStringify)(spanInput),
|
|
33376
33612
|
...isSemanticSearch && {
|
|
33377
33613
|
"memory.semantic.limit": semanticLimit,
|
|
33378
33614
|
"memory.semantic.threshold": semanticThreshold,
|
|
@@ -33594,10 +33830,10 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
33594
33830
|
rootSpan.setAttribute("prompt.version", metadata.version);
|
|
33595
33831
|
}
|
|
33596
33832
|
if (metadata.labels && metadata.labels.length > 0) {
|
|
33597
|
-
rootSpan.setAttribute("prompt.labels", (0,
|
|
33833
|
+
rootSpan.setAttribute("prompt.labels", (0, import_utils34.safeStringify)(metadata.labels));
|
|
33598
33834
|
}
|
|
33599
33835
|
if (metadata.tags && metadata.tags.length > 0) {
|
|
33600
|
-
rootSpan.setAttribute("prompt.tags", (0,
|
|
33836
|
+
rootSpan.setAttribute("prompt.tags", (0, import_utils34.safeStringify)(metadata.tags));
|
|
33601
33837
|
}
|
|
33602
33838
|
if (metadata.source) {
|
|
33603
33839
|
rootSpan.setAttribute("prompt.source", metadata.source);
|
|
@@ -33609,7 +33845,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
33609
33845
|
rootSpan.setAttribute("prompt.outdated", metadata.outdated);
|
|
33610
33846
|
}
|
|
33611
33847
|
if (metadata.config) {
|
|
33612
|
-
rootSpan.setAttribute("prompt.config", (0,
|
|
33848
|
+
rootSpan.setAttribute("prompt.config", (0, import_utils34.safeStringify)(metadata.config));
|
|
33613
33849
|
}
|
|
33614
33850
|
}
|
|
33615
33851
|
}
|
|
@@ -33810,7 +34046,7 @@ ${retrieverContext}`;
|
|
|
33810
34046
|
label: this.retriever.tool.name || "Retriever",
|
|
33811
34047
|
attributes: {
|
|
33812
34048
|
"retriever.name": this.retriever.tool.name || "Retriever",
|
|
33813
|
-
input: typeof input === "string" ? input : (0,
|
|
34049
|
+
input: typeof input === "string" ? input : (0, import_utils34.safeStringify)(input),
|
|
33814
34050
|
...this.getRetrieverObservabilityAttributes()
|
|
33815
34051
|
}
|
|
33816
34052
|
});
|
|
@@ -34057,7 +34293,7 @@ ${retrieverContext}`;
|
|
|
34057
34293
|
nextModelIndex: nextCandidate ? index + 1 : void 0
|
|
34058
34294
|
});
|
|
34059
34295
|
logger.warn(`[Agent:${this.name}] - Failed to resolve model, falling back`, {
|
|
34060
|
-
error: (0,
|
|
34296
|
+
error: (0, import_utils34.safeStringify)(error),
|
|
34061
34297
|
modelIndex: index,
|
|
34062
34298
|
operation
|
|
34063
34299
|
});
|
|
@@ -34102,7 +34338,7 @@ ${retrieverContext}`;
|
|
|
34102
34338
|
retryEligible,
|
|
34103
34339
|
isRetryable: error?.isRetryable,
|
|
34104
34340
|
statusCode: error?.statusCode,
|
|
34105
|
-
error: (0,
|
|
34341
|
+
error: (0, import_utils34.safeStringify)(error)
|
|
34106
34342
|
});
|
|
34107
34343
|
await hooks.onRetry?.({
|
|
34108
34344
|
agent: this,
|
|
@@ -34134,7 +34370,7 @@ ${retrieverContext}`;
|
|
|
34134
34370
|
fallbackEligible,
|
|
34135
34371
|
retryEligible,
|
|
34136
34372
|
isLastModel,
|
|
34137
|
-
error: (0,
|
|
34373
|
+
error: (0, import_utils34.safeStringify)(error)
|
|
34138
34374
|
});
|
|
34139
34375
|
throw error;
|
|
34140
34376
|
}
|
|
@@ -34154,7 +34390,7 @@ ${retrieverContext}`;
|
|
|
34154
34390
|
nextModelIndex: nextCandidate ? index + 1 : void 0
|
|
34155
34391
|
});
|
|
34156
34392
|
logger.warn(`[Agent:${this.name}] - Model failed, trying fallback`, {
|
|
34157
|
-
error: (0,
|
|
34393
|
+
error: (0, import_utils34.safeStringify)(error),
|
|
34158
34394
|
modelName,
|
|
34159
34395
|
modelIndex: index,
|
|
34160
34396
|
operation,
|
|
@@ -34374,9 +34610,9 @@ ${retrieverContext}`;
|
|
|
34374
34610
|
"tool.name": tool2.name,
|
|
34375
34611
|
"tool.call.id": toolCallId,
|
|
34376
34612
|
"tool.description": tool2.description,
|
|
34377
|
-
...toolTags && toolTags.length > 0 ? { "tool.tags": (0,
|
|
34378
|
-
"tool.parameters": (0,
|
|
34379
|
-
input: args ? (0,
|
|
34613
|
+
...toolTags && toolTags.length > 0 ? { "tool.tags": (0, import_utils34.safeStringify)(toolTags) } : {},
|
|
34614
|
+
"tool.parameters": (0, import_utils34.safeStringify)(tool2.parameters),
|
|
34615
|
+
input: args ? (0, import_utils34.safeStringify)(args) : void 0
|
|
34380
34616
|
},
|
|
34381
34617
|
kind: import_api16.SpanKind.CLIENT
|
|
34382
34618
|
});
|
|
@@ -34817,7 +35053,7 @@ ${retrieverContext}`;
|
|
|
34817
35053
|
output: selections,
|
|
34818
35054
|
attributes: {
|
|
34819
35055
|
"tool.search.selection.count": selections.length,
|
|
34820
|
-
"tool.search.selection.names": (0,
|
|
35056
|
+
"tool.search.selection.names": (0, import_utils34.safeStringify)(
|
|
34821
35057
|
selections.map((selection) => selection.name)
|
|
34822
35058
|
)
|
|
34823
35059
|
}
|
|
@@ -34825,7 +35061,7 @@ ${retrieverContext}`;
|
|
|
34825
35061
|
oc.logger.debug("Tool search selections computed", {
|
|
34826
35062
|
tool: TOOL_ROUTING_SEARCH_TOOL_NAME,
|
|
34827
35063
|
query,
|
|
34828
|
-
selections: (0,
|
|
35064
|
+
selections: (0, import_utils34.safeStringify)(selections)
|
|
34829
35065
|
});
|
|
34830
35066
|
} catch (error) {
|
|
34831
35067
|
oc.traceContext.endChildSpan(selectionSpan, "error", {
|
|
@@ -34971,7 +35207,7 @@ ${retrieverContext}`;
|
|
|
34971
35207
|
const tools = {
|
|
34972
35208
|
[tool2.name]: tool2
|
|
34973
35209
|
};
|
|
34974
|
-
const argsInstruction = `Use these tool arguments exactly: ${(0,
|
|
35210
|
+
const argsInstruction = `Use these tool arguments exactly: ${(0, import_utils34.safeStringify)(args)}`;
|
|
34975
35211
|
const result = await this.runInternalGenerateText({
|
|
34976
35212
|
oc,
|
|
34977
35213
|
messages: [
|
|
@@ -35316,7 +35552,7 @@ ${retrieverContext}`;
|
|
|
35316
35552
|
oc.conversationSteps?.push({
|
|
35317
35553
|
id: toolCall.toolCallId || randomUUID(),
|
|
35318
35554
|
type: "tool_call",
|
|
35319
|
-
content: (0,
|
|
35555
|
+
content: (0, import_utils34.safeStringify)(toolCall.input ?? {}),
|
|
35320
35556
|
role: "assistant",
|
|
35321
35557
|
name: toolCall.toolName,
|
|
35322
35558
|
arguments: toolCall.input || {},
|
|
@@ -35348,7 +35584,7 @@ ${retrieverContext}`;
|
|
|
35348
35584
|
oc.conversationSteps?.push({
|
|
35349
35585
|
id: toolResult.toolCallId || randomUUID(),
|
|
35350
35586
|
type: "tool_result",
|
|
35351
|
-
content: (0,
|
|
35587
|
+
content: (0, import_utils34.safeStringify)(toolResult.output),
|
|
35352
35588
|
role: "assistant",
|
|
35353
35589
|
name: toolResult.toolName,
|
|
35354
35590
|
result: toolResult.output,
|
|
@@ -36230,7 +36466,7 @@ ${retrieverContext}`;
|
|
|
36230
36466
|
};
|
|
36231
36467
|
|
|
36232
36468
|
// src/planagent/plan-agent.ts
|
|
36233
|
-
var
|
|
36469
|
+
var import_utils39 = require("@voltagent/internal/utils");
|
|
36234
36470
|
var import_zod10 = require("zod");
|
|
36235
36471
|
|
|
36236
36472
|
// src/planagent/context-keys.ts
|
|
@@ -36242,7 +36478,7 @@ var import_internal11 = require("@voltagent/internal");
|
|
|
36242
36478
|
var import_zod8 = require("zod");
|
|
36243
36479
|
|
|
36244
36480
|
// src/planagent/state.ts
|
|
36245
|
-
var
|
|
36481
|
+
var import_utils36 = require("@voltagent/internal/utils");
|
|
36246
36482
|
var PLANAGENT_METADATA_KEY = "planagent";
|
|
36247
36483
|
var STATE_CACHE_KEY = Symbol("planagentState");
|
|
36248
36484
|
var fallbackState = /* @__PURE__ */ new Map();
|
|
@@ -36254,13 +36490,13 @@ function readStateFromMetadata(metadata) {
|
|
|
36254
36490
|
if (!metadata) return null;
|
|
36255
36491
|
const entry = metadata[PLANAGENT_METADATA_KEY];
|
|
36256
36492
|
if (!entry || typeof entry !== "object") return null;
|
|
36257
|
-
return (0,
|
|
36493
|
+
return (0, import_utils36.deepClone)(entry);
|
|
36258
36494
|
}
|
|
36259
36495
|
__name(readStateFromMetadata, "readStateFromMetadata");
|
|
36260
36496
|
async function loadPlanAgentState(agent, context8) {
|
|
36261
36497
|
const cached = context8.systemContext.get(STATE_CACHE_KEY);
|
|
36262
36498
|
if (cached) {
|
|
36263
|
-
return (0,
|
|
36499
|
+
return (0, import_utils36.deepClone)(cached);
|
|
36264
36500
|
}
|
|
36265
36501
|
let state = null;
|
|
36266
36502
|
const memory = agent.getMemory();
|
|
@@ -36270,23 +36506,23 @@ async function loadPlanAgentState(agent, context8) {
|
|
|
36270
36506
|
state = readStateFromMetadata(conversation?.metadata);
|
|
36271
36507
|
} catch (error) {
|
|
36272
36508
|
context8.logger.debug("[PlanAgent] Failed to load state from memory", {
|
|
36273
|
-
error: (0,
|
|
36509
|
+
error: (0, import_utils36.safeStringify)(error)
|
|
36274
36510
|
});
|
|
36275
36511
|
}
|
|
36276
36512
|
}
|
|
36277
36513
|
if (!state) {
|
|
36278
|
-
state = (0,
|
|
36514
|
+
state = (0, import_utils36.deepClone)(fallbackState.get(getConversationKey(context8)) || {});
|
|
36279
36515
|
}
|
|
36280
36516
|
context8.systemContext.set(STATE_CACHE_KEY, state);
|
|
36281
|
-
return (0,
|
|
36517
|
+
return (0, import_utils36.deepClone)(state);
|
|
36282
36518
|
}
|
|
36283
36519
|
__name(loadPlanAgentState, "loadPlanAgentState");
|
|
36284
36520
|
async function updatePlanAgentState(agent, context8, updater) {
|
|
36285
36521
|
const current = await loadPlanAgentState(agent, context8);
|
|
36286
|
-
const nextState = updater((0,
|
|
36522
|
+
const nextState = updater((0, import_utils36.deepClone)(current));
|
|
36287
36523
|
const normalized = nextState || {};
|
|
36288
36524
|
context8.systemContext.set(STATE_CACHE_KEY, normalized);
|
|
36289
|
-
fallbackState.set(getConversationKey(context8), (0,
|
|
36525
|
+
fallbackState.set(getConversationKey(context8), (0, import_utils36.deepClone)(normalized));
|
|
36290
36526
|
const memory = agent.getMemory();
|
|
36291
36527
|
if (memory && context8.conversationId) {
|
|
36292
36528
|
try {
|
|
@@ -36294,17 +36530,17 @@ async function updatePlanAgentState(agent, context8, updater) {
|
|
|
36294
36530
|
if (conversation) {
|
|
36295
36531
|
const metadata = {
|
|
36296
36532
|
...conversation.metadata,
|
|
36297
|
-
[PLANAGENT_METADATA_KEY]: (0,
|
|
36533
|
+
[PLANAGENT_METADATA_KEY]: (0, import_utils36.deepClone)(normalized)
|
|
36298
36534
|
};
|
|
36299
36535
|
await memory.updateConversation(context8.conversationId, { metadata });
|
|
36300
36536
|
}
|
|
36301
36537
|
} catch (error) {
|
|
36302
36538
|
context8.logger.debug("[PlanAgent] Failed to persist state", {
|
|
36303
|
-
error: (0,
|
|
36539
|
+
error: (0, import_utils36.safeStringify)(error)
|
|
36304
36540
|
});
|
|
36305
36541
|
}
|
|
36306
36542
|
}
|
|
36307
|
-
return (0,
|
|
36543
|
+
return (0, import_utils36.deepClone)(normalized);
|
|
36308
36544
|
}
|
|
36309
36545
|
__name(updatePlanAgentState, "updatePlanAgentState");
|
|
36310
36546
|
|
|
@@ -36714,7 +36950,7 @@ function createToolResultEvictor(options) {
|
|
|
36714
36950
|
__name(createToolResultEvictor, "createToolResultEvictor");
|
|
36715
36951
|
|
|
36716
36952
|
// src/planagent/planning/index.ts
|
|
36717
|
-
var
|
|
36953
|
+
var import_utils38 = require("@voltagent/internal/utils");
|
|
36718
36954
|
var import_zod9 = require("zod");
|
|
36719
36955
|
|
|
36720
36956
|
// src/planagent/planning/backend.ts
|
|
@@ -36858,7 +37094,7 @@ function createPlanningToolkit(agent, options = {}) {
|
|
|
36858
37094
|
toolSpan.setAttribute("planagent.todos.done", doneCount);
|
|
36859
37095
|
toolSpan.setAttribute("planagent.todos.truncated", snapshot.truncated);
|
|
36860
37096
|
toolSpan.setAttribute("planagent.todos.blocked_done", blockedCount);
|
|
36861
|
-
toolSpan.setAttribute("planagent.todos", (0,
|
|
37097
|
+
toolSpan.setAttribute("planagent.todos", (0, import_utils38.safeStringify)(snapshot.todos));
|
|
36862
37098
|
}
|
|
36863
37099
|
return {
|
|
36864
37100
|
todos: guardedTodos,
|
|
@@ -37434,7 +37670,7 @@ function createTaskToolkit(options) {
|
|
|
37434
37670
|
parentSpan: toolSpan
|
|
37435
37671
|
});
|
|
37436
37672
|
if (toolSpan) {
|
|
37437
|
-
const responsePreview = typeof result.result === "string" ? truncateText3(result.result, 500) : truncateText3((0,
|
|
37673
|
+
const responsePreview = typeof result.result === "string" ? truncateText3(result.result, 500) : truncateText3((0, import_utils39.safeStringify)(result.result), 500);
|
|
37438
37674
|
toolSpan.setAttribute("planagent.task.status", result.bailed ? "bailed" : "completed");
|
|
37439
37675
|
toolSpan.setAttribute("planagent.task.response_preview", responsePreview);
|
|
37440
37676
|
}
|
|
@@ -41167,7 +41403,7 @@ var import_node_crypto = __toESM(require("crypto"));
|
|
|
41167
41403
|
var import_node_fs3 = __toESM(require("fs"));
|
|
41168
41404
|
var import_node_os = __toESM(require("os"));
|
|
41169
41405
|
var import_node_path3 = __toESM(require("path"));
|
|
41170
|
-
var
|
|
41406
|
+
var import_utils40 = require("@voltagent/internal/utils");
|
|
41171
41407
|
var getEnvPaths = /* @__PURE__ */ __name((name) => {
|
|
41172
41408
|
const homedir = import_node_os.default.homedir();
|
|
41173
41409
|
const tmpdir = import_node_os.default.tmpdir();
|
|
@@ -41237,7 +41473,7 @@ var writeUpdateCache = /* @__PURE__ */ __name(async (projectPath, cache) => {
|
|
|
41237
41473
|
try {
|
|
41238
41474
|
ensureCacheDir();
|
|
41239
41475
|
const cacheFilePath = getCacheFilePath(projectPath);
|
|
41240
|
-
import_node_fs3.default.writeFileSync(cacheFilePath, (0,
|
|
41476
|
+
import_node_fs3.default.writeFileSync(cacheFilePath, (0, import_utils40.safeStringify)(cache, { indentation: 2 }), "utf8");
|
|
41241
41477
|
} catch (error) {
|
|
41242
41478
|
const logger = new LoggerProxy({ component: "update-cache" });
|
|
41243
41479
|
logger.error("Error writing update cache", { error });
|
|
@@ -42292,7 +42528,7 @@ var VoltAgent = class {
|
|
|
42292
42528
|
};
|
|
42293
42529
|
|
|
42294
42530
|
// src/index.ts
|
|
42295
|
-
var
|
|
42531
|
+
var import_utils41 = require("@voltagent/internal/utils");
|
|
42296
42532
|
var import_ai9 = require("ai");
|
|
42297
42533
|
// Annotate the CommonJS export names for ESM import in node:
|
|
42298
42534
|
0 && (module.exports = {
|