@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
|
@@ -2,7 +2,7 @@ import { LanguageModelV2, JSONSchema7, SharedV2ProviderMetadata, LanguageModelV2
|
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
|
-
type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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 & {});
|
|
5
|
+
type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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 & {});
|
|
6
6
|
|
|
7
7
|
type AnthropicMessagesConfig = {
|
|
8
8
|
provider: string;
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { LanguageModelV2, JSONSchema7, SharedV2ProviderMetadata, LanguageModelV2
|
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
|
-
type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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 & {});
|
|
5
|
+
type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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 & {});
|
|
6
6
|
|
|
7
7
|
type AnthropicMessagesConfig = {
|
|
8
8
|
provider: string;
|
package/dist/internal/index.js
CHANGED
|
@@ -660,6 +660,19 @@ var anthropicFilePartProviderOptions = import_v43.z.object({
|
|
|
660
660
|
context: import_v43.z.string().optional()
|
|
661
661
|
});
|
|
662
662
|
var anthropicSystemMessageProviderOptions = import_v43.z.object({
|
|
663
|
+
/**
|
|
664
|
+
* Controls when a mid-conversation system message is cleared.
|
|
665
|
+
*
|
|
666
|
+
* The value is forwarded to Anthropic as `clear_at`. The required
|
|
667
|
+
* `mid-conversation-system-clear-at-2026-08-21` beta is added automatically.
|
|
668
|
+
*/
|
|
669
|
+
clearAt: import_v43.z.literal("next_user_message").optional(),
|
|
670
|
+
/**
|
|
671
|
+
* Overrides the effort for the turn following this mid-conversation system
|
|
672
|
+
* message. The required `mid-conversation-effort-2026-08-01` beta is added
|
|
673
|
+
* automatically.
|
|
674
|
+
*/
|
|
675
|
+
effort: import_v43.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
663
676
|
/**
|
|
664
677
|
* Mid-conversation tool changes. Adds or removes tools from the
|
|
665
678
|
* conversation's tool set between turns without invalidating the prompt
|
|
@@ -687,6 +700,14 @@ var anthropicSystemMessageProviderOptions = import_v43.z.object({
|
|
|
687
700
|
])
|
|
688
701
|
).optional()
|
|
689
702
|
});
|
|
703
|
+
var anthropicThinkingBlockBinding = import_v43.z.object({
|
|
704
|
+
/**
|
|
705
|
+
* Controls behavior when a replayed thinking block does not match its
|
|
706
|
+
* conversation prefix. The `drop_block` behavior drops the mismatched block
|
|
707
|
+
* instead of returning an invalid signature error.
|
|
708
|
+
*/
|
|
709
|
+
prefixMismatchBehavior: import_v43.z.literal("drop_block")
|
|
710
|
+
});
|
|
690
711
|
var anthropicProviderOptions = import_v43.z.object({
|
|
691
712
|
/**
|
|
692
713
|
* Whether to send reasoning to the model.
|
|
@@ -698,8 +719,8 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
698
719
|
* Determines how structured outputs are generated.
|
|
699
720
|
*
|
|
700
721
|
* - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
|
|
701
|
-
* - `jsonTool`: Use a special
|
|
702
|
-
* - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool'.
|
|
722
|
+
* - `jsonTool`: Use a special JSON response tool to specify the structured output format (default for most models).
|
|
723
|
+
* - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default for Fable 5.1).
|
|
703
724
|
*/
|
|
704
725
|
structuredOutputMode: import_v43.z.enum(["outputFormat", "jsonTool", "auto"]).optional(),
|
|
705
726
|
/**
|
|
@@ -708,7 +729,7 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
708
729
|
* When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
|
|
709
730
|
* Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
|
|
710
731
|
*/
|
|
711
|
-
thinking: import_v43.z.
|
|
732
|
+
thinking: import_v43.z.union([
|
|
712
733
|
import_v43.z.object({
|
|
713
734
|
/** for Sonnet 4.6, Opus 4.6, and newer models */
|
|
714
735
|
type: import_v43.z.literal("adaptive"),
|
|
@@ -716,16 +737,34 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
716
737
|
* Controls whether thinking content is included in the response.
|
|
717
738
|
* - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
|
|
718
739
|
* - `"summarized"`: Thinking content is returned. Required to see reasoning output.
|
|
740
|
+
* - `"updates"`: Thinking summaries are emitted between tool calls.
|
|
719
741
|
*/
|
|
720
|
-
display: import_v43.z.enum(["omitted", "summarized"]).optional()
|
|
742
|
+
display: import_v43.z.enum(["omitted", "summarized", "updates"]).optional(),
|
|
743
|
+
/**
|
|
744
|
+
* Controls handling for thinking blocks whose conversation prefix no
|
|
745
|
+
* longer matches. Forwarded as `block_binding`.
|
|
746
|
+
*/
|
|
747
|
+
blockBinding: anthropicThinkingBlockBinding.optional()
|
|
721
748
|
}),
|
|
722
749
|
import_v43.z.object({
|
|
723
750
|
/** for models before Opus 4.6, except Sonnet 4.6 still supports it */
|
|
724
751
|
type: import_v43.z.literal("enabled"),
|
|
725
|
-
budgetTokens: import_v43.z.number().optional()
|
|
752
|
+
budgetTokens: import_v43.z.number().optional(),
|
|
753
|
+
/**
|
|
754
|
+
* Controls handling for thinking blocks whose conversation prefix no
|
|
755
|
+
* longer matches. Forwarded as `block_binding`.
|
|
756
|
+
*/
|
|
757
|
+
blockBinding: anthropicThinkingBlockBinding.optional()
|
|
726
758
|
}),
|
|
727
759
|
import_v43.z.object({
|
|
728
760
|
type: import_v43.z.literal("disabled")
|
|
761
|
+
}),
|
|
762
|
+
import_v43.z.object({
|
|
763
|
+
/**
|
|
764
|
+
* Configure prefix mismatch handling without changing the model's
|
|
765
|
+
* default thinking mode.
|
|
766
|
+
*/
|
|
767
|
+
blockBinding: anthropicThinkingBlockBinding
|
|
729
768
|
})
|
|
730
769
|
]).optional(),
|
|
731
770
|
/**
|
|
@@ -1468,7 +1507,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1468
1507
|
warnings,
|
|
1469
1508
|
cacheControlValidator
|
|
1470
1509
|
}) {
|
|
1471
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1510
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1472
1511
|
const betas = /* @__PURE__ */ new Set();
|
|
1473
1512
|
const blocks = groupIntoBlocks(prompt);
|
|
1474
1513
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -1502,6 +1541,8 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1502
1541
|
case "system": {
|
|
1503
1542
|
const content = [];
|
|
1504
1543
|
let toolChangeCount = 0;
|
|
1544
|
+
let clearAt = void 0;
|
|
1545
|
+
let effort = void 0;
|
|
1505
1546
|
for (const { content: text, providerOptions } of block.messages) {
|
|
1506
1547
|
const systemMessageOptions = await (0, import_provider_utils9.parseProviderOptions)({
|
|
1507
1548
|
provider: "anthropic",
|
|
@@ -1509,7 +1550,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1509
1550
|
schema: anthropicSystemMessageProviderOptions
|
|
1510
1551
|
});
|
|
1511
1552
|
const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
|
|
1512
|
-
|
|
1553
|
+
clearAt = (_b = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) != null ? _b : clearAt;
|
|
1554
|
+
effort = (_c = systemMessageOptions == null ? void 0 : systemMessageOptions.effort) != null ? _c : effort;
|
|
1555
|
+
if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
|
|
1513
1556
|
content.push({
|
|
1514
1557
|
type: "text",
|
|
1515
1558
|
text,
|
|
@@ -1530,22 +1573,34 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1530
1573
|
});
|
|
1531
1574
|
}
|
|
1532
1575
|
}
|
|
1533
|
-
|
|
1534
|
-
|
|
1576
|
+
const hasMidConversationOptions = toolChangeCount > 0 || clearAt != null || effort != null;
|
|
1577
|
+
if (i === 0 || system == null && !hasMidConversationOptions) {
|
|
1578
|
+
if (hasMidConversationOptions) {
|
|
1535
1579
|
warnings.push({
|
|
1536
1580
|
type: "other",
|
|
1537
|
-
message: "
|
|
1581
|
+
message: "mid-conversation Anthropic system message options on the initial system message are not supported. The options have been ignored."
|
|
1538
1582
|
});
|
|
1539
1583
|
}
|
|
1540
1584
|
system = content.filter(
|
|
1541
1585
|
(part) => part.type === "text"
|
|
1542
1586
|
);
|
|
1543
1587
|
} else {
|
|
1544
|
-
messages.push({
|
|
1588
|
+
messages.push({
|
|
1589
|
+
role: "system",
|
|
1590
|
+
content,
|
|
1591
|
+
...clearAt != null && { clear_at: clearAt },
|
|
1592
|
+
...effort != null && { output_config: { effort } }
|
|
1593
|
+
});
|
|
1545
1594
|
betas.add("mid-conversation-system-2026-04-07");
|
|
1546
1595
|
if (toolChangeCount > 0) {
|
|
1547
1596
|
betas.add("mid-conversation-tool-changes-2026-07-01");
|
|
1548
1597
|
}
|
|
1598
|
+
if (clearAt != null) {
|
|
1599
|
+
betas.add("mid-conversation-system-clear-at-2026-08-21");
|
|
1600
|
+
}
|
|
1601
|
+
if (effort != null) {
|
|
1602
|
+
betas.add("mid-conversation-effort-2026-08-01");
|
|
1603
|
+
}
|
|
1549
1604
|
}
|
|
1550
1605
|
break;
|
|
1551
1606
|
}
|
|
@@ -1558,10 +1613,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1558
1613
|
for (let j = 0; j < content.length; j++) {
|
|
1559
1614
|
const part = content[j];
|
|
1560
1615
|
const isLastPart = j === content.length - 1;
|
|
1561
|
-
const cacheControl = (
|
|
1616
|
+
const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
|
|
1562
1617
|
type: "user message part",
|
|
1563
1618
|
canCache: true
|
|
1564
|
-
})) != null ?
|
|
1619
|
+
})) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
1565
1620
|
type: "user message",
|
|
1566
1621
|
canCache: true
|
|
1567
1622
|
}) : void 0;
|
|
@@ -1606,7 +1661,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1606
1661
|
media_type: "application/pdf",
|
|
1607
1662
|
data: (0, import_provider_utils9.convertToBase64)(part.data)
|
|
1608
1663
|
},
|
|
1609
|
-
title: (
|
|
1664
|
+
title: (_e = metadata.title) != null ? _e : part.filename,
|
|
1610
1665
|
...metadata.context && { context: metadata.context },
|
|
1611
1666
|
...enableCitations && {
|
|
1612
1667
|
citations: { enabled: true }
|
|
@@ -1630,7 +1685,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1630
1685
|
media_type: "text/plain",
|
|
1631
1686
|
data: convertToString(part.data)
|
|
1632
1687
|
},
|
|
1633
|
-
title: (
|
|
1688
|
+
title: (_f = metadata.title) != null ? _f : part.filename,
|
|
1634
1689
|
...metadata.context && { context: metadata.context },
|
|
1635
1690
|
...enableCitations && {
|
|
1636
1691
|
citations: { enabled: true }
|
|
@@ -1652,10 +1707,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1652
1707
|
for (let i2 = 0; i2 < content.length; i2++) {
|
|
1653
1708
|
const part = content[i2];
|
|
1654
1709
|
const isLastPart = i2 === content.length - 1;
|
|
1655
|
-
const cacheControl = (
|
|
1710
|
+
const cacheControl = (_g = validator.getCacheControl(part.providerOptions, {
|
|
1656
1711
|
type: "tool result part",
|
|
1657
1712
|
canCache: true
|
|
1658
|
-
})) != null ?
|
|
1713
|
+
})) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
1659
1714
|
type: "tool result message",
|
|
1660
1715
|
canCache: true
|
|
1661
1716
|
}) : void 0;
|
|
@@ -1737,16 +1792,16 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1737
1792
|
for (let k = 0; k < content.length; k++) {
|
|
1738
1793
|
const part = content[k];
|
|
1739
1794
|
const isLastContentPart = k === content.length - 1;
|
|
1740
|
-
const cacheControl = (
|
|
1795
|
+
const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
|
|
1741
1796
|
type: "assistant message part",
|
|
1742
1797
|
canCache: true
|
|
1743
|
-
})) != null ?
|
|
1798
|
+
})) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
1744
1799
|
type: "assistant message",
|
|
1745
1800
|
canCache: true
|
|
1746
1801
|
}) : void 0;
|
|
1747
1802
|
switch (part.type) {
|
|
1748
1803
|
case "text": {
|
|
1749
|
-
const textMetadata = (
|
|
1804
|
+
const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
|
|
1750
1805
|
if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
|
|
1751
1806
|
anthropicContent.push({
|
|
1752
1807
|
type: "compaction",
|
|
@@ -2243,6 +2298,15 @@ function isPlainObject(value) {
|
|
|
2243
2298
|
}
|
|
2244
2299
|
|
|
2245
2300
|
// src/anthropic-messages-language-model.ts
|
|
2301
|
+
function getJsonResponseToolName(tools) {
|
|
2302
|
+
const toolNames = new Set(tools == null ? void 0 : tools.map((tool) => tool.name));
|
|
2303
|
+
let name = "json";
|
|
2304
|
+
let suffix = 1;
|
|
2305
|
+
while (toolNames.has(name)) {
|
|
2306
|
+
name = `json_${suffix++}`;
|
|
2307
|
+
}
|
|
2308
|
+
return name;
|
|
2309
|
+
}
|
|
2246
2310
|
function createCitationSource(citation, citationDocuments, generateId2) {
|
|
2247
2311
|
var _a;
|
|
2248
2312
|
if (citation.type !== "page_location" && citation.type !== "char_location") {
|
|
@@ -2306,7 +2370,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2306
2370
|
toolChoice,
|
|
2307
2371
|
providerOptions
|
|
2308
2372
|
}) {
|
|
2309
|
-
var _a, _b, _c, _d, _e
|
|
2373
|
+
var _a, _b, _c, _d, _e;
|
|
2310
2374
|
const warnings = [];
|
|
2311
2375
|
if (frequencyPenalty != null) {
|
|
2312
2376
|
warnings.push({
|
|
@@ -2348,12 +2412,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2348
2412
|
setting: "responseFormat",
|
|
2349
2413
|
details: "JSON response format requires a schema. The response format is ignored."
|
|
2350
2414
|
});
|
|
2351
|
-
} else if (tools != null) {
|
|
2352
|
-
warnings.push({
|
|
2353
|
-
type: "unsupported-setting",
|
|
2354
|
-
setting: "tools",
|
|
2355
|
-
details: "JSON response format does not support tools. The provided tools are ignored."
|
|
2356
|
-
});
|
|
2357
2415
|
}
|
|
2358
2416
|
}
|
|
2359
2417
|
const anthropicOptions = await (0, import_provider_utils10.parseProviderOptions)({
|
|
@@ -2401,11 +2459,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2401
2459
|
}
|
|
2402
2460
|
}
|
|
2403
2461
|
const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
|
|
2404
|
-
const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "jsonTool";
|
|
2462
|
+
const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : this.modelId.includes("claude-fable-5-1") ? "auto" : "jsonTool";
|
|
2405
2463
|
const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
2464
|
+
const jsonResponseToolName = getJsonResponseToolName(tools);
|
|
2406
2465
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
|
|
2407
2466
|
type: "function",
|
|
2408
|
-
name:
|
|
2467
|
+
name: jsonResponseToolName,
|
|
2409
2468
|
description: "Respond with a JSON object.",
|
|
2410
2469
|
inputSchema: responseFormat.schema
|
|
2411
2470
|
} : void 0;
|
|
@@ -2423,7 +2482,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2423
2482
|
warnings,
|
|
2424
2483
|
cacheControlValidator
|
|
2425
2484
|
});
|
|
2426
|
-
|
|
2485
|
+
const thinkingOptions = anthropicOptions == null ? void 0 : anthropicOptions.thinking;
|
|
2486
|
+
const thinkingType = thinkingOptions != null && "type" in thinkingOptions ? thinkingOptions.type : void 0;
|
|
2487
|
+
if (rejectsThinkingDisabledAboveHighEffort && thinkingType === "disabled" && anthropicOptions != null && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
|
|
2427
2488
|
warnings.push({
|
|
2428
2489
|
type: "unsupported-setting",
|
|
2429
2490
|
setting: "providerOptions.anthropic.effort",
|
|
@@ -2431,10 +2492,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2431
2492
|
});
|
|
2432
2493
|
anthropicOptions.effort = "high";
|
|
2433
2494
|
}
|
|
2434
|
-
const thinkingType = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.type;
|
|
2435
2495
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
2436
|
-
let thinkingBudget =
|
|
2437
|
-
const thinkingDisplay =
|
|
2496
|
+
let thinkingBudget = thinkingOptions != null && "budgetTokens" in thinkingOptions ? thinkingOptions.budgetTokens : void 0;
|
|
2497
|
+
const thinkingDisplay = thinkingOptions != null && "display" in thinkingOptions ? thinkingOptions.display : void 0;
|
|
2498
|
+
const thinkingBlockBinding = thinkingOptions != null && "blockBinding" in thinkingOptions ? thinkingOptions.blockBinding : void 0;
|
|
2438
2499
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
2439
2500
|
const baseArgs = {
|
|
2440
2501
|
// model id:
|
|
@@ -2446,11 +2507,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2446
2507
|
top_p: topP,
|
|
2447
2508
|
stop_sequences: stopSequences,
|
|
2448
2509
|
// provider specific settings:
|
|
2449
|
-
...isThinking && {
|
|
2510
|
+
...(isThinking || thinkingBlockBinding != null) && {
|
|
2450
2511
|
thinking: {
|
|
2451
|
-
type: thinkingType,
|
|
2512
|
+
...thinkingType != null && { type: thinkingType },
|
|
2452
2513
|
...thinkingBudget != null && { budget_tokens: thinkingBudget },
|
|
2453
|
-
...thinkingDisplay != null && { display: thinkingDisplay }
|
|
2514
|
+
...thinkingDisplay != null && { display: thinkingDisplay },
|
|
2515
|
+
...thinkingBlockBinding != null && {
|
|
2516
|
+
block_binding: {
|
|
2517
|
+
prefix_mismatch_behavior: thinkingBlockBinding.prefixMismatchBehavior
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2454
2520
|
}
|
|
2455
2521
|
},
|
|
2456
2522
|
...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
@@ -2487,14 +2553,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2487
2553
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
2488
2554
|
cache_control: anthropicOptions.cacheControl
|
|
2489
2555
|
},
|
|
2490
|
-
...((
|
|
2556
|
+
...((_c = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _c.userId) != null && {
|
|
2491
2557
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
2492
2558
|
},
|
|
2493
2559
|
// container with agent skills:
|
|
2494
2560
|
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
2495
2561
|
container: {
|
|
2496
2562
|
id: anthropicOptions.container.id,
|
|
2497
|
-
skills: (
|
|
2563
|
+
skills: (_d = anthropicOptions.container.skills) == null ? void 0 : _d.map((skill) => ({
|
|
2498
2564
|
type: skill.type,
|
|
2499
2565
|
skill_id: skill.skillId,
|
|
2500
2566
|
version: skill.version
|
|
@@ -2620,6 +2686,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2620
2686
|
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
2621
2687
|
betas.add("effort-2025-11-24");
|
|
2622
2688
|
}
|
|
2689
|
+
if (thinkingDisplay === "updates") {
|
|
2690
|
+
betas.add("thinking-display-updates-2026-08-18");
|
|
2691
|
+
}
|
|
2692
|
+
if (thinkingBlockBinding != null) {
|
|
2693
|
+
betas.add("thinking-binding-controls-2026-08-01");
|
|
2694
|
+
}
|
|
2623
2695
|
if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
|
|
2624
2696
|
betas.add("task-budgets-2026-03-13");
|
|
2625
2697
|
}
|
|
@@ -2631,7 +2703,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2631
2703
|
} else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
2632
2704
|
betas.add("server-side-fallback-2026-06-01");
|
|
2633
2705
|
}
|
|
2634
|
-
if (useStructuredOutput) {
|
|
2706
|
+
if (useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
2635
2707
|
betas.add("structured-outputs-2025-11-13");
|
|
2636
2708
|
}
|
|
2637
2709
|
const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
|
|
@@ -2648,8 +2720,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2648
2720
|
betas: toolsBetas
|
|
2649
2721
|
} = await prepareTools(
|
|
2650
2722
|
jsonResponseTool != null ? {
|
|
2651
|
-
tools: [jsonResponseTool],
|
|
2652
|
-
toolChoice: { type: "tool", toolName: jsonResponseTool.name },
|
|
2723
|
+
tools: [...tools != null ? tools : [], jsonResponseTool],
|
|
2724
|
+
toolChoice: tools != null && tools.length > 0 ? { type: "required" } : { type: "tool", toolName: jsonResponseTool.name },
|
|
2653
2725
|
disableParallelToolUse: true,
|
|
2654
2726
|
cacheControlValidator
|
|
2655
2727
|
} : {
|
|
@@ -2671,9 +2743,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2671
2743
|
...betas,
|
|
2672
2744
|
...toolsBetas,
|
|
2673
2745
|
...userSuppliedBetas,
|
|
2674
|
-
...(
|
|
2746
|
+
...(_e = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _e : []
|
|
2675
2747
|
]),
|
|
2676
|
-
|
|
2748
|
+
jsonResponseToolName: jsonResponseTool != null ? jsonResponseToolName : void 0
|
|
2677
2749
|
};
|
|
2678
2750
|
}
|
|
2679
2751
|
async getHeaders({
|
|
@@ -2731,7 +2803,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2731
2803
|
}
|
|
2732
2804
|
async doGenerate(options) {
|
|
2733
2805
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2734
|
-
const { args, warnings, betas,
|
|
2806
|
+
const { args, warnings, betas, jsonResponseToolName } = await this.getArgs({
|
|
2735
2807
|
...options,
|
|
2736
2808
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
2737
2809
|
});
|
|
@@ -2752,10 +2824,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2752
2824
|
fetch: this.config.fetch
|
|
2753
2825
|
});
|
|
2754
2826
|
const content = [];
|
|
2827
|
+
let isJsonResponseFromTool = false;
|
|
2755
2828
|
for (const part of response.content) {
|
|
2756
2829
|
switch (part.type) {
|
|
2757
2830
|
case "text": {
|
|
2758
|
-
if (
|
|
2831
|
+
if (jsonResponseToolName == null) {
|
|
2759
2832
|
const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
|
|
2760
2833
|
(citation) => citation.type === "web_search_result_location"
|
|
2761
2834
|
);
|
|
@@ -2822,18 +2895,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2822
2895
|
break;
|
|
2823
2896
|
}
|
|
2824
2897
|
case "tool_use": {
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2898
|
+
const isJsonResponseTool = part.name === jsonResponseToolName;
|
|
2899
|
+
if (isJsonResponseTool) {
|
|
2900
|
+
isJsonResponseFromTool = true;
|
|
2901
|
+
content.push({
|
|
2828
2902
|
type: "text",
|
|
2829
2903
|
text: JSON.stringify(part.input)
|
|
2830
|
-
}
|
|
2904
|
+
});
|
|
2905
|
+
} else {
|
|
2906
|
+
content.push({
|
|
2831
2907
|
type: "tool-call",
|
|
2832
2908
|
toolCallId: part.id,
|
|
2833
2909
|
toolName: part.name,
|
|
2834
2910
|
input: JSON.stringify(part.input)
|
|
2835
|
-
}
|
|
2836
|
-
|
|
2911
|
+
});
|
|
2912
|
+
}
|
|
2837
2913
|
break;
|
|
2838
2914
|
}
|
|
2839
2915
|
case "server_tool_use": {
|
|
@@ -3015,7 +3091,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3015
3091
|
content,
|
|
3016
3092
|
finishReason: mapAnthropicStopReason({
|
|
3017
3093
|
finishReason: response.stop_reason,
|
|
3018
|
-
isJsonResponseFromTool
|
|
3094
|
+
isJsonResponseFromTool
|
|
3019
3095
|
}),
|
|
3020
3096
|
usage: {
|
|
3021
3097
|
inputTokens,
|
|
@@ -3083,7 +3159,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3083
3159
|
}
|
|
3084
3160
|
async doStream(options) {
|
|
3085
3161
|
var _a, _b;
|
|
3086
|
-
const { args, warnings, betas,
|
|
3162
|
+
const { args, warnings, betas, jsonResponseToolName } = await this.getArgs({
|
|
3087
3163
|
...options,
|
|
3088
3164
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
3089
3165
|
});
|
|
@@ -3115,6 +3191,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3115
3191
|
let container = null;
|
|
3116
3192
|
let iterations = null;
|
|
3117
3193
|
let contextManagement = null;
|
|
3194
|
+
let isJsonResponseFromTool = false;
|
|
3118
3195
|
let isMessageOpen = false;
|
|
3119
3196
|
let activeMessageId;
|
|
3120
3197
|
let hasInvalidMessageSequence = false;
|
|
@@ -3198,20 +3275,31 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3198
3275
|
return;
|
|
3199
3276
|
}
|
|
3200
3277
|
case "tool_use": {
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3278
|
+
const isJsonResponseTool = value.content_block.name === jsonResponseToolName;
|
|
3279
|
+
if (isJsonResponseTool) {
|
|
3280
|
+
isJsonResponseFromTool = true;
|
|
3281
|
+
contentBlocks[value.index] = {
|
|
3282
|
+
type: "text",
|
|
3283
|
+
citations: []
|
|
3284
|
+
};
|
|
3285
|
+
controller.enqueue({
|
|
3286
|
+
type: "text-start",
|
|
3287
|
+
id: String(value.index)
|
|
3288
|
+
});
|
|
3289
|
+
} else {
|
|
3290
|
+
contentBlocks[value.index] = {
|
|
3291
|
+
type: "tool-call",
|
|
3292
|
+
toolCallId: value.content_block.id,
|
|
3293
|
+
toolName: value.content_block.name,
|
|
3294
|
+
input: "",
|
|
3295
|
+
firstDelta: true
|
|
3296
|
+
};
|
|
3297
|
+
controller.enqueue({
|
|
3210
3298
|
type: "tool-input-start",
|
|
3211
3299
|
id: value.content_block.id,
|
|
3212
3300
|
toolName: value.content_block.name
|
|
3213
|
-
}
|
|
3214
|
-
|
|
3301
|
+
});
|
|
3302
|
+
}
|
|
3215
3303
|
return;
|
|
3216
3304
|
}
|
|
3217
3305
|
case "server_tool_use": {
|
|
@@ -3407,22 +3495,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3407
3495
|
});
|
|
3408
3496
|
break;
|
|
3409
3497
|
}
|
|
3410
|
-
case "tool-call":
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
});
|
|
3424
|
-
}
|
|
3498
|
+
case "tool-call": {
|
|
3499
|
+
controller.enqueue({
|
|
3500
|
+
type: "tool-input-end",
|
|
3501
|
+
id: contentBlock.toolCallId
|
|
3502
|
+
});
|
|
3503
|
+
const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
|
|
3504
|
+
controller.enqueue({
|
|
3505
|
+
type: "tool-call",
|
|
3506
|
+
toolCallId: contentBlock.toolCallId,
|
|
3507
|
+
toolName,
|
|
3508
|
+
input: contentBlock.input === "" ? "{}" : contentBlock.input,
|
|
3509
|
+
providerExecuted: contentBlock.providerExecuted
|
|
3510
|
+
});
|
|
3425
3511
|
break;
|
|
3512
|
+
}
|
|
3426
3513
|
}
|
|
3427
3514
|
delete contentBlocks[value.index];
|
|
3428
3515
|
}
|
|
@@ -3433,7 +3520,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3433
3520
|
const deltaType = value.delta.type;
|
|
3434
3521
|
switch (deltaType) {
|
|
3435
3522
|
case "text_delta": {
|
|
3436
|
-
if (
|
|
3523
|
+
if (jsonResponseToolName != null) {
|
|
3437
3524
|
return;
|
|
3438
3525
|
}
|
|
3439
3526
|
controller.enqueue({
|
|
@@ -3482,10 +3569,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3482
3569
|
if (delta.length === 0) {
|
|
3483
3570
|
return;
|
|
3484
3571
|
}
|
|
3485
|
-
if (
|
|
3486
|
-
if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
|
|
3487
|
-
return;
|
|
3488
|
-
}
|
|
3572
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) === "text") {
|
|
3489
3573
|
controller.enqueue({
|
|
3490
3574
|
type: "text-delta",
|
|
3491
3575
|
id: String(value.index),
|
|
@@ -3594,7 +3678,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3594
3678
|
usage.totalTokens = ((_g = usage.inputTokens) != null ? _g : 0) + ((_h = usage.outputTokens) != null ? _h : 0);
|
|
3595
3679
|
finishReason = mapAnthropicStopReason({
|
|
3596
3680
|
finishReason: value.delta.stop_reason,
|
|
3597
|
-
isJsonResponseFromTool
|
|
3681
|
+
isJsonResponseFromTool
|
|
3598
3682
|
});
|
|
3599
3683
|
stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
|
|
3600
3684
|
stopSequence = (_i = value.delta.stop_sequence) != null ? _i : null;
|
|
@@ -3719,7 +3803,7 @@ function getModelCapabilities(modelId) {
|
|
|
3719
3803
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
3720
3804
|
isKnownModel: true
|
|
3721
3805
|
};
|
|
3722
|
-
} else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
|
|
3806
|
+
} 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")) {
|
|
3723
3807
|
return {
|
|
3724
3808
|
maxOutputTokens: 128e3,
|
|
3725
3809
|
supportsStructuredOutput: true,
|