@ai-sdk/anthropic 3.0.20 → 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 +6 -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/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/tool/tool-search-bm25_20251119.ts +1 -0
- package/src/tool/tool-search-regex_20251119.ts +1 -0
package/dist/internal/index.mjs
CHANGED
|
@@ -1535,7 +1535,8 @@ var toolSearchRegex_20251119InputSchema = lazySchema8(
|
|
|
1535
1535
|
var factory6 = createProviderToolFactoryWithOutputSchema5({
|
|
1536
1536
|
id: "anthropic.tool_search_regex_20251119",
|
|
1537
1537
|
inputSchema: toolSearchRegex_20251119InputSchema,
|
|
1538
|
-
outputSchema: toolSearchRegex_20251119OutputSchema
|
|
1538
|
+
outputSchema: toolSearchRegex_20251119OutputSchema,
|
|
1539
|
+
supportsDeferredResults: true
|
|
1539
1540
|
});
|
|
1540
1541
|
var toolSearchRegex_20251119 = (args = {}) => {
|
|
1541
1542
|
return factory6(args);
|
|
@@ -2767,7 +2768,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2767
2768
|
});
|
|
2768
2769
|
}
|
|
2769
2770
|
async doGenerate(options) {
|
|
2770
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k
|
|
2771
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2771
2772
|
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
|
|
2772
2773
|
...options,
|
|
2773
2774
|
stream: false,
|
|
@@ -3056,7 +3057,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3056
3057
|
}
|
|
3057
3058
|
// tool search tool results:
|
|
3058
3059
|
case "tool_search_tool_result": {
|
|
3059
|
-
|
|
3060
|
+
let providerToolName = serverToolCalls[part.tool_use_id];
|
|
3061
|
+
if (providerToolName == null) {
|
|
3062
|
+
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
3063
|
+
"tool_search_tool_bm25"
|
|
3064
|
+
);
|
|
3065
|
+
const regexCustomName = toolNameMapping.toCustomToolName(
|
|
3066
|
+
"tool_search_tool_regex"
|
|
3067
|
+
);
|
|
3068
|
+
if (bm25CustomName !== "tool_search_tool_bm25") {
|
|
3069
|
+
providerToolName = "tool_search_tool_bm25";
|
|
3070
|
+
} else if (regexCustomName !== "tool_search_tool_regex") {
|
|
3071
|
+
providerToolName = "tool_search_tool_regex";
|
|
3072
|
+
} else {
|
|
3073
|
+
providerToolName = "tool_search_tool_regex";
|
|
3074
|
+
}
|
|
3075
|
+
}
|
|
3060
3076
|
if (part.content.type === "tool_search_tool_search_result") {
|
|
3061
3077
|
content.push({
|
|
3062
3078
|
type: "tool-result",
|
|
@@ -3090,13 +3106,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3090
3106
|
finishReason: response.stop_reason,
|
|
3091
3107
|
isJsonResponseFromTool
|
|
3092
3108
|
}),
|
|
3093
|
-
raw: (
|
|
3109
|
+
raw: (_d = response.stop_reason) != null ? _d : void 0
|
|
3094
3110
|
},
|
|
3095
3111
|
usage: convertAnthropicMessagesUsage(response.usage),
|
|
3096
3112
|
request: { body: args },
|
|
3097
3113
|
response: {
|
|
3098
|
-
id: (
|
|
3099
|
-
modelId: (
|
|
3114
|
+
id: (_e = response.id) != null ? _e : void 0,
|
|
3115
|
+
modelId: (_f = response.model) != null ? _f : void 0,
|
|
3100
3116
|
headers: responseHeaders,
|
|
3101
3117
|
body: rawResponse
|
|
3102
3118
|
},
|
|
@@ -3104,20 +3120,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3104
3120
|
providerMetadata: {
|
|
3105
3121
|
anthropic: {
|
|
3106
3122
|
usage: response.usage,
|
|
3107
|
-
cacheCreationInputTokens: (
|
|
3108
|
-
stopSequence: (
|
|
3123
|
+
cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
|
|
3124
|
+
stopSequence: (_h = response.stop_sequence) != null ? _h : null,
|
|
3109
3125
|
container: response.container ? {
|
|
3110
3126
|
expiresAt: response.container.expires_at,
|
|
3111
3127
|
id: response.container.id,
|
|
3112
|
-
skills: (
|
|
3128
|
+
skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
|
|
3113
3129
|
type: skill.type,
|
|
3114
3130
|
skillId: skill.skill_id,
|
|
3115
3131
|
version: skill.version
|
|
3116
|
-
}))) != null ?
|
|
3132
|
+
}))) != null ? _j : null
|
|
3117
3133
|
} : null,
|
|
3118
|
-
contextManagement: (
|
|
3134
|
+
contextManagement: (_k = mapAnthropicResponseContextManagement(
|
|
3119
3135
|
response.context_management
|
|
3120
|
-
)) != null ?
|
|
3136
|
+
)) != null ? _k : null
|
|
3121
3137
|
}
|
|
3122
3138
|
}
|
|
3123
3139
|
};
|
|
@@ -3177,7 +3193,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3177
3193
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3178
3194
|
},
|
|
3179
3195
|
transform(chunk, controller) {
|
|
3180
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m
|
|
3196
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
3181
3197
|
if (options.includeRawChunks) {
|
|
3182
3198
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3183
3199
|
}
|
|
@@ -3438,7 +3454,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3438
3454
|
}
|
|
3439
3455
|
// tool search tool results:
|
|
3440
3456
|
case "tool_search_tool_result": {
|
|
3441
|
-
|
|
3457
|
+
let providerToolName = serverToolCalls[part.tool_use_id];
|
|
3458
|
+
if (providerToolName == null) {
|
|
3459
|
+
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
3460
|
+
"tool_search_tool_bm25"
|
|
3461
|
+
);
|
|
3462
|
+
const regexCustomName = toolNameMapping.toCustomToolName(
|
|
3463
|
+
"tool_search_tool_regex"
|
|
3464
|
+
);
|
|
3465
|
+
if (bm25CustomName !== "tool_search_tool_bm25") {
|
|
3466
|
+
providerToolName = "tool_search_tool_bm25";
|
|
3467
|
+
} else if (regexCustomName !== "tool_search_tool_regex") {
|
|
3468
|
+
providerToolName = "tool_search_tool_regex";
|
|
3469
|
+
} else {
|
|
3470
|
+
providerToolName = "tool_search_tool_regex";
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3442
3473
|
if (part.content.type === "tool_search_tool_search_result") {
|
|
3443
3474
|
controller.enqueue({
|
|
3444
3475
|
type: "tool-result",
|
|
@@ -3652,12 +3683,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3652
3683
|
}
|
|
3653
3684
|
case "message_start": {
|
|
3654
3685
|
usage.input_tokens = value.message.usage.input_tokens;
|
|
3655
|
-
usage.cache_read_input_tokens = (
|
|
3656
|
-
usage.cache_creation_input_tokens = (
|
|
3686
|
+
usage.cache_read_input_tokens = (_d = value.message.usage.cache_read_input_tokens) != null ? _d : 0;
|
|
3687
|
+
usage.cache_creation_input_tokens = (_e = value.message.usage.cache_creation_input_tokens) != null ? _e : 0;
|
|
3657
3688
|
rawUsage = {
|
|
3658
3689
|
...value.message.usage
|
|
3659
3690
|
};
|
|
3660
|
-
cacheCreationInputTokens = (
|
|
3691
|
+
cacheCreationInputTokens = (_f = value.message.usage.cache_creation_input_tokens) != null ? _f : null;
|
|
3661
3692
|
if (value.message.container != null) {
|
|
3662
3693
|
container = {
|
|
3663
3694
|
expiresAt: value.message.container.expires_at,
|
|
@@ -3676,8 +3707,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3676
3707
|
}
|
|
3677
3708
|
controller.enqueue({
|
|
3678
3709
|
type: "response-metadata",
|
|
3679
|
-
id: (
|
|
3680
|
-
modelId: (
|
|
3710
|
+
id: (_g = value.message.id) != null ? _g : void 0,
|
|
3711
|
+
modelId: (_h = value.message.model) != null ? _h : void 0
|
|
3681
3712
|
});
|
|
3682
3713
|
if (value.message.content != null) {
|
|
3683
3714
|
for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
|
|
@@ -3693,7 +3724,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3693
3724
|
id: part.id,
|
|
3694
3725
|
toolName: part.name
|
|
3695
3726
|
});
|
|
3696
|
-
const inputStr = JSON.stringify((
|
|
3727
|
+
const inputStr = JSON.stringify((_i = part.input) != null ? _i : {});
|
|
3697
3728
|
controller.enqueue({
|
|
3698
3729
|
type: "tool-input-delta",
|
|
3699
3730
|
id: part.id,
|
|
@@ -3731,17 +3762,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3731
3762
|
finishReason: value.delta.stop_reason,
|
|
3732
3763
|
isJsonResponseFromTool
|
|
3733
3764
|
}),
|
|
3734
|
-
raw: (
|
|
3765
|
+
raw: (_j = value.delta.stop_reason) != null ? _j : void 0
|
|
3735
3766
|
};
|
|
3736
|
-
stopSequence = (
|
|
3767
|
+
stopSequence = (_k = value.delta.stop_sequence) != null ? _k : null;
|
|
3737
3768
|
container = value.delta.container != null ? {
|
|
3738
3769
|
expiresAt: value.delta.container.expires_at,
|
|
3739
3770
|
id: value.delta.container.id,
|
|
3740
|
-
skills: (
|
|
3771
|
+
skills: (_m = (_l = value.delta.container.skills) == null ? void 0 : _l.map((skill) => ({
|
|
3741
3772
|
type: skill.type,
|
|
3742
3773
|
skillId: skill.skill_id,
|
|
3743
3774
|
version: skill.version
|
|
3744
|
-
}))) != null ?
|
|
3775
|
+
}))) != null ? _m : null
|
|
3745
3776
|
} : null;
|
|
3746
3777
|
if (value.delta.context_management) {
|
|
3747
3778
|
contextManagement = mapAnthropicResponseContextManagement(
|
|
@@ -4155,7 +4186,8 @@ var toolSearchBm25_20251119InputSchema = lazySchema17(
|
|
|
4155
4186
|
var factory7 = createProviderToolFactoryWithOutputSchema6({
|
|
4156
4187
|
id: "anthropic.tool_search_bm25_20251119",
|
|
4157
4188
|
inputSchema: toolSearchBm25_20251119InputSchema,
|
|
4158
|
-
outputSchema: toolSearchBm25_20251119OutputSchema
|
|
4189
|
+
outputSchema: toolSearchBm25_20251119OutputSchema,
|
|
4190
|
+
supportsDeferredResults: true
|
|
4159
4191
|
});
|
|
4160
4192
|
var toolSearchBm25_20251119 = (args = {}) => {
|
|
4161
4193
|
return factory7(args);
|