@ai-sdk/anthropic 3.0.20 → 3.0.22
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 +12 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +77 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -34
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +57 -25
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +57 -25
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__fixtures__/anthropic-tool-search-deferred-bm25.2.json +65 -0
- package/src/__fixtures__/anthropic-tool-search-deferred-bm25.chunks.txt +115 -0
- package/src/__fixtures__/anthropic-tool-search-deferred-regex.2.json +69 -0
- package/src/__fixtures__/anthropic-tool-search-deferred-regex.chunks.txt +119 -0
- package/src/anthropic-messages-language-model.test.ts +198 -0
- package/src/anthropic-messages-language-model.ts +38 -5
- package/src/anthropic-provider.test.ts +36 -0
- package/src/anthropic-provider.ts +32 -7
- package/src/tool/tool-search-bm25_20251119.ts +1 -0
- package/src/tool/tool-search-regex_20251119.ts +1 -0
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/anthropic-provider.ts
|
|
2
2
|
import {
|
|
3
|
+
InvalidArgumentError,
|
|
3
4
|
NoSuchModelError
|
|
4
5
|
} from "@ai-sdk/provider";
|
|
5
6
|
import {
|
|
@@ -11,7 +12,7 @@ import {
|
|
|
11
12
|
} from "@ai-sdk/provider-utils";
|
|
12
13
|
|
|
13
14
|
// src/version.ts
|
|
14
|
-
var VERSION = true ? "3.0.
|
|
15
|
+
var VERSION = true ? "3.0.22" : "0.0.0-test";
|
|
15
16
|
|
|
16
17
|
// src/anthropic-messages-language-model.ts
|
|
17
18
|
import {
|
|
@@ -1550,7 +1551,8 @@ var toolSearchRegex_20251119InputSchema = lazySchema8(
|
|
|
1550
1551
|
var factory6 = createProviderToolFactoryWithOutputSchema5({
|
|
1551
1552
|
id: "anthropic.tool_search_regex_20251119",
|
|
1552
1553
|
inputSchema: toolSearchRegex_20251119InputSchema,
|
|
1553
|
-
outputSchema: toolSearchRegex_20251119OutputSchema
|
|
1554
|
+
outputSchema: toolSearchRegex_20251119OutputSchema,
|
|
1555
|
+
supportsDeferredResults: true
|
|
1554
1556
|
});
|
|
1555
1557
|
var toolSearchRegex_20251119 = (args = {}) => {
|
|
1556
1558
|
return factory6(args);
|
|
@@ -2782,7 +2784,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2782
2784
|
});
|
|
2783
2785
|
}
|
|
2784
2786
|
async doGenerate(options) {
|
|
2785
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k
|
|
2787
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2786
2788
|
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
|
|
2787
2789
|
...options,
|
|
2788
2790
|
stream: false,
|
|
@@ -3071,7 +3073,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3071
3073
|
}
|
|
3072
3074
|
// tool search tool results:
|
|
3073
3075
|
case "tool_search_tool_result": {
|
|
3074
|
-
|
|
3076
|
+
let providerToolName = serverToolCalls[part.tool_use_id];
|
|
3077
|
+
if (providerToolName == null) {
|
|
3078
|
+
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
3079
|
+
"tool_search_tool_bm25"
|
|
3080
|
+
);
|
|
3081
|
+
const regexCustomName = toolNameMapping.toCustomToolName(
|
|
3082
|
+
"tool_search_tool_regex"
|
|
3083
|
+
);
|
|
3084
|
+
if (bm25CustomName !== "tool_search_tool_bm25") {
|
|
3085
|
+
providerToolName = "tool_search_tool_bm25";
|
|
3086
|
+
} else if (regexCustomName !== "tool_search_tool_regex") {
|
|
3087
|
+
providerToolName = "tool_search_tool_regex";
|
|
3088
|
+
} else {
|
|
3089
|
+
providerToolName = "tool_search_tool_regex";
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3075
3092
|
if (part.content.type === "tool_search_tool_search_result") {
|
|
3076
3093
|
content.push({
|
|
3077
3094
|
type: "tool-result",
|
|
@@ -3105,13 +3122,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3105
3122
|
finishReason: response.stop_reason,
|
|
3106
3123
|
isJsonResponseFromTool
|
|
3107
3124
|
}),
|
|
3108
|
-
raw: (
|
|
3125
|
+
raw: (_d = response.stop_reason) != null ? _d : void 0
|
|
3109
3126
|
},
|
|
3110
3127
|
usage: convertAnthropicMessagesUsage(response.usage),
|
|
3111
3128
|
request: { body: args },
|
|
3112
3129
|
response: {
|
|
3113
|
-
id: (
|
|
3114
|
-
modelId: (
|
|
3130
|
+
id: (_e = response.id) != null ? _e : void 0,
|
|
3131
|
+
modelId: (_f = response.model) != null ? _f : void 0,
|
|
3115
3132
|
headers: responseHeaders,
|
|
3116
3133
|
body: rawResponse
|
|
3117
3134
|
},
|
|
@@ -3119,20 +3136,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3119
3136
|
providerMetadata: {
|
|
3120
3137
|
anthropic: {
|
|
3121
3138
|
usage: response.usage,
|
|
3122
|
-
cacheCreationInputTokens: (
|
|
3123
|
-
stopSequence: (
|
|
3139
|
+
cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
|
|
3140
|
+
stopSequence: (_h = response.stop_sequence) != null ? _h : null,
|
|
3124
3141
|
container: response.container ? {
|
|
3125
3142
|
expiresAt: response.container.expires_at,
|
|
3126
3143
|
id: response.container.id,
|
|
3127
|
-
skills: (
|
|
3144
|
+
skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
|
|
3128
3145
|
type: skill.type,
|
|
3129
3146
|
skillId: skill.skill_id,
|
|
3130
3147
|
version: skill.version
|
|
3131
|
-
}))) != null ?
|
|
3148
|
+
}))) != null ? _j : null
|
|
3132
3149
|
} : null,
|
|
3133
|
-
contextManagement: (
|
|
3150
|
+
contextManagement: (_k = mapAnthropicResponseContextManagement(
|
|
3134
3151
|
response.context_management
|
|
3135
|
-
)) != null ?
|
|
3152
|
+
)) != null ? _k : null
|
|
3136
3153
|
}
|
|
3137
3154
|
}
|
|
3138
3155
|
};
|
|
@@ -3192,7 +3209,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3192
3209
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3193
3210
|
},
|
|
3194
3211
|
transform(chunk, controller) {
|
|
3195
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m
|
|
3212
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
3196
3213
|
if (options.includeRawChunks) {
|
|
3197
3214
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3198
3215
|
}
|
|
@@ -3453,7 +3470,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3453
3470
|
}
|
|
3454
3471
|
// tool search tool results:
|
|
3455
3472
|
case "tool_search_tool_result": {
|
|
3456
|
-
|
|
3473
|
+
let providerToolName = serverToolCalls[part.tool_use_id];
|
|
3474
|
+
if (providerToolName == null) {
|
|
3475
|
+
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
3476
|
+
"tool_search_tool_bm25"
|
|
3477
|
+
);
|
|
3478
|
+
const regexCustomName = toolNameMapping.toCustomToolName(
|
|
3479
|
+
"tool_search_tool_regex"
|
|
3480
|
+
);
|
|
3481
|
+
if (bm25CustomName !== "tool_search_tool_bm25") {
|
|
3482
|
+
providerToolName = "tool_search_tool_bm25";
|
|
3483
|
+
} else if (regexCustomName !== "tool_search_tool_regex") {
|
|
3484
|
+
providerToolName = "tool_search_tool_regex";
|
|
3485
|
+
} else {
|
|
3486
|
+
providerToolName = "tool_search_tool_regex";
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3457
3489
|
if (part.content.type === "tool_search_tool_search_result") {
|
|
3458
3490
|
controller.enqueue({
|
|
3459
3491
|
type: "tool-result",
|
|
@@ -3667,12 +3699,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3667
3699
|
}
|
|
3668
3700
|
case "message_start": {
|
|
3669
3701
|
usage.input_tokens = value.message.usage.input_tokens;
|
|
3670
|
-
usage.cache_read_input_tokens = (
|
|
3671
|
-
usage.cache_creation_input_tokens = (
|
|
3702
|
+
usage.cache_read_input_tokens = (_d = value.message.usage.cache_read_input_tokens) != null ? _d : 0;
|
|
3703
|
+
usage.cache_creation_input_tokens = (_e = value.message.usage.cache_creation_input_tokens) != null ? _e : 0;
|
|
3672
3704
|
rawUsage = {
|
|
3673
3705
|
...value.message.usage
|
|
3674
3706
|
};
|
|
3675
|
-
cacheCreationInputTokens = (
|
|
3707
|
+
cacheCreationInputTokens = (_f = value.message.usage.cache_creation_input_tokens) != null ? _f : null;
|
|
3676
3708
|
if (value.message.container != null) {
|
|
3677
3709
|
container = {
|
|
3678
3710
|
expiresAt: value.message.container.expires_at,
|
|
@@ -3691,8 +3723,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3691
3723
|
}
|
|
3692
3724
|
controller.enqueue({
|
|
3693
3725
|
type: "response-metadata",
|
|
3694
|
-
id: (
|
|
3695
|
-
modelId: (
|
|
3726
|
+
id: (_g = value.message.id) != null ? _g : void 0,
|
|
3727
|
+
modelId: (_h = value.message.model) != null ? _h : void 0
|
|
3696
3728
|
});
|
|
3697
3729
|
if (value.message.content != null) {
|
|
3698
3730
|
for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
|
|
@@ -3708,7 +3740,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3708
3740
|
id: part.id,
|
|
3709
3741
|
toolName: part.name
|
|
3710
3742
|
});
|
|
3711
|
-
const inputStr = JSON.stringify((
|
|
3743
|
+
const inputStr = JSON.stringify((_i = part.input) != null ? _i : {});
|
|
3712
3744
|
controller.enqueue({
|
|
3713
3745
|
type: "tool-input-delta",
|
|
3714
3746
|
id: part.id,
|
|
@@ -3746,17 +3778,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3746
3778
|
finishReason: value.delta.stop_reason,
|
|
3747
3779
|
isJsonResponseFromTool
|
|
3748
3780
|
}),
|
|
3749
|
-
raw: (
|
|
3781
|
+
raw: (_j = value.delta.stop_reason) != null ? _j : void 0
|
|
3750
3782
|
};
|
|
3751
|
-
stopSequence = (
|
|
3783
|
+
stopSequence = (_k = value.delta.stop_sequence) != null ? _k : null;
|
|
3752
3784
|
container = value.delta.container != null ? {
|
|
3753
3785
|
expiresAt: value.delta.container.expires_at,
|
|
3754
3786
|
id: value.delta.container.id,
|
|
3755
|
-
skills: (
|
|
3787
|
+
skills: (_m = (_l = value.delta.container.skills) == null ? void 0 : _l.map((skill) => ({
|
|
3756
3788
|
type: skill.type,
|
|
3757
3789
|
skillId: skill.skill_id,
|
|
3758
3790
|
version: skill.version
|
|
3759
|
-
}))) != null ?
|
|
3791
|
+
}))) != null ? _m : null
|
|
3760
3792
|
} : null;
|
|
3761
3793
|
if (value.delta.context_management) {
|
|
3762
3794
|
contextManagement = mapAnthropicResponseContextManagement(
|
|
@@ -4170,7 +4202,8 @@ var toolSearchBm25_20251119InputSchema = lazySchema17(
|
|
|
4170
4202
|
var factory7 = createProviderToolFactoryWithOutputSchema6({
|
|
4171
4203
|
id: "anthropic.tool_search_bm25_20251119",
|
|
4172
4204
|
inputSchema: toolSearchBm25_20251119InputSchema,
|
|
4173
|
-
outputSchema: toolSearchBm25_20251119OutputSchema
|
|
4205
|
+
outputSchema: toolSearchBm25_20251119OutputSchema,
|
|
4206
|
+
supportsDeferredResults: true
|
|
4174
4207
|
});
|
|
4175
4208
|
var toolSearchBm25_20251119 = (args = {}) => {
|
|
4176
4209
|
return factory7(args);
|
|
@@ -4340,18 +4373,29 @@ function createAnthropic(options = {}) {
|
|
|
4340
4373
|
})
|
|
4341
4374
|
)) != null ? _a : "https://api.anthropic.com/v1";
|
|
4342
4375
|
const providerName = (_b = options.name) != null ? _b : "anthropic.messages";
|
|
4343
|
-
|
|
4344
|
-
{
|
|
4345
|
-
|
|
4376
|
+
if (options.apiKey && options.authToken) {
|
|
4377
|
+
throw new InvalidArgumentError({
|
|
4378
|
+
argument: "apiKey/authToken",
|
|
4379
|
+
message: "Both apiKey and authToken were provided. Please use only one authentication method."
|
|
4380
|
+
});
|
|
4381
|
+
}
|
|
4382
|
+
const getHeaders = () => {
|
|
4383
|
+
const authHeaders = options.authToken ? { Authorization: `Bearer ${options.authToken}` } : {
|
|
4346
4384
|
"x-api-key": loadApiKey({
|
|
4347
4385
|
apiKey: options.apiKey,
|
|
4348
4386
|
environmentVariableName: "ANTHROPIC_API_KEY",
|
|
4349
4387
|
description: "Anthropic"
|
|
4350
|
-
})
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4388
|
+
})
|
|
4389
|
+
};
|
|
4390
|
+
return withUserAgentSuffix(
|
|
4391
|
+
{
|
|
4392
|
+
"anthropic-version": "2023-06-01",
|
|
4393
|
+
...authHeaders,
|
|
4394
|
+
...options.headers
|
|
4395
|
+
},
|
|
4396
|
+
`ai-sdk/anthropic/${VERSION}`
|
|
4397
|
+
);
|
|
4398
|
+
};
|
|
4355
4399
|
const createChatModel = (modelId) => {
|
|
4356
4400
|
var _a2;
|
|
4357
4401
|
return new AnthropicMessagesLanguageModel(modelId, {
|