@ai-sdk/anthropic 4.0.47 → 4.0.48

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,13 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 4.0.48
4
+
5
+ ### Patch Changes
6
+
7
+ - 4d25a08: feat(anthropic): add fable 5.1 support
8
+ - Updated dependencies [6bcc0f8]
9
+ - @ai-sdk/provider-utils@5.0.36
10
+
3
11
  ## 4.0.47
4
12
 
5
13
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -183,11 +183,19 @@ interface AnthropicMessageMetadata {
183
183
  } | null;
184
184
  }
185
185
 
186
- type AnthropicModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
186
+ type AnthropicModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | (string & {});
187
187
  /**
188
188
  * Anthropic provider options for system messages.
189
189
  */
190
190
  declare const anthropicSystemMessageProviderOptions: z.ZodObject<{
191
+ clearAt: z.ZodOptional<z.ZodLiteral<"next_user_message">>;
192
+ effort: z.ZodOptional<z.ZodEnum<{
193
+ low: "low";
194
+ medium: "medium";
195
+ high: "high";
196
+ xhigh: "xhigh";
197
+ max: "max";
198
+ }>>;
191
199
  toolChanges: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
192
200
  type: z.ZodLiteral<"tool_addition">;
193
201
  toolName: z.ZodString;
@@ -204,17 +212,26 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
204
212
  jsonTool: "jsonTool";
205
213
  auto: "auto";
206
214
  }>>;
207
- thinking: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
215
+ thinking: z.ZodOptional<z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject<{
208
216
  type: z.ZodLiteral<"adaptive">;
209
217
  display: z.ZodOptional<z.ZodEnum<{
210
218
  omitted: "omitted";
211
219
  summarized: "summarized";
220
+ updates: "updates";
212
221
  }>>;
222
+ blockBinding: z.ZodOptional<z.ZodObject<{
223
+ prefixMismatchBehavior: z.ZodLiteral<"drop_block">;
224
+ }, z.core.$strip>>;
213
225
  }, z.core.$strip>, z.ZodObject<{
214
226
  type: z.ZodLiteral<"enabled">;
215
227
  budgetTokens: z.ZodOptional<z.ZodNumber>;
216
228
  }, z.core.$strip>, z.ZodObject<{
217
229
  type: z.ZodLiteral<"disabled">;
230
+ }, z.core.$strip>]>, z.ZodObject<{
231
+ type: z.ZodOptional<z.ZodNever>;
232
+ blockBinding: z.ZodObject<{
233
+ prefixMismatchBehavior: z.ZodLiteral<"drop_block">;
234
+ }, z.core.$strip>;
218
235
  }, z.core.$strip>]>>;
219
236
  disableParallelToolUse: z.ZodOptional<z.ZodBoolean>;
220
237
  cacheControl: z.ZodOptional<z.ZodObject<{
package/dist/index.js CHANGED
@@ -998,6 +998,20 @@ var anthropicFilePartProviderOptions = z4.object({
998
998
  context: z4.string().optional()
999
999
  });
1000
1000
  var anthropicSystemMessageProviderOptions = z4.object({
1001
+ /**
1002
+ * Controls when an ephemeral mid-conversation system message is cleared.
1003
+ *
1004
+ * Only supported on system messages that appear mid-conversation.
1005
+ * The required `mid-conversation-system-clear-at-2026-08-21` beta is
1006
+ * added automatically.
1007
+ */
1008
+ clearAt: z4.literal("next_user_message").optional(),
1009
+ /**
1010
+ * Sets the model effort for the turn that follows this mid-conversation
1011
+ * system message. The required `mid-conversation-effort-2026-08-01` beta
1012
+ * is added automatically.
1013
+ */
1014
+ effort: z4.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
1001
1015
  /**
1002
1016
  * Mid-conversation tool changes. Adds or removes tools from the
1003
1017
  * conversation's tool set between turns without invalidating the prompt
@@ -1046,24 +1060,40 @@ var anthropicLanguageModelOptions = z4.object({
1046
1060
  * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
1047
1061
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
1048
1062
  */
1049
- thinking: z4.discriminatedUnion("type", [
1050
- z4.object({
1051
- /** for Sonnet 4.6, Opus 4.6, and newer models */
1052
- type: z4.literal("adaptive"),
1053
- /**
1054
- * Controls whether thinking content is included in the response.
1055
- * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
1056
- * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
1057
- */
1058
- display: z4.enum(["omitted", "summarized"]).optional()
1059
- }),
1060
- z4.object({
1061
- /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
1062
- type: z4.literal("enabled"),
1063
- budgetTokens: z4.number().optional()
1064
- }),
1063
+ thinking: z4.union([
1064
+ z4.discriminatedUnion("type", [
1065
+ z4.object({
1066
+ /** for Sonnet 4.6, Opus 4.6, and newer models */
1067
+ type: z4.literal("adaptive"),
1068
+ /**
1069
+ * Controls whether thinking content is included in the response.
1070
+ * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
1071
+ * - `"summarized"`: Thinking content is returned.
1072
+ * - `"updates"`: Thinking updates are returned between tool calls.
1073
+ */
1074
+ display: z4.enum(["omitted", "summarized", "updates"]).optional(),
1075
+ /**
1076
+ * Controls how thinking blocks are bound to an existing thinking
1077
+ * prefix. Requires the `thinking-binding-controls-2026-08-01` beta.
1078
+ */
1079
+ blockBinding: z4.object({
1080
+ prefixMismatchBehavior: z4.literal("drop_block")
1081
+ }).optional()
1082
+ }),
1083
+ z4.object({
1084
+ /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
1085
+ type: z4.literal("enabled"),
1086
+ budgetTokens: z4.number().optional()
1087
+ }),
1088
+ z4.object({
1089
+ type: z4.literal("disabled")
1090
+ })
1091
+ ]),
1065
1092
  z4.object({
1066
- type: z4.literal("disabled")
1093
+ type: z4.never().optional(),
1094
+ blockBinding: z4.object({
1095
+ prefixMismatchBehavior: z4.literal("drop_block")
1096
+ })
1067
1097
  })
1068
1098
  ]).optional(),
1069
1099
  /**
@@ -2480,8 +2510,7 @@ async function convertToAnthropicPrompt({
2480
2510
  const type = block.type;
2481
2511
  switch (type) {
2482
2512
  case "system": {
2483
- const content = [];
2484
- let toolChangeCount = 0;
2513
+ const convertedMessages = [];
2485
2514
  for (const { content: text, providerOptions } of block.messages) {
2486
2515
  const systemMessageOptions = await parseProviderOptions({
2487
2516
  provider: "anthropic",
@@ -2489,7 +2518,8 @@ async function convertToAnthropicPrompt({
2489
2518
  schema: anthropicSystemMessageProviderOptions
2490
2519
  });
2491
2520
  const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
2492
- if (text !== "" || toolChanges.length === 0) {
2521
+ const content = [];
2522
+ if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
2493
2523
  content.push({
2494
2524
  type: "text",
2495
2525
  text,
@@ -2500,7 +2530,6 @@ async function convertToAnthropicPrompt({
2500
2530
  });
2501
2531
  }
2502
2532
  for (const toolChange of toolChanges) {
2503
- toolChangeCount++;
2504
2533
  content.push({
2505
2534
  type: toolChange.type,
2506
2535
  tool: {
@@ -2509,22 +2538,60 @@ async function convertToAnthropicPrompt({
2509
2538
  }
2510
2539
  });
2511
2540
  }
2541
+ convertedMessages.push({
2542
+ content,
2543
+ clearAt: systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt,
2544
+ effort: systemMessageOptions == null ? void 0 : systemMessageOptions.effort,
2545
+ toolChangeCount: toolChanges.length
2546
+ });
2512
2547
  }
2513
- if (i === 0 || system == null && toolChangeCount === 0) {
2548
+ const toolChangeCount = convertedMessages.reduce(
2549
+ (count, message) => count + message.toolChangeCount,
2550
+ 0
2551
+ );
2552
+ const hasInlineSystemOptions = convertedMessages.some(
2553
+ (message) => message.clearAt != null || message.effort != null
2554
+ );
2555
+ if (i === 0 || system == null && toolChangeCount === 0 && !hasInlineSystemOptions) {
2514
2556
  if (toolChangeCount > 0) {
2515
2557
  warnings.push({
2516
2558
  type: "other",
2517
2559
  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."
2518
2560
  });
2519
2561
  }
2520
- system = content.filter(
2521
- (part) => part.type === "text"
2562
+ for (const message of convertedMessages) {
2563
+ if (message.clearAt != null || message.effort != null) {
2564
+ warnings.push({
2565
+ type: "other",
2566
+ message: "clearAt and effort on the initial system message are not supported by Anthropic. These options have been ignored."
2567
+ });
2568
+ }
2569
+ }
2570
+ system = convertedMessages.flatMap(
2571
+ (message) => message.content.filter(
2572
+ (part) => part.type === "text"
2573
+ )
2522
2574
  );
2523
2575
  } else {
2524
- messages.push({ role: "system", content });
2525
2576
  betas.add("mid-conversation-system-2026-04-07");
2526
- if (toolChangeCount > 0) {
2527
- betas.add("mid-conversation-tool-changes-2026-07-01");
2577
+ for (const message of convertedMessages) {
2578
+ messages.push({
2579
+ role: "system",
2580
+ content: message.content,
2581
+ ...message.clearAt != null && { clear_at: message.clearAt },
2582
+ ...message.effort != null && {
2583
+ output_config: { effort: message.effort }
2584
+ }
2585
+ });
2586
+ if (message.toolChangeCount > 0) {
2587
+ betas.add("mid-conversation-tool-changes-2026-07-01");
2588
+ }
2589
+ if (message.clearAt != null) {
2590
+ betas.add("mid-conversation-system-clear-at-2026-08-21");
2591
+ }
2592
+ if (message.effort != null) {
2593
+ betas.add("mid-conversation-effort-2026-08-01");
2594
+ }
2528
2595
  }
2529
2596
  }
2530
2597
  break;
@@ -3945,7 +4012,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3945
4012
  }
3946
4013
  const thinkingType = (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.type;
3947
4014
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
3948
- const sendThinking = isThinking || thinkingType === "disabled";
4015
+ const thinkingBlockBinding = (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null && "blockBinding" in anthropicOptions.thinking ? anthropicOptions.thinking.blockBinding : void 0;
4016
+ const sendThinking = isThinking || thinkingType === "disabled" || thinkingBlockBinding != null;
3949
4017
  let thinkingBudget = thinkingType === "enabled" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.budgetTokens : void 0;
3950
4018
  const thinkingDisplay = thinkingType === "adaptive" ? (_i = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _i.display : void 0;
3951
4019
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
@@ -3961,9 +4029,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3961
4029
  // provider specific settings:
3962
4030
  ...sendThinking && {
3963
4031
  thinking: {
3964
- type: thinkingType,
4032
+ ...thinkingType != null && { type: thinkingType },
3965
4033
  ...thinkingBudget != null && { budget_tokens: thinkingBudget },
3966
- ...thinkingDisplay != null && { display: thinkingDisplay }
4034
+ ...thinkingDisplay != null && { display: thinkingDisplay },
4035
+ ...thinkingBlockBinding != null && {
4036
+ block_binding: {
4037
+ prefix_mismatch_behavior: thinkingBlockBinding.prefixMismatchBehavior
4038
+ }
4039
+ }
3967
4040
  }
3968
4041
  },
3969
4042
  ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
@@ -4179,6 +4252,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4179
4252
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
4180
4253
  betas.add("fast-mode-2026-02-01");
4181
4254
  }
4255
+ if (thinkingDisplay === "updates") {
4256
+ betas.add("thinking-display-updates-2026-08-18");
4257
+ }
4258
+ if (thinkingBlockBinding != null) {
4259
+ betas.add("thinking-binding-controls-2026-08-01");
4260
+ }
4182
4261
  if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) === "default") {
4183
4262
  betas.add("server-side-fallback-2026-07-01");
4184
4263
  } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
@@ -7484,7 +7563,7 @@ var AnthropicSkills = class {
7484
7563
  };
7485
7564
 
7486
7565
  // src/version.ts
7487
- var VERSION = true ? "4.0.47" : "0.0.0-test";
7566
+ var VERSION = true ? "4.0.48" : "0.0.0-test";
7488
7567
 
7489
7568
  // src/anthropic-provider.ts
7490
7569
  var ANTHROPIC_API_URL = "https://api.anthropic.com";