@ai-sdk/anthropic 4.0.54 → 4.0.56
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 +26 -0
- package/dist/index.d.ts +107 -1
- package/dist/index.js +662 -484
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +109 -2
- package/dist/internal/index.js +608 -435
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +91 -7
- package/package.json +3 -3
- package/src/anthropic-api.ts +8 -2
- package/src/anthropic-language-model.ts +14 -12
- package/src/anthropic-prepare-tools.ts +38 -0
- package/src/anthropic-provider.ts +10 -0
- package/src/anthropic-tools.ts +26 -0
- package/src/convert-to-anthropic-prompt.ts +8 -7
- package/src/tool/web-fetch-20260318.ts +159 -0
- package/src/tool/web-search_20260318.ts +143 -0
package/docs/05-anthropic.mdx
CHANGED
|
@@ -1052,12 +1052,13 @@ You can enable web search using the provider-defined web search tool:
|
|
|
1052
1052
|
import { anthropic } from '@ai-sdk/anthropic';
|
|
1053
1053
|
import { generateText } from 'ai';
|
|
1054
1054
|
|
|
1055
|
-
const webSearchTool = anthropic.tools.
|
|
1055
|
+
const webSearchTool = anthropic.tools.webSearch_20260318({
|
|
1056
1056
|
maxUses: 5,
|
|
1057
|
+
responseInclusion: 'excluded',
|
|
1057
1058
|
});
|
|
1058
1059
|
|
|
1059
1060
|
const result = await generateText({
|
|
1060
|
-
model: anthropic('claude-opus-
|
|
1061
|
+
model: anthropic('claude-opus-5'),
|
|
1061
1062
|
prompt: 'What are the latest developments in AI?',
|
|
1062
1063
|
tools: {
|
|
1063
1064
|
web_search: webSearchTool,
|
|
@@ -1072,6 +1073,10 @@ const result = await generateText({
|
|
|
1072
1073
|
|
|
1073
1074
|
#### Configuration Options
|
|
1074
1075
|
|
|
1076
|
+
Use `webSearch_20260318` for dynamic filtering and response inclusion control.
|
|
1077
|
+
The older `webSearch_20260209` and `webSearch_20250305` versions remain
|
|
1078
|
+
available for applications that need their earlier behavior.
|
|
1079
|
+
|
|
1075
1080
|
The web search tool supports several configuration options:
|
|
1076
1081
|
|
|
1077
1082
|
- **maxUses** _number_
|
|
@@ -1090,11 +1095,17 @@ The web search tool supports several configuration options:
|
|
|
1090
1095
|
|
|
1091
1096
|
Optional user location information to provide geographically relevant search results.
|
|
1092
1097
|
|
|
1098
|
+
- **responseInclusion** _'full' | 'excluded'_
|
|
1099
|
+
|
|
1100
|
+
Available with `webSearch_20260318`. Controls whether search result blocks
|
|
1101
|
+
consumed by a completed code execution call in the same turn are included in
|
|
1102
|
+
the API response. The default is `'full'`. Use `'excluded'` to omit those
|
|
1103
|
+
nested call/result pairs and reduce output token usage.
|
|
1104
|
+
|
|
1093
1105
|
```ts
|
|
1094
|
-
const webSearchTool = anthropic.tools.
|
|
1106
|
+
const webSearchTool = anthropic.tools.webSearch_20260318({
|
|
1095
1107
|
maxUses: 3,
|
|
1096
1108
|
allowedDomains: ['techcrunch.com', 'wired.com'],
|
|
1097
|
-
blockedDomains: ['example-spam-site.com'],
|
|
1098
1109
|
userLocation: {
|
|
1099
1110
|
type: 'approximate',
|
|
1100
1111
|
country: 'US',
|
|
@@ -1102,10 +1113,11 @@ const webSearchTool = anthropic.tools.webSearch_20250305({
|
|
|
1102
1113
|
city: 'San Francisco',
|
|
1103
1114
|
timezone: 'America/Los_Angeles',
|
|
1104
1115
|
},
|
|
1116
|
+
responseInclusion: 'excluded',
|
|
1105
1117
|
});
|
|
1106
1118
|
|
|
1107
1119
|
const result = await generateText({
|
|
1108
|
-
model: anthropic('claude-opus-
|
|
1120
|
+
model: anthropic('claude-opus-5'),
|
|
1109
1121
|
prompt: 'Find local news about technology',
|
|
1110
1122
|
tools: {
|
|
1111
1123
|
web_search: webSearchTool,
|
|
@@ -1113,6 +1125,13 @@ const result = await generateText({
|
|
|
1113
1125
|
});
|
|
1114
1126
|
```
|
|
1115
1127
|
|
|
1128
|
+
<Note>
|
|
1129
|
+
`responseInclusion: 'excluded'` only omits results consumed by code execution
|
|
1130
|
+
calls that complete in the same turn. Results from direct calls and from code
|
|
1131
|
+
execution calls that pause before completing are always returned in full so
|
|
1132
|
+
they can be sent back on the next turn.
|
|
1133
|
+
</Note>
|
|
1134
|
+
|
|
1116
1135
|
### Web Fetch Tool
|
|
1117
1136
|
|
|
1118
1137
|
Anthropic provides a provider-defined web fetch tool that allows Claude to retrieve content from specific URLs. This is useful when you want Claude to analyze or reference content from a particular webpage or document.
|
|
@@ -1124,11 +1143,14 @@ import { anthropic } from '@ai-sdk/anthropic';
|
|
|
1124
1143
|
import { generateText } from 'ai';
|
|
1125
1144
|
|
|
1126
1145
|
const result = await generateText({
|
|
1127
|
-
model: anthropic('claude-
|
|
1146
|
+
model: anthropic('claude-opus-5'),
|
|
1128
1147
|
prompt:
|
|
1129
1148
|
'What is this page about? https://en.wikipedia.org/wiki/Maglemosian_culture',
|
|
1130
1149
|
tools: {
|
|
1131
|
-
web_fetch: anthropic.tools.
|
|
1150
|
+
web_fetch: anthropic.tools.webFetch_20260318({
|
|
1151
|
+
maxUses: 1,
|
|
1152
|
+
responseInclusion: 'excluded',
|
|
1153
|
+
}),
|
|
1132
1154
|
},
|
|
1133
1155
|
});
|
|
1134
1156
|
```
|
|
@@ -1473,6 +1495,19 @@ The web fetch tool supports several configuration options:
|
|
|
1473
1495
|
|
|
1474
1496
|
The maxContentTokens parameter limits the amount of content that will be included in the context.
|
|
1475
1497
|
|
|
1498
|
+
- **useCache** _boolean_
|
|
1499
|
+
|
|
1500
|
+
Available with `webFetch_20260318`. Set to `false` to bypass cached content
|
|
1501
|
+
and fetch fresh content. The default is `true`; disabling the cache can
|
|
1502
|
+
increase latency.
|
|
1503
|
+
|
|
1504
|
+
- **responseInclusion** _'full' | 'excluded'_
|
|
1505
|
+
|
|
1506
|
+
Available with `webFetch_20260318`. Controls whether fetch result blocks
|
|
1507
|
+
consumed by a completed code execution call in the same turn are included in
|
|
1508
|
+
the API response. The default is `'full'`. Direct results and results from
|
|
1509
|
+
code execution calls that pause before completing are always returned in full.
|
|
1510
|
+
|
|
1476
1511
|
#### Error Handling
|
|
1477
1512
|
|
|
1478
1513
|
Web search errors are handled differently depending on whether you're using streaming or non-streaming:
|
|
@@ -1858,3 +1893,52 @@ and the `mediaType` should be set to `'application/pdf'`.
|
|
|
1858
1893
|
of available models. The table above lists popular models. You can also pass
|
|
1859
1894
|
any available provider model ID as a string if needed.
|
|
1860
1895
|
</Note>
|
|
1896
|
+
|
|
1897
|
+
## Evaluation Models
|
|
1898
|
+
|
|
1899
|
+
Create an experimental evaluation model with `anthropic.evaluationModel(modelId)`.
|
|
1900
|
+
It uses the Messages API's structured-output support for Choice, Score, and Boolean
|
|
1901
|
+
questions. `claude-haiku-4-5-20251001` is one supported model.
|
|
1902
|
+
|
|
1903
|
+
```ts
|
|
1904
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
1905
|
+
import { experimental_evaluate } from 'ai';
|
|
1906
|
+
|
|
1907
|
+
const { answers } = await experimental_evaluate({
|
|
1908
|
+
model: anthropic.evaluationModel('claude-haiku-4-5-20251001'),
|
|
1909
|
+
state: 'I was charged twice.',
|
|
1910
|
+
questions: {
|
|
1911
|
+
requestsRefund: {
|
|
1912
|
+
type: 'boolean',
|
|
1913
|
+
instructions: 'Is the customer requesting money back?',
|
|
1914
|
+
},
|
|
1915
|
+
department: {
|
|
1916
|
+
type: 'choice',
|
|
1917
|
+
instructions: 'Which team should handle this?',
|
|
1918
|
+
criteria: { billing: 'Charges and refunds', support: 'Other requests' },
|
|
1919
|
+
},
|
|
1920
|
+
},
|
|
1921
|
+
});
|
|
1922
|
+
```
|
|
1923
|
+
|
|
1924
|
+
Choice labels are preserved exactly, and Scores are finite fractional positions
|
|
1925
|
+
on the ordered rubric. Anthropic does not support numeric bounds in its native
|
|
1926
|
+
output schema, so the adapter describes them in the prompt and validates them
|
|
1927
|
+
after parsing. Invalid answers, refusals, and truncation fail the entire call.
|
|
1928
|
+
|
|
1929
|
+
The adapter returns no probability distributions for Choice or Score. Boolean
|
|
1930
|
+
answers contain prompted estimates of P(true), validated to be finite and in
|
|
1931
|
+
`[0, 1]`. These estimates are not guaranteed to be calibrated. Apply thresholds
|
|
1932
|
+
in application code, for example `answers.requestsRefund.probability >= 0.5`.
|
|
1933
|
+
It respects
|
|
1934
|
+
`createAnthropic` configuration and forwards `providerOptions.anthropic`, including
|
|
1935
|
+
`structuredOutputMode`. Supported models use native structured output by default;
|
|
1936
|
+
`jsonTool` uses the existing Messages JSON-tool fallback. Usage, warnings,
|
|
1937
|
+
response information, and provider metadata are preserved.
|
|
1938
|
+
See [Evaluation](/docs/ai-sdk-core/evaluation).
|
|
1939
|
+
|
|
1940
|
+
Evaluation models can also be accessed through `customProvider` aliases or
|
|
1941
|
+
`createProviderRegistry().evaluationModel('provider:model')`. Direct string IDs
|
|
1942
|
+
require an explicitly configured default provider with an `evaluationModel`
|
|
1943
|
+
method; they do not automatically use Gateway. See
|
|
1944
|
+
[model aliases and registries](/docs/ai-sdk-core/evaluation#model-aliases-and-registries).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/anthropic",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.56",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ai-sdk/provider": "4.0.
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
38
|
+
"@ai-sdk/provider": "4.0.17",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.43"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@ai-sdk/test-server": "2.0.1",
|
package/src/anthropic-api.ts
CHANGED
|
@@ -508,17 +508,22 @@ export type AnthropicTool =
|
|
|
508
508
|
type: 'memory_20250818';
|
|
509
509
|
}
|
|
510
510
|
| {
|
|
511
|
-
type: 'web_fetch_20250910' | 'web_fetch_20260209';
|
|
511
|
+
type: 'web_fetch_20250910' | 'web_fetch_20260209' | 'web_fetch_20260318';
|
|
512
512
|
name: string;
|
|
513
513
|
max_uses?: number;
|
|
514
514
|
allowed_domains?: string[];
|
|
515
515
|
blocked_domains?: string[];
|
|
516
516
|
citations?: { enabled: boolean };
|
|
517
517
|
max_content_tokens?: number;
|
|
518
|
+
use_cache?: boolean;
|
|
519
|
+
response_inclusion?: 'full' | 'excluded';
|
|
518
520
|
cache_control: AnthropicCacheControl | undefined;
|
|
519
521
|
}
|
|
520
522
|
| {
|
|
521
|
-
type:
|
|
523
|
+
type:
|
|
524
|
+
| 'web_search_20250305'
|
|
525
|
+
| 'web_search_20260209'
|
|
526
|
+
| 'web_search_20260318';
|
|
522
527
|
name: string;
|
|
523
528
|
max_uses?: number;
|
|
524
529
|
allowed_domains?: string[];
|
|
@@ -530,6 +535,7 @@ export type AnthropicTool =
|
|
|
530
535
|
country?: string;
|
|
531
536
|
timezone?: string;
|
|
532
537
|
};
|
|
538
|
+
response_inclusion?: 'full' | 'excluded';
|
|
533
539
|
cache_control: AnthropicCacheControl | undefined;
|
|
534
540
|
}
|
|
535
541
|
| {
|
|
@@ -465,8 +465,10 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
465
465
|
'anthropic.memory_20250818': 'memory',
|
|
466
466
|
'anthropic.web_search_20250305': 'web_search',
|
|
467
467
|
'anthropic.web_search_20260209': 'web_search',
|
|
468
|
+
'anthropic.web_search_20260318': 'web_search',
|
|
468
469
|
'anthropic.web_fetch_20250910': 'web_fetch',
|
|
469
470
|
'anthropic.web_fetch_20260209': 'web_fetch',
|
|
471
|
+
'anthropic.web_fetch_20260318': 'web_fetch',
|
|
470
472
|
'anthropic.tool_search_regex_20251119': 'tool_search_tool_regex',
|
|
471
473
|
'anthropic.tool_search_bm25_20251119': 'tool_search_tool_bm25',
|
|
472
474
|
'anthropic.advisor_20260301': 'advisor',
|
|
@@ -1046,9 +1048,8 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1046
1048
|
...this.extractCitationDocuments(options.prompt),
|
|
1047
1049
|
];
|
|
1048
1050
|
|
|
1049
|
-
const markCodeExecutionDynamic =
|
|
1050
|
-
args.tools
|
|
1051
|
-
);
|
|
1051
|
+
const markCodeExecutionDynamic =
|
|
1052
|
+
hasDynamicFilteringWebToolWithoutCodeExecution(args.tools);
|
|
1052
1053
|
|
|
1053
1054
|
const {
|
|
1054
1055
|
responseHeaders,
|
|
@@ -1637,9 +1638,8 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1637
1638
|
...this.extractCitationDocuments(options.prompt),
|
|
1638
1639
|
];
|
|
1639
1640
|
|
|
1640
|
-
const markCodeExecutionDynamic =
|
|
1641
|
-
body.tools
|
|
1642
|
-
);
|
|
1641
|
+
const markCodeExecutionDynamic =
|
|
1642
|
+
hasDynamicFilteringWebToolWithoutCodeExecution(body.tools);
|
|
1643
1643
|
|
|
1644
1644
|
const url = this.buildRequestUrl(true);
|
|
1645
1645
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
@@ -1903,7 +1903,7 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1903
1903
|
const customToolName =
|
|
1904
1904
|
toolNameMapping.toCustomToolName(providerToolName);
|
|
1905
1905
|
|
|
1906
|
-
//
|
|
1906
|
+
// Dynamic web tools provide input data here.
|
|
1907
1907
|
// Other tools like 'code_execution_20260120' provide input data via deltas.
|
|
1908
1908
|
// So we only use this if it's non-empty to avoid conflicts.
|
|
1909
1909
|
const finalInput =
|
|
@@ -2978,21 +2978,23 @@ export function getModelCapabilities(modelId: string): {
|
|
|
2978
2978
|
}
|
|
2979
2979
|
}
|
|
2980
2980
|
|
|
2981
|
-
export function
|
|
2981
|
+
export function hasDynamicFilteringWebToolWithoutCodeExecution(
|
|
2982
2982
|
tools: AnthropicTool[] | undefined,
|
|
2983
2983
|
): boolean {
|
|
2984
2984
|
if (!tools) {
|
|
2985
2985
|
return false;
|
|
2986
2986
|
}
|
|
2987
|
-
let
|
|
2987
|
+
let hasDynamicFilteringWebTool = false;
|
|
2988
2988
|
let hasCodeExecutionTool = false;
|
|
2989
2989
|
for (const tool of tools) {
|
|
2990
2990
|
if (
|
|
2991
2991
|
'type' in tool &&
|
|
2992
2992
|
(tool.type === 'web_fetch_20260209' ||
|
|
2993
|
-
tool.type === '
|
|
2993
|
+
tool.type === 'web_fetch_20260318' ||
|
|
2994
|
+
tool.type === 'web_search_20260209' ||
|
|
2995
|
+
tool.type === 'web_search_20260318')
|
|
2994
2996
|
) {
|
|
2995
|
-
|
|
2997
|
+
hasDynamicFilteringWebTool = true;
|
|
2996
2998
|
continue;
|
|
2997
2999
|
}
|
|
2998
3000
|
if (
|
|
@@ -3005,7 +3007,7 @@ export function hasWebTool20260209WithoutCodeExecution(
|
|
|
3005
3007
|
break;
|
|
3006
3008
|
}
|
|
3007
3009
|
}
|
|
3008
|
-
return
|
|
3010
|
+
return hasDynamicFilteringWebTool && !hasCodeExecutionTool;
|
|
3009
3011
|
}
|
|
3010
3012
|
|
|
3011
3013
|
function resolveAnthropicReasoningConfig({
|
|
@@ -7,8 +7,10 @@ import type { AnthropicTool, AnthropicToolChoice } from './anthropic-api';
|
|
|
7
7
|
import { CacheControlValidator } from './get-cache-control';
|
|
8
8
|
import { advisor_20260301ArgsSchema } from './tool/advisor_20260301';
|
|
9
9
|
import { textEditor_20250728ArgsSchema } from './tool/text-editor_20250728';
|
|
10
|
+
import { webSearch_20260318ArgsSchema } from './tool/web-search_20260318';
|
|
10
11
|
import { webSearch_20260209ArgsSchema } from './tool/web-search_20260209';
|
|
11
12
|
import { webSearch_20250305ArgsSchema } from './tool/web-search_20250305';
|
|
13
|
+
import { webFetch_20260318ArgsSchema } from './tool/web-fetch-20260318';
|
|
12
14
|
import { webFetch_20260209ArgsSchema } from './tool/web-fetch-20260209';
|
|
13
15
|
import { webFetch_20250910ArgsSchema } from './tool/web-fetch-20250910';
|
|
14
16
|
import { validateTypes } from '@ai-sdk/provider-utils';
|
|
@@ -297,6 +299,25 @@ export async function prepareTools({
|
|
|
297
299
|
});
|
|
298
300
|
break;
|
|
299
301
|
}
|
|
302
|
+
case 'anthropic.web_fetch_20260318': {
|
|
303
|
+
const args = await validateTypes({
|
|
304
|
+
value: tool.args,
|
|
305
|
+
schema: webFetch_20260318ArgsSchema,
|
|
306
|
+
});
|
|
307
|
+
anthropicTools.push({
|
|
308
|
+
type: 'web_fetch_20260318',
|
|
309
|
+
name: 'web_fetch',
|
|
310
|
+
max_uses: args.maxUses,
|
|
311
|
+
allowed_domains: args.allowedDomains,
|
|
312
|
+
blocked_domains: args.blockedDomains,
|
|
313
|
+
citations: args.citations,
|
|
314
|
+
max_content_tokens: args.maxContentTokens,
|
|
315
|
+
use_cache: args.useCache,
|
|
316
|
+
response_inclusion: args.responseInclusion,
|
|
317
|
+
cache_control: undefined,
|
|
318
|
+
});
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
300
321
|
case 'anthropic.web_search_20250305': {
|
|
301
322
|
const args = await validateTypes({
|
|
302
323
|
value: tool.args,
|
|
@@ -330,6 +351,23 @@ export async function prepareTools({
|
|
|
330
351
|
});
|
|
331
352
|
break;
|
|
332
353
|
}
|
|
354
|
+
case 'anthropic.web_search_20260318': {
|
|
355
|
+
const args = await validateTypes({
|
|
356
|
+
value: tool.args,
|
|
357
|
+
schema: webSearch_20260318ArgsSchema,
|
|
358
|
+
});
|
|
359
|
+
anthropicTools.push({
|
|
360
|
+
type: 'web_search_20260318',
|
|
361
|
+
name: 'web_search',
|
|
362
|
+
max_uses: args.maxUses,
|
|
363
|
+
allowed_domains: args.allowedDomains,
|
|
364
|
+
blocked_domains: args.blockedDomains,
|
|
365
|
+
user_location: args.userLocation,
|
|
366
|
+
response_inclusion: args.responseInclusion,
|
|
367
|
+
cache_control: undefined,
|
|
368
|
+
});
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
333
371
|
|
|
334
372
|
case 'anthropic.tool_search_regex_20251119': {
|
|
335
373
|
anthropicTools.push({
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
InvalidArgumentError,
|
|
3
3
|
NoSuchModelError,
|
|
4
4
|
type Experimental_BatchV4 as BatchV4,
|
|
5
|
+
type Experimental_EvaluationModelV4 as EvaluationModelV4,
|
|
5
6
|
type FilesV4,
|
|
6
7
|
type LanguageModelV4,
|
|
7
8
|
type ProviderV4,
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
withUserAgentSuffix,
|
|
17
18
|
type FetchFunction,
|
|
18
19
|
} from '@ai-sdk/provider-utils';
|
|
20
|
+
import { Experimental_EvaluationLanguageModel as EvaluationLanguageModel } from '@ai-sdk/provider-utils/experimental-evaluation';
|
|
19
21
|
import { AnthropicFiles } from './anthropic-files';
|
|
20
22
|
import { AnthropicLanguageModel } from './anthropic-language-model';
|
|
21
23
|
import { AnthropicBatch } from './anthropic-batch';
|
|
@@ -52,6 +54,9 @@ export interface AnthropicProvider extends ProviderV4 {
|
|
|
52
54
|
|
|
53
55
|
messages(modelId: AnthropicModelId): LanguageModelV4;
|
|
54
56
|
|
|
57
|
+
/** Creates an experimental Choice/Score/Boolean evaluation model using Messages. */
|
|
58
|
+
evaluationModel(modelId: AnthropicModelId): EvaluationModelV4;
|
|
59
|
+
|
|
55
60
|
experimental_batch(): BatchV4<{ text: AnthropicModelId }>;
|
|
56
61
|
|
|
57
62
|
/**
|
|
@@ -204,6 +209,11 @@ export function createAnthropic(
|
|
|
204
209
|
provider.languageModel = createChatModel;
|
|
205
210
|
provider.chat = createChatModel;
|
|
206
211
|
provider.messages = createChatModel;
|
|
212
|
+
provider.evaluationModel = (modelId: AnthropicModelId) =>
|
|
213
|
+
new EvaluationLanguageModel({
|
|
214
|
+
model: createChatModel(modelId),
|
|
215
|
+
provider: `${providerName.replace(/\.messages$/, '')}.evaluation`,
|
|
216
|
+
});
|
|
207
217
|
provider.experimental_batch = createBatch;
|
|
208
218
|
|
|
209
219
|
provider.embeddingModel = (modelId: string) => {
|
package/src/anthropic-tools.ts
CHANGED
|
@@ -14,8 +14,10 @@ import { textEditor_20250429 } from './tool/text-editor_20250429';
|
|
|
14
14
|
import { textEditor_20250728 } from './tool/text-editor_20250728';
|
|
15
15
|
import { toolSearchBm25_20251119 } from './tool/tool-search-bm25_20251119';
|
|
16
16
|
import { toolSearchRegex_20251119 } from './tool/tool-search-regex_20251119';
|
|
17
|
+
import { webFetch_20260318 } from './tool/web-fetch-20260318';
|
|
17
18
|
import { webFetch_20260209 } from './tool/web-fetch-20260209';
|
|
18
19
|
import { webFetch_20250910 } from './tool/web-fetch-20250910';
|
|
20
|
+
import { webSearch_20260318 } from './tool/web-search_20260318';
|
|
19
21
|
import { webSearch_20260209 } from './tool/web-search_20260209';
|
|
20
22
|
import { webSearch_20250305 } from './tool/web-search_20250305';
|
|
21
23
|
|
|
@@ -219,6 +221,19 @@ export const anthropicTools = {
|
|
|
219
221
|
*/
|
|
220
222
|
webFetch_20260209,
|
|
221
223
|
|
|
224
|
+
/**
|
|
225
|
+
* Creates a web fetch tool that gives Claude direct access to real-time web content.
|
|
226
|
+
*
|
|
227
|
+
* @param maxUses - The max_uses parameter limits the number of web fetches performed
|
|
228
|
+
* @param allowedDomains - Only fetch from these domains
|
|
229
|
+
* @param blockedDomains - Never fetch from these domains
|
|
230
|
+
* @param citations - Unlike web search where citations are always enabled, citations are optional for web fetch. Set "citations": {"enabled": true} to enable Claude to cite specific passages from fetched documents.
|
|
231
|
+
* @param maxContentTokens - The max_content_tokens parameter limits the amount of content that will be included in the context.
|
|
232
|
+
* @param useCache - Whether cached content may be returned. Set to false to fetch fresh content.
|
|
233
|
+
* @param responseInclusion - Whether result blocks consumed by completed code execution calls are returned. Defaults to "full".
|
|
234
|
+
*/
|
|
235
|
+
webFetch_20260318,
|
|
236
|
+
|
|
222
237
|
/**
|
|
223
238
|
* Creates a web search tool that gives Claude direct access to real-time web content.
|
|
224
239
|
*
|
|
@@ -239,6 +254,17 @@ export const anthropicTools = {
|
|
|
239
254
|
*/
|
|
240
255
|
webSearch_20260209,
|
|
241
256
|
|
|
257
|
+
/**
|
|
258
|
+
* Creates a web search tool that gives Claude direct access to real-time web content.
|
|
259
|
+
*
|
|
260
|
+
* @param maxUses - Maximum number of web searches Claude can perform during the conversation.
|
|
261
|
+
* @param allowedDomains - Optional list of domains that Claude is allowed to search.
|
|
262
|
+
* @param blockedDomains - Optional list of domains that Claude should avoid when searching.
|
|
263
|
+
* @param userLocation - Optional user location information to provide geographically relevant search results.
|
|
264
|
+
* @param responseInclusion - Whether result blocks consumed by completed code execution calls are returned. Defaults to "full".
|
|
265
|
+
*/
|
|
266
|
+
webSearch_20260318,
|
|
267
|
+
|
|
242
268
|
/**
|
|
243
269
|
* Creates a tool search tool that uses regex patterns to find tools.
|
|
244
270
|
*
|
|
@@ -1007,7 +1007,8 @@ export async function convertToAnthropicPrompt({
|
|
|
1007
1007
|
}
|
|
1008
1008
|
|
|
1009
1009
|
// to distinguish between code execution 20250522, 20250825,
|
|
1010
|
-
// and encrypted results
|
|
1010
|
+
// and encrypted results from implicitly provisioned code
|
|
1011
|
+
// execution for dynamic web tools,
|
|
1011
1012
|
// we check the type property in output.value
|
|
1012
1013
|
if (output.value.type === 'code_execution_result') {
|
|
1013
1014
|
// code execution 20250522
|
|
@@ -1140,9 +1141,9 @@ export async function convertToAnthropicPrompt({
|
|
|
1140
1141
|
break;
|
|
1141
1142
|
}
|
|
1142
1143
|
|
|
1143
|
-
// ideally we'd switch schema based on the tool version
|
|
1144
|
-
//
|
|
1145
|
-
//
|
|
1144
|
+
// ideally we'd switch schema based on the tool version, but
|
|
1145
|
+
// all supported versions share an identical output schema,
|
|
1146
|
+
// so we use one here.
|
|
1146
1147
|
const webFetchOutput = await validateTypes({
|
|
1147
1148
|
value: output.value,
|
|
1148
1149
|
schema: webFetch_20250910OutputSchema,
|
|
@@ -1205,9 +1206,9 @@ export async function convertToAnthropicPrompt({
|
|
|
1205
1206
|
break;
|
|
1206
1207
|
}
|
|
1207
1208
|
|
|
1208
|
-
// ideally we'd switch schema based on the tool version
|
|
1209
|
-
//
|
|
1210
|
-
//
|
|
1209
|
+
// ideally we'd switch schema based on the tool version, but
|
|
1210
|
+
// all supported versions share an identical output schema,
|
|
1211
|
+
// so we use one here.
|
|
1211
1212
|
const webSearchOutput = await validateTypes({
|
|
1212
1213
|
value: output.value,
|
|
1213
1214
|
schema: webSearch_20250305OutputSchema,
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from 'zod/v4';
|
|
7
|
+
|
|
8
|
+
export const webFetch_20260318ArgsSchema = lazySchema(() =>
|
|
9
|
+
zodSchema(
|
|
10
|
+
z.object({
|
|
11
|
+
maxUses: z.number().optional(),
|
|
12
|
+
allowedDomains: z.array(z.string()).optional(),
|
|
13
|
+
blockedDomains: z.array(z.string()).optional(),
|
|
14
|
+
citations: z.object({ enabled: z.boolean() }).optional(),
|
|
15
|
+
maxContentTokens: z.number().optional(),
|
|
16
|
+
useCache: z.boolean().optional(),
|
|
17
|
+
responseInclusion: z.enum(['full', 'excluded']).optional(),
|
|
18
|
+
}),
|
|
19
|
+
),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export const webFetch_20260318OutputSchema = lazySchema(() =>
|
|
23
|
+
zodSchema(
|
|
24
|
+
z.object({
|
|
25
|
+
type: z.literal('web_fetch_result'),
|
|
26
|
+
url: z.string(),
|
|
27
|
+
content: z.object({
|
|
28
|
+
type: z.literal('document'),
|
|
29
|
+
title: z.string().nullable(),
|
|
30
|
+
citations: z.object({ enabled: z.boolean() }).optional(),
|
|
31
|
+
source: z.union([
|
|
32
|
+
z.object({
|
|
33
|
+
type: z.literal('base64'),
|
|
34
|
+
mediaType: z.literal('application/pdf'),
|
|
35
|
+
data: z.string(),
|
|
36
|
+
}),
|
|
37
|
+
z.object({
|
|
38
|
+
type: z.literal('text'),
|
|
39
|
+
mediaType: z.literal('text/plain'),
|
|
40
|
+
data: z.string(),
|
|
41
|
+
}),
|
|
42
|
+
]),
|
|
43
|
+
}),
|
|
44
|
+
retrievedAt: z.string().nullable(),
|
|
45
|
+
}),
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const webFetch_20260318InputSchema = lazySchema(() =>
|
|
50
|
+
zodSchema(
|
|
51
|
+
z.object({
|
|
52
|
+
url: z.string(),
|
|
53
|
+
}),
|
|
54
|
+
),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const factory = createProviderExecutedToolFactory<
|
|
58
|
+
{
|
|
59
|
+
/**
|
|
60
|
+
* The URL to fetch.
|
|
61
|
+
*/
|
|
62
|
+
url: string;
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: 'web_fetch_result';
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Fetched content URL
|
|
69
|
+
*/
|
|
70
|
+
url: string;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Fetched content.
|
|
74
|
+
*/
|
|
75
|
+
content: {
|
|
76
|
+
type: 'document';
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Title of the document
|
|
80
|
+
*/
|
|
81
|
+
title: string | null;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Citation configuration for the document
|
|
85
|
+
*/
|
|
86
|
+
citations?: { enabled: boolean };
|
|
87
|
+
|
|
88
|
+
source:
|
|
89
|
+
| {
|
|
90
|
+
type: 'base64';
|
|
91
|
+
mediaType: 'application/pdf';
|
|
92
|
+
data: string;
|
|
93
|
+
}
|
|
94
|
+
| {
|
|
95
|
+
type: 'text';
|
|
96
|
+
mediaType: 'text/plain';
|
|
97
|
+
data: string;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* ISO 8601 timestamp when the content was retrieved
|
|
103
|
+
*/
|
|
104
|
+
retrievedAt: string | null;
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
/**
|
|
108
|
+
* The maxUses parameter limits the number of web fetches performed
|
|
109
|
+
*/
|
|
110
|
+
maxUses?: number;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Only fetch from these domains
|
|
114
|
+
*/
|
|
115
|
+
allowedDomains?: string[];
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Never fetch from these domains
|
|
119
|
+
*/
|
|
120
|
+
blockedDomains?: string[];
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Unlike web search where citations are always enabled, citations are optional for
|
|
124
|
+
* web fetch. Set "citations": {"enabled": true} to enable Claude to cite specific passages
|
|
125
|
+
* from fetched documents.
|
|
126
|
+
*/
|
|
127
|
+
citations?: {
|
|
128
|
+
enabled: boolean;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The maxContentTokens parameter limits the amount of content that will be included in the context.
|
|
133
|
+
*/
|
|
134
|
+
maxContentTokens?: number;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Whether cached content may be returned. Set to `false` to fetch fresh
|
|
138
|
+
* content. Defaults to `true`.
|
|
139
|
+
*/
|
|
140
|
+
useCache?: boolean;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Controls whether web fetch result blocks consumed by completed code
|
|
144
|
+
* execution calls are included in the response. Defaults to `full`.
|
|
145
|
+
*/
|
|
146
|
+
responseInclusion?: 'full' | 'excluded';
|
|
147
|
+
}
|
|
148
|
+
>({
|
|
149
|
+
id: 'anthropic.web_fetch_20260318',
|
|
150
|
+
inputSchema: webFetch_20260318InputSchema,
|
|
151
|
+
outputSchema: webFetch_20260318OutputSchema,
|
|
152
|
+
supportsDeferredResults: true,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
export const webFetch_20260318 = (
|
|
156
|
+
args: Parameters<typeof factory>[0] = {}, // default
|
|
157
|
+
) => {
|
|
158
|
+
return factory(args);
|
|
159
|
+
};
|