@prestyj/ai 4.3.200 → 4.3.201

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
@@ -721,6 +721,20 @@ function normalizeOpenAIStopReason(reason) {
721
721
  function isJsonObject(value) {
722
722
  return value != null && typeof value === "object" && !Array.isArray(value);
723
723
  }
724
+ function uniqueToolsByName(tools) {
725
+ const seen = /* @__PURE__ */ new Set();
726
+ const unique = [];
727
+ for (const tool of tools) {
728
+ if (!tool.name) {
729
+ unique.push(tool);
730
+ continue;
731
+ }
732
+ if (seen.has(tool.name)) continue;
733
+ seen.add(tool.name);
734
+ unique.push(tool);
735
+ }
736
+ return unique;
737
+ }
724
738
  function createClient(options) {
725
739
  const isOAuth = options.apiKey?.startsWith("sk-ant-oat");
726
740
  return new Anthropic({
@@ -789,18 +803,18 @@ async function* runStream(options) {
789
803
  if (name) reservedServerNames.add(name);
790
804
  }
791
805
  const clientTools = options.tools?.length ? toAnthropicTools(
792
- options.tools.filter((t) => !reservedServerNames.has(t.name)),
806
+ uniqueToolsByName(options.tools.filter((t) => !reservedServerNames.has(t.name))),
793
807
  {
794
808
  ...supportsFirstPartyToolExtras && cacheControl ? { cacheControl } : {},
795
809
  ...supportsFirstPartyToolExtras ? { enableFineGrainedToolStreaming: true } : {}
796
810
  }
797
811
  ) : [];
798
812
  return {
799
- tools: [
813
+ tools: uniqueToolsByName([
800
814
  ...clientTools,
801
815
  ...options.serverTools ?? [],
802
816
  ...options.webSearch ? [{ type: "web_search_20250305", name: "web_search" }] : []
803
- ]
817
+ ])
804
818
  };
805
819
  })() : {},
806
820
  ...options.toolChoice && options.tools?.length ? { tool_choice: toAnthropicToolChoice(options.toolChoice) } : {},