@fairyhunter13/ai-anthropic 3.0.58-fork.2 → 3.0.58-fork.21
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/CHANGELOG.md +101 -4
- package/dist/index.d.mts +85 -6
- package/dist/index.d.ts +85 -6
- package/dist/index.js +696 -376
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +671 -347
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +124 -14
- package/dist/internal/index.d.ts +124 -14
- package/dist/internal/index.js +690 -368
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +670 -345
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +53 -6
- package/package.json +7 -7
- package/src/anthropic-messages-api.ts +31 -7
- package/src/anthropic-messages-language-model.ts +272 -36
- package/src/anthropic-messages-options.ts +24 -0
- package/src/anthropic-prepare-tools.ts +50 -14
- package/src/anthropic-provider.ts +8 -8
- package/src/anthropic-tools.ts +18 -0
- package/src/convert-anthropic-messages-usage.ts +2 -2
- package/src/convert-to-anthropic-messages-prompt.ts +47 -27
- package/src/get-cache-control.ts +5 -5
- package/src/internal/index.ts +4 -1
- package/src/map-anthropic-stop-reason.ts +2 -2
- package/src/tool/web-fetch-20260309.ts +182 -0
- package/src/tool/web-search_20260209.ts +17 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,102 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [1f509d4]
|
|
8
|
+
- @ai-sdk/provider-utils@5.0.0-beta.7
|
|
9
|
+
- @ai-sdk/provider@4.0.0-beta.5
|
|
10
|
+
|
|
11
|
+
## 4.0.0-beta.11
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 0ee8aec: feat (provider/anthropic): support passing metadata.user_id
|
|
16
|
+
|
|
17
|
+
## 4.0.0-beta.10
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 3887c70: feat(provider): add new top-level reasoning parameter to spec and support it in `generateText` and `streamText`
|
|
22
|
+
- Updated dependencies [3887c70]
|
|
23
|
+
- @ai-sdk/provider-utils@5.0.0-beta.6
|
|
24
|
+
- @ai-sdk/provider@4.0.0-beta.4
|
|
25
|
+
|
|
26
|
+
## 4.0.0-beta.9
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [776b617]
|
|
31
|
+
- @ai-sdk/provider-utils@5.0.0-beta.5
|
|
32
|
+
- @ai-sdk/provider@4.0.0-beta.3
|
|
33
|
+
|
|
34
|
+
## 4.0.0-beta.8
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- Updated dependencies [61753c3]
|
|
39
|
+
- @ai-sdk/provider-utils@5.0.0-beta.4
|
|
40
|
+
|
|
41
|
+
## 4.0.0-beta.7
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- Updated dependencies [f7d4f01]
|
|
46
|
+
- @ai-sdk/provider-utils@5.0.0-beta.3
|
|
47
|
+
- @ai-sdk/provider@4.0.0-beta.2
|
|
48
|
+
|
|
49
|
+
## 4.0.0-beta.6
|
|
50
|
+
|
|
51
|
+
### Patch Changes
|
|
52
|
+
|
|
53
|
+
- 21d1ee3: fix(anthropic): skip passing beta header for tool search tools
|
|
54
|
+
|
|
55
|
+
## 4.0.0-beta.5
|
|
56
|
+
|
|
57
|
+
### Patch Changes
|
|
58
|
+
|
|
59
|
+
- Updated dependencies [5c2a5a2]
|
|
60
|
+
- @ai-sdk/provider@4.0.0-beta.1
|
|
61
|
+
- @ai-sdk/provider-utils@5.0.0-beta.2
|
|
62
|
+
|
|
63
|
+
## 4.0.0-beta.4
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- f05a40d: fix(vertex): throw warning when strict: true for vertexAnthropic
|
|
68
|
+
|
|
69
|
+
## 4.0.0-beta.3
|
|
70
|
+
|
|
71
|
+
### Patch Changes
|
|
72
|
+
|
|
73
|
+
- e748b35: chore: update v3 specs to v4
|
|
74
|
+
|
|
75
|
+
## 4.0.0-beta.2
|
|
76
|
+
|
|
77
|
+
### Patch Changes
|
|
78
|
+
|
|
79
|
+
- 1fe058b: fix(anthropic): preserve the error code returned by model
|
|
80
|
+
|
|
81
|
+
## 4.0.0-beta.1
|
|
82
|
+
|
|
83
|
+
### Patch Changes
|
|
84
|
+
|
|
85
|
+
- Updated dependencies [531251e]
|
|
86
|
+
- @ai-sdk/provider-utils@5.0.0-beta.1
|
|
87
|
+
|
|
88
|
+
## 4.0.0-beta.0
|
|
89
|
+
|
|
90
|
+
### Major Changes
|
|
91
|
+
|
|
92
|
+
- 8359612: Start v7 pre-release
|
|
93
|
+
|
|
94
|
+
### Patch Changes
|
|
95
|
+
|
|
96
|
+
- Updated dependencies [8359612]
|
|
97
|
+
- @ai-sdk/provider@4.0.0-beta.0
|
|
98
|
+
- @ai-sdk/provider-utils@5.0.0-beta.0
|
|
99
|
+
|
|
3
100
|
## 3.0.58
|
|
4
101
|
|
|
5
102
|
### Patch Changes
|
|
@@ -415,13 +512,13 @@
|
|
|
415
512
|
Before
|
|
416
513
|
|
|
417
514
|
```ts
|
|
418
|
-
model.textEmbeddingModel(
|
|
515
|
+
model.textEmbeddingModel("my-model-id");
|
|
419
516
|
```
|
|
420
517
|
|
|
421
518
|
After
|
|
422
519
|
|
|
423
520
|
```ts
|
|
424
|
-
model.embeddingModel(
|
|
521
|
+
model.embeddingModel("my-model-id");
|
|
425
522
|
```
|
|
426
523
|
|
|
427
524
|
- f33a018: chore: add model ID for Haiku 4.5
|
|
@@ -761,13 +858,13 @@
|
|
|
761
858
|
Before
|
|
762
859
|
|
|
763
860
|
```ts
|
|
764
|
-
model.textEmbeddingModel(
|
|
861
|
+
model.textEmbeddingModel("my-model-id");
|
|
765
862
|
```
|
|
766
863
|
|
|
767
864
|
After
|
|
768
865
|
|
|
769
866
|
```ts
|
|
770
|
-
model.embeddingModel(
|
|
867
|
+
model.embeddingModel("my-model-id");
|
|
771
868
|
```
|
|
772
869
|
|
|
773
870
|
- Updated dependencies [8d9e8ad]
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSONObject,
|
|
1
|
+
import { JSONObject, ProviderV4, LanguageModelV4 } from '@ai-sdk/provider';
|
|
2
2
|
import { z } from 'zod/v4';
|
|
3
3
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
4
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
@@ -157,6 +157,9 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
|
|
|
157
157
|
type: z.ZodLiteral<"ephemeral">;
|
|
158
158
|
ttl: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
|
|
159
159
|
}, z.core.$strip>>;
|
|
160
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
161
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
162
|
+
}, z.core.$strip>>;
|
|
160
163
|
mcpServers: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
161
164
|
type: z.ZodLiteral<"url">;
|
|
162
165
|
name: z.ZodString;
|
|
@@ -188,6 +191,9 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
|
|
|
188
191
|
}>>;
|
|
189
192
|
anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
190
193
|
prefill: z.ZodOptional<z.ZodString>;
|
|
194
|
+
serviceTier: z.ZodOptional<z.ZodEnum<{
|
|
195
|
+
auto: "auto";
|
|
196
|
+
}>>;
|
|
191
197
|
contextManagement: z.ZodOptional<z.ZodObject<{
|
|
192
198
|
edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
193
199
|
type: z.ZodLiteral<"clear_tool_uses_20250919">;
|
|
@@ -890,6 +896,78 @@ declare const anthropicTools: {
|
|
|
890
896
|
};
|
|
891
897
|
retrievedAt: string | null;
|
|
892
898
|
}>;
|
|
899
|
+
/**
|
|
900
|
+
* Creates a web fetch tool that gives Claude direct access to real-time web content.
|
|
901
|
+
* GA version (no beta header required). Includes caller restrictions, cache control,
|
|
902
|
+
* deferred loading, and strict mode.
|
|
903
|
+
*
|
|
904
|
+
* @param maxUses - The max_uses parameter limits the number of web fetches performed
|
|
905
|
+
* @param allowedDomains - Only fetch from these domains
|
|
906
|
+
* @param blockedDomains - Never fetch from these domains
|
|
907
|
+
* @param citations - Citations configuration for fetched documents
|
|
908
|
+
* @param maxContentTokens - Max content tokens included in context
|
|
909
|
+
* @param allowedCallers - Restrict callers (e.g. ["direct"] to prevent code_execution usage)
|
|
910
|
+
* @param useCache - Whether to use cached content (set false for fresh content)
|
|
911
|
+
* @param deferLoading - Defer loading until tool_search discovers it
|
|
912
|
+
* @param strict - Enable strict schema validation
|
|
913
|
+
*/
|
|
914
|
+
webFetch_20260309: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{
|
|
915
|
+
url: string;
|
|
916
|
+
}, {
|
|
917
|
+
type: "web_fetch_result";
|
|
918
|
+
url: string;
|
|
919
|
+
content: {
|
|
920
|
+
type: "document";
|
|
921
|
+
title: string | null;
|
|
922
|
+
citations?: {
|
|
923
|
+
enabled: boolean;
|
|
924
|
+
};
|
|
925
|
+
source: {
|
|
926
|
+
type: "base64";
|
|
927
|
+
mediaType: "application/pdf";
|
|
928
|
+
data: string;
|
|
929
|
+
} | {
|
|
930
|
+
type: "text";
|
|
931
|
+
mediaType: "text/plain";
|
|
932
|
+
data: string;
|
|
933
|
+
};
|
|
934
|
+
};
|
|
935
|
+
retrievedAt: string | null;
|
|
936
|
+
}, {
|
|
937
|
+
maxUses?: number;
|
|
938
|
+
allowedDomains?: string[];
|
|
939
|
+
blockedDomains?: string[];
|
|
940
|
+
citations?: {
|
|
941
|
+
enabled: boolean;
|
|
942
|
+
};
|
|
943
|
+
maxContentTokens?: number;
|
|
944
|
+
allowedCallers?: Array<"direct" | "code_execution_20250825" | "code_execution_20260120">;
|
|
945
|
+
useCache?: boolean;
|
|
946
|
+
deferLoading?: boolean;
|
|
947
|
+
strict?: boolean;
|
|
948
|
+
}>>[0]) => _ai_sdk_provider_utils.Tool<{
|
|
949
|
+
url: string;
|
|
950
|
+
}, {
|
|
951
|
+
type: "web_fetch_result";
|
|
952
|
+
url: string;
|
|
953
|
+
content: {
|
|
954
|
+
type: "document";
|
|
955
|
+
title: string | null;
|
|
956
|
+
citations?: {
|
|
957
|
+
enabled: boolean;
|
|
958
|
+
};
|
|
959
|
+
source: {
|
|
960
|
+
type: "base64";
|
|
961
|
+
mediaType: "application/pdf";
|
|
962
|
+
data: string;
|
|
963
|
+
} | {
|
|
964
|
+
type: "text";
|
|
965
|
+
mediaType: "text/plain";
|
|
966
|
+
data: string;
|
|
967
|
+
};
|
|
968
|
+
};
|
|
969
|
+
retrievedAt: string | null;
|
|
970
|
+
}>;
|
|
893
971
|
/**
|
|
894
972
|
* Creates a web search tool that gives Claude direct access to real-time web content.
|
|
895
973
|
*
|
|
@@ -953,6 +1031,7 @@ declare const anthropicTools: {
|
|
|
953
1031
|
country?: string;
|
|
954
1032
|
timezone?: string;
|
|
955
1033
|
};
|
|
1034
|
+
allowedCallers?: Array<"direct" | "code_execution_20250825" | "code_execution_20260120">;
|
|
956
1035
|
}>>[0]) => _ai_sdk_provider_utils.Tool<{
|
|
957
1036
|
query: string;
|
|
958
1037
|
}, {
|
|
@@ -1016,17 +1095,17 @@ declare const anthropicTools: {
|
|
|
1016
1095
|
}[]>;
|
|
1017
1096
|
};
|
|
1018
1097
|
|
|
1019
|
-
interface AnthropicProvider extends
|
|
1098
|
+
interface AnthropicProvider extends ProviderV4 {
|
|
1020
1099
|
/**
|
|
1021
1100
|
* Creates a model for text generation.
|
|
1022
1101
|
*/
|
|
1023
|
-
(modelId: AnthropicMessagesModelId):
|
|
1102
|
+
(modelId: AnthropicMessagesModelId): LanguageModelV4;
|
|
1024
1103
|
/**
|
|
1025
1104
|
* Creates a model for text generation.
|
|
1026
1105
|
*/
|
|
1027
|
-
languageModel(modelId: AnthropicMessagesModelId):
|
|
1028
|
-
chat(modelId: AnthropicMessagesModelId):
|
|
1029
|
-
messages(modelId: AnthropicMessagesModelId):
|
|
1106
|
+
languageModel(modelId: AnthropicMessagesModelId): LanguageModelV4;
|
|
1107
|
+
chat(modelId: AnthropicMessagesModelId): LanguageModelV4;
|
|
1108
|
+
messages(modelId: AnthropicMessagesModelId): LanguageModelV4;
|
|
1030
1109
|
/**
|
|
1031
1110
|
* @deprecated Use `embeddingModel` instead.
|
|
1032
1111
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSONObject,
|
|
1
|
+
import { JSONObject, ProviderV4, LanguageModelV4 } from '@ai-sdk/provider';
|
|
2
2
|
import { z } from 'zod/v4';
|
|
3
3
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
4
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
@@ -157,6 +157,9 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
|
|
|
157
157
|
type: z.ZodLiteral<"ephemeral">;
|
|
158
158
|
ttl: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
|
|
159
159
|
}, z.core.$strip>>;
|
|
160
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
161
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
162
|
+
}, z.core.$strip>>;
|
|
160
163
|
mcpServers: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
161
164
|
type: z.ZodLiteral<"url">;
|
|
162
165
|
name: z.ZodString;
|
|
@@ -188,6 +191,9 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
|
|
|
188
191
|
}>>;
|
|
189
192
|
anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
190
193
|
prefill: z.ZodOptional<z.ZodString>;
|
|
194
|
+
serviceTier: z.ZodOptional<z.ZodEnum<{
|
|
195
|
+
auto: "auto";
|
|
196
|
+
}>>;
|
|
191
197
|
contextManagement: z.ZodOptional<z.ZodObject<{
|
|
192
198
|
edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
193
199
|
type: z.ZodLiteral<"clear_tool_uses_20250919">;
|
|
@@ -890,6 +896,78 @@ declare const anthropicTools: {
|
|
|
890
896
|
};
|
|
891
897
|
retrievedAt: string | null;
|
|
892
898
|
}>;
|
|
899
|
+
/**
|
|
900
|
+
* Creates a web fetch tool that gives Claude direct access to real-time web content.
|
|
901
|
+
* GA version (no beta header required). Includes caller restrictions, cache control,
|
|
902
|
+
* deferred loading, and strict mode.
|
|
903
|
+
*
|
|
904
|
+
* @param maxUses - The max_uses parameter limits the number of web fetches performed
|
|
905
|
+
* @param allowedDomains - Only fetch from these domains
|
|
906
|
+
* @param blockedDomains - Never fetch from these domains
|
|
907
|
+
* @param citations - Citations configuration for fetched documents
|
|
908
|
+
* @param maxContentTokens - Max content tokens included in context
|
|
909
|
+
* @param allowedCallers - Restrict callers (e.g. ["direct"] to prevent code_execution usage)
|
|
910
|
+
* @param useCache - Whether to use cached content (set false for fresh content)
|
|
911
|
+
* @param deferLoading - Defer loading until tool_search discovers it
|
|
912
|
+
* @param strict - Enable strict schema validation
|
|
913
|
+
*/
|
|
914
|
+
webFetch_20260309: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{
|
|
915
|
+
url: string;
|
|
916
|
+
}, {
|
|
917
|
+
type: "web_fetch_result";
|
|
918
|
+
url: string;
|
|
919
|
+
content: {
|
|
920
|
+
type: "document";
|
|
921
|
+
title: string | null;
|
|
922
|
+
citations?: {
|
|
923
|
+
enabled: boolean;
|
|
924
|
+
};
|
|
925
|
+
source: {
|
|
926
|
+
type: "base64";
|
|
927
|
+
mediaType: "application/pdf";
|
|
928
|
+
data: string;
|
|
929
|
+
} | {
|
|
930
|
+
type: "text";
|
|
931
|
+
mediaType: "text/plain";
|
|
932
|
+
data: string;
|
|
933
|
+
};
|
|
934
|
+
};
|
|
935
|
+
retrievedAt: string | null;
|
|
936
|
+
}, {
|
|
937
|
+
maxUses?: number;
|
|
938
|
+
allowedDomains?: string[];
|
|
939
|
+
blockedDomains?: string[];
|
|
940
|
+
citations?: {
|
|
941
|
+
enabled: boolean;
|
|
942
|
+
};
|
|
943
|
+
maxContentTokens?: number;
|
|
944
|
+
allowedCallers?: Array<"direct" | "code_execution_20250825" | "code_execution_20260120">;
|
|
945
|
+
useCache?: boolean;
|
|
946
|
+
deferLoading?: boolean;
|
|
947
|
+
strict?: boolean;
|
|
948
|
+
}>>[0]) => _ai_sdk_provider_utils.Tool<{
|
|
949
|
+
url: string;
|
|
950
|
+
}, {
|
|
951
|
+
type: "web_fetch_result";
|
|
952
|
+
url: string;
|
|
953
|
+
content: {
|
|
954
|
+
type: "document";
|
|
955
|
+
title: string | null;
|
|
956
|
+
citations?: {
|
|
957
|
+
enabled: boolean;
|
|
958
|
+
};
|
|
959
|
+
source: {
|
|
960
|
+
type: "base64";
|
|
961
|
+
mediaType: "application/pdf";
|
|
962
|
+
data: string;
|
|
963
|
+
} | {
|
|
964
|
+
type: "text";
|
|
965
|
+
mediaType: "text/plain";
|
|
966
|
+
data: string;
|
|
967
|
+
};
|
|
968
|
+
};
|
|
969
|
+
retrievedAt: string | null;
|
|
970
|
+
}>;
|
|
893
971
|
/**
|
|
894
972
|
* Creates a web search tool that gives Claude direct access to real-time web content.
|
|
895
973
|
*
|
|
@@ -953,6 +1031,7 @@ declare const anthropicTools: {
|
|
|
953
1031
|
country?: string;
|
|
954
1032
|
timezone?: string;
|
|
955
1033
|
};
|
|
1034
|
+
allowedCallers?: Array<"direct" | "code_execution_20250825" | "code_execution_20260120">;
|
|
956
1035
|
}>>[0]) => _ai_sdk_provider_utils.Tool<{
|
|
957
1036
|
query: string;
|
|
958
1037
|
}, {
|
|
@@ -1016,17 +1095,17 @@ declare const anthropicTools: {
|
|
|
1016
1095
|
}[]>;
|
|
1017
1096
|
};
|
|
1018
1097
|
|
|
1019
|
-
interface AnthropicProvider extends
|
|
1098
|
+
interface AnthropicProvider extends ProviderV4 {
|
|
1020
1099
|
/**
|
|
1021
1100
|
* Creates a model for text generation.
|
|
1022
1101
|
*/
|
|
1023
|
-
(modelId: AnthropicMessagesModelId):
|
|
1102
|
+
(modelId: AnthropicMessagesModelId): LanguageModelV4;
|
|
1024
1103
|
/**
|
|
1025
1104
|
* Creates a model for text generation.
|
|
1026
1105
|
*/
|
|
1027
|
-
languageModel(modelId: AnthropicMessagesModelId):
|
|
1028
|
-
chat(modelId: AnthropicMessagesModelId):
|
|
1029
|
-
messages(modelId: AnthropicMessagesModelId):
|
|
1106
|
+
languageModel(modelId: AnthropicMessagesModelId): LanguageModelV4;
|
|
1107
|
+
chat(modelId: AnthropicMessagesModelId): LanguageModelV4;
|
|
1108
|
+
messages(modelId: AnthropicMessagesModelId): LanguageModelV4;
|
|
1030
1109
|
/**
|
|
1031
1110
|
* @deprecated Use `embeddingModel` instead.
|
|
1032
1111
|
*/
|