@ai-sdk/anthropic 4.0.46 → 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,22 @@
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
+
11
+ ## 4.0.47
12
+
13
+ ### Patch Changes
14
+
15
+ - 5190b67: feat(provider): extend the FilesV4 interface with optional `getFileMetadata`, `downloadFile` (streaming), and `deleteFile` operations, plus `abortSignal`/`headers` call options and a `{ type: 'stream' }` upload data variant; upload results now expose `byteSize`, `createdAt`, and `expiresAt` (also surfaced by the core `uploadFile()` helper, which now forwards `abortSignal`/`headers`); add `postMultipartStreamToApi` (streaming multipart uploads with deterministic part ordering and failure-path stream teardown), `deleteFromApi`, and `createBinaryStreamResponseHandler` to provider-utils
16
+ - Updated dependencies [5190b67]
17
+ - @ai-sdk/provider@4.0.10
18
+ - @ai-sdk/provider-utils@5.0.35
19
+
3
20
  ## 4.0.46
4
21
 
5
22
  ### 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
@@ -71,7 +71,9 @@ var AnthropicFiles = class {
71
71
  async uploadFile({
72
72
  data,
73
73
  mediaType,
74
- filename
74
+ filename,
75
+ abortSignal,
76
+ headers
75
77
  }) {
76
78
  var _a, _b;
77
79
  const fileBytes = convertInlineFileDataToUint8Array(data);
@@ -84,14 +86,17 @@ var AnthropicFiles = class {
84
86
  }
85
87
  const { value: response } = await postFormDataToApi({
86
88
  url: `${this.config.baseURL}/files`,
87
- headers: combineHeaders(this.config.headers(), {
88
- "anthropic-beta": "files-api-2025-04-14"
89
- }),
89
+ headers: combineHeaders(
90
+ this.config.headers(),
91
+ { "anthropic-beta": "files-api-2025-04-14" },
92
+ headers
93
+ ),
90
94
  formData,
91
95
  failedResponseHandler: anthropicFailedResponseHandler,
92
96
  successfulResponseHandler: createJsonResponseHandler(
93
97
  anthropicUploadFileResponseSchema
94
98
  ),
99
+ abortSignal,
95
100
  fetch: this.config.fetch
96
101
  });
97
102
  return {
@@ -993,6 +998,20 @@ var anthropicFilePartProviderOptions = z4.object({
993
998
  context: z4.string().optional()
994
999
  });
995
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(),
996
1015
  /**
997
1016
  * Mid-conversation tool changes. Adds or removes tools from the
998
1017
  * conversation's tool set between turns without invalidating the prompt
@@ -1041,24 +1060,40 @@ var anthropicLanguageModelOptions = z4.object({
1041
1060
  * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
1042
1061
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
1043
1062
  */
1044
- thinking: z4.discriminatedUnion("type", [
1045
- z4.object({
1046
- /** for Sonnet 4.6, Opus 4.6, and newer models */
1047
- type: z4.literal("adaptive"),
1048
- /**
1049
- * Controls whether thinking content is included in the response.
1050
- * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
1051
- * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
1052
- */
1053
- display: z4.enum(["omitted", "summarized"]).optional()
1054
- }),
1055
- z4.object({
1056
- /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
1057
- type: z4.literal("enabled"),
1058
- budgetTokens: z4.number().optional()
1059
- }),
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
+ ]),
1060
1092
  z4.object({
1061
- type: z4.literal("disabled")
1093
+ type: z4.never().optional(),
1094
+ blockBinding: z4.object({
1095
+ prefixMismatchBehavior: z4.literal("drop_block")
1096
+ })
1062
1097
  })
1063
1098
  ]).optional(),
1064
1099
  /**
@@ -2475,8 +2510,7 @@ async function convertToAnthropicPrompt({
2475
2510
  const type = block.type;
2476
2511
  switch (type) {
2477
2512
  case "system": {
2478
- const content = [];
2479
- let toolChangeCount = 0;
2513
+ const convertedMessages = [];
2480
2514
  for (const { content: text, providerOptions } of block.messages) {
2481
2515
  const systemMessageOptions = await parseProviderOptions({
2482
2516
  provider: "anthropic",
@@ -2484,7 +2518,8 @@ async function convertToAnthropicPrompt({
2484
2518
  schema: anthropicSystemMessageProviderOptions
2485
2519
  });
2486
2520
  const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
2487
- 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) {
2488
2523
  content.push({
2489
2524
  type: "text",
2490
2525
  text,
@@ -2495,7 +2530,6 @@ async function convertToAnthropicPrompt({
2495
2530
  });
2496
2531
  }
2497
2532
  for (const toolChange of toolChanges) {
2498
- toolChangeCount++;
2499
2533
  content.push({
2500
2534
  type: toolChange.type,
2501
2535
  tool: {
@@ -2504,22 +2538,60 @@ async function convertToAnthropicPrompt({
2504
2538
  }
2505
2539
  });
2506
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
+ });
2507
2547
  }
2508
- 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) {
2509
2556
  if (toolChangeCount > 0) {
2510
2557
  warnings.push({
2511
2558
  type: "other",
2512
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."
2513
2560
  });
2514
2561
  }
2515
- system = content.filter(
2516
- (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
+ )
2517
2574
  );
2518
2575
  } else {
2519
- messages.push({ role: "system", content });
2520
2576
  betas.add("mid-conversation-system-2026-04-07");
2521
- if (toolChangeCount > 0) {
2522
- 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
+ }
2523
2595
  }
2524
2596
  }
2525
2597
  break;
@@ -3940,7 +4012,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3940
4012
  }
3941
4013
  const thinkingType = (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.type;
3942
4014
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
3943
- 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;
3944
4017
  let thinkingBudget = thinkingType === "enabled" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.budgetTokens : void 0;
3945
4018
  const thinkingDisplay = thinkingType === "adaptive" ? (_i = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _i.display : void 0;
3946
4019
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
@@ -3956,9 +4029,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3956
4029
  // provider specific settings:
3957
4030
  ...sendThinking && {
3958
4031
  thinking: {
3959
- type: thinkingType,
4032
+ ...thinkingType != null && { type: thinkingType },
3960
4033
  ...thinkingBudget != null && { budget_tokens: thinkingBudget },
3961
- ...thinkingDisplay != null && { display: thinkingDisplay }
4034
+ ...thinkingDisplay != null && { display: thinkingDisplay },
4035
+ ...thinkingBlockBinding != null && {
4036
+ block_binding: {
4037
+ prefix_mismatch_behavior: thinkingBlockBinding.prefixMismatchBehavior
4038
+ }
4039
+ }
3962
4040
  }
3963
4041
  },
3964
4042
  ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
@@ -4174,6 +4252,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4174
4252
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
4175
4253
  betas.add("fast-mode-2026-02-01");
4176
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
+ }
4177
4261
  if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) === "default") {
4178
4262
  betas.add("server-side-fallback-2026-07-01");
4179
4263
  } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
@@ -7479,7 +7563,7 @@ var AnthropicSkills = class {
7479
7563
  };
7480
7564
 
7481
7565
  // src/version.ts
7482
- var VERSION = true ? "4.0.46" : "0.0.0-test";
7566
+ var VERSION = true ? "4.0.48" : "0.0.0-test";
7483
7567
 
7484
7568
  // src/anthropic-provider.ts
7485
7569
  var ANTHROPIC_API_URL = "https://api.anthropic.com";