@ai-sdk/anthropic 3.0.114 → 3.0.116

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
+ ## 3.0.116
4
+
5
+ ### Patch Changes
6
+
7
+ - 57d88f5: feat(anthropic): add fable 5.1 support
8
+
9
+ ## 3.0.115
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [cc23556]
14
+ - @ai-sdk/provider-utils@4.0.50
15
+
3
16
  ## 3.0.114
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -184,11 +184,19 @@ interface AnthropicMessageMetadata {
184
184
  } | null;
185
185
  }
186
186
 
187
- type AnthropicMessagesModelId = '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 & {});
187
+ type AnthropicMessagesModelId = '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 & {});
188
188
  /**
189
189
  * Anthropic provider options for system messages.
190
190
  */
191
191
  declare const anthropicSystemMessageProviderOptions: z.ZodObject<{
192
+ clearAt: z.ZodOptional<z.ZodLiteral<"next_user_message">>;
193
+ effort: z.ZodOptional<z.ZodEnum<{
194
+ low: "low";
195
+ medium: "medium";
196
+ high: "high";
197
+ xhigh: "xhigh";
198
+ max: "max";
199
+ }>>;
192
200
  toolChanges: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
193
201
  type: z.ZodLiteral<"tool_addition">;
194
202
  toolName: z.ZodString;
@@ -205,17 +213,25 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
205
213
  jsonTool: "jsonTool";
206
214
  auto: "auto";
207
215
  }>>;
208
- thinking: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
216
+ thinking: z.ZodOptional<z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject<{
209
217
  type: z.ZodLiteral<"adaptive">;
210
218
  display: z.ZodOptional<z.ZodEnum<{
211
219
  omitted: "omitted";
212
220
  summarized: "summarized";
221
+ updates: "updates";
213
222
  }>>;
223
+ blockBinding: z.ZodOptional<z.ZodObject<{
224
+ prefixMismatchBehavior: z.ZodLiteral<"drop_block">;
225
+ }, z.core.$strip>>;
214
226
  }, z.core.$strip>, z.ZodObject<{
215
227
  type: z.ZodLiteral<"enabled">;
216
228
  budgetTokens: z.ZodOptional<z.ZodNumber>;
217
229
  }, z.core.$strip>, z.ZodObject<{
218
230
  type: z.ZodLiteral<"disabled">;
231
+ }, z.core.$strip>]>, z.ZodObject<{
232
+ blockBinding: z.ZodObject<{
233
+ prefixMismatchBehavior: z.ZodLiteral<"drop_block">;
234
+ }, z.core.$strip>;
219
235
  }, z.core.$strip>]>>;
220
236
  disableParallelToolUse: z.ZodOptional<z.ZodBoolean>;
221
237
  cacheControl: z.ZodOptional<z.ZodObject<{
package/dist/index.d.ts CHANGED
@@ -184,11 +184,19 @@ interface AnthropicMessageMetadata {
184
184
  } | null;
185
185
  }
186
186
 
187
- type AnthropicMessagesModelId = '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 & {});
187
+ type AnthropicMessagesModelId = '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 & {});
188
188
  /**
189
189
  * Anthropic provider options for system messages.
190
190
  */
191
191
  declare const anthropicSystemMessageProviderOptions: z.ZodObject<{
192
+ clearAt: z.ZodOptional<z.ZodLiteral<"next_user_message">>;
193
+ effort: z.ZodOptional<z.ZodEnum<{
194
+ low: "low";
195
+ medium: "medium";
196
+ high: "high";
197
+ xhigh: "xhigh";
198
+ max: "max";
199
+ }>>;
192
200
  toolChanges: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
193
201
  type: z.ZodLiteral<"tool_addition">;
194
202
  toolName: z.ZodString;
@@ -205,17 +213,25 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
205
213
  jsonTool: "jsonTool";
206
214
  auto: "auto";
207
215
  }>>;
208
- thinking: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
216
+ thinking: z.ZodOptional<z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject<{
209
217
  type: z.ZodLiteral<"adaptive">;
210
218
  display: z.ZodOptional<z.ZodEnum<{
211
219
  omitted: "omitted";
212
220
  summarized: "summarized";
221
+ updates: "updates";
213
222
  }>>;
223
+ blockBinding: z.ZodOptional<z.ZodObject<{
224
+ prefixMismatchBehavior: z.ZodLiteral<"drop_block">;
225
+ }, z.core.$strip>>;
214
226
  }, z.core.$strip>, z.ZodObject<{
215
227
  type: z.ZodLiteral<"enabled">;
216
228
  budgetTokens: z.ZodOptional<z.ZodNumber>;
217
229
  }, z.core.$strip>, z.ZodObject<{
218
230
  type: z.ZodLiteral<"disabled">;
231
+ }, z.core.$strip>]>, z.ZodObject<{
232
+ blockBinding: z.ZodObject<{
233
+ prefixMismatchBehavior: z.ZodLiteral<"drop_block">;
234
+ }, z.core.$strip>;
219
235
  }, z.core.$strip>]>>;
220
236
  disableParallelToolUse: z.ZodOptional<z.ZodBoolean>;
221
237
  cacheControl: z.ZodOptional<z.ZodObject<{
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
32
32
  var import_provider_utils26 = require("@ai-sdk/provider-utils");
33
33
 
34
34
  // src/version.ts
35
- var VERSION = true ? "3.0.114" : "0.0.0-test";
35
+ var VERSION = true ? "3.0.116" : "0.0.0-test";
36
36
 
37
37
  // src/anthropic-messages-language-model.ts
38
38
  var import_provider3 = require("@ai-sdk/provider");
@@ -866,6 +866,21 @@ var anthropicFilePartProviderOptions = import_v43.z.object({
866
866
  context: import_v43.z.string().optional()
867
867
  });
868
868
  var anthropicSystemMessageProviderOptions = import_v43.z.object({
869
+ /**
870
+ * Clears this mid-conversation system message after the current turn.
871
+ *
872
+ * Requires the `mid-conversation-system-clear-at-2026-08-21` beta,
873
+ * which is added automatically.
874
+ */
875
+ clearAt: import_v43.z.literal("next_user_message").optional(),
876
+ /**
877
+ * Overrides the effort level for the turn following this
878
+ * mid-conversation system message.
879
+ *
880
+ * Requires the `mid-conversation-effort-2026-08-01` beta,
881
+ * which is added automatically.
882
+ */
883
+ effort: import_v43.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
869
884
  /**
870
885
  * Mid-conversation tool changes. Adds or removes tools from the
871
886
  * conversation's tool set between turns without invalidating the prompt
@@ -893,6 +908,9 @@ var anthropicSystemMessageProviderOptions = import_v43.z.object({
893
908
  ])
894
909
  ).optional()
895
910
  });
911
+ var anthropicThinkingBlockBinding = import_v43.z.object({
912
+ prefixMismatchBehavior: import_v43.z.literal("drop_block")
913
+ });
896
914
  var anthropicLanguageModelOptions = import_v43.z.object({
897
915
  /**
898
916
  * Whether to send reasoning to the model.
@@ -914,24 +932,41 @@ var anthropicLanguageModelOptions = import_v43.z.object({
914
932
  * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
915
933
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
916
934
  */
917
- thinking: import_v43.z.discriminatedUnion("type", [
918
- import_v43.z.object({
919
- /** for Sonnet 4.6, Opus 4.6, and newer models */
920
- type: import_v43.z.literal("adaptive"),
921
- /**
922
- * Controls whether thinking content is included in the response.
923
- * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
924
- * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
925
- */
926
- display: import_v43.z.enum(["omitted", "summarized"]).optional()
927
- }),
928
- import_v43.z.object({
929
- /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
930
- type: import_v43.z.literal("enabled"),
931
- budgetTokens: import_v43.z.number().optional()
932
- }),
935
+ thinking: import_v43.z.union([
936
+ import_v43.z.discriminatedUnion("type", [
937
+ import_v43.z.object({
938
+ /** for Sonnet 4.6, Opus 4.6, and newer models */
939
+ type: import_v43.z.literal("adaptive"),
940
+ /**
941
+ * Controls whether thinking content is included in the response.
942
+ * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
943
+ * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
944
+ * - `"updates"`: Thinking updates are returned between tool calls.
945
+ */
946
+ display: import_v43.z.enum(["omitted", "summarized", "updates"]).optional(),
947
+ /**
948
+ * Controls how thinking blocks are bound to an assistant prefix.
949
+ *
950
+ * Requires the `thinking-binding-controls-2026-08-01` beta,
951
+ * which is added automatically.
952
+ */
953
+ blockBinding: anthropicThinkingBlockBinding.optional()
954
+ }),
955
+ import_v43.z.object({
956
+ /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
957
+ type: import_v43.z.literal("enabled"),
958
+ budgetTokens: import_v43.z.number().optional()
959
+ }),
960
+ import_v43.z.object({
961
+ type: import_v43.z.literal("disabled")
962
+ })
963
+ ]),
964
+ /**
965
+ * Configures prefix mismatch recovery without changing the model's
966
+ * default thinking mode.
967
+ */
933
968
  import_v43.z.object({
934
- type: import_v43.z.literal("disabled")
969
+ blockBinding: anthropicThinkingBlockBinding
935
970
  })
936
971
  ]).optional(),
937
972
  /**
@@ -2251,8 +2286,9 @@ async function convertToAnthropicMessagesPrompt({
2251
2286
  const type = block.type;
2252
2287
  switch (type) {
2253
2288
  case "system": {
2254
- const content = [];
2289
+ const systemMessages = [];
2255
2290
  let toolChangeCount = 0;
2291
+ let hasMidConversationOptions = false;
2256
2292
  for (const { content: text, providerOptions } of block.messages) {
2257
2293
  const systemMessageOptions = await (0, import_provider_utils14.parseProviderOptions)({
2258
2294
  provider: "anthropic",
@@ -2260,7 +2296,10 @@ async function convertToAnthropicMessagesPrompt({
2260
2296
  schema: anthropicSystemMessageProviderOptions
2261
2297
  });
2262
2298
  const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
2263
- if (text !== "" || toolChanges.length === 0) {
2299
+ const clearAt = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt;
2300
+ const effort = systemMessageOptions == null ? void 0 : systemMessageOptions.effort;
2301
+ const content = [];
2302
+ if (text !== "" || toolChanges.length === 0 && clearAt == null && effort == null) {
2264
2303
  content.push({
2265
2304
  type: "text",
2266
2305
  text,
@@ -2280,23 +2319,44 @@ async function convertToAnthropicMessagesPrompt({
2280
2319
  }
2281
2320
  });
2282
2321
  }
2322
+ hasMidConversationOptions || (hasMidConversationOptions = clearAt != null || effort != null);
2323
+ systemMessages.push({
2324
+ role: "system",
2325
+ content,
2326
+ ...clearAt != null && { clear_at: clearAt },
2327
+ ...effort != null && { output_config: { effort } }
2328
+ });
2283
2329
  }
2284
- if (i === 0 || system == null && toolChangeCount === 0) {
2330
+ if (i === 0 || system == null && toolChangeCount === 0 && !hasMidConversationOptions) {
2285
2331
  if (toolChangeCount > 0) {
2286
2332
  warnings.push({
2287
2333
  type: "other",
2288
2334
  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."
2289
2335
  });
2290
2336
  }
2291
- system = content.filter(
2292
- (part) => part.type === "text"
2337
+ if (hasMidConversationOptions) {
2338
+ warnings.push({
2339
+ type: "other",
2340
+ message: "clearAt and effort on the initial system message are not supported by Anthropic. Configure these options on a mid-conversation system message instead. The options have been ignored."
2341
+ });
2342
+ }
2343
+ system = systemMessages.flatMap(
2344
+ (message) => message.content.filter(
2345
+ (part) => part.type === "text"
2346
+ )
2293
2347
  );
2294
2348
  } else {
2295
- messages.push({ role: "system", content });
2349
+ messages.push(...systemMessages);
2296
2350
  betas.add("mid-conversation-system-2026-04-07");
2297
2351
  if (toolChangeCount > 0) {
2298
2352
  betas.add("mid-conversation-tool-changes-2026-07-01");
2299
2353
  }
2354
+ if (systemMessages.some((message) => message.clear_at != null)) {
2355
+ betas.add("mid-conversation-system-clear-at-2026-08-21");
2356
+ }
2357
+ if (systemMessages.some((message) => message.output_config != null)) {
2358
+ betas.add("mid-conversation-effort-2026-08-01");
2359
+ }
2300
2360
  }
2301
2361
  break;
2302
2362
  }
@@ -3412,7 +3472,7 @@ var AnthropicMessagesLanguageModel = class {
3412
3472
  providerOptions,
3413
3473
  stream
3414
3474
  }) {
3415
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3475
+ var _a, _b, _c, _d, _e, _f, _g;
3416
3476
  const warnings = [];
3417
3477
  if (frequencyPenalty != null) {
3418
3478
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -3555,7 +3615,9 @@ var AnthropicMessagesLanguageModel = class {
3555
3615
  cacheControlValidator,
3556
3616
  toolNameMapping
3557
3617
  });
3558
- if (rejectsThinkingDisabledAboveHighEffort && ((_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
3618
+ const thinking = anthropicOptions == null ? void 0 : anthropicOptions.thinking;
3619
+ const thinkingType = thinking != null && "type" in thinking ? thinking.type : void 0;
3620
+ if (rejectsThinkingDisabledAboveHighEffort && thinkingType === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
3559
3621
  warnings.push({
3560
3622
  type: "unsupported",
3561
3623
  feature: "providerOptions.anthropic.effort",
@@ -3563,11 +3625,12 @@ var AnthropicMessagesLanguageModel = class {
3563
3625
  });
3564
3626
  anthropicOptions.effort = "high";
3565
3627
  }
3566
- const thinkingType = (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.type;
3567
3628
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
3568
3629
  const sendThinking = isThinking || thinkingType === "disabled";
3569
- let thinkingBudget = thinkingType === "enabled" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.budgetTokens : void 0;
3570
- const thinkingDisplay = thinkingType === "adaptive" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.display : void 0;
3630
+ let thinkingBudget = thinkingType === "enabled" && thinking != null && "budgetTokens" in thinking ? thinking.budgetTokens : void 0;
3631
+ const thinkingDisplay = thinkingType === "adaptive" && thinking != null && "display" in thinking ? thinking.display : void 0;
3632
+ const thinkingBlockBinding = thinking != null && "blockBinding" in thinking ? thinking.blockBinding : void 0;
3633
+ const sendThinkingConfig = sendThinking || thinkingBlockBinding != null;
3571
3634
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
3572
3635
  const baseArgs = {
3573
3636
  // model id:
@@ -3579,11 +3642,16 @@ var AnthropicMessagesLanguageModel = class {
3579
3642
  top_p: topP,
3580
3643
  stop_sequences: stopSequences,
3581
3644
  // provider specific settings:
3582
- ...sendThinking && {
3645
+ ...sendThinkingConfig && {
3583
3646
  thinking: {
3584
- type: thinkingType,
3647
+ ...thinkingType != null && { type: thinkingType },
3585
3648
  ...thinkingBudget != null && { budget_tokens: thinkingBudget },
3586
- ...thinkingDisplay != null && { display: thinkingDisplay }
3649
+ ...thinkingDisplay != null && { display: thinkingDisplay },
3650
+ ...thinkingBlockBinding != null && {
3651
+ block_binding: {
3652
+ prefix_mismatch_behavior: thinkingBlockBinding.prefixMismatchBehavior
3653
+ }
3654
+ }
3587
3655
  }
3588
3656
  },
3589
3657
  ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
@@ -3620,7 +3688,7 @@ var AnthropicMessagesLanguageModel = class {
3620
3688
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
3621
3689
  cache_control: anthropicOptions.cacheControl
3622
3690
  },
3623
- ...((_i = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _i.userId) != null && {
3691
+ ...((_e = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _e.userId) != null && {
3624
3692
  metadata: { user_id: anthropicOptions.metadata.userId }
3625
3693
  },
3626
3694
  // mcp servers:
@@ -3790,6 +3858,12 @@ var AnthropicMessagesLanguageModel = class {
3790
3858
  if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
3791
3859
  betas.add("task-budgets-2026-03-13");
3792
3860
  }
3861
+ if (thinkingDisplay === "updates") {
3862
+ betas.add("thinking-display-updates-2026-08-18");
3863
+ }
3864
+ if (thinkingBlockBinding != null) {
3865
+ betas.add("thinking-binding-controls-2026-08-01");
3866
+ }
3793
3867
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
3794
3868
  betas.add("fast-mode-2026-02-01");
3795
3869
  }
@@ -3798,7 +3872,7 @@ var AnthropicMessagesLanguageModel = class {
3798
3872
  } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
3799
3873
  betas.add("server-side-fallback-2026-06-01");
3800
3874
  }
3801
- const defaultEagerInputStreaming = stream && ((_j = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _j : true);
3875
+ const defaultEagerInputStreaming = stream && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _f : true);
3802
3876
  const {
3803
3877
  tools: anthropicTools2,
3804
3878
  toolChoice: anthropicToolChoice,
@@ -3837,7 +3911,7 @@ var AnthropicMessagesLanguageModel = class {
3837
3911
  ...betas,
3838
3912
  ...toolsBetas,
3839
3913
  ...userSuppliedBetas,
3840
- ...(_k = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _k : []
3914
+ ...(_g = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _g : []
3841
3915
  ]),
3842
3916
  usesJsonResponseTool: jsonResponseTool != null,
3843
3917
  toolNameMapping,