@ai-sdk/anthropic 4.0.110 → 4.0.112

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 4.0.112
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [743e15b]
8
+ - @ai-sdk/provider-utils@5.0.86
9
+
10
+ ## 4.0.111
11
+
12
+ ### Patch Changes
13
+
14
+ - 55d9909: fix(anthropic): keep the cache control of mid-conversation system messages that carry only tool changes, and add the `midConversationSystemMessages` option to keep a later system message in place when no system message comes before it
15
+
3
16
  ## 4.0.110
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1093,6 +1093,7 @@ declare const anthropicLanguageModelOptions: import("@ai-sdk/provider-utils").La
1093
1093
  sendReasoning?: boolean | undefined;
1094
1094
  structuredOutputMode?: "outputFormat" | "jsonTool" | "auto" | undefined;
1095
1095
  includePings?: boolean | undefined;
1096
+ midConversationSystemMessages?: boolean | undefined;
1096
1097
  thinking?: {
1097
1098
  type: "adaptive";
1098
1099
  display?: "omitted" | "summarized" | "updates" | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["SandboxSession","SandboxSession","_$__tool_computer_toolset_202608010.ComputerToolset_20260801Member","DecisionModelV4","ExtractionModelV4","BatchV4"],"sources":["../src/anthropic-api.ts","../src/anthropic-message-metadata.ts","../src/anthropic-provider-metadata.ts","../src/anthropic-model-catalog.ts","../src/anthropic-language-model-options.ts","../src/anthropic-prepare-tools.ts","../src/tool/computer-toolset_20260801.ts","../src/tool/bash_20241022.ts","../src/tool/bash_20250124.ts","../src/anthropic-tools.ts","../src/anthropic-provider.ts","../src/forward-anthropic-container-id-from-last-step.ts","../src/version.ts"],"mappings":";;;;cAgtBM,sCAA8B,EAAA;;;;;;;;;;GAgBhC,EAAA,KAAA;KAEQ,2BAA2B,E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;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAQP;MACF;MACJ;MAEwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAJlB;MACF;MACJ;MAEwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAHxB;MACA;MAEa;MACK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UCAJ,0BAA0B;;;;GAIxC,SAAS,mBAAmB;;;;EAK7B,cAAc,SAAS,mBAAmB;EAE1C,KAAK,SAAS,mBAAmB;EAEjC,SAAS,SAAS,mBAAmB;;EAGrC,cAAc,SAAS,mBAAmBE;;EAE1C,gBAAgB,SAAS,mBAAmBA;IAC1C,YAAYA;;;EAId,gBAAgB,SAAS,mBAAmBC;EAE5C,sBAAsBC;IAAU,MAAM;;;;;EAKtC,mBAAmB;EAEnB,SAAS;;;;EAKT,UAAU;;;;EAKV,cAAc;;UAGC;;EAEf;;IAEE;;;;;;EAOF;;;;;;EAOA;;;;;;;EAQA,YAAY;;;;EAKZ,UAAU;;;;;EAMV,QAAQ;EAER;;;;;EAMA;;;;;wBAMc,gBACd,UAAS,4BACR;;;;qBA6IU,WAAS;;;;;;;;;;wBClRN,0CACd;EAEA,OAAO;IACL,mBAAmB,eAAe;;;EAEpB,kBAAkB,eAAe;;;;qBCdtC"}
1
+ {"version":3,"file":"index.d.ts","names":["SandboxSession","SandboxSession","_$__tool_computer_toolset_202608010.ComputerToolset_20260801Member","DecisionModelV4","ExtractionModelV4","BatchV4"],"sources":["../src/anthropic-api.ts","../src/anthropic-message-metadata.ts","../src/anthropic-provider-metadata.ts","../src/anthropic-model-catalog.ts","../src/anthropic-language-model-options.ts","../src/anthropic-prepare-tools.ts","../src/tool/computer-toolset_20260801.ts","../src/tool/bash_20241022.ts","../src/tool/bash_20250124.ts","../src/anthropic-tools.ts","../src/anthropic-provider.ts","../src/forward-anthropic-container-id-from-last-step.ts","../src/version.ts"],"mappings":";;;;cAgtBM,sCAA8B,EAAA;;;;;;;;;;GAgBhC,EAAA,KAAA;KAEQ,2BAA2B,EAAE,MACvC,kBAAkB;cA2FP,0DAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAqwBxB,WAAW,aACpB,mBAAmB;EAClB;;;;;;;;;;;;;;;;;;;KCnjDQ;EACV;;;;;;EAOA;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;;UAGe;EACf,OAAO;EACP;;EAGA;;;;;;;EAQA,uBAAuB;IACrB;IACA;IACA;;;;;;;;;;;;;EAcF,mBAAmB;;;;;;;;;;EAWnB;;;;;IAKE;;;;;IAMA;;;;;IAMA;;;;;;IAOA;;;;;;;;;EAUF,YAAY;;;;;;;EAQZ;;;;IAIE;;;;IAKA;;;;IAKA,QAAQ;;;;MAIN;;;;MAKA;;;;MAKA;;;;;;;;EASJ;;;;;IAKE,cAAc;;;;;;;;;MASR;;;;;MAMA;;;;;MAMA;;;;;;;;;;MAUA;;;;;MAMA;;;;;MAMA;;;;;;;;;;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MA;;;;;wBAMc,gBACd,UAAS,4BACR;;;;qBA6IU,WAAS;;;;;;;;;;wBClRN,0CACd;EAEA,OAAO;IACL,mBAAmB,eAAe;;;EAEpB,kBAAkB,eAAe;;;;qBCdtC"}
package/dist/index.js CHANGED
@@ -159,6 +159,7 @@ const anthropicProviderOptions = { language: {
159
159
  thread: { description: "Create or continue a short-lived message thread." },
160
160
  sendReasoning: { description: "Whether to send reasoning to the model." },
161
161
  includePings: { description: "Include transient ping events in streams." },
162
+ midConversationSystemMessages: { description: "Keep later system messages in the conversation." },
162
163
  structuredOutputMode: { description: "How structured outputs are generated." },
163
164
  thinking: { description: "Extended thinking configuration." },
164
165
  disableParallelToolUse: { description: "Use at most one tool per response." },
@@ -1787,6 +1788,15 @@ const anthropicLanguageModelOptions = lazySchema(() => zodSchema(z.object({
1787
1788
  /** Emit typed streaming heartbeat parts. Disabled by default. */
1788
1789
  includePings: z.boolean().optional(),
1789
1790
  /**
1791
+ * Keep a system message that follows user or assistant messages in the
1792
+ * `messages` array, even when no system message comes before it. By
1793
+ * default the first system message becomes the top-level `system`
1794
+ * prompt wherever it appears, which models without mid-conversation
1795
+ * system message support require. Enable this only for models that
1796
+ * support mid-conversation system messages.
1797
+ */
1798
+ midConversationSystemMessages: z.boolean().optional(),
1799
+ /**
1790
1800
  * Configuration for enabling Claude's extended thinking.
1791
1801
  *
1792
1802
  * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
@@ -3214,7 +3224,7 @@ async function getInlineToolsFromPrompt(prompt) {
3214
3224
  }
3215
3225
  return inlineTools;
3216
3226
  }
3217
- async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cacheControlValidator, toolNameMapping, toolsetNames = {}, convertMediaPart, convertInlineTool }) {
3227
+ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cacheControlValidator, toolNameMapping, toolsetNames = {}, convertMediaPart, convertInlineTool, keepMidConversationSystemMessages = false }) {
3218
3228
  const betas = /* @__PURE__ */ new Set();
3219
3229
  const blocks = groupIntoBlocks(prompt);
3220
3230
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -3261,7 +3271,8 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
3261
3271
  });
3262
3272
  const toolChanges = systemMessageOptions?.toolChanges ?? [];
3263
3273
  const content = [];
3264
- if (text !== "" || toolChanges.length === 0 && systemMessageOptions?.clearAt == null && systemMessageOptions?.effort == null) content.push({
3274
+ const emitsText = text !== "" || toolChanges.length === 0 && systemMessageOptions?.clearAt == null && systemMessageOptions?.effort == null;
3275
+ if (emitsText) content.push({
3265
3276
  type: "text",
3266
3277
  text,
3267
3278
  cache_control: validator.getCacheControl(providerOptions, {
@@ -3306,6 +3317,15 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
3306
3317
  });
3307
3318
  toolChangeCount++;
3308
3319
  }
3320
+ const lastToolChange = content.at(-1);
3321
+ const definesOwnCacheControl = lastToolChange?.type === "tool_addition" && lastToolChange.tool.type === "tool_definition" && "cache_control" in lastToolChange.tool.definition && lastToolChange.tool.definition.cache_control != null;
3322
+ if (!emitsText && lastToolChange != null && !definesOwnCacheControl) {
3323
+ const cacheControl = validator.getCacheControl(providerOptions, {
3324
+ type: "system message",
3325
+ canCache: true
3326
+ });
3327
+ if (cacheControl != null) lastToolChange.cache_control = cacheControl;
3328
+ }
3309
3329
  if (content.length === 0 && systemMessageOptions?.clearAt == null && systemMessageOptions?.effort == null) continue;
3310
3330
  convertedMessages.push({
3311
3331
  content,
@@ -3317,7 +3337,7 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
3317
3337
  }
3318
3338
  const toolChangeCount = convertedMessages.reduce((count, message) => count + message.toolChangeCount, 0);
3319
3339
  const hasInlineSystemOptions = convertedMessages.some((message) => message.clearAt != null || message.effort != null);
3320
- if (i === 0 || system == null && toolChangeCount === 0 && !hasInlineSystemOptions) {
3340
+ if (i === 0 || !keepMidConversationSystemMessages && system == null && toolChangeCount === 0 && !hasInlineSystemOptions) {
3321
3341
  if (toolChangeCount > 0) warnings.push({
3322
3342
  type: "other",
3323
3343
  message: "tool changes on the initial system message are not supported by Anthropic. Configure the initial tool set via the tools option instead. The tool changes have been ignored."
@@ -4919,6 +4939,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
4919
4939
  toolNameMapping,
4920
4940
  toolsetNames,
4921
4941
  convertMediaPart: config.convertMediaPart,
4942
+ keepMidConversationSystemMessages: anthropicOptions?.midConversationSystemMessages ?? false,
4922
4943
  convertInlineTool: async (tool) => {
4923
4944
  const { tools: definitions, toolWarnings, betas } = await prepareTools({
4924
4945
  tools: [tool],
@@ -8130,7 +8151,7 @@ var AnthropicSkills = class {
8130
8151
  };
8131
8152
  //#endregion
8132
8153
  //#region src/version.ts
8133
- const VERSION = "4.0.110";
8154
+ const VERSION = "4.0.112";
8134
8155
  //#endregion
8135
8156
  //#region src/anthropic-provider.ts
8136
8157
  const ANTHROPIC_API_URL = "https://api.anthropic.com";