@ai-sdk/anthropic 3.0.79 → 3.0.81
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.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +37 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -16
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -2
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal/index.js +36 -15
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +36 -15
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +5 -4
- package/package.json +1 -1
- package/src/anthropic-messages-api.ts +9 -1
- package/src/anthropic-messages-language-model.ts +34 -9
- package/src/anthropic-messages-options.ts +1 -0
- package/src/anthropic-tools.ts +1 -1
- package/src/convert-to-anthropic-messages-prompt.ts +9 -9
- package/src/tool/advisor_20260301.ts +1 -1
|
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
|
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
|
-
type AnthropicMessagesModelId = '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' | (string & {});
|
|
5
|
+
type AnthropicMessagesModelId = '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' | (string & {});
|
|
6
6
|
|
|
7
7
|
type AnthropicMessagesConfig = {
|
|
8
8
|
provider: string;
|
|
@@ -70,7 +70,7 @@ declare const anthropicTools: {
|
|
|
70
70
|
* Supported executor models: Claude Haiku 4.5, Sonnet 4.6, Opus 4.6,
|
|
71
71
|
* Opus 4.7. The advisor must be at least as capable as the executor.
|
|
72
72
|
*
|
|
73
|
-
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-
|
|
73
|
+
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-8"`.
|
|
74
74
|
* @param maxUses - Maximum advisor calls per request (per-request cap).
|
|
75
75
|
* @param caching - Enables prompt caching for the advisor's transcript
|
|
76
76
|
* across calls within a conversation. Worthwhile from ~3 advisor calls
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
|
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
|
-
type AnthropicMessagesModelId = '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' | (string & {});
|
|
5
|
+
type AnthropicMessagesModelId = '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' | (string & {});
|
|
6
6
|
|
|
7
7
|
type AnthropicMessagesConfig = {
|
|
8
8
|
provider: string;
|
|
@@ -70,7 +70,7 @@ declare const anthropicTools: {
|
|
|
70
70
|
* Supported executor models: Claude Haiku 4.5, Sonnet 4.6, Opus 4.6,
|
|
71
71
|
* Opus 4.7. The advisor must be at least as capable as the executor.
|
|
72
72
|
*
|
|
73
|
-
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-
|
|
73
|
+
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-8"`.
|
|
74
74
|
* @param maxUses - Maximum advisor calls per request (per-request cap).
|
|
75
75
|
* @param caching - Enables prompt caching for the advisor's transcript
|
|
76
76
|
* across calls within a conversation. Worthwhile from ~3 advisor calls
|
package/dist/internal/index.js
CHANGED
|
@@ -2202,19 +2202,20 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2202
2202
|
const type = block.type;
|
|
2203
2203
|
switch (type) {
|
|
2204
2204
|
case "system": {
|
|
2205
|
-
|
|
2206
|
-
throw new import_provider2.UnsupportedFunctionalityError({
|
|
2207
|
-
functionality: "Multiple system messages that are separated by user/assistant messages"
|
|
2208
|
-
});
|
|
2209
|
-
}
|
|
2210
|
-
system = block.messages.map(({ content, providerOptions }) => ({
|
|
2205
|
+
const content = block.messages.map(({ content: content2, providerOptions }) => ({
|
|
2211
2206
|
type: "text",
|
|
2212
|
-
text:
|
|
2207
|
+
text: content2,
|
|
2213
2208
|
cache_control: validator.getCacheControl(providerOptions, {
|
|
2214
2209
|
type: "system message",
|
|
2215
2210
|
canCache: true
|
|
2216
2211
|
})
|
|
2217
2212
|
}));
|
|
2213
|
+
if (system == null) {
|
|
2214
|
+
system = content;
|
|
2215
|
+
} else {
|
|
2216
|
+
messages.push({ role: "system", content });
|
|
2217
|
+
betas.add("mid-conversation-system-2026-04-07");
|
|
2218
|
+
}
|
|
2218
2219
|
break;
|
|
2219
2220
|
}
|
|
2220
2221
|
case "user": {
|
|
@@ -3848,12 +3849,18 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3848
3849
|
}
|
|
3849
3850
|
case "server_tool_use": {
|
|
3850
3851
|
if (part.name === "text_editor_code_execution" || part.name === "bash_code_execution") {
|
|
3852
|
+
const providerToolName = "code_execution";
|
|
3851
3853
|
content.push({
|
|
3852
3854
|
type: "tool-call",
|
|
3853
3855
|
toolCallId: part.id,
|
|
3854
3856
|
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
3855
3857
|
input: JSON.stringify({ type: part.name, ...part.input }),
|
|
3856
|
-
providerExecuted: true
|
|
3858
|
+
providerExecuted: true,
|
|
3859
|
+
// Specific 'web_fetch' or 'web_search' tools may need code execution, which the Anthropic API
|
|
3860
|
+
// implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
|
|
3861
|
+
// tool was not explicitly provided. We therefore bypass the general validation by marking the
|
|
3862
|
+
// tool as dynamic.
|
|
3863
|
+
...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {}
|
|
3857
3864
|
});
|
|
3858
3865
|
} else if (part.name === "web_search" || part.name === "code_execution" || part.name === "web_fetch") {
|
|
3859
3866
|
const inputToSerialize = part.name === "code_execution" && part.input != null && typeof part.input === "object" && "code" in part.input && !("type" in part.input) ? { type: "programmatic-tool-call", ...part.input } : part.input;
|
|
@@ -3863,8 +3870,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3863
3870
|
toolName: toolNameMapping.toCustomToolName(part.name),
|
|
3864
3871
|
input: JSON.stringify(inputToSerialize),
|
|
3865
3872
|
providerExecuted: true,
|
|
3866
|
-
//
|
|
3867
|
-
//
|
|
3873
|
+
// Specific 'web_fetch' or 'web_search' tools may need code execution, which the Anthropic API
|
|
3874
|
+
// implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
|
|
3875
|
+
// tool was not explicitly provided. We therefore bypass the general validation by marking the
|
|
3876
|
+
// tool as dynamic.
|
|
3868
3877
|
...markCodeExecutionDynamic && part.name === "code_execution" ? { dynamic: true } : {}
|
|
3869
3878
|
});
|
|
3870
3879
|
} else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
|
|
@@ -4384,15 +4393,23 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4384
4393
|
toolName: customToolName,
|
|
4385
4394
|
input: finalInput,
|
|
4386
4395
|
providerExecuted: true,
|
|
4396
|
+
// Specific 'web_fetch' or 'web_search' tools may need code execution, which the Anthropic API
|
|
4397
|
+
// implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
|
|
4398
|
+
// tool was not explicitly provided. We therefore bypass the general validation by marking the
|
|
4399
|
+
// tool as dynamic.
|
|
4387
4400
|
...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {},
|
|
4388
4401
|
firstDelta: true,
|
|
4389
|
-
providerToolName
|
|
4402
|
+
providerToolName
|
|
4390
4403
|
};
|
|
4391
4404
|
controller.enqueue({
|
|
4392
4405
|
type: "tool-input-start",
|
|
4393
4406
|
id: part.id,
|
|
4394
4407
|
toolName: customToolName,
|
|
4395
4408
|
providerExecuted: true,
|
|
4409
|
+
// Specific 'web_fetch' or 'web_search' tools may need code execution, which the Anthropic API
|
|
4410
|
+
// implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
|
|
4411
|
+
// tool was not explicitly provided. We therefore bypass the general validation by marking the
|
|
4412
|
+
// tool as dynamic.
|
|
4396
4413
|
...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {}
|
|
4397
4414
|
});
|
|
4398
4415
|
} else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
|
|
@@ -4735,6 +4752,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4735
4752
|
toolName: contentBlock.toolName,
|
|
4736
4753
|
input: finalInput,
|
|
4737
4754
|
providerExecuted: contentBlock.providerExecuted,
|
|
4755
|
+
// Specific 'web_fetch' or 'web_search' tools may need code execution, which the Anthropic API
|
|
4756
|
+
// implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
|
|
4757
|
+
// tool was not explicitly provided. We therefore bypass the general validation by marking the
|
|
4758
|
+
// tool as dynamic.
|
|
4738
4759
|
...markCodeExecutionDynamic && contentBlock.providerToolName === "code_execution" ? { dynamic: true } : {},
|
|
4739
4760
|
...contentBlock.caller && {
|
|
4740
4761
|
providerMetadata: {
|
|
@@ -4818,8 +4839,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4818
4839
|
if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
|
|
4819
4840
|
return;
|
|
4820
4841
|
}
|
|
4821
|
-
if (contentBlock.firstDelta &&
|
|
4822
|
-
delta = `{"type": "
|
|
4842
|
+
if (contentBlock.firstDelta && contentBlock.providerToolName === "code_execution") {
|
|
4843
|
+
delta = `{"type": "programmatic-tool-call",${delta.substring(1)}`;
|
|
4823
4844
|
}
|
|
4824
4845
|
controller.enqueue({
|
|
4825
4846
|
type: "tool-input-delta",
|
|
@@ -5056,7 +5077,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5056
5077
|
}
|
|
5057
5078
|
};
|
|
5058
5079
|
function getModelCapabilities(modelId) {
|
|
5059
|
-
if (modelId.includes("claude-opus-4-7")) {
|
|
5080
|
+
if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7")) {
|
|
5060
5081
|
return {
|
|
5061
5082
|
maxOutputTokens: 128e3,
|
|
5062
5083
|
supportsStructuredOutput: true,
|
|
@@ -5474,7 +5495,7 @@ var anthropicTools = {
|
|
|
5474
5495
|
* Supported executor models: Claude Haiku 4.5, Sonnet 4.6, Opus 4.6,
|
|
5475
5496
|
* Opus 4.7. The advisor must be at least as capable as the executor.
|
|
5476
5497
|
*
|
|
5477
|
-
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-
|
|
5498
|
+
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-8"`.
|
|
5478
5499
|
* @param maxUses - Maximum advisor calls per request (per-request cap).
|
|
5479
5500
|
* @param caching - Enables prompt caching for the advisor's transcript
|
|
5480
5501
|
* across calls within a conversation. Worthwhile from ~3 advisor calls
|