@yourgpt/llm-sdk 2.0.1 → 2.0.2-beta.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/adapters/index.d.mts +27 -4
- package/dist/adapters/index.d.ts +27 -4
- package/dist/adapters/index.js +395 -25
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +395 -25
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/index.d.mts +24 -5
- package/dist/index.d.ts +24 -5
- package/dist/index.js +20 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -4
- package/dist/index.mjs.map +1 -1
- package/dist/providers/anthropic/index.d.mts +1 -2
- package/dist/providers/anthropic/index.d.ts +1 -2
- package/dist/providers/anthropic/index.js +108 -12
- package/dist/providers/anthropic/index.js.map +1 -1
- package/dist/providers/anthropic/index.mjs +108 -12
- package/dist/providers/anthropic/index.mjs.map +1 -1
- package/dist/providers/azure/index.d.mts +1 -2
- package/dist/providers/azure/index.d.ts +1 -2
- package/dist/providers/azure/index.js.map +1 -1
- package/dist/providers/azure/index.mjs.map +1 -1
- package/dist/providers/google/index.d.mts +1 -2
- package/dist/providers/google/index.d.ts +1 -2
- package/dist/providers/google/index.js +61 -2
- package/dist/providers/google/index.js.map +1 -1
- package/dist/providers/google/index.mjs +61 -2
- package/dist/providers/google/index.mjs.map +1 -1
- package/dist/providers/ollama/index.d.mts +8 -3
- package/dist/providers/ollama/index.d.ts +8 -3
- package/dist/providers/ollama/index.js +227 -17
- package/dist/providers/ollama/index.js.map +1 -1
- package/dist/providers/ollama/index.mjs +227 -17
- package/dist/providers/ollama/index.mjs.map +1 -1
- package/dist/providers/openai/index.d.mts +1 -2
- package/dist/providers/openai/index.d.ts +1 -2
- package/dist/providers/openai/index.js +57 -3
- package/dist/providers/openai/index.js.map +1 -1
- package/dist/providers/openai/index.mjs +57 -3
- package/dist/providers/openai/index.mjs.map +1 -1
- package/dist/providers/openrouter/index.d.mts +56 -3
- package/dist/providers/openrouter/index.d.ts +56 -3
- package/dist/providers/openrouter/index.js +90 -276
- package/dist/providers/openrouter/index.js.map +1 -1
- package/dist/providers/openrouter/index.mjs +89 -277
- package/dist/providers/openrouter/index.mjs.map +1 -1
- package/dist/providers/xai/index.d.mts +1 -2
- package/dist/providers/xai/index.d.ts +1 -2
- package/dist/providers/xai/index.js.map +1 -1
- package/dist/providers/xai/index.mjs.map +1 -1
- package/dist/{base-DdxolpKP.d.mts → types-C_f95PKp.d.mts} +434 -3
- package/dist/{base-DdxolpKP.d.ts → types-C_f95PKp.d.ts} +434 -3
- package/package.json +1 -1
- package/dist/types-Ck25ZYma.d.mts +0 -323
- package/dist/types-Dsz8SpdB.d.ts +0 -323
|
@@ -702,14 +702,45 @@ var AnthropicAdapter = class {
|
|
|
702
702
|
) : {},
|
|
703
703
|
required: action.parameters ? Object.entries(action.parameters).filter(([, param]) => param.required).map(([key]) => key) : []
|
|
704
704
|
}
|
|
705
|
-
}));
|
|
705
|
+
})) || [];
|
|
706
|
+
const webSearchConfig = request.webSearch ?? this.config.webSearch;
|
|
707
|
+
let serverToolConfiguration;
|
|
708
|
+
if (webSearchConfig) {
|
|
709
|
+
tools.push({
|
|
710
|
+
type: "web_search_20260209",
|
|
711
|
+
name: "web_search",
|
|
712
|
+
allowed_callers: ["direct"]
|
|
713
|
+
});
|
|
714
|
+
const wsConfig = typeof webSearchConfig === "object" ? webSearchConfig : {};
|
|
715
|
+
const webSearchToolConfig = {};
|
|
716
|
+
if (wsConfig.maxUses !== void 0) {
|
|
717
|
+
webSearchToolConfig.max_uses = wsConfig.maxUses;
|
|
718
|
+
}
|
|
719
|
+
if (wsConfig.allowedDomains && wsConfig.allowedDomains.length > 0) {
|
|
720
|
+
webSearchToolConfig.allowed_domains = wsConfig.allowedDomains;
|
|
721
|
+
}
|
|
722
|
+
if (wsConfig.blockedDomains && wsConfig.blockedDomains.length > 0) {
|
|
723
|
+
webSearchToolConfig.blocked_domains = wsConfig.blockedDomains;
|
|
724
|
+
}
|
|
725
|
+
if (wsConfig.userLocation) {
|
|
726
|
+
webSearchToolConfig.user_location = wsConfig.userLocation;
|
|
727
|
+
}
|
|
728
|
+
if (Object.keys(webSearchToolConfig).length > 0) {
|
|
729
|
+
serverToolConfiguration = {
|
|
730
|
+
web_search: webSearchToolConfig
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
}
|
|
706
734
|
const options = {
|
|
707
735
|
model: request.config?.model || this.model,
|
|
708
736
|
max_tokens: request.config?.maxTokens || this.config.maxTokens || 4096,
|
|
709
737
|
system: systemMessage,
|
|
710
738
|
messages,
|
|
711
|
-
tools: tools
|
|
739
|
+
tools: tools.length ? tools : void 0
|
|
712
740
|
};
|
|
741
|
+
if (serverToolConfiguration) {
|
|
742
|
+
options.server_tool_configuration = serverToolConfiguration;
|
|
743
|
+
}
|
|
713
744
|
if (this.config.thinking?.type === "enabled") {
|
|
714
745
|
options.thinking = {
|
|
715
746
|
type: "enabled",
|
|
@@ -765,6 +796,8 @@ var AnthropicAdapter = class {
|
|
|
765
796
|
const stream = await client.messages.stream(options);
|
|
766
797
|
let currentToolUse = null;
|
|
767
798
|
let isInThinkingBlock = false;
|
|
799
|
+
const collectedCitations = [];
|
|
800
|
+
let citationIndex = 0;
|
|
768
801
|
let usage;
|
|
769
802
|
for await (const event of stream) {
|
|
770
803
|
if (request.signal?.aborted) {
|
|
@@ -793,11 +826,30 @@ var AnthropicAdapter = class {
|
|
|
793
826
|
name: event.content_block.name,
|
|
794
827
|
input: ""
|
|
795
828
|
};
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
829
|
+
if (currentToolUse.name !== "web_search") {
|
|
830
|
+
yield {
|
|
831
|
+
type: "action:start",
|
|
832
|
+
id: currentToolUse.id,
|
|
833
|
+
name: currentToolUse.name
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
} else if (event.content_block.type === "web_search_tool_result") {
|
|
837
|
+
const webSearchResult = event.content_block;
|
|
838
|
+
if (webSearchResult.content && Array.isArray(webSearchResult.content)) {
|
|
839
|
+
for (const result of webSearchResult.content) {
|
|
840
|
+
if (result.type === "web_search_result" && result.url) {
|
|
841
|
+
citationIndex++;
|
|
842
|
+
const domain = extractDomain(result.url);
|
|
843
|
+
collectedCitations.push({
|
|
844
|
+
index: citationIndex,
|
|
845
|
+
url: result.url,
|
|
846
|
+
title: result.title || domain,
|
|
847
|
+
domain,
|
|
848
|
+
favicon: domain ? `https://www.google.com/s2/favicons?domain=${domain}&sz=32` : void 0
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
801
853
|
} else if (event.content_block.type === "thinking") {
|
|
802
854
|
isInThinkingBlock = true;
|
|
803
855
|
yield { type: "thinking:start" };
|
|
@@ -806,6 +858,20 @@ var AnthropicAdapter = class {
|
|
|
806
858
|
case "content_block_delta":
|
|
807
859
|
if (event.delta.type === "text_delta") {
|
|
808
860
|
yield { type: "message:delta", content: event.delta.text };
|
|
861
|
+
} else if (event.delta.type === "citations_delta") {
|
|
862
|
+
const citationsDelta = event.delta;
|
|
863
|
+
if (citationsDelta.citation?.url) {
|
|
864
|
+
citationIndex++;
|
|
865
|
+
const domain = extractDomain(citationsDelta.citation.url);
|
|
866
|
+
collectedCitations.push({
|
|
867
|
+
index: citationIndex,
|
|
868
|
+
url: citationsDelta.citation.url,
|
|
869
|
+
title: citationsDelta.citation.title || domain,
|
|
870
|
+
citedText: citationsDelta.citation.cited_text,
|
|
871
|
+
domain,
|
|
872
|
+
favicon: domain ? `https://www.google.com/s2/favicons?domain=${domain}&sz=32` : void 0
|
|
873
|
+
});
|
|
874
|
+
}
|
|
809
875
|
} else if (event.delta.type === "thinking_delta") {
|
|
810
876
|
yield { type: "thinking:delta", content: event.delta.thinking };
|
|
811
877
|
} else if (event.delta.type === "input_json_delta" && currentToolUse) {
|
|
@@ -814,11 +880,18 @@ var AnthropicAdapter = class {
|
|
|
814
880
|
break;
|
|
815
881
|
case "content_block_stop":
|
|
816
882
|
if (currentToolUse) {
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
883
|
+
if (currentToolUse.name !== "web_search") {
|
|
884
|
+
yield {
|
|
885
|
+
type: "action:args",
|
|
886
|
+
id: currentToolUse.id,
|
|
887
|
+
args: currentToolUse.input
|
|
888
|
+
};
|
|
889
|
+
yield {
|
|
890
|
+
type: "action:end",
|
|
891
|
+
id: currentToolUse.id,
|
|
892
|
+
name: currentToolUse.name
|
|
893
|
+
};
|
|
894
|
+
}
|
|
822
895
|
currentToolUse = null;
|
|
823
896
|
}
|
|
824
897
|
if (isInThinkingBlock) {
|
|
@@ -830,6 +903,10 @@ var AnthropicAdapter = class {
|
|
|
830
903
|
break;
|
|
831
904
|
}
|
|
832
905
|
}
|
|
906
|
+
if (collectedCitations.length > 0) {
|
|
907
|
+
const uniqueCitations = deduplicateCitations(collectedCitations);
|
|
908
|
+
yield { type: "citation", citations: uniqueCitations };
|
|
909
|
+
}
|
|
833
910
|
yield { type: "message:end" };
|
|
834
911
|
yield { type: "done", usage };
|
|
835
912
|
} catch (error) {
|
|
@@ -841,6 +918,25 @@ var AnthropicAdapter = class {
|
|
|
841
918
|
}
|
|
842
919
|
}
|
|
843
920
|
};
|
|
921
|
+
function extractDomain(url) {
|
|
922
|
+
try {
|
|
923
|
+
const parsed = new URL(url);
|
|
924
|
+
return parsed.hostname;
|
|
925
|
+
} catch {
|
|
926
|
+
return "";
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
function deduplicateCitations(citations) {
|
|
930
|
+
const seen = /* @__PURE__ */ new Map();
|
|
931
|
+
let index = 0;
|
|
932
|
+
for (const citation of citations) {
|
|
933
|
+
if (!seen.has(citation.url)) {
|
|
934
|
+
index++;
|
|
935
|
+
seen.set(citation.url, { ...citation, index });
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
return Array.from(seen.values());
|
|
939
|
+
}
|
|
844
940
|
function createAnthropicAdapter(config) {
|
|
845
941
|
return new AnthropicAdapter(config);
|
|
846
942
|
}
|