@ai-sdk/anthropic 3.0.124 → 3.0.125
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 +13 -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 +1 -1
- 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/internal/index.mjs
CHANGED
|
@@ -932,6 +932,9 @@ var anthropicLanguageModelOptions = z3.object({
|
|
|
932
932
|
* `claude-fable-5-1`) reject `enabled` and `disabled`. For those models the
|
|
933
933
|
* provider drops the unsupported setting, emits a warning, and sends an
|
|
934
934
|
* adaptive thinking request. Use `effort` to control how much they think.
|
|
935
|
+
*
|
|
936
|
+
* `claude-sonnet-5-5` supports `between_tools`, its lowest thinking setting,
|
|
937
|
+
* and the provider uses it in place of `disabled` for that model.
|
|
935
938
|
*/
|
|
936
939
|
thinking: z3.union([
|
|
937
940
|
z3.discriminatedUnion("type", [
|
|
@@ -960,6 +963,14 @@ var anthropicLanguageModelOptions = z3.object({
|
|
|
960
963
|
}),
|
|
961
964
|
z3.object({
|
|
962
965
|
type: z3.literal("disabled")
|
|
966
|
+
}),
|
|
967
|
+
z3.object({
|
|
968
|
+
/**
|
|
969
|
+
* for `claude-sonnet-5-5`: no upfront thinking, but progress notes
|
|
970
|
+
* between tool calls are returned as summarized thinking blocks.
|
|
971
|
+
* Only supported at `low`, `medium`, and `high` effort.
|
|
972
|
+
*/
|
|
973
|
+
type: z3.literal("between_tools")
|
|
963
974
|
})
|
|
964
975
|
]),
|
|
965
976
|
/**
|
|
@@ -2442,6 +2453,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2442
2453
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
2443
2454
|
let system = void 0;
|
|
2444
2455
|
const messages = [];
|
|
2456
|
+
let lastUserMessageIndex = -1;
|
|
2445
2457
|
async function shouldEnableCitations(providerMetadata) {
|
|
2446
2458
|
var _a2, _b2;
|
|
2447
2459
|
const anthropicOptions = await parseProviderOptions({
|
|
@@ -2553,6 +2565,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2553
2565
|
const { role, content } = message;
|
|
2554
2566
|
switch (role) {
|
|
2555
2567
|
case "user": {
|
|
2568
|
+
if (content.length > 0) {
|
|
2569
|
+
lastUserMessageIndex = messages.length;
|
|
2570
|
+
}
|
|
2556
2571
|
for (let j = 0; j < content.length; j++) {
|
|
2557
2572
|
const part = content[j];
|
|
2558
2573
|
const isLastPart = j === content.length - 1;
|
|
@@ -3337,6 +3352,42 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
3337
3352
|
}
|
|
3338
3353
|
}
|
|
3339
3354
|
}
|
|
3355
|
+
const codeExecutionToolCallIds = /* @__PURE__ */ new Set();
|
|
3356
|
+
for (const message of messages) {
|
|
3357
|
+
if (message.role !== "assistant") {
|
|
3358
|
+
continue;
|
|
3359
|
+
}
|
|
3360
|
+
for (const part of message.content) {
|
|
3361
|
+
if (part.type === "server_tool_use" && part.name === "code_execution") {
|
|
3362
|
+
codeExecutionToolCallIds.add(part.id);
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
}
|
|
3366
|
+
const warnedToolCallIds = /* @__PURE__ */ new Set();
|
|
3367
|
+
for (let i = 0; i < lastUserMessageIndex; i++) {
|
|
3368
|
+
const message = messages[i];
|
|
3369
|
+
if (message.role !== "assistant") {
|
|
3370
|
+
continue;
|
|
3371
|
+
}
|
|
3372
|
+
for (const part of message.content) {
|
|
3373
|
+
if (!("caller" in part)) {
|
|
3374
|
+
continue;
|
|
3375
|
+
}
|
|
3376
|
+
const caller = part.caller;
|
|
3377
|
+
if (caller == null || caller.type === "direct" || codeExecutionToolCallIds.has(caller.tool_id)) {
|
|
3378
|
+
continue;
|
|
3379
|
+
}
|
|
3380
|
+
const toolCallId = "id" in part ? part.id : part.tool_use_id;
|
|
3381
|
+
delete part.caller;
|
|
3382
|
+
if (!warnedToolCallIds.has(toolCallId)) {
|
|
3383
|
+
warnedToolCallIds.add(toolCallId);
|
|
3384
|
+
warnings.push({
|
|
3385
|
+
type: "other",
|
|
3386
|
+
message: `Omitted caller metadata for tool ${toolCallId} because source code execution tool ${caller.tool_id} is missing from the conversation history.`
|
|
3387
|
+
});
|
|
3388
|
+
}
|
|
3389
|
+
}
|
|
3390
|
+
}
|
|
3340
3391
|
return {
|
|
3341
3392
|
prompt: { system, messages },
|
|
3342
3393
|
betas
|
|
@@ -3780,6 +3831,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3780
3831
|
rejectsThinkingDisabledAboveHighEffort,
|
|
3781
3832
|
rejectsThinkingDisabled,
|
|
3782
3833
|
rejectsForcedToolUse,
|
|
3834
|
+
supportsBetweenToolsThinking,
|
|
3783
3835
|
isKnownModel
|
|
3784
3836
|
} = getModelCapabilities(this.modelId);
|
|
3785
3837
|
if (!isKnownModel && maxOutputTokens == null) {
|
|
@@ -3881,7 +3933,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3881
3933
|
if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
|
|
3882
3934
|
const requestedThinking = anthropicOptions.thinking;
|
|
3883
3935
|
const requestedType = "type" in requestedThinking ? requestedThinking.type : void 0;
|
|
3884
|
-
if (requestedType === "disabled") {
|
|
3936
|
+
if (requestedType === "disabled" && supportsBetweenToolsThinking) {
|
|
3937
|
+
warnings.push({
|
|
3938
|
+
type: "unsupported",
|
|
3939
|
+
feature: "providerOptions.anthropic.thinking",
|
|
3940
|
+
details: `thinking cannot be disabled for ${this.modelId}. Using 'between_tools' thinking, the lowest thinking setting, instead.`
|
|
3941
|
+
});
|
|
3942
|
+
anthropicOptions.thinking = { type: "between_tools" };
|
|
3943
|
+
} else if (requestedType === "disabled") {
|
|
3885
3944
|
warnings.push({
|
|
3886
3945
|
type: "unsupported",
|
|
3887
3946
|
feature: "providerOptions.anthropic.thinking",
|
|
@@ -3907,7 +3966,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3907
3966
|
});
|
|
3908
3967
|
anthropicOptions.effort = "high";
|
|
3909
3968
|
}
|
|
3910
|
-
|
|
3969
|
+
if (thinkingType === "between_tools" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
|
|
3970
|
+
warnings.push({
|
|
3971
|
+
type: "unsupported",
|
|
3972
|
+
feature: "providerOptions.anthropic.effort",
|
|
3973
|
+
details: `effort '${anthropicOptions.effort}' is not supported with 'between_tools' thinking. The effort has been lowered to 'high'.`
|
|
3974
|
+
});
|
|
3975
|
+
anthropicOptions.effort = "high";
|
|
3976
|
+
}
|
|
3977
|
+
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive" || thinkingType === "between_tools";
|
|
3911
3978
|
const sendThinking = isThinking || thinkingType === "disabled";
|
|
3912
3979
|
let thinkingBudget = thinkingType === "enabled" && thinking != null && "budgetTokens" in thinking ? thinking.budgetTokens : void 0;
|
|
3913
3980
|
const thinkingDisplay = thinkingType === "adaptive" && thinking != null && "display" in thinking ? thinking.display : void 0;
|
|
@@ -5743,7 +5810,18 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5743
5810
|
}
|
|
5744
5811
|
};
|
|
5745
5812
|
function getModelCapabilities(modelId) {
|
|
5746
|
-
if (modelId.includes("claude-
|
|
5813
|
+
if (modelId.includes("claude-sonnet-5-5")) {
|
|
5814
|
+
return {
|
|
5815
|
+
maxOutputTokens: 128e3,
|
|
5816
|
+
supportsStructuredOutput: true,
|
|
5817
|
+
rejectsSamplingParameters: true,
|
|
5818
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5819
|
+
rejectsThinkingDisabled: true,
|
|
5820
|
+
rejectsForcedToolUse: true,
|
|
5821
|
+
supportsBetweenToolsThinking: true,
|
|
5822
|
+
isKnownModel: true
|
|
5823
|
+
};
|
|
5824
|
+
} else if (modelId.includes("claude-opus-5-5")) {
|
|
5747
5825
|
return {
|
|
5748
5826
|
maxOutputTokens: 128e3,
|
|
5749
5827
|
supportsStructuredOutput: true,
|
|
@@ -5751,6 +5829,7 @@ function getModelCapabilities(modelId) {
|
|
|
5751
5829
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5752
5830
|
rejectsThinkingDisabled: true,
|
|
5753
5831
|
rejectsForcedToolUse: true,
|
|
5832
|
+
supportsBetweenToolsThinking: false,
|
|
5754
5833
|
isKnownModel: true
|
|
5755
5834
|
};
|
|
5756
5835
|
} else if (modelId.includes("claude-opus-5")) {
|
|
@@ -5761,6 +5840,7 @@ function getModelCapabilities(modelId) {
|
|
|
5761
5840
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5762
5841
|
rejectsThinkingDisabled: false,
|
|
5763
5842
|
rejectsForcedToolUse: false,
|
|
5843
|
+
supportsBetweenToolsThinking: false,
|
|
5764
5844
|
isKnownModel: true
|
|
5765
5845
|
};
|
|
5766
5846
|
} else if (modelId.includes("claude-fable-5-1")) {
|
|
@@ -5771,6 +5851,7 @@ function getModelCapabilities(modelId) {
|
|
|
5771
5851
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5772
5852
|
rejectsThinkingDisabled: true,
|
|
5773
5853
|
rejectsForcedToolUse: true,
|
|
5854
|
+
supportsBetweenToolsThinking: false,
|
|
5774
5855
|
isKnownModel: true
|
|
5775
5856
|
};
|
|
5776
5857
|
} else if (modelId.includes("claude-fable-5")) {
|
|
@@ -5781,6 +5862,7 @@ function getModelCapabilities(modelId) {
|
|
|
5781
5862
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5782
5863
|
rejectsThinkingDisabled: true,
|
|
5783
5864
|
rejectsForcedToolUse: false,
|
|
5865
|
+
supportsBetweenToolsThinking: false,
|
|
5784
5866
|
isKnownModel: true
|
|
5785
5867
|
};
|
|
5786
5868
|
} else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-sonnet-5")) {
|
|
@@ -5791,6 +5873,7 @@ function getModelCapabilities(modelId) {
|
|
|
5791
5873
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5792
5874
|
rejectsThinkingDisabled: false,
|
|
5793
5875
|
rejectsForcedToolUse: false,
|
|
5876
|
+
supportsBetweenToolsThinking: false,
|
|
5794
5877
|
isKnownModel: true
|
|
5795
5878
|
};
|
|
5796
5879
|
} else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
|
|
@@ -5801,6 +5884,7 @@ function getModelCapabilities(modelId) {
|
|
|
5801
5884
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5802
5885
|
rejectsThinkingDisabled: false,
|
|
5803
5886
|
rejectsForcedToolUse: false,
|
|
5887
|
+
supportsBetweenToolsThinking: false,
|
|
5804
5888
|
isKnownModel: true
|
|
5805
5889
|
};
|
|
5806
5890
|
} else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
|
|
@@ -5811,6 +5895,7 @@ function getModelCapabilities(modelId) {
|
|
|
5811
5895
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5812
5896
|
rejectsThinkingDisabled: false,
|
|
5813
5897
|
rejectsForcedToolUse: false,
|
|
5898
|
+
supportsBetweenToolsThinking: false,
|
|
5814
5899
|
isKnownModel: true
|
|
5815
5900
|
};
|
|
5816
5901
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
@@ -5821,6 +5906,7 @@ function getModelCapabilities(modelId) {
|
|
|
5821
5906
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5822
5907
|
rejectsThinkingDisabled: false,
|
|
5823
5908
|
rejectsForcedToolUse: false,
|
|
5909
|
+
supportsBetweenToolsThinking: false,
|
|
5824
5910
|
isKnownModel: true
|
|
5825
5911
|
};
|
|
5826
5912
|
} else if (modelId.includes("claude-sonnet-4-")) {
|
|
@@ -5831,6 +5917,7 @@ function getModelCapabilities(modelId) {
|
|
|
5831
5917
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5832
5918
|
rejectsThinkingDisabled: false,
|
|
5833
5919
|
rejectsForcedToolUse: false,
|
|
5920
|
+
supportsBetweenToolsThinking: false,
|
|
5834
5921
|
isKnownModel: true
|
|
5835
5922
|
};
|
|
5836
5923
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
@@ -5841,6 +5928,7 @@ function getModelCapabilities(modelId) {
|
|
|
5841
5928
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5842
5929
|
rejectsThinkingDisabled: false,
|
|
5843
5930
|
rejectsForcedToolUse: false,
|
|
5931
|
+
supportsBetweenToolsThinking: false,
|
|
5844
5932
|
isKnownModel: true
|
|
5845
5933
|
};
|
|
5846
5934
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
@@ -5851,6 +5939,7 @@ function getModelCapabilities(modelId) {
|
|
|
5851
5939
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5852
5940
|
rejectsThinkingDisabled: false,
|
|
5853
5941
|
rejectsForcedToolUse: false,
|
|
5942
|
+
supportsBetweenToolsThinking: false,
|
|
5854
5943
|
isKnownModel: true
|
|
5855
5944
|
};
|
|
5856
5945
|
} else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
|
|
@@ -5861,6 +5950,7 @@ function getModelCapabilities(modelId) {
|
|
|
5861
5950
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5862
5951
|
rejectsThinkingDisabled: false,
|
|
5863
5952
|
rejectsForcedToolUse: false,
|
|
5953
|
+
supportsBetweenToolsThinking: false,
|
|
5864
5954
|
isKnownModel: false
|
|
5865
5955
|
};
|
|
5866
5956
|
} else if (modelId.includes("claude-")) {
|
|
@@ -5871,6 +5961,7 @@ function getModelCapabilities(modelId) {
|
|
|
5871
5961
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5872
5962
|
rejectsThinkingDisabled: false,
|
|
5873
5963
|
rejectsForcedToolUse: false,
|
|
5964
|
+
supportsBetweenToolsThinking: false,
|
|
5874
5965
|
isKnownModel: false
|
|
5875
5966
|
};
|
|
5876
5967
|
} else {
|
|
@@ -5881,6 +5972,7 @@ function getModelCapabilities(modelId) {
|
|
|
5881
5972
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5882
5973
|
rejectsThinkingDisabled: false,
|
|
5883
5974
|
rejectsForcedToolUse: false,
|
|
5975
|
+
supportsBetweenToolsThinking: false,
|
|
5884
5976
|
isKnownModel: false
|
|
5885
5977
|
};
|
|
5886
5978
|
}
|