@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 +17 -0
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -9
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +4 -3
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +9 -6
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/anthropic-messages-language-model.ts +7 -2
- package/src/anthropic-provider.ts +13 -2
- package/src/convert-to-anthropic-messages-prompt.ts +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/anthropic",
|
|
3
|
-
"version": "3.0.
|
|
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.
|
|
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,
|
|
@@ -375,6 +376,10 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
375
376
|
const thinkingType = anthropicOptions?.thinking?.type;
|
|
376
377
|
const isThinking =
|
|
377
378
|
thinkingType === 'enabled' || thinkingType === 'adaptive';
|
|
379
|
+
// `disabled` must still be forwarded to the API: some models (e.g. Sonnet 5)
|
|
380
|
+
// default thinking on, so omitting it would leave thinking enabled and
|
|
381
|
+
// consume the max_tokens budget.
|
|
382
|
+
const sendThinking = isThinking || thinkingType === 'disabled';
|
|
378
383
|
let thinkingBudget =
|
|
379
384
|
thinkingType === 'enabled'
|
|
380
385
|
? anthropicOptions?.thinking?.budgetTokens
|
|
@@ -398,7 +403,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
398
403
|
stop_sequences: stopSequences,
|
|
399
404
|
|
|
400
405
|
// provider specific settings:
|
|
401
|
-
...(
|
|
406
|
+
...(sendThinking && {
|
|
402
407
|
thinking: {
|
|
403
408
|
type: thinkingType,
|
|
404
409
|
...(thinkingBudget != null && { budget_tokens: thinkingBudget }),
|
|
@@ -2074,7 +2079,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
2074
2079
|
contentBlock.input === '' ? '{}' : contentBlock.input;
|
|
2075
2080
|
if (contentBlock.providerToolName === 'code_execution') {
|
|
2076
2081
|
try {
|
|
2077
|
-
const parsed =
|
|
2082
|
+
const parsed = secureJsonParse(finalInput);
|
|
2078
2083
|
if (
|
|
2079
2084
|
parsed != null &&
|
|
2080
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
|
-
|
|
105
|
+
normalizeBaseURL(
|
|
95
106
|
loadOptionalSetting({
|
|
96
107
|
settingValue: options.baseURL,
|
|
97
108
|
environmentVariableName: 'ANTHROPIC_BASE_URL',
|
|
98
109
|
}),
|
|
99
|
-
) ??
|
|
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 =
|
|
771
|
+
errorInfo = secureJsonParse(output.value);
|
|
771
772
|
} else if (
|
|
772
773
|
typeof output.value === 'object' &&
|
|
773
774
|
output.value !== null
|