@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/internal/index.js
CHANGED
|
@@ -1214,19 +1214,24 @@ var import_provider = require("@ai-sdk/provider");
|
|
|
1214
1214
|
|
|
1215
1215
|
// src/get-cache-control.ts
|
|
1216
1216
|
var MAX_CACHE_BREAKPOINTS = 4;
|
|
1217
|
-
function getCacheControl(providerMetadata) {
|
|
1218
|
-
var _a;
|
|
1217
|
+
function getCacheControl(providerMetadata, providerOptionsName) {
|
|
1218
|
+
var _a, _b, _c;
|
|
1219
|
+
const custom = providerMetadata == null ? void 0 : providerMetadata[providerOptionsName];
|
|
1219
1220
|
const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
1220
|
-
const cacheControlValue = (_a = anthropic == null ? void 0 : anthropic.cacheControl) != null ?
|
|
1221
|
+
const cacheControlValue = (_c = (_b = (_a = custom == null ? void 0 : custom.cacheControl) != null ? _a : custom == null ? void 0 : custom.cache_control) != null ? _b : anthropic == null ? void 0 : anthropic.cacheControl) != null ? _c : anthropic == null ? void 0 : anthropic.cache_control;
|
|
1221
1222
|
return cacheControlValue;
|
|
1222
1223
|
}
|
|
1223
1224
|
var CacheControlValidator = class {
|
|
1224
|
-
constructor() {
|
|
1225
|
+
constructor(providerOptionsName = "anthropic") {
|
|
1226
|
+
this.providerOptionsName = providerOptionsName;
|
|
1225
1227
|
this.breakpointCount = 0;
|
|
1226
1228
|
this.warnings = [];
|
|
1227
1229
|
}
|
|
1228
1230
|
getCacheControl(providerMetadata, context) {
|
|
1229
|
-
const cacheControlValue = getCacheControl(
|
|
1231
|
+
const cacheControlValue = getCacheControl(
|
|
1232
|
+
providerMetadata,
|
|
1233
|
+
this.providerOptionsName
|
|
1234
|
+
);
|
|
1230
1235
|
if (!cacheControlValue) {
|
|
1231
1236
|
return void 0;
|
|
1232
1237
|
}
|
|
@@ -2436,7 +2441,8 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2436
2441
|
warnings,
|
|
2437
2442
|
cacheControlValidator,
|
|
2438
2443
|
toolNameMapping,
|
|
2439
|
-
toolsetNames = {}
|
|
2444
|
+
toolsetNames = {},
|
|
2445
|
+
convertMediaPart
|
|
2440
2446
|
}) {
|
|
2441
2447
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2442
2448
|
const betas = /* @__PURE__ */ new Set();
|
|
@@ -2579,6 +2585,14 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2579
2585
|
break;
|
|
2580
2586
|
}
|
|
2581
2587
|
case "file": {
|
|
2588
|
+
const customContent = await (convertMediaPart == null ? void 0 : convertMediaPart(part));
|
|
2589
|
+
if (customContent != null) {
|
|
2590
|
+
anthropicContent.push({
|
|
2591
|
+
...customContent,
|
|
2592
|
+
cache_control: cacheControl
|
|
2593
|
+
});
|
|
2594
|
+
break;
|
|
2595
|
+
}
|
|
2582
2596
|
if (part.mediaType.startsWith("image/")) {
|
|
2583
2597
|
anthropicContent.push({
|
|
2584
2598
|
type: "image",
|
|
@@ -3775,7 +3789,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3775
3789
|
providerOptions,
|
|
3776
3790
|
stream
|
|
3777
3791
|
}) {
|
|
3778
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
3792
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3779
3793
|
const warnings = [];
|
|
3780
3794
|
if (frequencyPenalty != null) {
|
|
3781
3795
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -3786,18 +3800,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3786
3800
|
if (seed != null) {
|
|
3787
3801
|
warnings.push({ type: "unsupported", feature: "seed" });
|
|
3788
3802
|
}
|
|
3789
|
-
|
|
3803
|
+
const maxTemperature = (_a = this.config.maxTemperature) != null ? _a : 1;
|
|
3804
|
+
const temperatureProvider = this.config.maxTemperature == null ? "anthropic" : this.providerOptionsName;
|
|
3805
|
+
if (temperature != null && temperature > maxTemperature) {
|
|
3790
3806
|
warnings.push({
|
|
3791
3807
|
type: "unsupported",
|
|
3792
3808
|
feature: "temperature",
|
|
3793
|
-
details: `${temperature} exceeds
|
|
3809
|
+
details: `${temperature} exceeds ${temperatureProvider} maximum of ${maxTemperature.toFixed(1)}. clamped to ${maxTemperature.toFixed(1)}`
|
|
3794
3810
|
});
|
|
3795
|
-
temperature =
|
|
3811
|
+
temperature = maxTemperature;
|
|
3796
3812
|
} else if (temperature != null && temperature < 0) {
|
|
3797
3813
|
warnings.push({
|
|
3798
3814
|
type: "unsupported",
|
|
3799
3815
|
feature: "temperature",
|
|
3800
|
-
details: `${temperature} is below
|
|
3816
|
+
details: `${temperature} is below ${temperatureProvider} minimum of 0. clamped to 0`
|
|
3801
3817
|
});
|
|
3802
3818
|
temperature = 0;
|
|
3803
3819
|
}
|
|
@@ -3872,9 +3888,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3872
3888
|
}
|
|
3873
3889
|
}
|
|
3874
3890
|
const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
|
|
3875
|
-
const supportsStructuredOutput = ((
|
|
3876
|
-
const supportsStrictTools = ((
|
|
3877
|
-
const structureOutputMode = (
|
|
3891
|
+
const supportsStructuredOutput = ((_b = this.config.supportsNativeStructuredOutput) != null ? _b : true) && modelSupportsStructuredOutput;
|
|
3892
|
+
const supportsStrictTools = ((_c = this.config.supportsStrictTools) != null ? _c : true) && modelSupportsStructuredOutput;
|
|
3893
|
+
const structureOutputMode = (_d = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _d : "auto";
|
|
3878
3894
|
let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
3879
3895
|
if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
3880
3896
|
warnings.push({
|
|
@@ -3898,7 +3914,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3898
3914
|
});
|
|
3899
3915
|
}
|
|
3900
3916
|
const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
|
|
3901
|
-
const cacheControlValidator = new CacheControlValidator(
|
|
3917
|
+
const cacheControlValidator = new CacheControlValidator(
|
|
3918
|
+
this.config.cacheControlProviderOptionsName
|
|
3919
|
+
);
|
|
3902
3920
|
const toolNameMapping = (0, import_provider_utils16.createToolNameMapping)({
|
|
3903
3921
|
tools,
|
|
3904
3922
|
providerToolNames: {
|
|
@@ -3928,11 +3946,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3928
3946
|
const toolsetNames = getAnthropicToolsetNames(tools);
|
|
3929
3947
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
3930
3948
|
prompt,
|
|
3931
|
-
sendReasoning: (
|
|
3949
|
+
sendReasoning: (_e = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _e : true,
|
|
3932
3950
|
warnings,
|
|
3933
3951
|
cacheControlValidator,
|
|
3934
3952
|
toolNameMapping,
|
|
3935
|
-
toolsetNames
|
|
3953
|
+
toolsetNames,
|
|
3954
|
+
convertMediaPart: this.config.convertMediaPart
|
|
3936
3955
|
});
|
|
3937
3956
|
if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
|
|
3938
3957
|
const requestedThinking = anthropicOptions.thinking;
|
|
@@ -4042,7 +4061,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4042
4061
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
4043
4062
|
cache_control: anthropicOptions.cacheControl
|
|
4044
4063
|
},
|
|
4045
|
-
...((
|
|
4064
|
+
...((_f = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _f.userId) != null && {
|
|
4046
4065
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
4047
4066
|
},
|
|
4048
4067
|
// mcp servers:
|
|
@@ -4150,7 +4169,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4150
4169
|
};
|
|
4151
4170
|
thinkingBudget = 1024;
|
|
4152
4171
|
}
|
|
4153
|
-
if (baseArgs.temperature != null) {
|
|
4172
|
+
if (baseArgs.temperature != null && !this.config.supportsTemperatureAndTopPWithThinking) {
|
|
4154
4173
|
baseArgs.temperature = void 0;
|
|
4155
4174
|
warnings.push({
|
|
4156
4175
|
type: "unsupported",
|
|
@@ -4166,7 +4185,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4166
4185
|
details: "topK is not supported when thinking is enabled"
|
|
4167
4186
|
});
|
|
4168
4187
|
}
|
|
4169
|
-
if (topP != null) {
|
|
4188
|
+
if (topP != null && !this.config.supportsTemperatureAndTopPWithThinking) {
|
|
4170
4189
|
baseArgs.top_p = void 0;
|
|
4171
4190
|
warnings.push({
|
|
4172
4191
|
type: "unsupported",
|
|
@@ -4237,7 +4256,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4237
4256
|
} else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
4238
4257
|
betas.add("server-side-fallback-2026-06-01");
|
|
4239
4258
|
}
|
|
4240
|
-
const defaultEagerInputStreaming = stream && ((
|
|
4259
|
+
const defaultEagerInputStreaming = stream && ((_g = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _g : true);
|
|
4241
4260
|
const {
|
|
4242
4261
|
tools: anthropicTools2,
|
|
4243
4262
|
toolChoice: anthropicToolChoice,
|
|
@@ -4278,7 +4297,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4278
4297
|
...betas,
|
|
4279
4298
|
...toolsBetas,
|
|
4280
4299
|
...userSuppliedBetas,
|
|
4281
|
-
...(
|
|
4300
|
+
...(_h = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _h : []
|
|
4282
4301
|
]),
|
|
4283
4302
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
4284
4303
|
toolNameMapping,
|