@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 3.0.21
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 662d359: feat(anthropic): deferred results for tool search tool
|
|
8
|
+
|
|
9
|
+
## 3.0.20
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 2b8369d: chore: add docs to package dist
|
|
14
|
+
|
|
3
15
|
## 3.0.19
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
32
32
|
var import_provider_utils22 = require("@ai-sdk/provider-utils");
|
|
33
33
|
|
|
34
34
|
// src/version.ts
|
|
35
|
-
var VERSION = true ? "3.0.
|
|
35
|
+
var VERSION = true ? "3.0.21" : "0.0.0-test";
|
|
36
36
|
|
|
37
37
|
// src/anthropic-messages-language-model.ts
|
|
38
38
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -1527,7 +1527,8 @@ var toolSearchRegex_20251119InputSchema = (0, import_provider_utils10.lazySchema
|
|
|
1527
1527
|
var factory6 = (0, import_provider_utils10.createProviderToolFactoryWithOutputSchema)({
|
|
1528
1528
|
id: "anthropic.tool_search_regex_20251119",
|
|
1529
1529
|
inputSchema: toolSearchRegex_20251119InputSchema,
|
|
1530
|
-
outputSchema: toolSearchRegex_20251119OutputSchema
|
|
1530
|
+
outputSchema: toolSearchRegex_20251119OutputSchema,
|
|
1531
|
+
supportsDeferredResults: true
|
|
1531
1532
|
});
|
|
1532
1533
|
var toolSearchRegex_20251119 = (args = {}) => {
|
|
1533
1534
|
return factory6(args);
|
|
@@ -2759,7 +2760,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2759
2760
|
});
|
|
2760
2761
|
}
|
|
2761
2762
|
async doGenerate(options) {
|
|
2762
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k
|
|
2763
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2763
2764
|
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
|
|
2764
2765
|
...options,
|
|
2765
2766
|
stream: false,
|
|
@@ -3048,7 +3049,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3048
3049
|
}
|
|
3049
3050
|
// tool search tool results:
|
|
3050
3051
|
case "tool_search_tool_result": {
|
|
3051
|
-
|
|
3052
|
+
let providerToolName = serverToolCalls[part.tool_use_id];
|
|
3053
|
+
if (providerToolName == null) {
|
|
3054
|
+
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
3055
|
+
"tool_search_tool_bm25"
|
|
3056
|
+
);
|
|
3057
|
+
const regexCustomName = toolNameMapping.toCustomToolName(
|
|
3058
|
+
"tool_search_tool_regex"
|
|
3059
|
+
);
|
|
3060
|
+
if (bm25CustomName !== "tool_search_tool_bm25") {
|
|
3061
|
+
providerToolName = "tool_search_tool_bm25";
|
|
3062
|
+
} else if (regexCustomName !== "tool_search_tool_regex") {
|
|
3063
|
+
providerToolName = "tool_search_tool_regex";
|
|
3064
|
+
} else {
|
|
3065
|
+
providerToolName = "tool_search_tool_regex";
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3052
3068
|
if (part.content.type === "tool_search_tool_search_result") {
|
|
3053
3069
|
content.push({
|
|
3054
3070
|
type: "tool-result",
|
|
@@ -3082,13 +3098,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3082
3098
|
finishReason: response.stop_reason,
|
|
3083
3099
|
isJsonResponseFromTool
|
|
3084
3100
|
}),
|
|
3085
|
-
raw: (
|
|
3101
|
+
raw: (_d = response.stop_reason) != null ? _d : void 0
|
|
3086
3102
|
},
|
|
3087
3103
|
usage: convertAnthropicMessagesUsage(response.usage),
|
|
3088
3104
|
request: { body: args },
|
|
3089
3105
|
response: {
|
|
3090
|
-
id: (
|
|
3091
|
-
modelId: (
|
|
3106
|
+
id: (_e = response.id) != null ? _e : void 0,
|
|
3107
|
+
modelId: (_f = response.model) != null ? _f : void 0,
|
|
3092
3108
|
headers: responseHeaders,
|
|
3093
3109
|
body: rawResponse
|
|
3094
3110
|
},
|
|
@@ -3096,20 +3112,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3096
3112
|
providerMetadata: {
|
|
3097
3113
|
anthropic: {
|
|
3098
3114
|
usage: response.usage,
|
|
3099
|
-
cacheCreationInputTokens: (
|
|
3100
|
-
stopSequence: (
|
|
3115
|
+
cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
|
|
3116
|
+
stopSequence: (_h = response.stop_sequence) != null ? _h : null,
|
|
3101
3117
|
container: response.container ? {
|
|
3102
3118
|
expiresAt: response.container.expires_at,
|
|
3103
3119
|
id: response.container.id,
|
|
3104
|
-
skills: (
|
|
3120
|
+
skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
|
|
3105
3121
|
type: skill.type,
|
|
3106
3122
|
skillId: skill.skill_id,
|
|
3107
3123
|
version: skill.version
|
|
3108
|
-
}))) != null ?
|
|
3124
|
+
}))) != null ? _j : null
|
|
3109
3125
|
} : null,
|
|
3110
|
-
contextManagement: (
|
|
3126
|
+
contextManagement: (_k = mapAnthropicResponseContextManagement(
|
|
3111
3127
|
response.context_management
|
|
3112
|
-
)) != null ?
|
|
3128
|
+
)) != null ? _k : null
|
|
3113
3129
|
}
|
|
3114
3130
|
}
|
|
3115
3131
|
};
|
|
@@ -3169,7 +3185,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3169
3185
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3170
3186
|
},
|
|
3171
3187
|
transform(chunk, controller) {
|
|
3172
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m
|
|
3188
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
3173
3189
|
if (options.includeRawChunks) {
|
|
3174
3190
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3175
3191
|
}
|
|
@@ -3430,7 +3446,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3430
3446
|
}
|
|
3431
3447
|
// tool search tool results:
|
|
3432
3448
|
case "tool_search_tool_result": {
|
|
3433
|
-
|
|
3449
|
+
let providerToolName = serverToolCalls[part.tool_use_id];
|
|
3450
|
+
if (providerToolName == null) {
|
|
3451
|
+
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
3452
|
+
"tool_search_tool_bm25"
|
|
3453
|
+
);
|
|
3454
|
+
const regexCustomName = toolNameMapping.toCustomToolName(
|
|
3455
|
+
"tool_search_tool_regex"
|
|
3456
|
+
);
|
|
3457
|
+
if (bm25CustomName !== "tool_search_tool_bm25") {
|
|
3458
|
+
providerToolName = "tool_search_tool_bm25";
|
|
3459
|
+
} else if (regexCustomName !== "tool_search_tool_regex") {
|
|
3460
|
+
providerToolName = "tool_search_tool_regex";
|
|
3461
|
+
} else {
|
|
3462
|
+
providerToolName = "tool_search_tool_regex";
|
|
3463
|
+
}
|
|
3464
|
+
}
|
|
3434
3465
|
if (part.content.type === "tool_search_tool_search_result") {
|
|
3435
3466
|
controller.enqueue({
|
|
3436
3467
|
type: "tool-result",
|
|
@@ -3644,12 +3675,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3644
3675
|
}
|
|
3645
3676
|
case "message_start": {
|
|
3646
3677
|
usage.input_tokens = value.message.usage.input_tokens;
|
|
3647
|
-
usage.cache_read_input_tokens = (
|
|
3648
|
-
usage.cache_creation_input_tokens = (
|
|
3678
|
+
usage.cache_read_input_tokens = (_d = value.message.usage.cache_read_input_tokens) != null ? _d : 0;
|
|
3679
|
+
usage.cache_creation_input_tokens = (_e = value.message.usage.cache_creation_input_tokens) != null ? _e : 0;
|
|
3649
3680
|
rawUsage = {
|
|
3650
3681
|
...value.message.usage
|
|
3651
3682
|
};
|
|
3652
|
-
cacheCreationInputTokens = (
|
|
3683
|
+
cacheCreationInputTokens = (_f = value.message.usage.cache_creation_input_tokens) != null ? _f : null;
|
|
3653
3684
|
if (value.message.container != null) {
|
|
3654
3685
|
container = {
|
|
3655
3686
|
expiresAt: value.message.container.expires_at,
|
|
@@ -3668,8 +3699,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3668
3699
|
}
|
|
3669
3700
|
controller.enqueue({
|
|
3670
3701
|
type: "response-metadata",
|
|
3671
|
-
id: (
|
|
3672
|
-
modelId: (
|
|
3702
|
+
id: (_g = value.message.id) != null ? _g : void 0,
|
|
3703
|
+
modelId: (_h = value.message.model) != null ? _h : void 0
|
|
3673
3704
|
});
|
|
3674
3705
|
if (value.message.content != null) {
|
|
3675
3706
|
for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
|
|
@@ -3685,7 +3716,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3685
3716
|
id: part.id,
|
|
3686
3717
|
toolName: part.name
|
|
3687
3718
|
});
|
|
3688
|
-
const inputStr = JSON.stringify((
|
|
3719
|
+
const inputStr = JSON.stringify((_i = part.input) != null ? _i : {});
|
|
3689
3720
|
controller.enqueue({
|
|
3690
3721
|
type: "tool-input-delta",
|
|
3691
3722
|
id: part.id,
|
|
@@ -3723,17 +3754,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3723
3754
|
finishReason: value.delta.stop_reason,
|
|
3724
3755
|
isJsonResponseFromTool
|
|
3725
3756
|
}),
|
|
3726
|
-
raw: (
|
|
3757
|
+
raw: (_j = value.delta.stop_reason) != null ? _j : void 0
|
|
3727
3758
|
};
|
|
3728
|
-
stopSequence = (
|
|
3759
|
+
stopSequence = (_k = value.delta.stop_sequence) != null ? _k : null;
|
|
3729
3760
|
container = value.delta.container != null ? {
|
|
3730
3761
|
expiresAt: value.delta.container.expires_at,
|
|
3731
3762
|
id: value.delta.container.id,
|
|
3732
|
-
skills: (
|
|
3763
|
+
skills: (_m = (_l = value.delta.container.skills) == null ? void 0 : _l.map((skill) => ({
|
|
3733
3764
|
type: skill.type,
|
|
3734
3765
|
skillId: skill.skill_id,
|
|
3735
3766
|
version: skill.version
|
|
3736
|
-
}))) != null ?
|
|
3767
|
+
}))) != null ? _m : null
|
|
3737
3768
|
} : null;
|
|
3738
3769
|
if (value.delta.context_management) {
|
|
3739
3770
|
contextManagement = mapAnthropicResponseContextManagement(
|
|
@@ -4111,7 +4142,8 @@ var toolSearchBm25_20251119InputSchema = (0, import_provider_utils21.lazySchema)
|
|
|
4111
4142
|
var factory7 = (0, import_provider_utils21.createProviderToolFactoryWithOutputSchema)({
|
|
4112
4143
|
id: "anthropic.tool_search_bm25_20251119",
|
|
4113
4144
|
inputSchema: toolSearchBm25_20251119InputSchema,
|
|
4114
|
-
outputSchema: toolSearchBm25_20251119OutputSchema
|
|
4145
|
+
outputSchema: toolSearchBm25_20251119OutputSchema,
|
|
4146
|
+
supportsDeferredResults: true
|
|
4115
4147
|
});
|
|
4116
4148
|
var toolSearchBm25_20251119 = (args = {}) => {
|
|
4117
4149
|
return factory7(args);
|