@ai-sdk/anthropic 4.0.14 → 4.0.16
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/internal/index.js +49 -13
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +2 -2
- package/package.json +2 -2
- package/src/anthropic-api.ts +1 -0
- package/src/anthropic-language-model.ts +46 -5
- package/src/convert-to-anthropic-prompt.ts +5 -2
package/dist/internal/index.js
CHANGED
|
@@ -2733,6 +2733,9 @@ async function convertToAnthropicPrompt({
|
|
|
2733
2733
|
// in pre-filled assistant responses
|
|
2734
2734
|
isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
|
|
2735
2735
|
),
|
|
2736
|
+
...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
|
|
2737
|
+
citations: textMetadata.citations
|
|
2738
|
+
},
|
|
2736
2739
|
cache_control: cacheControl
|
|
2737
2740
|
});
|
|
2738
2741
|
}
|
|
@@ -4035,7 +4038,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4035
4038
|
});
|
|
4036
4039
|
}
|
|
4037
4040
|
async doGenerate(options) {
|
|
4038
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
4041
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
4039
4042
|
const {
|
|
4040
4043
|
args,
|
|
4041
4044
|
warnings,
|
|
@@ -4078,7 +4081,20 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4078
4081
|
switch (part.type) {
|
|
4079
4082
|
case "text": {
|
|
4080
4083
|
if (!usesJsonResponseTool) {
|
|
4081
|
-
|
|
4084
|
+
const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
|
|
4085
|
+
(citation) => citation.type === "web_search_result_location"
|
|
4086
|
+
);
|
|
4087
|
+
content.push({
|
|
4088
|
+
type: "text",
|
|
4089
|
+
text: part.text,
|
|
4090
|
+
...webSearchCitations != null && webSearchCitations.length > 0 && {
|
|
4091
|
+
providerMetadata: {
|
|
4092
|
+
anthropic: {
|
|
4093
|
+
citations: webSearchCitations
|
|
4094
|
+
}
|
|
4095
|
+
}
|
|
4096
|
+
}
|
|
4097
|
+
});
|
|
4082
4098
|
if (part.citations) {
|
|
4083
4099
|
for (const citation of part.citations) {
|
|
4084
4100
|
const source = createCitationSource(
|
|
@@ -4242,7 +4258,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4242
4258
|
case "web_fetch_tool_result": {
|
|
4243
4259
|
if (part.content.type === "web_fetch_result") {
|
|
4244
4260
|
citationDocuments.push({
|
|
4245
|
-
title: (
|
|
4261
|
+
title: (_b = part.content.content.title) != null ? _b : part.content.url,
|
|
4246
4262
|
mediaType: part.content.content.source.media_type
|
|
4247
4263
|
});
|
|
4248
4264
|
content.push({
|
|
@@ -4305,7 +4321,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4305
4321
|
title: result.title,
|
|
4306
4322
|
providerMetadata: {
|
|
4307
4323
|
anthropic: {
|
|
4308
|
-
pageAge: (
|
|
4324
|
+
pageAge: (_c = result.page_age) != null ? _c : null
|
|
4309
4325
|
}
|
|
4310
4326
|
}
|
|
4311
4327
|
});
|
|
@@ -4336,7 +4352,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4336
4352
|
stdout: part.content.stdout,
|
|
4337
4353
|
stderr: part.content.stderr,
|
|
4338
4354
|
return_code: part.content.return_code,
|
|
4339
|
-
content: (
|
|
4355
|
+
content: (_d = part.content.content) != null ? _d : []
|
|
4340
4356
|
}
|
|
4341
4357
|
});
|
|
4342
4358
|
} else if (part.content.type === "encrypted_code_execution_result") {
|
|
@@ -4349,7 +4365,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4349
4365
|
encrypted_stdout: part.content.encrypted_stdout,
|
|
4350
4366
|
stderr: part.content.stderr,
|
|
4351
4367
|
return_code: part.content.return_code,
|
|
4352
|
-
content: (
|
|
4368
|
+
content: (_e = part.content.content) != null ? _e : []
|
|
4353
4369
|
}
|
|
4354
4370
|
});
|
|
4355
4371
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -4471,13 +4487,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4471
4487
|
finishReason: response.stop_reason,
|
|
4472
4488
|
isJsonResponseFromTool
|
|
4473
4489
|
}),
|
|
4474
|
-
raw: (
|
|
4490
|
+
raw: (_f = response.stop_reason) != null ? _f : void 0
|
|
4475
4491
|
},
|
|
4476
4492
|
usage: convertAnthropicUsage({ usage: response.usage }),
|
|
4477
4493
|
request: { body: args },
|
|
4478
4494
|
response: {
|
|
4479
|
-
id: (
|
|
4480
|
-
modelId: (
|
|
4495
|
+
id: (_g = response.id) != null ? _g : void 0,
|
|
4496
|
+
modelId: (_h = response.model) != null ? _h : void 0,
|
|
4481
4497
|
headers: responseHeaders,
|
|
4482
4498
|
body: rawResponse
|
|
4483
4499
|
},
|
|
@@ -4611,7 +4627,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4611
4627
|
if (usesJsonResponseTool) {
|
|
4612
4628
|
return;
|
|
4613
4629
|
}
|
|
4614
|
-
contentBlocks[value.index] = {
|
|
4630
|
+
contentBlocks[value.index] = {
|
|
4631
|
+
type: "text",
|
|
4632
|
+
citations: []
|
|
4633
|
+
};
|
|
4615
4634
|
controller.enqueue({
|
|
4616
4635
|
type: "text-start",
|
|
4617
4636
|
id: String(value.index)
|
|
@@ -4640,7 +4659,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4640
4659
|
return;
|
|
4641
4660
|
}
|
|
4642
4661
|
case "compaction": {
|
|
4643
|
-
contentBlocks[value.index] = {
|
|
4662
|
+
contentBlocks[value.index] = {
|
|
4663
|
+
type: "text",
|
|
4664
|
+
citations: []
|
|
4665
|
+
};
|
|
4644
4666
|
controller.enqueue({
|
|
4645
4667
|
type: "text-start",
|
|
4646
4668
|
id: String(value.index),
|
|
@@ -4656,7 +4678,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4656
4678
|
const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
|
|
4657
4679
|
if (isJsonResponseTool) {
|
|
4658
4680
|
isJsonResponseFromTool = true;
|
|
4659
|
-
contentBlocks[value.index] = {
|
|
4681
|
+
contentBlocks[value.index] = {
|
|
4682
|
+
type: "text",
|
|
4683
|
+
citations: []
|
|
4684
|
+
};
|
|
4660
4685
|
controller.enqueue({
|
|
4661
4686
|
type: "text-start",
|
|
4662
4687
|
id: String(value.index)
|
|
@@ -5029,7 +5054,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5029
5054
|
case "text": {
|
|
5030
5055
|
controller.enqueue({
|
|
5031
5056
|
type: "text-end",
|
|
5032
|
-
id: String(value.index)
|
|
5057
|
+
id: String(value.index),
|
|
5058
|
+
...contentBlock.citations.length > 0 && {
|
|
5059
|
+
providerMetadata: {
|
|
5060
|
+
anthropic: {
|
|
5061
|
+
citations: contentBlock.citations
|
|
5062
|
+
}
|
|
5063
|
+
}
|
|
5064
|
+
}
|
|
5033
5065
|
});
|
|
5034
5066
|
break;
|
|
5035
5067
|
}
|
|
@@ -5168,6 +5200,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5168
5200
|
}
|
|
5169
5201
|
case "citations_delta": {
|
|
5170
5202
|
const citation = value.delta.citation;
|
|
5203
|
+
const contentBlock = contentBlocks[value.index];
|
|
5204
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
|
|
5205
|
+
contentBlock.citations.push(citation);
|
|
5206
|
+
}
|
|
5171
5207
|
const source = createCitationSource(
|
|
5172
5208
|
citation,
|
|
5173
5209
|
citationDocuments,
|