@ai-sdk/anthropic 4.0.65 → 4.0.67
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 +22 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +103 -4
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +7 -2
- package/dist/internal/index.js +102 -3
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +111 -40
- package/package.json +3 -3
- package/src/anthropic-language-model-options.ts +12 -0
- package/src/anthropic-language-model.ts +73 -3
- package/src/convert-to-anthropic-prompt.ts +54 -0
package/dist/internal/index.d.ts
CHANGED
|
@@ -799,7 +799,7 @@ type Citation = NonNullable<(InferSchema<typeof anthropicResponseSchema>['conten
|
|
|
799
799
|
type: 'text';
|
|
800
800
|
})['citations']>[number];
|
|
801
801
|
|
|
802
|
-
type AnthropicModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | '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' | (string & {});
|
|
802
|
+
type AnthropicModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | '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' | (string & {});
|
|
803
803
|
|
|
804
804
|
type AnthropicLanguageModelConfig = {
|
|
805
805
|
provider: string;
|
|
@@ -941,7 +941,7 @@ declare class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
941
941
|
} | undefined;
|
|
942
942
|
display?: "omitted" | "summarized" | "updates" | undefined;
|
|
943
943
|
budget_tokens?: number | undefined;
|
|
944
|
-
type?: "enabled" | "adaptive" | "disabled" | undefined;
|
|
944
|
+
type?: "enabled" | "adaptive" | "disabled" | "between_tools" | undefined;
|
|
945
945
|
} | undefined;
|
|
946
946
|
model: AnthropicModelId;
|
|
947
947
|
max_tokens: number;
|
|
@@ -988,6 +988,11 @@ declare function getModelCapabilities(modelId: string): {
|
|
|
988
988
|
* Forced tool use (`tool_choice` `any` or a named tool) is rejected with a 400.
|
|
989
989
|
*/
|
|
990
990
|
rejectsForcedToolUse: boolean;
|
|
991
|
+
/**
|
|
992
|
+
* Supports `thinking.type` `between_tools`, the lowest thinking setting on
|
|
993
|
+
* models that reject disabled thinking.
|
|
994
|
+
*/
|
|
995
|
+
supportsBetweenToolsThinking: boolean;
|
|
991
996
|
isKnownModel: boolean;
|
|
992
997
|
};
|
|
993
998
|
|
package/dist/internal/index.js
CHANGED
|
@@ -1056,6 +1056,9 @@ var anthropicLanguageModelOptions = z4.object({
|
|
|
1056
1056
|
* `claude-fable-5-1`) reject `enabled` and `disabled`. For those models the
|
|
1057
1057
|
* provider drops the unsupported setting, emits a warning, and sends an
|
|
1058
1058
|
* adaptive thinking request. Use `effort` to control how much they think.
|
|
1059
|
+
*
|
|
1060
|
+
* `claude-sonnet-5-5` supports `between_tools`, its lowest thinking setting,
|
|
1061
|
+
* and the provider uses it in place of `disabled` for that model.
|
|
1059
1062
|
*/
|
|
1060
1063
|
thinking: z4.union([
|
|
1061
1064
|
z4.discriminatedUnion("type", [
|
|
@@ -1084,6 +1087,14 @@ var anthropicLanguageModelOptions = z4.object({
|
|
|
1084
1087
|
}),
|
|
1085
1088
|
z4.object({
|
|
1086
1089
|
type: z4.literal("disabled")
|
|
1090
|
+
}),
|
|
1091
|
+
z4.object({
|
|
1092
|
+
/**
|
|
1093
|
+
* for `claude-sonnet-5-5`: no upfront thinking, but progress notes
|
|
1094
|
+
* between tool calls are returned as summarized thinking blocks.
|
|
1095
|
+
* Only supported at `low`, `medium`, and `high` effort.
|
|
1096
|
+
*/
|
|
1097
|
+
type: z4.literal("between_tools")
|
|
1087
1098
|
})
|
|
1088
1099
|
]),
|
|
1089
1100
|
z4.object({
|
|
@@ -2774,6 +2785,7 @@ async function convertToAnthropicPrompt({
|
|
|
2774
2785
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
2775
2786
|
let system = void 0;
|
|
2776
2787
|
const messages = [];
|
|
2788
|
+
let lastUserMessageIndex = -1;
|
|
2777
2789
|
async function shouldEnableCitations(providerMetadata) {
|
|
2778
2790
|
const anthropicOptions = await parseProviderOptions({
|
|
2779
2791
|
provider: "anthropic",
|
|
@@ -2906,6 +2918,9 @@ async function convertToAnthropicPrompt({
|
|
|
2906
2918
|
const { role, content } = message;
|
|
2907
2919
|
switch (role) {
|
|
2908
2920
|
case "user": {
|
|
2921
|
+
if (content.length > 0) {
|
|
2922
|
+
lastUserMessageIndex = messages.length;
|
|
2923
|
+
}
|
|
2909
2924
|
for (let j = 0; j < content.length; j++) {
|
|
2910
2925
|
const part = content[j];
|
|
2911
2926
|
const isLastPart = j === content.length - 1;
|
|
@@ -3788,6 +3803,42 @@ async function convertToAnthropicPrompt({
|
|
|
3788
3803
|
}
|
|
3789
3804
|
}
|
|
3790
3805
|
}
|
|
3806
|
+
const codeExecutionToolCallIds = /* @__PURE__ */ new Set();
|
|
3807
|
+
for (const message of messages) {
|
|
3808
|
+
if (message.role !== "assistant") {
|
|
3809
|
+
continue;
|
|
3810
|
+
}
|
|
3811
|
+
for (const part of message.content) {
|
|
3812
|
+
if (part.type === "server_tool_use" && part.name === "code_execution") {
|
|
3813
|
+
codeExecutionToolCallIds.add(part.id);
|
|
3814
|
+
}
|
|
3815
|
+
}
|
|
3816
|
+
}
|
|
3817
|
+
const warnedToolCallIds = /* @__PURE__ */ new Set();
|
|
3818
|
+
for (let i = 0; i < lastUserMessageIndex; i++) {
|
|
3819
|
+
const message = messages[i];
|
|
3820
|
+
if (message.role !== "assistant") {
|
|
3821
|
+
continue;
|
|
3822
|
+
}
|
|
3823
|
+
for (const part of message.content) {
|
|
3824
|
+
if (!("caller" in part)) {
|
|
3825
|
+
continue;
|
|
3826
|
+
}
|
|
3827
|
+
const caller = part.caller;
|
|
3828
|
+
if (caller == null || caller.type === "direct" || codeExecutionToolCallIds.has(caller.tool_id)) {
|
|
3829
|
+
continue;
|
|
3830
|
+
}
|
|
3831
|
+
const toolCallId = "id" in part ? part.id : part.tool_use_id;
|
|
3832
|
+
delete part.caller;
|
|
3833
|
+
if (!warnedToolCallIds.has(toolCallId)) {
|
|
3834
|
+
warnedToolCallIds.add(toolCallId);
|
|
3835
|
+
warnings.push({
|
|
3836
|
+
type: "other",
|
|
3837
|
+
message: `Omitted caller metadata for tool ${toolCallId} because source code execution tool ${caller.tool_id} is missing from the conversation history.`
|
|
3838
|
+
});
|
|
3839
|
+
}
|
|
3840
|
+
}
|
|
3841
|
+
}
|
|
3791
3842
|
return {
|
|
3792
3843
|
prompt: { system, messages },
|
|
3793
3844
|
betas
|
|
@@ -4271,6 +4322,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4271
4322
|
rejectsThinkingDisabledAboveHighEffort,
|
|
4272
4323
|
rejectsThinkingDisabled,
|
|
4273
4324
|
rejectsForcedToolUse,
|
|
4325
|
+
supportsBetweenToolsThinking,
|
|
4274
4326
|
isKnownModel
|
|
4275
4327
|
} = getModelCapabilities(modelId);
|
|
4276
4328
|
if (!isKnownModel && maxOutputTokens == null) {
|
|
@@ -4385,6 +4437,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4385
4437
|
supportsAdaptiveThinking,
|
|
4386
4438
|
supportsXhighEffort,
|
|
4387
4439
|
rejectsThinkingDisabled,
|
|
4440
|
+
supportsBetweenToolsThinking,
|
|
4388
4441
|
maxOutputTokensForModel,
|
|
4389
4442
|
warnings
|
|
4390
4443
|
});
|
|
@@ -4399,7 +4452,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4399
4452
|
}
|
|
4400
4453
|
if (rejectsThinkingDisabled && anthropicOptions?.thinking != null) {
|
|
4401
4454
|
const thinking = anthropicOptions.thinking;
|
|
4402
|
-
if (thinking.type === "disabled") {
|
|
4455
|
+
if (thinking.type === "disabled" && supportsBetweenToolsThinking) {
|
|
4456
|
+
warnings.push({
|
|
4457
|
+
type: "unsupported",
|
|
4458
|
+
feature: "providerOptions.anthropic.thinking",
|
|
4459
|
+
details: `thinking cannot be disabled for ${modelId}. Using 'between_tools' thinking, the lowest thinking setting, instead.`
|
|
4460
|
+
});
|
|
4461
|
+
anthropicOptions.thinking = { type: "between_tools" };
|
|
4462
|
+
} else if (thinking.type === "disabled") {
|
|
4403
4463
|
warnings.push({
|
|
4404
4464
|
type: "unsupported",
|
|
4405
4465
|
feature: "providerOptions.anthropic.thinking",
|
|
@@ -4423,8 +4483,16 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4423
4483
|
});
|
|
4424
4484
|
anthropicOptions.effort = "high";
|
|
4425
4485
|
}
|
|
4486
|
+
if (anthropicOptions?.thinking?.type === "between_tools" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
|
|
4487
|
+
warnings.push({
|
|
4488
|
+
type: "unsupported",
|
|
4489
|
+
feature: "providerOptions.anthropic.effort",
|
|
4490
|
+
details: `effort '${anthropicOptions.effort}' is not supported with 'between_tools' thinking. The effort has been lowered to 'high'.`
|
|
4491
|
+
});
|
|
4492
|
+
anthropicOptions.effort = "high";
|
|
4493
|
+
}
|
|
4426
4494
|
const thinkingType = anthropicOptions?.thinking?.type;
|
|
4427
|
-
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
4495
|
+
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive" || thinkingType === "between_tools";
|
|
4428
4496
|
const thinkingBlockBinding = anthropicOptions?.thinking != null && "blockBinding" in anthropicOptions.thinking ? anthropicOptions.thinking.blockBinding : void 0;
|
|
4429
4497
|
const sendThinking = isThinking || thinkingType === "disabled" || thinkingBlockBinding != null;
|
|
4430
4498
|
let thinkingBudget = thinkingType === "enabled" ? anthropicOptions?.thinking?.budgetTokens : void 0;
|
|
@@ -6317,7 +6385,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6317
6385
|
}
|
|
6318
6386
|
};
|
|
6319
6387
|
function getModelCapabilities(modelId) {
|
|
6320
|
-
if (modelId.includes("claude-
|
|
6388
|
+
if (modelId.includes("claude-sonnet-5-5")) {
|
|
6321
6389
|
return {
|
|
6322
6390
|
maxOutputTokens: 128e3,
|
|
6323
6391
|
supportsStructuredOutput: true,
|
|
@@ -6327,6 +6395,20 @@ function getModelCapabilities(modelId) {
|
|
|
6327
6395
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
6328
6396
|
rejectsThinkingDisabled: true,
|
|
6329
6397
|
rejectsForcedToolUse: true,
|
|
6398
|
+
supportsBetweenToolsThinking: true,
|
|
6399
|
+
isKnownModel: true
|
|
6400
|
+
};
|
|
6401
|
+
} else if (modelId.includes("claude-opus-5-5")) {
|
|
6402
|
+
return {
|
|
6403
|
+
maxOutputTokens: 128e3,
|
|
6404
|
+
supportsStructuredOutput: true,
|
|
6405
|
+
supportsAdaptiveThinking: true,
|
|
6406
|
+
rejectsSamplingParameters: true,
|
|
6407
|
+
supportsXhighEffort: true,
|
|
6408
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
6409
|
+
rejectsThinkingDisabled: true,
|
|
6410
|
+
rejectsForcedToolUse: true,
|
|
6411
|
+
supportsBetweenToolsThinking: false,
|
|
6330
6412
|
isKnownModel: true
|
|
6331
6413
|
};
|
|
6332
6414
|
} else if (modelId.includes("claude-opus-5")) {
|
|
@@ -6339,6 +6421,7 @@ function getModelCapabilities(modelId) {
|
|
|
6339
6421
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
6340
6422
|
rejectsThinkingDisabled: false,
|
|
6341
6423
|
rejectsForcedToolUse: false,
|
|
6424
|
+
supportsBetweenToolsThinking: false,
|
|
6342
6425
|
isKnownModel: true
|
|
6343
6426
|
};
|
|
6344
6427
|
} else if (modelId.includes("claude-fable-5-1")) {
|
|
@@ -6351,6 +6434,7 @@ function getModelCapabilities(modelId) {
|
|
|
6351
6434
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
6352
6435
|
rejectsThinkingDisabled: true,
|
|
6353
6436
|
rejectsForcedToolUse: true,
|
|
6437
|
+
supportsBetweenToolsThinking: false,
|
|
6354
6438
|
isKnownModel: true
|
|
6355
6439
|
};
|
|
6356
6440
|
} else if (modelId.includes("claude-fable-5")) {
|
|
@@ -6363,6 +6447,7 @@ function getModelCapabilities(modelId) {
|
|
|
6363
6447
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
6364
6448
|
rejectsThinkingDisabled: true,
|
|
6365
6449
|
rejectsForcedToolUse: false,
|
|
6450
|
+
supportsBetweenToolsThinking: false,
|
|
6366
6451
|
isKnownModel: true
|
|
6367
6452
|
};
|
|
6368
6453
|
} else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-sonnet-5")) {
|
|
@@ -6375,6 +6460,7 @@ function getModelCapabilities(modelId) {
|
|
|
6375
6460
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
6376
6461
|
rejectsThinkingDisabled: false,
|
|
6377
6462
|
rejectsForcedToolUse: false,
|
|
6463
|
+
supportsBetweenToolsThinking: false,
|
|
6378
6464
|
isKnownModel: true
|
|
6379
6465
|
};
|
|
6380
6466
|
} else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
|
|
@@ -6387,6 +6473,7 @@ function getModelCapabilities(modelId) {
|
|
|
6387
6473
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
6388
6474
|
rejectsThinkingDisabled: false,
|
|
6389
6475
|
rejectsForcedToolUse: false,
|
|
6476
|
+
supportsBetweenToolsThinking: false,
|
|
6390
6477
|
isKnownModel: true
|
|
6391
6478
|
};
|
|
6392
6479
|
} else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
|
|
@@ -6399,6 +6486,7 @@ function getModelCapabilities(modelId) {
|
|
|
6399
6486
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
6400
6487
|
rejectsThinkingDisabled: false,
|
|
6401
6488
|
rejectsForcedToolUse: false,
|
|
6489
|
+
supportsBetweenToolsThinking: false,
|
|
6402
6490
|
isKnownModel: true
|
|
6403
6491
|
};
|
|
6404
6492
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
@@ -6411,6 +6499,7 @@ function getModelCapabilities(modelId) {
|
|
|
6411
6499
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
6412
6500
|
rejectsThinkingDisabled: false,
|
|
6413
6501
|
rejectsForcedToolUse: false,
|
|
6502
|
+
supportsBetweenToolsThinking: false,
|
|
6414
6503
|
isKnownModel: true
|
|
6415
6504
|
};
|
|
6416
6505
|
} else if (/claude-sonnet-4(?:-|@)/.test(modelId)) {
|
|
@@ -6423,6 +6512,7 @@ function getModelCapabilities(modelId) {
|
|
|
6423
6512
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
6424
6513
|
rejectsThinkingDisabled: false,
|
|
6425
6514
|
rejectsForcedToolUse: false,
|
|
6515
|
+
supportsBetweenToolsThinking: false,
|
|
6426
6516
|
isKnownModel: true
|
|
6427
6517
|
};
|
|
6428
6518
|
} else if (/claude-opus-4(?:-|@)/.test(modelId)) {
|
|
@@ -6435,6 +6525,7 @@ function getModelCapabilities(modelId) {
|
|
|
6435
6525
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
6436
6526
|
rejectsThinkingDisabled: false,
|
|
6437
6527
|
rejectsForcedToolUse: false,
|
|
6528
|
+
supportsBetweenToolsThinking: false,
|
|
6438
6529
|
isKnownModel: true
|
|
6439
6530
|
};
|
|
6440
6531
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
@@ -6447,6 +6538,7 @@ function getModelCapabilities(modelId) {
|
|
|
6447
6538
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
6448
6539
|
rejectsThinkingDisabled: false,
|
|
6449
6540
|
rejectsForcedToolUse: false,
|
|
6541
|
+
supportsBetweenToolsThinking: false,
|
|
6450
6542
|
isKnownModel: true
|
|
6451
6543
|
};
|
|
6452
6544
|
} else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
|
|
@@ -6459,6 +6551,7 @@ function getModelCapabilities(modelId) {
|
|
|
6459
6551
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
6460
6552
|
rejectsThinkingDisabled: false,
|
|
6461
6553
|
rejectsForcedToolUse: false,
|
|
6554
|
+
supportsBetweenToolsThinking: false,
|
|
6462
6555
|
isKnownModel: false
|
|
6463
6556
|
};
|
|
6464
6557
|
} else if (modelId.includes("claude-")) {
|
|
@@ -6471,6 +6564,7 @@ function getModelCapabilities(modelId) {
|
|
|
6471
6564
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
6472
6565
|
rejectsThinkingDisabled: false,
|
|
6473
6566
|
rejectsForcedToolUse: false,
|
|
6567
|
+
supportsBetweenToolsThinking: false,
|
|
6474
6568
|
isKnownModel: false
|
|
6475
6569
|
};
|
|
6476
6570
|
} else {
|
|
@@ -6483,6 +6577,7 @@ function getModelCapabilities(modelId) {
|
|
|
6483
6577
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
6484
6578
|
rejectsThinkingDisabled: false,
|
|
6485
6579
|
rejectsForcedToolUse: false,
|
|
6580
|
+
supportsBetweenToolsThinking: false,
|
|
6486
6581
|
isKnownModel: false
|
|
6487
6582
|
};
|
|
6488
6583
|
}
|
|
@@ -6511,6 +6606,7 @@ function resolveAnthropicReasoningConfig({
|
|
|
6511
6606
|
supportsAdaptiveThinking,
|
|
6512
6607
|
supportsXhighEffort,
|
|
6513
6608
|
rejectsThinkingDisabled,
|
|
6609
|
+
supportsBetweenToolsThinking,
|
|
6514
6610
|
maxOutputTokensForModel,
|
|
6515
6611
|
warnings
|
|
6516
6612
|
}) {
|
|
@@ -6518,6 +6614,9 @@ function resolveAnthropicReasoningConfig({
|
|
|
6518
6614
|
return void 0;
|
|
6519
6615
|
}
|
|
6520
6616
|
if (reasoning === "none") {
|
|
6617
|
+
if (supportsBetweenToolsThinking) {
|
|
6618
|
+
return { thinking: { type: "between_tools" } };
|
|
6619
|
+
}
|
|
6521
6620
|
if (rejectsThinkingDisabled) {
|
|
6522
6621
|
warnings.push({
|
|
6523
6622
|
type: "compatibility",
|