@ai-sdk/anthropic 3.0.92 → 3.0.94

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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 3.0.94
4
+
5
+ ### Patch Changes
6
+
7
+ - 0952964: Prevent prototype pollution when synchronously parsing provider JSON inputs and expose `secureJsonParse` from provider-utils.
8
+ - 764baab: Normalize a bare `https://api.anthropic.com` base URL to include `/v1`.
9
+ - Updated dependencies [0952964]
10
+ - @ai-sdk/provider-utils@4.0.36
11
+
12
+ ## 3.0.93
13
+
14
+ ### Patch Changes
15
+
16
+ - 4241b49: fix(anthropic): forward `thinking: { type: 'disabled' }` to the API instead of stripping it
17
+
18
+ Previously, setting `providerOptions.anthropic.thinking = { type: 'disabled' }` was accepted by the schema but silently dropped from the outgoing request. For models that default thinking on (e.g. Sonnet 5), this left thinking enabled and could consume a small `max_tokens` budget entirely. The `disabled` value is now sent to the Anthropic Messages API.
19
+
3
20
  ## 3.0.92
4
21
 
5
22
  ### Patch Changes
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
32
32
  var import_provider_utils26 = require("@ai-sdk/provider-utils");
33
33
 
34
34
  // src/version.ts
35
- var VERSION = true ? "3.0.92" : "0.0.0-test";
35
+ var VERSION = true ? "3.0.94" : "0.0.0-test";
36
36
 
37
37
  // src/anthropic-messages-language-model.ts
38
38
  var import_provider3 = require("@ai-sdk/provider");
@@ -2707,7 +2707,7 @@ async function convertToAnthropicMessagesPrompt({
2707
2707
  let errorInfo = {};
2708
2708
  try {
2709
2709
  if (typeof output.value === "string") {
2710
- errorInfo = JSON.parse(output.value);
2710
+ errorInfo = (0, import_provider_utils14.secureJsonParse)(output.value);
2711
2711
  } else if (typeof output.value === "object" && output.value !== null) {
2712
2712
  errorInfo = output.value;
2713
2713
  }
@@ -3465,6 +3465,7 @@ var AnthropicMessagesLanguageModel = class {
3465
3465
  });
3466
3466
  const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
3467
3467
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
3468
+ const sendThinking = isThinking || thinkingType === "disabled";
3468
3469
  let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
3469
3470
  const thinkingDisplay = thinkingType === "adaptive" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.display : void 0;
3470
3471
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
@@ -3478,7 +3479,7 @@ var AnthropicMessagesLanguageModel = class {
3478
3479
  top_p: topP,
3479
3480
  stop_sequences: stopSequences,
3480
3481
  // provider specific settings:
3481
- ...isThinking && {
3482
+ ...sendThinking && {
3482
3483
  thinking: {
3483
3484
  type: thinkingType,
3484
3485
  ...thinkingBudget != null && { budget_tokens: thinkingBudget },
@@ -4814,7 +4815,7 @@ var AnthropicMessagesLanguageModel = class {
4814
4815
  let finalInput = contentBlock.input === "" ? "{}" : contentBlock.input;
4815
4816
  if (contentBlock.providerToolName === "code_execution") {
4816
4817
  try {
4817
- const parsed = JSON.parse(finalInput);
4818
+ const parsed = (0, import_provider_utils15.secureJsonParse)(finalInput);
4818
4819
  if (parsed != null && typeof parsed === "object" && "code" in parsed && !("type" in parsed)) {
4819
4820
  finalInput = JSON.stringify({
4820
4821
  type: "programmatic-tool-call",
@@ -5784,14 +5785,20 @@ var anthropicTools = {
5784
5785
  };
5785
5786
 
5786
5787
  // src/anthropic-provider.ts
5788
+ var ANTHROPIC_API_URL = "https://api.anthropic.com";
5789
+ var ANTHROPIC_API_VERSIONED_URL = `${ANTHROPIC_API_URL}/v1`;
5790
+ function normalizeBaseURL(baseURL) {
5791
+ const baseURLWithoutTrailingSlash = (0, import_provider_utils26.withoutTrailingSlash)(baseURL);
5792
+ return baseURLWithoutTrailingSlash === ANTHROPIC_API_URL ? ANTHROPIC_API_VERSIONED_URL : baseURLWithoutTrailingSlash;
5793
+ }
5787
5794
  function createAnthropic(options = {}) {
5788
5795
  var _a, _b;
5789
- const baseURL = (_a = (0, import_provider_utils26.withoutTrailingSlash)(
5796
+ const baseURL = (_a = normalizeBaseURL(
5790
5797
  (0, import_provider_utils26.loadOptionalSetting)({
5791
5798
  settingValue: options.baseURL,
5792
5799
  environmentVariableName: "ANTHROPIC_BASE_URL"
5793
5800
  })
5794
- )) != null ? _a : "https://api.anthropic.com/v1";
5801
+ )) != null ? _a : ANTHROPIC_API_VERSIONED_URL;
5795
5802
  const providerName = (_b = options.name) != null ? _b : "anthropic.messages";
5796
5803
  if (options.apiKey && options.authToken) {
5797
5804
  throw new import_provider4.InvalidArgumentError({