@ai-sdk/anthropic 4.0.79 → 4.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 +18 -0
- package/dist/index.js +33 -9
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +4 -3
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +32 -8
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +7 -0
- package/package.json +3 -3
- package/src/anthropic-language-model.ts +27 -5
- package/src/anthropic-prepare-tools.ts +5 -5
- package/src/convert-to-anthropic-prompt.ts +25 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 4.0.81
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e254e96: fix(anthropic): support provider-referenced files in tool results
|
|
8
|
+
- Updated dependencies [130e871]
|
|
9
|
+
- @ai-sdk/provider@4.0.28
|
|
10
|
+
- @ai-sdk/provider-utils@5.0.61
|
|
11
|
+
|
|
12
|
+
## 4.0.80
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 40d0aec: feat(vertex-anthropic): forward 'providerOptions.vertex.labels' as a header
|
|
17
|
+
- 40a4ce1: Fall back to automatic tool choice with a warning when manual thinking is enabled with a required or named tool choice, avoiding an Anthropic API 400 error. Named tool choices send only the selected tool.
|
|
18
|
+
- Updated dependencies [2e89fa4]
|
|
19
|
+
- @ai-sdk/provider-utils@5.0.60
|
|
20
|
+
|
|
3
21
|
## 4.0.79
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1843,7 +1843,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
1843
1843
|
toolWarnings.push({
|
|
1844
1844
|
type: "unsupported",
|
|
1845
1845
|
feature: "toolChoice",
|
|
1846
|
-
details: "toolChoice 'required' is not supported
|
|
1846
|
+
details: "toolChoice 'required' is not supported with this model or thinking configuration. Using 'auto' instead. Instruct the model to use a tool in the prompt and verify that a tool call was made."
|
|
1847
1847
|
});
|
|
1848
1848
|
return {
|
|
1849
1849
|
tools: anthropicTools,
|
|
@@ -1875,7 +1875,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
1875
1875
|
toolWarnings.push({
|
|
1876
1876
|
type: "unsupported",
|
|
1877
1877
|
feature: "toolChoice",
|
|
1878
|
-
details: `toolChoice 'tool' is not supported
|
|
1878
|
+
details: `toolChoice 'tool' is not supported with this model or thinking configuration. Only the '${toolChoice.toolName}' tool is sent with 'auto' tool choice. Instruct the model to use the tool in the prompt and verify that a tool call was made.`
|
|
1879
1879
|
});
|
|
1880
1880
|
return {
|
|
1881
1881
|
tools: anthropicTools.filter((tool) => "name" in tool && tool.name === toolChoice.toolName),
|
|
@@ -2528,6 +2528,27 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
|
|
|
2528
2528
|
};
|
|
2529
2529
|
case "file": {
|
|
2530
2530
|
const topLevel = getTopLevelMediaType(contentPart.mediaType);
|
|
2531
|
+
if (contentPart.data.type === "reference") {
|
|
2532
|
+
const fileId = resolveProviderReference({
|
|
2533
|
+
reference: contentPart.data.reference,
|
|
2534
|
+
provider: "anthropic"
|
|
2535
|
+
});
|
|
2536
|
+
betas.add("files-api-2025-04-14");
|
|
2537
|
+
if (topLevel === "image") return {
|
|
2538
|
+
type: "image",
|
|
2539
|
+
source: {
|
|
2540
|
+
type: "file",
|
|
2541
|
+
file_id: fileId
|
|
2542
|
+
}
|
|
2543
|
+
};
|
|
2544
|
+
return {
|
|
2545
|
+
type: "document",
|
|
2546
|
+
source: {
|
|
2547
|
+
type: "file",
|
|
2548
|
+
file_id: fileId
|
|
2549
|
+
}
|
|
2550
|
+
};
|
|
2551
|
+
}
|
|
2531
2552
|
if (contentPart.data.type === "url") {
|
|
2532
2553
|
if (topLevel === "image") return {
|
|
2533
2554
|
type: "image",
|
|
@@ -3921,7 +3942,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
3921
3942
|
supportsStructuredOutput: false,
|
|
3922
3943
|
supportsStrictTools,
|
|
3923
3944
|
defaultEagerInputStreaming,
|
|
3924
|
-
rejectsForcedToolUse
|
|
3945
|
+
rejectsForcedToolUse: rejectsForcedToolUse || thinkingType === "enabled"
|
|
3925
3946
|
} : {
|
|
3926
3947
|
tools: tools ?? [],
|
|
3927
3948
|
toolChoice,
|
|
@@ -3930,7 +3951,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
3930
3951
|
supportsStructuredOutput,
|
|
3931
3952
|
supportsStrictTools,
|
|
3932
3953
|
defaultEagerInputStreaming,
|
|
3933
|
-
rejectsForcedToolUse
|
|
3954
|
+
rejectsForcedToolUse: rejectsForcedToolUse || thinkingType === "enabled"
|
|
3934
3955
|
});
|
|
3935
3956
|
const cacheWarnings = cacheControlValidator.getWarnings();
|
|
3936
3957
|
return {
|
|
@@ -3964,8 +3985,9 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
3964
3985
|
options
|
|
3965
3986
|
});
|
|
3966
3987
|
}
|
|
3967
|
-
async getHeaders({ betas, headers }) {
|
|
3968
|
-
|
|
3988
|
+
async getHeaders({ betas, headers, providerOptions }) {
|
|
3989
|
+
const combinedHeaders = combineHeaders(this.config.headers ? await resolve(this.config.headers) : void 0, headers, betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {});
|
|
3990
|
+
return this.config.transformRequestHeaders ? this.config.transformRequestHeaders(combinedHeaders, providerOptions) : combinedHeaders;
|
|
3969
3991
|
}
|
|
3970
3992
|
async getBetasFromHeaders(requestHeaders) {
|
|
3971
3993
|
const configBetaHeader = (this.config.headers ? await resolve(this.config.headers) : void 0)?.["anthropic-beta"] ?? "";
|
|
@@ -4005,7 +4027,8 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4005
4027
|
url: this.buildRequestUrl(false),
|
|
4006
4028
|
headers: await this.getHeaders({
|
|
4007
4029
|
betas,
|
|
4008
|
-
headers: options.headers
|
|
4030
|
+
headers: options.headers,
|
|
4031
|
+
providerOptions: options.providerOptions
|
|
4009
4032
|
}),
|
|
4010
4033
|
body: this.transformRequestBody(args, betas),
|
|
4011
4034
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
@@ -4425,7 +4448,8 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4425
4448
|
url,
|
|
4426
4449
|
headers: await this.getHeaders({
|
|
4427
4450
|
betas,
|
|
4428
|
-
headers: options.headers
|
|
4451
|
+
headers: options.headers,
|
|
4452
|
+
providerOptions: options.providerOptions
|
|
4429
4453
|
}),
|
|
4430
4454
|
body: this.transformRequestBody(body, betas),
|
|
4431
4455
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
@@ -6933,7 +6957,7 @@ var AnthropicSkills = class {
|
|
|
6933
6957
|
};
|
|
6934
6958
|
//#endregion
|
|
6935
6959
|
//#region src/version.ts
|
|
6936
|
-
const VERSION = "4.0.
|
|
6960
|
+
const VERSION = "4.0.81";
|
|
6937
6961
|
//#endregion
|
|
6938
6962
|
//#region src/anthropic-provider.ts
|
|
6939
6963
|
const ANTHROPIC_API_URL = "https://api.anthropic.com";
|