@ai-sdk/anthropic 3.0.17 → 3.0.18
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 +57 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -30
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +56 -29
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +56 -29
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
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.18" : "0.0.0-test";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-messages-language-model.ts
|
|
17
17
|
import {
|
|
@@ -2349,6 +2349,21 @@ function mapAnthropicStopReason({
|
|
|
2349
2349
|
// src/anthropic-messages-language-model.ts
|
|
2350
2350
|
function createCitationSource(citation, citationDocuments, generateId3) {
|
|
2351
2351
|
var _a;
|
|
2352
|
+
if (citation.type === "web_search_result_location") {
|
|
2353
|
+
return {
|
|
2354
|
+
type: "source",
|
|
2355
|
+
sourceType: "url",
|
|
2356
|
+
id: generateId3(),
|
|
2357
|
+
url: citation.url,
|
|
2358
|
+
title: citation.title,
|
|
2359
|
+
providerMetadata: {
|
|
2360
|
+
anthropic: {
|
|
2361
|
+
citedText: citation.cited_text,
|
|
2362
|
+
encryptedIndex: citation.encrypted_index
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
};
|
|
2366
|
+
}
|
|
2352
2367
|
if (citation.type !== "page_location" && citation.type !== "char_location") {
|
|
2353
2368
|
return;
|
|
2354
2369
|
}
|
|
@@ -2767,13 +2782,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2767
2782
|
});
|
|
2768
2783
|
}
|
|
2769
2784
|
async doGenerate(options) {
|
|
2770
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2785
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
2771
2786
|
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
|
|
2772
2787
|
...options,
|
|
2773
2788
|
stream: false,
|
|
2774
2789
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
2775
2790
|
});
|
|
2776
|
-
const citationDocuments =
|
|
2791
|
+
const citationDocuments = [
|
|
2792
|
+
...this.extractCitationDocuments(options.prompt)
|
|
2793
|
+
];
|
|
2777
2794
|
const {
|
|
2778
2795
|
responseHeaders,
|
|
2779
2796
|
value: response,
|
|
@@ -2929,6 +2946,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2929
2946
|
}
|
|
2930
2947
|
case "web_fetch_tool_result": {
|
|
2931
2948
|
if (part.content.type === "web_fetch_result") {
|
|
2949
|
+
citationDocuments.push({
|
|
2950
|
+
title: (_a = part.content.content.title) != null ? _a : part.content.url,
|
|
2951
|
+
mediaType: part.content.content.source.media_type
|
|
2952
|
+
});
|
|
2932
2953
|
content.push({
|
|
2933
2954
|
type: "tool-result",
|
|
2934
2955
|
toolCallId: part.tool_use_id,
|
|
@@ -2989,7 +3010,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2989
3010
|
title: result.title,
|
|
2990
3011
|
providerMetadata: {
|
|
2991
3012
|
anthropic: {
|
|
2992
|
-
pageAge: (
|
|
3013
|
+
pageAge: (_b = result.page_age) != null ? _b : null
|
|
2993
3014
|
}
|
|
2994
3015
|
}
|
|
2995
3016
|
});
|
|
@@ -3020,7 +3041,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3020
3041
|
stdout: part.content.stdout,
|
|
3021
3042
|
stderr: part.content.stderr,
|
|
3022
3043
|
return_code: part.content.return_code,
|
|
3023
|
-
content: (
|
|
3044
|
+
content: (_c = part.content.content) != null ? _c : []
|
|
3024
3045
|
}
|
|
3025
3046
|
});
|
|
3026
3047
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -3050,7 +3071,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3050
3071
|
}
|
|
3051
3072
|
// tool search tool results:
|
|
3052
3073
|
case "tool_search_tool_result": {
|
|
3053
|
-
const providerToolName = (
|
|
3074
|
+
const providerToolName = (_d = serverToolCalls[part.tool_use_id]) != null ? _d : "tool_search_tool_regex";
|
|
3054
3075
|
if (part.content.type === "tool_search_tool_search_result") {
|
|
3055
3076
|
content.push({
|
|
3056
3077
|
type: "tool-result",
|
|
@@ -3084,13 +3105,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3084
3105
|
finishReason: response.stop_reason,
|
|
3085
3106
|
isJsonResponseFromTool
|
|
3086
3107
|
}),
|
|
3087
|
-
raw: (
|
|
3108
|
+
raw: (_e = response.stop_reason) != null ? _e : void 0
|
|
3088
3109
|
},
|
|
3089
3110
|
usage: convertAnthropicMessagesUsage(response.usage),
|
|
3090
3111
|
request: { body: args },
|
|
3091
3112
|
response: {
|
|
3092
|
-
id: (
|
|
3093
|
-
modelId: (
|
|
3113
|
+
id: (_f = response.id) != null ? _f : void 0,
|
|
3114
|
+
modelId: (_g = response.model) != null ? _g : void 0,
|
|
3094
3115
|
headers: responseHeaders,
|
|
3095
3116
|
body: rawResponse
|
|
3096
3117
|
},
|
|
@@ -3098,20 +3119,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3098
3119
|
providerMetadata: {
|
|
3099
3120
|
anthropic: {
|
|
3100
3121
|
usage: response.usage,
|
|
3101
|
-
cacheCreationInputTokens: (
|
|
3102
|
-
stopSequence: (
|
|
3122
|
+
cacheCreationInputTokens: (_h = response.usage.cache_creation_input_tokens) != null ? _h : null,
|
|
3123
|
+
stopSequence: (_i = response.stop_sequence) != null ? _i : null,
|
|
3103
3124
|
container: response.container ? {
|
|
3104
3125
|
expiresAt: response.container.expires_at,
|
|
3105
3126
|
id: response.container.id,
|
|
3106
|
-
skills: (
|
|
3127
|
+
skills: (_k = (_j = response.container.skills) == null ? void 0 : _j.map((skill) => ({
|
|
3107
3128
|
type: skill.type,
|
|
3108
3129
|
skillId: skill.skill_id,
|
|
3109
3130
|
version: skill.version
|
|
3110
|
-
}))) != null ?
|
|
3131
|
+
}))) != null ? _k : null
|
|
3111
3132
|
} : null,
|
|
3112
|
-
contextManagement: (
|
|
3133
|
+
contextManagement: (_l = mapAnthropicResponseContextManagement(
|
|
3113
3134
|
response.context_management
|
|
3114
|
-
)) != null ?
|
|
3135
|
+
)) != null ? _l : null
|
|
3115
3136
|
}
|
|
3116
3137
|
}
|
|
3117
3138
|
};
|
|
@@ -3129,7 +3150,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3129
3150
|
stream: true,
|
|
3130
3151
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
3131
3152
|
});
|
|
3132
|
-
const citationDocuments =
|
|
3153
|
+
const citationDocuments = [
|
|
3154
|
+
...this.extractCitationDocuments(options.prompt)
|
|
3155
|
+
];
|
|
3133
3156
|
const url = this.buildRequestUrl(true);
|
|
3134
3157
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
3135
3158
|
url,
|
|
@@ -3169,7 +3192,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3169
3192
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3170
3193
|
},
|
|
3171
3194
|
transform(chunk, controller) {
|
|
3172
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
3195
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
3173
3196
|
if (options.includeRawChunks) {
|
|
3174
3197
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3175
3198
|
}
|
|
@@ -3305,6 +3328,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3305
3328
|
}
|
|
3306
3329
|
case "web_fetch_tool_result": {
|
|
3307
3330
|
if (part.content.type === "web_fetch_result") {
|
|
3331
|
+
citationDocuments.push({
|
|
3332
|
+
title: (_a2 = part.content.content.title) != null ? _a2 : part.content.url,
|
|
3333
|
+
mediaType: part.content.content.source.media_type
|
|
3334
|
+
});
|
|
3308
3335
|
controller.enqueue({
|
|
3309
3336
|
type: "tool-result",
|
|
3310
3337
|
toolCallId: part.tool_use_id,
|
|
@@ -3365,7 +3392,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3365
3392
|
title: result.title,
|
|
3366
3393
|
providerMetadata: {
|
|
3367
3394
|
anthropic: {
|
|
3368
|
-
pageAge: (
|
|
3395
|
+
pageAge: (_b2 = result.page_age) != null ? _b2 : null
|
|
3369
3396
|
}
|
|
3370
3397
|
}
|
|
3371
3398
|
});
|
|
@@ -3396,7 +3423,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3396
3423
|
stdout: part.content.stdout,
|
|
3397
3424
|
stderr: part.content.stderr,
|
|
3398
3425
|
return_code: part.content.return_code,
|
|
3399
|
-
content: (
|
|
3426
|
+
content: (_c = part.content.content) != null ? _c : []
|
|
3400
3427
|
}
|
|
3401
3428
|
});
|
|
3402
3429
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -3426,7 +3453,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3426
3453
|
}
|
|
3427
3454
|
// tool search tool results:
|
|
3428
3455
|
case "tool_search_tool_result": {
|
|
3429
|
-
const providerToolName = (
|
|
3456
|
+
const providerToolName = (_d = serverToolCalls[part.tool_use_id]) != null ? _d : "tool_search_tool_regex";
|
|
3430
3457
|
if (part.content.type === "tool_search_tool_search_result") {
|
|
3431
3458
|
controller.enqueue({
|
|
3432
3459
|
type: "tool-result",
|
|
@@ -3640,12 +3667,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3640
3667
|
}
|
|
3641
3668
|
case "message_start": {
|
|
3642
3669
|
usage.input_tokens = value.message.usage.input_tokens;
|
|
3643
|
-
usage.cache_read_input_tokens = (
|
|
3644
|
-
usage.cache_creation_input_tokens = (
|
|
3670
|
+
usage.cache_read_input_tokens = (_e = value.message.usage.cache_read_input_tokens) != null ? _e : 0;
|
|
3671
|
+
usage.cache_creation_input_tokens = (_f = value.message.usage.cache_creation_input_tokens) != null ? _f : 0;
|
|
3645
3672
|
rawUsage = {
|
|
3646
3673
|
...value.message.usage
|
|
3647
3674
|
};
|
|
3648
|
-
cacheCreationInputTokens = (
|
|
3675
|
+
cacheCreationInputTokens = (_g = value.message.usage.cache_creation_input_tokens) != null ? _g : null;
|
|
3649
3676
|
if (value.message.container != null) {
|
|
3650
3677
|
container = {
|
|
3651
3678
|
expiresAt: value.message.container.expires_at,
|
|
@@ -3664,8 +3691,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3664
3691
|
}
|
|
3665
3692
|
controller.enqueue({
|
|
3666
3693
|
type: "response-metadata",
|
|
3667
|
-
id: (
|
|
3668
|
-
modelId: (
|
|
3694
|
+
id: (_h = value.message.id) != null ? _h : void 0,
|
|
3695
|
+
modelId: (_i = value.message.model) != null ? _i : void 0
|
|
3669
3696
|
});
|
|
3670
3697
|
if (value.message.content != null) {
|
|
3671
3698
|
for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
|
|
@@ -3681,7 +3708,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3681
3708
|
id: part.id,
|
|
3682
3709
|
toolName: part.name
|
|
3683
3710
|
});
|
|
3684
|
-
const inputStr = JSON.stringify((
|
|
3711
|
+
const inputStr = JSON.stringify((_j = part.input) != null ? _j : {});
|
|
3685
3712
|
controller.enqueue({
|
|
3686
3713
|
type: "tool-input-delta",
|
|
3687
3714
|
id: part.id,
|
|
@@ -3719,17 +3746,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3719
3746
|
finishReason: value.delta.stop_reason,
|
|
3720
3747
|
isJsonResponseFromTool
|
|
3721
3748
|
}),
|
|
3722
|
-
raw: (
|
|
3749
|
+
raw: (_k = value.delta.stop_reason) != null ? _k : void 0
|
|
3723
3750
|
};
|
|
3724
|
-
stopSequence = (
|
|
3751
|
+
stopSequence = (_l = value.delta.stop_sequence) != null ? _l : null;
|
|
3725
3752
|
container = value.delta.container != null ? {
|
|
3726
3753
|
expiresAt: value.delta.container.expires_at,
|
|
3727
3754
|
id: value.delta.container.id,
|
|
3728
|
-
skills: (
|
|
3755
|
+
skills: (_n = (_m = value.delta.container.skills) == null ? void 0 : _m.map((skill) => ({
|
|
3729
3756
|
type: skill.type,
|
|
3730
3757
|
skillId: skill.skill_id,
|
|
3731
3758
|
version: skill.version
|
|
3732
|
-
}))) != null ?
|
|
3759
|
+
}))) != null ? _n : null
|
|
3733
3760
|
} : null;
|
|
3734
3761
|
if (value.delta.context_management) {
|
|
3735
3762
|
contextManagement = mapAnthropicResponseContextManagement(
|