@voltagent/core 2.6.0 → 2.6.2

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.d.mts CHANGED
@@ -9410,6 +9410,9 @@ declare class Agent {
9410
9410
  private executeWithModelFallback;
9411
9411
  private probeStreamStart;
9412
9412
  private cloneResultWithFullStream;
9413
+ private withProbedFullStream;
9414
+ private usesGetterBasedTeeingFullStream;
9415
+ private findPropertyDescriptor;
9413
9416
  private toAsyncIterableStream;
9414
9417
  private discardStream;
9415
9418
  /**
package/dist/index.d.ts CHANGED
@@ -9410,6 +9410,9 @@ declare class Agent {
9410
9410
  private executeWithModelFallback;
9411
9411
  private probeStreamStart;
9412
9412
  private cloneResultWithFullStream;
9413
+ private withProbedFullStream;
9414
+ private usesGetterBasedTeeingFullStream;
9415
+ private findPropertyDescriptor;
9413
9416
  private toAsyncIterableStream;
9414
9417
  private discardStream;
9415
9418
  /**
package/dist/index.js CHANGED
@@ -31223,8 +31223,13 @@ var Agent = class {
31223
31223
  );
31224
31224
  }, "onFinish")
31225
31225
  });
31226
- const probeResult = await this.probeStreamStart(streamResult.fullStream, attemptState);
31227
- const streamResultForConsumption = probeResult.stream === streamResult.fullStream ? streamResult : this.cloneResultWithFullStream(streamResult, probeResult.stream);
31226
+ const originalFullStream = streamResult.fullStream;
31227
+ const probeResult = await this.probeStreamStart(originalFullStream, attemptState);
31228
+ const streamResultForConsumption = this.withProbedFullStream(
31229
+ streamResult,
31230
+ originalFullStream,
31231
+ probeResult.stream
31232
+ );
31228
31233
  if (probeResult.status === "error") {
31229
31234
  this.discardStream(streamResultForConsumption.fullStream);
31230
31235
  const fallbackEligible = this.shouldFallbackOnError(probeResult.error);
@@ -32095,8 +32100,13 @@ var Agent = class {
32095
32100
  }
32096
32101
  }, "onFinish")
32097
32102
  });
32098
- const probeResult = await this.probeStreamStart(streamResult.fullStream, attemptState);
32099
- const streamResultForConsumption = probeResult.stream === streamResult.fullStream ? streamResult : this.cloneResultWithFullStream(streamResult, probeResult.stream);
32103
+ const originalFullStream = streamResult.fullStream;
32104
+ const probeResult = await this.probeStreamStart(originalFullStream, attemptState);
32105
+ const streamResultForConsumption = this.withProbedFullStream(
32106
+ streamResult,
32107
+ originalFullStream,
32108
+ probeResult.stream
32109
+ );
32100
32110
  if (probeResult.status === "error") {
32101
32111
  this.discardStream(streamResultForConsumption.fullStream);
32102
32112
  const fallbackEligible = this.shouldFallbackOnError(probeResult.error);
@@ -33713,6 +33723,30 @@ ${retrieverContext}`;
33713
33723
  });
33714
33724
  return clone;
33715
33725
  }
33726
+ withProbedFullStream(result, originalFullStream, probedFullStream) {
33727
+ if (probedFullStream === originalFullStream) {
33728
+ return result;
33729
+ }
33730
+ if (this.usesGetterBasedTeeingFullStream(result)) {
33731
+ return result;
33732
+ }
33733
+ return this.cloneResultWithFullStream(result, probedFullStream);
33734
+ }
33735
+ usesGetterBasedTeeingFullStream(result) {
33736
+ const descriptor = this.findPropertyDescriptor(result, "fullStream");
33737
+ return typeof descriptor?.get === "function" && typeof result.teeStream === "function";
33738
+ }
33739
+ findPropertyDescriptor(target, propertyName) {
33740
+ let current = target;
33741
+ while (current) {
33742
+ const descriptor = Object.getOwnPropertyDescriptor(current, propertyName);
33743
+ if (descriptor) {
33744
+ return descriptor;
33745
+ }
33746
+ current = Object.getPrototypeOf(current);
33747
+ }
33748
+ return void 0;
33749
+ }
33716
33750
  toAsyncIterableStream(stream) {
33717
33751
  const asyncStream = stream;
33718
33752
  if (!asyncStream[Symbol.asyncIterator]) {
@@ -33768,18 +33802,18 @@ ${retrieverContext}`;
33768
33802
  const toolRouting = this.resolveToolRouting(options);
33769
33803
  oc.systemContext.set(TOOL_ROUTING_CONTEXT_KEY, toolRouting);
33770
33804
  if (toolRouting === false) {
33771
- const supportNames = this.getToolRoutingSupportToolNames();
33772
- const allNames = /* @__PURE__ */ new Set([
33773
- ...Object.keys(preparedStaticTools),
33774
- ...Object.keys(preparedDynamicTools)
33775
- ]);
33776
- const conflicts = [...allNames].filter((name) => supportNames.has(name));
33777
- if (conflicts.length > 0) {
33805
+ const conflicts = /* @__PURE__ */ new Set();
33806
+ for (const tool2 of [...this.toolManager.getAllTools(), ...tempManager.getAllTools()]) {
33807
+ if (this.isToolRoutingSupportTool(tool2)) {
33808
+ conflicts.add(tool2.name);
33809
+ }
33810
+ }
33811
+ if (conflicts.size > 0) {
33778
33812
  throw new Error(
33779
33813
  [
33780
- "toolRouting is disabled but reserved routing tool names are in use:",
33781
- conflicts.join(", "),
33782
- "Rename these tools or enable toolRouting to use the built-in names."
33814
+ "toolRouting is disabled but internal routing support tools are in use:",
33815
+ Array.from(conflicts).join(", "),
33816
+ "Enable toolRouting or remove internal routing tools before disabling it for this request."
33783
33817
  ].join(" ")
33784
33818
  );
33785
33819
  }
@@ -34052,10 +34086,7 @@ ${retrieverContext}`;
34052
34086
  if (!tool2 || typeof tool2 !== "object") {
34053
34087
  return false;
34054
34088
  }
34055
- if (TOOL_ROUTING_INTERNAL_TOOL_SYMBOL in tool2) {
34056
- return true;
34057
- }
34058
- return tool2.name === TOOL_ROUTING_SEARCH_TOOL_NAME || tool2.name === TOOL_ROUTING_CALL_TOOL_NAME;
34089
+ return Object.prototype.hasOwnProperty.call(tool2, TOOL_ROUTING_INTERNAL_TOOL_SYMBOL);
34059
34090
  }
34060
34091
  isToolExecutableForRouting(tool2) {
34061
34092
  if (isProviderTool(tool2)) {
@@ -35131,12 +35162,12 @@ ${retrieverContext}`;
35131
35162
  const memoryInstance = activeMemory || void 0;
35132
35163
  const toolRoutingConfig = this.toolRouting && typeof this.toolRouting === "object" ? this.toolRouting : void 0;
35133
35164
  const toolRoutingState = toolRoutingConfig ? (() => {
35134
- const supportNames = this.getToolRoutingSupportToolNames();
35135
35165
  const searchTool = this.toolManager.getToolByName(TOOL_ROUTING_SEARCH_TOOL_NAME);
35136
35166
  const callTool = this.toolManager.getToolByName(TOOL_ROUTING_CALL_TOOL_NAME);
35137
35167
  const searchApiTool = searchTool && this.isToolRoutingSupportTool(searchTool) ? new ToolManager([searchTool], this.logger).getToolsForApi()[0] : void 0;
35138
35168
  const callApiTool = callTool && this.isToolRoutingSupportTool(callTool) ? new ToolManager([callTool], this.logger).getToolsForApi()[0] : void 0;
35139
- const poolApiTools = this.toolPoolManager.getToolsForApi().filter((tool2) => !supportNames.has(tool2.name));
35169
+ const poolTools = this.toolPoolManager.getAllTools().filter((tool2) => !this.isToolRoutingSupportTool(tool2));
35170
+ const poolApiTools = poolTools.length > 0 ? new ToolManager(poolTools, this.logger).getToolsForApi() : [];
35140
35171
  const exposeApiTools = toolRoutingConfig.expose && toolRoutingConfig.expose.length > 0 ? new ToolManager(toolRoutingConfig.expose, this.logger).getToolsForApi() : [];
35141
35172
  return {
35142
35173
  search: searchApiTool,
@@ -35442,9 +35473,10 @@ ${retrieverContext}`;
35442
35473
  upsertToolRoutingSupportTool(tool2) {
35443
35474
  const existing = this.toolManager.getToolByName(tool2.name);
35444
35475
  if (existing && !this.isToolRoutingSupportTool(existing)) {
35445
- throw new Error(
35446
- `Tool routing requires reserved tool name "${tool2.name}". Rename the conflicting tool to enable tool routing.`
35476
+ this.logger.debug(
35477
+ `Tool routing support tool "${tool2.name}" not added because a user-defined tool with the same name exists.`
35447
35478
  );
35479
+ return;
35448
35480
  }
35449
35481
  if (existing && this.isToolRoutingSupportTool(existing)) {
35450
35482
  this.toolManager.removeTool(tool2.name);