@ai-sdk/anthropic 2.0.85 → 2.0.87
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 +15 -0
- package/dist/index.js +49 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -16
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +48 -15
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +48 -15
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
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 ? "2.0.
|
|
14
|
+
var VERSION = true ? "2.0.87" : "0.0.0-test";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-messages-language-model.ts
|
|
17
17
|
import {
|
|
@@ -1722,6 +1722,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1722
1722
|
// in pre-filled assistant responses
|
|
1723
1723
|
isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
|
|
1724
1724
|
),
|
|
1725
|
+
...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
|
|
1726
|
+
citations: textMetadata.citations
|
|
1727
|
+
},
|
|
1725
1728
|
cache_control: cacheControl
|
|
1726
1729
|
});
|
|
1727
1730
|
}
|
|
@@ -2630,7 +2633,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2630
2633
|
});
|
|
2631
2634
|
}
|
|
2632
2635
|
async doGenerate(options) {
|
|
2633
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2636
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2634
2637
|
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
|
|
2635
2638
|
...options,
|
|
2636
2639
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
@@ -2656,7 +2659,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2656
2659
|
switch (part.type) {
|
|
2657
2660
|
case "text": {
|
|
2658
2661
|
if (!usesJsonResponseTool) {
|
|
2659
|
-
|
|
2662
|
+
const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
|
|
2663
|
+
(citation) => citation.type === "web_search_result_location"
|
|
2664
|
+
);
|
|
2665
|
+
content.push({
|
|
2666
|
+
type: "text",
|
|
2667
|
+
text: part.text,
|
|
2668
|
+
...webSearchCitations != null && webSearchCitations.length > 0 && {
|
|
2669
|
+
providerMetadata: {
|
|
2670
|
+
anthropic: {
|
|
2671
|
+
citations: webSearchCitations
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
});
|
|
2660
2676
|
if (part.citations) {
|
|
2661
2677
|
for (const citation of part.citations) {
|
|
2662
2678
|
const source = createCitationSource(
|
|
@@ -2808,7 +2824,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2808
2824
|
title: result.title,
|
|
2809
2825
|
providerMetadata: {
|
|
2810
2826
|
anthropic: {
|
|
2811
|
-
pageAge: (
|
|
2827
|
+
pageAge: (_b = result.page_age) != null ? _b : null
|
|
2812
2828
|
}
|
|
2813
2829
|
}
|
|
2814
2830
|
});
|
|
@@ -2880,7 +2896,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2880
2896
|
}
|
|
2881
2897
|
let inputTokens;
|
|
2882
2898
|
let outputTokens;
|
|
2883
|
-
const servedByFallback = (
|
|
2899
|
+
const servedByFallback = (_c = response.usage.iterations) == null ? void 0 : _c.some(
|
|
2884
2900
|
(iter) => iter.type === "fallback_message"
|
|
2885
2901
|
);
|
|
2886
2902
|
if (response.usage.iterations && response.usage.iterations.length > 0 && !servedByFallback) {
|
|
@@ -2908,12 +2924,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2908
2924
|
inputTokens,
|
|
2909
2925
|
outputTokens,
|
|
2910
2926
|
totalTokens: inputTokens + outputTokens,
|
|
2911
|
-
cachedInputTokens: (
|
|
2927
|
+
cachedInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : void 0
|
|
2912
2928
|
},
|
|
2913
2929
|
request: { body: args },
|
|
2914
2930
|
response: {
|
|
2915
|
-
id: (
|
|
2916
|
-
modelId: (
|
|
2931
|
+
id: (_e = response.id) != null ? _e : void 0,
|
|
2932
|
+
modelId: (_f = response.model) != null ? _f : void 0,
|
|
2917
2933
|
headers: responseHeaders,
|
|
2918
2934
|
body: rawResponse
|
|
2919
2935
|
},
|
|
@@ -2921,8 +2937,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2921
2937
|
providerMetadata: {
|
|
2922
2938
|
anthropic: {
|
|
2923
2939
|
usage: response.usage,
|
|
2924
|
-
cacheCreationInputTokens: (
|
|
2925
|
-
stopSequence: (
|
|
2940
|
+
cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
|
|
2941
|
+
stopSequence: (_h = response.stop_sequence) != null ? _h : null,
|
|
2926
2942
|
...stopDetails != null ? { stopDetails } : {},
|
|
2927
2943
|
iterations: response.usage.iterations ? response.usage.iterations.map((iter) => ({
|
|
2928
2944
|
type: iter.type,
|
|
@@ -2933,11 +2949,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2933
2949
|
container: response.container ? {
|
|
2934
2950
|
expiresAt: response.container.expires_at,
|
|
2935
2951
|
id: response.container.id,
|
|
2936
|
-
skills: (
|
|
2952
|
+
skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
|
|
2937
2953
|
type: skill.type,
|
|
2938
2954
|
skillId: skill.skill_id,
|
|
2939
2955
|
version: skill.version
|
|
2940
|
-
}))) != null ?
|
|
2956
|
+
}))) != null ? _j : null
|
|
2941
2957
|
} : null,
|
|
2942
2958
|
contextManagement: response.context_management ? {
|
|
2943
2959
|
appliedEdits: response.context_management.applied_edits.map(
|
|
@@ -3031,7 +3047,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3031
3047
|
blockType = contentBlockType;
|
|
3032
3048
|
switch (contentBlockType) {
|
|
3033
3049
|
case "text": {
|
|
3034
|
-
contentBlocks[value.index] = {
|
|
3050
|
+
contentBlocks[value.index] = {
|
|
3051
|
+
type: "text",
|
|
3052
|
+
citations: []
|
|
3053
|
+
};
|
|
3035
3054
|
controller.enqueue({
|
|
3036
3055
|
type: "text-start",
|
|
3037
3056
|
id: String(value.index)
|
|
@@ -3060,7 +3079,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3060
3079
|
return;
|
|
3061
3080
|
}
|
|
3062
3081
|
case "compaction": {
|
|
3063
|
-
contentBlocks[value.index] = {
|
|
3082
|
+
contentBlocks[value.index] = {
|
|
3083
|
+
type: "text",
|
|
3084
|
+
citations: []
|
|
3085
|
+
};
|
|
3064
3086
|
controller.enqueue({
|
|
3065
3087
|
type: "text-start",
|
|
3066
3088
|
id: String(value.index),
|
|
@@ -3073,7 +3095,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3073
3095
|
return;
|
|
3074
3096
|
}
|
|
3075
3097
|
case "tool_use": {
|
|
3076
|
-
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
|
|
3098
|
+
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text", citations: [] } : {
|
|
3077
3099
|
type: "tool-call",
|
|
3078
3100
|
toolCallId: value.content_block.id,
|
|
3079
3101
|
toolName: value.content_block.name,
|
|
@@ -3264,7 +3286,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3264
3286
|
case "text": {
|
|
3265
3287
|
controller.enqueue({
|
|
3266
3288
|
type: "text-end",
|
|
3267
|
-
id: String(value.index)
|
|
3289
|
+
id: String(value.index),
|
|
3290
|
+
...contentBlock.citations.length > 0 && {
|
|
3291
|
+
providerMetadata: {
|
|
3292
|
+
anthropic: {
|
|
3293
|
+
citations: contentBlock.citations
|
|
3294
|
+
}
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3268
3297
|
});
|
|
3269
3298
|
break;
|
|
3270
3299
|
}
|
|
@@ -3378,6 +3407,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3378
3407
|
}
|
|
3379
3408
|
case "citations_delta": {
|
|
3380
3409
|
const citation = value.delta.citation;
|
|
3410
|
+
const contentBlock = contentBlocks[value.index];
|
|
3411
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
|
|
3412
|
+
contentBlock.citations.push(citation);
|
|
3413
|
+
}
|
|
3381
3414
|
const source = createCitationSource(
|
|
3382
3415
|
citation,
|
|
3383
3416
|
citationDocuments,
|