@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.cjs +17 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -770,6 +770,20 @@ function normalizeOpenAIStopReason(reason) {
|
|
|
770
770
|
function isJsonObject(value) {
|
|
771
771
|
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
772
772
|
}
|
|
773
|
+
function uniqueToolsByName(tools) {
|
|
774
|
+
const seen = /* @__PURE__ */ new Set();
|
|
775
|
+
const unique = [];
|
|
776
|
+
for (const tool of tools) {
|
|
777
|
+
if (!tool.name) {
|
|
778
|
+
unique.push(tool);
|
|
779
|
+
continue;
|
|
780
|
+
}
|
|
781
|
+
if (seen.has(tool.name)) continue;
|
|
782
|
+
seen.add(tool.name);
|
|
783
|
+
unique.push(tool);
|
|
784
|
+
}
|
|
785
|
+
return unique;
|
|
786
|
+
}
|
|
773
787
|
function createClient(options) {
|
|
774
788
|
const isOAuth = options.apiKey?.startsWith("sk-ant-oat");
|
|
775
789
|
return new import_sdk.default({
|
|
@@ -838,18 +852,18 @@ async function* runStream(options) {
|
|
|
838
852
|
if (name) reservedServerNames.add(name);
|
|
839
853
|
}
|
|
840
854
|
const clientTools = options.tools?.length ? toAnthropicTools(
|
|
841
|
-
options.tools.filter((t) => !reservedServerNames.has(t.name)),
|
|
855
|
+
uniqueToolsByName(options.tools.filter((t) => !reservedServerNames.has(t.name))),
|
|
842
856
|
{
|
|
843
857
|
...supportsFirstPartyToolExtras && cacheControl ? { cacheControl } : {},
|
|
844
858
|
...supportsFirstPartyToolExtras ? { enableFineGrainedToolStreaming: true } : {}
|
|
845
859
|
}
|
|
846
860
|
) : [];
|
|
847
861
|
return {
|
|
848
|
-
tools: [
|
|
862
|
+
tools: uniqueToolsByName([
|
|
849
863
|
...clientTools,
|
|
850
864
|
...options.serverTools ?? [],
|
|
851
865
|
...options.webSearch ? [{ type: "web_search_20250305", name: "web_search" }] : []
|
|
852
|
-
]
|
|
866
|
+
])
|
|
853
867
|
};
|
|
854
868
|
})() : {},
|
|
855
869
|
...options.toolChoice && options.tools?.length ? { tool_choice: toAnthropicToolChoice(options.toolChoice) } : {},
|