@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/docs/05-anthropic.mdx
CHANGED
|
@@ -1489,7 +1489,7 @@ To use skills, you need to:
|
|
|
1489
1489
|
1. Enable the code execution tool
|
|
1490
1490
|
2. Specify the container with skills in `providerOptions`
|
|
1491
1491
|
|
|
1492
|
-
```ts highlight="
|
|
1492
|
+
```ts highlight="6-8,10-23"
|
|
1493
1493
|
import { anthropic, AnthropicLanguageModelOptions } from '@ai-sdk/anthropic';
|
|
1494
1494
|
import { generateText } from 'ai';
|
|
1495
1495
|
|
|
@@ -1519,7 +1519,7 @@ const result = await generateText({
|
|
|
1519
1519
|
|
|
1520
1520
|
You can also use custom skills by specifying `type: 'custom'`:
|
|
1521
1521
|
|
|
1522
|
-
```ts highlight="
|
|
1522
|
+
```ts highlight="11-15"
|
|
1523
1523
|
const result = await generateText({
|
|
1524
1524
|
model: anthropic('claude-sonnet-4-5'),
|
|
1525
1525
|
tools: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/anthropic",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@ai-sdk/provider": "4.0.3",
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.11"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "22.19.19",
|
package/src/anthropic-api.ts
CHANGED
|
@@ -927,7 +927,22 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
927
927
|
switch (part.type) {
|
|
928
928
|
case 'text': {
|
|
929
929
|
if (!usesJsonResponseTool) {
|
|
930
|
-
|
|
930
|
+
const webSearchCitations = part.citations?.filter(
|
|
931
|
+
citation => citation.type === 'web_search_result_location',
|
|
932
|
+
);
|
|
933
|
+
|
|
934
|
+
content.push({
|
|
935
|
+
type: 'text',
|
|
936
|
+
text: part.text,
|
|
937
|
+
...(webSearchCitations != null &&
|
|
938
|
+
webSearchCitations.length > 0 && {
|
|
939
|
+
providerMetadata: {
|
|
940
|
+
anthropic: {
|
|
941
|
+
citations: webSearchCitations,
|
|
942
|
+
},
|
|
943
|
+
},
|
|
944
|
+
}),
|
|
945
|
+
});
|
|
931
946
|
|
|
932
947
|
// Process citations if present
|
|
933
948
|
if (part.citations) {
|
|
@@ -1509,7 +1524,8 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1509
1524
|
toolId?: string;
|
|
1510
1525
|
};
|
|
1511
1526
|
}
|
|
1512
|
-
| { type: 'text'
|
|
1527
|
+
| { type: 'text'; citations: Citation[] }
|
|
1528
|
+
| { type: 'reasoning' }
|
|
1513
1529
|
> = {};
|
|
1514
1530
|
const mcpToolCalls: Record<string, LanguageModelV4ToolCall> = {};
|
|
1515
1531
|
const serverToolCalls: Record<string, string> = {}; // tool_use_id -> provider tool name
|
|
@@ -1590,7 +1606,10 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1590
1606
|
return;
|
|
1591
1607
|
}
|
|
1592
1608
|
|
|
1593
|
-
contentBlocks[value.index] = {
|
|
1609
|
+
contentBlocks[value.index] = {
|
|
1610
|
+
type: 'text',
|
|
1611
|
+
citations: [],
|
|
1612
|
+
};
|
|
1594
1613
|
controller.enqueue({
|
|
1595
1614
|
type: 'text-start',
|
|
1596
1615
|
id: String(value.index),
|
|
@@ -1622,7 +1641,10 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1622
1641
|
}
|
|
1623
1642
|
|
|
1624
1643
|
case 'compaction': {
|
|
1625
|
-
contentBlocks[value.index] = {
|
|
1644
|
+
contentBlocks[value.index] = {
|
|
1645
|
+
type: 'text',
|
|
1646
|
+
citations: [],
|
|
1647
|
+
};
|
|
1626
1648
|
controller.enqueue({
|
|
1627
1649
|
type: 'text-start',
|
|
1628
1650
|
id: String(value.index),
|
|
@@ -1642,7 +1664,10 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1642
1664
|
if (isJsonResponseTool) {
|
|
1643
1665
|
isJsonResponseFromTool = true;
|
|
1644
1666
|
|
|
1645
|
-
contentBlocks[value.index] = {
|
|
1667
|
+
contentBlocks[value.index] = {
|
|
1668
|
+
type: 'text',
|
|
1669
|
+
citations: [],
|
|
1670
|
+
};
|
|
1646
1671
|
|
|
1647
1672
|
controller.enqueue({
|
|
1648
1673
|
type: 'text-start',
|
|
@@ -2101,6 +2126,13 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
2101
2126
|
controller.enqueue({
|
|
2102
2127
|
type: 'text-end',
|
|
2103
2128
|
id: String(value.index),
|
|
2129
|
+
...(contentBlock.citations.length > 0 && {
|
|
2130
|
+
providerMetadata: {
|
|
2131
|
+
anthropic: {
|
|
2132
|
+
citations: contentBlock.citations,
|
|
2133
|
+
},
|
|
2134
|
+
},
|
|
2135
|
+
}),
|
|
2104
2136
|
});
|
|
2105
2137
|
break;
|
|
2106
2138
|
}
|
|
@@ -2291,6 +2323,15 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
2291
2323
|
|
|
2292
2324
|
case 'citations_delta': {
|
|
2293
2325
|
const citation = value.delta.citation;
|
|
2326
|
+
const contentBlock = contentBlocks[value.index];
|
|
2327
|
+
|
|
2328
|
+
if (
|
|
2329
|
+
contentBlock?.type === 'text' &&
|
|
2330
|
+
citation.type === 'web_search_result_location'
|
|
2331
|
+
) {
|
|
2332
|
+
contentBlock.citations.push(citation);
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2294
2335
|
const source = createCitationSource(
|
|
2295
2336
|
citation,
|
|
2296
2337
|
citationDocuments,
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
type AnthropicToolResultContent,
|
|
27
27
|
type AnthropicUserMessage,
|
|
28
28
|
type AnthropicWebFetchToolResultContent,
|
|
29
|
+
type Citation,
|
|
29
30
|
} from './anthropic-api';
|
|
30
31
|
import { anthropicFilePartProviderOptions } from './anthropic-language-model-options';
|
|
31
32
|
import { CacheControlValidator } from './get-cache-control';
|
|
@@ -585,7 +586,7 @@ export async function convertToAnthropicPrompt({
|
|
|
585
586
|
case 'text': {
|
|
586
587
|
// Check if this is a compaction block (via providerMetadata)
|
|
587
588
|
const textMetadata = part.providerOptions?.anthropic as
|
|
588
|
-
| { type?: string }
|
|
589
|
+
| { type?: string; citations?: Citation[] }
|
|
589
590
|
| undefined;
|
|
590
591
|
|
|
591
592
|
if (textMetadata?.type === 'compaction') {
|
|
@@ -604,7 +605,9 @@ export async function convertToAnthropicPrompt({
|
|
|
604
605
|
isLastBlock && isLastMessage && isLastContentPart
|
|
605
606
|
? part.text.trim()
|
|
606
607
|
: part.text,
|
|
607
|
-
|
|
608
|
+
...(textMetadata?.citations != null && {
|
|
609
|
+
citations: textMetadata.citations,
|
|
610
|
+
}),
|
|
608
611
|
cache_control: cacheControl,
|
|
609
612
|
});
|
|
610
613
|
}
|