@ai-sdk/anthropic 4.0.62 → 4.0.65
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 +22 -0
- package/README.md +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +301 -283
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +6 -0
- package/dist/internal/index.js +253 -228
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +146 -42
- package/package.json +3 -3
- package/src/anthropic-api.ts +3 -0
- package/src/anthropic-batch.ts +6 -1
- package/src/anthropic-language-model-options.ts +17 -3
- package/src/anthropic-language-model.ts +44 -0
- package/src/convert-to-anthropic-prompt.ts +28 -8
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/anthropic-provider.ts
|
|
2
2
|
import {
|
|
3
|
-
InvalidArgumentError as
|
|
3
|
+
InvalidArgumentError as InvalidArgumentError3,
|
|
4
4
|
NoSuchModelError
|
|
5
5
|
} from "@ai-sdk/provider";
|
|
6
6
|
import {
|
|
@@ -76,7 +76,6 @@ var AnthropicFiles = class {
|
|
|
76
76
|
abortSignal,
|
|
77
77
|
headers
|
|
78
78
|
}) {
|
|
79
|
-
var _a, _b;
|
|
80
79
|
const fileBytes = convertInlineFileDataToUint8Array(data);
|
|
81
80
|
const blob = new Blob([fileBytes], { type: mediaType });
|
|
82
81
|
const formData = new FormData();
|
|
@@ -103,8 +102,8 @@ var AnthropicFiles = class {
|
|
|
103
102
|
return {
|
|
104
103
|
warnings: [],
|
|
105
104
|
providerReference: { anthropic: response.id },
|
|
106
|
-
mediaType:
|
|
107
|
-
filename:
|
|
105
|
+
mediaType: response.mime_type ?? mediaType,
|
|
106
|
+
filename: response.filename ?? filename,
|
|
108
107
|
providerMetadata: {
|
|
109
108
|
anthropic: {
|
|
110
109
|
filename: response.filename,
|
|
@@ -121,6 +120,7 @@ var AnthropicFiles = class {
|
|
|
121
120
|
// src/anthropic-language-model.ts
|
|
122
121
|
import {
|
|
123
122
|
APICallError,
|
|
123
|
+
InvalidArgumentError,
|
|
124
124
|
InvalidResponseDataError
|
|
125
125
|
} from "@ai-sdk/provider";
|
|
126
126
|
import {
|
|
@@ -272,7 +272,8 @@ var anthropicResponseSchema = lazySchema3(
|
|
|
272
272
|
}),
|
|
273
273
|
z3.object({
|
|
274
274
|
type: z3.literal("compaction"),
|
|
275
|
-
content: z3.string().nullish()
|
|
275
|
+
content: z3.string().nullish(),
|
|
276
|
+
signature: z3.string().nullish()
|
|
276
277
|
}),
|
|
277
278
|
z3.object({
|
|
278
279
|
type: z3.literal("tool_use"),
|
|
@@ -627,7 +628,8 @@ var anthropicChunkSchema = lazySchema3(
|
|
|
627
628
|
}),
|
|
628
629
|
z3.object({
|
|
629
630
|
type: z3.literal("compaction"),
|
|
630
|
-
content: z3.string().nullish()
|
|
631
|
+
content: z3.string().nullish(),
|
|
632
|
+
signature: z3.string().nullish()
|
|
631
633
|
}),
|
|
632
634
|
z3.object({
|
|
633
635
|
type: z3.literal("server_tool_use"),
|
|
@@ -1011,9 +1013,10 @@ var anthropicSystemMessageProviderOptions = z4.object({
|
|
|
1011
1013
|
*/
|
|
1012
1014
|
clearAt: z4.literal("next_user_message").optional(),
|
|
1013
1015
|
/**
|
|
1014
|
-
* Sets the model effort
|
|
1015
|
-
* system message
|
|
1016
|
-
* beta is
|
|
1016
|
+
* Sets the model effort from the next user turn until a later message
|
|
1017
|
+
* changes it. An effort-only system message with empty content can appear
|
|
1018
|
+
* first. The required `mid-conversation-output-config-2026-07-01` beta is
|
|
1019
|
+
* added automatically.
|
|
1017
1020
|
*/
|
|
1018
1021
|
effort: z4.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
1019
1022
|
/**
|
|
@@ -1266,6 +1269,16 @@ var anthropicLanguageModelOptions = z4.object({
|
|
|
1266
1269
|
classifierContext: z4.record(z4.string(), z4.unknown()).optional()
|
|
1267
1270
|
})
|
|
1268
1271
|
).optional(),
|
|
1272
|
+
/**
|
|
1273
|
+
* Requests an on-demand summary of the supplied conversation.
|
|
1274
|
+
*
|
|
1275
|
+
* The required `compact-2026-09-04` beta is added automatically.
|
|
1276
|
+
* Cannot be combined with `contextManagement`.
|
|
1277
|
+
*/
|
|
1278
|
+
compaction: z4.object({
|
|
1279
|
+
type: z4.literal("summarize"),
|
|
1280
|
+
instructions: z4.string().optional()
|
|
1281
|
+
}).optional(),
|
|
1269
1282
|
contextManagement: z4.object({
|
|
1270
1283
|
edits: z4.array(
|
|
1271
1284
|
z4.discriminatedUnion("type", [
|
|
@@ -1324,9 +1337,8 @@ import {
|
|
|
1324
1337
|
// src/get-cache-control.ts
|
|
1325
1338
|
var MAX_CACHE_BREAKPOINTS = 4;
|
|
1326
1339
|
function getCacheControl(providerMetadata) {
|
|
1327
|
-
|
|
1328
|
-
const
|
|
1329
|
-
const cacheControlValue = (_a = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a : anthropic2 == null ? void 0 : anthropic2.cache_control;
|
|
1340
|
+
const anthropic2 = providerMetadata?.anthropic;
|
|
1341
|
+
const cacheControlValue = anthropic2?.cacheControl ?? anthropic2?.cache_control;
|
|
1330
1342
|
return cacheControlValue;
|
|
1331
1343
|
}
|
|
1332
1344
|
var CacheControlValidator = class {
|
|
@@ -1873,8 +1885,7 @@ async function prepareTools({
|
|
|
1873
1885
|
defaultEagerInputStreaming = false,
|
|
1874
1886
|
rejectsForcedToolUse = false
|
|
1875
1887
|
}) {
|
|
1876
|
-
|
|
1877
|
-
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
1888
|
+
tools = tools?.length ? tools : void 0;
|
|
1878
1889
|
const toolWarnings = [];
|
|
1879
1890
|
const betas = /* @__PURE__ */ new Set();
|
|
1880
1891
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -1889,10 +1900,10 @@ async function prepareTools({
|
|
|
1889
1900
|
type: "tool definition",
|
|
1890
1901
|
canCache: true
|
|
1891
1902
|
});
|
|
1892
|
-
const anthropicOptions =
|
|
1893
|
-
const eagerInputStreaming =
|
|
1894
|
-
const deferLoading = anthropicOptions
|
|
1895
|
-
const allowedCallers = anthropicOptions
|
|
1903
|
+
const anthropicOptions = tool.providerOptions?.anthropic;
|
|
1904
|
+
const eagerInputStreaming = anthropicOptions?.eagerInputStreaming ?? defaultEagerInputStreaming;
|
|
1905
|
+
const deferLoading = anthropicOptions?.deferLoading;
|
|
1906
|
+
const allowedCallers = anthropicOptions?.allowedCallers;
|
|
1896
1907
|
if (!supportsStrictTools && tool.strict != null) {
|
|
1897
1908
|
toolWarnings.push({
|
|
1898
1909
|
type: "unsupported",
|
|
@@ -1983,10 +1994,10 @@ async function prepareTools({
|
|
|
1983
1994
|
Object.entries(args.configs).map(([member, config]) => [
|
|
1984
1995
|
member,
|
|
1985
1996
|
{
|
|
1986
|
-
...
|
|
1997
|
+
...config?.enabled != null && {
|
|
1987
1998
|
enabled: config.enabled
|
|
1988
1999
|
},
|
|
1989
|
-
...
|
|
2000
|
+
...config?.deferLoading != null && {
|
|
1990
2001
|
defer_loading: config.deferLoading
|
|
1991
2002
|
}
|
|
1992
2003
|
}
|
|
@@ -2324,13 +2335,12 @@ function convertAnthropicUsage({
|
|
|
2324
2335
|
usage,
|
|
2325
2336
|
rawUsage
|
|
2326
2337
|
}) {
|
|
2327
|
-
|
|
2328
|
-
const
|
|
2329
|
-
const
|
|
2330
|
-
const reasoningTokens = (_d = (_c = usage.output_tokens_details) == null ? void 0 : _c.thinking_tokens) != null ? _d : void 0;
|
|
2338
|
+
const cacheCreationTokens = usage.cache_creation_input_tokens ?? 0;
|
|
2339
|
+
const cacheReadTokens = usage.cache_read_input_tokens ?? 0;
|
|
2340
|
+
const reasoningTokens = usage.output_tokens_details?.thinking_tokens ?? void 0;
|
|
2331
2341
|
let inputTokens;
|
|
2332
2342
|
let outputTokens;
|
|
2333
|
-
const servedByFallback =
|
|
2343
|
+
const servedByFallback = usage.iterations?.some(
|
|
2334
2344
|
(iter) => iter.type === "fallback_message"
|
|
2335
2345
|
);
|
|
2336
2346
|
if (usage.iterations && usage.iterations.length > 0 && !servedByFallback) {
|
|
@@ -2367,7 +2377,7 @@ function convertAnthropicUsage({
|
|
|
2367
2377
|
text: reasoningTokens == null ? void 0 : outputTokens - reasoningTokens,
|
|
2368
2378
|
reasoning: reasoningTokens
|
|
2369
2379
|
},
|
|
2370
|
-
raw: rawUsage
|
|
2380
|
+
raw: rawUsage ?? usage
|
|
2371
2381
|
};
|
|
2372
2382
|
}
|
|
2373
2383
|
|
|
@@ -2540,15 +2550,14 @@ var codeExecution_20250825 = (args = {}) => {
|
|
|
2540
2550
|
return experimental_toolCaller(factory10(args), {
|
|
2541
2551
|
type: "provider",
|
|
2542
2552
|
prepareProviderOptions: (providerOptions) => {
|
|
2543
|
-
|
|
2544
|
-
const anthropicOptions = providerOptions == null ? void 0 : providerOptions.anthropic;
|
|
2553
|
+
const anthropicOptions = providerOptions?.anthropic;
|
|
2545
2554
|
return {
|
|
2546
2555
|
...providerOptions,
|
|
2547
2556
|
anthropic: {
|
|
2548
2557
|
...anthropicOptions,
|
|
2549
2558
|
allowedCallers: [
|
|
2550
2559
|
.../* @__PURE__ */ new Set([
|
|
2551
|
-
...
|
|
2560
|
+
...anthropicOptions?.allowedCallers ?? [],
|
|
2552
2561
|
"code_execution_20250825"
|
|
2553
2562
|
])
|
|
2554
2563
|
]
|
|
@@ -2680,15 +2689,14 @@ var codeExecution_20260120 = (args = {}) => {
|
|
|
2680
2689
|
return experimental_toolCaller2(factory11(args), {
|
|
2681
2690
|
type: "provider",
|
|
2682
2691
|
prepareProviderOptions: (providerOptions) => {
|
|
2683
|
-
|
|
2684
|
-
const anthropicOptions = providerOptions == null ? void 0 : providerOptions.anthropic;
|
|
2692
|
+
const anthropicOptions = providerOptions?.anthropic;
|
|
2685
2693
|
return {
|
|
2686
2694
|
...providerOptions,
|
|
2687
2695
|
anthropic: {
|
|
2688
2696
|
...anthropicOptions,
|
|
2689
2697
|
allowedCallers: [
|
|
2690
2698
|
.../* @__PURE__ */ new Set([
|
|
2691
|
-
...
|
|
2699
|
+
...anthropicOptions?.allowedCallers ?? [],
|
|
2692
2700
|
"code_execution_20260120"
|
|
2693
2701
|
])
|
|
2694
2702
|
]
|
|
@@ -2760,8 +2768,8 @@ function extractErrorValue(value) {
|
|
|
2760
2768
|
} else if (typeof value === "object" && value !== null) {
|
|
2761
2769
|
return value;
|
|
2762
2770
|
}
|
|
2763
|
-
} catch
|
|
2764
|
-
const extractedErrorCode = value
|
|
2771
|
+
} catch {
|
|
2772
|
+
const extractedErrorCode = value?.errorCode;
|
|
2765
2773
|
return {
|
|
2766
2774
|
errorCode: typeof extractedErrorCode === "string" ? extractedErrorCode : "unavailable"
|
|
2767
2775
|
};
|
|
@@ -2776,29 +2784,26 @@ async function convertToAnthropicPrompt({
|
|
|
2776
2784
|
toolNameMapping,
|
|
2777
2785
|
toolsetNames = {}
|
|
2778
2786
|
}) {
|
|
2779
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2780
2787
|
const betas = /* @__PURE__ */ new Set();
|
|
2781
2788
|
const blocks = groupIntoBlocks(prompt);
|
|
2782
2789
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
2783
2790
|
let system = void 0;
|
|
2784
2791
|
const messages = [];
|
|
2785
2792
|
async function shouldEnableCitations(providerMetadata) {
|
|
2786
|
-
var _a2, _b2;
|
|
2787
2793
|
const anthropicOptions = await parseProviderOptions({
|
|
2788
2794
|
provider: "anthropic",
|
|
2789
2795
|
providerOptions: providerMetadata,
|
|
2790
2796
|
schema: anthropicFilePartProviderOptions
|
|
2791
2797
|
});
|
|
2792
|
-
return
|
|
2798
|
+
return anthropicOptions?.citations?.enabled ?? false;
|
|
2793
2799
|
}
|
|
2794
2800
|
async function shouldUseContainerUpload(providerMetadata) {
|
|
2795
|
-
var _a2;
|
|
2796
2801
|
const anthropicOptions = await parseProviderOptions({
|
|
2797
2802
|
provider: "anthropic",
|
|
2798
2803
|
providerOptions: providerMetadata,
|
|
2799
2804
|
schema: anthropicFilePartProviderOptions
|
|
2800
2805
|
});
|
|
2801
|
-
return
|
|
2806
|
+
return anthropicOptions?.containerUpload ?? false;
|
|
2802
2807
|
}
|
|
2803
2808
|
async function getDocumentMetadata(providerMetadata) {
|
|
2804
2809
|
const anthropicOptions = await parseProviderOptions({
|
|
@@ -2807,8 +2812,8 @@ async function convertToAnthropicPrompt({
|
|
|
2807
2812
|
schema: anthropicFilePartProviderOptions
|
|
2808
2813
|
});
|
|
2809
2814
|
return {
|
|
2810
|
-
title: anthropicOptions
|
|
2811
|
-
context: anthropicOptions
|
|
2815
|
+
title: anthropicOptions?.title,
|
|
2816
|
+
context: anthropicOptions?.context
|
|
2812
2817
|
};
|
|
2813
2818
|
}
|
|
2814
2819
|
for (let i = 0; i < blocks.length; i++) {
|
|
@@ -2824,9 +2829,9 @@ async function convertToAnthropicPrompt({
|
|
|
2824
2829
|
providerOptions,
|
|
2825
2830
|
schema: anthropicSystemMessageProviderOptions
|
|
2826
2831
|
});
|
|
2827
|
-
const toolChanges =
|
|
2832
|
+
const toolChanges = systemMessageOptions?.toolChanges ?? [];
|
|
2828
2833
|
const content = [];
|
|
2829
|
-
if (text !== "" || toolChanges.length === 0 &&
|
|
2834
|
+
if (text !== "" || toolChanges.length === 0 && systemMessageOptions?.clearAt == null && systemMessageOptions?.effort == null) {
|
|
2830
2835
|
content.push({
|
|
2831
2836
|
type: "text",
|
|
2832
2837
|
text,
|
|
@@ -2847,8 +2852,8 @@ async function convertToAnthropicPrompt({
|
|
|
2847
2852
|
}
|
|
2848
2853
|
convertedMessages.push({
|
|
2849
2854
|
content,
|
|
2850
|
-
clearAt: systemMessageOptions
|
|
2851
|
-
effort: systemMessageOptions
|
|
2855
|
+
clearAt: systemMessageOptions?.clearAt,
|
|
2856
|
+
effort: systemMessageOptions?.effort,
|
|
2852
2857
|
toolChangeCount: toolChanges.length
|
|
2853
2858
|
});
|
|
2854
2859
|
}
|
|
@@ -2867,10 +2872,17 @@ async function convertToAnthropicPrompt({
|
|
|
2867
2872
|
});
|
|
2868
2873
|
}
|
|
2869
2874
|
for (const message of convertedMessages) {
|
|
2870
|
-
if (message.clearAt
|
|
2875
|
+
if (message.content.length === 0 && message.clearAt == null && message.effort != null) {
|
|
2876
|
+
messages.push({
|
|
2877
|
+
role: "system",
|
|
2878
|
+
content: [],
|
|
2879
|
+
output_config: { effort: message.effort }
|
|
2880
|
+
});
|
|
2881
|
+
betas.add("mid-conversation-output-config-2026-07-01");
|
|
2882
|
+
} else if (message.clearAt != null || message.effort != null) {
|
|
2871
2883
|
warnings.push({
|
|
2872
2884
|
type: "other",
|
|
2873
|
-
message: "clearAt and effort on
|
|
2885
|
+
message: "clearAt and effort on this initial system message are not supported by Anthropic. Use a separate effort-only system message with empty content to set effort. These options have been ignored."
|
|
2874
2886
|
});
|
|
2875
2887
|
}
|
|
2876
2888
|
}
|
|
@@ -2912,13 +2924,13 @@ async function convertToAnthropicPrompt({
|
|
|
2912
2924
|
for (let j = 0; j < content.length; j++) {
|
|
2913
2925
|
const part = content[j];
|
|
2914
2926
|
const isLastPart = j === content.length - 1;
|
|
2915
|
-
const cacheControl =
|
|
2927
|
+
const cacheControl = validator.getCacheControl(part.providerOptions, {
|
|
2916
2928
|
type: "user message part",
|
|
2917
2929
|
canCache: true
|
|
2918
|
-
})
|
|
2930
|
+
}) ?? (isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
2919
2931
|
type: "user message",
|
|
2920
2932
|
canCache: true
|
|
2921
|
-
}) : void 0;
|
|
2933
|
+
}) : void 0);
|
|
2922
2934
|
switch (part.type) {
|
|
2923
2935
|
case "text": {
|
|
2924
2936
|
anthropicContent.push({
|
|
@@ -2970,7 +2982,7 @@ async function convertToAnthropicPrompt({
|
|
|
2970
2982
|
media_type: "text/plain",
|
|
2971
2983
|
data: part.data.text
|
|
2972
2984
|
},
|
|
2973
|
-
title:
|
|
2985
|
+
title: metadata.title ?? part.filename,
|
|
2974
2986
|
...metadata.context && {
|
|
2975
2987
|
context: metadata.context
|
|
2976
2988
|
},
|
|
@@ -3015,7 +3027,7 @@ async function convertToAnthropicPrompt({
|
|
|
3015
3027
|
media_type: "application/pdf",
|
|
3016
3028
|
data: convertToBase64(part.data.data)
|
|
3017
3029
|
},
|
|
3018
|
-
title:
|
|
3030
|
+
title: metadata.title ?? part.filename,
|
|
3019
3031
|
...metadata.context && {
|
|
3020
3032
|
context: metadata.context
|
|
3021
3033
|
},
|
|
@@ -3043,7 +3055,7 @@ async function convertToAnthropicPrompt({
|
|
|
3043
3055
|
part.data.data
|
|
3044
3056
|
)
|
|
3045
3057
|
},
|
|
3046
|
-
title:
|
|
3058
|
+
title: metadata.title ?? part.filename,
|
|
3047
3059
|
...metadata.context && {
|
|
3048
3060
|
context: metadata.context
|
|
3049
3061
|
},
|
|
@@ -3073,25 +3085,24 @@ async function convertToAnthropicPrompt({
|
|
|
3073
3085
|
continue;
|
|
3074
3086
|
}
|
|
3075
3087
|
const output = part.output;
|
|
3076
|
-
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ?
|
|
3088
|
+
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? output.value.find(
|
|
3077
3089
|
(contentPart) => contentPart.providerOptions != null
|
|
3078
|
-
)
|
|
3090
|
+
)?.providerOptions : void 0;
|
|
3079
3091
|
const isLastPart = i2 === content.length - 1;
|
|
3080
|
-
const cacheControl =
|
|
3092
|
+
const cacheControl = validator.getCacheControl(part.providerOptions, {
|
|
3081
3093
|
type: "tool result part",
|
|
3082
3094
|
canCache: true
|
|
3083
|
-
})
|
|
3095
|
+
}) ?? validator.getCacheControl(outputProviderOptions, {
|
|
3084
3096
|
type: "tool result output",
|
|
3085
3097
|
canCache: true
|
|
3086
|
-
})
|
|
3098
|
+
}) ?? (isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
3087
3099
|
type: "tool result message",
|
|
3088
3100
|
canCache: true
|
|
3089
|
-
}) : void 0;
|
|
3101
|
+
}) : void 0);
|
|
3090
3102
|
let contentValue;
|
|
3091
3103
|
switch (output.type) {
|
|
3092
3104
|
case "content":
|
|
3093
3105
|
contentValue = output.value.map((contentPart) => {
|
|
3094
|
-
var _a2;
|
|
3095
3106
|
switch (contentPart.type) {
|
|
3096
3107
|
case "text":
|
|
3097
3108
|
return {
|
|
@@ -3161,8 +3172,8 @@ async function convertToAnthropicPrompt({
|
|
|
3161
3172
|
return void 0;
|
|
3162
3173
|
}
|
|
3163
3174
|
case "custom": {
|
|
3164
|
-
const anthropicOptions =
|
|
3165
|
-
if (
|
|
3175
|
+
const anthropicOptions = contentPart.providerOptions?.anthropic;
|
|
3176
|
+
if (anthropicOptions?.type === "tool-reference") {
|
|
3166
3177
|
return {
|
|
3167
3178
|
type: "tool_reference",
|
|
3168
3179
|
tool_name: anthropicOptions.toolName
|
|
@@ -3189,7 +3200,7 @@ async function convertToAnthropicPrompt({
|
|
|
3189
3200
|
contentValue = output.value;
|
|
3190
3201
|
break;
|
|
3191
3202
|
case "execution-denied":
|
|
3192
|
-
contentValue =
|
|
3203
|
+
contentValue = output.reason ?? "Tool call execution denied.";
|
|
3193
3204
|
break;
|
|
3194
3205
|
case "json":
|
|
3195
3206
|
case "error-json":
|
|
@@ -3232,23 +3243,29 @@ async function convertToAnthropicPrompt({
|
|
|
3232
3243
|
for (let k = 0; k < content.length; k++) {
|
|
3233
3244
|
const part = content[k];
|
|
3234
3245
|
const isLastContentPart = k === content.length - 1;
|
|
3235
|
-
const cacheControl =
|
|
3246
|
+
const cacheControl = validator.getCacheControl(part.providerOptions, {
|
|
3236
3247
|
type: "assistant message part",
|
|
3237
3248
|
canCache: true
|
|
3238
|
-
})
|
|
3249
|
+
}) ?? (isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
3239
3250
|
type: "assistant message",
|
|
3240
3251
|
canCache: true
|
|
3241
|
-
}) : void 0;
|
|
3252
|
+
}) : void 0);
|
|
3242
3253
|
switch (part.type) {
|
|
3243
3254
|
case "text": {
|
|
3244
|
-
const textMetadata =
|
|
3245
|
-
if (
|
|
3255
|
+
const textMetadata = part.providerOptions?.anthropic;
|
|
3256
|
+
if (textMetadata?.type === "compaction") {
|
|
3246
3257
|
if (part.text === "") {
|
|
3247
3258
|
break;
|
|
3248
3259
|
}
|
|
3260
|
+
if (typeof textMetadata.signature === "string") {
|
|
3261
|
+
betas.add("compact-2026-09-04");
|
|
3262
|
+
}
|
|
3249
3263
|
anthropicContent.push({
|
|
3250
3264
|
type: "compaction",
|
|
3251
3265
|
content: part.text,
|
|
3266
|
+
...typeof textMetadata.signature === "string" && {
|
|
3267
|
+
signature: textMetadata.signature
|
|
3268
|
+
},
|
|
3252
3269
|
cache_control: cacheControl
|
|
3253
3270
|
});
|
|
3254
3271
|
} else {
|
|
@@ -3260,7 +3277,7 @@ async function convertToAnthropicPrompt({
|
|
|
3260
3277
|
// in pre-filled assistant responses
|
|
3261
3278
|
isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
|
|
3262
3279
|
),
|
|
3263
|
-
...
|
|
3280
|
+
...textMetadata?.citations != null && {
|
|
3264
3281
|
citations: textMetadata.citations
|
|
3265
3282
|
},
|
|
3266
3283
|
cache_control: cacheControl
|
|
@@ -3321,10 +3338,10 @@ async function convertToAnthropicPrompt({
|
|
|
3321
3338
|
const providerToolName = toolNameMapping.toProviderToolName(
|
|
3322
3339
|
part.toolName
|
|
3323
3340
|
);
|
|
3324
|
-
const isMcpToolUse =
|
|
3341
|
+
const isMcpToolUse = part.providerOptions?.anthropic?.type === "mcp-tool-use";
|
|
3325
3342
|
if (isMcpToolUse) {
|
|
3326
3343
|
mcpToolUseIds.add(part.toolCallId);
|
|
3327
|
-
const serverName =
|
|
3344
|
+
const serverName = part.providerOptions?.anthropic?.serverName;
|
|
3328
3345
|
if (serverName == null || typeof serverName !== "string") {
|
|
3329
3346
|
warnings.push({
|
|
3330
3347
|
type: "other",
|
|
@@ -3474,7 +3491,7 @@ async function convertToAnthropicPrompt({
|
|
|
3474
3491
|
} else if (typeof output.value === "object" && output.value !== null) {
|
|
3475
3492
|
errorInfo = output.value;
|
|
3476
3493
|
}
|
|
3477
|
-
} catch
|
|
3494
|
+
} catch {
|
|
3478
3495
|
}
|
|
3479
3496
|
if (errorInfo.type === "code_execution_tool_result_error") {
|
|
3480
3497
|
anthropicContent.push({
|
|
@@ -3482,7 +3499,7 @@ async function convertToAnthropicPrompt({
|
|
|
3482
3499
|
tool_use_id: part.toolCallId,
|
|
3483
3500
|
content: {
|
|
3484
3501
|
type: "code_execution_tool_result_error",
|
|
3485
|
-
error_code:
|
|
3502
|
+
error_code: errorInfo.errorCode ?? "unknown"
|
|
3486
3503
|
},
|
|
3487
3504
|
cache_control: cacheControl
|
|
3488
3505
|
});
|
|
@@ -3493,7 +3510,7 @@ async function convertToAnthropicPrompt({
|
|
|
3493
3510
|
cache_control: cacheControl,
|
|
3494
3511
|
content: {
|
|
3495
3512
|
type: "bash_code_execution_tool_result_error",
|
|
3496
|
-
error_code:
|
|
3513
|
+
error_code: errorInfo.errorCode ?? "unknown"
|
|
3497
3514
|
}
|
|
3498
3515
|
});
|
|
3499
3516
|
}
|
|
@@ -3526,7 +3543,7 @@ async function convertToAnthropicPrompt({
|
|
|
3526
3543
|
stdout: codeExecutionOutput.stdout,
|
|
3527
3544
|
stderr: codeExecutionOutput.stderr,
|
|
3528
3545
|
return_code: codeExecutionOutput.return_code,
|
|
3529
|
-
content:
|
|
3546
|
+
content: codeExecutionOutput.content ?? []
|
|
3530
3547
|
},
|
|
3531
3548
|
cache_control: cacheControl
|
|
3532
3549
|
});
|
|
@@ -3544,7 +3561,7 @@ async function convertToAnthropicPrompt({
|
|
|
3544
3561
|
encrypted_stdout: codeExecutionOutput.encrypted_stdout,
|
|
3545
3562
|
stderr: codeExecutionOutput.stderr,
|
|
3546
3563
|
return_code: codeExecutionOutput.return_code,
|
|
3547
|
-
content:
|
|
3564
|
+
content: codeExecutionOutput.content ?? []
|
|
3548
3565
|
},
|
|
3549
3566
|
cache_control: cacheControl
|
|
3550
3567
|
});
|
|
@@ -3563,7 +3580,7 @@ async function convertToAnthropicPrompt({
|
|
|
3563
3580
|
stdout: codeExecutionOutput.stdout,
|
|
3564
3581
|
stderr: codeExecutionOutput.stderr,
|
|
3565
3582
|
return_code: codeExecutionOutput.return_code,
|
|
3566
|
-
content:
|
|
3583
|
+
content: codeExecutionOutput.content ?? []
|
|
3567
3584
|
},
|
|
3568
3585
|
cache_control: cacheControl
|
|
3569
3586
|
});
|
|
@@ -3601,7 +3618,7 @@ async function convertToAnthropicPrompt({
|
|
|
3601
3618
|
tool_use_id: part.toolCallId,
|
|
3602
3619
|
content: {
|
|
3603
3620
|
type: "web_fetch_tool_result_error",
|
|
3604
|
-
error_code:
|
|
3621
|
+
error_code: extractErrorValue(output.value).errorCode ?? "unavailable"
|
|
3605
3622
|
},
|
|
3606
3623
|
...caller && { caller },
|
|
3607
3624
|
cache_control: cacheControl
|
|
@@ -3650,7 +3667,7 @@ async function convertToAnthropicPrompt({
|
|
|
3650
3667
|
tool_use_id: part.toolCallId,
|
|
3651
3668
|
content: {
|
|
3652
3669
|
type: "web_search_tool_result_error",
|
|
3653
|
-
error_code:
|
|
3670
|
+
error_code: extractErrorValue(output.value).errorCode ?? "unavailable"
|
|
3654
3671
|
},
|
|
3655
3672
|
...caller && { caller },
|
|
3656
3673
|
cache_control: cacheControl
|
|
@@ -3798,7 +3815,7 @@ function groupIntoBlocks(prompt) {
|
|
|
3798
3815
|
const { role } = message;
|
|
3799
3816
|
switch (role) {
|
|
3800
3817
|
case "system": {
|
|
3801
|
-
if (
|
|
3818
|
+
if (currentBlock?.type !== "system") {
|
|
3802
3819
|
currentBlock = { type: "system", messages: [] };
|
|
3803
3820
|
blocks.push(currentBlock);
|
|
3804
3821
|
}
|
|
@@ -3806,7 +3823,7 @@ function groupIntoBlocks(prompt) {
|
|
|
3806
3823
|
break;
|
|
3807
3824
|
}
|
|
3808
3825
|
case "assistant": {
|
|
3809
|
-
if (
|
|
3826
|
+
if (currentBlock?.type !== "assistant") {
|
|
3810
3827
|
currentBlock = { type: "assistant", messages: [] };
|
|
3811
3828
|
blocks.push(currentBlock);
|
|
3812
3829
|
}
|
|
@@ -3814,7 +3831,7 @@ function groupIntoBlocks(prompt) {
|
|
|
3814
3831
|
break;
|
|
3815
3832
|
}
|
|
3816
3833
|
case "user": {
|
|
3817
|
-
if (
|
|
3834
|
+
if (currentBlock?.type !== "user") {
|
|
3818
3835
|
currentBlock = { type: "user", messages: [] };
|
|
3819
3836
|
blocks.push(currentBlock);
|
|
3820
3837
|
}
|
|
@@ -3822,7 +3839,7 @@ function groupIntoBlocks(prompt) {
|
|
|
3822
3839
|
break;
|
|
3823
3840
|
}
|
|
3824
3841
|
case "tool": {
|
|
3825
|
-
if (
|
|
3842
|
+
if (currentBlock?.type !== "user") {
|
|
3826
3843
|
currentBlock = { type: "user", messages: [] };
|
|
3827
3844
|
blocks.push(currentBlock);
|
|
3828
3845
|
}
|
|
@@ -3863,24 +3880,22 @@ function getAnthropicToolsetName({
|
|
|
3863
3880
|
providerOptions,
|
|
3864
3881
|
toolsetNames
|
|
3865
3882
|
}) {
|
|
3866
|
-
var _a;
|
|
3867
3883
|
const fromTools = toolsetNames[toolName];
|
|
3868
3884
|
if (fromTools != null) {
|
|
3869
3885
|
return fromTools;
|
|
3870
3886
|
}
|
|
3871
|
-
const fromMetadata =
|
|
3887
|
+
const fromMetadata = providerOptions?.anthropic?.toolsetName;
|
|
3872
3888
|
return typeof fromMetadata === "string" ? fromMetadata : void 0;
|
|
3873
3889
|
}
|
|
3874
3890
|
function getAnthropicCaller(providerOptions) {
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
if (((caller == null ? void 0 : caller.type) === "code_execution_20250825" || (caller == null ? void 0 : caller.type) === "code_execution_20260120") && caller.toolId) {
|
|
3891
|
+
const caller = providerOptions?.anthropic?.caller;
|
|
3892
|
+
if ((caller?.type === "code_execution_20250825" || caller?.type === "code_execution_20260120") && caller.toolId) {
|
|
3878
3893
|
return {
|
|
3879
3894
|
type: caller.type,
|
|
3880
3895
|
tool_id: caller.toolId
|
|
3881
3896
|
};
|
|
3882
3897
|
}
|
|
3883
|
-
return
|
|
3898
|
+
return caller?.type === "direct" ? { type: "direct" } : void 0;
|
|
3884
3899
|
}
|
|
3885
3900
|
function toAnthropicToolInput(input) {
|
|
3886
3901
|
return typeof input === "object" && input !== null && !Array.isArray(input) ? input : { rawInvalidInput: input };
|
|
@@ -4056,14 +4071,13 @@ function formatConstraintValue(value) {
|
|
|
4056
4071
|
|
|
4057
4072
|
// src/anthropic-language-model.ts
|
|
4058
4073
|
function createAnthropicStreamError(error) {
|
|
4059
|
-
var _a, _b, _c;
|
|
4060
4074
|
const inferredMetadata = getAnthropicStreamErrorMetadata(error.type);
|
|
4061
4075
|
return createProviderStreamError({
|
|
4062
4076
|
message: error.message,
|
|
4063
4077
|
type: error.type,
|
|
4064
|
-
code:
|
|
4065
|
-
statusCode:
|
|
4066
|
-
isRetryable:
|
|
4078
|
+
code: error.code ?? void 0,
|
|
4079
|
+
statusCode: error.statusCode ?? inferredMetadata.statusCode,
|
|
4080
|
+
isRetryable: error.isRetryable ?? inferredMetadata.isRetryable,
|
|
4067
4081
|
data: "data" in error ? error.data : error
|
|
4068
4082
|
});
|
|
4069
4083
|
}
|
|
@@ -4091,14 +4105,13 @@ function getAnthropicStreamErrorMetadata(type) {
|
|
|
4091
4105
|
}
|
|
4092
4106
|
}
|
|
4093
4107
|
function createCitationSource(citation, citationDocuments, generateId4) {
|
|
4094
|
-
var _a, _b;
|
|
4095
4108
|
if (citation.type === "web_search_result_location") {
|
|
4096
4109
|
return {
|
|
4097
4110
|
type: "source",
|
|
4098
4111
|
sourceType: "url",
|
|
4099
4112
|
id: generateId4(),
|
|
4100
4113
|
url: citation.url,
|
|
4101
|
-
title:
|
|
4114
|
+
title: citation.title ?? void 0,
|
|
4102
4115
|
providerMetadata: {
|
|
4103
4116
|
anthropic: {
|
|
4104
4117
|
citedText: citation.cited_text,
|
|
@@ -4119,7 +4132,7 @@ function createCitationSource(citation, citationDocuments, generateId4) {
|
|
|
4119
4132
|
sourceType: "document",
|
|
4120
4133
|
id: generateId4(),
|
|
4121
4134
|
mediaType: documentInfo.mediaType,
|
|
4122
|
-
title:
|
|
4135
|
+
title: citation.document_title ?? documentInfo.title,
|
|
4123
4136
|
filename: documentInfo.filename,
|
|
4124
4137
|
providerMetadata: {
|
|
4125
4138
|
anthropic: citation.type === "page_location" ? {
|
|
@@ -4146,7 +4159,7 @@ function getAnthropicCallerMetadata(caller) {
|
|
|
4146
4159
|
}
|
|
4147
4160
|
function getAnthropicToolsetNames(tools) {
|
|
4148
4161
|
const toolsetNames = {};
|
|
4149
|
-
for (const tool of tools
|
|
4162
|
+
for (const tool of tools ?? []) {
|
|
4150
4163
|
if (tool.type === "provider" && tool.id === "anthropic.computer_toolset_20260801") {
|
|
4151
4164
|
toolsetNames[tool.name] = "computer";
|
|
4152
4165
|
}
|
|
@@ -4169,10 +4182,9 @@ function getProviderOptionsName(provider) {
|
|
|
4169
4182
|
var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
4170
4183
|
constructor(modelId, config) {
|
|
4171
4184
|
this.specificationVersion = "v4";
|
|
4172
|
-
var _a;
|
|
4173
4185
|
this.modelId = modelId;
|
|
4174
4186
|
this.config = config;
|
|
4175
|
-
this.generateId =
|
|
4187
|
+
this.generateId = config.generateId ?? generateId;
|
|
4176
4188
|
}
|
|
4177
4189
|
static [WORKFLOW_SERIALIZE](model) {
|
|
4178
4190
|
return serializeModelOptions({
|
|
@@ -4190,8 +4202,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4190
4202
|
return this.config.provider;
|
|
4191
4203
|
}
|
|
4192
4204
|
get supportedUrls() {
|
|
4193
|
-
|
|
4194
|
-
return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
|
4205
|
+
return this.config.supportedUrls?.() ?? {};
|
|
4195
4206
|
}
|
|
4196
4207
|
static async prepareRequest({
|
|
4197
4208
|
modelId,
|
|
@@ -4215,7 +4226,6 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4215
4226
|
stream
|
|
4216
4227
|
}
|
|
4217
4228
|
}) {
|
|
4218
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
4219
4229
|
const warnings = [];
|
|
4220
4230
|
if (frequencyPenalty != null) {
|
|
4221
4231
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -4241,7 +4251,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4241
4251
|
});
|
|
4242
4252
|
temperature = 0;
|
|
4243
4253
|
}
|
|
4244
|
-
if (
|
|
4254
|
+
if (responseFormat?.type === "json") {
|
|
4245
4255
|
if (responseFormat.schema == null) {
|
|
4246
4256
|
warnings.push({
|
|
4247
4257
|
type: "unsupported",
|
|
@@ -4264,8 +4274,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4264
4274
|
const usedCustomProviderKey = customProviderOptions != null;
|
|
4265
4275
|
const anthropicOptions = Object.assign(
|
|
4266
4276
|
{},
|
|
4267
|
-
canonicalOptions
|
|
4268
|
-
customProviderOptions
|
|
4277
|
+
canonicalOptions ?? {},
|
|
4278
|
+
customProviderOptions ?? {}
|
|
4269
4279
|
);
|
|
4270
4280
|
const {
|
|
4271
4281
|
maxOutputTokens: maxOutputTokensForModel,
|
|
@@ -4312,11 +4322,11 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4312
4322
|
}
|
|
4313
4323
|
}
|
|
4314
4324
|
const isAnthropicModel = isKnownModel || modelId.includes("claude-");
|
|
4315
|
-
const supportsStructuredOutput = (
|
|
4316
|
-
const supportsStrictTools = (
|
|
4317
|
-
const structureOutputMode =
|
|
4325
|
+
const supportsStructuredOutput = (config.supportsNativeStructuredOutput ?? true) && modelSupportsStructuredOutput;
|
|
4326
|
+
const supportsStrictTools = (config.supportsStrictTools ?? true) && modelSupportsStructuredOutput;
|
|
4327
|
+
const structureOutputMode = anthropicOptions?.structuredOutputMode ?? "auto";
|
|
4318
4328
|
let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
4319
|
-
if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput &&
|
|
4329
|
+
if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && responseFormat?.type === "json" && responseFormat.schema != null) {
|
|
4320
4330
|
warnings.push({
|
|
4321
4331
|
type: "unsupported",
|
|
4322
4332
|
feature: "providerOptions.anthropic.structuredOutputMode",
|
|
@@ -4324,20 +4334,27 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4324
4334
|
});
|
|
4325
4335
|
useStructuredOutput = true;
|
|
4326
4336
|
}
|
|
4327
|
-
const jsonResponseTool =
|
|
4337
|
+
const jsonResponseTool = responseFormat?.type === "json" && responseFormat.schema != null && !useStructuredOutput ? {
|
|
4328
4338
|
type: "function",
|
|
4329
4339
|
name: "json",
|
|
4330
4340
|
description: "Respond with a JSON object.",
|
|
4331
4341
|
inputSchema: responseFormat.schema
|
|
4332
4342
|
} : void 0;
|
|
4333
|
-
if (jsonResponseTool != null &&
|
|
4343
|
+
if (jsonResponseTool != null && anthropicOptions?.disableParallelToolUse === false) {
|
|
4334
4344
|
warnings.push({
|
|
4335
4345
|
type: "unsupported",
|
|
4336
4346
|
feature: "providerOptions.anthropic.disableParallelToolUse",
|
|
4337
4347
|
details: "`disableParallelToolUse: false` is ignored when using the JSON response tool. Parallel tool use is disabled to ensure a single coherent JSON tool call."
|
|
4338
4348
|
});
|
|
4339
4349
|
}
|
|
4340
|
-
const contextManagement = anthropicOptions
|
|
4350
|
+
const contextManagement = anthropicOptions?.contextManagement;
|
|
4351
|
+
const compaction = anthropicOptions?.compaction;
|
|
4352
|
+
if (contextManagement != null && compaction != null) {
|
|
4353
|
+
throw new InvalidArgumentError({
|
|
4354
|
+
argument: "providerOptions",
|
|
4355
|
+
message: "Anthropic provider options `compaction` and `contextManagement` cannot be used together."
|
|
4356
|
+
});
|
|
4357
|
+
}
|
|
4341
4358
|
const cacheControlValidator = new CacheControlValidator();
|
|
4342
4359
|
const toolNameMapping = createToolNameMapping({
|
|
4343
4360
|
tools,
|
|
@@ -4370,13 +4387,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4370
4387
|
const toolsetNames = getAnthropicToolsetNames(tools);
|
|
4371
4388
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicPrompt({
|
|
4372
4389
|
prompt,
|
|
4373
|
-
sendReasoning:
|
|
4390
|
+
sendReasoning: anthropicOptions?.sendReasoning ?? true,
|
|
4374
4391
|
warnings,
|
|
4375
4392
|
cacheControlValidator,
|
|
4376
4393
|
toolNameMapping,
|
|
4377
4394
|
toolsetNames
|
|
4378
4395
|
});
|
|
4379
|
-
if (isCustomReasoning(reasoning) &&
|
|
4396
|
+
if (isCustomReasoning(reasoning) && anthropicOptions?.effort == null) {
|
|
4380
4397
|
const reasoningConfig = resolveAnthropicReasoningConfig({
|
|
4381
4398
|
reasoning,
|
|
4382
4399
|
modelId,
|
|
@@ -4390,12 +4407,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4390
4407
|
if (anthropicOptions.thinking == null) {
|
|
4391
4408
|
anthropicOptions.thinking = reasoningConfig.thinking;
|
|
4392
4409
|
}
|
|
4393
|
-
if (reasoningConfig.effort != null &&
|
|
4410
|
+
if (reasoningConfig.effort != null && anthropicOptions.thinking?.type !== "disabled") {
|
|
4394
4411
|
anthropicOptions.effort = reasoningConfig.effort;
|
|
4395
4412
|
}
|
|
4396
4413
|
}
|
|
4397
4414
|
}
|
|
4398
|
-
if (rejectsThinkingDisabled &&
|
|
4415
|
+
if (rejectsThinkingDisabled && anthropicOptions?.thinking != null) {
|
|
4399
4416
|
const thinking = anthropicOptions.thinking;
|
|
4400
4417
|
if (thinking.type === "disabled") {
|
|
4401
4418
|
warnings.push({
|
|
@@ -4413,7 +4430,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4413
4430
|
anthropicOptions.thinking = { type: "adaptive" };
|
|
4414
4431
|
}
|
|
4415
4432
|
}
|
|
4416
|
-
if (rejectsThinkingDisabledAboveHighEffort &&
|
|
4433
|
+
if (rejectsThinkingDisabledAboveHighEffort && anthropicOptions?.thinking?.type === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
|
|
4417
4434
|
warnings.push({
|
|
4418
4435
|
type: "unsupported",
|
|
4419
4436
|
feature: "providerOptions.anthropic.effort",
|
|
@@ -4421,13 +4438,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4421
4438
|
});
|
|
4422
4439
|
anthropicOptions.effort = "high";
|
|
4423
4440
|
}
|
|
4424
|
-
const thinkingType =
|
|
4441
|
+
const thinkingType = anthropicOptions?.thinking?.type;
|
|
4425
4442
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
4426
|
-
const thinkingBlockBinding =
|
|
4443
|
+
const thinkingBlockBinding = anthropicOptions?.thinking != null && "blockBinding" in anthropicOptions.thinking ? anthropicOptions.thinking.blockBinding : void 0;
|
|
4427
4444
|
const sendThinking = isThinking || thinkingType === "disabled" || thinkingBlockBinding != null;
|
|
4428
|
-
let thinkingBudget = thinkingType === "enabled" ?
|
|
4429
|
-
const thinkingDisplay = thinkingType === "adaptive" ?
|
|
4430
|
-
const maxTokens = maxOutputTokens
|
|
4445
|
+
let thinkingBudget = thinkingType === "enabled" ? anthropicOptions?.thinking?.budgetTokens : void 0;
|
|
4446
|
+
const thinkingDisplay = thinkingType === "adaptive" ? anthropicOptions?.thinking?.display : void 0;
|
|
4447
|
+
const maxTokens = maxOutputTokens ?? maxOutputTokensForModel;
|
|
4431
4448
|
const baseArgs = {
|
|
4432
4449
|
// model id:
|
|
4433
4450
|
model: modelId,
|
|
@@ -4450,12 +4467,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4450
4467
|
}
|
|
4451
4468
|
}
|
|
4452
4469
|
},
|
|
4453
|
-
...(
|
|
4470
|
+
...(anthropicOptions?.effort || anthropicOptions?.taskBudget || useStructuredOutput && responseFormat?.type === "json" && responseFormat.schema != null) && {
|
|
4454
4471
|
output_config: {
|
|
4455
|
-
...
|
|
4472
|
+
...anthropicOptions?.effort && {
|
|
4456
4473
|
effort: anthropicOptions.effort
|
|
4457
4474
|
},
|
|
4458
|
-
...
|
|
4475
|
+
...anthropicOptions?.taskBudget && {
|
|
4459
4476
|
task_budget: {
|
|
4460
4477
|
type: anthropicOptions.taskBudget.type,
|
|
4461
4478
|
total: anthropicOptions.taskBudget.total,
|
|
@@ -4464,7 +4481,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4464
4481
|
}
|
|
4465
4482
|
}
|
|
4466
4483
|
},
|
|
4467
|
-
...useStructuredOutput &&
|
|
4484
|
+
...useStructuredOutput && responseFormat?.type === "json" && responseFormat.schema != null && {
|
|
4468
4485
|
format: {
|
|
4469
4486
|
type: "json_schema",
|
|
4470
4487
|
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
@@ -4472,26 +4489,26 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4472
4489
|
}
|
|
4473
4490
|
}
|
|
4474
4491
|
},
|
|
4475
|
-
...
|
|
4492
|
+
...anthropicOptions?.speed && {
|
|
4476
4493
|
speed: anthropicOptions.speed
|
|
4477
4494
|
},
|
|
4478
|
-
...
|
|
4495
|
+
...anthropicOptions?.serviceTier && {
|
|
4479
4496
|
service_tier: anthropicOptions.serviceTier
|
|
4480
4497
|
},
|
|
4481
|
-
...
|
|
4498
|
+
...anthropicOptions?.inferenceGeo && {
|
|
4482
4499
|
inference_geo: anthropicOptions.inferenceGeo
|
|
4483
4500
|
},
|
|
4484
|
-
...
|
|
4501
|
+
...anthropicOptions?.fallbacks != null && (anthropicOptions.fallbacks === "default" || anthropicOptions.fallbacks.length > 0) && {
|
|
4485
4502
|
fallbacks: anthropicOptions.fallbacks
|
|
4486
4503
|
},
|
|
4487
|
-
...
|
|
4504
|
+
...anthropicOptions?.cacheControl && {
|
|
4488
4505
|
cache_control: anthropicOptions.cacheControl
|
|
4489
4506
|
},
|
|
4490
|
-
...
|
|
4507
|
+
...anthropicOptions?.metadata?.userId != null && {
|
|
4491
4508
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
4492
4509
|
},
|
|
4493
4510
|
// mcp servers:
|
|
4494
|
-
...
|
|
4511
|
+
...anthropicOptions?.mcpServers && anthropicOptions.mcpServers.length > 0 && {
|
|
4495
4512
|
mcp_servers: anthropicOptions.mcpServers.map((server) => ({
|
|
4496
4513
|
type: server.type,
|
|
4497
4514
|
name: server.name,
|
|
@@ -4504,7 +4521,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4504
4521
|
}))
|
|
4505
4522
|
},
|
|
4506
4523
|
// container: For programmatic tool calling (just an ID string) or agent skills (object with id and skills)
|
|
4507
|
-
...
|
|
4524
|
+
...anthropicOptions?.container && {
|
|
4508
4525
|
container: anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0 ? (
|
|
4509
4526
|
// Object format when skills are provided (agent skills feature)
|
|
4510
4527
|
{
|
|
@@ -4526,7 +4543,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4526
4543
|
// prompt:
|
|
4527
4544
|
system: messagesPrompt.system,
|
|
4528
4545
|
messages: messagesPrompt.messages,
|
|
4529
|
-
...
|
|
4546
|
+
...anthropicOptions?.safeguards && anthropicOptions.safeguards.length > 0 && {
|
|
4530
4547
|
safeguards: anthropicOptions.safeguards.map((safeguard) => ({
|
|
4531
4548
|
type: safeguard.type,
|
|
4532
4549
|
...safeguard.classifierContext !== void 0 && {
|
|
@@ -4534,6 +4551,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4534
4551
|
}
|
|
4535
4552
|
}))
|
|
4536
4553
|
},
|
|
4554
|
+
...compaction && {
|
|
4555
|
+
compaction: {
|
|
4556
|
+
type: compaction.type,
|
|
4557
|
+
...compaction.instructions !== void 0 && {
|
|
4558
|
+
instructions: compaction.instructions
|
|
4559
|
+
}
|
|
4560
|
+
}
|
|
4561
|
+
},
|
|
4537
4562
|
...contextManagement && {
|
|
4538
4563
|
context_management: {
|
|
4539
4564
|
edits: contextManagement.edits.map((edit) => {
|
|
@@ -4622,7 +4647,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4622
4647
|
details: "topP is not supported when thinking is enabled"
|
|
4623
4648
|
});
|
|
4624
4649
|
}
|
|
4625
|
-
baseArgs.max_tokens = maxTokens + (thinkingBudget
|
|
4650
|
+
baseArgs.max_tokens = maxTokens + (thinkingBudget ?? 0);
|
|
4626
4651
|
} else {
|
|
4627
4652
|
if (isAnthropicModel && topP != null && temperature != null) {
|
|
4628
4653
|
warnings.push({
|
|
@@ -4643,35 +4668,38 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4643
4668
|
}
|
|
4644
4669
|
baseArgs.max_tokens = maxOutputTokensForModel;
|
|
4645
4670
|
}
|
|
4646
|
-
if (
|
|
4671
|
+
if (anthropicOptions?.mcpServers && anthropicOptions.mcpServers.length > 0) {
|
|
4647
4672
|
betas.add("mcp-client-2025-04-04");
|
|
4648
4673
|
}
|
|
4649
|
-
if (
|
|
4674
|
+
if (anthropicOptions?.safeguards && anthropicOptions.safeguards.length > 0) {
|
|
4650
4675
|
betas.add("dangerous-tool-use-2026-09-03");
|
|
4651
4676
|
}
|
|
4677
|
+
if (compaction) {
|
|
4678
|
+
betas.add("compact-2026-09-04");
|
|
4679
|
+
}
|
|
4652
4680
|
if (contextManagement) {
|
|
4653
4681
|
betas.add("context-management-2025-06-27");
|
|
4654
4682
|
if (contextManagement.edits.some((e) => e.type === "compact_20260112")) {
|
|
4655
4683
|
betas.add("compact-2026-01-12");
|
|
4656
4684
|
}
|
|
4657
4685
|
}
|
|
4658
|
-
if (
|
|
4686
|
+
if (anthropicOptions?.container && anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0) {
|
|
4659
4687
|
betas.add("code-execution-2025-08-25");
|
|
4660
4688
|
betas.add("skills-2025-10-02");
|
|
4661
4689
|
betas.add("files-api-2025-04-14");
|
|
4662
|
-
if (!
|
|
4690
|
+
if (!tools?.some(
|
|
4663
4691
|
(tool) => tool.type === "provider" && (tool.id === "anthropic.code_execution_20250825" || tool.id === "anthropic.code_execution_20260120")
|
|
4664
|
-
))
|
|
4692
|
+
)) {
|
|
4665
4693
|
warnings.push({
|
|
4666
4694
|
type: "other",
|
|
4667
4695
|
message: "code execution tool is required when using skills"
|
|
4668
4696
|
});
|
|
4669
4697
|
}
|
|
4670
4698
|
}
|
|
4671
|
-
if (anthropicOptions
|
|
4699
|
+
if (anthropicOptions?.taskBudget) {
|
|
4672
4700
|
betas.add("task-budgets-2026-03-13");
|
|
4673
4701
|
}
|
|
4674
|
-
if (
|
|
4702
|
+
if (anthropicOptions?.speed === "fast") {
|
|
4675
4703
|
betas.add("fast-mode-2026-02-01");
|
|
4676
4704
|
}
|
|
4677
4705
|
if (thinkingDisplay === "updates") {
|
|
@@ -4680,12 +4708,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4680
4708
|
if (thinkingBlockBinding != null) {
|
|
4681
4709
|
betas.add("thinking-binding-controls-2026-08-01");
|
|
4682
4710
|
}
|
|
4683
|
-
if (
|
|
4711
|
+
if (anthropicOptions?.fallbacks === "default") {
|
|
4684
4712
|
betas.add("server-side-fallback-2026-07-01");
|
|
4685
|
-
} else if (
|
|
4713
|
+
} else if (anthropicOptions?.fallbacks && anthropicOptions.fallbacks.length > 0) {
|
|
4686
4714
|
betas.add("server-side-fallback-2026-06-01");
|
|
4687
4715
|
}
|
|
4688
|
-
const defaultEagerInputStreaming = stream && (
|
|
4716
|
+
const defaultEagerInputStreaming = stream && (anthropicOptions?.toolStreaming ?? true);
|
|
4689
4717
|
const {
|
|
4690
4718
|
tools: anthropicTools2,
|
|
4691
4719
|
toolChoice: anthropicToolChoice,
|
|
@@ -4693,7 +4721,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4693
4721
|
betas: toolsBetas
|
|
4694
4722
|
} = await prepareTools(
|
|
4695
4723
|
jsonResponseTool != null ? {
|
|
4696
|
-
tools: [...tools
|
|
4724
|
+
tools: [...tools ?? [], jsonResponseTool],
|
|
4697
4725
|
toolChoice: { type: "required" },
|
|
4698
4726
|
disableParallelToolUse: true,
|
|
4699
4727
|
cacheControlValidator,
|
|
@@ -4702,9 +4730,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4702
4730
|
defaultEagerInputStreaming,
|
|
4703
4731
|
rejectsForcedToolUse
|
|
4704
4732
|
} : {
|
|
4705
|
-
tools: tools
|
|
4733
|
+
tools: tools ?? [],
|
|
4706
4734
|
toolChoice,
|
|
4707
|
-
disableParallelToolUse: anthropicOptions
|
|
4735
|
+
disableParallelToolUse: anthropicOptions?.disableParallelToolUse,
|
|
4708
4736
|
cacheControlValidator,
|
|
4709
4737
|
supportsStructuredOutput,
|
|
4710
4738
|
supportsStrictTools,
|
|
@@ -4726,7 +4754,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4726
4754
|
...betas,
|
|
4727
4755
|
...toolsBetas,
|
|
4728
4756
|
...userSuppliedBetas,
|
|
4729
|
-
...
|
|
4757
|
+
...anthropicOptions?.anthropicBeta ?? []
|
|
4730
4758
|
]),
|
|
4731
4759
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
4732
4760
|
toolNameMapping,
|
|
@@ -4752,10 +4780,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4752
4780
|
);
|
|
4753
4781
|
}
|
|
4754
4782
|
async getBetasFromHeaders(requestHeaders) {
|
|
4755
|
-
var _a, _b;
|
|
4756
4783
|
const configHeaders = this.config.headers ? await resolve(this.config.headers) : void 0;
|
|
4757
|
-
const configBetaHeader =
|
|
4758
|
-
const requestBetaHeader =
|
|
4784
|
+
const configBetaHeader = configHeaders?.["anthropic-beta"] ?? "";
|
|
4785
|
+
const requestBetaHeader = requestHeaders?.["anthropic-beta"] ?? "";
|
|
4759
4786
|
return new Set(
|
|
4760
4787
|
[
|
|
4761
4788
|
...configBetaHeader.toLowerCase().split(","),
|
|
@@ -4764,38 +4791,33 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4764
4791
|
);
|
|
4765
4792
|
}
|
|
4766
4793
|
buildRequestUrl(isStreaming) {
|
|
4767
|
-
|
|
4768
|
-
return (_c = (_b = (_a = this.config).buildRequestUrl) == null ? void 0 : _b.call(_a, this.config.baseURL, isStreaming)) != null ? _c : `${this.config.baseURL}/messages`;
|
|
4794
|
+
return this.config.buildRequestUrl?.(this.config.baseURL, isStreaming) ?? `${this.config.baseURL}/messages`;
|
|
4769
4795
|
}
|
|
4770
4796
|
transformRequestBody(args, betas) {
|
|
4771
|
-
|
|
4772
|
-
return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args, betas)) != null ? _c : args;
|
|
4797
|
+
return this.config.transformRequestBody?.(args, betas) ?? args;
|
|
4773
4798
|
}
|
|
4774
4799
|
extractCitationDocuments(prompt) {
|
|
4775
4800
|
const isCitationPart = (part) => {
|
|
4776
|
-
var _a, _b;
|
|
4777
4801
|
if (part.type !== "file") {
|
|
4778
4802
|
return false;
|
|
4779
4803
|
}
|
|
4780
4804
|
if (part.mediaType !== "application/pdf" && part.mediaType !== "text/plain") {
|
|
4781
4805
|
return false;
|
|
4782
4806
|
}
|
|
4783
|
-
const anthropic2 =
|
|
4784
|
-
const citationsConfig = anthropic2
|
|
4785
|
-
return
|
|
4807
|
+
const anthropic2 = part.providerOptions?.anthropic;
|
|
4808
|
+
const citationsConfig = anthropic2?.citations;
|
|
4809
|
+
return citationsConfig?.enabled ?? false;
|
|
4786
4810
|
};
|
|
4787
4811
|
return prompt.filter((message) => message.role === "user").flatMap((message) => message.content).filter(isCitationPart).map((part) => {
|
|
4788
|
-
var _a;
|
|
4789
4812
|
const filePart = part;
|
|
4790
4813
|
return {
|
|
4791
|
-
title:
|
|
4814
|
+
title: filePart.filename ?? "Untitled Document",
|
|
4792
4815
|
filename: filePart.filename,
|
|
4793
4816
|
mediaType: filePart.mediaType
|
|
4794
4817
|
};
|
|
4795
4818
|
});
|
|
4796
4819
|
}
|
|
4797
4820
|
async doGenerate(options) {
|
|
4798
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
4799
4821
|
const {
|
|
4800
4822
|
args,
|
|
4801
4823
|
warnings,
|
|
@@ -4836,7 +4858,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4836
4858
|
switch (part.type) {
|
|
4837
4859
|
case "text": {
|
|
4838
4860
|
if (!usesJsonResponseTool) {
|
|
4839
|
-
const webSearchCitations =
|
|
4861
|
+
const webSearchCitations = part.citations?.filter(
|
|
4840
4862
|
(citation) => citation.type === "web_search_result_location"
|
|
4841
4863
|
);
|
|
4842
4864
|
content.push({
|
|
@@ -4906,7 +4928,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4906
4928
|
text: part.content,
|
|
4907
4929
|
providerMetadata: {
|
|
4908
4930
|
anthropic: {
|
|
4909
|
-
type: "compaction"
|
|
4931
|
+
type: "compaction",
|
|
4932
|
+
...part.signature != null && {
|
|
4933
|
+
signature: part.signature
|
|
4934
|
+
}
|
|
4910
4935
|
}
|
|
4911
4936
|
}
|
|
4912
4937
|
});
|
|
@@ -4934,7 +4959,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4934
4959
|
providerMetadata: {
|
|
4935
4960
|
anthropic: {
|
|
4936
4961
|
toolsetName: part.toolset_name,
|
|
4937
|
-
...
|
|
4962
|
+
...getAnthropicCallerMetadata(part.caller).providerMetadata?.anthropic
|
|
4938
4963
|
}
|
|
4939
4964
|
}
|
|
4940
4965
|
});
|
|
@@ -5035,7 +5060,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5035
5060
|
case "web_fetch_tool_result": {
|
|
5036
5061
|
if (part.content.type === "web_fetch_result") {
|
|
5037
5062
|
citationDocuments.push({
|
|
5038
|
-
title:
|
|
5063
|
+
title: part.content.content.title ?? part.content.url,
|
|
5039
5064
|
mediaType: part.content.content.source.media_type
|
|
5040
5065
|
});
|
|
5041
5066
|
content.push({
|
|
@@ -5080,16 +5105,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5080
5105
|
type: "tool-result",
|
|
5081
5106
|
toolCallId: part.tool_use_id,
|
|
5082
5107
|
toolName: toolNameMapping.toCustomToolName("web_search"),
|
|
5083
|
-
result: part.content.map((result) => {
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
type: result.type
|
|
5091
|
-
};
|
|
5092
|
-
}),
|
|
5108
|
+
result: part.content.map((result) => ({
|
|
5109
|
+
url: result.url,
|
|
5110
|
+
...result.title != null ? { title: result.title } : {},
|
|
5111
|
+
pageAge: result.page_age ?? null,
|
|
5112
|
+
encryptedContent: result.encrypted_content,
|
|
5113
|
+
type: result.type
|
|
5114
|
+
})),
|
|
5093
5115
|
...getAnthropicCallerMetadata(part.caller)
|
|
5094
5116
|
});
|
|
5095
5117
|
for (const result of part.content) {
|
|
@@ -5101,7 +5123,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5101
5123
|
...result.title != null ? { title: result.title } : {},
|
|
5102
5124
|
providerMetadata: {
|
|
5103
5125
|
anthropic: {
|
|
5104
|
-
pageAge:
|
|
5126
|
+
pageAge: result.page_age ?? null
|
|
5105
5127
|
}
|
|
5106
5128
|
}
|
|
5107
5129
|
});
|
|
@@ -5133,7 +5155,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5133
5155
|
stdout: part.content.stdout,
|
|
5134
5156
|
stderr: part.content.stderr,
|
|
5135
5157
|
return_code: part.content.return_code,
|
|
5136
|
-
content:
|
|
5158
|
+
content: part.content.content ?? []
|
|
5137
5159
|
}
|
|
5138
5160
|
});
|
|
5139
5161
|
} else if (part.content.type === "encrypted_code_execution_result") {
|
|
@@ -5146,7 +5168,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5146
5168
|
encrypted_stdout: part.content.encrypted_stdout,
|
|
5147
5169
|
stderr: part.content.stderr,
|
|
5148
5170
|
return_code: part.content.return_code,
|
|
5149
|
-
content:
|
|
5171
|
+
content: part.content.content ?? []
|
|
5150
5172
|
}
|
|
5151
5173
|
});
|
|
5152
5174
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -5274,23 +5296,22 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5274
5296
|
finishReason: response.stop_reason,
|
|
5275
5297
|
isJsonResponseFromTool
|
|
5276
5298
|
}),
|
|
5277
|
-
raw:
|
|
5299
|
+
raw: response.stop_reason ?? void 0
|
|
5278
5300
|
},
|
|
5279
5301
|
usage: convertAnthropicUsage({ usage: response.usage }),
|
|
5280
5302
|
request: { body: args },
|
|
5281
5303
|
response: {
|
|
5282
|
-
id:
|
|
5283
|
-
modelId:
|
|
5304
|
+
id: response.id ?? void 0,
|
|
5305
|
+
modelId: response.model ?? void 0,
|
|
5284
5306
|
headers: responseHeaders,
|
|
5285
5307
|
body: rawResponse
|
|
5286
5308
|
},
|
|
5287
5309
|
warnings,
|
|
5288
5310
|
providerMetadata: (() => {
|
|
5289
|
-
var _a2, _b2, _c2, _d2;
|
|
5290
5311
|
const stopDetails = mapAnthropicStopDetails(response.stop_details);
|
|
5291
5312
|
const anthropicMetadata = {
|
|
5292
5313
|
usage: response.usage,
|
|
5293
|
-
stopSequence:
|
|
5314
|
+
stopSequence: response.stop_sequence ?? null,
|
|
5294
5315
|
...stopDetails != null ? { stopDetails } : {},
|
|
5295
5316
|
...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
|
|
5296
5317
|
...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
|
|
@@ -5311,15 +5332,15 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5311
5332
|
container: response.container ? {
|
|
5312
5333
|
expiresAt: response.container.expires_at,
|
|
5313
5334
|
id: response.container.id,
|
|
5314
|
-
skills:
|
|
5335
|
+
skills: response.container.skills?.map((skill) => ({
|
|
5315
5336
|
type: skill.type,
|
|
5316
5337
|
skillId: skill.skill_id,
|
|
5317
5338
|
version: skill.version
|
|
5318
|
-
}))
|
|
5339
|
+
})) ?? null
|
|
5319
5340
|
} : null,
|
|
5320
|
-
contextManagement:
|
|
5341
|
+
contextManagement: mapAnthropicResponseContextManagement(
|
|
5321
5342
|
response.context_management
|
|
5322
|
-
)
|
|
5343
|
+
) ?? null
|
|
5323
5344
|
};
|
|
5324
5345
|
const providerMetadata = {
|
|
5325
5346
|
anthropic: anthropicMetadata
|
|
@@ -5333,7 +5354,6 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5333
5354
|
}
|
|
5334
5355
|
async doStream(options) {
|
|
5335
5356
|
"use step";
|
|
5336
|
-
var _a, _b, _c, _d;
|
|
5337
5357
|
const {
|
|
5338
5358
|
args: body,
|
|
5339
5359
|
warnings,
|
|
@@ -5394,7 +5414,6 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5394
5414
|
controller.enqueue({ type: "stream-start", warnings });
|
|
5395
5415
|
},
|
|
5396
5416
|
transform(chunk, controller) {
|
|
5397
|
-
var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
5398
5417
|
if (hasInvalidMessageSequence) {
|
|
5399
5418
|
return;
|
|
5400
5419
|
}
|
|
@@ -5463,10 +5482,20 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5463
5482
|
id: String(value.index),
|
|
5464
5483
|
providerMetadata: {
|
|
5465
5484
|
anthropic: {
|
|
5466
|
-
type: "compaction"
|
|
5485
|
+
type: "compaction",
|
|
5486
|
+
...part.signature != null && {
|
|
5487
|
+
signature: part.signature
|
|
5488
|
+
}
|
|
5467
5489
|
}
|
|
5468
5490
|
}
|
|
5469
5491
|
});
|
|
5492
|
+
if (part.signature != null && part.content != null && part.content !== "") {
|
|
5493
|
+
controller.enqueue({
|
|
5494
|
+
type: "text-delta",
|
|
5495
|
+
id: String(value.index),
|
|
5496
|
+
delta: part.content
|
|
5497
|
+
});
|
|
5498
|
+
}
|
|
5470
5499
|
return;
|
|
5471
5500
|
}
|
|
5472
5501
|
case "tool_use": {
|
|
@@ -5612,7 +5641,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5612
5641
|
case "web_fetch_tool_result": {
|
|
5613
5642
|
if (part.content.type === "web_fetch_result") {
|
|
5614
5643
|
citationDocuments.push({
|
|
5615
|
-
title:
|
|
5644
|
+
title: part.content.content.title ?? part.content.url,
|
|
5616
5645
|
mediaType: part.content.content.source.media_type
|
|
5617
5646
|
});
|
|
5618
5647
|
controller.enqueue({
|
|
@@ -5657,16 +5686,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5657
5686
|
type: "tool-result",
|
|
5658
5687
|
toolCallId: part.tool_use_id,
|
|
5659
5688
|
toolName: toolNameMapping.toCustomToolName("web_search"),
|
|
5660
|
-
result: part.content.map((result) => {
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
type: result.type
|
|
5668
|
-
};
|
|
5669
|
-
}),
|
|
5689
|
+
result: part.content.map((result) => ({
|
|
5690
|
+
url: result.url,
|
|
5691
|
+
...result.title != null ? { title: result.title } : {},
|
|
5692
|
+
pageAge: result.page_age ?? null,
|
|
5693
|
+
encryptedContent: result.encrypted_content,
|
|
5694
|
+
type: result.type
|
|
5695
|
+
})),
|
|
5670
5696
|
...getAnthropicCallerMetadata(part.caller)
|
|
5671
5697
|
});
|
|
5672
5698
|
for (const result of part.content) {
|
|
@@ -5678,7 +5704,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5678
5704
|
...result.title != null ? { title: result.title } : {},
|
|
5679
5705
|
providerMetadata: {
|
|
5680
5706
|
anthropic: {
|
|
5681
|
-
pageAge:
|
|
5707
|
+
pageAge: result.page_age ?? null
|
|
5682
5708
|
}
|
|
5683
5709
|
}
|
|
5684
5710
|
});
|
|
@@ -5710,7 +5736,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5710
5736
|
stdout: part.content.stdout,
|
|
5711
5737
|
stderr: part.content.stderr,
|
|
5712
5738
|
return_code: part.content.return_code,
|
|
5713
|
-
content:
|
|
5739
|
+
content: part.content.content ?? []
|
|
5714
5740
|
}
|
|
5715
5741
|
});
|
|
5716
5742
|
} else if (part.content.type === "encrypted_code_execution_result") {
|
|
@@ -5723,7 +5749,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5723
5749
|
encrypted_stdout: part.content.encrypted_stdout,
|
|
5724
5750
|
stderr: part.content.stderr,
|
|
5725
5751
|
return_code: part.content.return_code,
|
|
5726
|
-
content:
|
|
5752
|
+
content: part.content.content ?? []
|
|
5727
5753
|
}
|
|
5728
5754
|
});
|
|
5729
5755
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -5907,7 +5933,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5907
5933
|
let memberInput = {};
|
|
5908
5934
|
try {
|
|
5909
5935
|
memberInput = contentBlock.input === "" ? {} : secureJsonParse2(contentBlock.input);
|
|
5910
|
-
} catch
|
|
5936
|
+
} catch {
|
|
5911
5937
|
memberInput = void 0;
|
|
5912
5938
|
}
|
|
5913
5939
|
contentBlock.input = memberInput === void 0 ? contentBlock.input : JSON.stringify(
|
|
@@ -5936,7 +5962,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5936
5962
|
...parsed
|
|
5937
5963
|
});
|
|
5938
5964
|
}
|
|
5939
|
-
} catch
|
|
5965
|
+
} catch {
|
|
5940
5966
|
}
|
|
5941
5967
|
}
|
|
5942
5968
|
controller.enqueue({
|
|
@@ -6025,7 +6051,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6025
6051
|
return;
|
|
6026
6052
|
}
|
|
6027
6053
|
if (isJsonResponseFromTool) {
|
|
6028
|
-
if (
|
|
6054
|
+
if (contentBlock?.type !== "text") {
|
|
6029
6055
|
return;
|
|
6030
6056
|
}
|
|
6031
6057
|
controller.enqueue({
|
|
@@ -6034,7 +6060,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6034
6060
|
delta
|
|
6035
6061
|
});
|
|
6036
6062
|
} else {
|
|
6037
|
-
if (
|
|
6063
|
+
if (contentBlock?.type !== "tool-call") {
|
|
6038
6064
|
return;
|
|
6039
6065
|
}
|
|
6040
6066
|
if (contentBlock.toolset != null) {
|
|
@@ -6057,7 +6083,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6057
6083
|
case "citations_delta": {
|
|
6058
6084
|
const citation = value.delta.citation;
|
|
6059
6085
|
const contentBlock = contentBlocks[value.index];
|
|
6060
|
-
if (
|
|
6086
|
+
if (contentBlock?.type === "text" && citation.type === "web_search_result_location") {
|
|
6061
6087
|
contentBlock.citations.push(citation);
|
|
6062
6088
|
}
|
|
6063
6089
|
const source = createCitationSource(
|
|
@@ -6096,8 +6122,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6096
6122
|
isMessageOpen = true;
|
|
6097
6123
|
activeMessageId = value.message.id;
|
|
6098
6124
|
usage.input_tokens = value.message.usage.input_tokens;
|
|
6099
|
-
usage.cache_read_input_tokens =
|
|
6100
|
-
usage.cache_creation_input_tokens =
|
|
6125
|
+
usage.cache_read_input_tokens = value.message.usage.cache_read_input_tokens ?? 0;
|
|
6126
|
+
usage.cache_creation_input_tokens = value.message.usage.cache_creation_input_tokens ?? 0;
|
|
6101
6127
|
rawUsage = {
|
|
6102
6128
|
...value.message.usage
|
|
6103
6129
|
};
|
|
@@ -6122,8 +6148,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6122
6148
|
}
|
|
6123
6149
|
controller.enqueue({
|
|
6124
6150
|
type: "response-metadata",
|
|
6125
|
-
id:
|
|
6126
|
-
modelId:
|
|
6151
|
+
id: value.message.id ?? void 0,
|
|
6152
|
+
modelId: value.message.model ?? void 0
|
|
6127
6153
|
});
|
|
6128
6154
|
if (value.message.content != null) {
|
|
6129
6155
|
for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
|
|
@@ -6135,7 +6161,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6135
6161
|
id: part.id,
|
|
6136
6162
|
toolName: part.name
|
|
6137
6163
|
});
|
|
6138
|
-
const inputStr = JSON.stringify(
|
|
6164
|
+
const inputStr = JSON.stringify(part.input ?? {});
|
|
6139
6165
|
controller.enqueue({
|
|
6140
6166
|
type: "tool-input-delta",
|
|
6141
6167
|
id: part.id,
|
|
@@ -6185,18 +6211,18 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6185
6211
|
finishReason: value.delta.stop_reason,
|
|
6186
6212
|
isJsonResponseFromTool
|
|
6187
6213
|
}),
|
|
6188
|
-
raw:
|
|
6214
|
+
raw: value.delta.stop_reason ?? void 0
|
|
6189
6215
|
};
|
|
6190
|
-
stopSequence =
|
|
6216
|
+
stopSequence = value.delta.stop_sequence ?? null;
|
|
6191
6217
|
stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
|
|
6192
6218
|
container = value.delta.container != null ? {
|
|
6193
6219
|
expiresAt: value.delta.container.expires_at,
|
|
6194
6220
|
id: value.delta.container.id,
|
|
6195
|
-
skills:
|
|
6221
|
+
skills: value.delta.container.skills?.map((skill) => ({
|
|
6196
6222
|
type: skill.type,
|
|
6197
6223
|
skillId: skill.skill_id,
|
|
6198
6224
|
version: skill.version
|
|
6199
|
-
}))
|
|
6225
|
+
})) ?? null
|
|
6200
6226
|
} : null;
|
|
6201
6227
|
if (value.context_management) {
|
|
6202
6228
|
contextManagement = mapAnthropicResponseContextManagement(
|
|
@@ -6219,7 +6245,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6219
6245
|
isMessageOpen = false;
|
|
6220
6246
|
activeMessageId = void 0;
|
|
6221
6247
|
const anthropicMetadata = {
|
|
6222
|
-
usage: rawUsage
|
|
6248
|
+
usage: rawUsage ?? null,
|
|
6223
6249
|
stopSequence,
|
|
6224
6250
|
...stopDetails != null ? { stopDetails } : {},
|
|
6225
6251
|
...inputTransformations != null ? { inputTransformations } : {},
|
|
@@ -6275,10 +6301,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6275
6301
|
try {
|
|
6276
6302
|
await firstChunkReader.read();
|
|
6277
6303
|
let result = await firstChunkReader.read();
|
|
6278
|
-
if (
|
|
6304
|
+
if (result.value?.type === "raw") {
|
|
6279
6305
|
result = await firstChunkReader.read();
|
|
6280
6306
|
}
|
|
6281
|
-
if (
|
|
6307
|
+
if (result.value?.type === "error") {
|
|
6282
6308
|
const error = result.value.error;
|
|
6283
6309
|
if (!isProviderStreamError(error)) {
|
|
6284
6310
|
throw new Error("Expected a normalized Anthropic stream error");
|
|
@@ -6287,10 +6313,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6287
6313
|
message: error.message,
|
|
6288
6314
|
url,
|
|
6289
6315
|
requestBodyValues: body,
|
|
6290
|
-
statusCode:
|
|
6316
|
+
statusCode: error.statusCode ?? 500,
|
|
6291
6317
|
responseHeaders,
|
|
6292
6318
|
responseBody: JSON.stringify(error.data),
|
|
6293
|
-
isRetryable:
|
|
6319
|
+
isRetryable: error.isRetryable ?? false
|
|
6294
6320
|
});
|
|
6295
6321
|
}
|
|
6296
6322
|
} finally {
|
|
@@ -6584,7 +6610,7 @@ function mapAnthropicStopDetails(stopDetails) {
|
|
|
6584
6610
|
|
|
6585
6611
|
// src/anthropic-batch.ts
|
|
6586
6612
|
import {
|
|
6587
|
-
InvalidArgumentError,
|
|
6613
|
+
InvalidArgumentError as InvalidArgumentError2,
|
|
6588
6614
|
InvalidResponseDataError as InvalidResponseDataError2,
|
|
6589
6615
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
6590
6616
|
} from "@ai-sdk/provider";
|
|
@@ -6705,10 +6731,9 @@ var AnthropicBatch = class {
|
|
|
6705
6731
|
constructor(options) {
|
|
6706
6732
|
this.options = options;
|
|
6707
6733
|
this.specificationVersion = "v4";
|
|
6708
|
-
var _a;
|
|
6709
6734
|
this.provider = options.provider;
|
|
6710
6735
|
this.supportedUrls = options.supportedUrls;
|
|
6711
|
-
this.generateId =
|
|
6736
|
+
this.generateId = options.config.generateId ?? generateId2;
|
|
6712
6737
|
}
|
|
6713
6738
|
async doStartBatch({
|
|
6714
6739
|
requests,
|
|
@@ -6717,7 +6742,6 @@ var AnthropicBatch = class {
|
|
|
6717
6742
|
abortSignal,
|
|
6718
6743
|
webhookUrl
|
|
6719
6744
|
}) {
|
|
6720
|
-
var _a, _b, _c, _d;
|
|
6721
6745
|
assertTextBatchRequests(requests);
|
|
6722
6746
|
validateRequestIds(requests);
|
|
6723
6747
|
const explicitBatchBetas = new Set(
|
|
@@ -6763,7 +6787,7 @@ var AnthropicBatch = class {
|
|
|
6763
6787
|
message: `Anthropic Message Batches cannot decode the JSON-tool structured-output fallback (request "${request.id}") because batch results are retrieved independently of the start call. Use a model that supports native output_format structured outputs.`
|
|
6764
6788
|
});
|
|
6765
6789
|
}
|
|
6766
|
-
const aliasedProviderTool =
|
|
6790
|
+
const aliasedProviderTool = request.options.tools?.find(
|
|
6767
6791
|
(tool) => tool.type === "provider" && prepared.toolNameMapping.toProviderToolName(tool.name) !== tool.name
|
|
6768
6792
|
);
|
|
6769
6793
|
if (aliasedProviderTool != null) {
|
|
@@ -6772,11 +6796,10 @@ var AnthropicBatch = class {
|
|
|
6772
6796
|
message: `Anthropic Message Batches cannot restore the custom provider-tool name "${aliasedProviderTool.name}" when results are retrieved independently of the start call (request "${request.id}"). Use the provider's canonical tool name.`
|
|
6773
6797
|
});
|
|
6774
6798
|
}
|
|
6775
|
-
const body =
|
|
6776
|
-
_b,
|
|
6799
|
+
const body = this.options.config.transformRequestBody?.(
|
|
6777
6800
|
prepared.args,
|
|
6778
6801
|
prepared.betas
|
|
6779
|
-
)
|
|
6802
|
+
) ?? prepared.args;
|
|
6780
6803
|
validateAnthropicBatchBody({
|
|
6781
6804
|
body,
|
|
6782
6805
|
requestId: request.id
|
|
@@ -6853,13 +6876,13 @@ var AnthropicBatch = class {
|
|
|
6853
6876
|
async doGetBatchResults(options) {
|
|
6854
6877
|
const batch = await this.retrieveBatch(options);
|
|
6855
6878
|
if (convertAnthropicBatchStatus(batch).status === "pending") {
|
|
6856
|
-
throw new
|
|
6879
|
+
throw new InvalidArgumentError2({
|
|
6857
6880
|
argument: "batchId",
|
|
6858
6881
|
message: `Anthropic batch "${options.batchId}" is not complete.`
|
|
6859
6882
|
});
|
|
6860
6883
|
}
|
|
6861
6884
|
if (batch.archived_at != null) {
|
|
6862
|
-
throw new
|
|
6885
|
+
throw new InvalidArgumentError2({
|
|
6863
6886
|
argument: "batchId",
|
|
6864
6887
|
message: `Anthropic batch "${options.batchId}" results are no longer available.`
|
|
6865
6888
|
});
|
|
@@ -6931,7 +6954,6 @@ async function getAnthropicBatchProviderBetas({
|
|
|
6931
6954
|
provider,
|
|
6932
6955
|
providerOptions
|
|
6933
6956
|
}) {
|
|
6934
|
-
var _a;
|
|
6935
6957
|
const providerOptionsName = provider.split(".")[0];
|
|
6936
6958
|
const canonicalOptions = await parseProviderOptions3({
|
|
6937
6959
|
provider: "anthropic",
|
|
@@ -6945,22 +6967,22 @@ async function getAnthropicBatchProviderBetas({
|
|
|
6945
6967
|
}) : void 0;
|
|
6946
6968
|
const anthropicOptions = Object.assign(
|
|
6947
6969
|
{},
|
|
6948
|
-
canonicalOptions
|
|
6949
|
-
customOptions
|
|
6970
|
+
canonicalOptions ?? {},
|
|
6971
|
+
customOptions ?? {}
|
|
6950
6972
|
);
|
|
6951
|
-
return
|
|
6973
|
+
return anthropicOptions.anthropicBeta ?? [];
|
|
6952
6974
|
}
|
|
6953
6975
|
function validateRequestIds(requests) {
|
|
6954
6976
|
const ids = /* @__PURE__ */ new Set();
|
|
6955
6977
|
for (const request of requests) {
|
|
6956
6978
|
if (!anthropicBatchRequestIdPattern.test(request.id)) {
|
|
6957
|
-
throw new
|
|
6979
|
+
throw new InvalidArgumentError2({
|
|
6958
6980
|
argument: "requests",
|
|
6959
6981
|
message: `Anthropic batch request ID "${request.id}" must match ^[A-Za-z0-9_-]{1,64}$.`
|
|
6960
6982
|
});
|
|
6961
6983
|
}
|
|
6962
6984
|
if (ids.has(request.id)) {
|
|
6963
|
-
throw new
|
|
6985
|
+
throw new InvalidArgumentError2({
|
|
6964
6986
|
argument: "requests",
|
|
6965
6987
|
message: `Anthropic batch request IDs must be unique; duplicate ID "${request.id}".`
|
|
6966
6988
|
});
|
|
@@ -6988,7 +7010,6 @@ function validateAnthropicBatchBody({
|
|
|
6988
7010
|
}
|
|
6989
7011
|
}
|
|
6990
7012
|
function convertAnthropicBatchStatus(batch) {
|
|
6991
|
-
var _a, _b, _c, _d;
|
|
6992
7013
|
const requestCounts = convertAnthropicRequestCounts(batch.request_counts);
|
|
6993
7014
|
return {
|
|
6994
7015
|
status: mapAnthropicBatchStatus(batch.processing_status),
|
|
@@ -6998,11 +7019,11 @@ function convertAnthropicBatchStatus(batch) {
|
|
|
6998
7019
|
expiresAt: batch.expires_at,
|
|
6999
7020
|
providerMetadata: {
|
|
7000
7021
|
anthropic: {
|
|
7001
|
-
archivedAt:
|
|
7002
|
-
cancelInitiatedAt:
|
|
7003
|
-
endedAt:
|
|
7022
|
+
archivedAt: batch.archived_at ?? null,
|
|
7023
|
+
cancelInitiatedAt: batch.cancel_initiated_at ?? null,
|
|
7024
|
+
endedAt: batch.ended_at ?? null,
|
|
7004
7025
|
requestCounts: batch.request_counts,
|
|
7005
|
-
resultsUrl:
|
|
7026
|
+
resultsUrl: batch.results_url ?? null
|
|
7006
7027
|
}
|
|
7007
7028
|
}
|
|
7008
7029
|
};
|
|
@@ -7114,7 +7135,6 @@ async function parseAnthropicBatchResponse(message) {
|
|
|
7114
7135
|
return recovered.success ? recovered.value : void 0;
|
|
7115
7136
|
}
|
|
7116
7137
|
function convertAnthropicBatchResponse(response, generateId4) {
|
|
7117
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
7118
7138
|
const content = [];
|
|
7119
7139
|
const mcpToolCalls = {};
|
|
7120
7140
|
const serverToolCalls = {};
|
|
@@ -7131,7 +7151,7 @@ function convertAnthropicBatchResponse(response, generateId4) {
|
|
|
7131
7151
|
}
|
|
7132
7152
|
}
|
|
7133
7153
|
});
|
|
7134
|
-
for (const citation of
|
|
7154
|
+
for (const citation of part.citations ?? []) {
|
|
7135
7155
|
const source = createCitationSource(citation, [], generateId4);
|
|
7136
7156
|
if (source != null) {
|
|
7137
7157
|
content.push(source);
|
|
@@ -7174,7 +7194,12 @@ function convertAnthropicBatchResponse(response, generateId4) {
|
|
|
7174
7194
|
content.push({
|
|
7175
7195
|
type: "text",
|
|
7176
7196
|
text: part.content,
|
|
7177
|
-
providerMetadata: {
|
|
7197
|
+
providerMetadata: {
|
|
7198
|
+
anthropic: {
|
|
7199
|
+
type: "compaction",
|
|
7200
|
+
...part.signature != null && { signature: part.signature }
|
|
7201
|
+
}
|
|
7202
|
+
}
|
|
7178
7203
|
});
|
|
7179
7204
|
break;
|
|
7180
7205
|
case "tool_use":
|
|
@@ -7232,11 +7257,11 @@ function convertAnthropicBatchResponse(response, generateId4) {
|
|
|
7232
7257
|
content.push({
|
|
7233
7258
|
type: "tool-result",
|
|
7234
7259
|
toolCallId: part.tool_use_id,
|
|
7235
|
-
toolName:
|
|
7260
|
+
toolName: toolCall?.toolName ?? "mcp",
|
|
7236
7261
|
isError: part.is_error,
|
|
7237
7262
|
result: part.content,
|
|
7238
7263
|
dynamic: true,
|
|
7239
|
-
...
|
|
7264
|
+
...toolCall?.providerMetadata != null && {
|
|
7240
7265
|
providerMetadata: toolCall.providerMetadata
|
|
7241
7266
|
}
|
|
7242
7267
|
});
|
|
@@ -7279,16 +7304,13 @@ function convertAnthropicBatchResponse(response, generateId4) {
|
|
|
7279
7304
|
toolCallId: part.tool_use_id,
|
|
7280
7305
|
toolName: "web_search",
|
|
7281
7306
|
...Array.isArray(part.content) ? {
|
|
7282
|
-
result: part.content.map((result) => {
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7288
|
-
|
|
7289
|
-
url: result.url
|
|
7290
|
-
};
|
|
7291
|
-
})
|
|
7307
|
+
result: part.content.map((result) => ({
|
|
7308
|
+
encryptedContent: result.encrypted_content,
|
|
7309
|
+
pageAge: result.page_age ?? null,
|
|
7310
|
+
...result.title != null ? { title: result.title } : {},
|
|
7311
|
+
type: result.type,
|
|
7312
|
+
url: result.url
|
|
7313
|
+
}))
|
|
7292
7314
|
} : {
|
|
7293
7315
|
isError: true,
|
|
7294
7316
|
result: {
|
|
@@ -7308,7 +7330,7 @@ function convertAnthropicBatchResponse(response, generateId4) {
|
|
|
7308
7330
|
...result.title != null ? { title: result.title } : {},
|
|
7309
7331
|
providerMetadata: {
|
|
7310
7332
|
anthropic: {
|
|
7311
|
-
pageAge:
|
|
7333
|
+
pageAge: result.page_age ?? null
|
|
7312
7334
|
}
|
|
7313
7335
|
}
|
|
7314
7336
|
});
|
|
@@ -7339,7 +7361,7 @@ function convertAnthropicBatchResponse(response, generateId4) {
|
|
|
7339
7361
|
});
|
|
7340
7362
|
break;
|
|
7341
7363
|
case "tool_search_tool_result": {
|
|
7342
|
-
const toolName =
|
|
7364
|
+
const toolName = serverToolCalls[part.tool_use_id] ?? "tool_search_tool_regex";
|
|
7343
7365
|
content.push({
|
|
7344
7366
|
type: "tool-result",
|
|
7345
7367
|
toolCallId: part.tool_use_id,
|
|
@@ -7405,12 +7427,12 @@ function convertAnthropicBatchResponse(response, generateId4) {
|
|
|
7405
7427
|
unified: mapAnthropicStopReason({
|
|
7406
7428
|
finishReason: response.stop_reason
|
|
7407
7429
|
}),
|
|
7408
|
-
raw:
|
|
7430
|
+
raw: response.stop_reason ?? void 0
|
|
7409
7431
|
},
|
|
7410
7432
|
usage: convertAnthropicUsage({ usage: response.usage }),
|
|
7411
7433
|
response: {
|
|
7412
|
-
id:
|
|
7413
|
-
modelId:
|
|
7434
|
+
id: response.id ?? void 0,
|
|
7435
|
+
modelId: response.model ?? void 0
|
|
7414
7436
|
},
|
|
7415
7437
|
warnings: [],
|
|
7416
7438
|
providerMetadata: {
|
|
@@ -7431,11 +7453,10 @@ function anthropicCallerMetadata(caller) {
|
|
|
7431
7453
|
};
|
|
7432
7454
|
}
|
|
7433
7455
|
function convertAnthropicMessageMetadata(response) {
|
|
7434
|
-
var _a, _b, _c;
|
|
7435
7456
|
const stopDetails = mapAnthropicStopDetails2(response.stop_details);
|
|
7436
7457
|
return {
|
|
7437
7458
|
usage: response.usage,
|
|
7438
|
-
stopSequence:
|
|
7459
|
+
stopSequence: response.stop_sequence ?? null,
|
|
7439
7460
|
...stopDetails != null ? { stopDetails } : {},
|
|
7440
7461
|
...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
|
|
7441
7462
|
...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
|
|
@@ -7454,11 +7475,11 @@ function convertAnthropicMessageMetadata(response) {
|
|
|
7454
7475
|
container: response.container ? {
|
|
7455
7476
|
expiresAt: response.container.expires_at,
|
|
7456
7477
|
id: response.container.id,
|
|
7457
|
-
skills:
|
|
7478
|
+
skills: response.container.skills?.map((skill) => ({
|
|
7458
7479
|
type: skill.type,
|
|
7459
7480
|
skillId: skill.skill_id,
|
|
7460
7481
|
version: skill.version
|
|
7461
|
-
}))
|
|
7482
|
+
})) ?? null
|
|
7462
7483
|
} : null,
|
|
7463
7484
|
contextManagement: mapAnthropicResponseContextManagement2(
|
|
7464
7485
|
response.context_management
|
|
@@ -8239,7 +8260,6 @@ var AnthropicSkills = class {
|
|
|
8239
8260
|
};
|
|
8240
8261
|
}
|
|
8241
8262
|
async uploadSkill(params) {
|
|
8242
|
-
var _a, _b;
|
|
8243
8263
|
const warnings = [];
|
|
8244
8264
|
const formData = new FormData();
|
|
8245
8265
|
if (params.displayTitle != null) {
|
|
@@ -8265,8 +8285,8 @@ var AnthropicSkills = class {
|
|
|
8265
8285
|
version: response.latest_version,
|
|
8266
8286
|
headers
|
|
8267
8287
|
}) : {};
|
|
8268
|
-
const name =
|
|
8269
|
-
const description =
|
|
8288
|
+
const name = versionMetadata.name ?? response.name;
|
|
8289
|
+
const description = versionMetadata.description ?? response.description;
|
|
8270
8290
|
return {
|
|
8271
8291
|
providerReference: { anthropic: response.id },
|
|
8272
8292
|
...response.display_title != null ? { displayTitle: response.display_title } : {},
|
|
@@ -8286,7 +8306,7 @@ var AnthropicSkills = class {
|
|
|
8286
8306
|
};
|
|
8287
8307
|
|
|
8288
8308
|
// src/version.ts
|
|
8289
|
-
var VERSION = true ? "4.0.
|
|
8309
|
+
var VERSION = true ? "4.0.65" : "0.0.0-test";
|
|
8290
8310
|
|
|
8291
8311
|
// src/anthropic-provider.ts
|
|
8292
8312
|
var ANTHROPIC_API_URL = "https://api.anthropic.com";
|
|
@@ -8298,20 +8318,19 @@ function normalizeBaseURL(baseURL) {
|
|
|
8298
8318
|
return baseURLWithoutTrailingSlash === ANTHROPIC_API_URL ? ANTHROPIC_API_VERSIONED_URL : baseURLWithoutTrailingSlash;
|
|
8299
8319
|
}
|
|
8300
8320
|
function createAnthropic(options = {}) {
|
|
8301
|
-
|
|
8302
|
-
const baseURL = (_a = normalizeBaseURL(
|
|
8321
|
+
const baseURL = normalizeBaseURL(
|
|
8303
8322
|
loadOptionalSetting({
|
|
8304
8323
|
settingValue: options.baseURL,
|
|
8305
8324
|
environmentVariableName: "ANTHROPIC_BASE_URL"
|
|
8306
8325
|
})
|
|
8307
|
-
)
|
|
8308
|
-
const providerName =
|
|
8326
|
+
) ?? ANTHROPIC_API_VERSIONED_URL;
|
|
8327
|
+
const providerName = options.name ?? "anthropic.messages";
|
|
8309
8328
|
const supportedUrls = {
|
|
8310
8329
|
"image/*": [/^https?:\/\/.*$/],
|
|
8311
8330
|
"application/pdf": [/^https?:\/\/.*$/]
|
|
8312
8331
|
};
|
|
8313
8332
|
if (options.apiKey && options.authToken) {
|
|
8314
|
-
throw new
|
|
8333
|
+
throw new InvalidArgumentError3({
|
|
8315
8334
|
argument: "apiKey/authToken",
|
|
8316
8335
|
message: "Both apiKey and authToken were provided. Please use only one authentication method."
|
|
8317
8336
|
});
|
|
@@ -8338,7 +8357,7 @@ function createAnthropic(options = {}) {
|
|
|
8338
8357
|
baseURL,
|
|
8339
8358
|
headers: getHeaders,
|
|
8340
8359
|
fetch: options.fetch,
|
|
8341
|
-
generateId:
|
|
8360
|
+
generateId: options.generateId ?? generateId3,
|
|
8342
8361
|
supportedUrls: () => supportedUrls
|
|
8343
8362
|
};
|
|
8344
8363
|
const createChatModel = (modelId) => new AnthropicLanguageModel(modelId, languageModelConfig);
|
|
@@ -8393,9 +8412,8 @@ var anthropic = createAnthropic();
|
|
|
8393
8412
|
function forwardAnthropicContainerIdFromLastStep({
|
|
8394
8413
|
steps
|
|
8395
8414
|
}) {
|
|
8396
|
-
var _a, _b, _c;
|
|
8397
8415
|
for (let i = steps.length - 1; i >= 0; i--) {
|
|
8398
|
-
const containerId =
|
|
8416
|
+
const containerId = steps[i].providerMetadata?.anthropic?.container?.id;
|
|
8399
8417
|
if (containerId) {
|
|
8400
8418
|
return {
|
|
8401
8419
|
providerOptions: {
|