@ai-sdk/anthropic 3.0.0-beta.29 → 3.0.0-beta.31

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.
@@ -570,7 +570,22 @@ var anthropicProviderOptions = z3.object({
570
570
  allowedTools: z3.array(z3.string()).nullish()
571
571
  }).nullish()
572
572
  })
573
- ).optional()
573
+ ).optional(),
574
+ /**
575
+ * Agent Skills configuration. Skills enable Claude to perform specialized tasks
576
+ * like document processing (PPTX, DOCX, PDF, XLSX) and data analysis.
577
+ * Requires code execution tool to be enabled.
578
+ */
579
+ container: z3.object({
580
+ id: z3.string().optional(),
581
+ skills: z3.array(
582
+ z3.object({
583
+ type: z3.union([z3.literal("anthropic"), z3.literal("custom")]),
584
+ skillId: z3.string(),
585
+ version: z3.string().optional()
586
+ })
587
+ ).optional()
588
+ }).optional()
574
589
  });
575
590
 
576
591
  // src/anthropic-prepare-tools.ts
@@ -579,12 +594,46 @@ import {
579
594
  } from "@ai-sdk/provider";
580
595
 
581
596
  // src/get-cache-control.ts
597
+ var MAX_CACHE_BREAKPOINTS = 4;
582
598
  function getCacheControl(providerMetadata) {
583
599
  var _a;
584
600
  const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
585
601
  const cacheControlValue = (_a = anthropic == null ? void 0 : anthropic.cacheControl) != null ? _a : anthropic == null ? void 0 : anthropic.cache_control;
586
602
  return cacheControlValue;
587
603
  }
604
+ var CacheControlValidator = class {
605
+ constructor() {
606
+ this.breakpointCount = 0;
607
+ this.warnings = [];
608
+ }
609
+ getCacheControl(providerMetadata, context) {
610
+ const cacheControlValue = getCacheControl(providerMetadata);
611
+ if (!cacheControlValue) {
612
+ return void 0;
613
+ }
614
+ if (!context.canCache) {
615
+ this.warnings.push({
616
+ type: "unsupported-setting",
617
+ setting: "cacheControl",
618
+ details: `cache_control cannot be set on ${context.type}. It will be ignored.`
619
+ });
620
+ return void 0;
621
+ }
622
+ this.breakpointCount++;
623
+ if (this.breakpointCount > MAX_CACHE_BREAKPOINTS) {
624
+ this.warnings.push({
625
+ type: "unsupported-setting",
626
+ setting: "cacheControl",
627
+ details: `Maximum ${MAX_CACHE_BREAKPOINTS} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`
628
+ });
629
+ return void 0;
630
+ }
631
+ return cacheControlValue;
632
+ }
633
+ getWarnings() {
634
+ return this.warnings;
635
+ }
636
+ };
588
637
 
589
638
  // src/tool/text-editor_20250728.ts
590
639
  import { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils";
@@ -738,11 +787,13 @@ import { validateTypes } from "@ai-sdk/provider-utils";
738
787
  async function prepareTools({
739
788
  tools,
740
789
  toolChoice,
741
- disableParallelToolUse
790
+ disableParallelToolUse,
791
+ cacheControlValidator
742
792
  }) {
743
793
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
744
794
  const toolWarnings = [];
745
795
  const betas = /* @__PURE__ */ new Set();
796
+ const validator = cacheControlValidator || new CacheControlValidator();
746
797
  if (tools == null) {
747
798
  return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
748
799
  }
@@ -750,7 +801,10 @@ async function prepareTools({
750
801
  for (const tool of tools) {
751
802
  switch (tool.type) {
752
803
  case "function": {
753
- const cacheControl = getCacheControl(tool.providerOptions);
804
+ const cacheControl = validator.getCacheControl(tool.providerOptions, {
805
+ type: "tool definition",
806
+ canCache: true
807
+ });
754
808
  anthropicTools2.push({
755
809
  name: tool.name,
756
810
  description: tool.description,
@@ -765,7 +819,8 @@ async function prepareTools({
765
819
  betas.add("code-execution-2025-05-22");
766
820
  anthropicTools2.push({
767
821
  type: "code_execution_20250522",
768
- name: "code_execution"
822
+ name: "code_execution",
823
+ cache_control: void 0
769
824
  });
770
825
  break;
771
826
  }
@@ -784,7 +839,8 @@ async function prepareTools({
784
839
  type: "computer_20250124",
785
840
  display_width_px: tool.args.displayWidthPx,
786
841
  display_height_px: tool.args.displayHeightPx,
787
- display_number: tool.args.displayNumber
842
+ display_number: tool.args.displayNumber,
843
+ cache_control: void 0
788
844
  });
789
845
  break;
790
846
  }
@@ -795,7 +851,8 @@ async function prepareTools({
795
851
  type: "computer_20241022",
796
852
  display_width_px: tool.args.displayWidthPx,
797
853
  display_height_px: tool.args.displayHeightPx,
798
- display_number: tool.args.displayNumber
854
+ display_number: tool.args.displayNumber,
855
+ cache_control: void 0
799
856
  });
800
857
  break;
801
858
  }
@@ -803,7 +860,8 @@ async function prepareTools({
803
860
  betas.add("computer-use-2025-01-24");
804
861
  anthropicTools2.push({
805
862
  name: "str_replace_editor",
806
- type: "text_editor_20250124"
863
+ type: "text_editor_20250124",
864
+ cache_control: void 0
807
865
  });
808
866
  break;
809
867
  }
@@ -811,7 +869,8 @@ async function prepareTools({
811
869
  betas.add("computer-use-2024-10-22");
812
870
  anthropicTools2.push({
813
871
  name: "str_replace_editor",
814
- type: "text_editor_20241022"
872
+ type: "text_editor_20241022",
873
+ cache_control: void 0
815
874
  });
816
875
  break;
817
876
  }
@@ -819,7 +878,8 @@ async function prepareTools({
819
878
  betas.add("computer-use-2025-01-24");
820
879
  anthropicTools2.push({
821
880
  name: "str_replace_based_edit_tool",
822
- type: "text_editor_20250429"
881
+ type: "text_editor_20250429",
882
+ cache_control: void 0
823
883
  });
824
884
  break;
825
885
  }
@@ -831,7 +891,8 @@ async function prepareTools({
831
891
  anthropicTools2.push({
832
892
  name: "str_replace_based_edit_tool",
833
893
  type: "text_editor_20250728",
834
- max_characters: args.maxCharacters
894
+ max_characters: args.maxCharacters,
895
+ cache_control: void 0
835
896
  });
836
897
  break;
837
898
  }
@@ -839,7 +900,8 @@ async function prepareTools({
839
900
  betas.add("computer-use-2025-01-24");
840
901
  anthropicTools2.push({
841
902
  name: "bash",
842
- type: "bash_20250124"
903
+ type: "bash_20250124",
904
+ cache_control: void 0
843
905
  });
844
906
  break;
845
907
  }
@@ -847,7 +909,8 @@ async function prepareTools({
847
909
  betas.add("computer-use-2024-10-22");
848
910
  anthropicTools2.push({
849
911
  name: "bash",
850
- type: "bash_20241022"
912
+ type: "bash_20241022",
913
+ cache_control: void 0
851
914
  });
852
915
  break;
853
916
  }
@@ -872,7 +935,8 @@ async function prepareTools({
872
935
  allowed_domains: args.allowedDomains,
873
936
  blocked_domains: args.blockedDomains,
874
937
  citations: args.citations,
875
- max_content_tokens: args.maxContentTokens
938
+ max_content_tokens: args.maxContentTokens,
939
+ cache_control: void 0
876
940
  });
877
941
  break;
878
942
  }
@@ -887,7 +951,8 @@ async function prepareTools({
887
951
  max_uses: args.maxUses,
888
952
  allowed_domains: args.allowedDomains,
889
953
  blocked_domains: args.blockedDomains,
890
- user_location: args.userLocation
954
+ user_location: args.userLocation,
955
+ cache_control: void 0
891
956
  });
892
957
  break;
893
958
  }
@@ -1114,11 +1179,13 @@ function convertToString(data) {
1114
1179
  async function convertToAnthropicMessagesPrompt({
1115
1180
  prompt,
1116
1181
  sendReasoning,
1117
- warnings
1182
+ warnings,
1183
+ cacheControlValidator
1118
1184
  }) {
1119
1185
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1120
1186
  const betas = /* @__PURE__ */ new Set();
1121
1187
  const blocks = groupIntoBlocks(prompt);
1188
+ const validator = cacheControlValidator || new CacheControlValidator();
1122
1189
  let system = void 0;
1123
1190
  const messages = [];
1124
1191
  async function shouldEnableCitations(providerMetadata) {
@@ -1155,7 +1222,10 @@ async function convertToAnthropicMessagesPrompt({
1155
1222
  system = block.messages.map(({ content, providerOptions }) => ({
1156
1223
  type: "text",
1157
1224
  text: content,
1158
- cache_control: getCacheControl(providerOptions)
1225
+ cache_control: validator.getCacheControl(providerOptions, {
1226
+ type: "system message",
1227
+ canCache: true
1228
+ })
1159
1229
  }));
1160
1230
  break;
1161
1231
  }
@@ -1168,7 +1238,13 @@ async function convertToAnthropicMessagesPrompt({
1168
1238
  for (let j = 0; j < content.length; j++) {
1169
1239
  const part = content[j];
1170
1240
  const isLastPart = j === content.length - 1;
1171
- const cacheControl = (_a = getCacheControl(part.providerOptions)) != null ? _a : isLastPart ? getCacheControl(message.providerOptions) : void 0;
1241
+ const cacheControl = (_a = validator.getCacheControl(part.providerOptions, {
1242
+ type: "user message part",
1243
+ canCache: true
1244
+ })) != null ? _a : isLastPart ? validator.getCacheControl(message.providerOptions, {
1245
+ type: "user message",
1246
+ canCache: true
1247
+ }) : void 0;
1172
1248
  switch (part.type) {
1173
1249
  case "text": {
1174
1250
  anthropicContent.push({
@@ -1256,7 +1332,13 @@ async function convertToAnthropicMessagesPrompt({
1256
1332
  for (let i2 = 0; i2 < content.length; i2++) {
1257
1333
  const part = content[i2];
1258
1334
  const isLastPart = i2 === content.length - 1;
1259
- const cacheControl = (_d = getCacheControl(part.providerOptions)) != null ? _d : isLastPart ? getCacheControl(message.providerOptions) : void 0;
1335
+ const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
1336
+ type: "tool result part",
1337
+ canCache: true
1338
+ })) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
1339
+ type: "tool result message",
1340
+ canCache: true
1341
+ }) : void 0;
1260
1342
  const output = part.output;
1261
1343
  let contentValue;
1262
1344
  switch (output.type) {
@@ -1266,8 +1348,7 @@ async function convertToAnthropicMessagesPrompt({
1266
1348
  case "text":
1267
1349
  return {
1268
1350
  type: "text",
1269
- text: contentPart.text,
1270
- cache_control: cacheControl
1351
+ text: contentPart.text
1271
1352
  };
1272
1353
  case "image-data": {
1273
1354
  return {
@@ -1276,8 +1357,7 @@ async function convertToAnthropicMessagesPrompt({
1276
1357
  type: "base64",
1277
1358
  media_type: contentPart.mediaType,
1278
1359
  data: contentPart.data
1279
- },
1280
- cache_control: cacheControl
1360
+ }
1281
1361
  };
1282
1362
  }
1283
1363
  case "file-data": {
@@ -1289,8 +1369,7 @@ async function convertToAnthropicMessagesPrompt({
1289
1369
  type: "base64",
1290
1370
  media_type: contentPart.mediaType,
1291
1371
  data: contentPart.data
1292
- },
1293
- cache_control: cacheControl
1372
+ }
1294
1373
  };
1295
1374
  }
1296
1375
  warnings.push({
@@ -1351,7 +1430,13 @@ async function convertToAnthropicMessagesPrompt({
1351
1430
  for (let k = 0; k < content.length; k++) {
1352
1431
  const part = content[k];
1353
1432
  const isLastContentPart = k === content.length - 1;
1354
- const cacheControl = (_f = getCacheControl(part.providerOptions)) != null ? _f : isLastContentPart ? getCacheControl(message.providerOptions) : void 0;
1433
+ const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
1434
+ type: "assistant message part",
1435
+ canCache: true
1436
+ })) != null ? _f : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1437
+ type: "assistant message",
1438
+ canCache: true
1439
+ }) : void 0;
1355
1440
  switch (part.type) {
1356
1441
  case "text": {
1357
1442
  anthropicContent.push({
@@ -1375,17 +1460,23 @@ async function convertToAnthropicMessagesPrompt({
1375
1460
  });
1376
1461
  if (reasoningMetadata != null) {
1377
1462
  if (reasoningMetadata.signature != null) {
1463
+ validator.getCacheControl(part.providerOptions, {
1464
+ type: "thinking block",
1465
+ canCache: false
1466
+ });
1378
1467
  anthropicContent.push({
1379
1468
  type: "thinking",
1380
1469
  thinking: part.text,
1381
- signature: reasoningMetadata.signature,
1382
- cache_control: cacheControl
1470
+ signature: reasoningMetadata.signature
1383
1471
  });
1384
1472
  } else if (reasoningMetadata.redactedData != null) {
1473
+ validator.getCacheControl(part.providerOptions, {
1474
+ type: "redacted thinking block",
1475
+ canCache: false
1476
+ });
1385
1477
  anthropicContent.push({
1386
1478
  type: "redacted_thinking",
1387
- data: reasoningMetadata.redactedData,
1388
- cache_control: cacheControl
1479
+ data: reasoningMetadata.redactedData
1389
1480
  });
1390
1481
  } else {
1391
1482
  warnings.push({
@@ -1752,7 +1843,7 @@ var AnthropicMessagesLanguageModel = class {
1752
1843
  toolChoice,
1753
1844
  providerOptions
1754
1845
  }) {
1755
- var _a, _b, _c;
1846
+ var _a, _b, _c, _d;
1756
1847
  const warnings = [];
1757
1848
  if (frequencyPenalty != null) {
1758
1849
  warnings.push({
@@ -1798,10 +1889,12 @@ var AnthropicMessagesLanguageModel = class {
1798
1889
  providerOptions,
1799
1890
  schema: anthropicProviderOptions
1800
1891
  });
1892
+ const cacheControlValidator = new CacheControlValidator();
1801
1893
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
1802
1894
  prompt,
1803
1895
  sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
1804
- warnings
1896
+ warnings,
1897
+ cacheControlValidator
1805
1898
  });
1806
1899
  const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
1807
1900
  const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
@@ -1833,6 +1926,17 @@ var AnthropicMessagesLanguageModel = class {
1833
1926
  } : void 0
1834
1927
  }))
1835
1928
  },
1929
+ // container with agent skills:
1930
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
1931
+ container: {
1932
+ id: anthropicOptions.container.id,
1933
+ skills: (_d = anthropicOptions.container.skills) == null ? void 0 : _d.map((skill) => ({
1934
+ type: skill.type,
1935
+ skill_id: skill.skillId,
1936
+ version: skill.version
1937
+ }))
1938
+ }
1939
+ },
1836
1940
  // prompt:
1837
1941
  system: messagesPrompt.system,
1838
1942
  messages: messagesPrompt.messages
@@ -1882,6 +1986,19 @@ var AnthropicMessagesLanguageModel = class {
1882
1986
  if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
1883
1987
  betas.add("mcp-client-2025-04-04");
1884
1988
  }
1989
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.container) && anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0) {
1990
+ betas.add("code-execution-2025-08-25");
1991
+ betas.add("skills-2025-10-02");
1992
+ betas.add("files-api-2025-04-14");
1993
+ if (!(tools == null ? void 0 : tools.some(
1994
+ (tool) => tool.type === "provider-defined" && tool.id === "anthropic.code_execution_20250825"
1995
+ ))) {
1996
+ warnings.push({
1997
+ type: "other",
1998
+ message: "code execution tool is required when using skills"
1999
+ });
2000
+ }
2001
+ }
1885
2002
  const {
1886
2003
  tools: anthropicTools2,
1887
2004
  toolChoice: anthropicToolChoice,
@@ -1891,20 +2008,23 @@ var AnthropicMessagesLanguageModel = class {
1891
2008
  jsonResponseTool != null ? {
1892
2009
  tools: [jsonResponseTool],
1893
2010
  toolChoice: { type: "tool", toolName: jsonResponseTool.name },
1894
- disableParallelToolUse: true
2011
+ disableParallelToolUse: true,
2012
+ cacheControlValidator
1895
2013
  } : {
1896
2014
  tools: tools != null ? tools : [],
1897
2015
  toolChoice,
1898
- disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
2016
+ disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
2017
+ cacheControlValidator
1899
2018
  }
1900
2019
  );
2020
+ const cacheWarnings = cacheControlValidator.getWarnings();
1901
2021
  return {
1902
2022
  args: {
1903
2023
  ...baseArgs,
1904
2024
  tools: anthropicTools2,
1905
2025
  tool_choice: anthropicToolChoice
1906
2026
  },
1907
- warnings: [...warnings, ...toolWarnings],
2027
+ warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
1908
2028
  betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas]),
1909
2029
  usesJsonResponseTool: jsonResponseTool != null
1910
2030
  };