@ai-sdk/anthropic 3.0.132 → 3.0.134
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.js +42 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -23
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +175 -139
- package/dist/internal/index.d.ts +175 -139
- package/dist/internal/index.js +41 -22
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +41 -22
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/anthropic-messages-api.ts +8 -0
- package/src/anthropic-messages-language-model.ts +31 -8
- package/src/convert-to-anthropic-messages-prompt.ts +22 -0
- package/src/get-cache-control.ts +15 -3
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.134" : "0.0.0-test";
|
|
16
16
|
|
|
17
17
|
// src/anthropic-messages-language-model.ts
|
|
18
18
|
import {
|
|
@@ -1222,19 +1222,24 @@ import {
|
|
|
1222
1222
|
|
|
1223
1223
|
// src/get-cache-control.ts
|
|
1224
1224
|
var MAX_CACHE_BREAKPOINTS = 4;
|
|
1225
|
-
function getCacheControl(providerMetadata) {
|
|
1226
|
-
var _a;
|
|
1225
|
+
function getCacheControl(providerMetadata, providerOptionsName) {
|
|
1226
|
+
var _a, _b, _c;
|
|
1227
|
+
const custom = providerMetadata == null ? void 0 : providerMetadata[providerOptionsName];
|
|
1227
1228
|
const anthropic2 = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
1228
|
-
const cacheControlValue = (_a = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ?
|
|
1229
|
+
const cacheControlValue = (_c = (_b = (_a = custom == null ? void 0 : custom.cacheControl) != null ? _a : custom == null ? void 0 : custom.cache_control) != null ? _b : anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _c : anthropic2 == null ? void 0 : anthropic2.cache_control;
|
|
1229
1230
|
return cacheControlValue;
|
|
1230
1231
|
}
|
|
1231
1232
|
var CacheControlValidator = class {
|
|
1232
|
-
constructor() {
|
|
1233
|
+
constructor(providerOptionsName = "anthropic") {
|
|
1234
|
+
this.providerOptionsName = providerOptionsName;
|
|
1233
1235
|
this.breakpointCount = 0;
|
|
1234
1236
|
this.warnings = [];
|
|
1235
1237
|
}
|
|
1236
1238
|
getCacheControl(providerMetadata, context) {
|
|
1237
|
-
const cacheControlValue = getCacheControl(
|
|
1239
|
+
const cacheControlValue = getCacheControl(
|
|
1240
|
+
providerMetadata,
|
|
1241
|
+
this.providerOptionsName
|
|
1242
|
+
);
|
|
1238
1243
|
if (!cacheControlValue) {
|
|
1239
1244
|
return void 0;
|
|
1240
1245
|
}
|
|
@@ -2498,7 +2503,8 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2498
2503
|
warnings,
|
|
2499
2504
|
cacheControlValidator,
|
|
2500
2505
|
toolNameMapping,
|
|
2501
|
-
toolsetNames = {}
|
|
2506
|
+
toolsetNames = {},
|
|
2507
|
+
convertMediaPart
|
|
2502
2508
|
}) {
|
|
2503
2509
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2504
2510
|
const betas = /* @__PURE__ */ new Set();
|
|
@@ -2641,6 +2647,14 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2641
2647
|
break;
|
|
2642
2648
|
}
|
|
2643
2649
|
case "file": {
|
|
2650
|
+
const customContent = await (convertMediaPart == null ? void 0 : convertMediaPart(part));
|
|
2651
|
+
if (customContent != null) {
|
|
2652
|
+
anthropicContent.push({
|
|
2653
|
+
...customContent,
|
|
2654
|
+
cache_control: cacheControl
|
|
2655
|
+
});
|
|
2656
|
+
break;
|
|
2657
|
+
}
|
|
2644
2658
|
if (part.mediaType.startsWith("image/")) {
|
|
2645
2659
|
anthropicContent.push({
|
|
2646
2660
|
type: "image",
|
|
@@ -3837,7 +3851,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3837
3851
|
providerOptions,
|
|
3838
3852
|
stream
|
|
3839
3853
|
}) {
|
|
3840
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
3854
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3841
3855
|
const warnings = [];
|
|
3842
3856
|
if (frequencyPenalty != null) {
|
|
3843
3857
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -3848,18 +3862,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3848
3862
|
if (seed != null) {
|
|
3849
3863
|
warnings.push({ type: "unsupported", feature: "seed" });
|
|
3850
3864
|
}
|
|
3851
|
-
|
|
3865
|
+
const maxTemperature = (_a = this.config.maxTemperature) != null ? _a : 1;
|
|
3866
|
+
const temperatureProvider = this.config.maxTemperature == null ? "anthropic" : this.providerOptionsName;
|
|
3867
|
+
if (temperature != null && temperature > maxTemperature) {
|
|
3852
3868
|
warnings.push({
|
|
3853
3869
|
type: "unsupported",
|
|
3854
3870
|
feature: "temperature",
|
|
3855
|
-
details: `${temperature} exceeds
|
|
3871
|
+
details: `${temperature} exceeds ${temperatureProvider} maximum of ${maxTemperature.toFixed(1)}. clamped to ${maxTemperature.toFixed(1)}`
|
|
3856
3872
|
});
|
|
3857
|
-
temperature =
|
|
3873
|
+
temperature = maxTemperature;
|
|
3858
3874
|
} else if (temperature != null && temperature < 0) {
|
|
3859
3875
|
warnings.push({
|
|
3860
3876
|
type: "unsupported",
|
|
3861
3877
|
feature: "temperature",
|
|
3862
|
-
details: `${temperature} is below
|
|
3878
|
+
details: `${temperature} is below ${temperatureProvider} minimum of 0. clamped to 0`
|
|
3863
3879
|
});
|
|
3864
3880
|
temperature = 0;
|
|
3865
3881
|
}
|
|
@@ -3934,9 +3950,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3934
3950
|
}
|
|
3935
3951
|
}
|
|
3936
3952
|
const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
|
|
3937
|
-
const supportsStructuredOutput = ((
|
|
3938
|
-
const supportsStrictTools = ((
|
|
3939
|
-
const structureOutputMode = (
|
|
3953
|
+
const supportsStructuredOutput = ((_b = this.config.supportsNativeStructuredOutput) != null ? _b : true) && modelSupportsStructuredOutput;
|
|
3954
|
+
const supportsStrictTools = ((_c = this.config.supportsStrictTools) != null ? _c : true) && modelSupportsStructuredOutput;
|
|
3955
|
+
const structureOutputMode = (_d = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _d : "auto";
|
|
3940
3956
|
let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
3941
3957
|
if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
3942
3958
|
warnings.push({
|
|
@@ -3960,7 +3976,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3960
3976
|
});
|
|
3961
3977
|
}
|
|
3962
3978
|
const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
|
|
3963
|
-
const cacheControlValidator = new CacheControlValidator(
|
|
3979
|
+
const cacheControlValidator = new CacheControlValidator(
|
|
3980
|
+
this.config.cacheControlProviderOptionsName
|
|
3981
|
+
);
|
|
3964
3982
|
const toolNameMapping = createToolNameMapping({
|
|
3965
3983
|
tools,
|
|
3966
3984
|
providerToolNames: {
|
|
@@ -3990,11 +4008,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3990
4008
|
const toolsetNames = getAnthropicToolsetNames(tools);
|
|
3991
4009
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
3992
4010
|
prompt,
|
|
3993
|
-
sendReasoning: (
|
|
4011
|
+
sendReasoning: (_e = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _e : true,
|
|
3994
4012
|
warnings,
|
|
3995
4013
|
cacheControlValidator,
|
|
3996
4014
|
toolNameMapping,
|
|
3997
|
-
toolsetNames
|
|
4015
|
+
toolsetNames,
|
|
4016
|
+
convertMediaPart: this.config.convertMediaPart
|
|
3998
4017
|
});
|
|
3999
4018
|
if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
|
|
4000
4019
|
const requestedThinking = anthropicOptions.thinking;
|
|
@@ -4104,7 +4123,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4104
4123
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
4105
4124
|
cache_control: anthropicOptions.cacheControl
|
|
4106
4125
|
},
|
|
4107
|
-
...((
|
|
4126
|
+
...((_f = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _f.userId) != null && {
|
|
4108
4127
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
4109
4128
|
},
|
|
4110
4129
|
// mcp servers:
|
|
@@ -4212,7 +4231,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4212
4231
|
};
|
|
4213
4232
|
thinkingBudget = 1024;
|
|
4214
4233
|
}
|
|
4215
|
-
if (baseArgs.temperature != null) {
|
|
4234
|
+
if (baseArgs.temperature != null && !this.config.supportsTemperatureAndTopPWithThinking) {
|
|
4216
4235
|
baseArgs.temperature = void 0;
|
|
4217
4236
|
warnings.push({
|
|
4218
4237
|
type: "unsupported",
|
|
@@ -4228,7 +4247,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4228
4247
|
details: "topK is not supported when thinking is enabled"
|
|
4229
4248
|
});
|
|
4230
4249
|
}
|
|
4231
|
-
if (topP != null) {
|
|
4250
|
+
if (topP != null && !this.config.supportsTemperatureAndTopPWithThinking) {
|
|
4232
4251
|
baseArgs.top_p = void 0;
|
|
4233
4252
|
warnings.push({
|
|
4234
4253
|
type: "unsupported",
|
|
@@ -4299,7 +4318,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4299
4318
|
} else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
4300
4319
|
betas.add("server-side-fallback-2026-06-01");
|
|
4301
4320
|
}
|
|
4302
|
-
const defaultEagerInputStreaming = stream && ((
|
|
4321
|
+
const defaultEagerInputStreaming = stream && ((_g = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _g : true);
|
|
4303
4322
|
const {
|
|
4304
4323
|
tools: anthropicTools2,
|
|
4305
4324
|
toolChoice: anthropicToolChoice,
|
|
@@ -4340,7 +4359,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4340
4359
|
...betas,
|
|
4341
4360
|
...toolsBetas,
|
|
4342
4361
|
...userSuppliedBetas,
|
|
4343
|
-
...(
|
|
4362
|
+
...(_h = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _h : []
|
|
4344
4363
|
]),
|
|
4345
4364
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
4346
4365
|
toolNameMapping,
|