@ai-sdk/anthropic 3.0.100 → 3.0.102
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 +17 -4
- package/dist/index.d.ts +17 -4
- package/dist/index.js +175 -66
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +175 -66
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +15 -2
- package/dist/internal/index.d.ts +15 -2
- package/dist/internal/index.js +176 -65
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +175 -65
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +79 -2
- package/package.json +1 -1
- package/src/anthropic-messages-api.ts +14 -1
- package/src/anthropic-messages-language-model.ts +72 -6
- package/src/anthropic-messages-options.ts +64 -20
- package/src/convert-to-anthropic-messages-prompt.ts +64 -12
- package/src/index.ts +1 -0
- package/src/internal/index.ts +4 -1
|
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
|
|
|
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-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
|
|
5
|
+
type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
|
|
6
6
|
|
|
7
7
|
type AnthropicMessagesConfig = {
|
|
8
8
|
provider: string;
|
|
@@ -46,6 +46,19 @@ declare class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
46
46
|
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
47
47
|
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns the capabilities of a Claude model that are used for defaults and feature selection.
|
|
51
|
+
*
|
|
52
|
+
* @see https://docs.claude.com/en/docs/about-claude/models/overview#model-comparison-table
|
|
53
|
+
* @see https://platform.claude.com/docs/en/build-with-claude/structured-outputs
|
|
54
|
+
*/
|
|
55
|
+
declare function getModelCapabilities(modelId: string): {
|
|
56
|
+
maxOutputTokens: number;
|
|
57
|
+
supportsStructuredOutput: boolean;
|
|
58
|
+
rejectsSamplingParameters: boolean;
|
|
59
|
+
rejectsThinkingDisabledAboveHighEffort: boolean;
|
|
60
|
+
isKnownModel: boolean;
|
|
61
|
+
};
|
|
49
62
|
|
|
50
63
|
declare const anthropicTools: {
|
|
51
64
|
/**
|
|
@@ -1043,4 +1056,4 @@ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cache
|
|
|
1043
1056
|
*/
|
|
1044
1057
|
declare function sanitizeJsonSchema(schema: JSONSchema7): JSONSchema7;
|
|
1045
1058
|
|
|
1046
|
-
export { AnthropicMessagesLanguageModel, type AnthropicMessagesModelId, anthropicTools, prepareTools, sanitizeJsonSchema };
|
|
1059
|
+
export { AnthropicMessagesLanguageModel, type AnthropicMessagesModelId, anthropicTools, getModelCapabilities, prepareTools, sanitizeJsonSchema };
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
|
|
|
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-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
|
|
5
|
+
type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
|
|
6
6
|
|
|
7
7
|
type AnthropicMessagesConfig = {
|
|
8
8
|
provider: string;
|
|
@@ -46,6 +46,19 @@ declare class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
46
46
|
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
47
47
|
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns the capabilities of a Claude model that are used for defaults and feature selection.
|
|
51
|
+
*
|
|
52
|
+
* @see https://docs.claude.com/en/docs/about-claude/models/overview#model-comparison-table
|
|
53
|
+
* @see https://platform.claude.com/docs/en/build-with-claude/structured-outputs
|
|
54
|
+
*/
|
|
55
|
+
declare function getModelCapabilities(modelId: string): {
|
|
56
|
+
maxOutputTokens: number;
|
|
57
|
+
supportsStructuredOutput: boolean;
|
|
58
|
+
rejectsSamplingParameters: boolean;
|
|
59
|
+
rejectsThinkingDisabledAboveHighEffort: boolean;
|
|
60
|
+
isKnownModel: boolean;
|
|
61
|
+
};
|
|
49
62
|
|
|
50
63
|
declare const anthropicTools: {
|
|
51
64
|
/**
|
|
@@ -1043,4 +1056,4 @@ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cache
|
|
|
1043
1056
|
*/
|
|
1044
1057
|
declare function sanitizeJsonSchema(schema: JSONSchema7): JSONSchema7;
|
|
1045
1058
|
|
|
1046
|
-
export { AnthropicMessagesLanguageModel, type AnthropicMessagesModelId, anthropicTools, prepareTools, sanitizeJsonSchema };
|
|
1059
|
+
export { AnthropicMessagesLanguageModel, type AnthropicMessagesModelId, anthropicTools, getModelCapabilities, prepareTools, sanitizeJsonSchema };
|
package/dist/internal/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
AnthropicMessagesLanguageModel: () => AnthropicMessagesLanguageModel,
|
|
24
24
|
anthropicTools: () => anthropicTools,
|
|
25
|
+
getModelCapabilities: () => getModelCapabilities,
|
|
25
26
|
prepareTools: () => prepareTools,
|
|
26
27
|
sanitizeJsonSchema: () => sanitizeJsonSchema
|
|
27
28
|
});
|
|
@@ -887,6 +888,34 @@ var anthropicFilePartProviderOptions = import_v43.z.object({
|
|
|
887
888
|
*/
|
|
888
889
|
context: import_v43.z.string().optional()
|
|
889
890
|
});
|
|
891
|
+
var anthropicSystemMessageProviderOptions = import_v43.z.object({
|
|
892
|
+
/**
|
|
893
|
+
* Mid-conversation tool changes. Adds or removes tools from the
|
|
894
|
+
* conversation's tool set between turns without invalidating the prompt
|
|
895
|
+
* cache.
|
|
896
|
+
*
|
|
897
|
+
* Only supported on system messages that appear mid-conversation (not the
|
|
898
|
+
* initial system prompt). A system message carrying tool changes must come
|
|
899
|
+
* right before an assistant message or at the end of the messages.
|
|
900
|
+
*
|
|
901
|
+
* Tools referenced by a `tool_addition` must be declared in the `tools`
|
|
902
|
+
* option (typically with `deferLoading: true` so they are not loaded until
|
|
903
|
+
* the addition surfaces them). The required
|
|
904
|
+
* `mid-conversation-tool-changes-2026-07-01` beta is added automatically.
|
|
905
|
+
*/
|
|
906
|
+
toolChanges: import_v43.z.array(
|
|
907
|
+
import_v43.z.discriminatedUnion("type", [
|
|
908
|
+
import_v43.z.object({
|
|
909
|
+
type: import_v43.z.literal("tool_addition"),
|
|
910
|
+
toolName: import_v43.z.string()
|
|
911
|
+
}),
|
|
912
|
+
import_v43.z.object({
|
|
913
|
+
type: import_v43.z.literal("tool_removal"),
|
|
914
|
+
toolName: import_v43.z.string()
|
|
915
|
+
})
|
|
916
|
+
])
|
|
917
|
+
).optional()
|
|
918
|
+
});
|
|
890
919
|
var anthropicLanguageModelOptions = import_v43.z.object({
|
|
891
920
|
/**
|
|
892
921
|
* Whether to send reasoning to the model.
|
|
@@ -1026,30 +1055,35 @@ var anthropicLanguageModelOptions = import_v43.z.object({
|
|
|
1026
1055
|
*/
|
|
1027
1056
|
inferenceGeo: import_v43.z.enum(["us", "global"]).optional(),
|
|
1028
1057
|
/**
|
|
1029
|
-
* Server-side fallback
|
|
1058
|
+
* Server-side fallback configuration.
|
|
1030
1059
|
*
|
|
1031
1060
|
* When the primary model's safety classifiers block a turn, the API
|
|
1032
|
-
* automatically retries it on
|
|
1033
|
-
* `content-filter` finish reason means the
|
|
1061
|
+
* automatically retries it server-side on a fallback model. A
|
|
1062
|
+
* `content-filter` finish reason means the fallback(s) refused as well.
|
|
1034
1063
|
*
|
|
1035
|
-
*
|
|
1036
|
-
* model
|
|
1037
|
-
*
|
|
1038
|
-
*
|
|
1039
|
-
*
|
|
1040
|
-
*
|
|
1041
|
-
*
|
|
1042
|
-
*
|
|
1064
|
+
* - `'default'` (recommended): the API routes the retry to Anthropic's
|
|
1065
|
+
* recommended fallback model based on the refusal category. Requires the
|
|
1066
|
+
* `server-side-fallback-2026-07-01` beta, which is added automatically.
|
|
1067
|
+
* - Array form: an explicit fallback chain. Each entry is merged into the
|
|
1068
|
+
* request as a direct request to that entry's model, so it must be
|
|
1069
|
+
* formatted accordingly: `model` is required, and an entry may
|
|
1070
|
+
* additionally override `max_tokens`, `thinking`, `output_config`, and
|
|
1071
|
+
* `speed` for that attempt only (`speed` additionally requires the speed
|
|
1072
|
+
* beta). The value is passed through to the API as-is, and the
|
|
1073
|
+
* `server-side-fallback-2026-06-01` beta is added automatically.
|
|
1043
1074
|
*/
|
|
1044
|
-
fallbacks: import_v43.z.
|
|
1045
|
-
import_v43.z.
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1075
|
+
fallbacks: import_v43.z.union([
|
|
1076
|
+
import_v43.z.literal("default"),
|
|
1077
|
+
import_v43.z.array(
|
|
1078
|
+
import_v43.z.object({
|
|
1079
|
+
model: import_v43.z.string(),
|
|
1080
|
+
max_tokens: import_v43.z.number().int().optional(),
|
|
1081
|
+
thinking: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional(),
|
|
1082
|
+
output_config: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional(),
|
|
1083
|
+
speed: import_v43.z.enum(["fast", "standard"]).optional()
|
|
1084
|
+
})
|
|
1085
|
+
)
|
|
1086
|
+
]).optional(),
|
|
1053
1087
|
/**
|
|
1054
1088
|
* A set of beta features to enable.
|
|
1055
1089
|
* Allow a provider to receive the full `betas` set if it needs it.
|
|
@@ -2207,7 +2241,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2207
2241
|
cacheControlValidator,
|
|
2208
2242
|
toolNameMapping
|
|
2209
2243
|
}) {
|
|
2210
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
2244
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2211
2245
|
const betas = /* @__PURE__ */ new Set();
|
|
2212
2246
|
const blocks = groupIntoBlocks(prompt);
|
|
2213
2247
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -2239,19 +2273,52 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2239
2273
|
const type = block.type;
|
|
2240
2274
|
switch (type) {
|
|
2241
2275
|
case "system": {
|
|
2242
|
-
const content =
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2276
|
+
const content = [];
|
|
2277
|
+
let toolChangeCount = 0;
|
|
2278
|
+
for (const { content: text, providerOptions } of block.messages) {
|
|
2279
|
+
const systemMessageOptions = await (0, import_provider_utils14.parseProviderOptions)({
|
|
2280
|
+
provider: "anthropic",
|
|
2281
|
+
providerOptions,
|
|
2282
|
+
schema: anthropicSystemMessageProviderOptions
|
|
2283
|
+
});
|
|
2284
|
+
const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
|
|
2285
|
+
if (text !== "" || toolChanges.length === 0) {
|
|
2286
|
+
content.push({
|
|
2287
|
+
type: "text",
|
|
2288
|
+
text,
|
|
2289
|
+
cache_control: validator.getCacheControl(providerOptions, {
|
|
2290
|
+
type: "system message",
|
|
2291
|
+
canCache: true
|
|
2292
|
+
})
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
for (const toolChange of toolChanges) {
|
|
2296
|
+
toolChangeCount++;
|
|
2297
|
+
content.push({
|
|
2298
|
+
type: toolChange.type,
|
|
2299
|
+
tool: {
|
|
2300
|
+
type: "tool_reference",
|
|
2301
|
+
name: toolNameMapping.toProviderToolName(toolChange.toolName)
|
|
2302
|
+
}
|
|
2303
|
+
});
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
if (i === 0 || system == null && toolChangeCount === 0) {
|
|
2307
|
+
if (toolChangeCount > 0) {
|
|
2308
|
+
warnings.push({
|
|
2309
|
+
type: "other",
|
|
2310
|
+
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."
|
|
2311
|
+
});
|
|
2312
|
+
}
|
|
2313
|
+
system = content.filter(
|
|
2314
|
+
(part) => part.type === "text"
|
|
2315
|
+
);
|
|
2252
2316
|
} else {
|
|
2253
2317
|
messages.push({ role: "system", content });
|
|
2254
2318
|
betas.add("mid-conversation-system-2026-04-07");
|
|
2319
|
+
if (toolChangeCount > 0) {
|
|
2320
|
+
betas.add("mid-conversation-tool-changes-2026-07-01");
|
|
2321
|
+
}
|
|
2255
2322
|
}
|
|
2256
2323
|
break;
|
|
2257
2324
|
}
|
|
@@ -2264,10 +2331,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2264
2331
|
for (let j = 0; j < content.length; j++) {
|
|
2265
2332
|
const part = content[j];
|
|
2266
2333
|
const isLastPart = j === content.length - 1;
|
|
2267
|
-
const cacheControl = (
|
|
2334
|
+
const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
|
|
2268
2335
|
type: "user message part",
|
|
2269
2336
|
canCache: true
|
|
2270
|
-
})) != null ?
|
|
2337
|
+
})) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
2271
2338
|
type: "user message",
|
|
2272
2339
|
canCache: true
|
|
2273
2340
|
}) : void 0;
|
|
@@ -2312,7 +2379,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2312
2379
|
media_type: "application/pdf",
|
|
2313
2380
|
data: (0, import_provider_utils14.convertToBase64)(part.data)
|
|
2314
2381
|
},
|
|
2315
|
-
title: (
|
|
2382
|
+
title: (_c = metadata.title) != null ? _c : part.filename,
|
|
2316
2383
|
...metadata.context && { context: metadata.context },
|
|
2317
2384
|
...enableCitations && {
|
|
2318
2385
|
citations: { enabled: true }
|
|
@@ -2336,7 +2403,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2336
2403
|
media_type: "text/plain",
|
|
2337
2404
|
data: convertToString(part.data)
|
|
2338
2405
|
},
|
|
2339
|
-
title: (
|
|
2406
|
+
title: (_d = metadata.title) != null ? _d : part.filename,
|
|
2340
2407
|
...metadata.context && { context: metadata.context },
|
|
2341
2408
|
...enableCitations && {
|
|
2342
2409
|
citations: { enabled: true }
|
|
@@ -2361,17 +2428,17 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2361
2428
|
continue;
|
|
2362
2429
|
}
|
|
2363
2430
|
const output = part.output;
|
|
2364
|
-
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (
|
|
2431
|
+
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_e = output.value.find(
|
|
2365
2432
|
(contentPart) => contentPart.providerOptions != null
|
|
2366
|
-
)) == null ? void 0 :
|
|
2433
|
+
)) == null ? void 0 : _e.providerOptions : void 0;
|
|
2367
2434
|
const isLastPart = i2 === content.length - 1;
|
|
2368
|
-
const cacheControl = (
|
|
2435
|
+
const cacheControl = (_g = (_f = validator.getCacheControl(part.providerOptions, {
|
|
2369
2436
|
type: "tool result part",
|
|
2370
2437
|
canCache: true
|
|
2371
|
-
})) != null ?
|
|
2438
|
+
})) != null ? _f : validator.getCacheControl(outputProviderOptions, {
|
|
2372
2439
|
type: "tool result output",
|
|
2373
2440
|
canCache: true
|
|
2374
|
-
})) != null ?
|
|
2441
|
+
})) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
2375
2442
|
type: "tool result message",
|
|
2376
2443
|
canCache: true
|
|
2377
2444
|
}) : void 0;
|
|
@@ -2461,7 +2528,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2461
2528
|
contentValue = output.value;
|
|
2462
2529
|
break;
|
|
2463
2530
|
case "execution-denied":
|
|
2464
|
-
contentValue = (
|
|
2531
|
+
contentValue = (_h = output.reason) != null ? _h : "Tool call execution denied.";
|
|
2465
2532
|
break;
|
|
2466
2533
|
case "json":
|
|
2467
2534
|
case "error-json":
|
|
@@ -2498,16 +2565,16 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2498
2565
|
for (let k = 0; k < content.length; k++) {
|
|
2499
2566
|
const part = content[k];
|
|
2500
2567
|
const isLastContentPart = k === content.length - 1;
|
|
2501
|
-
const cacheControl = (
|
|
2568
|
+
const cacheControl = (_i = validator.getCacheControl(part.providerOptions, {
|
|
2502
2569
|
type: "assistant message part",
|
|
2503
2570
|
canCache: true
|
|
2504
|
-
})) != null ?
|
|
2571
|
+
})) != null ? _i : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
2505
2572
|
type: "assistant message",
|
|
2506
2573
|
canCache: true
|
|
2507
2574
|
}) : void 0;
|
|
2508
2575
|
switch (part.type) {
|
|
2509
2576
|
case "text": {
|
|
2510
|
-
const textMetadata = (
|
|
2577
|
+
const textMetadata = (_j = part.providerOptions) == null ? void 0 : _j.anthropic;
|
|
2511
2578
|
if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
|
|
2512
2579
|
anthropicContent.push({
|
|
2513
2580
|
type: "compaction",
|
|
@@ -2583,10 +2650,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2583
2650
|
const providerToolName = toolNameMapping.toProviderToolName(
|
|
2584
2651
|
part.toolName
|
|
2585
2652
|
);
|
|
2586
|
-
const isMcpToolUse = ((
|
|
2653
|
+
const isMcpToolUse = ((_l = (_k = part.providerOptions) == null ? void 0 : _k.anthropic) == null ? void 0 : _l.type) === "mcp-tool-use";
|
|
2587
2654
|
if (isMcpToolUse) {
|
|
2588
2655
|
mcpToolUseIds.add(part.toolCallId);
|
|
2589
|
-
const serverName = (
|
|
2656
|
+
const serverName = (_n = (_m = part.providerOptions) == null ? void 0 : _m.anthropic) == null ? void 0 : _n.serverName;
|
|
2590
2657
|
if (serverName == null || typeof serverName !== "string") {
|
|
2591
2658
|
warnings.push({
|
|
2592
2659
|
type: "other",
|
|
@@ -2662,7 +2729,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2662
2729
|
}
|
|
2663
2730
|
break;
|
|
2664
2731
|
}
|
|
2665
|
-
const callerOptions = (
|
|
2732
|
+
const callerOptions = (_o = part.providerOptions) == null ? void 0 : _o.anthropic;
|
|
2666
2733
|
const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
|
|
2667
2734
|
type: callerOptions.caller.type,
|
|
2668
2735
|
tool_id: callerOptions.caller.toolId
|
|
@@ -2715,7 +2782,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2715
2782
|
tool_use_id: part.toolCallId,
|
|
2716
2783
|
content: {
|
|
2717
2784
|
type: "code_execution_tool_result_error",
|
|
2718
|
-
error_code: (
|
|
2785
|
+
error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
|
|
2719
2786
|
},
|
|
2720
2787
|
cache_control: cacheControl
|
|
2721
2788
|
});
|
|
@@ -2726,7 +2793,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2726
2793
|
cache_control: cacheControl,
|
|
2727
2794
|
content: {
|
|
2728
2795
|
type: "bash_code_execution_tool_result_error",
|
|
2729
|
-
error_code: (
|
|
2796
|
+
error_code: (_q = errorInfo.errorCode) != null ? _q : "unknown"
|
|
2730
2797
|
}
|
|
2731
2798
|
});
|
|
2732
2799
|
}
|
|
@@ -2759,7 +2826,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2759
2826
|
stdout: codeExecutionOutput.stdout,
|
|
2760
2827
|
stderr: codeExecutionOutput.stderr,
|
|
2761
2828
|
return_code: codeExecutionOutput.return_code,
|
|
2762
|
-
content: (
|
|
2829
|
+
content: (_r = codeExecutionOutput.content) != null ? _r : []
|
|
2763
2830
|
},
|
|
2764
2831
|
cache_control: cacheControl
|
|
2765
2832
|
});
|
|
@@ -2777,7 +2844,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2777
2844
|
encrypted_stdout: codeExecutionOutput.encrypted_stdout,
|
|
2778
2845
|
stderr: codeExecutionOutput.stderr,
|
|
2779
2846
|
return_code: codeExecutionOutput.return_code,
|
|
2780
|
-
content: (
|
|
2847
|
+
content: (_s = codeExecutionOutput.content) != null ? _s : []
|
|
2781
2848
|
},
|
|
2782
2849
|
cache_control: cacheControl
|
|
2783
2850
|
});
|
|
@@ -2796,7 +2863,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2796
2863
|
stdout: codeExecutionOutput.stdout,
|
|
2797
2864
|
stderr: codeExecutionOutput.stderr,
|
|
2798
2865
|
return_code: codeExecutionOutput.return_code,
|
|
2799
|
-
content: (
|
|
2866
|
+
content: (_t = codeExecutionOutput.content) != null ? _t : []
|
|
2800
2867
|
},
|
|
2801
2868
|
cache_control: cacheControl
|
|
2802
2869
|
});
|
|
@@ -2826,7 +2893,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2826
2893
|
tool_use_id: part.toolCallId,
|
|
2827
2894
|
content: {
|
|
2828
2895
|
type: "web_fetch_tool_result_error",
|
|
2829
|
-
error_code: (
|
|
2896
|
+
error_code: (_u = (await extractErrorValue(output.value)).errorCode) != null ? _u : "unavailable"
|
|
2830
2897
|
},
|
|
2831
2898
|
cache_control: cacheControl
|
|
2832
2899
|
});
|
|
@@ -2873,7 +2940,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2873
2940
|
tool_use_id: part.toolCallId,
|
|
2874
2941
|
content: {
|
|
2875
2942
|
type: "web_search_tool_result_error",
|
|
2876
|
-
error_code: (
|
|
2943
|
+
error_code: (_v = (await extractErrorValue(output.value)).errorCode) != null ? _v : "unavailable"
|
|
2877
2944
|
},
|
|
2878
2945
|
cache_control: cacheControl
|
|
2879
2946
|
});
|
|
@@ -3331,7 +3398,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3331
3398
|
providerOptions,
|
|
3332
3399
|
stream
|
|
3333
3400
|
}) {
|
|
3334
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3401
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3335
3402
|
const warnings = [];
|
|
3336
3403
|
if (frequencyPenalty != null) {
|
|
3337
3404
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -3387,6 +3454,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3387
3454
|
maxOutputTokens: maxOutputTokensForModel,
|
|
3388
3455
|
supportsStructuredOutput: modelSupportsStructuredOutput,
|
|
3389
3456
|
rejectsSamplingParameters,
|
|
3457
|
+
rejectsThinkingDisabledAboveHighEffort,
|
|
3390
3458
|
isKnownModel
|
|
3391
3459
|
} = getModelCapabilities(this.modelId);
|
|
3392
3460
|
if (!isKnownModel && maxOutputTokens == null) {
|
|
@@ -3422,7 +3490,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3422
3490
|
topP = void 0;
|
|
3423
3491
|
}
|
|
3424
3492
|
}
|
|
3425
|
-
const isAnthropicModel = isKnownModel || this.modelId.
|
|
3493
|
+
const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
|
|
3426
3494
|
const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
|
|
3427
3495
|
const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
|
|
3428
3496
|
const structureOutputMode = (_c = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _c : "auto";
|
|
@@ -3473,11 +3541,19 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3473
3541
|
cacheControlValidator,
|
|
3474
3542
|
toolNameMapping
|
|
3475
3543
|
});
|
|
3476
|
-
|
|
3544
|
+
if (rejectsThinkingDisabledAboveHighEffort && ((_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
|
|
3545
|
+
warnings.push({
|
|
3546
|
+
type: "unsupported",
|
|
3547
|
+
feature: "providerOptions.anthropic.effort",
|
|
3548
|
+
details: `effort '${anthropicOptions.effort}' is not supported by ${this.modelId} when thinking is disabled. The effort has been lowered to 'high'.`
|
|
3549
|
+
});
|
|
3550
|
+
anthropicOptions.effort = "high";
|
|
3551
|
+
}
|
|
3552
|
+
const thinkingType = (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.type;
|
|
3477
3553
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
3478
3554
|
const sendThinking = isThinking || thinkingType === "disabled";
|
|
3479
|
-
let thinkingBudget = thinkingType === "enabled" ? (
|
|
3480
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
3555
|
+
let thinkingBudget = thinkingType === "enabled" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.budgetTokens : void 0;
|
|
3556
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.display : void 0;
|
|
3481
3557
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
3482
3558
|
const baseArgs = {
|
|
3483
3559
|
// model id:
|
|
@@ -3524,13 +3600,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3524
3600
|
...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
|
|
3525
3601
|
inference_geo: anthropicOptions.inferenceGeo
|
|
3526
3602
|
},
|
|
3527
|
-
...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && {
|
|
3603
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) != null && (anthropicOptions.fallbacks === "default" || anthropicOptions.fallbacks.length > 0) && {
|
|
3528
3604
|
fallbacks: anthropicOptions.fallbacks
|
|
3529
3605
|
},
|
|
3530
3606
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
3531
3607
|
cache_control: anthropicOptions.cacheControl
|
|
3532
3608
|
},
|
|
3533
|
-
...((
|
|
3609
|
+
...((_i = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _i.userId) != null && {
|
|
3534
3610
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
3535
3611
|
},
|
|
3536
3612
|
// mcp servers:
|
|
@@ -3703,10 +3779,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3703
3779
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
3704
3780
|
betas.add("fast-mode-2026-02-01");
|
|
3705
3781
|
}
|
|
3706
|
-
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks)
|
|
3782
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) === "default") {
|
|
3783
|
+
betas.add("server-side-fallback-2026-07-01");
|
|
3784
|
+
} else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
3707
3785
|
betas.add("server-side-fallback-2026-06-01");
|
|
3708
3786
|
}
|
|
3709
|
-
const defaultEagerInputStreaming = stream && ((
|
|
3787
|
+
const defaultEagerInputStreaming = stream && ((_j = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _j : true);
|
|
3710
3788
|
const {
|
|
3711
3789
|
tools: anthropicTools2,
|
|
3712
3790
|
toolChoice: anthropicToolChoice,
|
|
@@ -3745,7 +3823,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3745
3823
|
...betas,
|
|
3746
3824
|
...toolsBetas,
|
|
3747
3825
|
...userSuppliedBetas,
|
|
3748
|
-
...(
|
|
3826
|
+
...(_k = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _k : []
|
|
3749
3827
|
]),
|
|
3750
3828
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
3751
3829
|
toolNameMapping,
|
|
@@ -5191,11 +5269,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5191
5269
|
}
|
|
5192
5270
|
};
|
|
5193
5271
|
function getModelCapabilities(modelId) {
|
|
5194
|
-
if (modelId.includes("claude-opus-
|
|
5272
|
+
if (modelId.includes("claude-opus-5")) {
|
|
5195
5273
|
return {
|
|
5196
5274
|
maxOutputTokens: 128e3,
|
|
5197
5275
|
supportsStructuredOutput: true,
|
|
5198
5276
|
rejectsSamplingParameters: true,
|
|
5277
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5278
|
+
isKnownModel: true
|
|
5279
|
+
};
|
|
5280
|
+
} else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
|
|
5281
|
+
return {
|
|
5282
|
+
maxOutputTokens: 128e3,
|
|
5283
|
+
supportsStructuredOutput: true,
|
|
5284
|
+
rejectsSamplingParameters: true,
|
|
5285
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5199
5286
|
isKnownModel: true
|
|
5200
5287
|
};
|
|
5201
5288
|
} else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
|
|
@@ -5203,6 +5290,7 @@ function getModelCapabilities(modelId) {
|
|
|
5203
5290
|
maxOutputTokens: 128e3,
|
|
5204
5291
|
supportsStructuredOutput: true,
|
|
5205
5292
|
rejectsSamplingParameters: false,
|
|
5293
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5206
5294
|
isKnownModel: true
|
|
5207
5295
|
};
|
|
5208
5296
|
} else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
|
|
@@ -5210,6 +5298,7 @@ function getModelCapabilities(modelId) {
|
|
|
5210
5298
|
maxOutputTokens: 64e3,
|
|
5211
5299
|
supportsStructuredOutput: true,
|
|
5212
5300
|
rejectsSamplingParameters: false,
|
|
5301
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5213
5302
|
isKnownModel: true
|
|
5214
5303
|
};
|
|
5215
5304
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
@@ -5217,6 +5306,7 @@ function getModelCapabilities(modelId) {
|
|
|
5217
5306
|
maxOutputTokens: 32e3,
|
|
5218
5307
|
supportsStructuredOutput: true,
|
|
5219
5308
|
rejectsSamplingParameters: false,
|
|
5309
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5220
5310
|
isKnownModel: true
|
|
5221
5311
|
};
|
|
5222
5312
|
} else if (modelId.includes("claude-sonnet-4-")) {
|
|
@@ -5224,6 +5314,7 @@ function getModelCapabilities(modelId) {
|
|
|
5224
5314
|
maxOutputTokens: 64e3,
|
|
5225
5315
|
supportsStructuredOutput: false,
|
|
5226
5316
|
rejectsSamplingParameters: false,
|
|
5317
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5227
5318
|
isKnownModel: true
|
|
5228
5319
|
};
|
|
5229
5320
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
@@ -5231,6 +5322,7 @@ function getModelCapabilities(modelId) {
|
|
|
5231
5322
|
maxOutputTokens: 32e3,
|
|
5232
5323
|
supportsStructuredOutput: false,
|
|
5233
5324
|
rejectsSamplingParameters: false,
|
|
5325
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5234
5326
|
isKnownModel: true
|
|
5235
5327
|
};
|
|
5236
5328
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
@@ -5238,13 +5330,31 @@ function getModelCapabilities(modelId) {
|
|
|
5238
5330
|
maxOutputTokens: 4096,
|
|
5239
5331
|
supportsStructuredOutput: false,
|
|
5240
5332
|
rejectsSamplingParameters: false,
|
|
5333
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5241
5334
|
isKnownModel: true
|
|
5242
5335
|
};
|
|
5336
|
+
} else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
|
|
5337
|
+
return {
|
|
5338
|
+
maxOutputTokens: 4096,
|
|
5339
|
+
supportsStructuredOutput: false,
|
|
5340
|
+
rejectsSamplingParameters: false,
|
|
5341
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5342
|
+
isKnownModel: false
|
|
5343
|
+
};
|
|
5344
|
+
} else if (modelId.includes("claude-")) {
|
|
5345
|
+
return {
|
|
5346
|
+
maxOutputTokens: 128e3,
|
|
5347
|
+
supportsStructuredOutput: true,
|
|
5348
|
+
rejectsSamplingParameters: true,
|
|
5349
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5350
|
+
isKnownModel: false
|
|
5351
|
+
};
|
|
5243
5352
|
} else {
|
|
5244
5353
|
return {
|
|
5245
5354
|
maxOutputTokens: 4096,
|
|
5246
5355
|
supportsStructuredOutput: false,
|
|
5247
5356
|
rejectsSamplingParameters: false,
|
|
5357
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5248
5358
|
isKnownModel: false
|
|
5249
5359
|
};
|
|
5250
5360
|
}
|
|
@@ -5830,6 +5940,7 @@ var anthropicTools = {
|
|
|
5830
5940
|
0 && (module.exports = {
|
|
5831
5941
|
AnthropicMessagesLanguageModel,
|
|
5832
5942
|
anthropicTools,
|
|
5943
|
+
getModelCapabilities,
|
|
5833
5944
|
prepareTools,
|
|
5834
5945
|
sanitizeJsonSchema
|
|
5835
5946
|
});
|