@ai-sdk/anthropic 4.0.5 → 4.0.6
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 +9 -0
- package/dist/index.js +16 -8
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +7 -5
- package/dist/internal/index.js.map +1 -1
- package/package.json +2 -2
- package/src/anthropic-language-model.ts +2 -1
- package/src/anthropic-provider.ts +13 -2
- package/src/convert-to-anthropic-prompt.ts +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/anthropic",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@ai-sdk/provider": "4.0.1",
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.4"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "22.19.19",
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
postJsonToApi,
|
|
29
29
|
resolve,
|
|
30
30
|
resolveProviderReference,
|
|
31
|
+
secureJsonParse,
|
|
31
32
|
serializeModelOptions,
|
|
32
33
|
WORKFLOW_SERIALIZE,
|
|
33
34
|
WORKFLOW_DESERIALIZE,
|
|
@@ -2126,7 +2127,7 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
2126
2127
|
contentBlock.input === '' ? '{}' : contentBlock.input;
|
|
2127
2128
|
if (contentBlock.providerToolName === 'code_execution') {
|
|
2128
2129
|
try {
|
|
2129
|
-
const parsed =
|
|
2130
|
+
const parsed = secureJsonParse(finalInput);
|
|
2130
2131
|
if (
|
|
2131
2132
|
parsed != null &&
|
|
2132
2133
|
typeof parsed === 'object' &&
|
|
@@ -21,6 +21,17 @@ import { anthropicTools } from './anthropic-tools';
|
|
|
21
21
|
import { AnthropicSkills } from './skills/anthropic-skills';
|
|
22
22
|
import { VERSION } from './version';
|
|
23
23
|
|
|
24
|
+
const ANTHROPIC_API_URL = 'https://api.anthropic.com';
|
|
25
|
+
const ANTHROPIC_API_VERSIONED_URL = `${ANTHROPIC_API_URL}/v1`;
|
|
26
|
+
|
|
27
|
+
function normalizeBaseURL(baseURL: string | undefined): string | undefined {
|
|
28
|
+
const baseURLWithoutTrailingSlash = withoutTrailingSlash(baseURL);
|
|
29
|
+
|
|
30
|
+
return baseURLWithoutTrailingSlash === ANTHROPIC_API_URL
|
|
31
|
+
? ANTHROPIC_API_VERSIONED_URL
|
|
32
|
+
: baseURLWithoutTrailingSlash;
|
|
33
|
+
}
|
|
34
|
+
|
|
24
35
|
export interface AnthropicProvider extends ProviderV4 {
|
|
25
36
|
/**
|
|
26
37
|
* Creates a model for text generation.
|
|
@@ -102,12 +113,12 @@ export function createAnthropic(
|
|
|
102
113
|
options: AnthropicProviderSettings = {},
|
|
103
114
|
): AnthropicProvider {
|
|
104
115
|
const baseURL =
|
|
105
|
-
|
|
116
|
+
normalizeBaseURL(
|
|
106
117
|
loadOptionalSetting({
|
|
107
118
|
settingValue: options.baseURL,
|
|
108
119
|
environmentVariableName: 'ANTHROPIC_BASE_URL',
|
|
109
120
|
}),
|
|
110
|
-
) ??
|
|
121
|
+
) ?? ANTHROPIC_API_VERSIONED_URL;
|
|
111
122
|
|
|
112
123
|
const providerName = options.name ?? 'anthropic.messages';
|
|
113
124
|
|
|
@@ -9,11 +9,12 @@ import {
|
|
|
9
9
|
convertBase64ToUint8Array,
|
|
10
10
|
convertToBase64,
|
|
11
11
|
getTopLevelMediaType,
|
|
12
|
+
isNonNullable,
|
|
12
13
|
parseProviderOptions,
|
|
13
14
|
resolveFullMediaType,
|
|
14
15
|
resolveProviderReference,
|
|
16
|
+
secureJsonParse,
|
|
15
17
|
validateTypes,
|
|
16
|
-
isNonNullable,
|
|
17
18
|
type ToolNameMapping,
|
|
18
19
|
} from '@ai-sdk/provider-utils';
|
|
19
20
|
import {
|
|
@@ -48,7 +49,7 @@ function convertBytesDataToString(data: Uint8Array | string): string {
|
|
|
48
49
|
function extractErrorValue(value: unknown): { errorCode?: string } {
|
|
49
50
|
try {
|
|
50
51
|
if (typeof value === 'string') {
|
|
51
|
-
return
|
|
52
|
+
return secureJsonParse(value);
|
|
52
53
|
} else if (typeof value === 'object' && value !== null) {
|
|
53
54
|
return value as { errorCode?: string };
|
|
54
55
|
}
|
|
@@ -844,7 +845,7 @@ export async function convertToAnthropicPrompt({
|
|
|
844
845
|
let errorInfo: { type?: string; errorCode?: string } = {};
|
|
845
846
|
try {
|
|
846
847
|
if (typeof output.value === 'string') {
|
|
847
|
-
errorInfo =
|
|
848
|
+
errorInfo = secureJsonParse(output.value);
|
|
848
849
|
} else if (
|
|
849
850
|
typeof output.value === 'object' &&
|
|
850
851
|
output.value !== null
|