@ai-sdk/anthropic 3.0.19 → 3.0.21
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.js +58 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -26
- 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/docs/05-anthropic.mdx +1096 -0
- package/package.json +8 -4
- 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/tool/tool-search-bm25_20251119.ts +1 -0
- package/src/tool/tool-search-regex_20251119.ts +1 -0
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "@ai-sdk/provider-utils";
|
|
12
12
|
|
|
13
13
|
// src/version.ts
|
|
14
|
-
var VERSION = true ? "3.0.
|
|
14
|
+
var VERSION = true ? "3.0.21" : "0.0.0-test";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-messages-language-model.ts
|
|
17
17
|
import {
|
|
@@ -1550,7 +1550,8 @@ var toolSearchRegex_20251119InputSchema = lazySchema8(
|
|
|
1550
1550
|
var factory6 = createProviderToolFactoryWithOutputSchema5({
|
|
1551
1551
|
id: "anthropic.tool_search_regex_20251119",
|
|
1552
1552
|
inputSchema: toolSearchRegex_20251119InputSchema,
|
|
1553
|
-
outputSchema: toolSearchRegex_20251119OutputSchema
|
|
1553
|
+
outputSchema: toolSearchRegex_20251119OutputSchema,
|
|
1554
|
+
supportsDeferredResults: true
|
|
1554
1555
|
});
|
|
1555
1556
|
var toolSearchRegex_20251119 = (args = {}) => {
|
|
1556
1557
|
return factory6(args);
|
|
@@ -2782,7 +2783,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2782
2783
|
});
|
|
2783
2784
|
}
|
|
2784
2785
|
async doGenerate(options) {
|
|
2785
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k
|
|
2786
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2786
2787
|
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
|
|
2787
2788
|
...options,
|
|
2788
2789
|
stream: false,
|
|
@@ -3071,7 +3072,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3071
3072
|
}
|
|
3072
3073
|
// tool search tool results:
|
|
3073
3074
|
case "tool_search_tool_result": {
|
|
3074
|
-
|
|
3075
|
+
let providerToolName = serverToolCalls[part.tool_use_id];
|
|
3076
|
+
if (providerToolName == null) {
|
|
3077
|
+
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
3078
|
+
"tool_search_tool_bm25"
|
|
3079
|
+
);
|
|
3080
|
+
const regexCustomName = toolNameMapping.toCustomToolName(
|
|
3081
|
+
"tool_search_tool_regex"
|
|
3082
|
+
);
|
|
3083
|
+
if (bm25CustomName !== "tool_search_tool_bm25") {
|
|
3084
|
+
providerToolName = "tool_search_tool_bm25";
|
|
3085
|
+
} else if (regexCustomName !== "tool_search_tool_regex") {
|
|
3086
|
+
providerToolName = "tool_search_tool_regex";
|
|
3087
|
+
} else {
|
|
3088
|
+
providerToolName = "tool_search_tool_regex";
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3075
3091
|
if (part.content.type === "tool_search_tool_search_result") {
|
|
3076
3092
|
content.push({
|
|
3077
3093
|
type: "tool-result",
|
|
@@ -3105,13 +3121,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3105
3121
|
finishReason: response.stop_reason,
|
|
3106
3122
|
isJsonResponseFromTool
|
|
3107
3123
|
}),
|
|
3108
|
-
raw: (
|
|
3124
|
+
raw: (_d = response.stop_reason) != null ? _d : void 0
|
|
3109
3125
|
},
|
|
3110
3126
|
usage: convertAnthropicMessagesUsage(response.usage),
|
|
3111
3127
|
request: { body: args },
|
|
3112
3128
|
response: {
|
|
3113
|
-
id: (
|
|
3114
|
-
modelId: (
|
|
3129
|
+
id: (_e = response.id) != null ? _e : void 0,
|
|
3130
|
+
modelId: (_f = response.model) != null ? _f : void 0,
|
|
3115
3131
|
headers: responseHeaders,
|
|
3116
3132
|
body: rawResponse
|
|
3117
3133
|
},
|
|
@@ -3119,20 +3135,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3119
3135
|
providerMetadata: {
|
|
3120
3136
|
anthropic: {
|
|
3121
3137
|
usage: response.usage,
|
|
3122
|
-
cacheCreationInputTokens: (
|
|
3123
|
-
stopSequence: (
|
|
3138
|
+
cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
|
|
3139
|
+
stopSequence: (_h = response.stop_sequence) != null ? _h : null,
|
|
3124
3140
|
container: response.container ? {
|
|
3125
3141
|
expiresAt: response.container.expires_at,
|
|
3126
3142
|
id: response.container.id,
|
|
3127
|
-
skills: (
|
|
3143
|
+
skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
|
|
3128
3144
|
type: skill.type,
|
|
3129
3145
|
skillId: skill.skill_id,
|
|
3130
3146
|
version: skill.version
|
|
3131
|
-
}))) != null ?
|
|
3147
|
+
}))) != null ? _j : null
|
|
3132
3148
|
} : null,
|
|
3133
|
-
contextManagement: (
|
|
3149
|
+
contextManagement: (_k = mapAnthropicResponseContextManagement(
|
|
3134
3150
|
response.context_management
|
|
3135
|
-
)) != null ?
|
|
3151
|
+
)) != null ? _k : null
|
|
3136
3152
|
}
|
|
3137
3153
|
}
|
|
3138
3154
|
};
|
|
@@ -3192,7 +3208,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3192
3208
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3193
3209
|
},
|
|
3194
3210
|
transform(chunk, controller) {
|
|
3195
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m
|
|
3211
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
3196
3212
|
if (options.includeRawChunks) {
|
|
3197
3213
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3198
3214
|
}
|
|
@@ -3453,7 +3469,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3453
3469
|
}
|
|
3454
3470
|
// tool search tool results:
|
|
3455
3471
|
case "tool_search_tool_result": {
|
|
3456
|
-
|
|
3472
|
+
let providerToolName = serverToolCalls[part.tool_use_id];
|
|
3473
|
+
if (providerToolName == null) {
|
|
3474
|
+
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
3475
|
+
"tool_search_tool_bm25"
|
|
3476
|
+
);
|
|
3477
|
+
const regexCustomName = toolNameMapping.toCustomToolName(
|
|
3478
|
+
"tool_search_tool_regex"
|
|
3479
|
+
);
|
|
3480
|
+
if (bm25CustomName !== "tool_search_tool_bm25") {
|
|
3481
|
+
providerToolName = "tool_search_tool_bm25";
|
|
3482
|
+
} else if (regexCustomName !== "tool_search_tool_regex") {
|
|
3483
|
+
providerToolName = "tool_search_tool_regex";
|
|
3484
|
+
} else {
|
|
3485
|
+
providerToolName = "tool_search_tool_regex";
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3457
3488
|
if (part.content.type === "tool_search_tool_search_result") {
|
|
3458
3489
|
controller.enqueue({
|
|
3459
3490
|
type: "tool-result",
|
|
@@ -3667,12 +3698,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3667
3698
|
}
|
|
3668
3699
|
case "message_start": {
|
|
3669
3700
|
usage.input_tokens = value.message.usage.input_tokens;
|
|
3670
|
-
usage.cache_read_input_tokens = (
|
|
3671
|
-
usage.cache_creation_input_tokens = (
|
|
3701
|
+
usage.cache_read_input_tokens = (_d = value.message.usage.cache_read_input_tokens) != null ? _d : 0;
|
|
3702
|
+
usage.cache_creation_input_tokens = (_e = value.message.usage.cache_creation_input_tokens) != null ? _e : 0;
|
|
3672
3703
|
rawUsage = {
|
|
3673
3704
|
...value.message.usage
|
|
3674
3705
|
};
|
|
3675
|
-
cacheCreationInputTokens = (
|
|
3706
|
+
cacheCreationInputTokens = (_f = value.message.usage.cache_creation_input_tokens) != null ? _f : null;
|
|
3676
3707
|
if (value.message.container != null) {
|
|
3677
3708
|
container = {
|
|
3678
3709
|
expiresAt: value.message.container.expires_at,
|
|
@@ -3691,8 +3722,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3691
3722
|
}
|
|
3692
3723
|
controller.enqueue({
|
|
3693
3724
|
type: "response-metadata",
|
|
3694
|
-
id: (
|
|
3695
|
-
modelId: (
|
|
3725
|
+
id: (_g = value.message.id) != null ? _g : void 0,
|
|
3726
|
+
modelId: (_h = value.message.model) != null ? _h : void 0
|
|
3696
3727
|
});
|
|
3697
3728
|
if (value.message.content != null) {
|
|
3698
3729
|
for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
|
|
@@ -3708,7 +3739,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3708
3739
|
id: part.id,
|
|
3709
3740
|
toolName: part.name
|
|
3710
3741
|
});
|
|
3711
|
-
const inputStr = JSON.stringify((
|
|
3742
|
+
const inputStr = JSON.stringify((_i = part.input) != null ? _i : {});
|
|
3712
3743
|
controller.enqueue({
|
|
3713
3744
|
type: "tool-input-delta",
|
|
3714
3745
|
id: part.id,
|
|
@@ -3746,17 +3777,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3746
3777
|
finishReason: value.delta.stop_reason,
|
|
3747
3778
|
isJsonResponseFromTool
|
|
3748
3779
|
}),
|
|
3749
|
-
raw: (
|
|
3780
|
+
raw: (_j = value.delta.stop_reason) != null ? _j : void 0
|
|
3750
3781
|
};
|
|
3751
|
-
stopSequence = (
|
|
3782
|
+
stopSequence = (_k = value.delta.stop_sequence) != null ? _k : null;
|
|
3752
3783
|
container = value.delta.container != null ? {
|
|
3753
3784
|
expiresAt: value.delta.container.expires_at,
|
|
3754
3785
|
id: value.delta.container.id,
|
|
3755
|
-
skills: (
|
|
3786
|
+
skills: (_m = (_l = value.delta.container.skills) == null ? void 0 : _l.map((skill) => ({
|
|
3756
3787
|
type: skill.type,
|
|
3757
3788
|
skillId: skill.skill_id,
|
|
3758
3789
|
version: skill.version
|
|
3759
|
-
}))) != null ?
|
|
3790
|
+
}))) != null ? _m : null
|
|
3760
3791
|
} : null;
|
|
3761
3792
|
if (value.delta.context_management) {
|
|
3762
3793
|
contextManagement = mapAnthropicResponseContextManagement(
|
|
@@ -4170,7 +4201,8 @@ var toolSearchBm25_20251119InputSchema = lazySchema17(
|
|
|
4170
4201
|
var factory7 = createProviderToolFactoryWithOutputSchema6({
|
|
4171
4202
|
id: "anthropic.tool_search_bm25_20251119",
|
|
4172
4203
|
inputSchema: toolSearchBm25_20251119InputSchema,
|
|
4173
|
-
outputSchema: toolSearchBm25_20251119OutputSchema
|
|
4204
|
+
outputSchema: toolSearchBm25_20251119OutputSchema,
|
|
4205
|
+
supportsDeferredResults: true
|
|
4174
4206
|
});
|
|
4175
4207
|
var toolSearchBm25_20251119 = (args = {}) => {
|
|
4176
4208
|
return factory7(args);
|