@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.
package/dist/index.mjs CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  } from "@ai-sdk/provider-utils";
11
11
 
12
12
  // src/version.ts
13
- var VERSION = true ? "3.0.0-beta.29" : "0.0.0-test";
13
+ var VERSION = true ? "3.0.0-beta.31" : "0.0.0-test";
14
14
 
15
15
  // src/anthropic-messages-language-model.ts
16
16
  import {
@@ -584,7 +584,22 @@ var anthropicProviderOptions = z3.object({
584
584
  allowedTools: z3.array(z3.string()).nullish()
585
585
  }).nullish()
586
586
  })
587
- ).optional()
587
+ ).optional(),
588
+ /**
589
+ * Agent Skills configuration. Skills enable Claude to perform specialized tasks
590
+ * like document processing (PPTX, DOCX, PDF, XLSX) and data analysis.
591
+ * Requires code execution tool to be enabled.
592
+ */
593
+ container: z3.object({
594
+ id: z3.string().optional(),
595
+ skills: z3.array(
596
+ z3.object({
597
+ type: z3.union([z3.literal("anthropic"), z3.literal("custom")]),
598
+ skillId: z3.string(),
599
+ version: z3.string().optional()
600
+ })
601
+ ).optional()
602
+ }).optional()
588
603
  });
589
604
 
590
605
  // src/anthropic-prepare-tools.ts
@@ -593,12 +608,46 @@ import {
593
608
  } from "@ai-sdk/provider";
594
609
 
595
610
  // src/get-cache-control.ts
611
+ var MAX_CACHE_BREAKPOINTS = 4;
596
612
  function getCacheControl(providerMetadata) {
597
613
  var _a;
598
614
  const anthropic2 = providerMetadata == null ? void 0 : providerMetadata.anthropic;
599
615
  const cacheControlValue = (_a = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a : anthropic2 == null ? void 0 : anthropic2.cache_control;
600
616
  return cacheControlValue;
601
617
  }
618
+ var CacheControlValidator = class {
619
+ constructor() {
620
+ this.breakpointCount = 0;
621
+ this.warnings = [];
622
+ }
623
+ getCacheControl(providerMetadata, context) {
624
+ const cacheControlValue = getCacheControl(providerMetadata);
625
+ if (!cacheControlValue) {
626
+ return void 0;
627
+ }
628
+ if (!context.canCache) {
629
+ this.warnings.push({
630
+ type: "unsupported-setting",
631
+ setting: "cacheControl",
632
+ details: `cache_control cannot be set on ${context.type}. It will be ignored.`
633
+ });
634
+ return void 0;
635
+ }
636
+ this.breakpointCount++;
637
+ if (this.breakpointCount > MAX_CACHE_BREAKPOINTS) {
638
+ this.warnings.push({
639
+ type: "unsupported-setting",
640
+ setting: "cacheControl",
641
+ details: `Maximum ${MAX_CACHE_BREAKPOINTS} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`
642
+ });
643
+ return void 0;
644
+ }
645
+ return cacheControlValue;
646
+ }
647
+ getWarnings() {
648
+ return this.warnings;
649
+ }
650
+ };
602
651
 
603
652
  // src/tool/text-editor_20250728.ts
604
653
  import { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils";
@@ -752,11 +801,13 @@ import { validateTypes } from "@ai-sdk/provider-utils";
752
801
  async function prepareTools({
753
802
  tools,
754
803
  toolChoice,
755
- disableParallelToolUse
804
+ disableParallelToolUse,
805
+ cacheControlValidator
756
806
  }) {
757
807
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
758
808
  const toolWarnings = [];
759
809
  const betas = /* @__PURE__ */ new Set();
810
+ const validator = cacheControlValidator || new CacheControlValidator();
760
811
  if (tools == null) {
761
812
  return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
762
813
  }
@@ -764,7 +815,10 @@ async function prepareTools({
764
815
  for (const tool of tools) {
765
816
  switch (tool.type) {
766
817
  case "function": {
767
- const cacheControl = getCacheControl(tool.providerOptions);
818
+ const cacheControl = validator.getCacheControl(tool.providerOptions, {
819
+ type: "tool definition",
820
+ canCache: true
821
+ });
768
822
  anthropicTools2.push({
769
823
  name: tool.name,
770
824
  description: tool.description,
@@ -779,7 +833,8 @@ async function prepareTools({
779
833
  betas.add("code-execution-2025-05-22");
780
834
  anthropicTools2.push({
781
835
  type: "code_execution_20250522",
782
- name: "code_execution"
836
+ name: "code_execution",
837
+ cache_control: void 0
783
838
  });
784
839
  break;
785
840
  }
@@ -798,7 +853,8 @@ async function prepareTools({
798
853
  type: "computer_20250124",
799
854
  display_width_px: tool.args.displayWidthPx,
800
855
  display_height_px: tool.args.displayHeightPx,
801
- display_number: tool.args.displayNumber
856
+ display_number: tool.args.displayNumber,
857
+ cache_control: void 0
802
858
  });
803
859
  break;
804
860
  }
@@ -809,7 +865,8 @@ async function prepareTools({
809
865
  type: "computer_20241022",
810
866
  display_width_px: tool.args.displayWidthPx,
811
867
  display_height_px: tool.args.displayHeightPx,
812
- display_number: tool.args.displayNumber
868
+ display_number: tool.args.displayNumber,
869
+ cache_control: void 0
813
870
  });
814
871
  break;
815
872
  }
@@ -817,7 +874,8 @@ async function prepareTools({
817
874
  betas.add("computer-use-2025-01-24");
818
875
  anthropicTools2.push({
819
876
  name: "str_replace_editor",
820
- type: "text_editor_20250124"
877
+ type: "text_editor_20250124",
878
+ cache_control: void 0
821
879
  });
822
880
  break;
823
881
  }
@@ -825,7 +883,8 @@ async function prepareTools({
825
883
  betas.add("computer-use-2024-10-22");
826
884
  anthropicTools2.push({
827
885
  name: "str_replace_editor",
828
- type: "text_editor_20241022"
886
+ type: "text_editor_20241022",
887
+ cache_control: void 0
829
888
  });
830
889
  break;
831
890
  }
@@ -833,7 +892,8 @@ async function prepareTools({
833
892
  betas.add("computer-use-2025-01-24");
834
893
  anthropicTools2.push({
835
894
  name: "str_replace_based_edit_tool",
836
- type: "text_editor_20250429"
895
+ type: "text_editor_20250429",
896
+ cache_control: void 0
837
897
  });
838
898
  break;
839
899
  }
@@ -845,7 +905,8 @@ async function prepareTools({
845
905
  anthropicTools2.push({
846
906
  name: "str_replace_based_edit_tool",
847
907
  type: "text_editor_20250728",
848
- max_characters: args.maxCharacters
908
+ max_characters: args.maxCharacters,
909
+ cache_control: void 0
849
910
  });
850
911
  break;
851
912
  }
@@ -853,7 +914,8 @@ async function prepareTools({
853
914
  betas.add("computer-use-2025-01-24");
854
915
  anthropicTools2.push({
855
916
  name: "bash",
856
- type: "bash_20250124"
917
+ type: "bash_20250124",
918
+ cache_control: void 0
857
919
  });
858
920
  break;
859
921
  }
@@ -861,7 +923,8 @@ async function prepareTools({
861
923
  betas.add("computer-use-2024-10-22");
862
924
  anthropicTools2.push({
863
925
  name: "bash",
864
- type: "bash_20241022"
926
+ type: "bash_20241022",
927
+ cache_control: void 0
865
928
  });
866
929
  break;
867
930
  }
@@ -886,7 +949,8 @@ async function prepareTools({
886
949
  allowed_domains: args.allowedDomains,
887
950
  blocked_domains: args.blockedDomains,
888
951
  citations: args.citations,
889
- max_content_tokens: args.maxContentTokens
952
+ max_content_tokens: args.maxContentTokens,
953
+ cache_control: void 0
890
954
  });
891
955
  break;
892
956
  }
@@ -901,7 +965,8 @@ async function prepareTools({
901
965
  max_uses: args.maxUses,
902
966
  allowed_domains: args.allowedDomains,
903
967
  blocked_domains: args.blockedDomains,
904
- user_location: args.userLocation
968
+ user_location: args.userLocation,
969
+ cache_control: void 0
905
970
  });
906
971
  break;
907
972
  }
@@ -1128,11 +1193,13 @@ function convertToString(data) {
1128
1193
  async function convertToAnthropicMessagesPrompt({
1129
1194
  prompt,
1130
1195
  sendReasoning,
1131
- warnings
1196
+ warnings,
1197
+ cacheControlValidator
1132
1198
  }) {
1133
1199
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1134
1200
  const betas = /* @__PURE__ */ new Set();
1135
1201
  const blocks = groupIntoBlocks(prompt);
1202
+ const validator = cacheControlValidator || new CacheControlValidator();
1136
1203
  let system = void 0;
1137
1204
  const messages = [];
1138
1205
  async function shouldEnableCitations(providerMetadata) {
@@ -1169,7 +1236,10 @@ async function convertToAnthropicMessagesPrompt({
1169
1236
  system = block.messages.map(({ content, providerOptions }) => ({
1170
1237
  type: "text",
1171
1238
  text: content,
1172
- cache_control: getCacheControl(providerOptions)
1239
+ cache_control: validator.getCacheControl(providerOptions, {
1240
+ type: "system message",
1241
+ canCache: true
1242
+ })
1173
1243
  }));
1174
1244
  break;
1175
1245
  }
@@ -1182,7 +1252,13 @@ async function convertToAnthropicMessagesPrompt({
1182
1252
  for (let j = 0; j < content.length; j++) {
1183
1253
  const part = content[j];
1184
1254
  const isLastPart = j === content.length - 1;
1185
- const cacheControl = (_a = getCacheControl(part.providerOptions)) != null ? _a : isLastPart ? getCacheControl(message.providerOptions) : void 0;
1255
+ const cacheControl = (_a = validator.getCacheControl(part.providerOptions, {
1256
+ type: "user message part",
1257
+ canCache: true
1258
+ })) != null ? _a : isLastPart ? validator.getCacheControl(message.providerOptions, {
1259
+ type: "user message",
1260
+ canCache: true
1261
+ }) : void 0;
1186
1262
  switch (part.type) {
1187
1263
  case "text": {
1188
1264
  anthropicContent.push({
@@ -1270,7 +1346,13 @@ async function convertToAnthropicMessagesPrompt({
1270
1346
  for (let i2 = 0; i2 < content.length; i2++) {
1271
1347
  const part = content[i2];
1272
1348
  const isLastPart = i2 === content.length - 1;
1273
- const cacheControl = (_d = getCacheControl(part.providerOptions)) != null ? _d : isLastPart ? getCacheControl(message.providerOptions) : void 0;
1349
+ const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
1350
+ type: "tool result part",
1351
+ canCache: true
1352
+ })) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
1353
+ type: "tool result message",
1354
+ canCache: true
1355
+ }) : void 0;
1274
1356
  const output = part.output;
1275
1357
  let contentValue;
1276
1358
  switch (output.type) {
@@ -1280,8 +1362,7 @@ async function convertToAnthropicMessagesPrompt({
1280
1362
  case "text":
1281
1363
  return {
1282
1364
  type: "text",
1283
- text: contentPart.text,
1284
- cache_control: cacheControl
1365
+ text: contentPart.text
1285
1366
  };
1286
1367
  case "image-data": {
1287
1368
  return {
@@ -1290,8 +1371,7 @@ async function convertToAnthropicMessagesPrompt({
1290
1371
  type: "base64",
1291
1372
  media_type: contentPart.mediaType,
1292
1373
  data: contentPart.data
1293
- },
1294
- cache_control: cacheControl
1374
+ }
1295
1375
  };
1296
1376
  }
1297
1377
  case "file-data": {
@@ -1303,8 +1383,7 @@ async function convertToAnthropicMessagesPrompt({
1303
1383
  type: "base64",
1304
1384
  media_type: contentPart.mediaType,
1305
1385
  data: contentPart.data
1306
- },
1307
- cache_control: cacheControl
1386
+ }
1308
1387
  };
1309
1388
  }
1310
1389
  warnings.push({
@@ -1365,7 +1444,13 @@ async function convertToAnthropicMessagesPrompt({
1365
1444
  for (let k = 0; k < content.length; k++) {
1366
1445
  const part = content[k];
1367
1446
  const isLastContentPart = k === content.length - 1;
1368
- const cacheControl = (_f = getCacheControl(part.providerOptions)) != null ? _f : isLastContentPart ? getCacheControl(message.providerOptions) : void 0;
1447
+ const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
1448
+ type: "assistant message part",
1449
+ canCache: true
1450
+ })) != null ? _f : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1451
+ type: "assistant message",
1452
+ canCache: true
1453
+ }) : void 0;
1369
1454
  switch (part.type) {
1370
1455
  case "text": {
1371
1456
  anthropicContent.push({
@@ -1389,17 +1474,23 @@ async function convertToAnthropicMessagesPrompt({
1389
1474
  });
1390
1475
  if (reasoningMetadata != null) {
1391
1476
  if (reasoningMetadata.signature != null) {
1477
+ validator.getCacheControl(part.providerOptions, {
1478
+ type: "thinking block",
1479
+ canCache: false
1480
+ });
1392
1481
  anthropicContent.push({
1393
1482
  type: "thinking",
1394
1483
  thinking: part.text,
1395
- signature: reasoningMetadata.signature,
1396
- cache_control: cacheControl
1484
+ signature: reasoningMetadata.signature
1397
1485
  });
1398
1486
  } else if (reasoningMetadata.redactedData != null) {
1487
+ validator.getCacheControl(part.providerOptions, {
1488
+ type: "redacted thinking block",
1489
+ canCache: false
1490
+ });
1399
1491
  anthropicContent.push({
1400
1492
  type: "redacted_thinking",
1401
- data: reasoningMetadata.redactedData,
1402
- cache_control: cacheControl
1493
+ data: reasoningMetadata.redactedData
1403
1494
  });
1404
1495
  } else {
1405
1496
  warnings.push({
@@ -1766,7 +1857,7 @@ var AnthropicMessagesLanguageModel = class {
1766
1857
  toolChoice,
1767
1858
  providerOptions
1768
1859
  }) {
1769
- var _a, _b, _c;
1860
+ var _a, _b, _c, _d;
1770
1861
  const warnings = [];
1771
1862
  if (frequencyPenalty != null) {
1772
1863
  warnings.push({
@@ -1812,10 +1903,12 @@ var AnthropicMessagesLanguageModel = class {
1812
1903
  providerOptions,
1813
1904
  schema: anthropicProviderOptions
1814
1905
  });
1906
+ const cacheControlValidator = new CacheControlValidator();
1815
1907
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
1816
1908
  prompt,
1817
1909
  sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
1818
- warnings
1910
+ warnings,
1911
+ cacheControlValidator
1819
1912
  });
1820
1913
  const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
1821
1914
  const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
@@ -1847,6 +1940,17 @@ var AnthropicMessagesLanguageModel = class {
1847
1940
  } : void 0
1848
1941
  }))
1849
1942
  },
1943
+ // container with agent skills:
1944
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
1945
+ container: {
1946
+ id: anthropicOptions.container.id,
1947
+ skills: (_d = anthropicOptions.container.skills) == null ? void 0 : _d.map((skill) => ({
1948
+ type: skill.type,
1949
+ skill_id: skill.skillId,
1950
+ version: skill.version
1951
+ }))
1952
+ }
1953
+ },
1850
1954
  // prompt:
1851
1955
  system: messagesPrompt.system,
1852
1956
  messages: messagesPrompt.messages
@@ -1896,6 +2000,19 @@ var AnthropicMessagesLanguageModel = class {
1896
2000
  if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
1897
2001
  betas.add("mcp-client-2025-04-04");
1898
2002
  }
2003
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.container) && anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0) {
2004
+ betas.add("code-execution-2025-08-25");
2005
+ betas.add("skills-2025-10-02");
2006
+ betas.add("files-api-2025-04-14");
2007
+ if (!(tools == null ? void 0 : tools.some(
2008
+ (tool) => tool.type === "provider-defined" && tool.id === "anthropic.code_execution_20250825"
2009
+ ))) {
2010
+ warnings.push({
2011
+ type: "other",
2012
+ message: "code execution tool is required when using skills"
2013
+ });
2014
+ }
2015
+ }
1899
2016
  const {
1900
2017
  tools: anthropicTools2,
1901
2018
  toolChoice: anthropicToolChoice,
@@ -1905,20 +2022,23 @@ var AnthropicMessagesLanguageModel = class {
1905
2022
  jsonResponseTool != null ? {
1906
2023
  tools: [jsonResponseTool],
1907
2024
  toolChoice: { type: "tool", toolName: jsonResponseTool.name },
1908
- disableParallelToolUse: true
2025
+ disableParallelToolUse: true,
2026
+ cacheControlValidator
1909
2027
  } : {
1910
2028
  tools: tools != null ? tools : [],
1911
2029
  toolChoice,
1912
- disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
2030
+ disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
2031
+ cacheControlValidator
1913
2032
  }
1914
2033
  );
2034
+ const cacheWarnings = cacheControlValidator.getWarnings();
1915
2035
  return {
1916
2036
  args: {
1917
2037
  ...baseArgs,
1918
2038
  tools: anthropicTools2,
1919
2039
  tool_choice: anthropicToolChoice
1920
2040
  },
1921
- warnings: [...warnings, ...toolWarnings],
2041
+ warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
1922
2042
  betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas]),
1923
2043
  usesJsonResponseTool: jsonResponseTool != null
1924
2044
  };