@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/CHANGELOG.md
CHANGED
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.18" : "0.0.0-test";
|
|
36
36
|
|
|
37
37
|
// src/anthropic-messages-language-model.ts
|
|
38
38
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -2326,6 +2326,21 @@ function mapAnthropicStopReason({
|
|
|
2326
2326
|
// src/anthropic-messages-language-model.ts
|
|
2327
2327
|
function createCitationSource(citation, citationDocuments, generateId3) {
|
|
2328
2328
|
var _a;
|
|
2329
|
+
if (citation.type === "web_search_result_location") {
|
|
2330
|
+
return {
|
|
2331
|
+
type: "source",
|
|
2332
|
+
sourceType: "url",
|
|
2333
|
+
id: generateId3(),
|
|
2334
|
+
url: citation.url,
|
|
2335
|
+
title: citation.title,
|
|
2336
|
+
providerMetadata: {
|
|
2337
|
+
anthropic: {
|
|
2338
|
+
citedText: citation.cited_text,
|
|
2339
|
+
encryptedIndex: citation.encrypted_index
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
};
|
|
2343
|
+
}
|
|
2329
2344
|
if (citation.type !== "page_location" && citation.type !== "char_location") {
|
|
2330
2345
|
return;
|
|
2331
2346
|
}
|
|
@@ -2744,13 +2759,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2744
2759
|
});
|
|
2745
2760
|
}
|
|
2746
2761
|
async doGenerate(options) {
|
|
2747
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2762
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
2748
2763
|
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
|
|
2749
2764
|
...options,
|
|
2750
2765
|
stream: false,
|
|
2751
2766
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
2752
2767
|
});
|
|
2753
|
-
const citationDocuments =
|
|
2768
|
+
const citationDocuments = [
|
|
2769
|
+
...this.extractCitationDocuments(options.prompt)
|
|
2770
|
+
];
|
|
2754
2771
|
const {
|
|
2755
2772
|
responseHeaders,
|
|
2756
2773
|
value: response,
|
|
@@ -2906,6 +2923,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2906
2923
|
}
|
|
2907
2924
|
case "web_fetch_tool_result": {
|
|
2908
2925
|
if (part.content.type === "web_fetch_result") {
|
|
2926
|
+
citationDocuments.push({
|
|
2927
|
+
title: (_a = part.content.content.title) != null ? _a : part.content.url,
|
|
2928
|
+
mediaType: part.content.content.source.media_type
|
|
2929
|
+
});
|
|
2909
2930
|
content.push({
|
|
2910
2931
|
type: "tool-result",
|
|
2911
2932
|
toolCallId: part.tool_use_id,
|
|
@@ -2966,7 +2987,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2966
2987
|
title: result.title,
|
|
2967
2988
|
providerMetadata: {
|
|
2968
2989
|
anthropic: {
|
|
2969
|
-
pageAge: (
|
|
2990
|
+
pageAge: (_b = result.page_age) != null ? _b : null
|
|
2970
2991
|
}
|
|
2971
2992
|
}
|
|
2972
2993
|
});
|
|
@@ -2997,7 +3018,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2997
3018
|
stdout: part.content.stdout,
|
|
2998
3019
|
stderr: part.content.stderr,
|
|
2999
3020
|
return_code: part.content.return_code,
|
|
3000
|
-
content: (
|
|
3021
|
+
content: (_c = part.content.content) != null ? _c : []
|
|
3001
3022
|
}
|
|
3002
3023
|
});
|
|
3003
3024
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -3027,7 +3048,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3027
3048
|
}
|
|
3028
3049
|
// tool search tool results:
|
|
3029
3050
|
case "tool_search_tool_result": {
|
|
3030
|
-
const providerToolName = (
|
|
3051
|
+
const providerToolName = (_d = serverToolCalls[part.tool_use_id]) != null ? _d : "tool_search_tool_regex";
|
|
3031
3052
|
if (part.content.type === "tool_search_tool_search_result") {
|
|
3032
3053
|
content.push({
|
|
3033
3054
|
type: "tool-result",
|
|
@@ -3061,13 +3082,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3061
3082
|
finishReason: response.stop_reason,
|
|
3062
3083
|
isJsonResponseFromTool
|
|
3063
3084
|
}),
|
|
3064
|
-
raw: (
|
|
3085
|
+
raw: (_e = response.stop_reason) != null ? _e : void 0
|
|
3065
3086
|
},
|
|
3066
3087
|
usage: convertAnthropicMessagesUsage(response.usage),
|
|
3067
3088
|
request: { body: args },
|
|
3068
3089
|
response: {
|
|
3069
|
-
id: (
|
|
3070
|
-
modelId: (
|
|
3090
|
+
id: (_f = response.id) != null ? _f : void 0,
|
|
3091
|
+
modelId: (_g = response.model) != null ? _g : void 0,
|
|
3071
3092
|
headers: responseHeaders,
|
|
3072
3093
|
body: rawResponse
|
|
3073
3094
|
},
|
|
@@ -3075,20 +3096,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3075
3096
|
providerMetadata: {
|
|
3076
3097
|
anthropic: {
|
|
3077
3098
|
usage: response.usage,
|
|
3078
|
-
cacheCreationInputTokens: (
|
|
3079
|
-
stopSequence: (
|
|
3099
|
+
cacheCreationInputTokens: (_h = response.usage.cache_creation_input_tokens) != null ? _h : null,
|
|
3100
|
+
stopSequence: (_i = response.stop_sequence) != null ? _i : null,
|
|
3080
3101
|
container: response.container ? {
|
|
3081
3102
|
expiresAt: response.container.expires_at,
|
|
3082
3103
|
id: response.container.id,
|
|
3083
|
-
skills: (
|
|
3104
|
+
skills: (_k = (_j = response.container.skills) == null ? void 0 : _j.map((skill) => ({
|
|
3084
3105
|
type: skill.type,
|
|
3085
3106
|
skillId: skill.skill_id,
|
|
3086
3107
|
version: skill.version
|
|
3087
|
-
}))) != null ?
|
|
3108
|
+
}))) != null ? _k : null
|
|
3088
3109
|
} : null,
|
|
3089
|
-
contextManagement: (
|
|
3110
|
+
contextManagement: (_l = mapAnthropicResponseContextManagement(
|
|
3090
3111
|
response.context_management
|
|
3091
|
-
)) != null ?
|
|
3112
|
+
)) != null ? _l : null
|
|
3092
3113
|
}
|
|
3093
3114
|
}
|
|
3094
3115
|
};
|
|
@@ -3106,7 +3127,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3106
3127
|
stream: true,
|
|
3107
3128
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
3108
3129
|
});
|
|
3109
|
-
const citationDocuments =
|
|
3130
|
+
const citationDocuments = [
|
|
3131
|
+
...this.extractCitationDocuments(options.prompt)
|
|
3132
|
+
];
|
|
3110
3133
|
const url = this.buildRequestUrl(true);
|
|
3111
3134
|
const { responseHeaders, value: response } = await (0, import_provider_utils12.postJsonToApi)({
|
|
3112
3135
|
url,
|
|
@@ -3146,7 +3169,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3146
3169
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3147
3170
|
},
|
|
3148
3171
|
transform(chunk, controller) {
|
|
3149
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
3172
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
3150
3173
|
if (options.includeRawChunks) {
|
|
3151
3174
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3152
3175
|
}
|
|
@@ -3282,6 +3305,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3282
3305
|
}
|
|
3283
3306
|
case "web_fetch_tool_result": {
|
|
3284
3307
|
if (part.content.type === "web_fetch_result") {
|
|
3308
|
+
citationDocuments.push({
|
|
3309
|
+
title: (_a2 = part.content.content.title) != null ? _a2 : part.content.url,
|
|
3310
|
+
mediaType: part.content.content.source.media_type
|
|
3311
|
+
});
|
|
3285
3312
|
controller.enqueue({
|
|
3286
3313
|
type: "tool-result",
|
|
3287
3314
|
toolCallId: part.tool_use_id,
|
|
@@ -3342,7 +3369,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3342
3369
|
title: result.title,
|
|
3343
3370
|
providerMetadata: {
|
|
3344
3371
|
anthropic: {
|
|
3345
|
-
pageAge: (
|
|
3372
|
+
pageAge: (_b2 = result.page_age) != null ? _b2 : null
|
|
3346
3373
|
}
|
|
3347
3374
|
}
|
|
3348
3375
|
});
|
|
@@ -3373,7 +3400,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3373
3400
|
stdout: part.content.stdout,
|
|
3374
3401
|
stderr: part.content.stderr,
|
|
3375
3402
|
return_code: part.content.return_code,
|
|
3376
|
-
content: (
|
|
3403
|
+
content: (_c = part.content.content) != null ? _c : []
|
|
3377
3404
|
}
|
|
3378
3405
|
});
|
|
3379
3406
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -3403,7 +3430,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3403
3430
|
}
|
|
3404
3431
|
// tool search tool results:
|
|
3405
3432
|
case "tool_search_tool_result": {
|
|
3406
|
-
const providerToolName = (
|
|
3433
|
+
const providerToolName = (_d = serverToolCalls[part.tool_use_id]) != null ? _d : "tool_search_tool_regex";
|
|
3407
3434
|
if (part.content.type === "tool_search_tool_search_result") {
|
|
3408
3435
|
controller.enqueue({
|
|
3409
3436
|
type: "tool-result",
|
|
@@ -3617,12 +3644,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3617
3644
|
}
|
|
3618
3645
|
case "message_start": {
|
|
3619
3646
|
usage.input_tokens = value.message.usage.input_tokens;
|
|
3620
|
-
usage.cache_read_input_tokens = (
|
|
3621
|
-
usage.cache_creation_input_tokens = (
|
|
3647
|
+
usage.cache_read_input_tokens = (_e = value.message.usage.cache_read_input_tokens) != null ? _e : 0;
|
|
3648
|
+
usage.cache_creation_input_tokens = (_f = value.message.usage.cache_creation_input_tokens) != null ? _f : 0;
|
|
3622
3649
|
rawUsage = {
|
|
3623
3650
|
...value.message.usage
|
|
3624
3651
|
};
|
|
3625
|
-
cacheCreationInputTokens = (
|
|
3652
|
+
cacheCreationInputTokens = (_g = value.message.usage.cache_creation_input_tokens) != null ? _g : null;
|
|
3626
3653
|
if (value.message.container != null) {
|
|
3627
3654
|
container = {
|
|
3628
3655
|
expiresAt: value.message.container.expires_at,
|
|
@@ -3641,8 +3668,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3641
3668
|
}
|
|
3642
3669
|
controller.enqueue({
|
|
3643
3670
|
type: "response-metadata",
|
|
3644
|
-
id: (
|
|
3645
|
-
modelId: (
|
|
3671
|
+
id: (_h = value.message.id) != null ? _h : void 0,
|
|
3672
|
+
modelId: (_i = value.message.model) != null ? _i : void 0
|
|
3646
3673
|
});
|
|
3647
3674
|
if (value.message.content != null) {
|
|
3648
3675
|
for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
|
|
@@ -3658,7 +3685,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3658
3685
|
id: part.id,
|
|
3659
3686
|
toolName: part.name
|
|
3660
3687
|
});
|
|
3661
|
-
const inputStr = JSON.stringify((
|
|
3688
|
+
const inputStr = JSON.stringify((_j = part.input) != null ? _j : {});
|
|
3662
3689
|
controller.enqueue({
|
|
3663
3690
|
type: "tool-input-delta",
|
|
3664
3691
|
id: part.id,
|
|
@@ -3696,17 +3723,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3696
3723
|
finishReason: value.delta.stop_reason,
|
|
3697
3724
|
isJsonResponseFromTool
|
|
3698
3725
|
}),
|
|
3699
|
-
raw: (
|
|
3726
|
+
raw: (_k = value.delta.stop_reason) != null ? _k : void 0
|
|
3700
3727
|
};
|
|
3701
|
-
stopSequence = (
|
|
3728
|
+
stopSequence = (_l = value.delta.stop_sequence) != null ? _l : null;
|
|
3702
3729
|
container = value.delta.container != null ? {
|
|
3703
3730
|
expiresAt: value.delta.container.expires_at,
|
|
3704
3731
|
id: value.delta.container.id,
|
|
3705
|
-
skills: (
|
|
3732
|
+
skills: (_n = (_m = value.delta.container.skills) == null ? void 0 : _m.map((skill) => ({
|
|
3706
3733
|
type: skill.type,
|
|
3707
3734
|
skillId: skill.skill_id,
|
|
3708
3735
|
version: skill.version
|
|
3709
|
-
}))) != null ?
|
|
3736
|
+
}))) != null ? _n : null
|
|
3710
3737
|
} : null;
|
|
3711
3738
|
if (value.delta.context_management) {
|
|
3712
3739
|
contextManagement = mapAnthropicResponseContextManagement(
|