@ai-sdk/anthropic 3.0.93 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/anthropic",
3
- "version": "3.0.93",
3
+ "version": "3.0.94",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@ai-sdk/provider": "3.0.13",
40
- "@ai-sdk/provider-utils": "4.0.35"
40
+ "@ai-sdk/provider-utils": "4.0.36"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "20.17.24",
@@ -24,6 +24,7 @@ import {
24
24
  parseProviderOptions,
25
25
  postJsonToApi,
26
26
  resolve,
27
+ secureJsonParse,
27
28
  type FetchFunction,
28
29
  type InferSchema,
29
30
  type ParseResult,
@@ -2078,7 +2079,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
2078
2079
  contentBlock.input === '' ? '{}' : contentBlock.input;
2079
2080
  if (contentBlock.providerToolName === 'code_execution') {
2080
2081
  try {
2081
- const parsed = JSON.parse(finalInput);
2082
+ const parsed = secureJsonParse(finalInput);
2082
2083
  if (
2083
2084
  parsed != null &&
2084
2085
  typeof parsed === 'object' &&
@@ -17,6 +17,17 @@ import { AnthropicMessagesLanguageModel } from './anthropic-messages-language-mo
17
17
  import type { AnthropicMessagesModelId } from './anthropic-messages-options';
18
18
  import { anthropicTools } from './anthropic-tools';
19
19
 
20
+ const ANTHROPIC_API_URL = 'https://api.anthropic.com';
21
+ const ANTHROPIC_API_VERSIONED_URL = `${ANTHROPIC_API_URL}/v1`;
22
+
23
+ function normalizeBaseURL(baseURL: string | undefined): string | undefined {
24
+ const baseURLWithoutTrailingSlash = withoutTrailingSlash(baseURL);
25
+
26
+ return baseURLWithoutTrailingSlash === ANTHROPIC_API_URL
27
+ ? ANTHROPIC_API_VERSIONED_URL
28
+ : baseURLWithoutTrailingSlash;
29
+ }
30
+
20
31
  export interface AnthropicProvider extends ProviderV3 {
21
32
  /**
22
33
  * Creates a model for text generation.
@@ -91,12 +102,12 @@ export function createAnthropic(
91
102
  options: AnthropicProviderSettings = {},
92
103
  ): AnthropicProvider {
93
104
  const baseURL =
94
- withoutTrailingSlash(
105
+ normalizeBaseURL(
95
106
  loadOptionalSetting({
96
107
  settingValue: options.baseURL,
97
108
  environmentVariableName: 'ANTHROPIC_BASE_URL',
98
109
  }),
99
- ) ?? 'https://api.anthropic.com/v1';
110
+ ) ?? ANTHROPIC_API_VERSIONED_URL;
100
111
 
101
112
  const providerName = options.name ?? 'anthropic.messages';
102
113
 
@@ -11,8 +11,9 @@ import {
11
11
  convertToBase64,
12
12
  parseProviderOptions,
13
13
  safeParseJSON,
14
- validateTypes,
15
14
  isNonNullable,
15
+ secureJsonParse,
16
+ validateTypes,
16
17
  type ToolNameMapping,
17
18
  } from '@ai-sdk/provider-utils';
18
19
  import {
@@ -767,7 +768,7 @@ export async function convertToAnthropicMessagesPrompt({
767
768
  let errorInfo: { type?: string; errorCode?: string } = {};
768
769
  try {
769
770
  if (typeof output.value === 'string') {
770
- errorInfo = JSON.parse(output.value);
771
+ errorInfo = secureJsonParse(output.value);
771
772
  } else if (
772
773
  typeof output.value === 'object' &&
773
774
  output.value !== null