@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/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.92" : "0.0.0-test";
15
+ var VERSION = true ? "3.0.94" : "0.0.0-test";
16
16
 
17
17
  // src/anthropic-messages-language-model.ts
18
18
  import {
@@ -26,7 +26,8 @@ import {
26
26
  generateId,
27
27
  parseProviderOptions as parseProviderOptions2,
28
28
  postJsonToApi,
29
- resolve
29
+ resolve,
30
+ secureJsonParse as secureJsonParse2
30
31
  } from "@ai-sdk/provider-utils";
31
32
 
32
33
  // src/anthropic-error.ts
@@ -1890,8 +1891,9 @@ import {
1890
1891
  convertToBase64,
1891
1892
  parseProviderOptions,
1892
1893
  safeParseJSON,
1893
- validateTypes as validateTypes2,
1894
- isNonNullable
1894
+ isNonNullable,
1895
+ secureJsonParse,
1896
+ validateTypes as validateTypes2
1895
1897
  } from "@ai-sdk/provider-utils";
1896
1898
 
1897
1899
  // src/tool/code-execution_20250522.ts
@@ -2756,7 +2758,7 @@ async function convertToAnthropicMessagesPrompt({
2756
2758
  let errorInfo = {};
2757
2759
  try {
2758
2760
  if (typeof output.value === "string") {
2759
- errorInfo = JSON.parse(output.value);
2761
+ errorInfo = secureJsonParse(output.value);
2760
2762
  } else if (typeof output.value === "object" && output.value !== null) {
2761
2763
  errorInfo = output.value;
2762
2764
  }
@@ -3514,6 +3516,7 @@ var AnthropicMessagesLanguageModel = class {
3514
3516
  });
3515
3517
  const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
3516
3518
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
3519
+ const sendThinking = isThinking || thinkingType === "disabled";
3517
3520
  let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
3518
3521
  const thinkingDisplay = thinkingType === "adaptive" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.display : void 0;
3519
3522
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
@@ -3527,7 +3530,7 @@ var AnthropicMessagesLanguageModel = class {
3527
3530
  top_p: topP,
3528
3531
  stop_sequences: stopSequences,
3529
3532
  // provider specific settings:
3530
- ...isThinking && {
3533
+ ...sendThinking && {
3531
3534
  thinking: {
3532
3535
  type: thinkingType,
3533
3536
  ...thinkingBudget != null && { budget_tokens: thinkingBudget },
@@ -4863,7 +4866,7 @@ var AnthropicMessagesLanguageModel = class {
4863
4866
  let finalInput = contentBlock.input === "" ? "{}" : contentBlock.input;
4864
4867
  if (contentBlock.providerToolName === "code_execution") {
4865
4868
  try {
4866
- const parsed = JSON.parse(finalInput);
4869
+ const parsed = secureJsonParse2(finalInput);
4867
4870
  if (parsed != null && typeof parsed === "object" && "code" in parsed && !("type" in parsed)) {
4868
4871
  finalInput = JSON.stringify({
4869
4872
  type: "programmatic-tool-call",
@@ -5873,14 +5876,20 @@ var anthropicTools = {
5873
5876
  };
5874
5877
 
5875
5878
  // src/anthropic-provider.ts
5879
+ var ANTHROPIC_API_URL = "https://api.anthropic.com";
5880
+ var ANTHROPIC_API_VERSIONED_URL = `${ANTHROPIC_API_URL}/v1`;
5881
+ function normalizeBaseURL(baseURL) {
5882
+ const baseURLWithoutTrailingSlash = withoutTrailingSlash(baseURL);
5883
+ return baseURLWithoutTrailingSlash === ANTHROPIC_API_URL ? ANTHROPIC_API_VERSIONED_URL : baseURLWithoutTrailingSlash;
5884
+ }
5876
5885
  function createAnthropic(options = {}) {
5877
5886
  var _a, _b;
5878
- const baseURL = (_a = withoutTrailingSlash(
5887
+ const baseURL = (_a = normalizeBaseURL(
5879
5888
  loadOptionalSetting({
5880
5889
  settingValue: options.baseURL,
5881
5890
  environmentVariableName: "ANTHROPIC_BASE_URL"
5882
5891
  })
5883
- )) != null ? _a : "https://api.anthropic.com/v1";
5892
+ )) != null ? _a : ANTHROPIC_API_VERSIONED_URL;
5884
5893
  const providerName = (_b = options.name) != null ? _b : "anthropic.messages";
5885
5894
  if (options.apiKey && options.authToken) {
5886
5895
  throw new InvalidArgumentError({