@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/CHANGELOG.md +14 -0
- package/dist/index.d.mts +21 -2
- package/dist/index.d.ts +21 -2
- package/dist/index.js +171 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +171 -87
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +170 -86
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +170 -86
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/internal/index.mjs
CHANGED
|
@@ -649,6 +649,19 @@ var anthropicFilePartProviderOptions = z3.object({
|
|
|
649
649
|
context: z3.string().optional()
|
|
650
650
|
});
|
|
651
651
|
var anthropicSystemMessageProviderOptions = z3.object({
|
|
652
|
+
/**
|
|
653
|
+
* Controls when a mid-conversation system message is cleared.
|
|
654
|
+
*
|
|
655
|
+
* The value is forwarded to Anthropic as `clear_at`. The required
|
|
656
|
+
* `mid-conversation-system-clear-at-2026-08-21` beta is added automatically.
|
|
657
|
+
*/
|
|
658
|
+
clearAt: z3.literal("next_user_message").optional(),
|
|
659
|
+
/**
|
|
660
|
+
* Overrides the effort for the turn following this mid-conversation system
|
|
661
|
+
* message. The required `mid-conversation-effort-2026-08-01` beta is added
|
|
662
|
+
* automatically.
|
|
663
|
+
*/
|
|
664
|
+
effort: z3.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
652
665
|
/**
|
|
653
666
|
* Mid-conversation tool changes. Adds or removes tools from the
|
|
654
667
|
* conversation's tool set between turns without invalidating the prompt
|
|
@@ -676,6 +689,14 @@ var anthropicSystemMessageProviderOptions = z3.object({
|
|
|
676
689
|
])
|
|
677
690
|
).optional()
|
|
678
691
|
});
|
|
692
|
+
var anthropicThinkingBlockBinding = z3.object({
|
|
693
|
+
/**
|
|
694
|
+
* Controls behavior when a replayed thinking block does not match its
|
|
695
|
+
* conversation prefix. The `drop_block` behavior drops the mismatched block
|
|
696
|
+
* instead of returning an invalid signature error.
|
|
697
|
+
*/
|
|
698
|
+
prefixMismatchBehavior: z3.literal("drop_block")
|
|
699
|
+
});
|
|
679
700
|
var anthropicProviderOptions = z3.object({
|
|
680
701
|
/**
|
|
681
702
|
* Whether to send reasoning to the model.
|
|
@@ -687,8 +708,8 @@ var anthropicProviderOptions = z3.object({
|
|
|
687
708
|
* Determines how structured outputs are generated.
|
|
688
709
|
*
|
|
689
710
|
* - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
|
|
690
|
-
* - `jsonTool`: Use a special
|
|
691
|
-
* - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool'.
|
|
711
|
+
* - `jsonTool`: Use a special JSON response tool to specify the structured output format (default for most models).
|
|
712
|
+
* - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default for Fable 5.1).
|
|
692
713
|
*/
|
|
693
714
|
structuredOutputMode: z3.enum(["outputFormat", "jsonTool", "auto"]).optional(),
|
|
694
715
|
/**
|
|
@@ -697,7 +718,7 @@ var anthropicProviderOptions = z3.object({
|
|
|
697
718
|
* When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
|
|
698
719
|
* Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
|
|
699
720
|
*/
|
|
700
|
-
thinking: z3.
|
|
721
|
+
thinking: z3.union([
|
|
701
722
|
z3.object({
|
|
702
723
|
/** for Sonnet 4.6, Opus 4.6, and newer models */
|
|
703
724
|
type: z3.literal("adaptive"),
|
|
@@ -705,16 +726,34 @@ var anthropicProviderOptions = z3.object({
|
|
|
705
726
|
* Controls whether thinking content is included in the response.
|
|
706
727
|
* - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
|
|
707
728
|
* - `"summarized"`: Thinking content is returned. Required to see reasoning output.
|
|
729
|
+
* - `"updates"`: Thinking summaries are emitted between tool calls.
|
|
708
730
|
*/
|
|
709
|
-
display: z3.enum(["omitted", "summarized"]).optional()
|
|
731
|
+
display: z3.enum(["omitted", "summarized", "updates"]).optional(),
|
|
732
|
+
/**
|
|
733
|
+
* Controls handling for thinking blocks whose conversation prefix no
|
|
734
|
+
* longer matches. Forwarded as `block_binding`.
|
|
735
|
+
*/
|
|
736
|
+
blockBinding: anthropicThinkingBlockBinding.optional()
|
|
710
737
|
}),
|
|
711
738
|
z3.object({
|
|
712
739
|
/** for models before Opus 4.6, except Sonnet 4.6 still supports it */
|
|
713
740
|
type: z3.literal("enabled"),
|
|
714
|
-
budgetTokens: z3.number().optional()
|
|
741
|
+
budgetTokens: z3.number().optional(),
|
|
742
|
+
/**
|
|
743
|
+
* Controls handling for thinking blocks whose conversation prefix no
|
|
744
|
+
* longer matches. Forwarded as `block_binding`.
|
|
745
|
+
*/
|
|
746
|
+
blockBinding: anthropicThinkingBlockBinding.optional()
|
|
715
747
|
}),
|
|
716
748
|
z3.object({
|
|
717
749
|
type: z3.literal("disabled")
|
|
750
|
+
}),
|
|
751
|
+
z3.object({
|
|
752
|
+
/**
|
|
753
|
+
* Configure prefix mismatch handling without changing the model's
|
|
754
|
+
* default thinking mode.
|
|
755
|
+
*/
|
|
756
|
+
blockBinding: anthropicThinkingBlockBinding
|
|
718
757
|
})
|
|
719
758
|
]).optional(),
|
|
720
759
|
/**
|
|
@@ -1485,7 +1524,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1485
1524
|
warnings,
|
|
1486
1525
|
cacheControlValidator
|
|
1487
1526
|
}) {
|
|
1488
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1527
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1489
1528
|
const betas = /* @__PURE__ */ new Set();
|
|
1490
1529
|
const blocks = groupIntoBlocks(prompt);
|
|
1491
1530
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -1519,6 +1558,8 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1519
1558
|
case "system": {
|
|
1520
1559
|
const content = [];
|
|
1521
1560
|
let toolChangeCount = 0;
|
|
1561
|
+
let clearAt = void 0;
|
|
1562
|
+
let effort = void 0;
|
|
1522
1563
|
for (const { content: text, providerOptions } of block.messages) {
|
|
1523
1564
|
const systemMessageOptions = await parseProviderOptions({
|
|
1524
1565
|
provider: "anthropic",
|
|
@@ -1526,7 +1567,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1526
1567
|
schema: anthropicSystemMessageProviderOptions
|
|
1527
1568
|
});
|
|
1528
1569
|
const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
|
|
1529
|
-
|
|
1570
|
+
clearAt = (_b = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) != null ? _b : clearAt;
|
|
1571
|
+
effort = (_c = systemMessageOptions == null ? void 0 : systemMessageOptions.effort) != null ? _c : effort;
|
|
1572
|
+
if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
|
|
1530
1573
|
content.push({
|
|
1531
1574
|
type: "text",
|
|
1532
1575
|
text,
|
|
@@ -1547,22 +1590,34 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1547
1590
|
});
|
|
1548
1591
|
}
|
|
1549
1592
|
}
|
|
1550
|
-
|
|
1551
|
-
|
|
1593
|
+
const hasMidConversationOptions = toolChangeCount > 0 || clearAt != null || effort != null;
|
|
1594
|
+
if (i === 0 || system == null && !hasMidConversationOptions) {
|
|
1595
|
+
if (hasMidConversationOptions) {
|
|
1552
1596
|
warnings.push({
|
|
1553
1597
|
type: "other",
|
|
1554
|
-
message: "
|
|
1598
|
+
message: "mid-conversation Anthropic system message options on the initial system message are not supported. The options have been ignored."
|
|
1555
1599
|
});
|
|
1556
1600
|
}
|
|
1557
1601
|
system = content.filter(
|
|
1558
1602
|
(part) => part.type === "text"
|
|
1559
1603
|
);
|
|
1560
1604
|
} else {
|
|
1561
|
-
messages.push({
|
|
1605
|
+
messages.push({
|
|
1606
|
+
role: "system",
|
|
1607
|
+
content,
|
|
1608
|
+
...clearAt != null && { clear_at: clearAt },
|
|
1609
|
+
...effort != null && { output_config: { effort } }
|
|
1610
|
+
});
|
|
1562
1611
|
betas.add("mid-conversation-system-2026-04-07");
|
|
1563
1612
|
if (toolChangeCount > 0) {
|
|
1564
1613
|
betas.add("mid-conversation-tool-changes-2026-07-01");
|
|
1565
1614
|
}
|
|
1615
|
+
if (clearAt != null) {
|
|
1616
|
+
betas.add("mid-conversation-system-clear-at-2026-08-21");
|
|
1617
|
+
}
|
|
1618
|
+
if (effort != null) {
|
|
1619
|
+
betas.add("mid-conversation-effort-2026-08-01");
|
|
1620
|
+
}
|
|
1566
1621
|
}
|
|
1567
1622
|
break;
|
|
1568
1623
|
}
|
|
@@ -1575,10 +1630,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1575
1630
|
for (let j = 0; j < content.length; j++) {
|
|
1576
1631
|
const part = content[j];
|
|
1577
1632
|
const isLastPart = j === content.length - 1;
|
|
1578
|
-
const cacheControl = (
|
|
1633
|
+
const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
|
|
1579
1634
|
type: "user message part",
|
|
1580
1635
|
canCache: true
|
|
1581
|
-
})) != null ?
|
|
1636
|
+
})) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
1582
1637
|
type: "user message",
|
|
1583
1638
|
canCache: true
|
|
1584
1639
|
}) : void 0;
|
|
@@ -1623,7 +1678,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1623
1678
|
media_type: "application/pdf",
|
|
1624
1679
|
data: convertToBase64(part.data)
|
|
1625
1680
|
},
|
|
1626
|
-
title: (
|
|
1681
|
+
title: (_e = metadata.title) != null ? _e : part.filename,
|
|
1627
1682
|
...metadata.context && { context: metadata.context },
|
|
1628
1683
|
...enableCitations && {
|
|
1629
1684
|
citations: { enabled: true }
|
|
@@ -1647,7 +1702,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1647
1702
|
media_type: "text/plain",
|
|
1648
1703
|
data: convertToString(part.data)
|
|
1649
1704
|
},
|
|
1650
|
-
title: (
|
|
1705
|
+
title: (_f = metadata.title) != null ? _f : part.filename,
|
|
1651
1706
|
...metadata.context && { context: metadata.context },
|
|
1652
1707
|
...enableCitations && {
|
|
1653
1708
|
citations: { enabled: true }
|
|
@@ -1669,10 +1724,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1669
1724
|
for (let i2 = 0; i2 < content.length; i2++) {
|
|
1670
1725
|
const part = content[i2];
|
|
1671
1726
|
const isLastPart = i2 === content.length - 1;
|
|
1672
|
-
const cacheControl = (
|
|
1727
|
+
const cacheControl = (_g = validator.getCacheControl(part.providerOptions, {
|
|
1673
1728
|
type: "tool result part",
|
|
1674
1729
|
canCache: true
|
|
1675
|
-
})) != null ?
|
|
1730
|
+
})) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
1676
1731
|
type: "tool result message",
|
|
1677
1732
|
canCache: true
|
|
1678
1733
|
}) : void 0;
|
|
@@ -1754,16 +1809,16 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1754
1809
|
for (let k = 0; k < content.length; k++) {
|
|
1755
1810
|
const part = content[k];
|
|
1756
1811
|
const isLastContentPart = k === content.length - 1;
|
|
1757
|
-
const cacheControl = (
|
|
1812
|
+
const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
|
|
1758
1813
|
type: "assistant message part",
|
|
1759
1814
|
canCache: true
|
|
1760
|
-
})) != null ?
|
|
1815
|
+
})) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
1761
1816
|
type: "assistant message",
|
|
1762
1817
|
canCache: true
|
|
1763
1818
|
}) : void 0;
|
|
1764
1819
|
switch (part.type) {
|
|
1765
1820
|
case "text": {
|
|
1766
|
-
const textMetadata = (
|
|
1821
|
+
const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
|
|
1767
1822
|
if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
|
|
1768
1823
|
anthropicContent.push({
|
|
1769
1824
|
type: "compaction",
|
|
@@ -2260,6 +2315,15 @@ function isPlainObject(value) {
|
|
|
2260
2315
|
}
|
|
2261
2316
|
|
|
2262
2317
|
// src/anthropic-messages-language-model.ts
|
|
2318
|
+
function getJsonResponseToolName(tools) {
|
|
2319
|
+
const toolNames = new Set(tools == null ? void 0 : tools.map((tool) => tool.name));
|
|
2320
|
+
let name = "json";
|
|
2321
|
+
let suffix = 1;
|
|
2322
|
+
while (toolNames.has(name)) {
|
|
2323
|
+
name = `json_${suffix++}`;
|
|
2324
|
+
}
|
|
2325
|
+
return name;
|
|
2326
|
+
}
|
|
2263
2327
|
function createCitationSource(citation, citationDocuments, generateId2) {
|
|
2264
2328
|
var _a;
|
|
2265
2329
|
if (citation.type !== "page_location" && citation.type !== "char_location") {
|
|
@@ -2323,7 +2387,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2323
2387
|
toolChoice,
|
|
2324
2388
|
providerOptions
|
|
2325
2389
|
}) {
|
|
2326
|
-
var _a, _b, _c, _d, _e
|
|
2390
|
+
var _a, _b, _c, _d, _e;
|
|
2327
2391
|
const warnings = [];
|
|
2328
2392
|
if (frequencyPenalty != null) {
|
|
2329
2393
|
warnings.push({
|
|
@@ -2365,12 +2429,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2365
2429
|
setting: "responseFormat",
|
|
2366
2430
|
details: "JSON response format requires a schema. The response format is ignored."
|
|
2367
2431
|
});
|
|
2368
|
-
} else if (tools != null) {
|
|
2369
|
-
warnings.push({
|
|
2370
|
-
type: "unsupported-setting",
|
|
2371
|
-
setting: "tools",
|
|
2372
|
-
details: "JSON response format does not support tools. The provided tools are ignored."
|
|
2373
|
-
});
|
|
2374
2432
|
}
|
|
2375
2433
|
}
|
|
2376
2434
|
const anthropicOptions = await parseProviderOptions2({
|
|
@@ -2418,11 +2476,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2418
2476
|
}
|
|
2419
2477
|
}
|
|
2420
2478
|
const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
|
|
2421
|
-
const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "jsonTool";
|
|
2479
|
+
const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : this.modelId.includes("claude-fable-5-1") ? "auto" : "jsonTool";
|
|
2422
2480
|
const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
2481
|
+
const jsonResponseToolName = getJsonResponseToolName(tools);
|
|
2423
2482
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
|
|
2424
2483
|
type: "function",
|
|
2425
|
-
name:
|
|
2484
|
+
name: jsonResponseToolName,
|
|
2426
2485
|
description: "Respond with a JSON object.",
|
|
2427
2486
|
inputSchema: responseFormat.schema
|
|
2428
2487
|
} : void 0;
|
|
@@ -2440,7 +2499,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2440
2499
|
warnings,
|
|
2441
2500
|
cacheControlValidator
|
|
2442
2501
|
});
|
|
2443
|
-
|
|
2502
|
+
const thinkingOptions = anthropicOptions == null ? void 0 : anthropicOptions.thinking;
|
|
2503
|
+
const thinkingType = thinkingOptions != null && "type" in thinkingOptions ? thinkingOptions.type : void 0;
|
|
2504
|
+
if (rejectsThinkingDisabledAboveHighEffort && thinkingType === "disabled" && anthropicOptions != null && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
|
|
2444
2505
|
warnings.push({
|
|
2445
2506
|
type: "unsupported-setting",
|
|
2446
2507
|
setting: "providerOptions.anthropic.effort",
|
|
@@ -2448,10 +2509,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2448
2509
|
});
|
|
2449
2510
|
anthropicOptions.effort = "high";
|
|
2450
2511
|
}
|
|
2451
|
-
const thinkingType = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.type;
|
|
2452
2512
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
2453
|
-
let thinkingBudget =
|
|
2454
|
-
const thinkingDisplay =
|
|
2513
|
+
let thinkingBudget = thinkingOptions != null && "budgetTokens" in thinkingOptions ? thinkingOptions.budgetTokens : void 0;
|
|
2514
|
+
const thinkingDisplay = thinkingOptions != null && "display" in thinkingOptions ? thinkingOptions.display : void 0;
|
|
2515
|
+
const thinkingBlockBinding = thinkingOptions != null && "blockBinding" in thinkingOptions ? thinkingOptions.blockBinding : void 0;
|
|
2455
2516
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
2456
2517
|
const baseArgs = {
|
|
2457
2518
|
// model id:
|
|
@@ -2463,11 +2524,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2463
2524
|
top_p: topP,
|
|
2464
2525
|
stop_sequences: stopSequences,
|
|
2465
2526
|
// provider specific settings:
|
|
2466
|
-
...isThinking && {
|
|
2527
|
+
...(isThinking || thinkingBlockBinding != null) && {
|
|
2467
2528
|
thinking: {
|
|
2468
|
-
type: thinkingType,
|
|
2529
|
+
...thinkingType != null && { type: thinkingType },
|
|
2469
2530
|
...thinkingBudget != null && { budget_tokens: thinkingBudget },
|
|
2470
|
-
...thinkingDisplay != null && { display: thinkingDisplay }
|
|
2531
|
+
...thinkingDisplay != null && { display: thinkingDisplay },
|
|
2532
|
+
...thinkingBlockBinding != null && {
|
|
2533
|
+
block_binding: {
|
|
2534
|
+
prefix_mismatch_behavior: thinkingBlockBinding.prefixMismatchBehavior
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2471
2537
|
}
|
|
2472
2538
|
},
|
|
2473
2539
|
...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
@@ -2504,14 +2570,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2504
2570
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
2505
2571
|
cache_control: anthropicOptions.cacheControl
|
|
2506
2572
|
},
|
|
2507
|
-
...((
|
|
2573
|
+
...((_c = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _c.userId) != null && {
|
|
2508
2574
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
2509
2575
|
},
|
|
2510
2576
|
// container with agent skills:
|
|
2511
2577
|
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
2512
2578
|
container: {
|
|
2513
2579
|
id: anthropicOptions.container.id,
|
|
2514
|
-
skills: (
|
|
2580
|
+
skills: (_d = anthropicOptions.container.skills) == null ? void 0 : _d.map((skill) => ({
|
|
2515
2581
|
type: skill.type,
|
|
2516
2582
|
skill_id: skill.skillId,
|
|
2517
2583
|
version: skill.version
|
|
@@ -2637,6 +2703,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2637
2703
|
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
2638
2704
|
betas.add("effort-2025-11-24");
|
|
2639
2705
|
}
|
|
2706
|
+
if (thinkingDisplay === "updates") {
|
|
2707
|
+
betas.add("thinking-display-updates-2026-08-18");
|
|
2708
|
+
}
|
|
2709
|
+
if (thinkingBlockBinding != null) {
|
|
2710
|
+
betas.add("thinking-binding-controls-2026-08-01");
|
|
2711
|
+
}
|
|
2640
2712
|
if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
|
|
2641
2713
|
betas.add("task-budgets-2026-03-13");
|
|
2642
2714
|
}
|
|
@@ -2648,7 +2720,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2648
2720
|
} else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
2649
2721
|
betas.add("server-side-fallback-2026-06-01");
|
|
2650
2722
|
}
|
|
2651
|
-
if (useStructuredOutput) {
|
|
2723
|
+
if (useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
2652
2724
|
betas.add("structured-outputs-2025-11-13");
|
|
2653
2725
|
}
|
|
2654
2726
|
const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
|
|
@@ -2665,8 +2737,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2665
2737
|
betas: toolsBetas
|
|
2666
2738
|
} = await prepareTools(
|
|
2667
2739
|
jsonResponseTool != null ? {
|
|
2668
|
-
tools: [jsonResponseTool],
|
|
2669
|
-
toolChoice: { type: "tool", toolName: jsonResponseTool.name },
|
|
2740
|
+
tools: [...tools != null ? tools : [], jsonResponseTool],
|
|
2741
|
+
toolChoice: tools != null && tools.length > 0 ? { type: "required" } : { type: "tool", toolName: jsonResponseTool.name },
|
|
2670
2742
|
disableParallelToolUse: true,
|
|
2671
2743
|
cacheControlValidator
|
|
2672
2744
|
} : {
|
|
@@ -2688,9 +2760,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2688
2760
|
...betas,
|
|
2689
2761
|
...toolsBetas,
|
|
2690
2762
|
...userSuppliedBetas,
|
|
2691
|
-
...(
|
|
2763
|
+
...(_e = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _e : []
|
|
2692
2764
|
]),
|
|
2693
|
-
|
|
2765
|
+
jsonResponseToolName: jsonResponseTool != null ? jsonResponseToolName : void 0
|
|
2694
2766
|
};
|
|
2695
2767
|
}
|
|
2696
2768
|
async getHeaders({
|
|
@@ -2748,7 +2820,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2748
2820
|
}
|
|
2749
2821
|
async doGenerate(options) {
|
|
2750
2822
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2751
|
-
const { args, warnings, betas,
|
|
2823
|
+
const { args, warnings, betas, jsonResponseToolName } = await this.getArgs({
|
|
2752
2824
|
...options,
|
|
2753
2825
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
2754
2826
|
});
|
|
@@ -2769,10 +2841,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2769
2841
|
fetch: this.config.fetch
|
|
2770
2842
|
});
|
|
2771
2843
|
const content = [];
|
|
2844
|
+
let isJsonResponseFromTool = false;
|
|
2772
2845
|
for (const part of response.content) {
|
|
2773
2846
|
switch (part.type) {
|
|
2774
2847
|
case "text": {
|
|
2775
|
-
if (
|
|
2848
|
+
if (jsonResponseToolName == null) {
|
|
2776
2849
|
const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
|
|
2777
2850
|
(citation) => citation.type === "web_search_result_location"
|
|
2778
2851
|
);
|
|
@@ -2839,18 +2912,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2839
2912
|
break;
|
|
2840
2913
|
}
|
|
2841
2914
|
case "tool_use": {
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2915
|
+
const isJsonResponseTool = part.name === jsonResponseToolName;
|
|
2916
|
+
if (isJsonResponseTool) {
|
|
2917
|
+
isJsonResponseFromTool = true;
|
|
2918
|
+
content.push({
|
|
2845
2919
|
type: "text",
|
|
2846
2920
|
text: JSON.stringify(part.input)
|
|
2847
|
-
}
|
|
2921
|
+
});
|
|
2922
|
+
} else {
|
|
2923
|
+
content.push({
|
|
2848
2924
|
type: "tool-call",
|
|
2849
2925
|
toolCallId: part.id,
|
|
2850
2926
|
toolName: part.name,
|
|
2851
2927
|
input: JSON.stringify(part.input)
|
|
2852
|
-
}
|
|
2853
|
-
|
|
2928
|
+
});
|
|
2929
|
+
}
|
|
2854
2930
|
break;
|
|
2855
2931
|
}
|
|
2856
2932
|
case "server_tool_use": {
|
|
@@ -3032,7 +3108,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3032
3108
|
content,
|
|
3033
3109
|
finishReason: mapAnthropicStopReason({
|
|
3034
3110
|
finishReason: response.stop_reason,
|
|
3035
|
-
isJsonResponseFromTool
|
|
3111
|
+
isJsonResponseFromTool
|
|
3036
3112
|
}),
|
|
3037
3113
|
usage: {
|
|
3038
3114
|
inputTokens,
|
|
@@ -3100,7 +3176,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3100
3176
|
}
|
|
3101
3177
|
async doStream(options) {
|
|
3102
3178
|
var _a, _b;
|
|
3103
|
-
const { args, warnings, betas,
|
|
3179
|
+
const { args, warnings, betas, jsonResponseToolName } = await this.getArgs({
|
|
3104
3180
|
...options,
|
|
3105
3181
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
3106
3182
|
});
|
|
@@ -3132,6 +3208,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3132
3208
|
let container = null;
|
|
3133
3209
|
let iterations = null;
|
|
3134
3210
|
let contextManagement = null;
|
|
3211
|
+
let isJsonResponseFromTool = false;
|
|
3135
3212
|
let isMessageOpen = false;
|
|
3136
3213
|
let activeMessageId;
|
|
3137
3214
|
let hasInvalidMessageSequence = false;
|
|
@@ -3215,20 +3292,31 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3215
3292
|
return;
|
|
3216
3293
|
}
|
|
3217
3294
|
case "tool_use": {
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3295
|
+
const isJsonResponseTool = value.content_block.name === jsonResponseToolName;
|
|
3296
|
+
if (isJsonResponseTool) {
|
|
3297
|
+
isJsonResponseFromTool = true;
|
|
3298
|
+
contentBlocks[value.index] = {
|
|
3299
|
+
type: "text",
|
|
3300
|
+
citations: []
|
|
3301
|
+
};
|
|
3302
|
+
controller.enqueue({
|
|
3303
|
+
type: "text-start",
|
|
3304
|
+
id: String(value.index)
|
|
3305
|
+
});
|
|
3306
|
+
} else {
|
|
3307
|
+
contentBlocks[value.index] = {
|
|
3308
|
+
type: "tool-call",
|
|
3309
|
+
toolCallId: value.content_block.id,
|
|
3310
|
+
toolName: value.content_block.name,
|
|
3311
|
+
input: "",
|
|
3312
|
+
firstDelta: true
|
|
3313
|
+
};
|
|
3314
|
+
controller.enqueue({
|
|
3227
3315
|
type: "tool-input-start",
|
|
3228
3316
|
id: value.content_block.id,
|
|
3229
3317
|
toolName: value.content_block.name
|
|
3230
|
-
}
|
|
3231
|
-
|
|
3318
|
+
});
|
|
3319
|
+
}
|
|
3232
3320
|
return;
|
|
3233
3321
|
}
|
|
3234
3322
|
case "server_tool_use": {
|
|
@@ -3424,22 +3512,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3424
3512
|
});
|
|
3425
3513
|
break;
|
|
3426
3514
|
}
|
|
3427
|
-
case "tool-call":
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
});
|
|
3441
|
-
}
|
|
3515
|
+
case "tool-call": {
|
|
3516
|
+
controller.enqueue({
|
|
3517
|
+
type: "tool-input-end",
|
|
3518
|
+
id: contentBlock.toolCallId
|
|
3519
|
+
});
|
|
3520
|
+
const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
|
|
3521
|
+
controller.enqueue({
|
|
3522
|
+
type: "tool-call",
|
|
3523
|
+
toolCallId: contentBlock.toolCallId,
|
|
3524
|
+
toolName,
|
|
3525
|
+
input: contentBlock.input === "" ? "{}" : contentBlock.input,
|
|
3526
|
+
providerExecuted: contentBlock.providerExecuted
|
|
3527
|
+
});
|
|
3442
3528
|
break;
|
|
3529
|
+
}
|
|
3443
3530
|
}
|
|
3444
3531
|
delete contentBlocks[value.index];
|
|
3445
3532
|
}
|
|
@@ -3450,7 +3537,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3450
3537
|
const deltaType = value.delta.type;
|
|
3451
3538
|
switch (deltaType) {
|
|
3452
3539
|
case "text_delta": {
|
|
3453
|
-
if (
|
|
3540
|
+
if (jsonResponseToolName != null) {
|
|
3454
3541
|
return;
|
|
3455
3542
|
}
|
|
3456
3543
|
controller.enqueue({
|
|
@@ -3499,10 +3586,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3499
3586
|
if (delta.length === 0) {
|
|
3500
3587
|
return;
|
|
3501
3588
|
}
|
|
3502
|
-
if (
|
|
3503
|
-
if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
|
|
3504
|
-
return;
|
|
3505
|
-
}
|
|
3589
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) === "text") {
|
|
3506
3590
|
controller.enqueue({
|
|
3507
3591
|
type: "text-delta",
|
|
3508
3592
|
id: String(value.index),
|
|
@@ -3611,7 +3695,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3611
3695
|
usage.totalTokens = ((_g = usage.inputTokens) != null ? _g : 0) + ((_h = usage.outputTokens) != null ? _h : 0);
|
|
3612
3696
|
finishReason = mapAnthropicStopReason({
|
|
3613
3697
|
finishReason: value.delta.stop_reason,
|
|
3614
|
-
isJsonResponseFromTool
|
|
3698
|
+
isJsonResponseFromTool
|
|
3615
3699
|
});
|
|
3616
3700
|
stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
|
|
3617
3701
|
stopSequence = (_i = value.delta.stop_sequence) != null ? _i : null;
|
|
@@ -3736,7 +3820,7 @@ function getModelCapabilities(modelId) {
|
|
|
3736
3820
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
3737
3821
|
isKnownModel: true
|
|
3738
3822
|
};
|
|
3739
|
-
} else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
|
|
3823
|
+
} 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")) {
|
|
3740
3824
|
return {
|
|
3741
3825
|
maxOutputTokens: 128e3,
|
|
3742
3826
|
supportsStructuredOutput: true,
|