@ai-sdk/anthropic 2.0.86 → 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 +8 -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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 2.0.87
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5082ee8: fix(provider/anthropic): preserve web search citations when replaying assistant messages
|
|
8
|
+
- Updated dependencies [2fd6076]
|
|
9
|
+
- @ai-sdk/provider-utils@3.0.30
|
|
10
|
+
|
|
3
11
|
## 2.0.86
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
31
31
|
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
|
32
32
|
|
|
33
33
|
// src/version.ts
|
|
34
|
-
var VERSION = true ? "2.0.
|
|
34
|
+
var VERSION = true ? "2.0.87" : "0.0.0-test";
|
|
35
35
|
|
|
36
36
|
// src/anthropic-messages-language-model.ts
|
|
37
37
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -1697,6 +1697,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1697
1697
|
// in pre-filled assistant responses
|
|
1698
1698
|
isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
|
|
1699
1699
|
),
|
|
1700
|
+
...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
|
|
1701
|
+
citations: textMetadata.citations
|
|
1702
|
+
},
|
|
1700
1703
|
cache_control: cacheControl
|
|
1701
1704
|
});
|
|
1702
1705
|
}
|
|
@@ -2605,7 +2608,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2605
2608
|
});
|
|
2606
2609
|
}
|
|
2607
2610
|
async doGenerate(options) {
|
|
2608
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2611
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2609
2612
|
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
|
|
2610
2613
|
...options,
|
|
2611
2614
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
@@ -2631,7 +2634,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2631
2634
|
switch (part.type) {
|
|
2632
2635
|
case "text": {
|
|
2633
2636
|
if (!usesJsonResponseTool) {
|
|
2634
|
-
|
|
2637
|
+
const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
|
|
2638
|
+
(citation) => citation.type === "web_search_result_location"
|
|
2639
|
+
);
|
|
2640
|
+
content.push({
|
|
2641
|
+
type: "text",
|
|
2642
|
+
text: part.text,
|
|
2643
|
+
...webSearchCitations != null && webSearchCitations.length > 0 && {
|
|
2644
|
+
providerMetadata: {
|
|
2645
|
+
anthropic: {
|
|
2646
|
+
citations: webSearchCitations
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
});
|
|
2635
2651
|
if (part.citations) {
|
|
2636
2652
|
for (const citation of part.citations) {
|
|
2637
2653
|
const source = createCitationSource(
|
|
@@ -2783,7 +2799,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2783
2799
|
title: result.title,
|
|
2784
2800
|
providerMetadata: {
|
|
2785
2801
|
anthropic: {
|
|
2786
|
-
pageAge: (
|
|
2802
|
+
pageAge: (_b = result.page_age) != null ? _b : null
|
|
2787
2803
|
}
|
|
2788
2804
|
}
|
|
2789
2805
|
});
|
|
@@ -2855,7 +2871,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2855
2871
|
}
|
|
2856
2872
|
let inputTokens;
|
|
2857
2873
|
let outputTokens;
|
|
2858
|
-
const servedByFallback = (
|
|
2874
|
+
const servedByFallback = (_c = response.usage.iterations) == null ? void 0 : _c.some(
|
|
2859
2875
|
(iter) => iter.type === "fallback_message"
|
|
2860
2876
|
);
|
|
2861
2877
|
if (response.usage.iterations && response.usage.iterations.length > 0 && !servedByFallback) {
|
|
@@ -2883,12 +2899,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2883
2899
|
inputTokens,
|
|
2884
2900
|
outputTokens,
|
|
2885
2901
|
totalTokens: inputTokens + outputTokens,
|
|
2886
|
-
cachedInputTokens: (
|
|
2902
|
+
cachedInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : void 0
|
|
2887
2903
|
},
|
|
2888
2904
|
request: { body: args },
|
|
2889
2905
|
response: {
|
|
2890
|
-
id: (
|
|
2891
|
-
modelId: (
|
|
2906
|
+
id: (_e = response.id) != null ? _e : void 0,
|
|
2907
|
+
modelId: (_f = response.model) != null ? _f : void 0,
|
|
2892
2908
|
headers: responseHeaders,
|
|
2893
2909
|
body: rawResponse
|
|
2894
2910
|
},
|
|
@@ -2896,8 +2912,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2896
2912
|
providerMetadata: {
|
|
2897
2913
|
anthropic: {
|
|
2898
2914
|
usage: response.usage,
|
|
2899
|
-
cacheCreationInputTokens: (
|
|
2900
|
-
stopSequence: (
|
|
2915
|
+
cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
|
|
2916
|
+
stopSequence: (_h = response.stop_sequence) != null ? _h : null,
|
|
2901
2917
|
...stopDetails != null ? { stopDetails } : {},
|
|
2902
2918
|
iterations: response.usage.iterations ? response.usage.iterations.map((iter) => ({
|
|
2903
2919
|
type: iter.type,
|
|
@@ -2908,11 +2924,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2908
2924
|
container: response.container ? {
|
|
2909
2925
|
expiresAt: response.container.expires_at,
|
|
2910
2926
|
id: response.container.id,
|
|
2911
|
-
skills: (
|
|
2927
|
+
skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
|
|
2912
2928
|
type: skill.type,
|
|
2913
2929
|
skillId: skill.skill_id,
|
|
2914
2930
|
version: skill.version
|
|
2915
|
-
}))) != null ?
|
|
2931
|
+
}))) != null ? _j : null
|
|
2916
2932
|
} : null,
|
|
2917
2933
|
contextManagement: response.context_management ? {
|
|
2918
2934
|
appliedEdits: response.context_management.applied_edits.map(
|
|
@@ -3006,7 +3022,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3006
3022
|
blockType = contentBlockType;
|
|
3007
3023
|
switch (contentBlockType) {
|
|
3008
3024
|
case "text": {
|
|
3009
|
-
contentBlocks[value.index] = {
|
|
3025
|
+
contentBlocks[value.index] = {
|
|
3026
|
+
type: "text",
|
|
3027
|
+
citations: []
|
|
3028
|
+
};
|
|
3010
3029
|
controller.enqueue({
|
|
3011
3030
|
type: "text-start",
|
|
3012
3031
|
id: String(value.index)
|
|
@@ -3035,7 +3054,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3035
3054
|
return;
|
|
3036
3055
|
}
|
|
3037
3056
|
case "compaction": {
|
|
3038
|
-
contentBlocks[value.index] = {
|
|
3057
|
+
contentBlocks[value.index] = {
|
|
3058
|
+
type: "text",
|
|
3059
|
+
citations: []
|
|
3060
|
+
};
|
|
3039
3061
|
controller.enqueue({
|
|
3040
3062
|
type: "text-start",
|
|
3041
3063
|
id: String(value.index),
|
|
@@ -3048,7 +3070,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3048
3070
|
return;
|
|
3049
3071
|
}
|
|
3050
3072
|
case "tool_use": {
|
|
3051
|
-
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
|
|
3073
|
+
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text", citations: [] } : {
|
|
3052
3074
|
type: "tool-call",
|
|
3053
3075
|
toolCallId: value.content_block.id,
|
|
3054
3076
|
toolName: value.content_block.name,
|
|
@@ -3239,7 +3261,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3239
3261
|
case "text": {
|
|
3240
3262
|
controller.enqueue({
|
|
3241
3263
|
type: "text-end",
|
|
3242
|
-
id: String(value.index)
|
|
3264
|
+
id: String(value.index),
|
|
3265
|
+
...contentBlock.citations.length > 0 && {
|
|
3266
|
+
providerMetadata: {
|
|
3267
|
+
anthropic: {
|
|
3268
|
+
citations: contentBlock.citations
|
|
3269
|
+
}
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3243
3272
|
});
|
|
3244
3273
|
break;
|
|
3245
3274
|
}
|
|
@@ -3353,6 +3382,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3353
3382
|
}
|
|
3354
3383
|
case "citations_delta": {
|
|
3355
3384
|
const citation = value.delta.citation;
|
|
3385
|
+
const contentBlock = contentBlocks[value.index];
|
|
3386
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
|
|
3387
|
+
contentBlock.citations.push(citation);
|
|
3388
|
+
}
|
|
3356
3389
|
const source = createCitationSource(
|
|
3357
3390
|
citation,
|
|
3358
3391
|
citationDocuments,
|