@ai-sdk/anthropic 3.0.97 → 3.0.99

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/anthropic",
3
- "version": "3.0.97",
3
+ "version": "3.0.99",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@ai-sdk/provider": "3.0.14",
40
- "@ai-sdk/provider-utils": "4.0.39"
40
+ "@ai-sdk/provider-utils": "4.0.40"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "20.17.24",
@@ -66,6 +66,7 @@ export interface AnthropicCompactionContent {
66
66
  export interface AnthropicTextContent {
67
67
  type: 'text';
68
68
  text: string;
69
+ citations?: Citation[];
69
70
  cache_control: AnthropicCacheControl | undefined;
70
71
  }
71
72
 
@@ -334,6 +334,19 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
334
334
  }
335
335
  : undefined;
336
336
 
337
+ if (
338
+ jsonResponseTool != null &&
339
+ anthropicOptions?.disableParallelToolUse === false
340
+ ) {
341
+ warnings.push({
342
+ type: 'unsupported',
343
+ feature: 'providerOptions.anthropic.disableParallelToolUse',
344
+ details:
345
+ '`disableParallelToolUse: false` is ignored when using the JSON response tool. ' +
346
+ 'Parallel tool use is disabled to ensure a single coherent JSON tool call.',
347
+ });
348
+ }
349
+
337
350
  const contextManagement = anthropicOptions?.contextManagement;
338
351
 
339
352
  // Create a shared cache control validator to track breakpoints across tools and messages
@@ -873,7 +886,22 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
873
886
  switch (part.type) {
874
887
  case 'text': {
875
888
  if (!usesJsonResponseTool) {
876
- content.push({ type: 'text', text: part.text });
889
+ const webSearchCitations = part.citations?.filter(
890
+ citation => citation.type === 'web_search_result_location',
891
+ );
892
+
893
+ content.push({
894
+ type: 'text',
895
+ text: part.text,
896
+ ...(webSearchCitations != null &&
897
+ webSearchCitations.length > 0 && {
898
+ providerMetadata: {
899
+ anthropic: {
900
+ citations: webSearchCitations,
901
+ },
902
+ },
903
+ }),
904
+ });
877
905
 
878
906
  // Process citations if present
879
907
  if (part.citations) {
@@ -1456,7 +1484,8 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
1456
1484
  toolId?: string;
1457
1485
  };
1458
1486
  }
1459
- | { type: 'text' | 'reasoning' }
1487
+ | { type: 'text'; citations: Citation[] }
1488
+ | { type: 'reasoning' }
1460
1489
  > = {};
1461
1490
  const mcpToolCalls: Record<string, LanguageModelV3ToolCall> = {};
1462
1491
  const serverToolCalls: Record<string, string> = {}; // tool_use_id -> provider tool name
@@ -1538,7 +1567,10 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
1538
1567
  return;
1539
1568
  }
1540
1569
 
1541
- contentBlocks[value.index] = { type: 'text' };
1570
+ contentBlocks[value.index] = {
1571
+ type: 'text',
1572
+ citations: [],
1573
+ };
1542
1574
  controller.enqueue({
1543
1575
  type: 'text-start',
1544
1576
  id: String(value.index),
@@ -1570,7 +1602,10 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
1570
1602
  }
1571
1603
 
1572
1604
  case 'compaction': {
1573
- contentBlocks[value.index] = { type: 'text' };
1605
+ contentBlocks[value.index] = {
1606
+ type: 'text',
1607
+ citations: [],
1608
+ };
1574
1609
  controller.enqueue({
1575
1610
  type: 'text-start',
1576
1611
  id: String(value.index),
@@ -1590,7 +1625,10 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
1590
1625
  if (isJsonResponseTool) {
1591
1626
  isJsonResponseFromTool = true;
1592
1627
 
1593
- contentBlocks[value.index] = { type: 'text' };
1628
+ contentBlocks[value.index] = {
1629
+ type: 'text',
1630
+ citations: [],
1631
+ };
1594
1632
 
1595
1633
  controller.enqueue({
1596
1634
  type: 'text-start',
@@ -2049,6 +2087,13 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
2049
2087
  controller.enqueue({
2050
2088
  type: 'text-end',
2051
2089
  id: String(value.index),
2090
+ ...(contentBlock.citations.length > 0 && {
2091
+ providerMetadata: {
2092
+ anthropic: {
2093
+ citations: contentBlock.citations,
2094
+ },
2095
+ },
2096
+ }),
2052
2097
  });
2053
2098
  break;
2054
2099
  }
@@ -2239,6 +2284,15 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
2239
2284
 
2240
2285
  case 'citations_delta': {
2241
2286
  const citation = value.delta.citation;
2287
+ const contentBlock = contentBlocks[value.index];
2288
+
2289
+ if (
2290
+ contentBlock?.type === 'text' &&
2291
+ citation.type === 'web_search_result_location'
2292
+ ) {
2293
+ contentBlock.citations.push(citation);
2294
+ }
2295
+
2242
2296
  const source = createCitationSource(
2243
2297
  citation,
2244
2298
  citationDocuments,
@@ -23,6 +23,7 @@ import {
23
23
  type AnthropicToolResultContent,
24
24
  type AnthropicUserMessage,
25
25
  type AnthropicWebFetchToolResultContent,
26
+ type Citation,
26
27
  } from './anthropic-messages-api';
27
28
  import { anthropicFilePartProviderOptions } from './anthropic-messages-options';
28
29
  import { CacheControlValidator } from './get-cache-control';
@@ -507,7 +508,7 @@ export async function convertToAnthropicMessagesPrompt({
507
508
  case 'text': {
508
509
  // Check if this is a compaction block (via providerMetadata)
509
510
  const textMetadata = part.providerOptions?.anthropic as
510
- | { type?: string }
511
+ | { type?: string; citations?: Citation[] }
511
512
  | undefined;
512
513
 
513
514
  if (textMetadata?.type === 'compaction') {
@@ -526,7 +527,9 @@ export async function convertToAnthropicMessagesPrompt({
526
527
  isLastBlock && isLastMessage && isLastContentPart
527
528
  ? part.text.trim()
528
529
  : part.text,
529
-
530
+ ...(textMetadata?.citations != null && {
531
+ citations: textMetadata.citations,
532
+ }),
530
533
  cache_control: cacheControl,
531
534
  });
532
535
  }
@@ -2,3 +2,4 @@ export { AnthropicMessagesLanguageModel } from '../anthropic-messages-language-m
2
2
  export { anthropicTools } from '../anthropic-tools';
3
3
  export type { AnthropicMessagesModelId } from '../anthropic-messages-options';
4
4
  export { prepareTools } from '../anthropic-prepare-tools';
5
+ export { sanitizeJsonSchema } from '../sanitize-json-schema';