@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/internal/index.js
CHANGED
|
@@ -1690,6 +1690,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1690
1690
|
// in pre-filled assistant responses
|
|
1691
1691
|
isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
|
|
1692
1692
|
),
|
|
1693
|
+
...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
|
|
1694
|
+
citations: textMetadata.citations
|
|
1695
|
+
},
|
|
1693
1696
|
cache_control: cacheControl
|
|
1694
1697
|
});
|
|
1695
1698
|
}
|
|
@@ -2598,7 +2601,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2598
2601
|
});
|
|
2599
2602
|
}
|
|
2600
2603
|
async doGenerate(options) {
|
|
2601
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2604
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2602
2605
|
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
|
|
2603
2606
|
...options,
|
|
2604
2607
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
@@ -2624,7 +2627,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2624
2627
|
switch (part.type) {
|
|
2625
2628
|
case "text": {
|
|
2626
2629
|
if (!usesJsonResponseTool) {
|
|
2627
|
-
|
|
2630
|
+
const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
|
|
2631
|
+
(citation) => citation.type === "web_search_result_location"
|
|
2632
|
+
);
|
|
2633
|
+
content.push({
|
|
2634
|
+
type: "text",
|
|
2635
|
+
text: part.text,
|
|
2636
|
+
...webSearchCitations != null && webSearchCitations.length > 0 && {
|
|
2637
|
+
providerMetadata: {
|
|
2638
|
+
anthropic: {
|
|
2639
|
+
citations: webSearchCitations
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
});
|
|
2628
2644
|
if (part.citations) {
|
|
2629
2645
|
for (const citation of part.citations) {
|
|
2630
2646
|
const source = createCitationSource(
|
|
@@ -2776,7 +2792,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2776
2792
|
title: result.title,
|
|
2777
2793
|
providerMetadata: {
|
|
2778
2794
|
anthropic: {
|
|
2779
|
-
pageAge: (
|
|
2795
|
+
pageAge: (_b = result.page_age) != null ? _b : null
|
|
2780
2796
|
}
|
|
2781
2797
|
}
|
|
2782
2798
|
});
|
|
@@ -2848,7 +2864,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2848
2864
|
}
|
|
2849
2865
|
let inputTokens;
|
|
2850
2866
|
let outputTokens;
|
|
2851
|
-
const servedByFallback = (
|
|
2867
|
+
const servedByFallback = (_c = response.usage.iterations) == null ? void 0 : _c.some(
|
|
2852
2868
|
(iter) => iter.type === "fallback_message"
|
|
2853
2869
|
);
|
|
2854
2870
|
if (response.usage.iterations && response.usage.iterations.length > 0 && !servedByFallback) {
|
|
@@ -2876,12 +2892,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2876
2892
|
inputTokens,
|
|
2877
2893
|
outputTokens,
|
|
2878
2894
|
totalTokens: inputTokens + outputTokens,
|
|
2879
|
-
cachedInputTokens: (
|
|
2895
|
+
cachedInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : void 0
|
|
2880
2896
|
},
|
|
2881
2897
|
request: { body: args },
|
|
2882
2898
|
response: {
|
|
2883
|
-
id: (
|
|
2884
|
-
modelId: (
|
|
2899
|
+
id: (_e = response.id) != null ? _e : void 0,
|
|
2900
|
+
modelId: (_f = response.model) != null ? _f : void 0,
|
|
2885
2901
|
headers: responseHeaders,
|
|
2886
2902
|
body: rawResponse
|
|
2887
2903
|
},
|
|
@@ -2889,8 +2905,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2889
2905
|
providerMetadata: {
|
|
2890
2906
|
anthropic: {
|
|
2891
2907
|
usage: response.usage,
|
|
2892
|
-
cacheCreationInputTokens: (
|
|
2893
|
-
stopSequence: (
|
|
2908
|
+
cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
|
|
2909
|
+
stopSequence: (_h = response.stop_sequence) != null ? _h : null,
|
|
2894
2910
|
...stopDetails != null ? { stopDetails } : {},
|
|
2895
2911
|
iterations: response.usage.iterations ? response.usage.iterations.map((iter) => ({
|
|
2896
2912
|
type: iter.type,
|
|
@@ -2901,11 +2917,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2901
2917
|
container: response.container ? {
|
|
2902
2918
|
expiresAt: response.container.expires_at,
|
|
2903
2919
|
id: response.container.id,
|
|
2904
|
-
skills: (
|
|
2920
|
+
skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
|
|
2905
2921
|
type: skill.type,
|
|
2906
2922
|
skillId: skill.skill_id,
|
|
2907
2923
|
version: skill.version
|
|
2908
|
-
}))) != null ?
|
|
2924
|
+
}))) != null ? _j : null
|
|
2909
2925
|
} : null,
|
|
2910
2926
|
contextManagement: response.context_management ? {
|
|
2911
2927
|
appliedEdits: response.context_management.applied_edits.map(
|
|
@@ -2999,7 +3015,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2999
3015
|
blockType = contentBlockType;
|
|
3000
3016
|
switch (contentBlockType) {
|
|
3001
3017
|
case "text": {
|
|
3002
|
-
contentBlocks[value.index] = {
|
|
3018
|
+
contentBlocks[value.index] = {
|
|
3019
|
+
type: "text",
|
|
3020
|
+
citations: []
|
|
3021
|
+
};
|
|
3003
3022
|
controller.enqueue({
|
|
3004
3023
|
type: "text-start",
|
|
3005
3024
|
id: String(value.index)
|
|
@@ -3028,7 +3047,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3028
3047
|
return;
|
|
3029
3048
|
}
|
|
3030
3049
|
case "compaction": {
|
|
3031
|
-
contentBlocks[value.index] = {
|
|
3050
|
+
contentBlocks[value.index] = {
|
|
3051
|
+
type: "text",
|
|
3052
|
+
citations: []
|
|
3053
|
+
};
|
|
3032
3054
|
controller.enqueue({
|
|
3033
3055
|
type: "text-start",
|
|
3034
3056
|
id: String(value.index),
|
|
@@ -3041,7 +3063,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3041
3063
|
return;
|
|
3042
3064
|
}
|
|
3043
3065
|
case "tool_use": {
|
|
3044
|
-
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
|
|
3066
|
+
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text", citations: [] } : {
|
|
3045
3067
|
type: "tool-call",
|
|
3046
3068
|
toolCallId: value.content_block.id,
|
|
3047
3069
|
toolName: value.content_block.name,
|
|
@@ -3232,7 +3254,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3232
3254
|
case "text": {
|
|
3233
3255
|
controller.enqueue({
|
|
3234
3256
|
type: "text-end",
|
|
3235
|
-
id: String(value.index)
|
|
3257
|
+
id: String(value.index),
|
|
3258
|
+
...contentBlock.citations.length > 0 && {
|
|
3259
|
+
providerMetadata: {
|
|
3260
|
+
anthropic: {
|
|
3261
|
+
citations: contentBlock.citations
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3236
3265
|
});
|
|
3237
3266
|
break;
|
|
3238
3267
|
}
|
|
@@ -3346,6 +3375,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3346
3375
|
}
|
|
3347
3376
|
case "citations_delta": {
|
|
3348
3377
|
const citation = value.delta.citation;
|
|
3378
|
+
const contentBlock = contentBlocks[value.index];
|
|
3379
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
|
|
3380
|
+
contentBlock.citations.push(citation);
|
|
3381
|
+
}
|
|
3349
3382
|
const source = createCitationSource(
|
|
3350
3383
|
citation,
|
|
3351
3384
|
citationDocuments,
|