@ai-sdk/anthropic 4.0.98 → 4.0.101
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 +35 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +100 -32
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2 -1
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +99 -31
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +62 -16
- package/package.json +3 -3
- package/src/anthropic-language-model-options.ts +1 -0
- package/src/anthropic-language-model.ts +170 -23
- package/src/anthropic-model-catalog.ts +4 -1
- package/src/tool/computer-toolset_20260801.ts +40 -26
package/docs/05-anthropic.mdx
CHANGED
|
@@ -548,8 +548,8 @@ const result = streamText({
|
|
|
548
548
|
});
|
|
549
549
|
```
|
|
550
550
|
|
|
551
|
-
For `claude-sonnet-5-5`, `claude-opus-5-5`,
|
|
552
|
-
default `"auto"` mode uses native structured outputs through
|
|
551
|
+
For `claude-sonnet-5-5`, `claude-opus-5-5`, `claude-fable-5-1`, and
|
|
552
|
+
`claude-fable-5-2`, the default `"auto"` mode uses native structured outputs through
|
|
553
553
|
`output_config.format`. These models reject forced tool use, so the
|
|
554
554
|
`"jsonTool"` mode cannot be used with them. If you
|
|
555
555
|
request `"jsonTool"` anyway, the provider falls back to `"outputFormat"` and
|
|
@@ -562,13 +562,21 @@ schemas with open objects such as maps (`additionalProperties` set to a schema
|
|
|
562
562
|
or `true`), which native structured outputs would return as `{}`.
|
|
563
563
|
Likewise, a `required` or named `toolChoice` is downgraded to
|
|
564
564
|
`auto` with a warning; instruct the model to use the tool in your prompt and
|
|
565
|
-
verify that a tool call was made.
|
|
565
|
+
verify that a tool call was made. When a named choice falls back to `auto`,
|
|
566
|
+
inline tool additions must use the selected tool's name. Conflicting additions,
|
|
567
|
+
including definitions replayed from conversation history, cause an
|
|
568
|
+
`InvalidArgumentError` before the request is sent.
|
|
566
569
|
|
|
567
570
|
The JSON-tool fallback limits which application tools are available:
|
|
568
571
|
`toolChoice: 'none'` sends only the internal JSON response tool, and a named tool
|
|
569
572
|
choice sends only that application tool alongside the JSON response tool. The
|
|
570
573
|
fallback can produce a JSON response without calling the named application tool;
|
|
571
574
|
verify the selected call if your application requires it.
|
|
575
|
+
These restrictions also apply to inline tool definitions: a named choice allows
|
|
576
|
+
only additions with the selected tool's name, and `toolChoice: 'none'` rejects
|
|
577
|
+
all inline additions. Conflicting definitions cause an `InvalidArgumentError`
|
|
578
|
+
before the request is sent. Tool changes on the initial system message remain
|
|
579
|
+
ignored with a warning.
|
|
572
580
|
|
|
573
581
|
When the JSON tool cannot be forced (for example with manual thinking) and the
|
|
574
582
|
model answers in text without calling it, the text of its final answer is
|
|
@@ -576,7 +584,7 @@ returned. Text before a tool call is still dropped.
|
|
|
576
584
|
|
|
577
585
|
### Effort
|
|
578
586
|
|
|
579
|
-
Anthropic introduced an `effort` option with `claude-opus-4-5` that affects thinking, text responses, and function calls. Effort defaults to `high` and you can set it to `medium` or `low` to save tokens and to lower time-to-last-token latency (TTLT). `claude-opus-4-7`, `claude-opus-4-8`, `claude-opus-5`, `claude-opus-5-5`, `claude-fable-5`, `claude-fable-5-1`, `claude-sonnet-5`, `claude-sonnet-5-5`, and `claude-haiku-5-5` additionally support `xhigh` for maximum reasoning effort.
|
|
587
|
+
Anthropic introduced an `effort` option with `claude-opus-4-5` that affects thinking, text responses, and function calls. Effort defaults to `high` and you can set it to `medium` or `low` to save tokens and to lower time-to-last-token latency (TTLT). `claude-opus-4-7`, `claude-opus-4-8`, `claude-opus-5`, `claude-opus-5-5`, `claude-fable-5`, `claude-fable-5-1`, `claude-fable-5-2`, `claude-sonnet-5`, `claude-sonnet-5-5`, and `claude-haiku-5-5` additionally support `xhigh` for maximum reasoning effort.
|
|
580
588
|
|
|
581
589
|
On `claude-opus-5` and `claude-haiku-5-5`, thinking can only be disabled at effort levels up to and including `high`. When you combine `thinking: { type: 'disabled' }` with `effort: 'xhigh'` or `effort: 'max'`, the AI SDK lowers the effort to `high` and emits a warning instead of sending a request that the API would reject.
|
|
582
590
|
|
|
@@ -589,6 +597,13 @@ thinks. Unlike `claude-sonnet-5-5`, thinking can still be turned off with
|
|
|
589
597
|
Start at `medium` effort and test other levels rather than carrying over the
|
|
590
598
|
settings you used on `claude-haiku-4-5`.
|
|
591
599
|
|
|
600
|
+
On `claude-fable-5-2`, thinking is always adaptive and cannot be disabled. It
|
|
601
|
+
supports `low`, `medium`, `high` (the API default), `xhigh`, and `max` effort.
|
|
602
|
+
The `medium` and `xhigh` levels behave differently than on `claude-fable-5-1`,
|
|
603
|
+
so start at `high` and re-test `medium` and your current setting rather than
|
|
604
|
+
carrying over the effort you tuned for `claude-fable-5-1`. Reserve `xhigh` for
|
|
605
|
+
the hardest long-running work where you have measured a gain.
|
|
606
|
+
|
|
592
607
|
On `claude-opus-5-5`, thinking is always adaptive and cannot be disabled, so
|
|
593
608
|
`effort` is the main control for latency and cost. The API default effort for
|
|
594
609
|
`claude-opus-5-5` is `medium`. Start there and test other levels rather than
|
|
@@ -883,8 +898,8 @@ const { text } = await generateText({
|
|
|
883
898
|
|
|
884
899
|
##### Adaptive-Only Models
|
|
885
900
|
|
|
886
|
-
`claude-sonnet-5-5`, `claude-opus-5-5`, `claude-fable-5`,
|
|
887
|
-
`claude-fable-5-
|
|
901
|
+
`claude-sonnet-5-5`, `claude-opus-5-5`, `claude-fable-5`, `claude-fable-5-1`,
|
|
902
|
+
and `claude-fable-5-2` always run adaptive thinking. The API rejects
|
|
888
903
|
`thinking: { type: 'disabled' }` and budget-based
|
|
889
904
|
`thinking: { type: 'enabled' }` for these models. To keep existing code
|
|
890
905
|
working, the provider:
|
|
@@ -985,8 +1000,8 @@ console.log(text);
|
|
|
985
1000
|
|
|
986
1001
|
##### Thinking Updates
|
|
987
1002
|
|
|
988
|
-
Use `display: 'updates'` with `claude-sonnet-5-5`, `claude-opus-5-5`,
|
|
989
|
-
`claude-fable-5-1` to stream thinking summaries between tool calls. These models
|
|
1003
|
+
Use `display: 'updates'` with `claude-sonnet-5-5`, `claude-opus-5-5`,
|
|
1004
|
+
`claude-fable-5-1`, or `claude-fable-5-2` to stream thinking summaries between tool calls. These models
|
|
990
1005
|
return progress notes between tool calls as thinking blocks rather than text, so
|
|
991
1006
|
without this setting a long tool-calling turn can look silent. The provider adds
|
|
992
1007
|
the required `thinking-display-updates-2026-08-18` beta header automatically:
|
|
@@ -1014,7 +1029,28 @@ const result = streamText({
|
|
|
1014
1029
|
|
|
1015
1030
|
##### Thinking Binding Controls
|
|
1016
1031
|
|
|
1017
|
-
Fable 5.1, Opus 5.5, and Sonnet 5.5
|
|
1032
|
+
Fable 5.2, Fable 5.1, Opus 5.5, and Sonnet 5.5 use preserved thinking. Each
|
|
1033
|
+
thinking block from an earlier assistant turn is bound to the request content
|
|
1034
|
+
before it: the system prompt, the tools, and the earlier messages. If that
|
|
1035
|
+
content changes between requests, the thinking blocks after the change become
|
|
1036
|
+
invalid. By default, the API then rejects the request with a 400 error ("The
|
|
1037
|
+
block is bound to a different conversation"). Keep the message history
|
|
1038
|
+
append-only, and keep the system prompt and tools stable, where you can.
|
|
1039
|
+
|
|
1040
|
+
This also applies inside a single multi-step `generateText` or `streamText`
|
|
1041
|
+
call. When `prepareStep` returns a different `system`, `activeTools`, or
|
|
1042
|
+
`messages` for a later step, the thinking from the earlier steps is sent with
|
|
1043
|
+
the changed content, and the next step fails. Editing or removing earlier
|
|
1044
|
+
messages between turns, or changing the system prompt or tools between turns,
|
|
1045
|
+
has the same effect.
|
|
1046
|
+
|
|
1047
|
+
If your application changes this content, set
|
|
1048
|
+
`blockBinding.prefixMismatchBehavior` to `drop_block` (see below). The API then
|
|
1049
|
+
drops the invalid thinking blocks instead of rejecting the request. The model
|
|
1050
|
+
thinks again for the dropped context, which can increase output token usage, so
|
|
1051
|
+
measure token usage on your own workloads before you rely on it.
|
|
1052
|
+
|
|
1053
|
+
Fable 5.2, Fable 5.1, Opus 5.5, and Sonnet 5.5 can recover from a thinking-block prefix
|
|
1018
1054
|
mismatch by dropping the mismatched block. Set
|
|
1019
1055
|
`blockBinding.prefixMismatchBehavior` to `drop_block`, or set it to `error` to
|
|
1020
1056
|
reject the request. You can provide block binding by itself to preserve the
|
|
@@ -1079,6 +1115,9 @@ the selected tool is sent. This also applies when the top-level `reasoning`
|
|
|
1079
1115
|
option enables manual thinking, including when structured output uses the
|
|
1080
1116
|
internal JSON response tool. Tool use is no longer guaranteed: instruct the
|
|
1081
1117
|
model to use the tool in your prompt and verify that a tool call was made.
|
|
1118
|
+
Inline tool additions must use the selected tool's name when a named choice
|
|
1119
|
+
falls back to `auto`. Conflicting additions, including definitions replayed from
|
|
1120
|
+
conversation history, cause an `InvalidArgumentError` before the request is sent.
|
|
1082
1121
|
|
|
1083
1122
|
See [AI SDK UI: Chatbot](/docs/ai-sdk-ui/chatbot#reasoning) for more details
|
|
1084
1123
|
on how to integrate reasoning into your chatbot.
|
|
@@ -1650,10 +1689,10 @@ const computerTool = anthropic.tools.computer_20251124({
|
|
|
1650
1689
|
|
|
1651
1690
|
<Note>
|
|
1652
1691
|
Use `computerToolset_20260801` for Claude Sonnet 5.5 and Opus 5.5 (required),
|
|
1653
|
-
Opus 5, Sonnet 5, Fable 5, Fable 5.1, and Opus 4.8. Use
|
|
1654
|
-
for Claude Opus 4.5 through Opus 4.7, which support the
|
|
1655
|
-
`computer_20250124` for Claude Sonnet 4.5, Haiku 4.5, Opus
|
|
1656
|
-
4, and Sonnet 3.7.
|
|
1692
|
+
Opus 5, Sonnet 5, Fable 5, Fable 5.1, Fable 5.2, and Opus 4.8. Use
|
|
1693
|
+
`computer_20251124` for Claude Opus 4.5 through Opus 4.7, which support the
|
|
1694
|
+
zoom action. Use `computer_20250124` for Claude Sonnet 4.5, Haiku 4.5, Opus
|
|
1695
|
+
4.1, Sonnet 4, Opus 4, and Sonnet 3.7.
|
|
1657
1696
|
</Note>
|
|
1658
1697
|
|
|
1659
1698
|
#### Computer Toolset
|
|
@@ -1668,7 +1707,13 @@ return several actions in one turn, each as its own tool call.
|
|
|
1668
1707
|
The API returns each action as a separate `tool_use` block with
|
|
1669
1708
|
`toolset_name: 'computer'`. The AI SDK maps every action to the toolset tool and
|
|
1670
1709
|
passes the action name as `action`, so `execute` receives the same input shape
|
|
1671
|
-
as the older computer tools
|
|
1710
|
+
as the older computer tools.
|
|
1711
|
+
|
|
1712
|
+
The SDK preserves the returned member name as `action` and rejects disabled or
|
|
1713
|
+
unavailable members before emitting tool calls, including during streaming.
|
|
1714
|
+
Disabled members are also rejected by the tool's local input schema.
|
|
1715
|
+
|
|
1716
|
+
For example:
|
|
1672
1717
|
|
|
1673
1718
|
```ts
|
|
1674
1719
|
const computerTool = anthropic.tools.computerToolset_20260801({
|
|
@@ -2050,8 +2095,8 @@ This sends `tool_reference` blocks to Anthropic, which loads the corresponding d
|
|
|
2050
2095
|
|
|
2051
2096
|
### Mid-Conversation System Controls
|
|
2052
2097
|
|
|
2053
|
-
With `claude-sonnet-5-5`, `claude-opus-5-5`,
|
|
2054
|
-
empty system message to change effort from the next user turn. A separate
|
|
2098
|
+
With `claude-sonnet-5-5`, `claude-opus-5-5`, `claude-fable-5-1`, and
|
|
2099
|
+
`claude-fable-5-2`, use an empty system message to change effort from the next user turn. A separate
|
|
2055
2100
|
system message containing text can provide a turn-scoped reminder with
|
|
2056
2101
|
`clearAt: 'next_user_message'`: its text applies until the next user message. Keep the reminder after a user turn and
|
|
2057
2102
|
before an assistant turn, or at the end of the messages array.
|
|
@@ -2727,6 +2772,7 @@ and the `mediaType` should be set to `'application/pdf'`.
|
|
|
2727
2772
|
| `claude-sonnet-5-5` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
2728
2773
|
| `claude-sonnet-5` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
2729
2774
|
| `claude-haiku-5-5` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
2775
|
+
| `claude-fable-5-2` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
2730
2776
|
| `claude-fable-5-1` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
2731
2777
|
| `claude-fable-5` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
2732
2778
|
| `claude-opus-4-8` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/anthropic",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.101",
|
|
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.37",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.78"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@ai-sdk/test-server": "2.0.4",
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
parseProviderOptions,
|
|
33
33
|
postJsonToApi,
|
|
34
34
|
resolve,
|
|
35
|
+
resolveProviderOptions,
|
|
35
36
|
resolveProviderReference,
|
|
36
37
|
secureJsonParse,
|
|
37
38
|
serializeModelOptions,
|
|
@@ -80,6 +81,33 @@ import { CacheControlValidator } from './get-cache-control';
|
|
|
80
81
|
import { mapAnthropicStopReason } from './map-anthropic-stop-reason';
|
|
81
82
|
import { sanitizeJsonSchema } from './sanitize-json-schema';
|
|
82
83
|
import { supportsNativeStructuredOutputSchema } from './supports-native-structured-output-schema';
|
|
84
|
+
import { computerToolset_20260801Members } from './tool/computer-toolset_20260801';
|
|
85
|
+
|
|
86
|
+
function validateToolsetMember({
|
|
87
|
+
toolsetName,
|
|
88
|
+
memberName,
|
|
89
|
+
tools,
|
|
90
|
+
}: {
|
|
91
|
+
toolsetName: string;
|
|
92
|
+
memberName: string;
|
|
93
|
+
tools: AnthropicTool[] | undefined;
|
|
94
|
+
}): void {
|
|
95
|
+
const toolset = tools?.find(
|
|
96
|
+
tool => 'type' in tool && tool.type === 'computer_toolset_20260801',
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
if (
|
|
100
|
+
toolsetName !== 'computer' ||
|
|
101
|
+
toolset == null ||
|
|
102
|
+
!computerToolset_20260801Members.some(member => member === memberName) ||
|
|
103
|
+
toolset.configs?.[memberName]?.enabled === false
|
|
104
|
+
) {
|
|
105
|
+
throw new InvalidResponseDataError({
|
|
106
|
+
data: { toolsetName, memberName },
|
|
107
|
+
message: `Received an unavailable toolset member: ${toolsetName}.${memberName}.`,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
83
111
|
|
|
84
112
|
function createAnthropicStreamError(error: {
|
|
85
113
|
message: string;
|
|
@@ -239,11 +267,16 @@ function toToolsetMemberInput({
|
|
|
239
267
|
memberName: string;
|
|
240
268
|
input: unknown;
|
|
241
269
|
}): JSONObject {
|
|
270
|
+
if (typeof input !== 'object' || input === null || Array.isArray(input)) {
|
|
271
|
+
throw new InvalidResponseDataError({
|
|
272
|
+
data: input,
|
|
273
|
+
message: 'Invalid toolset member input: expected an object.',
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
242
277
|
return {
|
|
278
|
+
...(input as JSONObject),
|
|
243
279
|
action: memberName,
|
|
244
|
-
...(typeof input === 'object' && input !== null && !Array.isArray(input)
|
|
245
|
-
? (input as JSONObject)
|
|
246
|
-
: {}),
|
|
247
280
|
};
|
|
248
281
|
}
|
|
249
282
|
|
|
@@ -284,6 +317,16 @@ export type AnthropicLanguageModelConfig = {
|
|
|
284
317
|
cacheControlProviderOptionsName?: string;
|
|
285
318
|
};
|
|
286
319
|
|
|
320
|
+
/**
|
|
321
|
+
* Legacy names of custom providerOptions keys, read when the current key is
|
|
322
|
+
* absent.
|
|
323
|
+
*/
|
|
324
|
+
const LEGACY_PROVIDER_OPTIONS_NAMES: Record<string, readonly string[]> = {
|
|
325
|
+
// The Google Vertex Anthropic provider was renamed from `vertex` to
|
|
326
|
+
// `googleVertex`, which silently changed its custom providerOptions key.
|
|
327
|
+
googleVertex: ['vertex'],
|
|
328
|
+
};
|
|
329
|
+
|
|
287
330
|
const TEXT_OR_THINKING_BLOCK_TYPES = new Set<string>([
|
|
288
331
|
'redacted_thinking',
|
|
289
332
|
'text',
|
|
@@ -451,17 +494,32 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
451
494
|
schema: anthropicLanguageModelOptions,
|
|
452
495
|
});
|
|
453
496
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
497
|
+
// The custom key and its legacy aliases are alternatives: the first
|
|
498
|
+
// present one is used.
|
|
499
|
+
const {
|
|
500
|
+
options: customProviderOptions,
|
|
501
|
+
namespaces: [customProviderOptionsName],
|
|
502
|
+
} = await resolveProviderOptions({
|
|
503
|
+
providerOptions,
|
|
504
|
+
namespaces:
|
|
505
|
+
providerOptionsName !== 'anthropic'
|
|
506
|
+
? [
|
|
507
|
+
providerOptionsName,
|
|
508
|
+
...(Object.hasOwn(
|
|
509
|
+
LEGACY_PROVIDER_OPTIONS_NAMES,
|
|
510
|
+
providerOptionsName,
|
|
511
|
+
)
|
|
512
|
+
? LEGACY_PROVIDER_OPTIONS_NAMES[providerOptionsName]
|
|
513
|
+
: []),
|
|
514
|
+
]
|
|
515
|
+
: [],
|
|
516
|
+
resolution: 'first',
|
|
517
|
+
schema: anthropicLanguageModelOptions,
|
|
518
|
+
});
|
|
462
519
|
|
|
463
520
|
// Track if custom key was explicitly used
|
|
464
|
-
const usedCustomProviderKey =
|
|
521
|
+
const usedCustomProviderKey =
|
|
522
|
+
customProviderOptionsName === providerOptionsName;
|
|
465
523
|
|
|
466
524
|
// Merge options
|
|
467
525
|
const anthropicOptions = Object.assign(
|
|
@@ -688,6 +746,10 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
688
746
|
});
|
|
689
747
|
|
|
690
748
|
const toolsetNames = getAnthropicToolsetNames(tools);
|
|
749
|
+
const inlineToolDefinitions: Array<{
|
|
750
|
+
sdkName: string;
|
|
751
|
+
definition: AnthropicTool;
|
|
752
|
+
}> = [];
|
|
691
753
|
|
|
692
754
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicPrompt({
|
|
693
755
|
prompt,
|
|
@@ -713,6 +775,13 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
713
775
|
// between streaming and non-streaming calls to keep the cache.
|
|
714
776
|
});
|
|
715
777
|
|
|
778
|
+
if (definitions?.[0] != null) {
|
|
779
|
+
inlineToolDefinitions.push({
|
|
780
|
+
sdkName: tool.name,
|
|
781
|
+
definition: definitions[0],
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
|
|
716
785
|
return {
|
|
717
786
|
definition: definitions?.[0],
|
|
718
787
|
warnings: toolWarnings,
|
|
@@ -1287,6 +1356,72 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1287
1356
|
},
|
|
1288
1357
|
);
|
|
1289
1358
|
|
|
1359
|
+
// Forced-choice and JSON-tool fallbacks restrict the declared tools.
|
|
1360
|
+
// MCP connectors and inline definitions, including those replayed from
|
|
1361
|
+
// history, must not restore other tools before the provider executes the request.
|
|
1362
|
+
if (
|
|
1363
|
+
(toolChoice?.type === 'tool' &&
|
|
1364
|
+
(anthropicToolChoice?.type === 'auto' || jsonResponseTool != null)) ||
|
|
1365
|
+
(toolChoice?.type === 'none' && jsonResponseTool != null)
|
|
1366
|
+
) {
|
|
1367
|
+
for (const server of baseArgs.mcp_servers ?? []) {
|
|
1368
|
+
server.tool_configuration = {
|
|
1369
|
+
allowed_tools: server.tool_configuration?.allowed_tools,
|
|
1370
|
+
enabled: false,
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
// Initial system tool changes are ignored by the prompt converter.
|
|
1375
|
+
// Validate only definitions that remain in the outgoing messages.
|
|
1376
|
+
const emittedInlineDefinitions = new Set(
|
|
1377
|
+
messagesPrompt.messages.flatMap(message =>
|
|
1378
|
+
message.role === 'system'
|
|
1379
|
+
? message.content.flatMap(part =>
|
|
1380
|
+
part.type === 'tool_addition' &&
|
|
1381
|
+
part.tool.type === 'tool_definition'
|
|
1382
|
+
? [part.tool.definition]
|
|
1383
|
+
: [],
|
|
1384
|
+
)
|
|
1385
|
+
: [],
|
|
1386
|
+
),
|
|
1387
|
+
);
|
|
1388
|
+
const selectedSdkName =
|
|
1389
|
+
toolChoice.type === 'tool' ? toolChoice.toolName : undefined;
|
|
1390
|
+
const selectedTool = tools?.find(tool => tool.name === selectedSdkName);
|
|
1391
|
+
const selectedProviderName =
|
|
1392
|
+
jsonResponseTool != null &&
|
|
1393
|
+
selectedSdkName != null &&
|
|
1394
|
+
selectedTool?.type !== 'function'
|
|
1395
|
+
? toolNameMapping.toProviderToolName(selectedSdkName)
|
|
1396
|
+
: selectedSdkName;
|
|
1397
|
+
const conflictingTool = inlineToolDefinitions.find(
|
|
1398
|
+
({ sdkName, definition }) =>
|
|
1399
|
+
emittedInlineDefinitions.has(definition) &&
|
|
1400
|
+
(toolChoice.type === 'none' ||
|
|
1401
|
+
// The JSON-tool path filters application tools by SDK name before
|
|
1402
|
+
// conversion; the forced-choice fallback filters by provider name.
|
|
1403
|
+
(jsonResponseTool != null && sdkName !== selectedSdkName) ||
|
|
1404
|
+
!('name' in definition) ||
|
|
1405
|
+
definition.name !== selectedProviderName),
|
|
1406
|
+
);
|
|
1407
|
+
if (conflictingTool != null) {
|
|
1408
|
+
const toolName =
|
|
1409
|
+
'name' in conflictingTool.definition
|
|
1410
|
+
? conflictingTool.definition.name
|
|
1411
|
+
: conflictingTool.definition.type;
|
|
1412
|
+
const choice =
|
|
1413
|
+
toolChoice.type === 'tool'
|
|
1414
|
+
? `named tool choice '${toolChoice.toolName}'`
|
|
1415
|
+
: `tool choice 'none'`;
|
|
1416
|
+
throw new InvalidArgumentError({
|
|
1417
|
+
argument: 'toolChoice',
|
|
1418
|
+
message:
|
|
1419
|
+
`Inline tool '${toolName}' conflicts with ${choice}. ` +
|
|
1420
|
+
'Inline definitions must respect the tool choice when forced tool use falls back or the JSON response tool is used.',
|
|
1421
|
+
});
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1290
1425
|
// Extract cache control warnings once at the end
|
|
1291
1426
|
const cacheWarnings = cacheControlValidator.getWarnings();
|
|
1292
1427
|
|
|
@@ -1310,6 +1445,7 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1310
1445
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
1311
1446
|
includePings: stream === true && anthropicOptions?.includePings === true,
|
|
1312
1447
|
toolNameMapping,
|
|
1448
|
+
preparedTools: anthropicTools,
|
|
1313
1449
|
providerOptionsName,
|
|
1314
1450
|
usedCustomProviderKey,
|
|
1315
1451
|
};
|
|
@@ -1438,6 +1574,7 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1438
1574
|
usesJsonResponseTool,
|
|
1439
1575
|
markCodeExecutionDynamic,
|
|
1440
1576
|
toolNameMapping,
|
|
1577
|
+
preparedTools,
|
|
1441
1578
|
providerOptionsName,
|
|
1442
1579
|
usedCustomProviderKey,
|
|
1443
1580
|
} = await this.getArgs({
|
|
@@ -1606,6 +1743,11 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1606
1743
|
text: JSON.stringify(part.input),
|
|
1607
1744
|
});
|
|
1608
1745
|
} else if (part.toolset_name != null) {
|
|
1746
|
+
validateToolsetMember({
|
|
1747
|
+
toolsetName: part.toolset_name,
|
|
1748
|
+
memberName: part.name,
|
|
1749
|
+
tools: preparedTools,
|
|
1750
|
+
});
|
|
1609
1751
|
// toolset member calls (e.g. the computer toolset) are mapped to
|
|
1610
1752
|
// the toolset tool with the member name as the `action`:
|
|
1611
1753
|
content.push({
|
|
@@ -2104,6 +2246,7 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
2104
2246
|
markCodeExecutionDynamic,
|
|
2105
2247
|
includePings,
|
|
2106
2248
|
toolNameMapping,
|
|
2249
|
+
preparedTools,
|
|
2107
2250
|
providerOptionsName,
|
|
2108
2251
|
usedCustomProviderKey,
|
|
2109
2252
|
} = await this.getArgs({
|
|
@@ -2395,6 +2538,11 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
2395
2538
|
id: String(value.index),
|
|
2396
2539
|
});
|
|
2397
2540
|
} else if (part.toolset_name != null) {
|
|
2541
|
+
validateToolsetMember({
|
|
2542
|
+
toolsetName: part.toolset_name,
|
|
2543
|
+
memberName: part.name,
|
|
2544
|
+
tools: preparedTools,
|
|
2545
|
+
});
|
|
2398
2546
|
const callerInfo = getAnthropicCallerInfo(part.caller);
|
|
2399
2547
|
const customToolName = toolNameMapping.toCustomToolName(
|
|
2400
2548
|
part.toolset_name,
|
|
@@ -2918,19 +3066,18 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
2918
3066
|
? {}
|
|
2919
3067
|
: secureJsonParse(contentBlock.input);
|
|
2920
3068
|
} catch {
|
|
2921
|
-
|
|
2922
|
-
|
|
3069
|
+
throw new InvalidResponseDataError({
|
|
3070
|
+
data: contentBlock.input,
|
|
3071
|
+
message: 'Invalid toolset member input JSON.',
|
|
3072
|
+
});
|
|
2923
3073
|
}
|
|
2924
3074
|
|
|
2925
|
-
contentBlock.input =
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
:
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
input: memberInput,
|
|
2932
|
-
}),
|
|
2933
|
-
);
|
|
3075
|
+
contentBlock.input = JSON.stringify(
|
|
3076
|
+
toToolsetMemberInput({
|
|
3077
|
+
memberName: contentBlock.toolset.memberName,
|
|
3078
|
+
input: memberInput,
|
|
3079
|
+
}),
|
|
3080
|
+
);
|
|
2934
3081
|
|
|
2935
3082
|
controller.enqueue({
|
|
2936
3083
|
type: 'tool-input-delta',
|
|
@@ -181,7 +181,9 @@ const runtimeRules: readonly {
|
|
|
181
181
|
}),
|
|
182
182
|
},
|
|
183
183
|
{
|
|
184
|
-
matches: modelId =>
|
|
184
|
+
matches: modelId =>
|
|
185
|
+
modelId.includes('claude-fable-5-2') ||
|
|
186
|
+
modelId.includes('claude-fable-5-1'),
|
|
185
187
|
definition: defineRuntime({
|
|
186
188
|
...currentClaudeWithoutSampling,
|
|
187
189
|
thinkingCanBeDisabled: false,
|
|
@@ -252,6 +254,7 @@ const documentedModels: Readonly<Record<string, DocumentedCapabilities>> = {
|
|
|
252
254
|
'claude-sonnet-5-5': { toolSearch: true, compaction: true, effort: true },
|
|
253
255
|
'claude-sonnet-5': { toolSearch: true, compaction: true, effort: true },
|
|
254
256
|
'claude-haiku-5-5': { toolSearch: true, compaction: true, effort: true },
|
|
257
|
+
'claude-fable-5-2': { toolSearch: true, compaction: true, effort: true },
|
|
255
258
|
'claude-fable-5-1': { toolSearch: true, compaction: true, effort: true },
|
|
256
259
|
'claude-fable-5': { toolSearch: true, compaction: true, effort: true },
|
|
257
260
|
'claude-opus-4-8': { toolSearch: true, compaction: true, effort: true },
|
|
@@ -33,30 +33,39 @@ export const computerToolset_20260801Members = [
|
|
|
33
33
|
export type ComputerToolset_20260801Member =
|
|
34
34
|
(typeof computerToolset_20260801Members)[number];
|
|
35
35
|
|
|
36
|
-
const computerToolset_20260801InputSchema =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
.optional(),
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
)
|
|
36
|
+
const computerToolset_20260801InputSchema = (
|
|
37
|
+
configs?: Partial<
|
|
38
|
+
Record<ComputerToolset_20260801Member, { enabled?: boolean }>
|
|
39
|
+
>,
|
|
40
|
+
) =>
|
|
41
|
+
lazySchema(() =>
|
|
42
|
+
zodSchema(
|
|
43
|
+
z.object({
|
|
44
|
+
action: z.enum(
|
|
45
|
+
computerToolset_20260801Members.filter(
|
|
46
|
+
member => configs?.[member]?.enabled !== false,
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
coordinate: z.tuple([z.number().int(), z.number().int()]).optional(),
|
|
50
|
+
duration: z.number().optional(),
|
|
51
|
+
region: z
|
|
52
|
+
.tuple([
|
|
53
|
+
z.number().int(),
|
|
54
|
+
z.number().int(),
|
|
55
|
+
z.number().int(),
|
|
56
|
+
z.number().int(),
|
|
57
|
+
])
|
|
58
|
+
.optional(),
|
|
59
|
+
repeat: z.number().int().optional(),
|
|
60
|
+
scroll_amount: z.number().optional(),
|
|
61
|
+
scroll_direction: z.enum(['up', 'down', 'left', 'right']).optional(),
|
|
62
|
+
start_coordinate: z
|
|
63
|
+
.tuple([z.number().int(), z.number().int()])
|
|
64
|
+
.optional(),
|
|
65
|
+
text: z.string().optional(),
|
|
66
|
+
}),
|
|
67
|
+
),
|
|
68
|
+
);
|
|
60
69
|
|
|
61
70
|
export const computerToolset_20260801ArgsSchema = lazySchema(() =>
|
|
62
71
|
zodSchema(
|
|
@@ -74,7 +83,7 @@ export const computerToolset_20260801ArgsSchema = lazySchema(() =>
|
|
|
74
83
|
),
|
|
75
84
|
);
|
|
76
85
|
|
|
77
|
-
|
|
86
|
+
const factory = createProviderDefinedToolFactory<
|
|
78
87
|
{
|
|
79
88
|
/**
|
|
80
89
|
* The member tool that Claude invoked. Each member is returned by the API
|
|
@@ -161,5 +170,10 @@ export const computerToolset_20260801 = createProviderDefinedToolFactory<
|
|
|
161
170
|
}
|
|
162
171
|
>({
|
|
163
172
|
id: 'anthropic.computer_toolset_20260801',
|
|
164
|
-
inputSchema: computerToolset_20260801InputSchema,
|
|
173
|
+
inputSchema: computerToolset_20260801InputSchema(),
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
export const computerToolset_20260801: typeof factory = args => ({
|
|
177
|
+
...factory(args),
|
|
178
|
+
inputSchema: computerToolset_20260801InputSchema(args.configs),
|
|
165
179
|
});
|