@voltagent/core 1.2.13 → 1.2.15

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
@@ -253,7 +253,7 @@ __export(index_exports, {
253
253
  context: () => import_api8.context,
254
254
  convertUsage: () => convertUsage,
255
255
  cosineSimilarity: () => cosineSimilarity,
256
- createAsyncIterableStream: () => import_utils19.createAsyncIterableStream,
256
+ createAsyncIterableStream: () => import_utils20.createAsyncIterableStream,
257
257
  createDefaultInputSafetyGuardrails: () => createDefaultInputSafetyGuardrails,
258
258
  createDefaultPIIGuardrails: () => createDefaultPIIGuardrails,
259
259
  createDefaultSafetyGuardrails: () => createDefaultSafetyGuardrails,
@@ -7370,7 +7370,7 @@ __name(createWorkflowChain, "createWorkflowChain");
7370
7370
 
7371
7371
  // src/agent/agent.ts
7372
7372
  var import_api15 = require("@opentelemetry/api");
7373
- var import_utils17 = require("@voltagent/internal/utils");
7373
+ var import_utils18 = require("@voltagent/internal/utils");
7374
7374
  var import_ai4 = require("ai");
7375
7375
  var import_zod3 = require("zod");
7376
7376
 
@@ -11072,6 +11072,70 @@ var createVoltOpsClient = /* @__PURE__ */ __name((options) => {
11072
11072
  return new VoltOpsClient(options);
11073
11073
  }, "createVoltOpsClient");
11074
11074
 
11075
+ // src/agent/error-utils.ts
11076
+ var import_utils11 = require("@voltagent/internal/utils");
11077
+ function buildToolErrorResult(error, toolCallId, toolName) {
11078
+ const errorResult = {
11079
+ error: true,
11080
+ name: error.name,
11081
+ message: error.message,
11082
+ stack: error.stack,
11083
+ toolCallId,
11084
+ toolName
11085
+ };
11086
+ const cause = error.cause;
11087
+ if (cause !== void 0) {
11088
+ errorResult.cause = cause instanceof Error ? {
11089
+ name: cause.name,
11090
+ message: cause.message,
11091
+ stack: cause.stack
11092
+ } : sanitizeErrorValue(cause);
11093
+ }
11094
+ for (const key of Object.getOwnPropertyNames(error)) {
11095
+ if (["name", "message", "stack", "cause", "error"].includes(key)) {
11096
+ continue;
11097
+ }
11098
+ const value = error[key];
11099
+ if (value === void 0 || typeof value === "function") {
11100
+ continue;
11101
+ }
11102
+ errorResult[key] = sanitizeErrorValue(value);
11103
+ }
11104
+ return errorResult;
11105
+ }
11106
+ __name(buildToolErrorResult, "buildToolErrorResult");
11107
+ function sanitizeErrorValue(value) {
11108
+ if (value === null || value === void 0) {
11109
+ return value;
11110
+ }
11111
+ const type = typeof value;
11112
+ if (type === "string" || type === "number" || type === "boolean") {
11113
+ return value;
11114
+ }
11115
+ if (Array.isArray(value)) {
11116
+ return value.map((item) => sanitizeErrorValue(item));
11117
+ }
11118
+ if (value instanceof Error) {
11119
+ return {
11120
+ name: value.name,
11121
+ message: value.message,
11122
+ stack: value.stack
11123
+ };
11124
+ }
11125
+ if (value instanceof Date) {
11126
+ return value.toISOString();
11127
+ }
11128
+ if (value instanceof Map || value instanceof Set) {
11129
+ return (0, import_utils11.safeStringify)(value);
11130
+ }
11131
+ try {
11132
+ return (0, import_utils11.safeStringify)(value);
11133
+ } catch {
11134
+ return String(value);
11135
+ }
11136
+ }
11137
+ __name(sanitizeErrorValue, "sanitizeErrorValue");
11138
+
11075
11139
  // src/agent/errors/client-http-errors.ts
11076
11140
  var ClientHTTPError = class extends Error {
11077
11141
  constructor(name, httpStatus, code, message) {
@@ -11206,10 +11270,10 @@ var VoltAgentError = class extends Error {
11206
11270
 
11207
11271
  // src/agent/eval.ts
11208
11272
  var import_api10 = require("@opentelemetry/api");
11209
- var import_utils13 = require("@voltagent/internal/utils");
11273
+ var import_utils14 = require("@voltagent/internal/utils");
11210
11274
 
11211
11275
  // src/eval/runtime/runtime.ts
11212
- var import_utils11 = require("@voltagent/internal/utils");
11276
+ var import_utils12 = require("@voltagent/internal/utils");
11213
11277
  var RUNTIME_METADATA_KEY = "__runtime";
11214
11278
  async function runLocalScorers(args) {
11215
11279
  const { payload, scorers, defaultSampling, baseArgs } = args;
@@ -11427,7 +11491,7 @@ function cloneRecord(value) {
11427
11491
  return void 0;
11428
11492
  }
11429
11493
  try {
11430
- return JSON.parse((0, import_utils11.safeStringify)(value));
11494
+ return JSON.parse((0, import_utils12.safeStringify)(value));
11431
11495
  } catch {
11432
11496
  return { ...value };
11433
11497
  }
@@ -11445,7 +11509,7 @@ function parseStatus(value) {
11445
11509
  __name(parseStatus, "parseStatus");
11446
11510
 
11447
11511
  // src/eval/create-scorer.ts
11448
- var import_utils12 = require("@voltagent/internal/utils");
11512
+ var import_utils13 = require("@voltagent/internal/utils");
11449
11513
  function createScorer(options) {
11450
11514
  const {
11451
11515
  id,
@@ -11560,7 +11624,7 @@ function cloneMetadata(value) {
11560
11624
  return null;
11561
11625
  }
11562
11626
  try {
11563
- return JSON.parse((0, import_utils12.safeStringify)(value));
11627
+ return JSON.parse((0, import_utils13.safeStringify)(value));
11564
11628
  } catch {
11565
11629
  return { ...value };
11566
11630
  }
@@ -11575,7 +11639,7 @@ function getErrorMetadata(error) {
11575
11639
  return null;
11576
11640
  }
11577
11641
  try {
11578
- return JSON.parse((0, import_utils12.safeStringify)(metadata));
11642
+ return JSON.parse((0, import_utils13.safeStringify)(metadata));
11579
11643
  } catch {
11580
11644
  return { ...metadata };
11581
11645
  }
@@ -12064,7 +12128,7 @@ function finalizeScorerSpan(span, host, descriptor, config, storagePayload, metr
12064
12128
  span.setAttributes(attributes);
12065
12129
  if (metrics.combinedMetadata && Object.keys(metrics.combinedMetadata).length > 0) {
12066
12130
  try {
12067
- span.setAttribute("eval.scorer.metadata", (0, import_utils13.safeStringify)(metrics.combinedMetadata));
12131
+ span.setAttribute("eval.scorer.metadata", (0, import_utils14.safeStringify)(metrics.combinedMetadata));
12068
12132
  } catch {
12069
12133
  span.setAttribute("eval.scorer.metadata", "[unserializable]");
12070
12134
  }
@@ -12423,7 +12487,7 @@ function ensureScorerText(value) {
12423
12487
  }
12424
12488
  if (typeof value === "object") {
12425
12489
  try {
12426
- return (0, import_utils13.safeStringify)(value);
12490
+ return (0, import_utils14.safeStringify)(value);
12427
12491
  } catch {
12428
12492
  return String(value);
12429
12493
  }
@@ -12459,11 +12523,11 @@ function normalizeEvalString(value) {
12459
12523
  if (typeof value === "string") {
12460
12524
  return value;
12461
12525
  }
12462
- return (0, import_utils13.safeStringify)(value);
12526
+ return (0, import_utils14.safeStringify)(value);
12463
12527
  }
12464
12528
  __name(normalizeEvalString, "normalizeEvalString");
12465
12529
  function cloneEvalPayload(payload) {
12466
- return JSON.parse((0, import_utils13.safeStringify)(payload));
12530
+ return JSON.parse((0, import_utils14.safeStringify)(payload));
12467
12531
  }
12468
12532
  __name(cloneEvalPayload, "cloneEvalPayload");
12469
12533
  function combineEvalMetadata(payload, scorerMetadata) {
@@ -12702,7 +12766,7 @@ function extractErrorMessage(error) {
12702
12766
  return error;
12703
12767
  }
12704
12768
  try {
12705
- return (0, import_utils13.safeStringify)(error);
12769
+ return (0, import_utils14.safeStringify)(error);
12706
12770
  } catch {
12707
12771
  return String(error);
12708
12772
  }
@@ -13477,7 +13541,7 @@ var ConversationBuffer = class {
13477
13541
 
13478
13542
  // src/agent/guardrail.ts
13479
13543
  var import_api12 = require("@opentelemetry/api");
13480
- var import_utils14 = require("@voltagent/internal/utils");
13544
+ var import_utils15 = require("@voltagent/internal/utils");
13481
13545
  var import_ai2 = require("ai");
13482
13546
 
13483
13547
  // src/utils/message-helpers.ts
@@ -13888,7 +13952,7 @@ function serializeGuardrailValue(value) {
13888
13952
  if (typeof value === "string") {
13889
13953
  return value;
13890
13954
  }
13891
- return (0, import_utils14.safeStringify)(value);
13955
+ return (0, import_utils15.safeStringify)(value);
13892
13956
  }
13893
13957
  __name(serializeGuardrailValue, "serializeGuardrailValue");
13894
13958
  function extractInputTextForGuardrail(value) {
@@ -13937,7 +14001,7 @@ function extractOutputTextForGuardrail(value) {
13937
14001
  }
13938
14002
  if (typeof value === "object") {
13939
14003
  try {
13940
- return (0, import_utils14.safeStringify)(value);
14004
+ return (0, import_utils15.safeStringify)(value);
13941
14005
  } catch {
13942
14006
  return void 0;
13943
14007
  }
@@ -13974,8 +14038,8 @@ async function runInputGuardrails(input, oc, guardrails, operation, agent) {
13974
14038
  "guardrail.name": guardrail.name,
13975
14039
  ...guardrail.description ? { "guardrail.description": guardrail.description } : {},
13976
14040
  ...guardrail.severity ? { "guardrail.severity": guardrail.severity } : {},
13977
- ...guardrail.tags && guardrail.tags.length > 0 ? { "guardrail.tags": (0, import_utils14.safeStringify)(guardrail.tags) } : {},
13978
- ...guardrail.metadata ? { "guardrail.metadata": (0, import_utils14.safeStringify)(guardrail.metadata) } : {},
14041
+ ...guardrail.tags && guardrail.tags.length > 0 ? { "guardrail.tags": (0, import_utils15.safeStringify)(guardrail.tags) } : {},
14042
+ ...guardrail.metadata ? { "guardrail.metadata": (0, import_utils15.safeStringify)(guardrail.metadata) } : {},
13979
14043
  "guardrail.input.original": serializeGuardrailValue(originalInput),
13980
14044
  "guardrail.input.current": serializeGuardrailValue(currentInput)
13981
14045
  }
@@ -14003,7 +14067,7 @@ async function runInputGuardrails(input, oc, guardrails, operation, agent) {
14003
14067
  span.setAttribute("guardrail.message", resolvedDecision.message);
14004
14068
  }
14005
14069
  if (resolvedDecision.metadata) {
14006
- span.setAttribute("guardrail.result.metadata", (0, import_utils14.safeStringify)(resolvedDecision.metadata));
14070
+ span.setAttribute("guardrail.result.metadata", (0, import_utils15.safeStringify)(resolvedDecision.metadata));
14007
14071
  }
14008
14072
  if (!pass || action === "block") {
14009
14073
  const message = resolvedDecision.message ?? "Input blocked by guardrail";
@@ -14081,8 +14145,8 @@ async function runOutputGuardrails({
14081
14145
  "guardrail.name": guardrail.name,
14082
14146
  ...guardrail.description ? { "guardrail.description": guardrail.description } : {},
14083
14147
  ...guardrail.severity ? { "guardrail.severity": guardrail.severity } : {},
14084
- ...guardrail.tags && guardrail.tags.length > 0 ? { "guardrail.tags": (0, import_utils14.safeStringify)(guardrail.tags) } : {},
14085
- ...guardrail.metadata ? { "guardrail.metadata": (0, import_utils14.safeStringify)(guardrail.metadata) } : {}
14148
+ ...guardrail.tags && guardrail.tags.length > 0 ? { "guardrail.tags": (0, import_utils15.safeStringify)(guardrail.tags) } : {},
14149
+ ...guardrail.metadata ? { "guardrail.metadata": (0, import_utils15.safeStringify)(guardrail.metadata) } : {}
14086
14150
  }
14087
14151
  }
14088
14152
  );
@@ -14090,13 +14154,13 @@ async function runOutputGuardrails({
14090
14154
  span?.setAttribute("guardrail.output.original", serializeGuardrailValue(originalOutput));
14091
14155
  span?.setAttribute("guardrail.output.current", serializeGuardrailValue(currentOutput));
14092
14156
  if (metadata.usage !== void 0) {
14093
- span?.setAttribute("guardrail.usage", (0, import_utils14.safeStringify)(metadata.usage));
14157
+ span?.setAttribute("guardrail.usage", (0, import_utils15.safeStringify)(metadata.usage));
14094
14158
  }
14095
14159
  if (metadata.finishReason !== void 0 && metadata.finishReason !== null) {
14096
14160
  span?.setAttribute("guardrail.finish_reason", metadata.finishReason);
14097
14161
  }
14098
14162
  if (metadata.warnings && metadata.warnings.length > 0) {
14099
- span?.setAttribute("guardrail.warnings", (0, import_utils14.safeStringify)(metadata.warnings));
14163
+ span?.setAttribute("guardrail.warnings", (0, import_utils15.safeStringify)(metadata.warnings));
14100
14164
  }
14101
14165
  try {
14102
14166
  const decision = await oc.traceContext.withSpan(
@@ -14123,7 +14187,7 @@ async function runOutputGuardrails({
14123
14187
  span?.setAttribute("guardrail.message", resolvedDecision.message);
14124
14188
  }
14125
14189
  if (resolvedDecision.metadata) {
14126
- span?.setAttribute("guardrail.result.metadata", (0, import_utils14.safeStringify)(resolvedDecision.metadata));
14190
+ span?.setAttribute("guardrail.result.metadata", (0, import_utils15.safeStringify)(resolvedDecision.metadata));
14127
14191
  }
14128
14192
  if (!pass || action === "block") {
14129
14193
  const message = resolvedDecision.message ?? "Output blocked by guardrail";
@@ -14659,7 +14723,7 @@ var import_ai3 = require("ai");
14659
14723
 
14660
14724
  // src/agent/streaming/output-guardrail-stream-runner.ts
14661
14725
  var import_api13 = require("@opentelemetry/api");
14662
- var import_utils15 = require("@voltagent/internal/utils");
14726
+ var import_utils16 = require("@voltagent/internal/utils");
14663
14727
  var isTextDelta = /* @__PURE__ */ __name((part) => part.type === "text-delta", "isTextDelta");
14664
14728
  var extractChunkText = /* @__PURE__ */ __name((part) => {
14665
14729
  if (!isTextDelta(part)) {
@@ -14914,8 +14978,8 @@ var OutputGuardrailStreamRunner = class {
14914
14978
  "guardrail.name": guardrail.name,
14915
14979
  ...guardrail.description ? { "guardrail.description": guardrail.description } : {},
14916
14980
  ...guardrail.severity ? { "guardrail.severity": guardrail.severity } : {},
14917
- ...guardrail.tags && guardrail.tags.length > 0 ? { "guardrail.tags": (0, import_utils15.safeStringify)(guardrail.tags) } : {},
14918
- ...guardrail.metadata ? { "guardrail.metadata": (0, import_utils15.safeStringify)(guardrail.metadata) } : {}
14981
+ ...guardrail.tags && guardrail.tags.length > 0 ? { "guardrail.tags": (0, import_utils16.safeStringify)(guardrail.tags) } : {},
14982
+ ...guardrail.metadata ? { "guardrail.metadata": (0, import_utils16.safeStringify)(guardrail.metadata) } : {}
14919
14983
  }
14920
14984
  }
14921
14985
  );
@@ -15443,7 +15507,7 @@ __name(convertFullStreamChunkToUIMessageStream, "convertFullStreamChunkToUIMessa
15443
15507
 
15444
15508
  // src/agent/subagent/index.ts
15445
15509
  var import_api14 = require("@opentelemetry/api");
15446
- var import_utils16 = require("@voltagent/internal/utils");
15510
+ var import_utils17 = require("@voltagent/internal/utils");
15447
15511
  var import_zod2 = require("zod");
15448
15512
 
15449
15513
  // src/agent/subagent/types.ts
@@ -15596,10 +15660,13 @@ var SubAgentManager = class {
15596
15660
  */
15597
15661
  extractAgentPurpose(agentConfig) {
15598
15662
  const agent = this.extractAgent(agentConfig);
15663
+ if (agent.purpose) {
15664
+ return agent.purpose;
15665
+ }
15599
15666
  if (typeof agent.instructions === "string") {
15600
- return agent.purpose ?? agent.instructions;
15667
+ return agent.instructions;
15601
15668
  }
15602
- return agent.purpose ?? "Dynamic instructions";
15669
+ return "Dynamic instructions";
15603
15670
  }
15604
15671
  /**
15605
15672
  * Type guard to check if a SubAgentConfig is a direct AgentV2 instance
@@ -15746,7 +15813,7 @@ ${guidelinesText}
15746
15813
  taskContent = `Task handed off from ${sourceAgent?.name || this.agentName} to ${targetAgent.name}:
15747
15814
  ${task}
15748
15815
 
15749
- Context: ${(0, import_utils16.safeStringify)(contextObj, { indentation: 2 })}`;
15816
+ Context: ${(0, import_utils17.safeStringify)(contextObj, { indentation: 2 })}`;
15750
15817
  }
15751
15818
  const taskMessage = {
15752
15819
  id: crypto.randomUUID(),
@@ -15903,7 +15970,7 @@ Context: ${(0, import_utils16.safeStringify)(contextObj, { indentation: 2 })}`;
15903
15970
  options2
15904
15971
  );
15905
15972
  const finalObject = await response.object;
15906
- finalResult = (0, import_utils16.safeStringify)(finalObject);
15973
+ finalResult = (0, import_utils17.safeStringify)(finalObject);
15907
15974
  const assistantMessage = {
15908
15975
  id: crypto.randomUUID(),
15909
15976
  role: "assistant",
@@ -15917,7 +15984,7 @@ Context: ${(0, import_utils16.safeStringify)(contextObj, { indentation: 2 })}`;
15917
15984
  targetAgentConfig.schema,
15918
15985
  options2
15919
15986
  );
15920
- finalResult = (0, import_utils16.safeStringify)(response);
15987
+ finalResult = (0, import_utils17.safeStringify)(response);
15921
15988
  usage = response.usage;
15922
15989
  const assistantMessage = {
15923
15990
  id: crypto.randomUUID(),
@@ -16329,12 +16396,12 @@ var Agent = class {
16329
16396
  );
16330
16397
  const contextMap = Object.fromEntries(oc.context.entries());
16331
16398
  if (Object.keys(contextMap).length > 0) {
16332
- rootSpan.setAttribute("agent.context", (0, import_utils17.safeStringify)(contextMap));
16399
+ rootSpan.setAttribute("agent.context", (0, import_utils18.safeStringify)(contextMap));
16333
16400
  }
16334
- rootSpan.setAttribute("agent.messages", (0, import_utils17.safeStringify)(messages));
16335
- rootSpan.setAttribute("agent.messages.ui", (0, import_utils17.safeStringify)(uiMessages));
16401
+ rootSpan.setAttribute("agent.messages", (0, import_utils18.safeStringify)(messages));
16402
+ rootSpan.setAttribute("agent.messages.ui", (0, import_utils18.safeStringify)(uiMessages));
16336
16403
  const agentState = this.getFullState();
16337
- rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils17.safeStringify)(agentState));
16404
+ rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils18.safeStringify)(agentState));
16338
16405
  methodLogger.debug(
16339
16406
  buildAgentLogMessage(
16340
16407
  this.name,
@@ -16484,7 +16551,7 @@ var Agent = class {
16484
16551
  operation: "generateText",
16485
16552
  metadata: {
16486
16553
  finishReason: result.finishReason,
16487
- usage: result.usage ? JSON.parse((0, import_utils17.safeStringify)(result.usage)) : void 0,
16554
+ usage: result.usage ? JSON.parse((0, import_utils18.safeStringify)(result.usage)) : void 0,
16488
16555
  toolCalls: aggregatedToolCalls
16489
16556
  }
16490
16557
  });
@@ -16594,12 +16661,12 @@ var Agent = class {
16594
16661
  );
16595
16662
  const contextMap = Object.fromEntries(oc.context.entries());
16596
16663
  if (Object.keys(contextMap).length > 0) {
16597
- rootSpan2.setAttribute("agent.context", (0, import_utils17.safeStringify)(contextMap));
16664
+ rootSpan2.setAttribute("agent.context", (0, import_utils18.safeStringify)(contextMap));
16598
16665
  }
16599
- rootSpan2.setAttribute("agent.messages", (0, import_utils17.safeStringify)(messages));
16600
- rootSpan2.setAttribute("agent.messages.ui", (0, import_utils17.safeStringify)(uiMessages));
16666
+ rootSpan2.setAttribute("agent.messages", (0, import_utils18.safeStringify)(messages));
16667
+ rootSpan2.setAttribute("agent.messages.ui", (0, import_utils18.safeStringify)(uiMessages));
16601
16668
  const agentState = this.getFullState();
16602
- rootSpan2.setAttribute("agent.stateSnapshot", (0, import_utils17.safeStringify)(agentState));
16669
+ rootSpan2.setAttribute("agent.stateSnapshot", (0, import_utils18.safeStringify)(agentState));
16603
16670
  }
16604
16671
  methodLogger.debug(
16605
16672
  buildAgentLogMessage(
@@ -16797,7 +16864,7 @@ var Agent = class {
16797
16864
  operation: "streamText",
16798
16865
  metadata: {
16799
16866
  finishReason: finalResult.finishReason,
16800
- usage: finalResult.totalUsage ? JSON.parse((0, import_utils17.safeStringify)(finalResult.totalUsage)) : void 0,
16867
+ usage: finalResult.totalUsage ? JSON.parse((0, import_utils18.safeStringify)(finalResult.totalUsage)) : void 0,
16801
16868
  toolCalls: finalResult.toolCalls
16802
16869
  }
16803
16870
  });
@@ -17051,12 +17118,12 @@ var Agent = class {
17051
17118
  );
17052
17119
  const contextMap = Object.fromEntries(oc.context.entries());
17053
17120
  if (Object.keys(contextMap).length > 0) {
17054
- rootSpan.setAttribute("agent.context", (0, import_utils17.safeStringify)(contextMap));
17121
+ rootSpan.setAttribute("agent.context", (0, import_utils18.safeStringify)(contextMap));
17055
17122
  }
17056
- rootSpan.setAttribute("agent.messages", (0, import_utils17.safeStringify)(messages));
17057
- rootSpan.setAttribute("agent.messages.ui", (0, import_utils17.safeStringify)(uiMessages));
17123
+ rootSpan.setAttribute("agent.messages", (0, import_utils18.safeStringify)(messages));
17124
+ rootSpan.setAttribute("agent.messages.ui", (0, import_utils18.safeStringify)(uiMessages));
17058
17125
  const agentState = this.getFullState();
17059
- rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils17.safeStringify)(agentState));
17126
+ rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils18.safeStringify)(agentState));
17060
17127
  methodLogger.debug(
17061
17128
  buildAgentLogMessage(
17062
17129
  this.name,
@@ -17122,7 +17189,7 @@ var Agent = class {
17122
17189
  parts: [
17123
17190
  {
17124
17191
  type: "text",
17125
- text: (0, import_utils17.safeStringify)(finalObject)
17192
+ text: (0, import_utils18.safeStringify)(finalObject)
17126
17193
  }
17127
17194
  ]
17128
17195
  };
@@ -17130,7 +17197,7 @@ var Agent = class {
17130
17197
  const step = {
17131
17198
  id: randomUUID(),
17132
17199
  type: "text",
17133
- content: (0, import_utils17.safeStringify)(finalObject),
17200
+ content: (0, import_utils18.safeStringify)(finalObject),
17134
17201
  role: "assistant",
17135
17202
  usage: usageInfo
17136
17203
  };
@@ -17145,7 +17212,7 @@ var Agent = class {
17145
17212
  operation: "generateObject",
17146
17213
  metadata: {
17147
17214
  finishReason: result.finishReason,
17148
- usage: result.usage ? JSON.parse((0, import_utils17.safeStringify)(result.usage)) : void 0,
17215
+ usage: result.usage ? JSON.parse((0, import_utils18.safeStringify)(result.usage)) : void 0,
17149
17216
  schemaName
17150
17217
  }
17151
17218
  });
@@ -17229,12 +17296,12 @@ var Agent = class {
17229
17296
  );
17230
17297
  const contextMap = Object.fromEntries(oc.context.entries());
17231
17298
  if (Object.keys(contextMap).length > 0) {
17232
- rootSpan.setAttribute("agent.context", (0, import_utils17.safeStringify)(contextMap));
17299
+ rootSpan.setAttribute("agent.context", (0, import_utils18.safeStringify)(contextMap));
17233
17300
  }
17234
- rootSpan.setAttribute("agent.messages", (0, import_utils17.safeStringify)(messages));
17235
- rootSpan.setAttribute("agent.messages.ui", (0, import_utils17.safeStringify)(uiMessages));
17301
+ rootSpan.setAttribute("agent.messages", (0, import_utils18.safeStringify)(messages));
17302
+ rootSpan.setAttribute("agent.messages.ui", (0, import_utils18.safeStringify)(uiMessages));
17236
17303
  const agentState = this.getFullState();
17237
- rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils17.safeStringify)(agentState));
17304
+ rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils18.safeStringify)(agentState));
17238
17305
  methodLogger.debug(
17239
17306
  buildAgentLogMessage(
17240
17307
  this.name,
@@ -17327,7 +17394,7 @@ var Agent = class {
17327
17394
  parts: [
17328
17395
  {
17329
17396
  type: "text",
17330
- text: (0, import_utils17.safeStringify)(finalObject)
17397
+ text: (0, import_utils18.safeStringify)(finalObject)
17331
17398
  }
17332
17399
  ]
17333
17400
  };
@@ -17335,7 +17402,7 @@ var Agent = class {
17335
17402
  const step = {
17336
17403
  id: randomUUID(),
17337
17404
  type: "text",
17338
- content: (0, import_utils17.safeStringify)(finalObject),
17405
+ content: (0, import_utils18.safeStringify)(finalObject),
17339
17406
  role: "assistant",
17340
17407
  usage: usageInfo
17341
17408
  };
@@ -17384,7 +17451,7 @@ var Agent = class {
17384
17451
  operation: "streamObject",
17385
17452
  metadata: {
17386
17453
  finishReason: finalResult.finishReason,
17387
- usage: finalResult.usage ? JSON.parse((0, import_utils17.safeStringify)(finalResult.usage)) : void 0,
17454
+ usage: finalResult.usage ? JSON.parse((0, import_utils18.safeStringify)(finalResult.usage)) : void 0,
17388
17455
  schemaName
17389
17456
  }
17390
17457
  });
@@ -17725,12 +17792,12 @@ var Agent = class {
17725
17792
  attrs["llm.top_p"] = topP;
17726
17793
  }
17727
17794
  if (callOptions.stop !== void 0) {
17728
- attrs["llm.stop_condition"] = (0, import_utils17.safeStringify)(callOptions.stop);
17795
+ attrs["llm.stop_condition"] = (0, import_utils18.safeStringify)(callOptions.stop);
17729
17796
  }
17730
17797
  if (params.messages && params.messages.length > 0) {
17731
17798
  attrs["llm.messages.count"] = params.messages.length;
17732
17799
  const trimmedMessages = params.messages.slice(-10);
17733
- attrs["llm.messages"] = (0, import_utils17.safeStringify)(
17800
+ attrs["llm.messages"] = (0, import_utils18.safeStringify)(
17734
17801
  trimmedMessages.map((msg) => ({
17735
17802
  role: msg.role,
17736
17803
  content: msg.content
@@ -17745,7 +17812,7 @@ var Agent = class {
17745
17812
  }
17746
17813
  }
17747
17814
  if (params.providerOptions) {
17748
- attrs["llm.provider_options"] = (0, import_utils17.safeStringify)(params.providerOptions);
17815
+ attrs["llm.provider_options"] = (0, import_utils18.safeStringify)(params.providerOptions);
17749
17816
  }
17750
17817
  return attrs;
17751
17818
  }
@@ -17903,7 +17970,7 @@ var Agent = class {
17903
17970
  attributes: {
17904
17971
  "memory.operation": "read",
17905
17972
  "memory.semantic": isSemanticSearch,
17906
- input: (0, import_utils17.safeStringify)(spanInput),
17973
+ input: (0, import_utils18.safeStringify)(spanInput),
17907
17974
  ...isSemanticSearch && {
17908
17975
  "memory.semantic.limit": semanticLimit,
17909
17976
  "memory.semantic.threshold": semanticThreshold,
@@ -18035,13 +18102,13 @@ var Agent = class {
18035
18102
  rootSpan.setAttribute("prompt.version", metadata.version);
18036
18103
  }
18037
18104
  if (metadata.labels && metadata.labels.length > 0) {
18038
- rootSpan.setAttribute("prompt.labels", (0, import_utils17.safeStringify)(metadata.labels));
18105
+ rootSpan.setAttribute("prompt.labels", (0, import_utils18.safeStringify)(metadata.labels));
18039
18106
  }
18040
18107
  if (metadata.tags && metadata.tags.length > 0) {
18041
- rootSpan.setAttribute("prompt.tags", (0, import_utils17.safeStringify)(metadata.tags));
18108
+ rootSpan.setAttribute("prompt.tags", (0, import_utils18.safeStringify)(metadata.tags));
18042
18109
  }
18043
18110
  if (metadata.config) {
18044
- rootSpan.setAttribute("prompt.config", (0, import_utils17.safeStringify)(metadata.config));
18111
+ rootSpan.setAttribute("prompt.config", (0, import_utils18.safeStringify)(metadata.config));
18045
18112
  }
18046
18113
  }
18047
18114
  }
@@ -18215,7 +18282,7 @@ ${retrieverContext}`;
18215
18282
  label: this.retriever.tool.name || "Retriever",
18216
18283
  attributes: {
18217
18284
  "retriever.name": this.retriever.tool.name || "Retriever",
18218
- input: typeof input === "string" ? input : (0, import_utils17.safeStringify)(input)
18285
+ input: typeof input === "string" ? input : (0, import_utils18.safeStringify)(input)
18219
18286
  }
18220
18287
  });
18221
18288
  try {
@@ -18361,9 +18428,9 @@ ${retrieverContext}`;
18361
18428
  "tool.name": tool2.name,
18362
18429
  "tool.call.id": toolCallId,
18363
18430
  "tool.description": tool2.description,
18364
- ...toolTags && toolTags.length > 0 ? { "tool.tags": (0, import_utils17.safeStringify)(toolTags) } : {},
18365
- "tool.parameters": (0, import_utils17.safeStringify)(tool2.parameters),
18366
- input: args ? (0, import_utils17.safeStringify)(args) : void 0
18431
+ ...toolTags && toolTags.length > 0 ? { "tool.tags": (0, import_utils18.safeStringify)(toolTags) } : {},
18432
+ "tool.parameters": (0, import_utils18.safeStringify)(tool2.parameters),
18433
+ input: args ? (0, import_utils18.safeStringify)(args) : void 0
18367
18434
  },
18368
18435
  kind: import_api15.SpanKind.CLIENT
18369
18436
  });
@@ -18384,7 +18451,7 @@ ${retrieverContext}`;
18384
18451
  }
18385
18452
  const result = await tool2.execute(args, executionOptions);
18386
18453
  const validatedResult = await this.validateToolOutput(result, tool2);
18387
- toolSpan.setAttribute("output", (0, import_utils17.safeStringify)(result));
18454
+ toolSpan.setAttribute("output", (0, import_utils18.safeStringify)(result));
18388
18455
  toolSpan.setStatus({ code: import_api15.SpanStatusCode.OK });
18389
18456
  toolSpan.end();
18390
18457
  await hooks.onToolEnd?.({
@@ -18398,7 +18465,16 @@ ${retrieverContext}`;
18398
18465
  return result;
18399
18466
  } catch (e) {
18400
18467
  const error = e instanceof Error ? e : new Error(String(e));
18401
- const errorResult = { error: true, ...error };
18468
+ const voltAgentError = createVoltAgentError(error, {
18469
+ stage: "tool_execution",
18470
+ toolError: {
18471
+ toolCallId,
18472
+ toolName: tool2.name,
18473
+ toolExecutionError: error,
18474
+ toolArguments: args
18475
+ }
18476
+ });
18477
+ const errorResult = buildToolErrorResult(error, toolCallId, tool2.name);
18402
18478
  toolSpan.setStatus({ code: import_api15.SpanStatusCode.ERROR, message: error.message });
18403
18479
  toolSpan.recordException(error);
18404
18480
  toolSpan.end();
@@ -18406,7 +18482,7 @@ ${retrieverContext}`;
18406
18482
  agent: this,
18407
18483
  tool: tool2,
18408
18484
  output: void 0,
18409
- error: errorResult,
18485
+ error: voltAgentError,
18410
18486
  context: oc,
18411
18487
  options: executionOptions
18412
18488
  });
@@ -18574,7 +18650,7 @@ ${retrieverContext}`;
18574
18650
  oc.conversationSteps?.push({
18575
18651
  id: toolCall.toolCallId || randomUUID(),
18576
18652
  type: "tool_call",
18577
- content: (0, import_utils17.safeStringify)(toolCall.input ?? {}),
18653
+ content: (0, import_utils18.safeStringify)(toolCall.input ?? {}),
18578
18654
  role: "assistant",
18579
18655
  name: toolCall.toolName,
18580
18656
  arguments: toolCall.input || {},
@@ -18606,7 +18682,7 @@ ${retrieverContext}`;
18606
18682
  oc.conversationSteps?.push({
18607
18683
  id: toolResult.toolCallId || randomUUID(),
18608
18684
  type: "tool_result",
18609
- content: (0, import_utils17.safeStringify)(toolResult.output),
18685
+ content: (0, import_utils18.safeStringify)(toolResult.output),
18610
18686
  role: "assistant",
18611
18687
  name: toolResult.toolName,
18612
18688
  result: toolResult.output,
@@ -21975,7 +22051,7 @@ var import_node_crypto = __toESM(require("crypto"));
21975
22051
  var import_node_fs = __toESM(require("fs"));
21976
22052
  var import_node_os = __toESM(require("os"));
21977
22053
  var import_node_path = __toESM(require("path"));
21978
- var import_utils18 = require("@voltagent/internal/utils");
22054
+ var import_utils19 = require("@voltagent/internal/utils");
21979
22055
  var getEnvPaths = /* @__PURE__ */ __name((name) => {
21980
22056
  const homedir = import_node_os.default.homedir();
21981
22057
  const tmpdir = import_node_os.default.tmpdir();
@@ -22045,7 +22121,7 @@ var writeUpdateCache = /* @__PURE__ */ __name(async (projectPath, cache) => {
22045
22121
  try {
22046
22122
  ensureCacheDir();
22047
22123
  const cacheFilePath = getCacheFilePath(projectPath);
22048
- import_node_fs.default.writeFileSync(cacheFilePath, (0, import_utils18.safeStringify)(cache, { indentation: 2 }), "utf8");
22124
+ import_node_fs.default.writeFileSync(cacheFilePath, (0, import_utils19.safeStringify)(cache, { indentation: 2 }), "utf8");
22049
22125
  } catch (error) {
22050
22126
  const logger = new LoggerProxy({ component: "update-cache" });
22051
22127
  logger.error("Error writing update cache", { error });
@@ -22938,7 +23014,7 @@ var VoltAgent = class {
22938
23014
  };
22939
23015
 
22940
23016
  // src/index.ts
22941
- var import_utils19 = require("@voltagent/internal/utils");
23017
+ var import_utils20 = require("@voltagent/internal/utils");
22942
23018
  var import_ai6 = require("ai");
22943
23019
  // Annotate the CommonJS export names for ESM import in node:
22944
23020
  0 && (module.exports = {