@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/internal/index.js
CHANGED
|
@@ -1519,7 +1519,8 @@ var toolSearchRegex_20251119InputSchema = (0, import_provider_utils10.lazySchema
|
|
|
1519
1519
|
var factory6 = (0, import_provider_utils10.createProviderToolFactoryWithOutputSchema)({
|
|
1520
1520
|
id: "anthropic.tool_search_regex_20251119",
|
|
1521
1521
|
inputSchema: toolSearchRegex_20251119InputSchema,
|
|
1522
|
-
outputSchema: toolSearchRegex_20251119OutputSchema
|
|
1522
|
+
outputSchema: toolSearchRegex_20251119OutputSchema,
|
|
1523
|
+
supportsDeferredResults: true
|
|
1523
1524
|
});
|
|
1524
1525
|
var toolSearchRegex_20251119 = (args = {}) => {
|
|
1525
1526
|
return factory6(args);
|
|
@@ -2751,7 +2752,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2751
2752
|
});
|
|
2752
2753
|
}
|
|
2753
2754
|
async doGenerate(options) {
|
|
2754
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k
|
|
2755
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2755
2756
|
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
|
|
2756
2757
|
...options,
|
|
2757
2758
|
stream: false,
|
|
@@ -3040,7 +3041,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3040
3041
|
}
|
|
3041
3042
|
// tool search tool results:
|
|
3042
3043
|
case "tool_search_tool_result": {
|
|
3043
|
-
|
|
3044
|
+
let providerToolName = serverToolCalls[part.tool_use_id];
|
|
3045
|
+
if (providerToolName == null) {
|
|
3046
|
+
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
3047
|
+
"tool_search_tool_bm25"
|
|
3048
|
+
);
|
|
3049
|
+
const regexCustomName = toolNameMapping.toCustomToolName(
|
|
3050
|
+
"tool_search_tool_regex"
|
|
3051
|
+
);
|
|
3052
|
+
if (bm25CustomName !== "tool_search_tool_bm25") {
|
|
3053
|
+
providerToolName = "tool_search_tool_bm25";
|
|
3054
|
+
} else if (regexCustomName !== "tool_search_tool_regex") {
|
|
3055
|
+
providerToolName = "tool_search_tool_regex";
|
|
3056
|
+
} else {
|
|
3057
|
+
providerToolName = "tool_search_tool_regex";
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3044
3060
|
if (part.content.type === "tool_search_tool_search_result") {
|
|
3045
3061
|
content.push({
|
|
3046
3062
|
type: "tool-result",
|
|
@@ -3074,13 +3090,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3074
3090
|
finishReason: response.stop_reason,
|
|
3075
3091
|
isJsonResponseFromTool
|
|
3076
3092
|
}),
|
|
3077
|
-
raw: (
|
|
3093
|
+
raw: (_d = response.stop_reason) != null ? _d : void 0
|
|
3078
3094
|
},
|
|
3079
3095
|
usage: convertAnthropicMessagesUsage(response.usage),
|
|
3080
3096
|
request: { body: args },
|
|
3081
3097
|
response: {
|
|
3082
|
-
id: (
|
|
3083
|
-
modelId: (
|
|
3098
|
+
id: (_e = response.id) != null ? _e : void 0,
|
|
3099
|
+
modelId: (_f = response.model) != null ? _f : void 0,
|
|
3084
3100
|
headers: responseHeaders,
|
|
3085
3101
|
body: rawResponse
|
|
3086
3102
|
},
|
|
@@ -3088,20 +3104,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3088
3104
|
providerMetadata: {
|
|
3089
3105
|
anthropic: {
|
|
3090
3106
|
usage: response.usage,
|
|
3091
|
-
cacheCreationInputTokens: (
|
|
3092
|
-
stopSequence: (
|
|
3107
|
+
cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
|
|
3108
|
+
stopSequence: (_h = response.stop_sequence) != null ? _h : null,
|
|
3093
3109
|
container: response.container ? {
|
|
3094
3110
|
expiresAt: response.container.expires_at,
|
|
3095
3111
|
id: response.container.id,
|
|
3096
|
-
skills: (
|
|
3112
|
+
skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
|
|
3097
3113
|
type: skill.type,
|
|
3098
3114
|
skillId: skill.skill_id,
|
|
3099
3115
|
version: skill.version
|
|
3100
|
-
}))) != null ?
|
|
3116
|
+
}))) != null ? _j : null
|
|
3101
3117
|
} : null,
|
|
3102
|
-
contextManagement: (
|
|
3118
|
+
contextManagement: (_k = mapAnthropicResponseContextManagement(
|
|
3103
3119
|
response.context_management
|
|
3104
|
-
)) != null ?
|
|
3120
|
+
)) != null ? _k : null
|
|
3105
3121
|
}
|
|
3106
3122
|
}
|
|
3107
3123
|
};
|
|
@@ -3161,7 +3177,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3161
3177
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3162
3178
|
},
|
|
3163
3179
|
transform(chunk, controller) {
|
|
3164
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m
|
|
3180
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
3165
3181
|
if (options.includeRawChunks) {
|
|
3166
3182
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3167
3183
|
}
|
|
@@ -3422,7 +3438,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3422
3438
|
}
|
|
3423
3439
|
// tool search tool results:
|
|
3424
3440
|
case "tool_search_tool_result": {
|
|
3425
|
-
|
|
3441
|
+
let providerToolName = serverToolCalls[part.tool_use_id];
|
|
3442
|
+
if (providerToolName == null) {
|
|
3443
|
+
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
3444
|
+
"tool_search_tool_bm25"
|
|
3445
|
+
);
|
|
3446
|
+
const regexCustomName = toolNameMapping.toCustomToolName(
|
|
3447
|
+
"tool_search_tool_regex"
|
|
3448
|
+
);
|
|
3449
|
+
if (bm25CustomName !== "tool_search_tool_bm25") {
|
|
3450
|
+
providerToolName = "tool_search_tool_bm25";
|
|
3451
|
+
} else if (regexCustomName !== "tool_search_tool_regex") {
|
|
3452
|
+
providerToolName = "tool_search_tool_regex";
|
|
3453
|
+
} else {
|
|
3454
|
+
providerToolName = "tool_search_tool_regex";
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3426
3457
|
if (part.content.type === "tool_search_tool_search_result") {
|
|
3427
3458
|
controller.enqueue({
|
|
3428
3459
|
type: "tool-result",
|
|
@@ -3636,12 +3667,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3636
3667
|
}
|
|
3637
3668
|
case "message_start": {
|
|
3638
3669
|
usage.input_tokens = value.message.usage.input_tokens;
|
|
3639
|
-
usage.cache_read_input_tokens = (
|
|
3640
|
-
usage.cache_creation_input_tokens = (
|
|
3670
|
+
usage.cache_read_input_tokens = (_d = value.message.usage.cache_read_input_tokens) != null ? _d : 0;
|
|
3671
|
+
usage.cache_creation_input_tokens = (_e = value.message.usage.cache_creation_input_tokens) != null ? _e : 0;
|
|
3641
3672
|
rawUsage = {
|
|
3642
3673
|
...value.message.usage
|
|
3643
3674
|
};
|
|
3644
|
-
cacheCreationInputTokens = (
|
|
3675
|
+
cacheCreationInputTokens = (_f = value.message.usage.cache_creation_input_tokens) != null ? _f : null;
|
|
3645
3676
|
if (value.message.container != null) {
|
|
3646
3677
|
container = {
|
|
3647
3678
|
expiresAt: value.message.container.expires_at,
|
|
@@ -3660,8 +3691,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3660
3691
|
}
|
|
3661
3692
|
controller.enqueue({
|
|
3662
3693
|
type: "response-metadata",
|
|
3663
|
-
id: (
|
|
3664
|
-
modelId: (
|
|
3694
|
+
id: (_g = value.message.id) != null ? _g : void 0,
|
|
3695
|
+
modelId: (_h = value.message.model) != null ? _h : void 0
|
|
3665
3696
|
});
|
|
3666
3697
|
if (value.message.content != null) {
|
|
3667
3698
|
for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
|
|
@@ -3677,7 +3708,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3677
3708
|
id: part.id,
|
|
3678
3709
|
toolName: part.name
|
|
3679
3710
|
});
|
|
3680
|
-
const inputStr = JSON.stringify((
|
|
3711
|
+
const inputStr = JSON.stringify((_i = part.input) != null ? _i : {});
|
|
3681
3712
|
controller.enqueue({
|
|
3682
3713
|
type: "tool-input-delta",
|
|
3683
3714
|
id: part.id,
|
|
@@ -3715,17 +3746,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3715
3746
|
finishReason: value.delta.stop_reason,
|
|
3716
3747
|
isJsonResponseFromTool
|
|
3717
3748
|
}),
|
|
3718
|
-
raw: (
|
|
3749
|
+
raw: (_j = value.delta.stop_reason) != null ? _j : void 0
|
|
3719
3750
|
};
|
|
3720
|
-
stopSequence = (
|
|
3751
|
+
stopSequence = (_k = value.delta.stop_sequence) != null ? _k : null;
|
|
3721
3752
|
container = value.delta.container != null ? {
|
|
3722
3753
|
expiresAt: value.delta.container.expires_at,
|
|
3723
3754
|
id: value.delta.container.id,
|
|
3724
|
-
skills: (
|
|
3755
|
+
skills: (_m = (_l = value.delta.container.skills) == null ? void 0 : _l.map((skill) => ({
|
|
3725
3756
|
type: skill.type,
|
|
3726
3757
|
skillId: skill.skill_id,
|
|
3727
3758
|
version: skill.version
|
|
3728
|
-
}))) != null ?
|
|
3759
|
+
}))) != null ? _m : null
|
|
3729
3760
|
} : null;
|
|
3730
3761
|
if (value.delta.context_management) {
|
|
3731
3762
|
contextManagement = mapAnthropicResponseContextManagement(
|
|
@@ -4103,7 +4134,8 @@ var toolSearchBm25_20251119InputSchema = (0, import_provider_utils21.lazySchema)
|
|
|
4103
4134
|
var factory7 = (0, import_provider_utils21.createProviderToolFactoryWithOutputSchema)({
|
|
4104
4135
|
id: "anthropic.tool_search_bm25_20251119",
|
|
4105
4136
|
inputSchema: toolSearchBm25_20251119InputSchema,
|
|
4106
|
-
outputSchema: toolSearchBm25_20251119OutputSchema
|
|
4137
|
+
outputSchema: toolSearchBm25_20251119OutputSchema,
|
|
4138
|
+
supportsDeferredResults: true
|
|
4107
4139
|
});
|
|
4108
4140
|
var toolSearchBm25_20251119 = (args = {}) => {
|
|
4109
4141
|
return factory7(args);
|