@ai-sdk/anthropic 2.0.99 → 2.0.101

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.js CHANGED
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
31
31
  var import_provider_utils20 = require("@ai-sdk/provider-utils");
32
32
 
33
33
  // src/version.ts
34
- var VERSION = true ? "2.0.99" : "0.0.0-test";
34
+ var VERSION = true ? "2.0.101" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -666,6 +666,19 @@ var anthropicFilePartProviderOptions = import_v43.z.object({
666
666
  context: import_v43.z.string().optional()
667
667
  });
668
668
  var anthropicSystemMessageProviderOptions = import_v43.z.object({
669
+ /**
670
+ * Controls when a mid-conversation system message is cleared.
671
+ *
672
+ * The value is forwarded to Anthropic as `clear_at`. The required
673
+ * `mid-conversation-system-clear-at-2026-08-21` beta is added automatically.
674
+ */
675
+ clearAt: import_v43.z.literal("next_user_message").optional(),
676
+ /**
677
+ * Overrides the effort for the turn following this mid-conversation system
678
+ * message. The required `mid-conversation-effort-2026-08-01` beta is added
679
+ * automatically.
680
+ */
681
+ effort: import_v43.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
669
682
  /**
670
683
  * Mid-conversation tool changes. Adds or removes tools from the
671
684
  * conversation's tool set between turns without invalidating the prompt
@@ -693,6 +706,14 @@ var anthropicSystemMessageProviderOptions = import_v43.z.object({
693
706
  ])
694
707
  ).optional()
695
708
  });
709
+ var anthropicThinkingBlockBinding = import_v43.z.object({
710
+ /**
711
+ * Controls behavior when a replayed thinking block does not match its
712
+ * conversation prefix. The `drop_block` behavior drops the mismatched block
713
+ * instead of returning an invalid signature error.
714
+ */
715
+ prefixMismatchBehavior: import_v43.z.literal("drop_block")
716
+ });
696
717
  var anthropicProviderOptions = import_v43.z.object({
697
718
  /**
698
719
  * Whether to send reasoning to the model.
@@ -704,8 +725,8 @@ var anthropicProviderOptions = import_v43.z.object({
704
725
  * Determines how structured outputs are generated.
705
726
  *
706
727
  * - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
707
- * - `jsonTool`: Use a special 'json' tool to specify the structured output format (default).
708
- * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool'.
728
+ * - `jsonTool`: Use a special JSON response tool to specify the structured output format (default for most models).
729
+ * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default for Fable 5.1).
709
730
  */
710
731
  structuredOutputMode: import_v43.z.enum(["outputFormat", "jsonTool", "auto"]).optional(),
711
732
  /**
@@ -714,7 +735,7 @@ var anthropicProviderOptions = import_v43.z.object({
714
735
  * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
715
736
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
716
737
  */
717
- thinking: import_v43.z.discriminatedUnion("type", [
738
+ thinking: import_v43.z.union([
718
739
  import_v43.z.object({
719
740
  /** for Sonnet 4.6, Opus 4.6, and newer models */
720
741
  type: import_v43.z.literal("adaptive"),
@@ -722,16 +743,34 @@ var anthropicProviderOptions = import_v43.z.object({
722
743
  * Controls whether thinking content is included in the response.
723
744
  * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
724
745
  * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
746
+ * - `"updates"`: Thinking summaries are emitted between tool calls.
725
747
  */
726
- display: import_v43.z.enum(["omitted", "summarized"]).optional()
748
+ display: import_v43.z.enum(["omitted", "summarized", "updates"]).optional(),
749
+ /**
750
+ * Controls handling for thinking blocks whose conversation prefix no
751
+ * longer matches. Forwarded as `block_binding`.
752
+ */
753
+ blockBinding: anthropicThinkingBlockBinding.optional()
727
754
  }),
728
755
  import_v43.z.object({
729
756
  /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
730
757
  type: import_v43.z.literal("enabled"),
731
- budgetTokens: import_v43.z.number().optional()
758
+ budgetTokens: import_v43.z.number().optional(),
759
+ /**
760
+ * Controls handling for thinking blocks whose conversation prefix no
761
+ * longer matches. Forwarded as `block_binding`.
762
+ */
763
+ blockBinding: anthropicThinkingBlockBinding.optional()
732
764
  }),
733
765
  import_v43.z.object({
734
766
  type: import_v43.z.literal("disabled")
767
+ }),
768
+ import_v43.z.object({
769
+ /**
770
+ * Configure prefix mismatch handling without changing the model's
771
+ * default thinking mode.
772
+ */
773
+ blockBinding: anthropicThinkingBlockBinding
735
774
  })
736
775
  ]).optional(),
737
776
  /**
@@ -1474,7 +1513,7 @@ async function convertToAnthropicMessagesPrompt({
1474
1513
  warnings,
1475
1514
  cacheControlValidator
1476
1515
  }) {
1477
- var _a, _b, _c, _d, _e, _f, _g;
1516
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1478
1517
  const betas = /* @__PURE__ */ new Set();
1479
1518
  const blocks = groupIntoBlocks(prompt);
1480
1519
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1508,6 +1547,8 @@ async function convertToAnthropicMessagesPrompt({
1508
1547
  case "system": {
1509
1548
  const content = [];
1510
1549
  let toolChangeCount = 0;
1550
+ let clearAt = void 0;
1551
+ let effort = void 0;
1511
1552
  for (const { content: text, providerOptions } of block.messages) {
1512
1553
  const systemMessageOptions = await (0, import_provider_utils9.parseProviderOptions)({
1513
1554
  provider: "anthropic",
@@ -1515,7 +1556,9 @@ async function convertToAnthropicMessagesPrompt({
1515
1556
  schema: anthropicSystemMessageProviderOptions
1516
1557
  });
1517
1558
  const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
1518
- if (text !== "" || toolChanges.length === 0) {
1559
+ clearAt = (_b = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) != null ? _b : clearAt;
1560
+ effort = (_c = systemMessageOptions == null ? void 0 : systemMessageOptions.effort) != null ? _c : effort;
1561
+ if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
1519
1562
  content.push({
1520
1563
  type: "text",
1521
1564
  text,
@@ -1536,22 +1579,34 @@ async function convertToAnthropicMessagesPrompt({
1536
1579
  });
1537
1580
  }
1538
1581
  }
1539
- if (i === 0 || system == null && toolChangeCount === 0) {
1540
- if (toolChangeCount > 0) {
1582
+ const hasMidConversationOptions = toolChangeCount > 0 || clearAt != null || effort != null;
1583
+ if (i === 0 || system == null && !hasMidConversationOptions) {
1584
+ if (hasMidConversationOptions) {
1541
1585
  warnings.push({
1542
1586
  type: "other",
1543
- 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."
1587
+ message: "mid-conversation Anthropic system message options on the initial system message are not supported. The options have been ignored."
1544
1588
  });
1545
1589
  }
1546
1590
  system = content.filter(
1547
1591
  (part) => part.type === "text"
1548
1592
  );
1549
1593
  } else {
1550
- messages.push({ role: "system", content });
1594
+ messages.push({
1595
+ role: "system",
1596
+ content,
1597
+ ...clearAt != null && { clear_at: clearAt },
1598
+ ...effort != null && { output_config: { effort } }
1599
+ });
1551
1600
  betas.add("mid-conversation-system-2026-04-07");
1552
1601
  if (toolChangeCount > 0) {
1553
1602
  betas.add("mid-conversation-tool-changes-2026-07-01");
1554
1603
  }
1604
+ if (clearAt != null) {
1605
+ betas.add("mid-conversation-system-clear-at-2026-08-21");
1606
+ }
1607
+ if (effort != null) {
1608
+ betas.add("mid-conversation-effort-2026-08-01");
1609
+ }
1555
1610
  }
1556
1611
  break;
1557
1612
  }
@@ -1564,10 +1619,10 @@ async function convertToAnthropicMessagesPrompt({
1564
1619
  for (let j = 0; j < content.length; j++) {
1565
1620
  const part = content[j];
1566
1621
  const isLastPart = j === content.length - 1;
1567
- const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
1622
+ const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
1568
1623
  type: "user message part",
1569
1624
  canCache: true
1570
- })) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
1625
+ })) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
1571
1626
  type: "user message",
1572
1627
  canCache: true
1573
1628
  }) : void 0;
@@ -1612,7 +1667,7 @@ async function convertToAnthropicMessagesPrompt({
1612
1667
  media_type: "application/pdf",
1613
1668
  data: (0, import_provider_utils9.convertToBase64)(part.data)
1614
1669
  },
1615
- title: (_c = metadata.title) != null ? _c : part.filename,
1670
+ title: (_e = metadata.title) != null ? _e : part.filename,
1616
1671
  ...metadata.context && { context: metadata.context },
1617
1672
  ...enableCitations && {
1618
1673
  citations: { enabled: true }
@@ -1636,7 +1691,7 @@ async function convertToAnthropicMessagesPrompt({
1636
1691
  media_type: "text/plain",
1637
1692
  data: convertToString(part.data)
1638
1693
  },
1639
- title: (_d = metadata.title) != null ? _d : part.filename,
1694
+ title: (_f = metadata.title) != null ? _f : part.filename,
1640
1695
  ...metadata.context && { context: metadata.context },
1641
1696
  ...enableCitations && {
1642
1697
  citations: { enabled: true }
@@ -1658,10 +1713,10 @@ async function convertToAnthropicMessagesPrompt({
1658
1713
  for (let i2 = 0; i2 < content.length; i2++) {
1659
1714
  const part = content[i2];
1660
1715
  const isLastPart = i2 === content.length - 1;
1661
- const cacheControl = (_e = validator.getCacheControl(part.providerOptions, {
1716
+ const cacheControl = (_g = validator.getCacheControl(part.providerOptions, {
1662
1717
  type: "tool result part",
1663
1718
  canCache: true
1664
- })) != null ? _e : isLastPart ? validator.getCacheControl(message.providerOptions, {
1719
+ })) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
1665
1720
  type: "tool result message",
1666
1721
  canCache: true
1667
1722
  }) : void 0;
@@ -1743,16 +1798,16 @@ async function convertToAnthropicMessagesPrompt({
1743
1798
  for (let k = 0; k < content.length; k++) {
1744
1799
  const part = content[k];
1745
1800
  const isLastContentPart = k === content.length - 1;
1746
- const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
1801
+ const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
1747
1802
  type: "assistant message part",
1748
1803
  canCache: true
1749
- })) != null ? _f : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1804
+ })) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1750
1805
  type: "assistant message",
1751
1806
  canCache: true
1752
1807
  }) : void 0;
1753
1808
  switch (part.type) {
1754
1809
  case "text": {
1755
- const textMetadata = (_g = part.providerOptions) == null ? void 0 : _g.anthropic;
1810
+ const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
1756
1811
  if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
1757
1812
  anthropicContent.push({
1758
1813
  type: "compaction",
@@ -2249,6 +2304,15 @@ function isPlainObject(value) {
2249
2304
  }
2250
2305
 
2251
2306
  // src/anthropic-messages-language-model.ts
2307
+ function getJsonResponseToolName(tools) {
2308
+ const toolNames = new Set(tools == null ? void 0 : tools.map((tool) => tool.name));
2309
+ let name = "json";
2310
+ let suffix = 1;
2311
+ while (toolNames.has(name)) {
2312
+ name = `json_${suffix++}`;
2313
+ }
2314
+ return name;
2315
+ }
2252
2316
  function createCitationSource(citation, citationDocuments, generateId3) {
2253
2317
  var _a;
2254
2318
  if (citation.type !== "page_location" && citation.type !== "char_location") {
@@ -2312,7 +2376,7 @@ var AnthropicMessagesLanguageModel = class {
2312
2376
  toolChoice,
2313
2377
  providerOptions
2314
2378
  }) {
2315
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2379
+ var _a, _b, _c, _d, _e;
2316
2380
  const warnings = [];
2317
2381
  if (frequencyPenalty != null) {
2318
2382
  warnings.push({
@@ -2354,12 +2418,6 @@ var AnthropicMessagesLanguageModel = class {
2354
2418
  setting: "responseFormat",
2355
2419
  details: "JSON response format requires a schema. The response format is ignored."
2356
2420
  });
2357
- } else if (tools != null) {
2358
- warnings.push({
2359
- type: "unsupported-setting",
2360
- setting: "tools",
2361
- details: "JSON response format does not support tools. The provided tools are ignored."
2362
- });
2363
2421
  }
2364
2422
  }
2365
2423
  const anthropicOptions = await (0, import_provider_utils10.parseProviderOptions)({
@@ -2407,11 +2465,12 @@ var AnthropicMessagesLanguageModel = class {
2407
2465
  }
2408
2466
  }
2409
2467
  const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
2410
- const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "jsonTool";
2468
+ const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : this.modelId.includes("claude-fable-5-1") ? "auto" : "jsonTool";
2411
2469
  const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
2470
+ const jsonResponseToolName = getJsonResponseToolName(tools);
2412
2471
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
2413
2472
  type: "function",
2414
- name: "json",
2473
+ name: jsonResponseToolName,
2415
2474
  description: "Respond with a JSON object.",
2416
2475
  inputSchema: responseFormat.schema
2417
2476
  } : void 0;
@@ -2429,7 +2488,9 @@ var AnthropicMessagesLanguageModel = class {
2429
2488
  warnings,
2430
2489
  cacheControlValidator
2431
2490
  });
2432
- if (rejectsThinkingDisabledAboveHighEffort && ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
2491
+ const thinkingOptions = anthropicOptions == null ? void 0 : anthropicOptions.thinking;
2492
+ const thinkingType = thinkingOptions != null && "type" in thinkingOptions ? thinkingOptions.type : void 0;
2493
+ if (rejectsThinkingDisabledAboveHighEffort && thinkingType === "disabled" && anthropicOptions != null && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
2433
2494
  warnings.push({
2434
2495
  type: "unsupported-setting",
2435
2496
  setting: "providerOptions.anthropic.effort",
@@ -2437,10 +2498,10 @@ var AnthropicMessagesLanguageModel = class {
2437
2498
  });
2438
2499
  anthropicOptions.effort = "high";
2439
2500
  }
2440
- const thinkingType = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.type;
2441
2501
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
2442
- let thinkingBudget = thinkingType === "enabled" ? (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.budgetTokens : void 0;
2443
- const thinkingDisplay = thinkingType === "adaptive" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.display : void 0;
2502
+ let thinkingBudget = thinkingOptions != null && "budgetTokens" in thinkingOptions ? thinkingOptions.budgetTokens : void 0;
2503
+ const thinkingDisplay = thinkingOptions != null && "display" in thinkingOptions ? thinkingOptions.display : void 0;
2504
+ const thinkingBlockBinding = thinkingOptions != null && "blockBinding" in thinkingOptions ? thinkingOptions.blockBinding : void 0;
2444
2505
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
2445
2506
  const baseArgs = {
2446
2507
  // model id:
@@ -2452,11 +2513,16 @@ var AnthropicMessagesLanguageModel = class {
2452
2513
  top_p: topP,
2453
2514
  stop_sequences: stopSequences,
2454
2515
  // provider specific settings:
2455
- ...isThinking && {
2516
+ ...(isThinking || thinkingBlockBinding != null) && {
2456
2517
  thinking: {
2457
- type: thinkingType,
2518
+ ...thinkingType != null && { type: thinkingType },
2458
2519
  ...thinkingBudget != null && { budget_tokens: thinkingBudget },
2459
- ...thinkingDisplay != null && { display: thinkingDisplay }
2520
+ ...thinkingDisplay != null && { display: thinkingDisplay },
2521
+ ...thinkingBlockBinding != null && {
2522
+ block_binding: {
2523
+ prefix_mismatch_behavior: thinkingBlockBinding.prefixMismatchBehavior
2524
+ }
2525
+ }
2460
2526
  }
2461
2527
  },
2462
2528
  ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
@@ -2493,14 +2559,14 @@ var AnthropicMessagesLanguageModel = class {
2493
2559
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
2494
2560
  cache_control: anthropicOptions.cacheControl
2495
2561
  },
2496
- ...((_g = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _g.userId) != null && {
2562
+ ...((_c = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _c.userId) != null && {
2497
2563
  metadata: { user_id: anthropicOptions.metadata.userId }
2498
2564
  },
2499
2565
  // container with agent skills:
2500
2566
  ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
2501
2567
  container: {
2502
2568
  id: anthropicOptions.container.id,
2503
- skills: (_h = anthropicOptions.container.skills) == null ? void 0 : _h.map((skill) => ({
2569
+ skills: (_d = anthropicOptions.container.skills) == null ? void 0 : _d.map((skill) => ({
2504
2570
  type: skill.type,
2505
2571
  skill_id: skill.skillId,
2506
2572
  version: skill.version
@@ -2626,6 +2692,12 @@ var AnthropicMessagesLanguageModel = class {
2626
2692
  if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
2627
2693
  betas.add("effort-2025-11-24");
2628
2694
  }
2695
+ if (thinkingDisplay === "updates") {
2696
+ betas.add("thinking-display-updates-2026-08-18");
2697
+ }
2698
+ if (thinkingBlockBinding != null) {
2699
+ betas.add("thinking-binding-controls-2026-08-01");
2700
+ }
2629
2701
  if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
2630
2702
  betas.add("task-budgets-2026-03-13");
2631
2703
  }
@@ -2637,7 +2709,7 @@ var AnthropicMessagesLanguageModel = class {
2637
2709
  } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
2638
2710
  betas.add("server-side-fallback-2026-06-01");
2639
2711
  }
2640
- if (useStructuredOutput) {
2712
+ if (useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
2641
2713
  betas.add("structured-outputs-2025-11-13");
2642
2714
  }
2643
2715
  const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
@@ -2654,8 +2726,8 @@ var AnthropicMessagesLanguageModel = class {
2654
2726
  betas: toolsBetas
2655
2727
  } = await prepareTools(
2656
2728
  jsonResponseTool != null ? {
2657
- tools: [jsonResponseTool],
2658
- toolChoice: { type: "tool", toolName: jsonResponseTool.name },
2729
+ tools: [...tools != null ? tools : [], jsonResponseTool],
2730
+ toolChoice: tools != null && tools.length > 0 ? { type: "required" } : { type: "tool", toolName: jsonResponseTool.name },
2659
2731
  disableParallelToolUse: true,
2660
2732
  cacheControlValidator
2661
2733
  } : {
@@ -2677,9 +2749,9 @@ var AnthropicMessagesLanguageModel = class {
2677
2749
  ...betas,
2678
2750
  ...toolsBetas,
2679
2751
  ...userSuppliedBetas,
2680
- ...(_i = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _i : []
2752
+ ...(_e = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _e : []
2681
2753
  ]),
2682
- usesJsonResponseTool: jsonResponseTool != null
2754
+ jsonResponseToolName: jsonResponseTool != null ? jsonResponseToolName : void 0
2683
2755
  };
2684
2756
  }
2685
2757
  async getHeaders({
@@ -2737,7 +2809,7 @@ var AnthropicMessagesLanguageModel = class {
2737
2809
  }
2738
2810
  async doGenerate(options) {
2739
2811
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2740
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2812
+ const { args, warnings, betas, jsonResponseToolName } = await this.getArgs({
2741
2813
  ...options,
2742
2814
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
2743
2815
  });
@@ -2758,10 +2830,11 @@ var AnthropicMessagesLanguageModel = class {
2758
2830
  fetch: this.config.fetch
2759
2831
  });
2760
2832
  const content = [];
2833
+ let isJsonResponseFromTool = false;
2761
2834
  for (const part of response.content) {
2762
2835
  switch (part.type) {
2763
2836
  case "text": {
2764
- if (!usesJsonResponseTool) {
2837
+ if (jsonResponseToolName == null) {
2765
2838
  const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
2766
2839
  (citation) => citation.type === "web_search_result_location"
2767
2840
  );
@@ -2828,18 +2901,21 @@ var AnthropicMessagesLanguageModel = class {
2828
2901
  break;
2829
2902
  }
2830
2903
  case "tool_use": {
2831
- content.push(
2832
- // when a json response tool is used, the tool call becomes the text:
2833
- usesJsonResponseTool ? {
2904
+ const isJsonResponseTool = part.name === jsonResponseToolName;
2905
+ if (isJsonResponseTool) {
2906
+ isJsonResponseFromTool = true;
2907
+ content.push({
2834
2908
  type: "text",
2835
2909
  text: JSON.stringify(part.input)
2836
- } : {
2910
+ });
2911
+ } else {
2912
+ content.push({
2837
2913
  type: "tool-call",
2838
2914
  toolCallId: part.id,
2839
2915
  toolName: part.name,
2840
2916
  input: JSON.stringify(part.input)
2841
- }
2842
- );
2917
+ });
2918
+ }
2843
2919
  break;
2844
2920
  }
2845
2921
  case "server_tool_use": {
@@ -3021,7 +3097,7 @@ var AnthropicMessagesLanguageModel = class {
3021
3097
  content,
3022
3098
  finishReason: mapAnthropicStopReason({
3023
3099
  finishReason: response.stop_reason,
3024
- isJsonResponseFromTool: usesJsonResponseTool
3100
+ isJsonResponseFromTool
3025
3101
  }),
3026
3102
  usage: {
3027
3103
  inputTokens,
@@ -3089,7 +3165,7 @@ var AnthropicMessagesLanguageModel = class {
3089
3165
  }
3090
3166
  async doStream(options) {
3091
3167
  var _a, _b;
3092
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
3168
+ const { args, warnings, betas, jsonResponseToolName } = await this.getArgs({
3093
3169
  ...options,
3094
3170
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
3095
3171
  });
@@ -3121,6 +3197,7 @@ var AnthropicMessagesLanguageModel = class {
3121
3197
  let container = null;
3122
3198
  let iterations = null;
3123
3199
  let contextManagement = null;
3200
+ let isJsonResponseFromTool = false;
3124
3201
  let isMessageOpen = false;
3125
3202
  let activeMessageId;
3126
3203
  let hasInvalidMessageSequence = false;
@@ -3204,20 +3281,31 @@ var AnthropicMessagesLanguageModel = class {
3204
3281
  return;
3205
3282
  }
3206
3283
  case "tool_use": {
3207
- contentBlocks[value.index] = usesJsonResponseTool ? { type: "text", citations: [] } : {
3208
- type: "tool-call",
3209
- toolCallId: value.content_block.id,
3210
- toolName: value.content_block.name,
3211
- input: "",
3212
- firstDelta: true
3213
- };
3214
- controller.enqueue(
3215
- usesJsonResponseTool ? { type: "text-start", id: String(value.index) } : {
3284
+ const isJsonResponseTool = value.content_block.name === jsonResponseToolName;
3285
+ if (isJsonResponseTool) {
3286
+ isJsonResponseFromTool = true;
3287
+ contentBlocks[value.index] = {
3288
+ type: "text",
3289
+ citations: []
3290
+ };
3291
+ controller.enqueue({
3292
+ type: "text-start",
3293
+ id: String(value.index)
3294
+ });
3295
+ } else {
3296
+ contentBlocks[value.index] = {
3297
+ type: "tool-call",
3298
+ toolCallId: value.content_block.id,
3299
+ toolName: value.content_block.name,
3300
+ input: "",
3301
+ firstDelta: true
3302
+ };
3303
+ controller.enqueue({
3216
3304
  type: "tool-input-start",
3217
3305
  id: value.content_block.id,
3218
3306
  toolName: value.content_block.name
3219
- }
3220
- );
3307
+ });
3308
+ }
3221
3309
  return;
3222
3310
  }
3223
3311
  case "server_tool_use": {
@@ -3413,22 +3501,21 @@ var AnthropicMessagesLanguageModel = class {
3413
3501
  });
3414
3502
  break;
3415
3503
  }
3416
- case "tool-call":
3417
- if (!usesJsonResponseTool) {
3418
- controller.enqueue({
3419
- type: "tool-input-end",
3420
- id: contentBlock.toolCallId
3421
- });
3422
- const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
3423
- controller.enqueue({
3424
- type: "tool-call",
3425
- toolCallId: contentBlock.toolCallId,
3426
- toolName,
3427
- input: contentBlock.input === "" ? "{}" : contentBlock.input,
3428
- providerExecuted: contentBlock.providerExecuted
3429
- });
3430
- }
3504
+ case "tool-call": {
3505
+ controller.enqueue({
3506
+ type: "tool-input-end",
3507
+ id: contentBlock.toolCallId
3508
+ });
3509
+ const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
3510
+ controller.enqueue({
3511
+ type: "tool-call",
3512
+ toolCallId: contentBlock.toolCallId,
3513
+ toolName,
3514
+ input: contentBlock.input === "" ? "{}" : contentBlock.input,
3515
+ providerExecuted: contentBlock.providerExecuted
3516
+ });
3431
3517
  break;
3518
+ }
3432
3519
  }
3433
3520
  delete contentBlocks[value.index];
3434
3521
  }
@@ -3439,7 +3526,7 @@ var AnthropicMessagesLanguageModel = class {
3439
3526
  const deltaType = value.delta.type;
3440
3527
  switch (deltaType) {
3441
3528
  case "text_delta": {
3442
- if (usesJsonResponseTool) {
3529
+ if (jsonResponseToolName != null) {
3443
3530
  return;
3444
3531
  }
3445
3532
  controller.enqueue({
@@ -3488,10 +3575,7 @@ var AnthropicMessagesLanguageModel = class {
3488
3575
  if (delta.length === 0) {
3489
3576
  return;
3490
3577
  }
3491
- if (usesJsonResponseTool) {
3492
- if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
3493
- return;
3494
- }
3578
+ if ((contentBlock == null ? void 0 : contentBlock.type) === "text") {
3495
3579
  controller.enqueue({
3496
3580
  type: "text-delta",
3497
3581
  id: String(value.index),
@@ -3600,7 +3684,7 @@ var AnthropicMessagesLanguageModel = class {
3600
3684
  usage.totalTokens = ((_g = usage.inputTokens) != null ? _g : 0) + ((_h = usage.outputTokens) != null ? _h : 0);
3601
3685
  finishReason = mapAnthropicStopReason({
3602
3686
  finishReason: value.delta.stop_reason,
3603
- isJsonResponseFromTool: usesJsonResponseTool
3687
+ isJsonResponseFromTool
3604
3688
  });
3605
3689
  stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
3606
3690
  stopSequence = (_i = value.delta.stop_sequence) != null ? _i : null;
@@ -3725,7 +3809,7 @@ function getModelCapabilities(modelId) {
3725
3809
  rejectsThinkingDisabledAboveHighEffort: true,
3726
3810
  isKnownModel: true
3727
3811
  };
3728
- } else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
3812
+ } else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5-1") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
3729
3813
  return {
3730
3814
  maxOutputTokens: 128e3,
3731
3815
  supportsStructuredOutput: true,