@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/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.88" : "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
|
}
|
|
@@ -2326,6 +2329,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2326
2329
|
description: "Respond with a JSON object.",
|
|
2327
2330
|
inputSchema: responseFormat.schema
|
|
2328
2331
|
} : void 0;
|
|
2332
|
+
if (jsonResponseTool != null && (anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse) === false) {
|
|
2333
|
+
warnings.push({
|
|
2334
|
+
type: "unsupported-setting",
|
|
2335
|
+
setting: "providerOptions",
|
|
2336
|
+
details: "`disableParallelToolUse: false` is ignored when using the JSON response tool. Parallel tool use is disabled to ensure a single coherent JSON tool call."
|
|
2337
|
+
});
|
|
2338
|
+
}
|
|
2329
2339
|
const cacheControlValidator = new CacheControlValidator();
|
|
2330
2340
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
2331
2341
|
prompt,
|
|
@@ -2630,7 +2640,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2630
2640
|
});
|
|
2631
2641
|
}
|
|
2632
2642
|
async doGenerate(options) {
|
|
2633
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2643
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2634
2644
|
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
|
|
2635
2645
|
...options,
|
|
2636
2646
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
@@ -2656,7 +2666,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2656
2666
|
switch (part.type) {
|
|
2657
2667
|
case "text": {
|
|
2658
2668
|
if (!usesJsonResponseTool) {
|
|
2659
|
-
|
|
2669
|
+
const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
|
|
2670
|
+
(citation) => citation.type === "web_search_result_location"
|
|
2671
|
+
);
|
|
2672
|
+
content.push({
|
|
2673
|
+
type: "text",
|
|
2674
|
+
text: part.text,
|
|
2675
|
+
...webSearchCitations != null && webSearchCitations.length > 0 && {
|
|
2676
|
+
providerMetadata: {
|
|
2677
|
+
anthropic: {
|
|
2678
|
+
citations: webSearchCitations
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
});
|
|
2660
2683
|
if (part.citations) {
|
|
2661
2684
|
for (const citation of part.citations) {
|
|
2662
2685
|
const source = createCitationSource(
|
|
@@ -2808,7 +2831,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2808
2831
|
title: result.title,
|
|
2809
2832
|
providerMetadata: {
|
|
2810
2833
|
anthropic: {
|
|
2811
|
-
pageAge: (
|
|
2834
|
+
pageAge: (_b = result.page_age) != null ? _b : null
|
|
2812
2835
|
}
|
|
2813
2836
|
}
|
|
2814
2837
|
});
|
|
@@ -2880,7 +2903,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2880
2903
|
}
|
|
2881
2904
|
let inputTokens;
|
|
2882
2905
|
let outputTokens;
|
|
2883
|
-
const servedByFallback = (
|
|
2906
|
+
const servedByFallback = (_c = response.usage.iterations) == null ? void 0 : _c.some(
|
|
2884
2907
|
(iter) => iter.type === "fallback_message"
|
|
2885
2908
|
);
|
|
2886
2909
|
if (response.usage.iterations && response.usage.iterations.length > 0 && !servedByFallback) {
|
|
@@ -2908,12 +2931,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2908
2931
|
inputTokens,
|
|
2909
2932
|
outputTokens,
|
|
2910
2933
|
totalTokens: inputTokens + outputTokens,
|
|
2911
|
-
cachedInputTokens: (
|
|
2934
|
+
cachedInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : void 0
|
|
2912
2935
|
},
|
|
2913
2936
|
request: { body: args },
|
|
2914
2937
|
response: {
|
|
2915
|
-
id: (
|
|
2916
|
-
modelId: (
|
|
2938
|
+
id: (_e = response.id) != null ? _e : void 0,
|
|
2939
|
+
modelId: (_f = response.model) != null ? _f : void 0,
|
|
2917
2940
|
headers: responseHeaders,
|
|
2918
2941
|
body: rawResponse
|
|
2919
2942
|
},
|
|
@@ -2921,8 +2944,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2921
2944
|
providerMetadata: {
|
|
2922
2945
|
anthropic: {
|
|
2923
2946
|
usage: response.usage,
|
|
2924
|
-
cacheCreationInputTokens: (
|
|
2925
|
-
stopSequence: (
|
|
2947
|
+
cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
|
|
2948
|
+
stopSequence: (_h = response.stop_sequence) != null ? _h : null,
|
|
2926
2949
|
...stopDetails != null ? { stopDetails } : {},
|
|
2927
2950
|
iterations: response.usage.iterations ? response.usage.iterations.map((iter) => ({
|
|
2928
2951
|
type: iter.type,
|
|
@@ -2933,11 +2956,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2933
2956
|
container: response.container ? {
|
|
2934
2957
|
expiresAt: response.container.expires_at,
|
|
2935
2958
|
id: response.container.id,
|
|
2936
|
-
skills: (
|
|
2959
|
+
skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
|
|
2937
2960
|
type: skill.type,
|
|
2938
2961
|
skillId: skill.skill_id,
|
|
2939
2962
|
version: skill.version
|
|
2940
|
-
}))) != null ?
|
|
2963
|
+
}))) != null ? _j : null
|
|
2941
2964
|
} : null,
|
|
2942
2965
|
contextManagement: response.context_management ? {
|
|
2943
2966
|
appliedEdits: response.context_management.applied_edits.map(
|
|
@@ -3031,7 +3054,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3031
3054
|
blockType = contentBlockType;
|
|
3032
3055
|
switch (contentBlockType) {
|
|
3033
3056
|
case "text": {
|
|
3034
|
-
contentBlocks[value.index] = {
|
|
3057
|
+
contentBlocks[value.index] = {
|
|
3058
|
+
type: "text",
|
|
3059
|
+
citations: []
|
|
3060
|
+
};
|
|
3035
3061
|
controller.enqueue({
|
|
3036
3062
|
type: "text-start",
|
|
3037
3063
|
id: String(value.index)
|
|
@@ -3060,7 +3086,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3060
3086
|
return;
|
|
3061
3087
|
}
|
|
3062
3088
|
case "compaction": {
|
|
3063
|
-
contentBlocks[value.index] = {
|
|
3089
|
+
contentBlocks[value.index] = {
|
|
3090
|
+
type: "text",
|
|
3091
|
+
citations: []
|
|
3092
|
+
};
|
|
3064
3093
|
controller.enqueue({
|
|
3065
3094
|
type: "text-start",
|
|
3066
3095
|
id: String(value.index),
|
|
@@ -3073,7 +3102,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3073
3102
|
return;
|
|
3074
3103
|
}
|
|
3075
3104
|
case "tool_use": {
|
|
3076
|
-
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
|
|
3105
|
+
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text", citations: [] } : {
|
|
3077
3106
|
type: "tool-call",
|
|
3078
3107
|
toolCallId: value.content_block.id,
|
|
3079
3108
|
toolName: value.content_block.name,
|
|
@@ -3264,7 +3293,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3264
3293
|
case "text": {
|
|
3265
3294
|
controller.enqueue({
|
|
3266
3295
|
type: "text-end",
|
|
3267
|
-
id: String(value.index)
|
|
3296
|
+
id: String(value.index),
|
|
3297
|
+
...contentBlock.citations.length > 0 && {
|
|
3298
|
+
providerMetadata: {
|
|
3299
|
+
anthropic: {
|
|
3300
|
+
citations: contentBlock.citations
|
|
3301
|
+
}
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3268
3304
|
});
|
|
3269
3305
|
break;
|
|
3270
3306
|
}
|
|
@@ -3378,6 +3414,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3378
3414
|
}
|
|
3379
3415
|
case "citations_delta": {
|
|
3380
3416
|
const citation = value.delta.citation;
|
|
3417
|
+
const contentBlock = contentBlocks[value.index];
|
|
3418
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
|
|
3419
|
+
contentBlock.citations.push(citation);
|
|
3420
|
+
}
|
|
3381
3421
|
const source = createCitationSource(
|
|
3382
3422
|
citation,
|
|
3383
3423
|
citationDocuments,
|