@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.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
|
}
|
|
@@ -2294,6 +2297,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2294
2297
|
description: "Respond with a JSON object.",
|
|
2295
2298
|
inputSchema: responseFormat.schema
|
|
2296
2299
|
} : void 0;
|
|
2300
|
+
if (jsonResponseTool != null && (anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse) === false) {
|
|
2301
|
+
warnings.push({
|
|
2302
|
+
type: "unsupported-setting",
|
|
2303
|
+
setting: "providerOptions",
|
|
2304
|
+
details: "`disableParallelToolUse: false` is ignored when using the JSON response tool. Parallel tool use is disabled to ensure a single coherent JSON tool call."
|
|
2305
|
+
});
|
|
2306
|
+
}
|
|
2297
2307
|
const cacheControlValidator = new CacheControlValidator();
|
|
2298
2308
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
2299
2309
|
prompt,
|
|
@@ -2598,7 +2608,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2598
2608
|
});
|
|
2599
2609
|
}
|
|
2600
2610
|
async doGenerate(options) {
|
|
2601
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2611
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2602
2612
|
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
|
|
2603
2613
|
...options,
|
|
2604
2614
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
@@ -2624,7 +2634,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2624
2634
|
switch (part.type) {
|
|
2625
2635
|
case "text": {
|
|
2626
2636
|
if (!usesJsonResponseTool) {
|
|
2627
|
-
|
|
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
|
+
});
|
|
2628
2651
|
if (part.citations) {
|
|
2629
2652
|
for (const citation of part.citations) {
|
|
2630
2653
|
const source = createCitationSource(
|
|
@@ -2776,7 +2799,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2776
2799
|
title: result.title,
|
|
2777
2800
|
providerMetadata: {
|
|
2778
2801
|
anthropic: {
|
|
2779
|
-
pageAge: (
|
|
2802
|
+
pageAge: (_b = result.page_age) != null ? _b : null
|
|
2780
2803
|
}
|
|
2781
2804
|
}
|
|
2782
2805
|
});
|
|
@@ -2848,7 +2871,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2848
2871
|
}
|
|
2849
2872
|
let inputTokens;
|
|
2850
2873
|
let outputTokens;
|
|
2851
|
-
const servedByFallback = (
|
|
2874
|
+
const servedByFallback = (_c = response.usage.iterations) == null ? void 0 : _c.some(
|
|
2852
2875
|
(iter) => iter.type === "fallback_message"
|
|
2853
2876
|
);
|
|
2854
2877
|
if (response.usage.iterations && response.usage.iterations.length > 0 && !servedByFallback) {
|
|
@@ -2876,12 +2899,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2876
2899
|
inputTokens,
|
|
2877
2900
|
outputTokens,
|
|
2878
2901
|
totalTokens: inputTokens + outputTokens,
|
|
2879
|
-
cachedInputTokens: (
|
|
2902
|
+
cachedInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : void 0
|
|
2880
2903
|
},
|
|
2881
2904
|
request: { body: args },
|
|
2882
2905
|
response: {
|
|
2883
|
-
id: (
|
|
2884
|
-
modelId: (
|
|
2906
|
+
id: (_e = response.id) != null ? _e : void 0,
|
|
2907
|
+
modelId: (_f = response.model) != null ? _f : void 0,
|
|
2885
2908
|
headers: responseHeaders,
|
|
2886
2909
|
body: rawResponse
|
|
2887
2910
|
},
|
|
@@ -2889,8 +2912,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2889
2912
|
providerMetadata: {
|
|
2890
2913
|
anthropic: {
|
|
2891
2914
|
usage: response.usage,
|
|
2892
|
-
cacheCreationInputTokens: (
|
|
2893
|
-
stopSequence: (
|
|
2915
|
+
cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
|
|
2916
|
+
stopSequence: (_h = response.stop_sequence) != null ? _h : null,
|
|
2894
2917
|
...stopDetails != null ? { stopDetails } : {},
|
|
2895
2918
|
iterations: response.usage.iterations ? response.usage.iterations.map((iter) => ({
|
|
2896
2919
|
type: iter.type,
|
|
@@ -2901,11 +2924,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2901
2924
|
container: response.container ? {
|
|
2902
2925
|
expiresAt: response.container.expires_at,
|
|
2903
2926
|
id: response.container.id,
|
|
2904
|
-
skills: (
|
|
2927
|
+
skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
|
|
2905
2928
|
type: skill.type,
|
|
2906
2929
|
skillId: skill.skill_id,
|
|
2907
2930
|
version: skill.version
|
|
2908
|
-
}))) != null ?
|
|
2931
|
+
}))) != null ? _j : null
|
|
2909
2932
|
} : null,
|
|
2910
2933
|
contextManagement: response.context_management ? {
|
|
2911
2934
|
appliedEdits: response.context_management.applied_edits.map(
|
|
@@ -2999,7 +3022,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2999
3022
|
blockType = contentBlockType;
|
|
3000
3023
|
switch (contentBlockType) {
|
|
3001
3024
|
case "text": {
|
|
3002
|
-
contentBlocks[value.index] = {
|
|
3025
|
+
contentBlocks[value.index] = {
|
|
3026
|
+
type: "text",
|
|
3027
|
+
citations: []
|
|
3028
|
+
};
|
|
3003
3029
|
controller.enqueue({
|
|
3004
3030
|
type: "text-start",
|
|
3005
3031
|
id: String(value.index)
|
|
@@ -3028,7 +3054,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3028
3054
|
return;
|
|
3029
3055
|
}
|
|
3030
3056
|
case "compaction": {
|
|
3031
|
-
contentBlocks[value.index] = {
|
|
3057
|
+
contentBlocks[value.index] = {
|
|
3058
|
+
type: "text",
|
|
3059
|
+
citations: []
|
|
3060
|
+
};
|
|
3032
3061
|
controller.enqueue({
|
|
3033
3062
|
type: "text-start",
|
|
3034
3063
|
id: String(value.index),
|
|
@@ -3041,7 +3070,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3041
3070
|
return;
|
|
3042
3071
|
}
|
|
3043
3072
|
case "tool_use": {
|
|
3044
|
-
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
|
|
3073
|
+
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text", citations: [] } : {
|
|
3045
3074
|
type: "tool-call",
|
|
3046
3075
|
toolCallId: value.content_block.id,
|
|
3047
3076
|
toolName: value.content_block.name,
|
|
@@ -3232,7 +3261,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3232
3261
|
case "text": {
|
|
3233
3262
|
controller.enqueue({
|
|
3234
3263
|
type: "text-end",
|
|
3235
|
-
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
|
+
}
|
|
3236
3272
|
});
|
|
3237
3273
|
break;
|
|
3238
3274
|
}
|
|
@@ -3346,6 +3382,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3346
3382
|
}
|
|
3347
3383
|
case "citations_delta": {
|
|
3348
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
|
+
}
|
|
3349
3389
|
const source = createCitationSource(
|
|
3350
3390
|
citation,
|
|
3351
3391
|
citationDocuments,
|