@ai-sdk/anthropic 2.0.86 → 2.0.88
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 +14 -0
- package/dist/index.js +56 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -16
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +55 -15
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +55 -15
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/internal/index.mjs
CHANGED
|
@@ -1707,6 +1707,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1707
1707
|
// in pre-filled assistant responses
|
|
1708
1708
|
isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
|
|
1709
1709
|
),
|
|
1710
|
+
...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
|
|
1711
|
+
citations: textMetadata.citations
|
|
1712
|
+
},
|
|
1710
1713
|
cache_control: cacheControl
|
|
1711
1714
|
});
|
|
1712
1715
|
}
|
|
@@ -2311,6 +2314,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2311
2314
|
description: "Respond with a JSON object.",
|
|
2312
2315
|
inputSchema: responseFormat.schema
|
|
2313
2316
|
} : void 0;
|
|
2317
|
+
if (jsonResponseTool != null && (anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse) === false) {
|
|
2318
|
+
warnings.push({
|
|
2319
|
+
type: "unsupported-setting",
|
|
2320
|
+
setting: "providerOptions",
|
|
2321
|
+
details: "`disableParallelToolUse: false` is ignored when using the JSON response tool. Parallel tool use is disabled to ensure a single coherent JSON tool call."
|
|
2322
|
+
});
|
|
2323
|
+
}
|
|
2314
2324
|
const cacheControlValidator = new CacheControlValidator();
|
|
2315
2325
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
2316
2326
|
prompt,
|
|
@@ -2615,7 +2625,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2615
2625
|
});
|
|
2616
2626
|
}
|
|
2617
2627
|
async doGenerate(options) {
|
|
2618
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2628
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2619
2629
|
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
|
|
2620
2630
|
...options,
|
|
2621
2631
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
@@ -2641,7 +2651,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2641
2651
|
switch (part.type) {
|
|
2642
2652
|
case "text": {
|
|
2643
2653
|
if (!usesJsonResponseTool) {
|
|
2644
|
-
|
|
2654
|
+
const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
|
|
2655
|
+
(citation) => citation.type === "web_search_result_location"
|
|
2656
|
+
);
|
|
2657
|
+
content.push({
|
|
2658
|
+
type: "text",
|
|
2659
|
+
text: part.text,
|
|
2660
|
+
...webSearchCitations != null && webSearchCitations.length > 0 && {
|
|
2661
|
+
providerMetadata: {
|
|
2662
|
+
anthropic: {
|
|
2663
|
+
citations: webSearchCitations
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
});
|
|
2645
2668
|
if (part.citations) {
|
|
2646
2669
|
for (const citation of part.citations) {
|
|
2647
2670
|
const source = createCitationSource(
|
|
@@ -2793,7 +2816,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2793
2816
|
title: result.title,
|
|
2794
2817
|
providerMetadata: {
|
|
2795
2818
|
anthropic: {
|
|
2796
|
-
pageAge: (
|
|
2819
|
+
pageAge: (_b = result.page_age) != null ? _b : null
|
|
2797
2820
|
}
|
|
2798
2821
|
}
|
|
2799
2822
|
});
|
|
@@ -2865,7 +2888,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2865
2888
|
}
|
|
2866
2889
|
let inputTokens;
|
|
2867
2890
|
let outputTokens;
|
|
2868
|
-
const servedByFallback = (
|
|
2891
|
+
const servedByFallback = (_c = response.usage.iterations) == null ? void 0 : _c.some(
|
|
2869
2892
|
(iter) => iter.type === "fallback_message"
|
|
2870
2893
|
);
|
|
2871
2894
|
if (response.usage.iterations && response.usage.iterations.length > 0 && !servedByFallback) {
|
|
@@ -2893,12 +2916,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2893
2916
|
inputTokens,
|
|
2894
2917
|
outputTokens,
|
|
2895
2918
|
totalTokens: inputTokens + outputTokens,
|
|
2896
|
-
cachedInputTokens: (
|
|
2919
|
+
cachedInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : void 0
|
|
2897
2920
|
},
|
|
2898
2921
|
request: { body: args },
|
|
2899
2922
|
response: {
|
|
2900
|
-
id: (
|
|
2901
|
-
modelId: (
|
|
2923
|
+
id: (_e = response.id) != null ? _e : void 0,
|
|
2924
|
+
modelId: (_f = response.model) != null ? _f : void 0,
|
|
2902
2925
|
headers: responseHeaders,
|
|
2903
2926
|
body: rawResponse
|
|
2904
2927
|
},
|
|
@@ -2906,8 +2929,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2906
2929
|
providerMetadata: {
|
|
2907
2930
|
anthropic: {
|
|
2908
2931
|
usage: response.usage,
|
|
2909
|
-
cacheCreationInputTokens: (
|
|
2910
|
-
stopSequence: (
|
|
2932
|
+
cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
|
|
2933
|
+
stopSequence: (_h = response.stop_sequence) != null ? _h : null,
|
|
2911
2934
|
...stopDetails != null ? { stopDetails } : {},
|
|
2912
2935
|
iterations: response.usage.iterations ? response.usage.iterations.map((iter) => ({
|
|
2913
2936
|
type: iter.type,
|
|
@@ -2918,11 +2941,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2918
2941
|
container: response.container ? {
|
|
2919
2942
|
expiresAt: response.container.expires_at,
|
|
2920
2943
|
id: response.container.id,
|
|
2921
|
-
skills: (
|
|
2944
|
+
skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
|
|
2922
2945
|
type: skill.type,
|
|
2923
2946
|
skillId: skill.skill_id,
|
|
2924
2947
|
version: skill.version
|
|
2925
|
-
}))) != null ?
|
|
2948
|
+
}))) != null ? _j : null
|
|
2926
2949
|
} : null,
|
|
2927
2950
|
contextManagement: response.context_management ? {
|
|
2928
2951
|
appliedEdits: response.context_management.applied_edits.map(
|
|
@@ -3016,7 +3039,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3016
3039
|
blockType = contentBlockType;
|
|
3017
3040
|
switch (contentBlockType) {
|
|
3018
3041
|
case "text": {
|
|
3019
|
-
contentBlocks[value.index] = {
|
|
3042
|
+
contentBlocks[value.index] = {
|
|
3043
|
+
type: "text",
|
|
3044
|
+
citations: []
|
|
3045
|
+
};
|
|
3020
3046
|
controller.enqueue({
|
|
3021
3047
|
type: "text-start",
|
|
3022
3048
|
id: String(value.index)
|
|
@@ -3045,7 +3071,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3045
3071
|
return;
|
|
3046
3072
|
}
|
|
3047
3073
|
case "compaction": {
|
|
3048
|
-
contentBlocks[value.index] = {
|
|
3074
|
+
contentBlocks[value.index] = {
|
|
3075
|
+
type: "text",
|
|
3076
|
+
citations: []
|
|
3077
|
+
};
|
|
3049
3078
|
controller.enqueue({
|
|
3050
3079
|
type: "text-start",
|
|
3051
3080
|
id: String(value.index),
|
|
@@ -3058,7 +3087,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3058
3087
|
return;
|
|
3059
3088
|
}
|
|
3060
3089
|
case "tool_use": {
|
|
3061
|
-
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
|
|
3090
|
+
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text", citations: [] } : {
|
|
3062
3091
|
type: "tool-call",
|
|
3063
3092
|
toolCallId: value.content_block.id,
|
|
3064
3093
|
toolName: value.content_block.name,
|
|
@@ -3249,7 +3278,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3249
3278
|
case "text": {
|
|
3250
3279
|
controller.enqueue({
|
|
3251
3280
|
type: "text-end",
|
|
3252
|
-
id: String(value.index)
|
|
3281
|
+
id: String(value.index),
|
|
3282
|
+
...contentBlock.citations.length > 0 && {
|
|
3283
|
+
providerMetadata: {
|
|
3284
|
+
anthropic: {
|
|
3285
|
+
citations: contentBlock.citations
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3253
3289
|
});
|
|
3254
3290
|
break;
|
|
3255
3291
|
}
|
|
@@ -3363,6 +3399,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3363
3399
|
}
|
|
3364
3400
|
case "citations_delta": {
|
|
3365
3401
|
const citation = value.delta.citation;
|
|
3402
|
+
const contentBlock = contentBlocks[value.index];
|
|
3403
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
|
|
3404
|
+
contentBlock.citations.push(citation);
|
|
3405
|
+
}
|
|
3366
3406
|
const source = createCitationSource(
|
|
3367
3407
|
citation,
|
|
3368
3408
|
citationDocuments,
|