@ai-sdk/anthropic 3.0.96 → 3.0.98
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 +50 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -14
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +49 -13
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +49 -13
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/anthropic-messages-api.ts +1 -0
- package/src/anthropic-messages-language-model.ts +46 -5
- package/src/convert-to-anthropic-messages-prompt.ts +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 3.0.98
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 10366a2: fix(provider/anthropic): preserve web search citations when replaying assistant messages
|
|
8
|
+
- Updated dependencies [19093fd]
|
|
9
|
+
- @ai-sdk/provider-utils@4.0.40
|
|
10
|
+
|
|
11
|
+
## 3.0.97
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [06fb54c]
|
|
16
|
+
- @ai-sdk/provider-utils@4.0.39
|
|
17
|
+
|
|
3
18
|
## 3.0.96
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
32
32
|
var import_provider_utils26 = require("@ai-sdk/provider-utils");
|
|
33
33
|
|
|
34
34
|
// src/version.ts
|
|
35
|
-
var VERSION = true ? "3.0.
|
|
35
|
+
var VERSION = true ? "3.0.98" : "0.0.0-test";
|
|
36
36
|
|
|
37
37
|
// src/anthropic-messages-language-model.ts
|
|
38
38
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -2530,6 +2530,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2530
2530
|
// in pre-filled assistant responses
|
|
2531
2531
|
isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
|
|
2532
2532
|
),
|
|
2533
|
+
...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
|
|
2534
|
+
citations: textMetadata.citations
|
|
2535
|
+
},
|
|
2533
2536
|
cache_control: cacheControl
|
|
2534
2537
|
});
|
|
2535
2538
|
}
|
|
@@ -3797,7 +3800,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3797
3800
|
});
|
|
3798
3801
|
}
|
|
3799
3802
|
async doGenerate(options) {
|
|
3800
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
3803
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3801
3804
|
const {
|
|
3802
3805
|
args,
|
|
3803
3806
|
warnings,
|
|
@@ -3840,7 +3843,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3840
3843
|
switch (part.type) {
|
|
3841
3844
|
case "text": {
|
|
3842
3845
|
if (!usesJsonResponseTool) {
|
|
3843
|
-
|
|
3846
|
+
const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
|
|
3847
|
+
(citation) => citation.type === "web_search_result_location"
|
|
3848
|
+
);
|
|
3849
|
+
content.push({
|
|
3850
|
+
type: "text",
|
|
3851
|
+
text: part.text,
|
|
3852
|
+
...webSearchCitations != null && webSearchCitations.length > 0 && {
|
|
3853
|
+
providerMetadata: {
|
|
3854
|
+
anthropic: {
|
|
3855
|
+
citations: webSearchCitations
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
}
|
|
3859
|
+
});
|
|
3844
3860
|
if (part.citations) {
|
|
3845
3861
|
for (const citation of part.citations) {
|
|
3846
3862
|
const source = createCitationSource(
|
|
@@ -4004,7 +4020,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4004
4020
|
case "web_fetch_tool_result": {
|
|
4005
4021
|
if (part.content.type === "web_fetch_result") {
|
|
4006
4022
|
citationDocuments.push({
|
|
4007
|
-
title: (
|
|
4023
|
+
title: (_b = part.content.content.title) != null ? _b : part.content.url,
|
|
4008
4024
|
mediaType: part.content.content.source.media_type
|
|
4009
4025
|
});
|
|
4010
4026
|
content.push({
|
|
@@ -4067,7 +4083,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4067
4083
|
title: result.title,
|
|
4068
4084
|
providerMetadata: {
|
|
4069
4085
|
anthropic: {
|
|
4070
|
-
pageAge: (
|
|
4086
|
+
pageAge: (_c = result.page_age) != null ? _c : null
|
|
4071
4087
|
}
|
|
4072
4088
|
}
|
|
4073
4089
|
});
|
|
@@ -4098,7 +4114,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4098
4114
|
stdout: part.content.stdout,
|
|
4099
4115
|
stderr: part.content.stderr,
|
|
4100
4116
|
return_code: part.content.return_code,
|
|
4101
|
-
content: (
|
|
4117
|
+
content: (_d = part.content.content) != null ? _d : []
|
|
4102
4118
|
}
|
|
4103
4119
|
});
|
|
4104
4120
|
} else if (part.content.type === "encrypted_code_execution_result") {
|
|
@@ -4111,7 +4127,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4111
4127
|
encrypted_stdout: part.content.encrypted_stdout,
|
|
4112
4128
|
stderr: part.content.stderr,
|
|
4113
4129
|
return_code: part.content.return_code,
|
|
4114
|
-
content: (
|
|
4130
|
+
content: (_e = part.content.content) != null ? _e : []
|
|
4115
4131
|
}
|
|
4116
4132
|
});
|
|
4117
4133
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -4233,13 +4249,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4233
4249
|
finishReason: response.stop_reason,
|
|
4234
4250
|
isJsonResponseFromTool
|
|
4235
4251
|
}),
|
|
4236
|
-
raw: (
|
|
4252
|
+
raw: (_f = response.stop_reason) != null ? _f : void 0
|
|
4237
4253
|
},
|
|
4238
4254
|
usage: convertAnthropicMessagesUsage({ usage: response.usage }),
|
|
4239
4255
|
request: { body: args },
|
|
4240
4256
|
response: {
|
|
4241
|
-
id: (
|
|
4242
|
-
modelId: (
|
|
4257
|
+
id: (_g = response.id) != null ? _g : void 0,
|
|
4258
|
+
modelId: (_h = response.model) != null ? _h : void 0,
|
|
4243
4259
|
headers: responseHeaders,
|
|
4244
4260
|
body: rawResponse
|
|
4245
4261
|
},
|
|
@@ -4376,7 +4392,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4376
4392
|
if (usesJsonResponseTool) {
|
|
4377
4393
|
return;
|
|
4378
4394
|
}
|
|
4379
|
-
contentBlocks[value.index] = {
|
|
4395
|
+
contentBlocks[value.index] = {
|
|
4396
|
+
type: "text",
|
|
4397
|
+
citations: []
|
|
4398
|
+
};
|
|
4380
4399
|
controller.enqueue({
|
|
4381
4400
|
type: "text-start",
|
|
4382
4401
|
id: String(value.index)
|
|
@@ -4405,7 +4424,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4405
4424
|
return;
|
|
4406
4425
|
}
|
|
4407
4426
|
case "compaction": {
|
|
4408
|
-
contentBlocks[value.index] = {
|
|
4427
|
+
contentBlocks[value.index] = {
|
|
4428
|
+
type: "text",
|
|
4429
|
+
citations: []
|
|
4430
|
+
};
|
|
4409
4431
|
controller.enqueue({
|
|
4410
4432
|
type: "text-start",
|
|
4411
4433
|
id: String(value.index),
|
|
@@ -4421,7 +4443,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4421
4443
|
const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
|
|
4422
4444
|
if (isJsonResponseTool) {
|
|
4423
4445
|
isJsonResponseFromTool = true;
|
|
4424
|
-
contentBlocks[value.index] = {
|
|
4446
|
+
contentBlocks[value.index] = {
|
|
4447
|
+
type: "text",
|
|
4448
|
+
citations: []
|
|
4449
|
+
};
|
|
4425
4450
|
controller.enqueue({
|
|
4426
4451
|
type: "text-start",
|
|
4427
4452
|
id: String(value.index)
|
|
@@ -4794,7 +4819,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4794
4819
|
case "text": {
|
|
4795
4820
|
controller.enqueue({
|
|
4796
4821
|
type: "text-end",
|
|
4797
|
-
id: String(value.index)
|
|
4822
|
+
id: String(value.index),
|
|
4823
|
+
...contentBlock.citations.length > 0 && {
|
|
4824
|
+
providerMetadata: {
|
|
4825
|
+
anthropic: {
|
|
4826
|
+
citations: contentBlock.citations
|
|
4827
|
+
}
|
|
4828
|
+
}
|
|
4829
|
+
}
|
|
4798
4830
|
});
|
|
4799
4831
|
break;
|
|
4800
4832
|
}
|
|
@@ -4933,6 +4965,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4933
4965
|
}
|
|
4934
4966
|
case "citations_delta": {
|
|
4935
4967
|
const citation = value.delta.citation;
|
|
4968
|
+
const contentBlock = contentBlocks[value.index];
|
|
4969
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
|
|
4970
|
+
contentBlock.citations.push(citation);
|
|
4971
|
+
}
|
|
4936
4972
|
const source = createCitationSource(
|
|
4937
4973
|
citation,
|
|
4938
4974
|
citationDocuments,
|