@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
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as AnthropicProviderConfig, A as AIProvider } from '../../types-Ck25ZYma.mjs';
|
|
1
|
+
import { k as LanguageModel, Z as AnthropicProviderConfig, A as AIProvider } from '../../types-C_f95PKp.mjs';
|
|
3
2
|
import 'zod';
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as AnthropicProviderConfig, A as AIProvider } from '../../types-Dsz8SpdB.js';
|
|
1
|
+
import { k as LanguageModel, Z as AnthropicProviderConfig, A as AIProvider } from '../../types-C_f95PKp.js';
|
|
3
2
|
import 'zod';
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -704,14 +704,45 @@ var AnthropicAdapter = class {
|
|
|
704
704
|
) : {},
|
|
705
705
|
required: action.parameters ? Object.entries(action.parameters).filter(([, param]) => param.required).map(([key]) => key) : []
|
|
706
706
|
}
|
|
707
|
-
}));
|
|
707
|
+
})) || [];
|
|
708
|
+
const webSearchConfig = request.webSearch ?? this.config.webSearch;
|
|
709
|
+
let serverToolConfiguration;
|
|
710
|
+
if (webSearchConfig) {
|
|
711
|
+
tools.push({
|
|
712
|
+
type: "web_search_20260209",
|
|
713
|
+
name: "web_search",
|
|
714
|
+
allowed_callers: ["direct"]
|
|
715
|
+
});
|
|
716
|
+
const wsConfig = typeof webSearchConfig === "object" ? webSearchConfig : {};
|
|
717
|
+
const webSearchToolConfig = {};
|
|
718
|
+
if (wsConfig.maxUses !== void 0) {
|
|
719
|
+
webSearchToolConfig.max_uses = wsConfig.maxUses;
|
|
720
|
+
}
|
|
721
|
+
if (wsConfig.allowedDomains && wsConfig.allowedDomains.length > 0) {
|
|
722
|
+
webSearchToolConfig.allowed_domains = wsConfig.allowedDomains;
|
|
723
|
+
}
|
|
724
|
+
if (wsConfig.blockedDomains && wsConfig.blockedDomains.length > 0) {
|
|
725
|
+
webSearchToolConfig.blocked_domains = wsConfig.blockedDomains;
|
|
726
|
+
}
|
|
727
|
+
if (wsConfig.userLocation) {
|
|
728
|
+
webSearchToolConfig.user_location = wsConfig.userLocation;
|
|
729
|
+
}
|
|
730
|
+
if (Object.keys(webSearchToolConfig).length > 0) {
|
|
731
|
+
serverToolConfiguration = {
|
|
732
|
+
web_search: webSearchToolConfig
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
}
|
|
708
736
|
const options = {
|
|
709
737
|
model: request.config?.model || this.model,
|
|
710
738
|
max_tokens: request.config?.maxTokens || this.config.maxTokens || 4096,
|
|
711
739
|
system: systemMessage,
|
|
712
740
|
messages,
|
|
713
|
-
tools: tools
|
|
741
|
+
tools: tools.length ? tools : void 0
|
|
714
742
|
};
|
|
743
|
+
if (serverToolConfiguration) {
|
|
744
|
+
options.server_tool_configuration = serverToolConfiguration;
|
|
745
|
+
}
|
|
715
746
|
if (this.config.thinking?.type === "enabled") {
|
|
716
747
|
options.thinking = {
|
|
717
748
|
type: "enabled",
|
|
@@ -767,6 +798,8 @@ var AnthropicAdapter = class {
|
|
|
767
798
|
const stream = await client.messages.stream(options);
|
|
768
799
|
let currentToolUse = null;
|
|
769
800
|
let isInThinkingBlock = false;
|
|
801
|
+
const collectedCitations = [];
|
|
802
|
+
let citationIndex = 0;
|
|
770
803
|
let usage;
|
|
771
804
|
for await (const event of stream) {
|
|
772
805
|
if (request.signal?.aborted) {
|
|
@@ -795,11 +828,30 @@ var AnthropicAdapter = class {
|
|
|
795
828
|
name: event.content_block.name,
|
|
796
829
|
input: ""
|
|
797
830
|
};
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
831
|
+
if (currentToolUse.name !== "web_search") {
|
|
832
|
+
yield {
|
|
833
|
+
type: "action:start",
|
|
834
|
+
id: currentToolUse.id,
|
|
835
|
+
name: currentToolUse.name
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
} else if (event.content_block.type === "web_search_tool_result") {
|
|
839
|
+
const webSearchResult = event.content_block;
|
|
840
|
+
if (webSearchResult.content && Array.isArray(webSearchResult.content)) {
|
|
841
|
+
for (const result of webSearchResult.content) {
|
|
842
|
+
if (result.type === "web_search_result" && result.url) {
|
|
843
|
+
citationIndex++;
|
|
844
|
+
const domain = extractDomain(result.url);
|
|
845
|
+
collectedCitations.push({
|
|
846
|
+
index: citationIndex,
|
|
847
|
+
url: result.url,
|
|
848
|
+
title: result.title || domain,
|
|
849
|
+
domain,
|
|
850
|
+
favicon: domain ? `https://www.google.com/s2/favicons?domain=${domain}&sz=32` : void 0
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
803
855
|
} else if (event.content_block.type === "thinking") {
|
|
804
856
|
isInThinkingBlock = true;
|
|
805
857
|
yield { type: "thinking:start" };
|
|
@@ -808,6 +860,20 @@ var AnthropicAdapter = class {
|
|
|
808
860
|
case "content_block_delta":
|
|
809
861
|
if (event.delta.type === "text_delta") {
|
|
810
862
|
yield { type: "message:delta", content: event.delta.text };
|
|
863
|
+
} else if (event.delta.type === "citations_delta") {
|
|
864
|
+
const citationsDelta = event.delta;
|
|
865
|
+
if (citationsDelta.citation?.url) {
|
|
866
|
+
citationIndex++;
|
|
867
|
+
const domain = extractDomain(citationsDelta.citation.url);
|
|
868
|
+
collectedCitations.push({
|
|
869
|
+
index: citationIndex,
|
|
870
|
+
url: citationsDelta.citation.url,
|
|
871
|
+
title: citationsDelta.citation.title || domain,
|
|
872
|
+
citedText: citationsDelta.citation.cited_text,
|
|
873
|
+
domain,
|
|
874
|
+
favicon: domain ? `https://www.google.com/s2/favicons?domain=${domain}&sz=32` : void 0
|
|
875
|
+
});
|
|
876
|
+
}
|
|
811
877
|
} else if (event.delta.type === "thinking_delta") {
|
|
812
878
|
yield { type: "thinking:delta", content: event.delta.thinking };
|
|
813
879
|
} else if (event.delta.type === "input_json_delta" && currentToolUse) {
|
|
@@ -816,11 +882,18 @@ var AnthropicAdapter = class {
|
|
|
816
882
|
break;
|
|
817
883
|
case "content_block_stop":
|
|
818
884
|
if (currentToolUse) {
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
885
|
+
if (currentToolUse.name !== "web_search") {
|
|
886
|
+
yield {
|
|
887
|
+
type: "action:args",
|
|
888
|
+
id: currentToolUse.id,
|
|
889
|
+
args: currentToolUse.input
|
|
890
|
+
};
|
|
891
|
+
yield {
|
|
892
|
+
type: "action:end",
|
|
893
|
+
id: currentToolUse.id,
|
|
894
|
+
name: currentToolUse.name
|
|
895
|
+
};
|
|
896
|
+
}
|
|
824
897
|
currentToolUse = null;
|
|
825
898
|
}
|
|
826
899
|
if (isInThinkingBlock) {
|
|
@@ -832,6 +905,10 @@ var AnthropicAdapter = class {
|
|
|
832
905
|
break;
|
|
833
906
|
}
|
|
834
907
|
}
|
|
908
|
+
if (collectedCitations.length > 0) {
|
|
909
|
+
const uniqueCitations = deduplicateCitations(collectedCitations);
|
|
910
|
+
yield { type: "citation", citations: uniqueCitations };
|
|
911
|
+
}
|
|
835
912
|
yield { type: "message:end" };
|
|
836
913
|
yield { type: "done", usage };
|
|
837
914
|
} catch (error) {
|
|
@@ -843,6 +920,25 @@ var AnthropicAdapter = class {
|
|
|
843
920
|
}
|
|
844
921
|
}
|
|
845
922
|
};
|
|
923
|
+
function extractDomain(url) {
|
|
924
|
+
try {
|
|
925
|
+
const parsed = new URL(url);
|
|
926
|
+
return parsed.hostname;
|
|
927
|
+
} catch {
|
|
928
|
+
return "";
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
function deduplicateCitations(citations) {
|
|
932
|
+
const seen = /* @__PURE__ */ new Map();
|
|
933
|
+
let index = 0;
|
|
934
|
+
for (const citation of citations) {
|
|
935
|
+
if (!seen.has(citation.url)) {
|
|
936
|
+
index++;
|
|
937
|
+
seen.set(citation.url, { ...citation, index });
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
return Array.from(seen.values());
|
|
941
|
+
}
|
|
846
942
|
function createAnthropicAdapter(config) {
|
|
847
943
|
return new AnthropicAdapter(config);
|
|
848
944
|
}
|