@ai-sdk/anthropic 3.0.133 → 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 +6 -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 +1 -1
- 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/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
32
32
|
var import_provider_utils27 = require("@ai-sdk/provider-utils");
|
|
33
33
|
|
|
34
34
|
// src/version.ts
|
|
35
|
-
var VERSION = true ? "3.0.
|
|
35
|
+
var VERSION = true ? "3.0.134" : "0.0.0-test";
|
|
36
36
|
|
|
37
37
|
// src/anthropic-messages-language-model.ts
|
|
38
38
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -1220,19 +1220,24 @@ var import_provider = require("@ai-sdk/provider");
|
|
|
1220
1220
|
|
|
1221
1221
|
// src/get-cache-control.ts
|
|
1222
1222
|
var MAX_CACHE_BREAKPOINTS = 4;
|
|
1223
|
-
function getCacheControl(providerMetadata) {
|
|
1224
|
-
var _a;
|
|
1223
|
+
function getCacheControl(providerMetadata, providerOptionsName) {
|
|
1224
|
+
var _a, _b, _c;
|
|
1225
|
+
const custom = providerMetadata == null ? void 0 : providerMetadata[providerOptionsName];
|
|
1225
1226
|
const anthropic2 = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
1226
|
-
const cacheControlValue = (_a = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ?
|
|
1227
|
+
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;
|
|
1227
1228
|
return cacheControlValue;
|
|
1228
1229
|
}
|
|
1229
1230
|
var CacheControlValidator = class {
|
|
1230
|
-
constructor() {
|
|
1231
|
+
constructor(providerOptionsName = "anthropic") {
|
|
1232
|
+
this.providerOptionsName = providerOptionsName;
|
|
1231
1233
|
this.breakpointCount = 0;
|
|
1232
1234
|
this.warnings = [];
|
|
1233
1235
|
}
|
|
1234
1236
|
getCacheControl(providerMetadata, context) {
|
|
1235
|
-
const cacheControlValue = getCacheControl(
|
|
1237
|
+
const cacheControlValue = getCacheControl(
|
|
1238
|
+
providerMetadata,
|
|
1239
|
+
this.providerOptionsName
|
|
1240
|
+
);
|
|
1236
1241
|
if (!cacheControlValue) {
|
|
1237
1242
|
return void 0;
|
|
1238
1243
|
}
|
|
@@ -2442,7 +2447,8 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2442
2447
|
warnings,
|
|
2443
2448
|
cacheControlValidator,
|
|
2444
2449
|
toolNameMapping,
|
|
2445
|
-
toolsetNames = {}
|
|
2450
|
+
toolsetNames = {},
|
|
2451
|
+
convertMediaPart
|
|
2446
2452
|
}) {
|
|
2447
2453
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2448
2454
|
const betas = /* @__PURE__ */ new Set();
|
|
@@ -2585,6 +2591,14 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2585
2591
|
break;
|
|
2586
2592
|
}
|
|
2587
2593
|
case "file": {
|
|
2594
|
+
const customContent = await (convertMediaPart == null ? void 0 : convertMediaPart(part));
|
|
2595
|
+
if (customContent != null) {
|
|
2596
|
+
anthropicContent.push({
|
|
2597
|
+
...customContent,
|
|
2598
|
+
cache_control: cacheControl
|
|
2599
|
+
});
|
|
2600
|
+
break;
|
|
2601
|
+
}
|
|
2588
2602
|
if (part.mediaType.startsWith("image/")) {
|
|
2589
2603
|
anthropicContent.push({
|
|
2590
2604
|
type: "image",
|
|
@@ -3781,7 +3795,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3781
3795
|
providerOptions,
|
|
3782
3796
|
stream
|
|
3783
3797
|
}) {
|
|
3784
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
3798
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3785
3799
|
const warnings = [];
|
|
3786
3800
|
if (frequencyPenalty != null) {
|
|
3787
3801
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -3792,18 +3806,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3792
3806
|
if (seed != null) {
|
|
3793
3807
|
warnings.push({ type: "unsupported", feature: "seed" });
|
|
3794
3808
|
}
|
|
3795
|
-
|
|
3809
|
+
const maxTemperature = (_a = this.config.maxTemperature) != null ? _a : 1;
|
|
3810
|
+
const temperatureProvider = this.config.maxTemperature == null ? "anthropic" : this.providerOptionsName;
|
|
3811
|
+
if (temperature != null && temperature > maxTemperature) {
|
|
3796
3812
|
warnings.push({
|
|
3797
3813
|
type: "unsupported",
|
|
3798
3814
|
feature: "temperature",
|
|
3799
|
-
details: `${temperature} exceeds
|
|
3815
|
+
details: `${temperature} exceeds ${temperatureProvider} maximum of ${maxTemperature.toFixed(1)}. clamped to ${maxTemperature.toFixed(1)}`
|
|
3800
3816
|
});
|
|
3801
|
-
temperature =
|
|
3817
|
+
temperature = maxTemperature;
|
|
3802
3818
|
} else if (temperature != null && temperature < 0) {
|
|
3803
3819
|
warnings.push({
|
|
3804
3820
|
type: "unsupported",
|
|
3805
3821
|
feature: "temperature",
|
|
3806
|
-
details: `${temperature} is below
|
|
3822
|
+
details: `${temperature} is below ${temperatureProvider} minimum of 0. clamped to 0`
|
|
3807
3823
|
});
|
|
3808
3824
|
temperature = 0;
|
|
3809
3825
|
}
|
|
@@ -3878,9 +3894,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3878
3894
|
}
|
|
3879
3895
|
}
|
|
3880
3896
|
const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
|
|
3881
|
-
const supportsStructuredOutput = ((
|
|
3882
|
-
const supportsStrictTools = ((
|
|
3883
|
-
const structureOutputMode = (
|
|
3897
|
+
const supportsStructuredOutput = ((_b = this.config.supportsNativeStructuredOutput) != null ? _b : true) && modelSupportsStructuredOutput;
|
|
3898
|
+
const supportsStrictTools = ((_c = this.config.supportsStrictTools) != null ? _c : true) && modelSupportsStructuredOutput;
|
|
3899
|
+
const structureOutputMode = (_d = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _d : "auto";
|
|
3884
3900
|
let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
3885
3901
|
if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
3886
3902
|
warnings.push({
|
|
@@ -3904,7 +3920,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3904
3920
|
});
|
|
3905
3921
|
}
|
|
3906
3922
|
const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
|
|
3907
|
-
const cacheControlValidator = new CacheControlValidator(
|
|
3923
|
+
const cacheControlValidator = new CacheControlValidator(
|
|
3924
|
+
this.config.cacheControlProviderOptionsName
|
|
3925
|
+
);
|
|
3908
3926
|
const toolNameMapping = (0, import_provider_utils16.createToolNameMapping)({
|
|
3909
3927
|
tools,
|
|
3910
3928
|
providerToolNames: {
|
|
@@ -3934,11 +3952,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3934
3952
|
const toolsetNames = getAnthropicToolsetNames(tools);
|
|
3935
3953
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
3936
3954
|
prompt,
|
|
3937
|
-
sendReasoning: (
|
|
3955
|
+
sendReasoning: (_e = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _e : true,
|
|
3938
3956
|
warnings,
|
|
3939
3957
|
cacheControlValidator,
|
|
3940
3958
|
toolNameMapping,
|
|
3941
|
-
toolsetNames
|
|
3959
|
+
toolsetNames,
|
|
3960
|
+
convertMediaPart: this.config.convertMediaPart
|
|
3942
3961
|
});
|
|
3943
3962
|
if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
|
|
3944
3963
|
const requestedThinking = anthropicOptions.thinking;
|
|
@@ -4048,7 +4067,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4048
4067
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
4049
4068
|
cache_control: anthropicOptions.cacheControl
|
|
4050
4069
|
},
|
|
4051
|
-
...((
|
|
4070
|
+
...((_f = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _f.userId) != null && {
|
|
4052
4071
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
4053
4072
|
},
|
|
4054
4073
|
// mcp servers:
|
|
@@ -4156,7 +4175,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4156
4175
|
};
|
|
4157
4176
|
thinkingBudget = 1024;
|
|
4158
4177
|
}
|
|
4159
|
-
if (baseArgs.temperature != null) {
|
|
4178
|
+
if (baseArgs.temperature != null && !this.config.supportsTemperatureAndTopPWithThinking) {
|
|
4160
4179
|
baseArgs.temperature = void 0;
|
|
4161
4180
|
warnings.push({
|
|
4162
4181
|
type: "unsupported",
|
|
@@ -4172,7 +4191,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4172
4191
|
details: "topK is not supported when thinking is enabled"
|
|
4173
4192
|
});
|
|
4174
4193
|
}
|
|
4175
|
-
if (topP != null) {
|
|
4194
|
+
if (topP != null && !this.config.supportsTemperatureAndTopPWithThinking) {
|
|
4176
4195
|
baseArgs.top_p = void 0;
|
|
4177
4196
|
warnings.push({
|
|
4178
4197
|
type: "unsupported",
|
|
@@ -4243,7 +4262,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4243
4262
|
} else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
4244
4263
|
betas.add("server-side-fallback-2026-06-01");
|
|
4245
4264
|
}
|
|
4246
|
-
const defaultEagerInputStreaming = stream && ((
|
|
4265
|
+
const defaultEagerInputStreaming = stream && ((_g = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _g : true);
|
|
4247
4266
|
const {
|
|
4248
4267
|
tools: anthropicTools2,
|
|
4249
4268
|
toolChoice: anthropicToolChoice,
|
|
@@ -4284,7 +4303,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4284
4303
|
...betas,
|
|
4285
4304
|
...toolsBetas,
|
|
4286
4305
|
...userSuppliedBetas,
|
|
4287
|
-
...(
|
|
4306
|
+
...(_h = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _h : []
|
|
4288
4307
|
]),
|
|
4289
4308
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
4290
4309
|
toolNameMapping,
|