@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.
@@ -1206,19 +1206,24 @@ import {
1206
1206
 
1207
1207
  // src/get-cache-control.ts
1208
1208
  var MAX_CACHE_BREAKPOINTS = 4;
1209
- function getCacheControl(providerMetadata) {
1210
- var _a;
1209
+ function getCacheControl(providerMetadata, providerOptionsName) {
1210
+ var _a, _b, _c;
1211
+ const custom = providerMetadata == null ? void 0 : providerMetadata[providerOptionsName];
1211
1212
  const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
1212
- const cacheControlValue = (_a = anthropic == null ? void 0 : anthropic.cacheControl) != null ? _a : anthropic == null ? void 0 : anthropic.cache_control;
1213
+ 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;
1213
1214
  return cacheControlValue;
1214
1215
  }
1215
1216
  var CacheControlValidator = class {
1216
- constructor() {
1217
+ constructor(providerOptionsName = "anthropic") {
1218
+ this.providerOptionsName = providerOptionsName;
1217
1219
  this.breakpointCount = 0;
1218
1220
  this.warnings = [];
1219
1221
  }
1220
1222
  getCacheControl(providerMetadata, context) {
1221
- const cacheControlValue = getCacheControl(providerMetadata);
1223
+ const cacheControlValue = getCacheControl(
1224
+ providerMetadata,
1225
+ this.providerOptionsName
1226
+ );
1222
1227
  if (!cacheControlValue) {
1223
1228
  return void 0;
1224
1229
  }
@@ -2482,7 +2487,8 @@ async function convertToAnthropicMessagesPrompt({
2482
2487
  warnings,
2483
2488
  cacheControlValidator,
2484
2489
  toolNameMapping,
2485
- toolsetNames = {}
2490
+ toolsetNames = {},
2491
+ convertMediaPart
2486
2492
  }) {
2487
2493
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
2488
2494
  const betas = /* @__PURE__ */ new Set();
@@ -2625,6 +2631,14 @@ async function convertToAnthropicMessagesPrompt({
2625
2631
  break;
2626
2632
  }
2627
2633
  case "file": {
2634
+ const customContent = await (convertMediaPart == null ? void 0 : convertMediaPart(part));
2635
+ if (customContent != null) {
2636
+ anthropicContent.push({
2637
+ ...customContent,
2638
+ cache_control: cacheControl
2639
+ });
2640
+ break;
2641
+ }
2628
2642
  if (part.mediaType.startsWith("image/")) {
2629
2643
  anthropicContent.push({
2630
2644
  type: "image",
@@ -3821,7 +3835,7 @@ var AnthropicMessagesLanguageModel = class {
3821
3835
  providerOptions,
3822
3836
  stream
3823
3837
  }) {
3824
- var _a, _b, _c, _d, _e, _f, _g;
3838
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3825
3839
  const warnings = [];
3826
3840
  if (frequencyPenalty != null) {
3827
3841
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -3832,18 +3846,20 @@ var AnthropicMessagesLanguageModel = class {
3832
3846
  if (seed != null) {
3833
3847
  warnings.push({ type: "unsupported", feature: "seed" });
3834
3848
  }
3835
- if (temperature != null && temperature > 1) {
3849
+ const maxTemperature = (_a = this.config.maxTemperature) != null ? _a : 1;
3850
+ const temperatureProvider = this.config.maxTemperature == null ? "anthropic" : this.providerOptionsName;
3851
+ if (temperature != null && temperature > maxTemperature) {
3836
3852
  warnings.push({
3837
3853
  type: "unsupported",
3838
3854
  feature: "temperature",
3839
- details: `${temperature} exceeds anthropic maximum of 1.0. clamped to 1.0`
3855
+ details: `${temperature} exceeds ${temperatureProvider} maximum of ${maxTemperature.toFixed(1)}. clamped to ${maxTemperature.toFixed(1)}`
3840
3856
  });
3841
- temperature = 1;
3857
+ temperature = maxTemperature;
3842
3858
  } else if (temperature != null && temperature < 0) {
3843
3859
  warnings.push({
3844
3860
  type: "unsupported",
3845
3861
  feature: "temperature",
3846
- details: `${temperature} is below anthropic minimum of 0. clamped to 0`
3862
+ details: `${temperature} is below ${temperatureProvider} minimum of 0. clamped to 0`
3847
3863
  });
3848
3864
  temperature = 0;
3849
3865
  }
@@ -3918,9 +3934,9 @@ var AnthropicMessagesLanguageModel = class {
3918
3934
  }
3919
3935
  }
3920
3936
  const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
3921
- const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
3922
- const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
3923
- const structureOutputMode = (_c = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _c : "auto";
3937
+ const supportsStructuredOutput = ((_b = this.config.supportsNativeStructuredOutput) != null ? _b : true) && modelSupportsStructuredOutput;
3938
+ const supportsStrictTools = ((_c = this.config.supportsStrictTools) != null ? _c : true) && modelSupportsStructuredOutput;
3939
+ const structureOutputMode = (_d = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _d : "auto";
3924
3940
  let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
3925
3941
  if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
3926
3942
  warnings.push({
@@ -3944,7 +3960,9 @@ var AnthropicMessagesLanguageModel = class {
3944
3960
  });
3945
3961
  }
3946
3962
  const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
3947
- const cacheControlValidator = new CacheControlValidator();
3963
+ const cacheControlValidator = new CacheControlValidator(
3964
+ this.config.cacheControlProviderOptionsName
3965
+ );
3948
3966
  const toolNameMapping = createToolNameMapping({
3949
3967
  tools,
3950
3968
  providerToolNames: {
@@ -3974,11 +3992,12 @@ var AnthropicMessagesLanguageModel = class {
3974
3992
  const toolsetNames = getAnthropicToolsetNames(tools);
3975
3993
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
3976
3994
  prompt,
3977
- sendReasoning: (_d = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _d : true,
3995
+ sendReasoning: (_e = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _e : true,
3978
3996
  warnings,
3979
3997
  cacheControlValidator,
3980
3998
  toolNameMapping,
3981
- toolsetNames
3999
+ toolsetNames,
4000
+ convertMediaPart: this.config.convertMediaPart
3982
4001
  });
3983
4002
  if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
3984
4003
  const requestedThinking = anthropicOptions.thinking;
@@ -4088,7 +4107,7 @@ var AnthropicMessagesLanguageModel = class {
4088
4107
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
4089
4108
  cache_control: anthropicOptions.cacheControl
4090
4109
  },
4091
- ...((_e = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _e.userId) != null && {
4110
+ ...((_f = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _f.userId) != null && {
4092
4111
  metadata: { user_id: anthropicOptions.metadata.userId }
4093
4112
  },
4094
4113
  // mcp servers:
@@ -4196,7 +4215,7 @@ var AnthropicMessagesLanguageModel = class {
4196
4215
  };
4197
4216
  thinkingBudget = 1024;
4198
4217
  }
4199
- if (baseArgs.temperature != null) {
4218
+ if (baseArgs.temperature != null && !this.config.supportsTemperatureAndTopPWithThinking) {
4200
4219
  baseArgs.temperature = void 0;
4201
4220
  warnings.push({
4202
4221
  type: "unsupported",
@@ -4212,7 +4231,7 @@ var AnthropicMessagesLanguageModel = class {
4212
4231
  details: "topK is not supported when thinking is enabled"
4213
4232
  });
4214
4233
  }
4215
- if (topP != null) {
4234
+ if (topP != null && !this.config.supportsTemperatureAndTopPWithThinking) {
4216
4235
  baseArgs.top_p = void 0;
4217
4236
  warnings.push({
4218
4237
  type: "unsupported",
@@ -4283,7 +4302,7 @@ var AnthropicMessagesLanguageModel = class {
4283
4302
  } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
4284
4303
  betas.add("server-side-fallback-2026-06-01");
4285
4304
  }
4286
- const defaultEagerInputStreaming = stream && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _f : true);
4305
+ const defaultEagerInputStreaming = stream && ((_g = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _g : true);
4287
4306
  const {
4288
4307
  tools: anthropicTools2,
4289
4308
  toolChoice: anthropicToolChoice,
@@ -4324,7 +4343,7 @@ var AnthropicMessagesLanguageModel = class {
4324
4343
  ...betas,
4325
4344
  ...toolsBetas,
4326
4345
  ...userSuppliedBetas,
4327
- ...(_g = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _g : []
4346
+ ...(_h = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _h : []
4328
4347
  ]),
4329
4348
  usesJsonResponseTool: jsonResponseTool != null,
4330
4349
  toolNameMapping,