@voltagent/core 2.6.12 → 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 CHANGED
@@ -26533,6 +26533,7 @@ var BINARY_PART_TYPES = /* @__PURE__ */ new Set([
26533
26533
  "media"
26534
26534
  ]);
26535
26535
  var LARGE_BINARY_KEYS = /* @__PURE__ */ new Set(["audio", "base64", "bytes", "data", "image"]);
26536
+ var CIRCULAR_REFERENCE_PLACEHOLDER = "[circular]";
26536
26537
  function estimatePromptContextUsage(params) {
26537
26538
  let systemTokensEstimated = 0;
26538
26539
  let messageTokensEstimated = 0;
@@ -26600,7 +26601,7 @@ function serializePromptMessage(message) {
26600
26601
  ${content}`;
26601
26602
  }
26602
26603
  __name(serializePromptMessage, "serializePromptMessage");
26603
- function serializePromptValue(value) {
26604
+ function serializePromptValue(value, seen = /* @__PURE__ */ new Set()) {
26604
26605
  if (typeof value === "string") {
26605
26606
  return value;
26606
26607
  }
@@ -26608,46 +26609,71 @@ function serializePromptValue(value) {
26608
26609
  return String(value);
26609
26610
  }
26610
26611
  if (Array.isArray(value)) {
26611
- return value.map((entry) => serializePromptValue(entry)).filter((entry) => entry.trim().length > 0).join("\n");
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
+ }
26612
26621
  }
26613
26622
  if (!value || typeof value !== "object") {
26614
26623
  return "";
26615
26624
  }
26616
26625
  const record = value;
26617
- const type = typeof record.type === "string" ? record.type : void 0;
26618
- if (typeof record.text === "string") {
26619
- return record.text;
26626
+ if (seen.has(record)) {
26627
+ return CIRCULAR_REFERENCE_PLACEHOLDER;
26620
26628
  }
26621
- if (type && BINARY_PART_TYPES.has(type)) {
26622
- return `[${type}]`;
26623
- }
26624
- if (type === "tool-call") {
26625
- const toolName = typeof record.toolName === "string" ? record.toolName : "tool";
26626
- const input = serializePromptValue(record.input);
26627
- return input ? `tool-call ${toolName}: ${input}` : `tool-call ${toolName}`;
26628
- }
26629
- if (type === "tool-result") {
26630
- const toolName = typeof record.toolName === "string" ? record.toolName : "tool";
26631
- const output = serializePromptValue(record.output);
26632
- return output ? `tool-result ${toolName}: ${output}` : `tool-result ${toolName}`;
26633
- }
26634
- if ("content" in record) {
26635
- const nestedContent = serializePromptValue(record.content);
26636
- if (nestedContent) {
26637
- return nestedContent;
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}`;
26638
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);
26639
26657
  }
26640
- return (0, import_utils29.safeStringify)(sanitizeRecord(record));
26641
26658
  }
26642
26659
  __name(serializePromptValue, "serializePromptValue");
26643
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);
26644
26669
  const sanitized = {};
26645
26670
  for (const [key, value] of Object.entries(record)) {
26646
- sanitized[key] = LARGE_BINARY_KEYS.has(key) ? "[omitted]" : value;
26671
+ sanitized[key] = LARGE_BINARY_KEYS.has(key) ? "[omitted]" : sanitizeValue(value, seen);
26647
26672
  }
26673
+ seen.delete(record);
26648
26674
  return sanitized;
26649
26675
  }
26650
- __name(sanitizeRecord, "sanitizeRecord");
26676
+ __name(sanitizeRecordValue, "sanitizeRecordValue");
26651
26677
  function serializeToolDefinition(name, tool2) {
26652
26678
  if (!tool2 || typeof tool2 !== "object") {
26653
26679
  return { name };
@@ -26666,9 +26692,7 @@ function serializeToolDefinition(name, tool2) {
26666
26692
  ...candidate.outputSchema || candidate.output_schema ? {
26667
26693
  outputSchema: normalizeSchema(candidate.outputSchema ?? candidate.output_schema)
26668
26694
  } : {},
26669
- ...candidate.providerOptions ? { providerOptions: candidate.providerOptions } : {},
26670
- ...candidate.args ? { args: sanitizeRecord(candidate.args) } : {},
26671
- ...candidate.needsApproval !== void 0 ? { needsApproval: candidate.needsApproval } : {}
26695
+ ...isPlainObject(candidate.args) ? { args: sanitizeRecord(candidate.args) } : {}
26672
26696
  };
26673
26697
  }
26674
26698
  __name(serializeToolDefinition, "serializeToolDefinition");
@@ -26686,6 +26710,39 @@ function normalizeSchema(schema) {
26686
26710
  return schema;
26687
26711
  }
26688
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");
26689
26746
 
26690
26747
  // src/agent/tool-input-coercion.ts
26691
26748
  var isPathSegment = /* @__PURE__ */ __name((value) => typeof value === "string" || typeof value === "number", "isPathSegment");
@@ -30335,7 +30392,7 @@ var DEFAULT_CONVERSATION_PERSISTENCE_OPTIONS = {
30335
30392
  flushOnToolResult: true
30336
30393
  };
30337
30394
  var isRecord4 = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null, "isRecord");
30338
- var isPlainObject = /* @__PURE__ */ __name((value) => isRecord4(value) && !Array.isArray(value), "isPlainObject");
30395
+ var isPlainObject2 = /* @__PURE__ */ __name((value) => isRecord4(value) && !Array.isArray(value), "isPlainObject");
30339
30396
  var hasNonEmptyString2 = /* @__PURE__ */ __name((value) => typeof value === "string" && value.trim().length > 0, "hasNonEmptyString");
30340
30397
  var firstNonBlank = /* @__PURE__ */ __name((...values) => {
30341
30398
  for (const value of values) {
@@ -30375,17 +30432,17 @@ var toBoolean = /* @__PURE__ */ __name((value) => {
30375
30432
  return void 0;
30376
30433
  }, "toBoolean");
30377
30434
  var extractOpenRouterUsageCost = /* @__PURE__ */ __name((providerMetadata) => {
30378
- if (!isPlainObject(providerMetadata)) {
30435
+ if (!isPlainObject2(providerMetadata)) {
30379
30436
  return void 0;
30380
30437
  }
30381
- const openRouterMetadata = isPlainObject(providerMetadata.openrouter) ? providerMetadata.openrouter : void 0;
30382
- const usage = openRouterMetadata && isPlainObject(openRouterMetadata.usage) ? openRouterMetadata.usage : void 0;
30438
+ const openRouterMetadata = isPlainObject2(providerMetadata.openrouter) ? providerMetadata.openrouter : void 0;
30439
+ const usage = openRouterMetadata && isPlainObject2(openRouterMetadata.usage) ? openRouterMetadata.usage : void 0;
30383
30440
  if (!usage) {
30384
30441
  return void 0;
30385
30442
  }
30386
30443
  const costDetails = firstDefined(
30387
- isPlainObject(usage.costDetails) ? usage.costDetails : void 0,
30388
- isPlainObject(usage.cost_details) ? usage.cost_details : void 0
30444
+ isPlainObject2(usage.costDetails) ? usage.costDetails : void 0,
30445
+ isPlainObject2(usage.cost_details) ? usage.cost_details : void 0
30389
30446
  );
30390
30447
  const result = {
30391
30448
  cost: toFiniteNumber(usage.cost),
@@ -30405,9 +30462,9 @@ var extractOpenRouterUsageCost = /* @__PURE__ */ __name((providerMetadata) => {
30405
30462
  };
30406
30463
  return Object.values(result).some((value) => value !== void 0) ? result : void 0;
30407
30464
  }, "extractOpenRouterUsageCost");
30408
- var toLanguageModelUsage = /* @__PURE__ */ __name((value) => isPlainObject(value) ? value : void 0, "toLanguageModelUsage");
30465
+ var toLanguageModelUsage = /* @__PURE__ */ __name((value) => isPlainObject2(value) ? value : void 0, "toLanguageModelUsage");
30409
30466
  var extractGenerationErrorDetails = /* @__PURE__ */ __name((error) => {
30410
- const metadata = isRecord4(error) && isPlainObject(error.metadata) ? error.metadata : void 0;
30467
+ const metadata = isRecord4(error) && isPlainObject2(error.metadata) ? error.metadata : void 0;
30411
30468
  const originalError = isRecord4(error) ? error.originalError : void 0;
30412
30469
  const usage = firstDefined(
30413
30470
  isRecord4(error) ? toLanguageModelUsage(error.usage) : void 0,
@@ -33264,10 +33321,10 @@ Metadata: ${(0, import_utils34.safeStringify)(metadata)}`;
33264
33321
  if (totalTokens !== void 0) {
33265
33322
  span.setAttribute("llm.usage.total_tokens", totalTokens);
33266
33323
  }
33267
- if (cachedInputTokens !== void 0) {
33324
+ if (cachedInputTokens !== void 0 && cachedInputTokens > 0) {
33268
33325
  span.setAttribute("llm.usage.cached_tokens", cachedInputTokens);
33269
33326
  }
33270
- if (reasoningTokens !== void 0) {
33327
+ if (reasoningTokens !== void 0 && reasoningTokens > 0) {
33271
33328
  span.setAttribute("llm.usage.reasoning_tokens", reasoningTokens);
33272
33329
  }
33273
33330
  }