@ai-sdk/anthropic 4.0.59 → 4.0.60
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 +12 -0
- package/dist/index.d.ts +47 -1
- package/dist/index.js +958 -559
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +84 -2
- package/dist/internal/index.js +906 -507
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +125 -14
- package/package.json +1 -1
- package/src/anthropic-api.ts +23 -0
- package/src/anthropic-language-model-options.ts +13 -3
- package/src/anthropic-language-model.ts +287 -5
- package/src/anthropic-prepare-tools.ts +76 -0
- package/src/anthropic-tools.ts +25 -0
- package/src/convert-to-anthropic-prompt.ts +74 -1
- package/src/tool/computer-toolset_20260801.ts +165 -0
|
@@ -195,6 +195,48 @@ function getAnthropicCallerMetadata(
|
|
|
195
195
|
: { providerMetadata: { anthropic: { caller: callerInfo } } };
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Maps the custom tool names of toolset tools (e.g. the computer toolset) to
|
|
200
|
+
* the toolset name that the Anthropic API uses in `toolset_name`.
|
|
201
|
+
*/
|
|
202
|
+
function getAnthropicToolsetNames(
|
|
203
|
+
tools: LanguageModelV4CallOptions['tools'],
|
|
204
|
+
): Record<string, string> {
|
|
205
|
+
const toolsetNames: Record<string, string> = {};
|
|
206
|
+
|
|
207
|
+
for (const tool of tools ?? []) {
|
|
208
|
+
if (
|
|
209
|
+
tool.type === 'provider' &&
|
|
210
|
+
tool.id === 'anthropic.computer_toolset_20260801'
|
|
211
|
+
) {
|
|
212
|
+
toolsetNames[tool.name] = 'computer';
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return toolsetNames;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Toolset member calls (e.g. `left_click` from the computer toolset) are
|
|
221
|
+
* exposed as a single tool call on the toolset tool. The member name is
|
|
222
|
+
* injected as the `action` property, matching the input shape of the older
|
|
223
|
+
* computer tool versions.
|
|
224
|
+
*/
|
|
225
|
+
function toToolsetMemberInput({
|
|
226
|
+
memberName,
|
|
227
|
+
input,
|
|
228
|
+
}: {
|
|
229
|
+
memberName: string;
|
|
230
|
+
input: unknown;
|
|
231
|
+
}): JSONObject {
|
|
232
|
+
return {
|
|
233
|
+
action: memberName,
|
|
234
|
+
...(typeof input === 'object' && input !== null && !Array.isArray(input)
|
|
235
|
+
? (input as JSONObject)
|
|
236
|
+
: {}),
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
198
240
|
function getProviderOptionsName(provider: string): string {
|
|
199
241
|
const dotIndex = provider.indexOf('.');
|
|
200
242
|
return dotIndex === -1 ? provider : provider.substring(0, dotIndex);
|
|
@@ -362,6 +404,8 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
362
404
|
rejectsSamplingParameters,
|
|
363
405
|
supportsXhighEffort,
|
|
364
406
|
rejectsThinkingDisabledAboveHighEffort,
|
|
407
|
+
rejectsThinkingDisabled,
|
|
408
|
+
rejectsForcedToolUse,
|
|
365
409
|
isKnownModel,
|
|
366
410
|
} = getModelCapabilities(modelId);
|
|
367
411
|
|
|
@@ -414,10 +458,30 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
414
458
|
|
|
415
459
|
const structureOutputMode =
|
|
416
460
|
anthropicOptions?.structuredOutputMode ?? 'auto';
|
|
417
|
-
|
|
461
|
+
let useStructuredOutput =
|
|
418
462
|
structureOutputMode === 'outputFormat' ||
|
|
419
463
|
(structureOutputMode === 'auto' && supportsStructuredOutput);
|
|
420
464
|
|
|
465
|
+
// The JSON response tool relies on forced tool use, which some models
|
|
466
|
+
// reject (e.g. Opus 5.5, Fable 5.1). Fall back to native structured
|
|
467
|
+
// outputs when the model supports them.
|
|
468
|
+
if (
|
|
469
|
+
!useStructuredOutput &&
|
|
470
|
+
rejectsForcedToolUse &&
|
|
471
|
+
supportsStructuredOutput &&
|
|
472
|
+
responseFormat?.type === 'json' &&
|
|
473
|
+
responseFormat.schema != null
|
|
474
|
+
) {
|
|
475
|
+
warnings.push({
|
|
476
|
+
type: 'unsupported',
|
|
477
|
+
feature: 'providerOptions.anthropic.structuredOutputMode',
|
|
478
|
+
details:
|
|
479
|
+
`structuredOutputMode 'jsonTool' is not supported by ${modelId} because it rejects forced tool use. ` +
|
|
480
|
+
`Using 'outputFormat' instead.`,
|
|
481
|
+
});
|
|
482
|
+
useStructuredOutput = true;
|
|
483
|
+
}
|
|
484
|
+
|
|
421
485
|
const jsonResponseTool: LanguageModelV4FunctionTool | undefined =
|
|
422
486
|
responseFormat?.type === 'json' &&
|
|
423
487
|
responseFormat.schema != null &&
|
|
@@ -456,6 +520,8 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
456
520
|
'anthropic.code_execution_20260120': 'code_execution',
|
|
457
521
|
'anthropic.computer_20241022': 'computer',
|
|
458
522
|
'anthropic.computer_20250124': 'computer',
|
|
523
|
+
'anthropic.computer_20251124': 'computer',
|
|
524
|
+
'anthropic.computer_toolset_20260801': 'computer',
|
|
459
525
|
'anthropic.text_editor_20241022': 'str_replace_editor',
|
|
460
526
|
'anthropic.text_editor_20250124': 'str_replace_editor',
|
|
461
527
|
'anthropic.text_editor_20250429': 'str_replace_based_edit_tool',
|
|
@@ -475,12 +541,15 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
475
541
|
},
|
|
476
542
|
});
|
|
477
543
|
|
|
544
|
+
const toolsetNames = getAnthropicToolsetNames(tools);
|
|
545
|
+
|
|
478
546
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicPrompt({
|
|
479
547
|
prompt,
|
|
480
548
|
sendReasoning: anthropicOptions?.sendReasoning ?? true,
|
|
481
549
|
warnings,
|
|
482
550
|
cacheControlValidator,
|
|
483
551
|
toolNameMapping,
|
|
552
|
+
toolsetNames,
|
|
484
553
|
});
|
|
485
554
|
|
|
486
555
|
/*
|
|
@@ -490,8 +559,10 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
490
559
|
if (isCustomReasoning(reasoning) && anthropicOptions?.effort == null) {
|
|
491
560
|
const reasoningConfig = resolveAnthropicReasoningConfig({
|
|
492
561
|
reasoning,
|
|
562
|
+
modelId,
|
|
493
563
|
supportsAdaptiveThinking,
|
|
494
564
|
supportsXhighEffort,
|
|
565
|
+
rejectsThinkingDisabled,
|
|
495
566
|
maxOutputTokensForModel,
|
|
496
567
|
warnings,
|
|
497
568
|
});
|
|
@@ -508,6 +579,33 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
508
579
|
}
|
|
509
580
|
}
|
|
510
581
|
|
|
582
|
+
// Some models always run adaptive thinking and reject `disabled` and
|
|
583
|
+
// budget-based `enabled` thinking with a 400. Drop the unsupported
|
|
584
|
+
// setting and keep the request adaptive so it still succeeds.
|
|
585
|
+
if (rejectsThinkingDisabled && anthropicOptions?.thinking != null) {
|
|
586
|
+
const thinking = anthropicOptions.thinking;
|
|
587
|
+
|
|
588
|
+
if (thinking.type === 'disabled') {
|
|
589
|
+
warnings.push({
|
|
590
|
+
type: 'unsupported',
|
|
591
|
+
feature: 'providerOptions.anthropic.thinking',
|
|
592
|
+
details:
|
|
593
|
+
`thinking cannot be disabled for ${modelId}; it always uses adaptive thinking. ` +
|
|
594
|
+
`The thinking setting has been removed. Lower 'effort' to reduce thinking.`,
|
|
595
|
+
});
|
|
596
|
+
anthropicOptions.thinking = undefined;
|
|
597
|
+
} else if (thinking.type === 'enabled') {
|
|
598
|
+
warnings.push({
|
|
599
|
+
type: 'unsupported',
|
|
600
|
+
feature: 'providerOptions.anthropic.thinking',
|
|
601
|
+
details:
|
|
602
|
+
`budget-based thinking is not supported by ${modelId}; it always uses adaptive thinking. ` +
|
|
603
|
+
`Using adaptive thinking instead. Use 'effort' to control how much the model thinks.`,
|
|
604
|
+
});
|
|
605
|
+
anthropicOptions.thinking = { type: 'adaptive' };
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
511
609
|
// Newer models only allow disabling thinking at effort levels up to and
|
|
512
610
|
// including `high`; at `xhigh` and `max` the API returns a 400. Lower
|
|
513
611
|
// the effort to `high` to preserve the explicit request to run without
|
|
@@ -903,6 +1001,7 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
903
1001
|
supportsStructuredOutput: false,
|
|
904
1002
|
supportsStrictTools,
|
|
905
1003
|
defaultEagerInputStreaming,
|
|
1004
|
+
rejectsForcedToolUse,
|
|
906
1005
|
}
|
|
907
1006
|
: {
|
|
908
1007
|
tools: tools ?? [],
|
|
@@ -912,6 +1011,7 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
912
1011
|
supportsStructuredOutput,
|
|
913
1012
|
supportsStrictTools,
|
|
914
1013
|
defaultEagerInputStreaming,
|
|
1014
|
+
rejectsForcedToolUse,
|
|
915
1015
|
},
|
|
916
1016
|
);
|
|
917
1017
|
|
|
@@ -1184,6 +1284,27 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1184
1284
|
type: 'text',
|
|
1185
1285
|
text: JSON.stringify(part.input),
|
|
1186
1286
|
});
|
|
1287
|
+
} else if (part.toolset_name != null) {
|
|
1288
|
+
// toolset member calls (e.g. the computer toolset) are mapped to
|
|
1289
|
+
// the toolset tool with the member name as the `action`:
|
|
1290
|
+
content.push({
|
|
1291
|
+
type: 'tool-call',
|
|
1292
|
+
toolCallId: part.id,
|
|
1293
|
+
toolName: toolNameMapping.toCustomToolName(part.toolset_name),
|
|
1294
|
+
input: JSON.stringify(
|
|
1295
|
+
toToolsetMemberInput({
|
|
1296
|
+
memberName: part.name,
|
|
1297
|
+
input: part.input,
|
|
1298
|
+
}),
|
|
1299
|
+
),
|
|
1300
|
+
providerMetadata: {
|
|
1301
|
+
anthropic: {
|
|
1302
|
+
toolsetName: part.toolset_name,
|
|
1303
|
+
...getAnthropicCallerMetadata(part.caller).providerMetadata
|
|
1304
|
+
?.anthropic,
|
|
1305
|
+
},
|
|
1306
|
+
},
|
|
1307
|
+
});
|
|
1187
1308
|
} else {
|
|
1188
1309
|
content.push({
|
|
1189
1310
|
type: 'tool-call',
|
|
@@ -1696,6 +1817,12 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1696
1817
|
firstDelta: boolean;
|
|
1697
1818
|
providerToolName?: string;
|
|
1698
1819
|
providerToolInputType?: string;
|
|
1820
|
+
/**
|
|
1821
|
+
* Set for toolset member calls (e.g. the computer toolset). The raw
|
|
1822
|
+
* member input is accumulated and emitted as a single delta with the
|
|
1823
|
+
* member name injected as `action` when the block completes.
|
|
1824
|
+
*/
|
|
1825
|
+
toolset?: { name: string; memberName: string };
|
|
1699
1826
|
caller?: {
|
|
1700
1827
|
type:
|
|
1701
1828
|
| 'code_execution_20250825'
|
|
@@ -1862,6 +1989,34 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1862
1989
|
type: 'text-start',
|
|
1863
1990
|
id: String(value.index),
|
|
1864
1991
|
});
|
|
1992
|
+
} else if (part.toolset_name != null) {
|
|
1993
|
+
const callerInfo = getAnthropicCallerInfo(part.caller);
|
|
1994
|
+
const customToolName = toolNameMapping.toCustomToolName(
|
|
1995
|
+
part.toolset_name,
|
|
1996
|
+
);
|
|
1997
|
+
const hasNonEmptyInput =
|
|
1998
|
+
part.input && Object.keys(part.input).length > 0;
|
|
1999
|
+
|
|
2000
|
+
// toolset member input is accumulated and emitted when the
|
|
2001
|
+
// block completes (see content_block_stop):
|
|
2002
|
+
contentBlocks[value.index] = {
|
|
2003
|
+
type: 'tool-call',
|
|
2004
|
+
toolCallId: part.id,
|
|
2005
|
+
toolName: customToolName,
|
|
2006
|
+
input: hasNonEmptyInput ? JSON.stringify(part.input) : '',
|
|
2007
|
+
firstDelta: true,
|
|
2008
|
+
toolset: {
|
|
2009
|
+
name: part.toolset_name,
|
|
2010
|
+
memberName: part.name,
|
|
2011
|
+
},
|
|
2012
|
+
...(callerInfo && { caller: callerInfo }),
|
|
2013
|
+
};
|
|
2014
|
+
|
|
2015
|
+
controller.enqueue({
|
|
2016
|
+
type: 'tool-input-start',
|
|
2017
|
+
id: part.id,
|
|
2018
|
+
toolName: customToolName,
|
|
2019
|
+
});
|
|
1865
2020
|
} else {
|
|
1866
2021
|
const callerInfo = getAnthropicCallerInfo(part.caller);
|
|
1867
2022
|
|
|
@@ -2352,6 +2507,37 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
2352
2507
|
usesJsonResponseTool && contentBlock.toolName === 'json';
|
|
2353
2508
|
|
|
2354
2509
|
if (!isJsonResponseTool) {
|
|
2510
|
+
// toolset member calls: emit the accumulated input with
|
|
2511
|
+
// the member name injected as `action` in one delta.
|
|
2512
|
+
if (contentBlock.toolset != null) {
|
|
2513
|
+
let memberInput: unknown = {};
|
|
2514
|
+
try {
|
|
2515
|
+
memberInput =
|
|
2516
|
+
contentBlock.input === ''
|
|
2517
|
+
? {}
|
|
2518
|
+
: secureJsonParse(contentBlock.input);
|
|
2519
|
+
} catch {
|
|
2520
|
+
// ignore parse errors, fall back to the raw input
|
|
2521
|
+
memberInput = undefined;
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
contentBlock.input =
|
|
2525
|
+
memberInput === undefined
|
|
2526
|
+
? contentBlock.input
|
|
2527
|
+
: JSON.stringify(
|
|
2528
|
+
toToolsetMemberInput({
|
|
2529
|
+
memberName: contentBlock.toolset.memberName,
|
|
2530
|
+
input: memberInput,
|
|
2531
|
+
}),
|
|
2532
|
+
);
|
|
2533
|
+
|
|
2534
|
+
controller.enqueue({
|
|
2535
|
+
type: 'tool-input-delta',
|
|
2536
|
+
id: contentBlock.toolCallId,
|
|
2537
|
+
delta: contentBlock.input,
|
|
2538
|
+
});
|
|
2539
|
+
}
|
|
2540
|
+
|
|
2355
2541
|
controller.enqueue({
|
|
2356
2542
|
type: 'tool-input-end',
|
|
2357
2543
|
id: contentBlock.toolCallId,
|
|
@@ -2394,10 +2580,15 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
2394
2580
|
contentBlock.providerToolName === 'code_execution'
|
|
2395
2581
|
? { dynamic: true }
|
|
2396
2582
|
: {}),
|
|
2397
|
-
...(contentBlock.caller && {
|
|
2583
|
+
...((contentBlock.caller || contentBlock.toolset) && {
|
|
2398
2584
|
providerMetadata: {
|
|
2399
2585
|
anthropic: {
|
|
2400
|
-
|
|
2586
|
+
...(contentBlock.toolset && {
|
|
2587
|
+
toolsetName: contentBlock.toolset.name,
|
|
2588
|
+
}),
|
|
2589
|
+
...(contentBlock.caller && {
|
|
2590
|
+
caller: contentBlock.caller,
|
|
2591
|
+
}),
|
|
2401
2592
|
},
|
|
2402
2593
|
},
|
|
2403
2594
|
}),
|
|
@@ -2499,6 +2690,13 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
2499
2690
|
return;
|
|
2500
2691
|
}
|
|
2501
2692
|
|
|
2693
|
+
// toolset member input is emitted as a single delta once
|
|
2694
|
+
// the block is complete (the member name is injected):
|
|
2695
|
+
if (contentBlock.toolset != null) {
|
|
2696
|
+
contentBlock.input += delta;
|
|
2697
|
+
return;
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2502
2700
|
// for the code execution 20250825, we need to add
|
|
2503
2701
|
// the type to the delta and change the tool name.
|
|
2504
2702
|
if (
|
|
@@ -2872,9 +3070,30 @@ export function getModelCapabilities(modelId: string): {
|
|
|
2872
3070
|
rejectsSamplingParameters: boolean;
|
|
2873
3071
|
supportsXhighEffort: boolean;
|
|
2874
3072
|
rejectsThinkingDisabledAboveHighEffort: boolean;
|
|
3073
|
+
/**
|
|
3074
|
+
* Thinking is always adaptive: `thinking.type` `disabled` and `enabled`
|
|
3075
|
+
* are rejected with a 400.
|
|
3076
|
+
*/
|
|
3077
|
+
rejectsThinkingDisabled: boolean;
|
|
3078
|
+
/**
|
|
3079
|
+
* Forced tool use (`tool_choice` `any` or a named tool) is rejected with a 400.
|
|
3080
|
+
*/
|
|
3081
|
+
rejectsForcedToolUse: boolean;
|
|
2875
3082
|
isKnownModel: boolean;
|
|
2876
3083
|
} {
|
|
2877
|
-
if (modelId.includes('claude-opus-5')) {
|
|
3084
|
+
if (modelId.includes('claude-opus-5-5')) {
|
|
3085
|
+
return {
|
|
3086
|
+
maxOutputTokens: 128000,
|
|
3087
|
+
supportsStructuredOutput: true,
|
|
3088
|
+
supportsAdaptiveThinking: true,
|
|
3089
|
+
rejectsSamplingParameters: true,
|
|
3090
|
+
supportsXhighEffort: true,
|
|
3091
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
3092
|
+
rejectsThinkingDisabled: true,
|
|
3093
|
+
rejectsForcedToolUse: true,
|
|
3094
|
+
isKnownModel: true,
|
|
3095
|
+
};
|
|
3096
|
+
} else if (modelId.includes('claude-opus-5')) {
|
|
2878
3097
|
return {
|
|
2879
3098
|
maxOutputTokens: 128000,
|
|
2880
3099
|
supportsStructuredOutput: true,
|
|
@@ -2882,12 +3101,37 @@ export function getModelCapabilities(modelId: string): {
|
|
|
2882
3101
|
rejectsSamplingParameters: true,
|
|
2883
3102
|
supportsXhighEffort: true,
|
|
2884
3103
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
3104
|
+
rejectsThinkingDisabled: false,
|
|
3105
|
+
rejectsForcedToolUse: false,
|
|
3106
|
+
isKnownModel: true,
|
|
3107
|
+
};
|
|
3108
|
+
} else if (modelId.includes('claude-fable-5-1')) {
|
|
3109
|
+
return {
|
|
3110
|
+
maxOutputTokens: 128000,
|
|
3111
|
+
supportsStructuredOutput: true,
|
|
3112
|
+
supportsAdaptiveThinking: true,
|
|
3113
|
+
rejectsSamplingParameters: true,
|
|
3114
|
+
supportsXhighEffort: true,
|
|
3115
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3116
|
+
rejectsThinkingDisabled: true,
|
|
3117
|
+
rejectsForcedToolUse: true,
|
|
3118
|
+
isKnownModel: true,
|
|
3119
|
+
};
|
|
3120
|
+
} else if (modelId.includes('claude-fable-5')) {
|
|
3121
|
+
return {
|
|
3122
|
+
maxOutputTokens: 128000,
|
|
3123
|
+
supportsStructuredOutput: true,
|
|
3124
|
+
supportsAdaptiveThinking: true,
|
|
3125
|
+
rejectsSamplingParameters: true,
|
|
3126
|
+
supportsXhighEffort: true,
|
|
3127
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3128
|
+
rejectsThinkingDisabled: true,
|
|
3129
|
+
rejectsForcedToolUse: false,
|
|
2885
3130
|
isKnownModel: true,
|
|
2886
3131
|
};
|
|
2887
3132
|
} else if (
|
|
2888
3133
|
modelId.includes('claude-opus-4-8') ||
|
|
2889
3134
|
modelId.includes('claude-opus-4-7') ||
|
|
2890
|
-
modelId.includes('claude-fable-5') ||
|
|
2891
3135
|
modelId.includes('claude-sonnet-5')
|
|
2892
3136
|
) {
|
|
2893
3137
|
return {
|
|
@@ -2897,6 +3141,8 @@ export function getModelCapabilities(modelId: string): {
|
|
|
2897
3141
|
rejectsSamplingParameters: true,
|
|
2898
3142
|
supportsXhighEffort: true,
|
|
2899
3143
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3144
|
+
rejectsThinkingDisabled: false,
|
|
3145
|
+
rejectsForcedToolUse: false,
|
|
2900
3146
|
isKnownModel: true,
|
|
2901
3147
|
};
|
|
2902
3148
|
} else if (
|
|
@@ -2910,6 +3156,8 @@ export function getModelCapabilities(modelId: string): {
|
|
|
2910
3156
|
rejectsSamplingParameters: false,
|
|
2911
3157
|
supportsXhighEffort: false,
|
|
2912
3158
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3159
|
+
rejectsThinkingDisabled: false,
|
|
3160
|
+
rejectsForcedToolUse: false,
|
|
2913
3161
|
isKnownModel: true,
|
|
2914
3162
|
};
|
|
2915
3163
|
} else if (
|
|
@@ -2924,6 +3172,8 @@ export function getModelCapabilities(modelId: string): {
|
|
|
2924
3172
|
rejectsSamplingParameters: false,
|
|
2925
3173
|
supportsXhighEffort: false,
|
|
2926
3174
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3175
|
+
rejectsThinkingDisabled: false,
|
|
3176
|
+
rejectsForcedToolUse: false,
|
|
2927
3177
|
isKnownModel: true,
|
|
2928
3178
|
};
|
|
2929
3179
|
} else if (modelId.includes('claude-opus-4-1')) {
|
|
@@ -2934,6 +3184,8 @@ export function getModelCapabilities(modelId: string): {
|
|
|
2934
3184
|
rejectsSamplingParameters: false,
|
|
2935
3185
|
supportsXhighEffort: false,
|
|
2936
3186
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3187
|
+
rejectsThinkingDisabled: false,
|
|
3188
|
+
rejectsForcedToolUse: false,
|
|
2937
3189
|
isKnownModel: true,
|
|
2938
3190
|
};
|
|
2939
3191
|
} else if (/claude-sonnet-4(?:-|@)/.test(modelId)) {
|
|
@@ -2944,6 +3196,8 @@ export function getModelCapabilities(modelId: string): {
|
|
|
2944
3196
|
rejectsSamplingParameters: false,
|
|
2945
3197
|
supportsXhighEffort: false,
|
|
2946
3198
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3199
|
+
rejectsThinkingDisabled: false,
|
|
3200
|
+
rejectsForcedToolUse: false,
|
|
2947
3201
|
isKnownModel: true,
|
|
2948
3202
|
};
|
|
2949
3203
|
} else if (/claude-opus-4(?:-|@)/.test(modelId)) {
|
|
@@ -2954,6 +3208,8 @@ export function getModelCapabilities(modelId: string): {
|
|
|
2954
3208
|
rejectsSamplingParameters: false,
|
|
2955
3209
|
supportsXhighEffort: false,
|
|
2956
3210
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3211
|
+
rejectsThinkingDisabled: false,
|
|
3212
|
+
rejectsForcedToolUse: false,
|
|
2957
3213
|
isKnownModel: true,
|
|
2958
3214
|
};
|
|
2959
3215
|
} else if (modelId.includes('claude-3-haiku')) {
|
|
@@ -2964,6 +3220,8 @@ export function getModelCapabilities(modelId: string): {
|
|
|
2964
3220
|
rejectsSamplingParameters: false,
|
|
2965
3221
|
supportsXhighEffort: false,
|
|
2966
3222
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3223
|
+
rejectsThinkingDisabled: false,
|
|
3224
|
+
rejectsForcedToolUse: false,
|
|
2967
3225
|
isKnownModel: true,
|
|
2968
3226
|
};
|
|
2969
3227
|
} else if (
|
|
@@ -2976,6 +3234,8 @@ export function getModelCapabilities(modelId: string): {
|
|
|
2976
3234
|
rejectsSamplingParameters: false,
|
|
2977
3235
|
supportsXhighEffort: false,
|
|
2978
3236
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3237
|
+
rejectsThinkingDisabled: false,
|
|
3238
|
+
rejectsForcedToolUse: false,
|
|
2979
3239
|
isKnownModel: false,
|
|
2980
3240
|
};
|
|
2981
3241
|
} else if (modelId.includes('claude-')) {
|
|
@@ -2989,6 +3249,8 @@ export function getModelCapabilities(modelId: string): {
|
|
|
2989
3249
|
rejectsSamplingParameters: true,
|
|
2990
3250
|
supportsXhighEffort: true,
|
|
2991
3251
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
3252
|
+
rejectsThinkingDisabled: false,
|
|
3253
|
+
rejectsForcedToolUse: false,
|
|
2992
3254
|
isKnownModel: false,
|
|
2993
3255
|
};
|
|
2994
3256
|
} else {
|
|
@@ -3001,6 +3263,8 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3001
3263
|
rejectsSamplingParameters: false,
|
|
3002
3264
|
supportsXhighEffort: false,
|
|
3003
3265
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3266
|
+
rejectsThinkingDisabled: false,
|
|
3267
|
+
rejectsForcedToolUse: false,
|
|
3004
3268
|
isKnownModel: false,
|
|
3005
3269
|
};
|
|
3006
3270
|
}
|
|
@@ -3040,14 +3304,18 @@ export function hasDynamicFilteringWebToolWithoutCodeExecution(
|
|
|
3040
3304
|
|
|
3041
3305
|
function resolveAnthropicReasoningConfig({
|
|
3042
3306
|
reasoning,
|
|
3307
|
+
modelId,
|
|
3043
3308
|
supportsAdaptiveThinking,
|
|
3044
3309
|
supportsXhighEffort,
|
|
3310
|
+
rejectsThinkingDisabled,
|
|
3045
3311
|
maxOutputTokensForModel,
|
|
3046
3312
|
warnings,
|
|
3047
3313
|
}: {
|
|
3048
3314
|
reasoning: LanguageModelV4CallOptions['reasoning'];
|
|
3315
|
+
modelId: string;
|
|
3049
3316
|
supportsAdaptiveThinking: boolean;
|
|
3050
3317
|
supportsXhighEffort: boolean;
|
|
3318
|
+
rejectsThinkingDisabled: boolean;
|
|
3051
3319
|
maxOutputTokensForModel: number;
|
|
3052
3320
|
warnings: SharedV4Warning[];
|
|
3053
3321
|
}): Pick<AnthropicLanguageModelOptions, 'thinking' | 'effort'> | undefined {
|
|
@@ -3056,6 +3324,20 @@ function resolveAnthropicReasoningConfig({
|
|
|
3056
3324
|
}
|
|
3057
3325
|
|
|
3058
3326
|
if (reasoning === 'none') {
|
|
3327
|
+
// Models that always run adaptive thinking cannot disable it. Use low
|
|
3328
|
+
// effort to keep thinking short instead of sending a request that the
|
|
3329
|
+
// API would reject.
|
|
3330
|
+
if (rejectsThinkingDisabled) {
|
|
3331
|
+
warnings.push({
|
|
3332
|
+
type: 'compatibility',
|
|
3333
|
+
feature: 'reasoning',
|
|
3334
|
+
details:
|
|
3335
|
+
`reasoning 'none' is not supported by ${modelId}; it always uses adaptive thinking. ` +
|
|
3336
|
+
`Using effort 'low' to minimize thinking instead.`,
|
|
3337
|
+
});
|
|
3338
|
+
return { effort: 'low' };
|
|
3339
|
+
}
|
|
3340
|
+
|
|
3059
3341
|
return { thinking: { type: 'disabled' } };
|
|
3060
3342
|
}
|
|
3061
3343
|
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
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
|
+
import { computerToolset_20260801ArgsSchema } from './tool/computer-toolset_20260801';
|
|
9
10
|
import { textEditor_20250728ArgsSchema } from './tool/text-editor_20250728';
|
|
10
11
|
import { webSearch_20260318ArgsSchema } from './tool/web-search_20260318';
|
|
11
12
|
import { webSearch_20260209ArgsSchema } from './tool/web-search_20260209';
|
|
@@ -31,6 +32,7 @@ export async function prepareTools({
|
|
|
31
32
|
supportsStructuredOutput,
|
|
32
33
|
supportsStrictTools,
|
|
33
34
|
defaultEagerInputStreaming = false,
|
|
35
|
+
rejectsForcedToolUse = false,
|
|
34
36
|
}: {
|
|
35
37
|
tools: LanguageModelV4CallOptions['tools'];
|
|
36
38
|
toolChoice: LanguageModelV4CallOptions['toolChoice'] | undefined;
|
|
@@ -52,6 +54,13 @@ export async function prepareTools({
|
|
|
52
54
|
* it explicitly. Driven by the model-level `toolStreaming` option.
|
|
53
55
|
*/
|
|
54
56
|
defaultEagerInputStreaming?: boolean;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Whether the model rejects forced tool use (`tool_choice` `any` or a
|
|
60
|
+
* named tool). When true, `required` and `tool` tool choices fall back to
|
|
61
|
+
* `auto` with a warning.
|
|
62
|
+
*/
|
|
63
|
+
rejectsForcedToolUse?: boolean;
|
|
55
64
|
}): Promise<{
|
|
56
65
|
tools: Array<AnthropicTool> | undefined;
|
|
57
66
|
toolChoice: AnthropicToolChoice | undefined;
|
|
@@ -185,6 +194,34 @@ export async function prepareTools({
|
|
|
185
194
|
});
|
|
186
195
|
break;
|
|
187
196
|
}
|
|
197
|
+
case 'anthropic.computer_toolset_20260801': {
|
|
198
|
+
const args = await validateTypes({
|
|
199
|
+
value: tool.args,
|
|
200
|
+
schema: computerToolset_20260801ArgsSchema,
|
|
201
|
+
});
|
|
202
|
+
const configs =
|
|
203
|
+
args.configs != null
|
|
204
|
+
? Object.fromEntries(
|
|
205
|
+
Object.entries(args.configs).map(([member, config]) => [
|
|
206
|
+
member,
|
|
207
|
+
{
|
|
208
|
+
...(config?.enabled != null && {
|
|
209
|
+
enabled: config.enabled,
|
|
210
|
+
}),
|
|
211
|
+
...(config?.deferLoading != null && {
|
|
212
|
+
defer_loading: config.deferLoading,
|
|
213
|
+
}),
|
|
214
|
+
},
|
|
215
|
+
]),
|
|
216
|
+
)
|
|
217
|
+
: undefined;
|
|
218
|
+
anthropicTools.push({
|
|
219
|
+
type: 'computer_toolset_20260801',
|
|
220
|
+
...(configs != null && { configs }),
|
|
221
|
+
cache_control: undefined,
|
|
222
|
+
});
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
188
225
|
case 'anthropic.computer_20241022': {
|
|
189
226
|
betas.add('computer-use-2024-10-22');
|
|
190
227
|
anthropicTools.push({
|
|
@@ -450,6 +487,24 @@ export async function prepareTools({
|
|
|
450
487
|
betas,
|
|
451
488
|
};
|
|
452
489
|
case 'required':
|
|
490
|
+
if (rejectsForcedToolUse) {
|
|
491
|
+
toolWarnings.push({
|
|
492
|
+
type: 'unsupported',
|
|
493
|
+
feature: 'toolChoice',
|
|
494
|
+
details:
|
|
495
|
+
`toolChoice 'required' is not supported by this model because it rejects forced tool use. ` +
|
|
496
|
+
`Using 'auto' instead. Instruct the model to use a tool in the prompt and verify that a tool call was made.`,
|
|
497
|
+
});
|
|
498
|
+
return {
|
|
499
|
+
tools: anthropicTools,
|
|
500
|
+
toolChoice: {
|
|
501
|
+
type: 'auto',
|
|
502
|
+
disable_parallel_tool_use: disableParallelToolUse,
|
|
503
|
+
},
|
|
504
|
+
toolWarnings,
|
|
505
|
+
betas,
|
|
506
|
+
};
|
|
507
|
+
}
|
|
453
508
|
return {
|
|
454
509
|
tools: anthropicTools,
|
|
455
510
|
toolChoice: {
|
|
@@ -463,6 +518,27 @@ export async function prepareTools({
|
|
|
463
518
|
// Anthropic does not support 'none' tool choice, so we remove the tools:
|
|
464
519
|
return { tools: undefined, toolChoice: undefined, toolWarnings, betas };
|
|
465
520
|
case 'tool':
|
|
521
|
+
if (rejectsForcedToolUse) {
|
|
522
|
+
toolWarnings.push({
|
|
523
|
+
type: 'unsupported',
|
|
524
|
+
feature: 'toolChoice',
|
|
525
|
+
details:
|
|
526
|
+
`toolChoice 'tool' is not supported by this model because it rejects forced tool use. ` +
|
|
527
|
+
`Only the '${toolChoice.toolName}' tool is sent with 'auto' tool choice. ` +
|
|
528
|
+
`Instruct the model to use the tool in the prompt and verify that a tool call was made.`,
|
|
529
|
+
});
|
|
530
|
+
return {
|
|
531
|
+
tools: anthropicTools.filter(
|
|
532
|
+
tool => 'name' in tool && tool.name === toolChoice.toolName,
|
|
533
|
+
),
|
|
534
|
+
toolChoice: {
|
|
535
|
+
type: 'auto',
|
|
536
|
+
disable_parallel_tool_use: disableParallelToolUse,
|
|
537
|
+
},
|
|
538
|
+
toolWarnings,
|
|
539
|
+
betas,
|
|
540
|
+
};
|
|
541
|
+
}
|
|
466
542
|
return {
|
|
467
543
|
tools: anthropicTools,
|
|
468
544
|
toolChoice: {
|
package/src/anthropic-tools.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { codeExecution_20260120 } from './tool/code-execution_20260120';
|
|
|
7
7
|
import { computer_20241022 } from './tool/computer_20241022';
|
|
8
8
|
import { computer_20250124 } from './tool/computer_20250124';
|
|
9
9
|
import { computer_20251124 } from './tool/computer_20251124';
|
|
10
|
+
import { computerToolset_20260801 } from './tool/computer-toolset_20260801';
|
|
10
11
|
import { memory_20250818 } from './tool/memory_20250818';
|
|
11
12
|
import { textEditor_20241022 } from './tool/text-editor_20241022';
|
|
12
13
|
import { textEditor_20250124 } from './tool/text-editor_20250124';
|
|
@@ -147,6 +148,30 @@ export const anthropicTools = {
|
|
|
147
148
|
*/
|
|
148
149
|
computer_20251124,
|
|
149
150
|
|
|
151
|
+
/**
|
|
152
|
+
* The computer toolset lets Claude control a computer through screenshots,
|
|
153
|
+
* mouse, and keyboard. It replaces the versioned computer tools
|
|
154
|
+
* (`computer_20251124` and earlier) on newer models.
|
|
155
|
+
*
|
|
156
|
+
* The API returns each computer action as its own `tool_use` block with
|
|
157
|
+
* `toolset_name: 'computer'`. The AI SDK maps every member call to this tool
|
|
158
|
+
* and exposes the member name as `action`, so `execute` receives the same
|
|
159
|
+
* input shape as the older computer tools. Claude may return several actions
|
|
160
|
+
* in one turn.
|
|
161
|
+
*
|
|
162
|
+
* Coordinates are always in the pixel space of the screenshots you return;
|
|
163
|
+
* there are no display size parameters. Zoom is enabled by default.
|
|
164
|
+
*
|
|
165
|
+
* Does not require a beta header.
|
|
166
|
+
*
|
|
167
|
+
* Supported models: Claude Opus 5.5 (required; older computer tool types
|
|
168
|
+
* are rejected), Opus 5, Sonnet 5, Fable 5, Fable 5.1, Opus 4.8.
|
|
169
|
+
*
|
|
170
|
+
* @param configs - Per-member settings keyed by member name, e.g.
|
|
171
|
+
* `{ zoom: { enabled: false } }`. Omitted members keep their defaults.
|
|
172
|
+
*/
|
|
173
|
+
computerToolset_20260801,
|
|
174
|
+
|
|
150
175
|
/**
|
|
151
176
|
* The memory tool enables Claude to store and retrieve information across conversations through a memory file directory.
|
|
152
177
|
* Claude can create, read, update, and delete files that persist between sessions,
|