@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.mjs CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  } from "@ai-sdk/provider-utils";
12
12
 
13
13
  // src/version.ts
14
- var VERSION = true ? "2.0.99" : "0.0.0-test";
14
+ var VERSION = true ? "2.0.101" : "0.0.0-test";
15
15
 
16
16
  // src/anthropic-messages-language-model.ts
17
17
  import {
@@ -664,6 +664,19 @@ var anthropicFilePartProviderOptions = z3.object({
664
664
  context: z3.string().optional()
665
665
  });
666
666
  var anthropicSystemMessageProviderOptions = z3.object({
667
+ /**
668
+ * Controls when a mid-conversation system message is cleared.
669
+ *
670
+ * The value is forwarded to Anthropic as `clear_at`. The required
671
+ * `mid-conversation-system-clear-at-2026-08-21` beta is added automatically.
672
+ */
673
+ clearAt: z3.literal("next_user_message").optional(),
674
+ /**
675
+ * Overrides the effort for the turn following this mid-conversation system
676
+ * message. The required `mid-conversation-effort-2026-08-01` beta is added
677
+ * automatically.
678
+ */
679
+ effort: z3.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
667
680
  /**
668
681
  * Mid-conversation tool changes. Adds or removes tools from the
669
682
  * conversation's tool set between turns without invalidating the prompt
@@ -691,6 +704,14 @@ var anthropicSystemMessageProviderOptions = z3.object({
691
704
  ])
692
705
  ).optional()
693
706
  });
707
+ var anthropicThinkingBlockBinding = z3.object({
708
+ /**
709
+ * Controls behavior when a replayed thinking block does not match its
710
+ * conversation prefix. The `drop_block` behavior drops the mismatched block
711
+ * instead of returning an invalid signature error.
712
+ */
713
+ prefixMismatchBehavior: z3.literal("drop_block")
714
+ });
694
715
  var anthropicProviderOptions = z3.object({
695
716
  /**
696
717
  * Whether to send reasoning to the model.
@@ -702,8 +723,8 @@ var anthropicProviderOptions = z3.object({
702
723
  * Determines how structured outputs are generated.
703
724
  *
704
725
  * - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
705
- * - `jsonTool`: Use a special 'json' tool to specify the structured output format (default).
706
- * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool'.
726
+ * - `jsonTool`: Use a special JSON response tool to specify the structured output format (default for most models).
727
+ * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default for Fable 5.1).
707
728
  */
708
729
  structuredOutputMode: z3.enum(["outputFormat", "jsonTool", "auto"]).optional(),
709
730
  /**
@@ -712,7 +733,7 @@ var anthropicProviderOptions = z3.object({
712
733
  * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
713
734
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
714
735
  */
715
- thinking: z3.discriminatedUnion("type", [
736
+ thinking: z3.union([
716
737
  z3.object({
717
738
  /** for Sonnet 4.6, Opus 4.6, and newer models */
718
739
  type: z3.literal("adaptive"),
@@ -720,16 +741,34 @@ var anthropicProviderOptions = z3.object({
720
741
  * Controls whether thinking content is included in the response.
721
742
  * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
722
743
  * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
744
+ * - `"updates"`: Thinking summaries are emitted between tool calls.
723
745
  */
724
- display: z3.enum(["omitted", "summarized"]).optional()
746
+ display: z3.enum(["omitted", "summarized", "updates"]).optional(),
747
+ /**
748
+ * Controls handling for thinking blocks whose conversation prefix no
749
+ * longer matches. Forwarded as `block_binding`.
750
+ */
751
+ blockBinding: anthropicThinkingBlockBinding.optional()
725
752
  }),
726
753
  z3.object({
727
754
  /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
728
755
  type: z3.literal("enabled"),
729
- budgetTokens: z3.number().optional()
756
+ budgetTokens: z3.number().optional(),
757
+ /**
758
+ * Controls handling for thinking blocks whose conversation prefix no
759
+ * longer matches. Forwarded as `block_binding`.
760
+ */
761
+ blockBinding: anthropicThinkingBlockBinding.optional()
730
762
  }),
731
763
  z3.object({
732
764
  type: z3.literal("disabled")
765
+ }),
766
+ z3.object({
767
+ /**
768
+ * Configure prefix mismatch handling without changing the model's
769
+ * default thinking mode.
770
+ */
771
+ blockBinding: anthropicThinkingBlockBinding
733
772
  })
734
773
  ]).optional(),
735
774
  /**
@@ -1500,7 +1539,7 @@ async function convertToAnthropicMessagesPrompt({
1500
1539
  warnings,
1501
1540
  cacheControlValidator
1502
1541
  }) {
1503
- var _a, _b, _c, _d, _e, _f, _g;
1542
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1504
1543
  const betas = /* @__PURE__ */ new Set();
1505
1544
  const blocks = groupIntoBlocks(prompt);
1506
1545
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1534,6 +1573,8 @@ async function convertToAnthropicMessagesPrompt({
1534
1573
  case "system": {
1535
1574
  const content = [];
1536
1575
  let toolChangeCount = 0;
1576
+ let clearAt = void 0;
1577
+ let effort = void 0;
1537
1578
  for (const { content: text, providerOptions } of block.messages) {
1538
1579
  const systemMessageOptions = await parseProviderOptions({
1539
1580
  provider: "anthropic",
@@ -1541,7 +1582,9 @@ async function convertToAnthropicMessagesPrompt({
1541
1582
  schema: anthropicSystemMessageProviderOptions
1542
1583
  });
1543
1584
  const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
1544
- if (text !== "" || toolChanges.length === 0) {
1585
+ clearAt = (_b = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) != null ? _b : clearAt;
1586
+ effort = (_c = systemMessageOptions == null ? void 0 : systemMessageOptions.effort) != null ? _c : effort;
1587
+ if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
1545
1588
  content.push({
1546
1589
  type: "text",
1547
1590
  text,
@@ -1562,22 +1605,34 @@ async function convertToAnthropicMessagesPrompt({
1562
1605
  });
1563
1606
  }
1564
1607
  }
1565
- if (i === 0 || system == null && toolChangeCount === 0) {
1566
- if (toolChangeCount > 0) {
1608
+ const hasMidConversationOptions = toolChangeCount > 0 || clearAt != null || effort != null;
1609
+ if (i === 0 || system == null && !hasMidConversationOptions) {
1610
+ if (hasMidConversationOptions) {
1567
1611
  warnings.push({
1568
1612
  type: "other",
1569
- 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."
1613
+ message: "mid-conversation Anthropic system message options on the initial system message are not supported. The options have been ignored."
1570
1614
  });
1571
1615
  }
1572
1616
  system = content.filter(
1573
1617
  (part) => part.type === "text"
1574
1618
  );
1575
1619
  } else {
1576
- messages.push({ role: "system", content });
1620
+ messages.push({
1621
+ role: "system",
1622
+ content,
1623
+ ...clearAt != null && { clear_at: clearAt },
1624
+ ...effort != null && { output_config: { effort } }
1625
+ });
1577
1626
  betas.add("mid-conversation-system-2026-04-07");
1578
1627
  if (toolChangeCount > 0) {
1579
1628
  betas.add("mid-conversation-tool-changes-2026-07-01");
1580
1629
  }
1630
+ if (clearAt != null) {
1631
+ betas.add("mid-conversation-system-clear-at-2026-08-21");
1632
+ }
1633
+ if (effort != null) {
1634
+ betas.add("mid-conversation-effort-2026-08-01");
1635
+ }
1581
1636
  }
1582
1637
  break;
1583
1638
  }
@@ -1590,10 +1645,10 @@ async function convertToAnthropicMessagesPrompt({
1590
1645
  for (let j = 0; j < content.length; j++) {
1591
1646
  const part = content[j];
1592
1647
  const isLastPart = j === content.length - 1;
1593
- const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
1648
+ const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
1594
1649
  type: "user message part",
1595
1650
  canCache: true
1596
- })) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
1651
+ })) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
1597
1652
  type: "user message",
1598
1653
  canCache: true
1599
1654
  }) : void 0;
@@ -1638,7 +1693,7 @@ async function convertToAnthropicMessagesPrompt({
1638
1693
  media_type: "application/pdf",
1639
1694
  data: convertToBase64(part.data)
1640
1695
  },
1641
- title: (_c = metadata.title) != null ? _c : part.filename,
1696
+ title: (_e = metadata.title) != null ? _e : part.filename,
1642
1697
  ...metadata.context && { context: metadata.context },
1643
1698
  ...enableCitations && {
1644
1699
  citations: { enabled: true }
@@ -1662,7 +1717,7 @@ async function convertToAnthropicMessagesPrompt({
1662
1717
  media_type: "text/plain",
1663
1718
  data: convertToString(part.data)
1664
1719
  },
1665
- title: (_d = metadata.title) != null ? _d : part.filename,
1720
+ title: (_f = metadata.title) != null ? _f : part.filename,
1666
1721
  ...metadata.context && { context: metadata.context },
1667
1722
  ...enableCitations && {
1668
1723
  citations: { enabled: true }
@@ -1684,10 +1739,10 @@ async function convertToAnthropicMessagesPrompt({
1684
1739
  for (let i2 = 0; i2 < content.length; i2++) {
1685
1740
  const part = content[i2];
1686
1741
  const isLastPart = i2 === content.length - 1;
1687
- const cacheControl = (_e = validator.getCacheControl(part.providerOptions, {
1742
+ const cacheControl = (_g = validator.getCacheControl(part.providerOptions, {
1688
1743
  type: "tool result part",
1689
1744
  canCache: true
1690
- })) != null ? _e : isLastPart ? validator.getCacheControl(message.providerOptions, {
1745
+ })) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
1691
1746
  type: "tool result message",
1692
1747
  canCache: true
1693
1748
  }) : void 0;
@@ -1769,16 +1824,16 @@ async function convertToAnthropicMessagesPrompt({
1769
1824
  for (let k = 0; k < content.length; k++) {
1770
1825
  const part = content[k];
1771
1826
  const isLastContentPart = k === content.length - 1;
1772
- const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
1827
+ const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
1773
1828
  type: "assistant message part",
1774
1829
  canCache: true
1775
- })) != null ? _f : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1830
+ })) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1776
1831
  type: "assistant message",
1777
1832
  canCache: true
1778
1833
  }) : void 0;
1779
1834
  switch (part.type) {
1780
1835
  case "text": {
1781
- const textMetadata = (_g = part.providerOptions) == null ? void 0 : _g.anthropic;
1836
+ const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
1782
1837
  if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
1783
1838
  anthropicContent.push({
1784
1839
  type: "compaction",
@@ -2275,6 +2330,15 @@ function isPlainObject(value) {
2275
2330
  }
2276
2331
 
2277
2332
  // src/anthropic-messages-language-model.ts
2333
+ function getJsonResponseToolName(tools) {
2334
+ const toolNames = new Set(tools == null ? void 0 : tools.map((tool) => tool.name));
2335
+ let name = "json";
2336
+ let suffix = 1;
2337
+ while (toolNames.has(name)) {
2338
+ name = `json_${suffix++}`;
2339
+ }
2340
+ return name;
2341
+ }
2278
2342
  function createCitationSource(citation, citationDocuments, generateId3) {
2279
2343
  var _a;
2280
2344
  if (citation.type !== "page_location" && citation.type !== "char_location") {
@@ -2338,7 +2402,7 @@ var AnthropicMessagesLanguageModel = class {
2338
2402
  toolChoice,
2339
2403
  providerOptions
2340
2404
  }) {
2341
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2405
+ var _a, _b, _c, _d, _e;
2342
2406
  const warnings = [];
2343
2407
  if (frequencyPenalty != null) {
2344
2408
  warnings.push({
@@ -2380,12 +2444,6 @@ var AnthropicMessagesLanguageModel = class {
2380
2444
  setting: "responseFormat",
2381
2445
  details: "JSON response format requires a schema. The response format is ignored."
2382
2446
  });
2383
- } else if (tools != null) {
2384
- warnings.push({
2385
- type: "unsupported-setting",
2386
- setting: "tools",
2387
- details: "JSON response format does not support tools. The provided tools are ignored."
2388
- });
2389
2447
  }
2390
2448
  }
2391
2449
  const anthropicOptions = await parseProviderOptions2({
@@ -2433,11 +2491,12 @@ var AnthropicMessagesLanguageModel = class {
2433
2491
  }
2434
2492
  }
2435
2493
  const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
2436
- const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "jsonTool";
2494
+ const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : this.modelId.includes("claude-fable-5-1") ? "auto" : "jsonTool";
2437
2495
  const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
2496
+ const jsonResponseToolName = getJsonResponseToolName(tools);
2438
2497
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
2439
2498
  type: "function",
2440
- name: "json",
2499
+ name: jsonResponseToolName,
2441
2500
  description: "Respond with a JSON object.",
2442
2501
  inputSchema: responseFormat.schema
2443
2502
  } : void 0;
@@ -2455,7 +2514,9 @@ var AnthropicMessagesLanguageModel = class {
2455
2514
  warnings,
2456
2515
  cacheControlValidator
2457
2516
  });
2458
- if (rejectsThinkingDisabledAboveHighEffort && ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
2517
+ const thinkingOptions = anthropicOptions == null ? void 0 : anthropicOptions.thinking;
2518
+ const thinkingType = thinkingOptions != null && "type" in thinkingOptions ? thinkingOptions.type : void 0;
2519
+ if (rejectsThinkingDisabledAboveHighEffort && thinkingType === "disabled" && anthropicOptions != null && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
2459
2520
  warnings.push({
2460
2521
  type: "unsupported-setting",
2461
2522
  setting: "providerOptions.anthropic.effort",
@@ -2463,10 +2524,10 @@ var AnthropicMessagesLanguageModel = class {
2463
2524
  });
2464
2525
  anthropicOptions.effort = "high";
2465
2526
  }
2466
- const thinkingType = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.type;
2467
2527
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
2468
- let thinkingBudget = thinkingType === "enabled" ? (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.budgetTokens : void 0;
2469
- const thinkingDisplay = thinkingType === "adaptive" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.display : void 0;
2528
+ let thinkingBudget = thinkingOptions != null && "budgetTokens" in thinkingOptions ? thinkingOptions.budgetTokens : void 0;
2529
+ const thinkingDisplay = thinkingOptions != null && "display" in thinkingOptions ? thinkingOptions.display : void 0;
2530
+ const thinkingBlockBinding = thinkingOptions != null && "blockBinding" in thinkingOptions ? thinkingOptions.blockBinding : void 0;
2470
2531
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
2471
2532
  const baseArgs = {
2472
2533
  // model id:
@@ -2478,11 +2539,16 @@ var AnthropicMessagesLanguageModel = class {
2478
2539
  top_p: topP,
2479
2540
  stop_sequences: stopSequences,
2480
2541
  // provider specific settings:
2481
- ...isThinking && {
2542
+ ...(isThinking || thinkingBlockBinding != null) && {
2482
2543
  thinking: {
2483
- type: thinkingType,
2544
+ ...thinkingType != null && { type: thinkingType },
2484
2545
  ...thinkingBudget != null && { budget_tokens: thinkingBudget },
2485
- ...thinkingDisplay != null && { display: thinkingDisplay }
2546
+ ...thinkingDisplay != null && { display: thinkingDisplay },
2547
+ ...thinkingBlockBinding != null && {
2548
+ block_binding: {
2549
+ prefix_mismatch_behavior: thinkingBlockBinding.prefixMismatchBehavior
2550
+ }
2551
+ }
2486
2552
  }
2487
2553
  },
2488
2554
  ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
@@ -2519,14 +2585,14 @@ var AnthropicMessagesLanguageModel = class {
2519
2585
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
2520
2586
  cache_control: anthropicOptions.cacheControl
2521
2587
  },
2522
- ...((_g = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _g.userId) != null && {
2588
+ ...((_c = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _c.userId) != null && {
2523
2589
  metadata: { user_id: anthropicOptions.metadata.userId }
2524
2590
  },
2525
2591
  // container with agent skills:
2526
2592
  ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
2527
2593
  container: {
2528
2594
  id: anthropicOptions.container.id,
2529
- skills: (_h = anthropicOptions.container.skills) == null ? void 0 : _h.map((skill) => ({
2595
+ skills: (_d = anthropicOptions.container.skills) == null ? void 0 : _d.map((skill) => ({
2530
2596
  type: skill.type,
2531
2597
  skill_id: skill.skillId,
2532
2598
  version: skill.version
@@ -2652,6 +2718,12 @@ var AnthropicMessagesLanguageModel = class {
2652
2718
  if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
2653
2719
  betas.add("effort-2025-11-24");
2654
2720
  }
2721
+ if (thinkingDisplay === "updates") {
2722
+ betas.add("thinking-display-updates-2026-08-18");
2723
+ }
2724
+ if (thinkingBlockBinding != null) {
2725
+ betas.add("thinking-binding-controls-2026-08-01");
2726
+ }
2655
2727
  if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
2656
2728
  betas.add("task-budgets-2026-03-13");
2657
2729
  }
@@ -2663,7 +2735,7 @@ var AnthropicMessagesLanguageModel = class {
2663
2735
  } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
2664
2736
  betas.add("server-side-fallback-2026-06-01");
2665
2737
  }
2666
- if (useStructuredOutput) {
2738
+ if (useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
2667
2739
  betas.add("structured-outputs-2025-11-13");
2668
2740
  }
2669
2741
  const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
@@ -2680,8 +2752,8 @@ var AnthropicMessagesLanguageModel = class {
2680
2752
  betas: toolsBetas
2681
2753
  } = await prepareTools(
2682
2754
  jsonResponseTool != null ? {
2683
- tools: [jsonResponseTool],
2684
- toolChoice: { type: "tool", toolName: jsonResponseTool.name },
2755
+ tools: [...tools != null ? tools : [], jsonResponseTool],
2756
+ toolChoice: tools != null && tools.length > 0 ? { type: "required" } : { type: "tool", toolName: jsonResponseTool.name },
2685
2757
  disableParallelToolUse: true,
2686
2758
  cacheControlValidator
2687
2759
  } : {
@@ -2703,9 +2775,9 @@ var AnthropicMessagesLanguageModel = class {
2703
2775
  ...betas,
2704
2776
  ...toolsBetas,
2705
2777
  ...userSuppliedBetas,
2706
- ...(_i = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _i : []
2778
+ ...(_e = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _e : []
2707
2779
  ]),
2708
- usesJsonResponseTool: jsonResponseTool != null
2780
+ jsonResponseToolName: jsonResponseTool != null ? jsonResponseToolName : void 0
2709
2781
  };
2710
2782
  }
2711
2783
  async getHeaders({
@@ -2763,7 +2835,7 @@ var AnthropicMessagesLanguageModel = class {
2763
2835
  }
2764
2836
  async doGenerate(options) {
2765
2837
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2766
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2838
+ const { args, warnings, betas, jsonResponseToolName } = await this.getArgs({
2767
2839
  ...options,
2768
2840
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
2769
2841
  });
@@ -2784,10 +2856,11 @@ var AnthropicMessagesLanguageModel = class {
2784
2856
  fetch: this.config.fetch
2785
2857
  });
2786
2858
  const content = [];
2859
+ let isJsonResponseFromTool = false;
2787
2860
  for (const part of response.content) {
2788
2861
  switch (part.type) {
2789
2862
  case "text": {
2790
- if (!usesJsonResponseTool) {
2863
+ if (jsonResponseToolName == null) {
2791
2864
  const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
2792
2865
  (citation) => citation.type === "web_search_result_location"
2793
2866
  );
@@ -2854,18 +2927,21 @@ var AnthropicMessagesLanguageModel = class {
2854
2927
  break;
2855
2928
  }
2856
2929
  case "tool_use": {
2857
- content.push(
2858
- // when a json response tool is used, the tool call becomes the text:
2859
- usesJsonResponseTool ? {
2930
+ const isJsonResponseTool = part.name === jsonResponseToolName;
2931
+ if (isJsonResponseTool) {
2932
+ isJsonResponseFromTool = true;
2933
+ content.push({
2860
2934
  type: "text",
2861
2935
  text: JSON.stringify(part.input)
2862
- } : {
2936
+ });
2937
+ } else {
2938
+ content.push({
2863
2939
  type: "tool-call",
2864
2940
  toolCallId: part.id,
2865
2941
  toolName: part.name,
2866
2942
  input: JSON.stringify(part.input)
2867
- }
2868
- );
2943
+ });
2944
+ }
2869
2945
  break;
2870
2946
  }
2871
2947
  case "server_tool_use": {
@@ -3047,7 +3123,7 @@ var AnthropicMessagesLanguageModel = class {
3047
3123
  content,
3048
3124
  finishReason: mapAnthropicStopReason({
3049
3125
  finishReason: response.stop_reason,
3050
- isJsonResponseFromTool: usesJsonResponseTool
3126
+ isJsonResponseFromTool
3051
3127
  }),
3052
3128
  usage: {
3053
3129
  inputTokens,
@@ -3115,7 +3191,7 @@ var AnthropicMessagesLanguageModel = class {
3115
3191
  }
3116
3192
  async doStream(options) {
3117
3193
  var _a, _b;
3118
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
3194
+ const { args, warnings, betas, jsonResponseToolName } = await this.getArgs({
3119
3195
  ...options,
3120
3196
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
3121
3197
  });
@@ -3147,6 +3223,7 @@ var AnthropicMessagesLanguageModel = class {
3147
3223
  let container = null;
3148
3224
  let iterations = null;
3149
3225
  let contextManagement = null;
3226
+ let isJsonResponseFromTool = false;
3150
3227
  let isMessageOpen = false;
3151
3228
  let activeMessageId;
3152
3229
  let hasInvalidMessageSequence = false;
@@ -3230,20 +3307,31 @@ var AnthropicMessagesLanguageModel = class {
3230
3307
  return;
3231
3308
  }
3232
3309
  case "tool_use": {
3233
- contentBlocks[value.index] = usesJsonResponseTool ? { type: "text", citations: [] } : {
3234
- type: "tool-call",
3235
- toolCallId: value.content_block.id,
3236
- toolName: value.content_block.name,
3237
- input: "",
3238
- firstDelta: true
3239
- };
3240
- controller.enqueue(
3241
- usesJsonResponseTool ? { type: "text-start", id: String(value.index) } : {
3310
+ const isJsonResponseTool = value.content_block.name === jsonResponseToolName;
3311
+ if (isJsonResponseTool) {
3312
+ isJsonResponseFromTool = true;
3313
+ contentBlocks[value.index] = {
3314
+ type: "text",
3315
+ citations: []
3316
+ };
3317
+ controller.enqueue({
3318
+ type: "text-start",
3319
+ id: String(value.index)
3320
+ });
3321
+ } else {
3322
+ contentBlocks[value.index] = {
3323
+ type: "tool-call",
3324
+ toolCallId: value.content_block.id,
3325
+ toolName: value.content_block.name,
3326
+ input: "",
3327
+ firstDelta: true
3328
+ };
3329
+ controller.enqueue({
3242
3330
  type: "tool-input-start",
3243
3331
  id: value.content_block.id,
3244
3332
  toolName: value.content_block.name
3245
- }
3246
- );
3333
+ });
3334
+ }
3247
3335
  return;
3248
3336
  }
3249
3337
  case "server_tool_use": {
@@ -3439,22 +3527,21 @@ var AnthropicMessagesLanguageModel = class {
3439
3527
  });
3440
3528
  break;
3441
3529
  }
3442
- case "tool-call":
3443
- if (!usesJsonResponseTool) {
3444
- controller.enqueue({
3445
- type: "tool-input-end",
3446
- id: contentBlock.toolCallId
3447
- });
3448
- const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
3449
- controller.enqueue({
3450
- type: "tool-call",
3451
- toolCallId: contentBlock.toolCallId,
3452
- toolName,
3453
- input: contentBlock.input === "" ? "{}" : contentBlock.input,
3454
- providerExecuted: contentBlock.providerExecuted
3455
- });
3456
- }
3530
+ case "tool-call": {
3531
+ controller.enqueue({
3532
+ type: "tool-input-end",
3533
+ id: contentBlock.toolCallId
3534
+ });
3535
+ const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
3536
+ controller.enqueue({
3537
+ type: "tool-call",
3538
+ toolCallId: contentBlock.toolCallId,
3539
+ toolName,
3540
+ input: contentBlock.input === "" ? "{}" : contentBlock.input,
3541
+ providerExecuted: contentBlock.providerExecuted
3542
+ });
3457
3543
  break;
3544
+ }
3458
3545
  }
3459
3546
  delete contentBlocks[value.index];
3460
3547
  }
@@ -3465,7 +3552,7 @@ var AnthropicMessagesLanguageModel = class {
3465
3552
  const deltaType = value.delta.type;
3466
3553
  switch (deltaType) {
3467
3554
  case "text_delta": {
3468
- if (usesJsonResponseTool) {
3555
+ if (jsonResponseToolName != null) {
3469
3556
  return;
3470
3557
  }
3471
3558
  controller.enqueue({
@@ -3514,10 +3601,7 @@ var AnthropicMessagesLanguageModel = class {
3514
3601
  if (delta.length === 0) {
3515
3602
  return;
3516
3603
  }
3517
- if (usesJsonResponseTool) {
3518
- if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
3519
- return;
3520
- }
3604
+ if ((contentBlock == null ? void 0 : contentBlock.type) === "text") {
3521
3605
  controller.enqueue({
3522
3606
  type: "text-delta",
3523
3607
  id: String(value.index),
@@ -3626,7 +3710,7 @@ var AnthropicMessagesLanguageModel = class {
3626
3710
  usage.totalTokens = ((_g = usage.inputTokens) != null ? _g : 0) + ((_h = usage.outputTokens) != null ? _h : 0);
3627
3711
  finishReason = mapAnthropicStopReason({
3628
3712
  finishReason: value.delta.stop_reason,
3629
- isJsonResponseFromTool: usesJsonResponseTool
3713
+ isJsonResponseFromTool
3630
3714
  });
3631
3715
  stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
3632
3716
  stopSequence = (_i = value.delta.stop_sequence) != null ? _i : null;
@@ -3751,7 +3835,7 @@ function getModelCapabilities(modelId) {
3751
3835
  rejectsThinkingDisabledAboveHighEffort: true,
3752
3836
  isKnownModel: true
3753
3837
  };
3754
- } else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
3838
+ } 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")) {
3755
3839
  return {
3756
3840
  maxOutputTokens: 128e3,
3757
3841
  supportsStructuredOutput: true,