@ai-sdk/anthropic 3.0.124 → 3.0.126
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.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +96 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -4
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +6 -1
- package/dist/internal/index.d.ts +6 -1
- package/dist/internal/index.js +95 -3
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +95 -3
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +101 -30
- package/package.json +2 -2
- package/src/anthropic-messages-language-model.ts +62 -3
- package/src/anthropic-messages-options.ts +12 -0
- package/src/convert-to-anthropic-messages-prompt.ts +54 -0
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "@ai-sdk/provider-utils";
|
|
13
13
|
|
|
14
14
|
// src/version.ts
|
|
15
|
-
var VERSION = true ? "3.0.
|
|
15
|
+
var VERSION = true ? "3.0.126" : "0.0.0-test";
|
|
16
16
|
|
|
17
17
|
// src/anthropic-messages-language-model.ts
|
|
18
18
|
import {
|
|
@@ -948,6 +948,9 @@ var anthropicLanguageModelOptions = z3.object({
|
|
|
948
948
|
* `claude-fable-5-1`) reject `enabled` and `disabled`. For those models the
|
|
949
949
|
* provider drops the unsupported setting, emits a warning, and sends an
|
|
950
950
|
* adaptive thinking request. Use `effort` to control how much they think.
|
|
951
|
+
*
|
|
952
|
+
* `claude-sonnet-5-5` supports `between_tools`, its lowest thinking setting,
|
|
953
|
+
* and the provider uses it in place of `disabled` for that model.
|
|
951
954
|
*/
|
|
952
955
|
thinking: z3.union([
|
|
953
956
|
z3.discriminatedUnion("type", [
|
|
@@ -976,6 +979,14 @@ var anthropicLanguageModelOptions = z3.object({
|
|
|
976
979
|
}),
|
|
977
980
|
z3.object({
|
|
978
981
|
type: z3.literal("disabled")
|
|
982
|
+
}),
|
|
983
|
+
z3.object({
|
|
984
|
+
/**
|
|
985
|
+
* for `claude-sonnet-5-5`: no upfront thinking, but progress notes
|
|
986
|
+
* between tool calls are returned as summarized thinking blocks.
|
|
987
|
+
* Only supported at `low`, `medium`, and `high` effort.
|
|
988
|
+
*/
|
|
989
|
+
type: z3.literal("between_tools")
|
|
979
990
|
})
|
|
980
991
|
]),
|
|
981
992
|
/**
|
|
@@ -2458,6 +2469,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2458
2469
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
2459
2470
|
let system = void 0;
|
|
2460
2471
|
const messages = [];
|
|
2472
|
+
let lastUserMessageIndex = -1;
|
|
2461
2473
|
async function shouldEnableCitations(providerMetadata) {
|
|
2462
2474
|
var _a2, _b2;
|
|
2463
2475
|
const anthropicOptions = await parseProviderOptions({
|
|
@@ -2569,6 +2581,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2569
2581
|
const { role, content } = message;
|
|
2570
2582
|
switch (role) {
|
|
2571
2583
|
case "user": {
|
|
2584
|
+
if (content.length > 0) {
|
|
2585
|
+
lastUserMessageIndex = messages.length;
|
|
2586
|
+
}
|
|
2572
2587
|
for (let j = 0; j < content.length; j++) {
|
|
2573
2588
|
const part = content[j];
|
|
2574
2589
|
const isLastPart = j === content.length - 1;
|
|
@@ -3353,6 +3368,42 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
3353
3368
|
}
|
|
3354
3369
|
}
|
|
3355
3370
|
}
|
|
3371
|
+
const codeExecutionToolCallIds = /* @__PURE__ */ new Set();
|
|
3372
|
+
for (const message of messages) {
|
|
3373
|
+
if (message.role !== "assistant") {
|
|
3374
|
+
continue;
|
|
3375
|
+
}
|
|
3376
|
+
for (const part of message.content) {
|
|
3377
|
+
if (part.type === "server_tool_use" && part.name === "code_execution") {
|
|
3378
|
+
codeExecutionToolCallIds.add(part.id);
|
|
3379
|
+
}
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3382
|
+
const warnedToolCallIds = /* @__PURE__ */ new Set();
|
|
3383
|
+
for (let i = 0; i < lastUserMessageIndex; i++) {
|
|
3384
|
+
const message = messages[i];
|
|
3385
|
+
if (message.role !== "assistant") {
|
|
3386
|
+
continue;
|
|
3387
|
+
}
|
|
3388
|
+
for (const part of message.content) {
|
|
3389
|
+
if (!("caller" in part)) {
|
|
3390
|
+
continue;
|
|
3391
|
+
}
|
|
3392
|
+
const caller = part.caller;
|
|
3393
|
+
if (caller == null || caller.type === "direct" || codeExecutionToolCallIds.has(caller.tool_id)) {
|
|
3394
|
+
continue;
|
|
3395
|
+
}
|
|
3396
|
+
const toolCallId = "id" in part ? part.id : part.tool_use_id;
|
|
3397
|
+
delete part.caller;
|
|
3398
|
+
if (!warnedToolCallIds.has(toolCallId)) {
|
|
3399
|
+
warnedToolCallIds.add(toolCallId);
|
|
3400
|
+
warnings.push({
|
|
3401
|
+
type: "other",
|
|
3402
|
+
message: `Omitted caller metadata for tool ${toolCallId} because source code execution tool ${caller.tool_id} is missing from the conversation history.`
|
|
3403
|
+
});
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
}
|
|
3356
3407
|
return {
|
|
3357
3408
|
prompt: { system, messages },
|
|
3358
3409
|
betas
|
|
@@ -3796,6 +3847,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3796
3847
|
rejectsThinkingDisabledAboveHighEffort,
|
|
3797
3848
|
rejectsThinkingDisabled,
|
|
3798
3849
|
rejectsForcedToolUse,
|
|
3850
|
+
supportsBetweenToolsThinking,
|
|
3799
3851
|
isKnownModel
|
|
3800
3852
|
} = getModelCapabilities(this.modelId);
|
|
3801
3853
|
if (!isKnownModel && maxOutputTokens == null) {
|
|
@@ -3897,7 +3949,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3897
3949
|
if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
|
|
3898
3950
|
const requestedThinking = anthropicOptions.thinking;
|
|
3899
3951
|
const requestedType = "type" in requestedThinking ? requestedThinking.type : void 0;
|
|
3900
|
-
if (requestedType === "disabled") {
|
|
3952
|
+
if (requestedType === "disabled" && supportsBetweenToolsThinking) {
|
|
3953
|
+
warnings.push({
|
|
3954
|
+
type: "unsupported",
|
|
3955
|
+
feature: "providerOptions.anthropic.thinking",
|
|
3956
|
+
details: `thinking cannot be disabled for ${this.modelId}. Using 'between_tools' thinking, the lowest thinking setting, instead.`
|
|
3957
|
+
});
|
|
3958
|
+
anthropicOptions.thinking = { type: "between_tools" };
|
|
3959
|
+
} else if (requestedType === "disabled") {
|
|
3901
3960
|
warnings.push({
|
|
3902
3961
|
type: "unsupported",
|
|
3903
3962
|
feature: "providerOptions.anthropic.thinking",
|
|
@@ -3923,7 +3982,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3923
3982
|
});
|
|
3924
3983
|
anthropicOptions.effort = "high";
|
|
3925
3984
|
}
|
|
3926
|
-
|
|
3985
|
+
if (thinkingType === "between_tools" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
|
|
3986
|
+
warnings.push({
|
|
3987
|
+
type: "unsupported",
|
|
3988
|
+
feature: "providerOptions.anthropic.effort",
|
|
3989
|
+
details: `effort '${anthropicOptions.effort}' is not supported with 'between_tools' thinking. The effort has been lowered to 'high'.`
|
|
3990
|
+
});
|
|
3991
|
+
anthropicOptions.effort = "high";
|
|
3992
|
+
}
|
|
3993
|
+
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive" || thinkingType === "between_tools";
|
|
3927
3994
|
const sendThinking = isThinking || thinkingType === "disabled";
|
|
3928
3995
|
let thinkingBudget = thinkingType === "enabled" && thinking != null && "budgetTokens" in thinking ? thinking.budgetTokens : void 0;
|
|
3929
3996
|
const thinkingDisplay = thinkingType === "adaptive" && thinking != null && "display" in thinking ? thinking.display : void 0;
|
|
@@ -5759,7 +5826,18 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5759
5826
|
}
|
|
5760
5827
|
};
|
|
5761
5828
|
function getModelCapabilities(modelId) {
|
|
5762
|
-
if (modelId.includes("claude-
|
|
5829
|
+
if (modelId.includes("claude-sonnet-5-5")) {
|
|
5830
|
+
return {
|
|
5831
|
+
maxOutputTokens: 128e3,
|
|
5832
|
+
supportsStructuredOutput: true,
|
|
5833
|
+
rejectsSamplingParameters: true,
|
|
5834
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5835
|
+
rejectsThinkingDisabled: true,
|
|
5836
|
+
rejectsForcedToolUse: true,
|
|
5837
|
+
supportsBetweenToolsThinking: true,
|
|
5838
|
+
isKnownModel: true
|
|
5839
|
+
};
|
|
5840
|
+
} else if (modelId.includes("claude-opus-5-5")) {
|
|
5763
5841
|
return {
|
|
5764
5842
|
maxOutputTokens: 128e3,
|
|
5765
5843
|
supportsStructuredOutput: true,
|
|
@@ -5767,6 +5845,7 @@ function getModelCapabilities(modelId) {
|
|
|
5767
5845
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5768
5846
|
rejectsThinkingDisabled: true,
|
|
5769
5847
|
rejectsForcedToolUse: true,
|
|
5848
|
+
supportsBetweenToolsThinking: false,
|
|
5770
5849
|
isKnownModel: true
|
|
5771
5850
|
};
|
|
5772
5851
|
} else if (modelId.includes("claude-opus-5")) {
|
|
@@ -5777,6 +5856,7 @@ function getModelCapabilities(modelId) {
|
|
|
5777
5856
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5778
5857
|
rejectsThinkingDisabled: false,
|
|
5779
5858
|
rejectsForcedToolUse: false,
|
|
5859
|
+
supportsBetweenToolsThinking: false,
|
|
5780
5860
|
isKnownModel: true
|
|
5781
5861
|
};
|
|
5782
5862
|
} else if (modelId.includes("claude-fable-5-1")) {
|
|
@@ -5787,6 +5867,7 @@ function getModelCapabilities(modelId) {
|
|
|
5787
5867
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5788
5868
|
rejectsThinkingDisabled: true,
|
|
5789
5869
|
rejectsForcedToolUse: true,
|
|
5870
|
+
supportsBetweenToolsThinking: false,
|
|
5790
5871
|
isKnownModel: true
|
|
5791
5872
|
};
|
|
5792
5873
|
} else if (modelId.includes("claude-fable-5")) {
|
|
@@ -5797,6 +5878,7 @@ function getModelCapabilities(modelId) {
|
|
|
5797
5878
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5798
5879
|
rejectsThinkingDisabled: true,
|
|
5799
5880
|
rejectsForcedToolUse: false,
|
|
5881
|
+
supportsBetweenToolsThinking: false,
|
|
5800
5882
|
isKnownModel: true
|
|
5801
5883
|
};
|
|
5802
5884
|
} else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-sonnet-5")) {
|
|
@@ -5807,6 +5889,7 @@ function getModelCapabilities(modelId) {
|
|
|
5807
5889
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5808
5890
|
rejectsThinkingDisabled: false,
|
|
5809
5891
|
rejectsForcedToolUse: false,
|
|
5892
|
+
supportsBetweenToolsThinking: false,
|
|
5810
5893
|
isKnownModel: true
|
|
5811
5894
|
};
|
|
5812
5895
|
} else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
|
|
@@ -5817,6 +5900,7 @@ function getModelCapabilities(modelId) {
|
|
|
5817
5900
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5818
5901
|
rejectsThinkingDisabled: false,
|
|
5819
5902
|
rejectsForcedToolUse: false,
|
|
5903
|
+
supportsBetweenToolsThinking: false,
|
|
5820
5904
|
isKnownModel: true
|
|
5821
5905
|
};
|
|
5822
5906
|
} else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
|
|
@@ -5827,6 +5911,7 @@ function getModelCapabilities(modelId) {
|
|
|
5827
5911
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5828
5912
|
rejectsThinkingDisabled: false,
|
|
5829
5913
|
rejectsForcedToolUse: false,
|
|
5914
|
+
supportsBetweenToolsThinking: false,
|
|
5830
5915
|
isKnownModel: true
|
|
5831
5916
|
};
|
|
5832
5917
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
@@ -5837,6 +5922,7 @@ function getModelCapabilities(modelId) {
|
|
|
5837
5922
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5838
5923
|
rejectsThinkingDisabled: false,
|
|
5839
5924
|
rejectsForcedToolUse: false,
|
|
5925
|
+
supportsBetweenToolsThinking: false,
|
|
5840
5926
|
isKnownModel: true
|
|
5841
5927
|
};
|
|
5842
5928
|
} else if (modelId.includes("claude-sonnet-4-")) {
|
|
@@ -5847,6 +5933,7 @@ function getModelCapabilities(modelId) {
|
|
|
5847
5933
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5848
5934
|
rejectsThinkingDisabled: false,
|
|
5849
5935
|
rejectsForcedToolUse: false,
|
|
5936
|
+
supportsBetweenToolsThinking: false,
|
|
5850
5937
|
isKnownModel: true
|
|
5851
5938
|
};
|
|
5852
5939
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
@@ -5857,6 +5944,7 @@ function getModelCapabilities(modelId) {
|
|
|
5857
5944
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5858
5945
|
rejectsThinkingDisabled: false,
|
|
5859
5946
|
rejectsForcedToolUse: false,
|
|
5947
|
+
supportsBetweenToolsThinking: false,
|
|
5860
5948
|
isKnownModel: true
|
|
5861
5949
|
};
|
|
5862
5950
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
@@ -5867,6 +5955,7 @@ function getModelCapabilities(modelId) {
|
|
|
5867
5955
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5868
5956
|
rejectsThinkingDisabled: false,
|
|
5869
5957
|
rejectsForcedToolUse: false,
|
|
5958
|
+
supportsBetweenToolsThinking: false,
|
|
5870
5959
|
isKnownModel: true
|
|
5871
5960
|
};
|
|
5872
5961
|
} else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
|
|
@@ -5877,6 +5966,7 @@ function getModelCapabilities(modelId) {
|
|
|
5877
5966
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5878
5967
|
rejectsThinkingDisabled: false,
|
|
5879
5968
|
rejectsForcedToolUse: false,
|
|
5969
|
+
supportsBetweenToolsThinking: false,
|
|
5880
5970
|
isKnownModel: false
|
|
5881
5971
|
};
|
|
5882
5972
|
} else if (modelId.includes("claude-")) {
|
|
@@ -5887,6 +5977,7 @@ function getModelCapabilities(modelId) {
|
|
|
5887
5977
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5888
5978
|
rejectsThinkingDisabled: false,
|
|
5889
5979
|
rejectsForcedToolUse: false,
|
|
5980
|
+
supportsBetweenToolsThinking: false,
|
|
5890
5981
|
isKnownModel: false
|
|
5891
5982
|
};
|
|
5892
5983
|
} else {
|
|
@@ -5897,6 +5988,7 @@ function getModelCapabilities(modelId) {
|
|
|
5897
5988
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5898
5989
|
rejectsThinkingDisabled: false,
|
|
5899
5990
|
rejectsForcedToolUse: false,
|
|
5991
|
+
supportsBetweenToolsThinking: false,
|
|
5900
5992
|
isKnownModel: false
|
|
5901
5993
|
};
|
|
5902
5994
|
}
|