@ai-sdk/anthropic 4.0.63 → 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 +16 -0
- package/dist/index.js +235 -272
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +200 -225
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +33 -11
- package/package.json +3 -3
- package/src/anthropic-language-model-options.ts +4 -3
- package/src/convert-to-anthropic-prompt.ts +16 -7
package/dist/internal/index.js
CHANGED
|
@@ -61,7 +61,6 @@ var AnthropicFiles = class {
|
|
|
61
61
|
abortSignal,
|
|
62
62
|
headers
|
|
63
63
|
}) {
|
|
64
|
-
var _a, _b;
|
|
65
64
|
const fileBytes = convertInlineFileDataToUint8Array(data);
|
|
66
65
|
const blob = new Blob([fileBytes], { type: mediaType });
|
|
67
66
|
const formData = new FormData();
|
|
@@ -88,8 +87,8 @@ var AnthropicFiles = class {
|
|
|
88
87
|
return {
|
|
89
88
|
warnings: [],
|
|
90
89
|
providerReference: { anthropic: response.id },
|
|
91
|
-
mediaType:
|
|
92
|
-
filename:
|
|
90
|
+
mediaType: response.mime_type ?? mediaType,
|
|
91
|
+
filename: response.filename ?? filename,
|
|
93
92
|
providerMetadata: {
|
|
94
93
|
anthropic: {
|
|
95
94
|
filename: response.filename,
|
|
@@ -999,9 +998,10 @@ var anthropicSystemMessageProviderOptions = z4.object({
|
|
|
999
998
|
*/
|
|
1000
999
|
clearAt: z4.literal("next_user_message").optional(),
|
|
1001
1000
|
/**
|
|
1002
|
-
* Sets the model effort
|
|
1003
|
-
* system message
|
|
1004
|
-
* beta is
|
|
1001
|
+
* Sets the model effort from the next user turn until a later message
|
|
1002
|
+
* changes it. An effort-only system message with empty content can appear
|
|
1003
|
+
* first. The required `mid-conversation-output-config-2026-07-01` beta is
|
|
1004
|
+
* added automatically.
|
|
1005
1005
|
*/
|
|
1006
1006
|
effort: z4.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
1007
1007
|
/**
|
|
@@ -1322,9 +1322,8 @@ import {
|
|
|
1322
1322
|
// src/get-cache-control.ts
|
|
1323
1323
|
var MAX_CACHE_BREAKPOINTS = 4;
|
|
1324
1324
|
function getCacheControl(providerMetadata) {
|
|
1325
|
-
|
|
1326
|
-
const
|
|
1327
|
-
const cacheControlValue = (_a = anthropic == null ? void 0 : anthropic.cacheControl) != null ? _a : anthropic == null ? void 0 : anthropic.cache_control;
|
|
1325
|
+
const anthropic = providerMetadata?.anthropic;
|
|
1326
|
+
const cacheControlValue = anthropic?.cacheControl ?? anthropic?.cache_control;
|
|
1328
1327
|
return cacheControlValue;
|
|
1329
1328
|
}
|
|
1330
1329
|
var CacheControlValidator = class {
|
|
@@ -1871,8 +1870,7 @@ async function prepareTools({
|
|
|
1871
1870
|
defaultEagerInputStreaming = false,
|
|
1872
1871
|
rejectsForcedToolUse = false
|
|
1873
1872
|
}) {
|
|
1874
|
-
|
|
1875
|
-
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
1873
|
+
tools = tools?.length ? tools : void 0;
|
|
1876
1874
|
const toolWarnings = [];
|
|
1877
1875
|
const betas = /* @__PURE__ */ new Set();
|
|
1878
1876
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -1887,10 +1885,10 @@ async function prepareTools({
|
|
|
1887
1885
|
type: "tool definition",
|
|
1888
1886
|
canCache: true
|
|
1889
1887
|
});
|
|
1890
|
-
const anthropicOptions =
|
|
1891
|
-
const eagerInputStreaming =
|
|
1892
|
-
const deferLoading = anthropicOptions
|
|
1893
|
-
const allowedCallers = anthropicOptions
|
|
1888
|
+
const anthropicOptions = tool.providerOptions?.anthropic;
|
|
1889
|
+
const eagerInputStreaming = anthropicOptions?.eagerInputStreaming ?? defaultEagerInputStreaming;
|
|
1890
|
+
const deferLoading = anthropicOptions?.deferLoading;
|
|
1891
|
+
const allowedCallers = anthropicOptions?.allowedCallers;
|
|
1894
1892
|
if (!supportsStrictTools && tool.strict != null) {
|
|
1895
1893
|
toolWarnings.push({
|
|
1896
1894
|
type: "unsupported",
|
|
@@ -1981,10 +1979,10 @@ async function prepareTools({
|
|
|
1981
1979
|
Object.entries(args.configs).map(([member, config]) => [
|
|
1982
1980
|
member,
|
|
1983
1981
|
{
|
|
1984
|
-
...
|
|
1982
|
+
...config?.enabled != null && {
|
|
1985
1983
|
enabled: config.enabled
|
|
1986
1984
|
},
|
|
1987
|
-
...
|
|
1985
|
+
...config?.deferLoading != null && {
|
|
1988
1986
|
defer_loading: config.deferLoading
|
|
1989
1987
|
}
|
|
1990
1988
|
}
|
|
@@ -2322,13 +2320,12 @@ function convertAnthropicUsage({
|
|
|
2322
2320
|
usage,
|
|
2323
2321
|
rawUsage
|
|
2324
2322
|
}) {
|
|
2325
|
-
|
|
2326
|
-
const
|
|
2327
|
-
const
|
|
2328
|
-
const reasoningTokens = (_d = (_c = usage.output_tokens_details) == null ? void 0 : _c.thinking_tokens) != null ? _d : void 0;
|
|
2323
|
+
const cacheCreationTokens = usage.cache_creation_input_tokens ?? 0;
|
|
2324
|
+
const cacheReadTokens = usage.cache_read_input_tokens ?? 0;
|
|
2325
|
+
const reasoningTokens = usage.output_tokens_details?.thinking_tokens ?? void 0;
|
|
2329
2326
|
let inputTokens;
|
|
2330
2327
|
let outputTokens;
|
|
2331
|
-
const servedByFallback =
|
|
2328
|
+
const servedByFallback = usage.iterations?.some(
|
|
2332
2329
|
(iter) => iter.type === "fallback_message"
|
|
2333
2330
|
);
|
|
2334
2331
|
if (usage.iterations && usage.iterations.length > 0 && !servedByFallback) {
|
|
@@ -2365,7 +2362,7 @@ function convertAnthropicUsage({
|
|
|
2365
2362
|
text: reasoningTokens == null ? void 0 : outputTokens - reasoningTokens,
|
|
2366
2363
|
reasoning: reasoningTokens
|
|
2367
2364
|
},
|
|
2368
|
-
raw: rawUsage
|
|
2365
|
+
raw: rawUsage ?? usage
|
|
2369
2366
|
};
|
|
2370
2367
|
}
|
|
2371
2368
|
|
|
@@ -2538,15 +2535,14 @@ var codeExecution_20250825 = (args = {}) => {
|
|
|
2538
2535
|
return experimental_toolCaller(factory10(args), {
|
|
2539
2536
|
type: "provider",
|
|
2540
2537
|
prepareProviderOptions: (providerOptions) => {
|
|
2541
|
-
|
|
2542
|
-
const anthropicOptions = providerOptions == null ? void 0 : providerOptions.anthropic;
|
|
2538
|
+
const anthropicOptions = providerOptions?.anthropic;
|
|
2543
2539
|
return {
|
|
2544
2540
|
...providerOptions,
|
|
2545
2541
|
anthropic: {
|
|
2546
2542
|
...anthropicOptions,
|
|
2547
2543
|
allowedCallers: [
|
|
2548
2544
|
.../* @__PURE__ */ new Set([
|
|
2549
|
-
...
|
|
2545
|
+
...anthropicOptions?.allowedCallers ?? [],
|
|
2550
2546
|
"code_execution_20250825"
|
|
2551
2547
|
])
|
|
2552
2548
|
]
|
|
@@ -2678,15 +2674,14 @@ var codeExecution_20260120 = (args = {}) => {
|
|
|
2678
2674
|
return experimental_toolCaller2(factory11(args), {
|
|
2679
2675
|
type: "provider",
|
|
2680
2676
|
prepareProviderOptions: (providerOptions) => {
|
|
2681
|
-
|
|
2682
|
-
const anthropicOptions = providerOptions == null ? void 0 : providerOptions.anthropic;
|
|
2677
|
+
const anthropicOptions = providerOptions?.anthropic;
|
|
2683
2678
|
return {
|
|
2684
2679
|
...providerOptions,
|
|
2685
2680
|
anthropic: {
|
|
2686
2681
|
...anthropicOptions,
|
|
2687
2682
|
allowedCallers: [
|
|
2688
2683
|
.../* @__PURE__ */ new Set([
|
|
2689
|
-
...
|
|
2684
|
+
...anthropicOptions?.allowedCallers ?? [],
|
|
2690
2685
|
"code_execution_20260120"
|
|
2691
2686
|
])
|
|
2692
2687
|
]
|
|
@@ -2758,8 +2753,8 @@ function extractErrorValue(value) {
|
|
|
2758
2753
|
} else if (typeof value === "object" && value !== null) {
|
|
2759
2754
|
return value;
|
|
2760
2755
|
}
|
|
2761
|
-
} catch
|
|
2762
|
-
const extractedErrorCode = value
|
|
2756
|
+
} catch {
|
|
2757
|
+
const extractedErrorCode = value?.errorCode;
|
|
2763
2758
|
return {
|
|
2764
2759
|
errorCode: typeof extractedErrorCode === "string" ? extractedErrorCode : "unavailable"
|
|
2765
2760
|
};
|
|
@@ -2774,29 +2769,26 @@ async function convertToAnthropicPrompt({
|
|
|
2774
2769
|
toolNameMapping,
|
|
2775
2770
|
toolsetNames = {}
|
|
2776
2771
|
}) {
|
|
2777
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2778
2772
|
const betas = /* @__PURE__ */ new Set();
|
|
2779
2773
|
const blocks = groupIntoBlocks(prompt);
|
|
2780
2774
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
2781
2775
|
let system = void 0;
|
|
2782
2776
|
const messages = [];
|
|
2783
2777
|
async function shouldEnableCitations(providerMetadata) {
|
|
2784
|
-
var _a2, _b2;
|
|
2785
2778
|
const anthropicOptions = await parseProviderOptions({
|
|
2786
2779
|
provider: "anthropic",
|
|
2787
2780
|
providerOptions: providerMetadata,
|
|
2788
2781
|
schema: anthropicFilePartProviderOptions
|
|
2789
2782
|
});
|
|
2790
|
-
return
|
|
2783
|
+
return anthropicOptions?.citations?.enabled ?? false;
|
|
2791
2784
|
}
|
|
2792
2785
|
async function shouldUseContainerUpload(providerMetadata) {
|
|
2793
|
-
var _a2;
|
|
2794
2786
|
const anthropicOptions = await parseProviderOptions({
|
|
2795
2787
|
provider: "anthropic",
|
|
2796
2788
|
providerOptions: providerMetadata,
|
|
2797
2789
|
schema: anthropicFilePartProviderOptions
|
|
2798
2790
|
});
|
|
2799
|
-
return
|
|
2791
|
+
return anthropicOptions?.containerUpload ?? false;
|
|
2800
2792
|
}
|
|
2801
2793
|
async function getDocumentMetadata(providerMetadata) {
|
|
2802
2794
|
const anthropicOptions = await parseProviderOptions({
|
|
@@ -2805,8 +2797,8 @@ async function convertToAnthropicPrompt({
|
|
|
2805
2797
|
schema: anthropicFilePartProviderOptions
|
|
2806
2798
|
});
|
|
2807
2799
|
return {
|
|
2808
|
-
title: anthropicOptions
|
|
2809
|
-
context: anthropicOptions
|
|
2800
|
+
title: anthropicOptions?.title,
|
|
2801
|
+
context: anthropicOptions?.context
|
|
2810
2802
|
};
|
|
2811
2803
|
}
|
|
2812
2804
|
for (let i = 0; i < blocks.length; i++) {
|
|
@@ -2822,9 +2814,9 @@ async function convertToAnthropicPrompt({
|
|
|
2822
2814
|
providerOptions,
|
|
2823
2815
|
schema: anthropicSystemMessageProviderOptions
|
|
2824
2816
|
});
|
|
2825
|
-
const toolChanges =
|
|
2817
|
+
const toolChanges = systemMessageOptions?.toolChanges ?? [];
|
|
2826
2818
|
const content = [];
|
|
2827
|
-
if (text !== "" || toolChanges.length === 0 &&
|
|
2819
|
+
if (text !== "" || toolChanges.length === 0 && systemMessageOptions?.clearAt == null && systemMessageOptions?.effort == null) {
|
|
2828
2820
|
content.push({
|
|
2829
2821
|
type: "text",
|
|
2830
2822
|
text,
|
|
@@ -2845,8 +2837,8 @@ async function convertToAnthropicPrompt({
|
|
|
2845
2837
|
}
|
|
2846
2838
|
convertedMessages.push({
|
|
2847
2839
|
content,
|
|
2848
|
-
clearAt: systemMessageOptions
|
|
2849
|
-
effort: systemMessageOptions
|
|
2840
|
+
clearAt: systemMessageOptions?.clearAt,
|
|
2841
|
+
effort: systemMessageOptions?.effort,
|
|
2850
2842
|
toolChangeCount: toolChanges.length
|
|
2851
2843
|
});
|
|
2852
2844
|
}
|
|
@@ -2865,10 +2857,17 @@ async function convertToAnthropicPrompt({
|
|
|
2865
2857
|
});
|
|
2866
2858
|
}
|
|
2867
2859
|
for (const message of convertedMessages) {
|
|
2868
|
-
if (message.clearAt
|
|
2860
|
+
if (message.content.length === 0 && message.clearAt == null && message.effort != null) {
|
|
2861
|
+
messages.push({
|
|
2862
|
+
role: "system",
|
|
2863
|
+
content: [],
|
|
2864
|
+
output_config: { effort: message.effort }
|
|
2865
|
+
});
|
|
2866
|
+
betas.add("mid-conversation-output-config-2026-07-01");
|
|
2867
|
+
} else if (message.clearAt != null || message.effort != null) {
|
|
2869
2868
|
warnings.push({
|
|
2870
2869
|
type: "other",
|
|
2871
|
-
message: "clearAt and effort on
|
|
2870
|
+
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."
|
|
2872
2871
|
});
|
|
2873
2872
|
}
|
|
2874
2873
|
}
|
|
@@ -2910,13 +2909,13 @@ async function convertToAnthropicPrompt({
|
|
|
2910
2909
|
for (let j = 0; j < content.length; j++) {
|
|
2911
2910
|
const part = content[j];
|
|
2912
2911
|
const isLastPart = j === content.length - 1;
|
|
2913
|
-
const cacheControl =
|
|
2912
|
+
const cacheControl = validator.getCacheControl(part.providerOptions, {
|
|
2914
2913
|
type: "user message part",
|
|
2915
2914
|
canCache: true
|
|
2916
|
-
})
|
|
2915
|
+
}) ?? (isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
2917
2916
|
type: "user message",
|
|
2918
2917
|
canCache: true
|
|
2919
|
-
}) : void 0;
|
|
2918
|
+
}) : void 0);
|
|
2920
2919
|
switch (part.type) {
|
|
2921
2920
|
case "text": {
|
|
2922
2921
|
anthropicContent.push({
|
|
@@ -2968,7 +2967,7 @@ async function convertToAnthropicPrompt({
|
|
|
2968
2967
|
media_type: "text/plain",
|
|
2969
2968
|
data: part.data.text
|
|
2970
2969
|
},
|
|
2971
|
-
title:
|
|
2970
|
+
title: metadata.title ?? part.filename,
|
|
2972
2971
|
...metadata.context && {
|
|
2973
2972
|
context: metadata.context
|
|
2974
2973
|
},
|
|
@@ -3013,7 +3012,7 @@ async function convertToAnthropicPrompt({
|
|
|
3013
3012
|
media_type: "application/pdf",
|
|
3014
3013
|
data: convertToBase64(part.data.data)
|
|
3015
3014
|
},
|
|
3016
|
-
title:
|
|
3015
|
+
title: metadata.title ?? part.filename,
|
|
3017
3016
|
...metadata.context && {
|
|
3018
3017
|
context: metadata.context
|
|
3019
3018
|
},
|
|
@@ -3041,7 +3040,7 @@ async function convertToAnthropicPrompt({
|
|
|
3041
3040
|
part.data.data
|
|
3042
3041
|
)
|
|
3043
3042
|
},
|
|
3044
|
-
title:
|
|
3043
|
+
title: metadata.title ?? part.filename,
|
|
3045
3044
|
...metadata.context && {
|
|
3046
3045
|
context: metadata.context
|
|
3047
3046
|
},
|
|
@@ -3071,25 +3070,24 @@ async function convertToAnthropicPrompt({
|
|
|
3071
3070
|
continue;
|
|
3072
3071
|
}
|
|
3073
3072
|
const output = part.output;
|
|
3074
|
-
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ?
|
|
3073
|
+
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? output.value.find(
|
|
3075
3074
|
(contentPart) => contentPart.providerOptions != null
|
|
3076
|
-
)
|
|
3075
|
+
)?.providerOptions : void 0;
|
|
3077
3076
|
const isLastPart = i2 === content.length - 1;
|
|
3078
|
-
const cacheControl =
|
|
3077
|
+
const cacheControl = validator.getCacheControl(part.providerOptions, {
|
|
3079
3078
|
type: "tool result part",
|
|
3080
3079
|
canCache: true
|
|
3081
|
-
})
|
|
3080
|
+
}) ?? validator.getCacheControl(outputProviderOptions, {
|
|
3082
3081
|
type: "tool result output",
|
|
3083
3082
|
canCache: true
|
|
3084
|
-
})
|
|
3083
|
+
}) ?? (isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
3085
3084
|
type: "tool result message",
|
|
3086
3085
|
canCache: true
|
|
3087
|
-
}) : void 0;
|
|
3086
|
+
}) : void 0);
|
|
3088
3087
|
let contentValue;
|
|
3089
3088
|
switch (output.type) {
|
|
3090
3089
|
case "content":
|
|
3091
3090
|
contentValue = output.value.map((contentPart) => {
|
|
3092
|
-
var _a2;
|
|
3093
3091
|
switch (contentPart.type) {
|
|
3094
3092
|
case "text":
|
|
3095
3093
|
return {
|
|
@@ -3159,8 +3157,8 @@ async function convertToAnthropicPrompt({
|
|
|
3159
3157
|
return void 0;
|
|
3160
3158
|
}
|
|
3161
3159
|
case "custom": {
|
|
3162
|
-
const anthropicOptions =
|
|
3163
|
-
if (
|
|
3160
|
+
const anthropicOptions = contentPart.providerOptions?.anthropic;
|
|
3161
|
+
if (anthropicOptions?.type === "tool-reference") {
|
|
3164
3162
|
return {
|
|
3165
3163
|
type: "tool_reference",
|
|
3166
3164
|
tool_name: anthropicOptions.toolName
|
|
@@ -3187,7 +3185,7 @@ async function convertToAnthropicPrompt({
|
|
|
3187
3185
|
contentValue = output.value;
|
|
3188
3186
|
break;
|
|
3189
3187
|
case "execution-denied":
|
|
3190
|
-
contentValue =
|
|
3188
|
+
contentValue = output.reason ?? "Tool call execution denied.";
|
|
3191
3189
|
break;
|
|
3192
3190
|
case "json":
|
|
3193
3191
|
case "error-json":
|
|
@@ -3230,17 +3228,17 @@ async function convertToAnthropicPrompt({
|
|
|
3230
3228
|
for (let k = 0; k < content.length; k++) {
|
|
3231
3229
|
const part = content[k];
|
|
3232
3230
|
const isLastContentPart = k === content.length - 1;
|
|
3233
|
-
const cacheControl =
|
|
3231
|
+
const cacheControl = validator.getCacheControl(part.providerOptions, {
|
|
3234
3232
|
type: "assistant message part",
|
|
3235
3233
|
canCache: true
|
|
3236
|
-
})
|
|
3234
|
+
}) ?? (isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
3237
3235
|
type: "assistant message",
|
|
3238
3236
|
canCache: true
|
|
3239
|
-
}) : void 0;
|
|
3237
|
+
}) : void 0);
|
|
3240
3238
|
switch (part.type) {
|
|
3241
3239
|
case "text": {
|
|
3242
|
-
const textMetadata =
|
|
3243
|
-
if (
|
|
3240
|
+
const textMetadata = part.providerOptions?.anthropic;
|
|
3241
|
+
if (textMetadata?.type === "compaction") {
|
|
3244
3242
|
if (part.text === "") {
|
|
3245
3243
|
break;
|
|
3246
3244
|
}
|
|
@@ -3264,7 +3262,7 @@ async function convertToAnthropicPrompt({
|
|
|
3264
3262
|
// in pre-filled assistant responses
|
|
3265
3263
|
isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
|
|
3266
3264
|
),
|
|
3267
|
-
...
|
|
3265
|
+
...textMetadata?.citations != null && {
|
|
3268
3266
|
citations: textMetadata.citations
|
|
3269
3267
|
},
|
|
3270
3268
|
cache_control: cacheControl
|
|
@@ -3325,10 +3323,10 @@ async function convertToAnthropicPrompt({
|
|
|
3325
3323
|
const providerToolName = toolNameMapping.toProviderToolName(
|
|
3326
3324
|
part.toolName
|
|
3327
3325
|
);
|
|
3328
|
-
const isMcpToolUse =
|
|
3326
|
+
const isMcpToolUse = part.providerOptions?.anthropic?.type === "mcp-tool-use";
|
|
3329
3327
|
if (isMcpToolUse) {
|
|
3330
3328
|
mcpToolUseIds.add(part.toolCallId);
|
|
3331
|
-
const serverName =
|
|
3329
|
+
const serverName = part.providerOptions?.anthropic?.serverName;
|
|
3332
3330
|
if (serverName == null || typeof serverName !== "string") {
|
|
3333
3331
|
warnings.push({
|
|
3334
3332
|
type: "other",
|
|
@@ -3478,7 +3476,7 @@ async function convertToAnthropicPrompt({
|
|
|
3478
3476
|
} else if (typeof output.value === "object" && output.value !== null) {
|
|
3479
3477
|
errorInfo = output.value;
|
|
3480
3478
|
}
|
|
3481
|
-
} catch
|
|
3479
|
+
} catch {
|
|
3482
3480
|
}
|
|
3483
3481
|
if (errorInfo.type === "code_execution_tool_result_error") {
|
|
3484
3482
|
anthropicContent.push({
|
|
@@ -3486,7 +3484,7 @@ async function convertToAnthropicPrompt({
|
|
|
3486
3484
|
tool_use_id: part.toolCallId,
|
|
3487
3485
|
content: {
|
|
3488
3486
|
type: "code_execution_tool_result_error",
|
|
3489
|
-
error_code:
|
|
3487
|
+
error_code: errorInfo.errorCode ?? "unknown"
|
|
3490
3488
|
},
|
|
3491
3489
|
cache_control: cacheControl
|
|
3492
3490
|
});
|
|
@@ -3497,7 +3495,7 @@ async function convertToAnthropicPrompt({
|
|
|
3497
3495
|
cache_control: cacheControl,
|
|
3498
3496
|
content: {
|
|
3499
3497
|
type: "bash_code_execution_tool_result_error",
|
|
3500
|
-
error_code:
|
|
3498
|
+
error_code: errorInfo.errorCode ?? "unknown"
|
|
3501
3499
|
}
|
|
3502
3500
|
});
|
|
3503
3501
|
}
|
|
@@ -3530,7 +3528,7 @@ async function convertToAnthropicPrompt({
|
|
|
3530
3528
|
stdout: codeExecutionOutput.stdout,
|
|
3531
3529
|
stderr: codeExecutionOutput.stderr,
|
|
3532
3530
|
return_code: codeExecutionOutput.return_code,
|
|
3533
|
-
content:
|
|
3531
|
+
content: codeExecutionOutput.content ?? []
|
|
3534
3532
|
},
|
|
3535
3533
|
cache_control: cacheControl
|
|
3536
3534
|
});
|
|
@@ -3548,7 +3546,7 @@ async function convertToAnthropicPrompt({
|
|
|
3548
3546
|
encrypted_stdout: codeExecutionOutput.encrypted_stdout,
|
|
3549
3547
|
stderr: codeExecutionOutput.stderr,
|
|
3550
3548
|
return_code: codeExecutionOutput.return_code,
|
|
3551
|
-
content:
|
|
3549
|
+
content: codeExecutionOutput.content ?? []
|
|
3552
3550
|
},
|
|
3553
3551
|
cache_control: cacheControl
|
|
3554
3552
|
});
|
|
@@ -3567,7 +3565,7 @@ async function convertToAnthropicPrompt({
|
|
|
3567
3565
|
stdout: codeExecutionOutput.stdout,
|
|
3568
3566
|
stderr: codeExecutionOutput.stderr,
|
|
3569
3567
|
return_code: codeExecutionOutput.return_code,
|
|
3570
|
-
content:
|
|
3568
|
+
content: codeExecutionOutput.content ?? []
|
|
3571
3569
|
},
|
|
3572
3570
|
cache_control: cacheControl
|
|
3573
3571
|
});
|
|
@@ -3605,7 +3603,7 @@ async function convertToAnthropicPrompt({
|
|
|
3605
3603
|
tool_use_id: part.toolCallId,
|
|
3606
3604
|
content: {
|
|
3607
3605
|
type: "web_fetch_tool_result_error",
|
|
3608
|
-
error_code:
|
|
3606
|
+
error_code: extractErrorValue(output.value).errorCode ?? "unavailable"
|
|
3609
3607
|
},
|
|
3610
3608
|
...caller && { caller },
|
|
3611
3609
|
cache_control: cacheControl
|
|
@@ -3654,7 +3652,7 @@ async function convertToAnthropicPrompt({
|
|
|
3654
3652
|
tool_use_id: part.toolCallId,
|
|
3655
3653
|
content: {
|
|
3656
3654
|
type: "web_search_tool_result_error",
|
|
3657
|
-
error_code:
|
|
3655
|
+
error_code: extractErrorValue(output.value).errorCode ?? "unavailable"
|
|
3658
3656
|
},
|
|
3659
3657
|
...caller && { caller },
|
|
3660
3658
|
cache_control: cacheControl
|
|
@@ -3802,7 +3800,7 @@ function groupIntoBlocks(prompt) {
|
|
|
3802
3800
|
const { role } = message;
|
|
3803
3801
|
switch (role) {
|
|
3804
3802
|
case "system": {
|
|
3805
|
-
if (
|
|
3803
|
+
if (currentBlock?.type !== "system") {
|
|
3806
3804
|
currentBlock = { type: "system", messages: [] };
|
|
3807
3805
|
blocks.push(currentBlock);
|
|
3808
3806
|
}
|
|
@@ -3810,7 +3808,7 @@ function groupIntoBlocks(prompt) {
|
|
|
3810
3808
|
break;
|
|
3811
3809
|
}
|
|
3812
3810
|
case "assistant": {
|
|
3813
|
-
if (
|
|
3811
|
+
if (currentBlock?.type !== "assistant") {
|
|
3814
3812
|
currentBlock = { type: "assistant", messages: [] };
|
|
3815
3813
|
blocks.push(currentBlock);
|
|
3816
3814
|
}
|
|
@@ -3818,7 +3816,7 @@ function groupIntoBlocks(prompt) {
|
|
|
3818
3816
|
break;
|
|
3819
3817
|
}
|
|
3820
3818
|
case "user": {
|
|
3821
|
-
if (
|
|
3819
|
+
if (currentBlock?.type !== "user") {
|
|
3822
3820
|
currentBlock = { type: "user", messages: [] };
|
|
3823
3821
|
blocks.push(currentBlock);
|
|
3824
3822
|
}
|
|
@@ -3826,7 +3824,7 @@ function groupIntoBlocks(prompt) {
|
|
|
3826
3824
|
break;
|
|
3827
3825
|
}
|
|
3828
3826
|
case "tool": {
|
|
3829
|
-
if (
|
|
3827
|
+
if (currentBlock?.type !== "user") {
|
|
3830
3828
|
currentBlock = { type: "user", messages: [] };
|
|
3831
3829
|
blocks.push(currentBlock);
|
|
3832
3830
|
}
|
|
@@ -3867,24 +3865,22 @@ function getAnthropicToolsetName({
|
|
|
3867
3865
|
providerOptions,
|
|
3868
3866
|
toolsetNames
|
|
3869
3867
|
}) {
|
|
3870
|
-
var _a;
|
|
3871
3868
|
const fromTools = toolsetNames[toolName];
|
|
3872
3869
|
if (fromTools != null) {
|
|
3873
3870
|
return fromTools;
|
|
3874
3871
|
}
|
|
3875
|
-
const fromMetadata =
|
|
3872
|
+
const fromMetadata = providerOptions?.anthropic?.toolsetName;
|
|
3876
3873
|
return typeof fromMetadata === "string" ? fromMetadata : void 0;
|
|
3877
3874
|
}
|
|
3878
3875
|
function getAnthropicCaller(providerOptions) {
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
if (((caller == null ? void 0 : caller.type) === "code_execution_20250825" || (caller == null ? void 0 : caller.type) === "code_execution_20260120") && caller.toolId) {
|
|
3876
|
+
const caller = providerOptions?.anthropic?.caller;
|
|
3877
|
+
if ((caller?.type === "code_execution_20250825" || caller?.type === "code_execution_20260120") && caller.toolId) {
|
|
3882
3878
|
return {
|
|
3883
3879
|
type: caller.type,
|
|
3884
3880
|
tool_id: caller.toolId
|
|
3885
3881
|
};
|
|
3886
3882
|
}
|
|
3887
|
-
return
|
|
3883
|
+
return caller?.type === "direct" ? { type: "direct" } : void 0;
|
|
3888
3884
|
}
|
|
3889
3885
|
function toAnthropicToolInput(input) {
|
|
3890
3886
|
return typeof input === "object" && input !== null && !Array.isArray(input) ? input : { rawInvalidInput: input };
|
|
@@ -4060,14 +4056,13 @@ function formatConstraintValue(value) {
|
|
|
4060
4056
|
|
|
4061
4057
|
// src/anthropic-language-model.ts
|
|
4062
4058
|
function createAnthropicStreamError(error) {
|
|
4063
|
-
var _a, _b, _c;
|
|
4064
4059
|
const inferredMetadata = getAnthropicStreamErrorMetadata(error.type);
|
|
4065
4060
|
return createProviderStreamError({
|
|
4066
4061
|
message: error.message,
|
|
4067
4062
|
type: error.type,
|
|
4068
|
-
code:
|
|
4069
|
-
statusCode:
|
|
4070
|
-
isRetryable:
|
|
4063
|
+
code: error.code ?? void 0,
|
|
4064
|
+
statusCode: error.statusCode ?? inferredMetadata.statusCode,
|
|
4065
|
+
isRetryable: error.isRetryable ?? inferredMetadata.isRetryable,
|
|
4071
4066
|
data: "data" in error ? error.data : error
|
|
4072
4067
|
});
|
|
4073
4068
|
}
|
|
@@ -4095,14 +4090,13 @@ function getAnthropicStreamErrorMetadata(type) {
|
|
|
4095
4090
|
}
|
|
4096
4091
|
}
|
|
4097
4092
|
function createCitationSource(citation, citationDocuments, generateId2) {
|
|
4098
|
-
var _a, _b;
|
|
4099
4093
|
if (citation.type === "web_search_result_location") {
|
|
4100
4094
|
return {
|
|
4101
4095
|
type: "source",
|
|
4102
4096
|
sourceType: "url",
|
|
4103
4097
|
id: generateId2(),
|
|
4104
4098
|
url: citation.url,
|
|
4105
|
-
title:
|
|
4099
|
+
title: citation.title ?? void 0,
|
|
4106
4100
|
providerMetadata: {
|
|
4107
4101
|
anthropic: {
|
|
4108
4102
|
citedText: citation.cited_text,
|
|
@@ -4123,7 +4117,7 @@ function createCitationSource(citation, citationDocuments, generateId2) {
|
|
|
4123
4117
|
sourceType: "document",
|
|
4124
4118
|
id: generateId2(),
|
|
4125
4119
|
mediaType: documentInfo.mediaType,
|
|
4126
|
-
title:
|
|
4120
|
+
title: citation.document_title ?? documentInfo.title,
|
|
4127
4121
|
filename: documentInfo.filename,
|
|
4128
4122
|
providerMetadata: {
|
|
4129
4123
|
anthropic: citation.type === "page_location" ? {
|
|
@@ -4150,7 +4144,7 @@ function getAnthropicCallerMetadata(caller) {
|
|
|
4150
4144
|
}
|
|
4151
4145
|
function getAnthropicToolsetNames(tools) {
|
|
4152
4146
|
const toolsetNames = {};
|
|
4153
|
-
for (const tool of tools
|
|
4147
|
+
for (const tool of tools ?? []) {
|
|
4154
4148
|
if (tool.type === "provider" && tool.id === "anthropic.computer_toolset_20260801") {
|
|
4155
4149
|
toolsetNames[tool.name] = "computer";
|
|
4156
4150
|
}
|
|
@@ -4173,10 +4167,9 @@ function getProviderOptionsName(provider) {
|
|
|
4173
4167
|
var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
4174
4168
|
constructor(modelId, config) {
|
|
4175
4169
|
this.specificationVersion = "v4";
|
|
4176
|
-
var _a;
|
|
4177
4170
|
this.modelId = modelId;
|
|
4178
4171
|
this.config = config;
|
|
4179
|
-
this.generateId =
|
|
4172
|
+
this.generateId = config.generateId ?? generateId;
|
|
4180
4173
|
}
|
|
4181
4174
|
static [WORKFLOW_SERIALIZE](model) {
|
|
4182
4175
|
return serializeModelOptions({
|
|
@@ -4194,8 +4187,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4194
4187
|
return this.config.provider;
|
|
4195
4188
|
}
|
|
4196
4189
|
get supportedUrls() {
|
|
4197
|
-
|
|
4198
|
-
return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
|
4190
|
+
return this.config.supportedUrls?.() ?? {};
|
|
4199
4191
|
}
|
|
4200
4192
|
static async prepareRequest({
|
|
4201
4193
|
modelId,
|
|
@@ -4219,7 +4211,6 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4219
4211
|
stream
|
|
4220
4212
|
}
|
|
4221
4213
|
}) {
|
|
4222
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
4223
4214
|
const warnings = [];
|
|
4224
4215
|
if (frequencyPenalty != null) {
|
|
4225
4216
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -4245,7 +4236,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4245
4236
|
});
|
|
4246
4237
|
temperature = 0;
|
|
4247
4238
|
}
|
|
4248
|
-
if (
|
|
4239
|
+
if (responseFormat?.type === "json") {
|
|
4249
4240
|
if (responseFormat.schema == null) {
|
|
4250
4241
|
warnings.push({
|
|
4251
4242
|
type: "unsupported",
|
|
@@ -4268,8 +4259,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4268
4259
|
const usedCustomProviderKey = customProviderOptions != null;
|
|
4269
4260
|
const anthropicOptions = Object.assign(
|
|
4270
4261
|
{},
|
|
4271
|
-
canonicalOptions
|
|
4272
|
-
customProviderOptions
|
|
4262
|
+
canonicalOptions ?? {},
|
|
4263
|
+
customProviderOptions ?? {}
|
|
4273
4264
|
);
|
|
4274
4265
|
const {
|
|
4275
4266
|
maxOutputTokens: maxOutputTokensForModel,
|
|
@@ -4316,11 +4307,11 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4316
4307
|
}
|
|
4317
4308
|
}
|
|
4318
4309
|
const isAnthropicModel = isKnownModel || modelId.includes("claude-");
|
|
4319
|
-
const supportsStructuredOutput = (
|
|
4320
|
-
const supportsStrictTools = (
|
|
4321
|
-
const structureOutputMode =
|
|
4310
|
+
const supportsStructuredOutput = (config.supportsNativeStructuredOutput ?? true) && modelSupportsStructuredOutput;
|
|
4311
|
+
const supportsStrictTools = (config.supportsStrictTools ?? true) && modelSupportsStructuredOutput;
|
|
4312
|
+
const structureOutputMode = anthropicOptions?.structuredOutputMode ?? "auto";
|
|
4322
4313
|
let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
4323
|
-
if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput &&
|
|
4314
|
+
if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && responseFormat?.type === "json" && responseFormat.schema != null) {
|
|
4324
4315
|
warnings.push({
|
|
4325
4316
|
type: "unsupported",
|
|
4326
4317
|
feature: "providerOptions.anthropic.structuredOutputMode",
|
|
@@ -4328,21 +4319,21 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4328
4319
|
});
|
|
4329
4320
|
useStructuredOutput = true;
|
|
4330
4321
|
}
|
|
4331
|
-
const jsonResponseTool =
|
|
4322
|
+
const jsonResponseTool = responseFormat?.type === "json" && responseFormat.schema != null && !useStructuredOutput ? {
|
|
4332
4323
|
type: "function",
|
|
4333
4324
|
name: "json",
|
|
4334
4325
|
description: "Respond with a JSON object.",
|
|
4335
4326
|
inputSchema: responseFormat.schema
|
|
4336
4327
|
} : void 0;
|
|
4337
|
-
if (jsonResponseTool != null &&
|
|
4328
|
+
if (jsonResponseTool != null && anthropicOptions?.disableParallelToolUse === false) {
|
|
4338
4329
|
warnings.push({
|
|
4339
4330
|
type: "unsupported",
|
|
4340
4331
|
feature: "providerOptions.anthropic.disableParallelToolUse",
|
|
4341
4332
|
details: "`disableParallelToolUse: false` is ignored when using the JSON response tool. Parallel tool use is disabled to ensure a single coherent JSON tool call."
|
|
4342
4333
|
});
|
|
4343
4334
|
}
|
|
4344
|
-
const contextManagement = anthropicOptions
|
|
4345
|
-
const compaction = anthropicOptions
|
|
4335
|
+
const contextManagement = anthropicOptions?.contextManagement;
|
|
4336
|
+
const compaction = anthropicOptions?.compaction;
|
|
4346
4337
|
if (contextManagement != null && compaction != null) {
|
|
4347
4338
|
throw new InvalidArgumentError({
|
|
4348
4339
|
argument: "providerOptions",
|
|
@@ -4381,13 +4372,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4381
4372
|
const toolsetNames = getAnthropicToolsetNames(tools);
|
|
4382
4373
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicPrompt({
|
|
4383
4374
|
prompt,
|
|
4384
|
-
sendReasoning:
|
|
4375
|
+
sendReasoning: anthropicOptions?.sendReasoning ?? true,
|
|
4385
4376
|
warnings,
|
|
4386
4377
|
cacheControlValidator,
|
|
4387
4378
|
toolNameMapping,
|
|
4388
4379
|
toolsetNames
|
|
4389
4380
|
});
|
|
4390
|
-
if (isCustomReasoning(reasoning) &&
|
|
4381
|
+
if (isCustomReasoning(reasoning) && anthropicOptions?.effort == null) {
|
|
4391
4382
|
const reasoningConfig = resolveAnthropicReasoningConfig({
|
|
4392
4383
|
reasoning,
|
|
4393
4384
|
modelId,
|
|
@@ -4401,12 +4392,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4401
4392
|
if (anthropicOptions.thinking == null) {
|
|
4402
4393
|
anthropicOptions.thinking = reasoningConfig.thinking;
|
|
4403
4394
|
}
|
|
4404
|
-
if (reasoningConfig.effort != null &&
|
|
4395
|
+
if (reasoningConfig.effort != null && anthropicOptions.thinking?.type !== "disabled") {
|
|
4405
4396
|
anthropicOptions.effort = reasoningConfig.effort;
|
|
4406
4397
|
}
|
|
4407
4398
|
}
|
|
4408
4399
|
}
|
|
4409
|
-
if (rejectsThinkingDisabled &&
|
|
4400
|
+
if (rejectsThinkingDisabled && anthropicOptions?.thinking != null) {
|
|
4410
4401
|
const thinking = anthropicOptions.thinking;
|
|
4411
4402
|
if (thinking.type === "disabled") {
|
|
4412
4403
|
warnings.push({
|
|
@@ -4424,7 +4415,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4424
4415
|
anthropicOptions.thinking = { type: "adaptive" };
|
|
4425
4416
|
}
|
|
4426
4417
|
}
|
|
4427
|
-
if (rejectsThinkingDisabledAboveHighEffort &&
|
|
4418
|
+
if (rejectsThinkingDisabledAboveHighEffort && anthropicOptions?.thinking?.type === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
|
|
4428
4419
|
warnings.push({
|
|
4429
4420
|
type: "unsupported",
|
|
4430
4421
|
feature: "providerOptions.anthropic.effort",
|
|
@@ -4432,13 +4423,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4432
4423
|
});
|
|
4433
4424
|
anthropicOptions.effort = "high";
|
|
4434
4425
|
}
|
|
4435
|
-
const thinkingType =
|
|
4426
|
+
const thinkingType = anthropicOptions?.thinking?.type;
|
|
4436
4427
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
4437
|
-
const thinkingBlockBinding =
|
|
4428
|
+
const thinkingBlockBinding = anthropicOptions?.thinking != null && "blockBinding" in anthropicOptions.thinking ? anthropicOptions.thinking.blockBinding : void 0;
|
|
4438
4429
|
const sendThinking = isThinking || thinkingType === "disabled" || thinkingBlockBinding != null;
|
|
4439
|
-
let thinkingBudget = thinkingType === "enabled" ?
|
|
4440
|
-
const thinkingDisplay = thinkingType === "adaptive" ?
|
|
4441
|
-
const maxTokens = maxOutputTokens
|
|
4430
|
+
let thinkingBudget = thinkingType === "enabled" ? anthropicOptions?.thinking?.budgetTokens : void 0;
|
|
4431
|
+
const thinkingDisplay = thinkingType === "adaptive" ? anthropicOptions?.thinking?.display : void 0;
|
|
4432
|
+
const maxTokens = maxOutputTokens ?? maxOutputTokensForModel;
|
|
4442
4433
|
const baseArgs = {
|
|
4443
4434
|
// model id:
|
|
4444
4435
|
model: modelId,
|
|
@@ -4461,12 +4452,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4461
4452
|
}
|
|
4462
4453
|
}
|
|
4463
4454
|
},
|
|
4464
|
-
...(
|
|
4455
|
+
...(anthropicOptions?.effort || anthropicOptions?.taskBudget || useStructuredOutput && responseFormat?.type === "json" && responseFormat.schema != null) && {
|
|
4465
4456
|
output_config: {
|
|
4466
|
-
...
|
|
4457
|
+
...anthropicOptions?.effort && {
|
|
4467
4458
|
effort: anthropicOptions.effort
|
|
4468
4459
|
},
|
|
4469
|
-
...
|
|
4460
|
+
...anthropicOptions?.taskBudget && {
|
|
4470
4461
|
task_budget: {
|
|
4471
4462
|
type: anthropicOptions.taskBudget.type,
|
|
4472
4463
|
total: anthropicOptions.taskBudget.total,
|
|
@@ -4475,7 +4466,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4475
4466
|
}
|
|
4476
4467
|
}
|
|
4477
4468
|
},
|
|
4478
|
-
...useStructuredOutput &&
|
|
4469
|
+
...useStructuredOutput && responseFormat?.type === "json" && responseFormat.schema != null && {
|
|
4479
4470
|
format: {
|
|
4480
4471
|
type: "json_schema",
|
|
4481
4472
|
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
@@ -4483,26 +4474,26 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4483
4474
|
}
|
|
4484
4475
|
}
|
|
4485
4476
|
},
|
|
4486
|
-
...
|
|
4477
|
+
...anthropicOptions?.speed && {
|
|
4487
4478
|
speed: anthropicOptions.speed
|
|
4488
4479
|
},
|
|
4489
|
-
...
|
|
4480
|
+
...anthropicOptions?.serviceTier && {
|
|
4490
4481
|
service_tier: anthropicOptions.serviceTier
|
|
4491
4482
|
},
|
|
4492
|
-
...
|
|
4483
|
+
...anthropicOptions?.inferenceGeo && {
|
|
4493
4484
|
inference_geo: anthropicOptions.inferenceGeo
|
|
4494
4485
|
},
|
|
4495
|
-
...
|
|
4486
|
+
...anthropicOptions?.fallbacks != null && (anthropicOptions.fallbacks === "default" || anthropicOptions.fallbacks.length > 0) && {
|
|
4496
4487
|
fallbacks: anthropicOptions.fallbacks
|
|
4497
4488
|
},
|
|
4498
|
-
...
|
|
4489
|
+
...anthropicOptions?.cacheControl && {
|
|
4499
4490
|
cache_control: anthropicOptions.cacheControl
|
|
4500
4491
|
},
|
|
4501
|
-
...
|
|
4492
|
+
...anthropicOptions?.metadata?.userId != null && {
|
|
4502
4493
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
4503
4494
|
},
|
|
4504
4495
|
// mcp servers:
|
|
4505
|
-
...
|
|
4496
|
+
...anthropicOptions?.mcpServers && anthropicOptions.mcpServers.length > 0 && {
|
|
4506
4497
|
mcp_servers: anthropicOptions.mcpServers.map((server) => ({
|
|
4507
4498
|
type: server.type,
|
|
4508
4499
|
name: server.name,
|
|
@@ -4515,7 +4506,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4515
4506
|
}))
|
|
4516
4507
|
},
|
|
4517
4508
|
// container: For programmatic tool calling (just an ID string) or agent skills (object with id and skills)
|
|
4518
|
-
...
|
|
4509
|
+
...anthropicOptions?.container && {
|
|
4519
4510
|
container: anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0 ? (
|
|
4520
4511
|
// Object format when skills are provided (agent skills feature)
|
|
4521
4512
|
{
|
|
@@ -4537,7 +4528,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4537
4528
|
// prompt:
|
|
4538
4529
|
system: messagesPrompt.system,
|
|
4539
4530
|
messages: messagesPrompt.messages,
|
|
4540
|
-
...
|
|
4531
|
+
...anthropicOptions?.safeguards && anthropicOptions.safeguards.length > 0 && {
|
|
4541
4532
|
safeguards: anthropicOptions.safeguards.map((safeguard) => ({
|
|
4542
4533
|
type: safeguard.type,
|
|
4543
4534
|
...safeguard.classifierContext !== void 0 && {
|
|
@@ -4641,7 +4632,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4641
4632
|
details: "topP is not supported when thinking is enabled"
|
|
4642
4633
|
});
|
|
4643
4634
|
}
|
|
4644
|
-
baseArgs.max_tokens = maxTokens + (thinkingBudget
|
|
4635
|
+
baseArgs.max_tokens = maxTokens + (thinkingBudget ?? 0);
|
|
4645
4636
|
} else {
|
|
4646
4637
|
if (isAnthropicModel && topP != null && temperature != null) {
|
|
4647
4638
|
warnings.push({
|
|
@@ -4662,10 +4653,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4662
4653
|
}
|
|
4663
4654
|
baseArgs.max_tokens = maxOutputTokensForModel;
|
|
4664
4655
|
}
|
|
4665
|
-
if (
|
|
4656
|
+
if (anthropicOptions?.mcpServers && anthropicOptions.mcpServers.length > 0) {
|
|
4666
4657
|
betas.add("mcp-client-2025-04-04");
|
|
4667
4658
|
}
|
|
4668
|
-
if (
|
|
4659
|
+
if (anthropicOptions?.safeguards && anthropicOptions.safeguards.length > 0) {
|
|
4669
4660
|
betas.add("dangerous-tool-use-2026-09-03");
|
|
4670
4661
|
}
|
|
4671
4662
|
if (compaction) {
|
|
@@ -4677,23 +4668,23 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4677
4668
|
betas.add("compact-2026-01-12");
|
|
4678
4669
|
}
|
|
4679
4670
|
}
|
|
4680
|
-
if (
|
|
4671
|
+
if (anthropicOptions?.container && anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0) {
|
|
4681
4672
|
betas.add("code-execution-2025-08-25");
|
|
4682
4673
|
betas.add("skills-2025-10-02");
|
|
4683
4674
|
betas.add("files-api-2025-04-14");
|
|
4684
|
-
if (!
|
|
4675
|
+
if (!tools?.some(
|
|
4685
4676
|
(tool) => tool.type === "provider" && (tool.id === "anthropic.code_execution_20250825" || tool.id === "anthropic.code_execution_20260120")
|
|
4686
|
-
))
|
|
4677
|
+
)) {
|
|
4687
4678
|
warnings.push({
|
|
4688
4679
|
type: "other",
|
|
4689
4680
|
message: "code execution tool is required when using skills"
|
|
4690
4681
|
});
|
|
4691
4682
|
}
|
|
4692
4683
|
}
|
|
4693
|
-
if (anthropicOptions
|
|
4684
|
+
if (anthropicOptions?.taskBudget) {
|
|
4694
4685
|
betas.add("task-budgets-2026-03-13");
|
|
4695
4686
|
}
|
|
4696
|
-
if (
|
|
4687
|
+
if (anthropicOptions?.speed === "fast") {
|
|
4697
4688
|
betas.add("fast-mode-2026-02-01");
|
|
4698
4689
|
}
|
|
4699
4690
|
if (thinkingDisplay === "updates") {
|
|
@@ -4702,12 +4693,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4702
4693
|
if (thinkingBlockBinding != null) {
|
|
4703
4694
|
betas.add("thinking-binding-controls-2026-08-01");
|
|
4704
4695
|
}
|
|
4705
|
-
if (
|
|
4696
|
+
if (anthropicOptions?.fallbacks === "default") {
|
|
4706
4697
|
betas.add("server-side-fallback-2026-07-01");
|
|
4707
|
-
} else if (
|
|
4698
|
+
} else if (anthropicOptions?.fallbacks && anthropicOptions.fallbacks.length > 0) {
|
|
4708
4699
|
betas.add("server-side-fallback-2026-06-01");
|
|
4709
4700
|
}
|
|
4710
|
-
const defaultEagerInputStreaming = stream && (
|
|
4701
|
+
const defaultEagerInputStreaming = stream && (anthropicOptions?.toolStreaming ?? true);
|
|
4711
4702
|
const {
|
|
4712
4703
|
tools: anthropicTools2,
|
|
4713
4704
|
toolChoice: anthropicToolChoice,
|
|
@@ -4715,7 +4706,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4715
4706
|
betas: toolsBetas
|
|
4716
4707
|
} = await prepareTools(
|
|
4717
4708
|
jsonResponseTool != null ? {
|
|
4718
|
-
tools: [...tools
|
|
4709
|
+
tools: [...tools ?? [], jsonResponseTool],
|
|
4719
4710
|
toolChoice: { type: "required" },
|
|
4720
4711
|
disableParallelToolUse: true,
|
|
4721
4712
|
cacheControlValidator,
|
|
@@ -4724,9 +4715,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4724
4715
|
defaultEagerInputStreaming,
|
|
4725
4716
|
rejectsForcedToolUse
|
|
4726
4717
|
} : {
|
|
4727
|
-
tools: tools
|
|
4718
|
+
tools: tools ?? [],
|
|
4728
4719
|
toolChoice,
|
|
4729
|
-
disableParallelToolUse: anthropicOptions
|
|
4720
|
+
disableParallelToolUse: anthropicOptions?.disableParallelToolUse,
|
|
4730
4721
|
cacheControlValidator,
|
|
4731
4722
|
supportsStructuredOutput,
|
|
4732
4723
|
supportsStrictTools,
|
|
@@ -4748,7 +4739,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4748
4739
|
...betas,
|
|
4749
4740
|
...toolsBetas,
|
|
4750
4741
|
...userSuppliedBetas,
|
|
4751
|
-
...
|
|
4742
|
+
...anthropicOptions?.anthropicBeta ?? []
|
|
4752
4743
|
]),
|
|
4753
4744
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
4754
4745
|
toolNameMapping,
|
|
@@ -4774,10 +4765,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4774
4765
|
);
|
|
4775
4766
|
}
|
|
4776
4767
|
async getBetasFromHeaders(requestHeaders) {
|
|
4777
|
-
var _a, _b;
|
|
4778
4768
|
const configHeaders = this.config.headers ? await resolve(this.config.headers) : void 0;
|
|
4779
|
-
const configBetaHeader =
|
|
4780
|
-
const requestBetaHeader =
|
|
4769
|
+
const configBetaHeader = configHeaders?.["anthropic-beta"] ?? "";
|
|
4770
|
+
const requestBetaHeader = requestHeaders?.["anthropic-beta"] ?? "";
|
|
4781
4771
|
return new Set(
|
|
4782
4772
|
[
|
|
4783
4773
|
...configBetaHeader.toLowerCase().split(","),
|
|
@@ -4786,38 +4776,33 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4786
4776
|
);
|
|
4787
4777
|
}
|
|
4788
4778
|
buildRequestUrl(isStreaming) {
|
|
4789
|
-
|
|
4790
|
-
return (_c = (_b = (_a = this.config).buildRequestUrl) == null ? void 0 : _b.call(_a, this.config.baseURL, isStreaming)) != null ? _c : `${this.config.baseURL}/messages`;
|
|
4779
|
+
return this.config.buildRequestUrl?.(this.config.baseURL, isStreaming) ?? `${this.config.baseURL}/messages`;
|
|
4791
4780
|
}
|
|
4792
4781
|
transformRequestBody(args, betas) {
|
|
4793
|
-
|
|
4794
|
-
return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args, betas)) != null ? _c : args;
|
|
4782
|
+
return this.config.transformRequestBody?.(args, betas) ?? args;
|
|
4795
4783
|
}
|
|
4796
4784
|
extractCitationDocuments(prompt) {
|
|
4797
4785
|
const isCitationPart = (part) => {
|
|
4798
|
-
var _a, _b;
|
|
4799
4786
|
if (part.type !== "file") {
|
|
4800
4787
|
return false;
|
|
4801
4788
|
}
|
|
4802
4789
|
if (part.mediaType !== "application/pdf" && part.mediaType !== "text/plain") {
|
|
4803
4790
|
return false;
|
|
4804
4791
|
}
|
|
4805
|
-
const anthropic =
|
|
4806
|
-
const citationsConfig = anthropic
|
|
4807
|
-
return
|
|
4792
|
+
const anthropic = part.providerOptions?.anthropic;
|
|
4793
|
+
const citationsConfig = anthropic?.citations;
|
|
4794
|
+
return citationsConfig?.enabled ?? false;
|
|
4808
4795
|
};
|
|
4809
4796
|
return prompt.filter((message) => message.role === "user").flatMap((message) => message.content).filter(isCitationPart).map((part) => {
|
|
4810
|
-
var _a;
|
|
4811
4797
|
const filePart = part;
|
|
4812
4798
|
return {
|
|
4813
|
-
title:
|
|
4799
|
+
title: filePart.filename ?? "Untitled Document",
|
|
4814
4800
|
filename: filePart.filename,
|
|
4815
4801
|
mediaType: filePart.mediaType
|
|
4816
4802
|
};
|
|
4817
4803
|
});
|
|
4818
4804
|
}
|
|
4819
4805
|
async doGenerate(options) {
|
|
4820
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
4821
4806
|
const {
|
|
4822
4807
|
args,
|
|
4823
4808
|
warnings,
|
|
@@ -4858,7 +4843,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4858
4843
|
switch (part.type) {
|
|
4859
4844
|
case "text": {
|
|
4860
4845
|
if (!usesJsonResponseTool) {
|
|
4861
|
-
const webSearchCitations =
|
|
4846
|
+
const webSearchCitations = part.citations?.filter(
|
|
4862
4847
|
(citation) => citation.type === "web_search_result_location"
|
|
4863
4848
|
);
|
|
4864
4849
|
content.push({
|
|
@@ -4959,7 +4944,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4959
4944
|
providerMetadata: {
|
|
4960
4945
|
anthropic: {
|
|
4961
4946
|
toolsetName: part.toolset_name,
|
|
4962
|
-
...
|
|
4947
|
+
...getAnthropicCallerMetadata(part.caller).providerMetadata?.anthropic
|
|
4963
4948
|
}
|
|
4964
4949
|
}
|
|
4965
4950
|
});
|
|
@@ -5060,7 +5045,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5060
5045
|
case "web_fetch_tool_result": {
|
|
5061
5046
|
if (part.content.type === "web_fetch_result") {
|
|
5062
5047
|
citationDocuments.push({
|
|
5063
|
-
title:
|
|
5048
|
+
title: part.content.content.title ?? part.content.url,
|
|
5064
5049
|
mediaType: part.content.content.source.media_type
|
|
5065
5050
|
});
|
|
5066
5051
|
content.push({
|
|
@@ -5105,16 +5090,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5105
5090
|
type: "tool-result",
|
|
5106
5091
|
toolCallId: part.tool_use_id,
|
|
5107
5092
|
toolName: toolNameMapping.toCustomToolName("web_search"),
|
|
5108
|
-
result: part.content.map((result) => {
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
type: result.type
|
|
5116
|
-
};
|
|
5117
|
-
}),
|
|
5093
|
+
result: part.content.map((result) => ({
|
|
5094
|
+
url: result.url,
|
|
5095
|
+
...result.title != null ? { title: result.title } : {},
|
|
5096
|
+
pageAge: result.page_age ?? null,
|
|
5097
|
+
encryptedContent: result.encrypted_content,
|
|
5098
|
+
type: result.type
|
|
5099
|
+
})),
|
|
5118
5100
|
...getAnthropicCallerMetadata(part.caller)
|
|
5119
5101
|
});
|
|
5120
5102
|
for (const result of part.content) {
|
|
@@ -5126,7 +5108,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5126
5108
|
...result.title != null ? { title: result.title } : {},
|
|
5127
5109
|
providerMetadata: {
|
|
5128
5110
|
anthropic: {
|
|
5129
|
-
pageAge:
|
|
5111
|
+
pageAge: result.page_age ?? null
|
|
5130
5112
|
}
|
|
5131
5113
|
}
|
|
5132
5114
|
});
|
|
@@ -5158,7 +5140,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5158
5140
|
stdout: part.content.stdout,
|
|
5159
5141
|
stderr: part.content.stderr,
|
|
5160
5142
|
return_code: part.content.return_code,
|
|
5161
|
-
content:
|
|
5143
|
+
content: part.content.content ?? []
|
|
5162
5144
|
}
|
|
5163
5145
|
});
|
|
5164
5146
|
} else if (part.content.type === "encrypted_code_execution_result") {
|
|
@@ -5171,7 +5153,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5171
5153
|
encrypted_stdout: part.content.encrypted_stdout,
|
|
5172
5154
|
stderr: part.content.stderr,
|
|
5173
5155
|
return_code: part.content.return_code,
|
|
5174
|
-
content:
|
|
5156
|
+
content: part.content.content ?? []
|
|
5175
5157
|
}
|
|
5176
5158
|
});
|
|
5177
5159
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -5299,23 +5281,22 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5299
5281
|
finishReason: response.stop_reason,
|
|
5300
5282
|
isJsonResponseFromTool
|
|
5301
5283
|
}),
|
|
5302
|
-
raw:
|
|
5284
|
+
raw: response.stop_reason ?? void 0
|
|
5303
5285
|
},
|
|
5304
5286
|
usage: convertAnthropicUsage({ usage: response.usage }),
|
|
5305
5287
|
request: { body: args },
|
|
5306
5288
|
response: {
|
|
5307
|
-
id:
|
|
5308
|
-
modelId:
|
|
5289
|
+
id: response.id ?? void 0,
|
|
5290
|
+
modelId: response.model ?? void 0,
|
|
5309
5291
|
headers: responseHeaders,
|
|
5310
5292
|
body: rawResponse
|
|
5311
5293
|
},
|
|
5312
5294
|
warnings,
|
|
5313
5295
|
providerMetadata: (() => {
|
|
5314
|
-
var _a2, _b2, _c2, _d2;
|
|
5315
5296
|
const stopDetails = mapAnthropicStopDetails(response.stop_details);
|
|
5316
5297
|
const anthropicMetadata = {
|
|
5317
5298
|
usage: response.usage,
|
|
5318
|
-
stopSequence:
|
|
5299
|
+
stopSequence: response.stop_sequence ?? null,
|
|
5319
5300
|
...stopDetails != null ? { stopDetails } : {},
|
|
5320
5301
|
...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
|
|
5321
5302
|
...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
|
|
@@ -5336,15 +5317,15 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5336
5317
|
container: response.container ? {
|
|
5337
5318
|
expiresAt: response.container.expires_at,
|
|
5338
5319
|
id: response.container.id,
|
|
5339
|
-
skills:
|
|
5320
|
+
skills: response.container.skills?.map((skill) => ({
|
|
5340
5321
|
type: skill.type,
|
|
5341
5322
|
skillId: skill.skill_id,
|
|
5342
5323
|
version: skill.version
|
|
5343
|
-
}))
|
|
5324
|
+
})) ?? null
|
|
5344
5325
|
} : null,
|
|
5345
|
-
contextManagement:
|
|
5326
|
+
contextManagement: mapAnthropicResponseContextManagement(
|
|
5346
5327
|
response.context_management
|
|
5347
|
-
)
|
|
5328
|
+
) ?? null
|
|
5348
5329
|
};
|
|
5349
5330
|
const providerMetadata = {
|
|
5350
5331
|
anthropic: anthropicMetadata
|
|
@@ -5358,7 +5339,6 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5358
5339
|
}
|
|
5359
5340
|
async doStream(options) {
|
|
5360
5341
|
"use step";
|
|
5361
|
-
var _a, _b, _c, _d;
|
|
5362
5342
|
const {
|
|
5363
5343
|
args: body,
|
|
5364
5344
|
warnings,
|
|
@@ -5419,7 +5399,6 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5419
5399
|
controller.enqueue({ type: "stream-start", warnings });
|
|
5420
5400
|
},
|
|
5421
5401
|
transform(chunk, controller) {
|
|
5422
|
-
var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
5423
5402
|
if (hasInvalidMessageSequence) {
|
|
5424
5403
|
return;
|
|
5425
5404
|
}
|
|
@@ -5647,7 +5626,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5647
5626
|
case "web_fetch_tool_result": {
|
|
5648
5627
|
if (part.content.type === "web_fetch_result") {
|
|
5649
5628
|
citationDocuments.push({
|
|
5650
|
-
title:
|
|
5629
|
+
title: part.content.content.title ?? part.content.url,
|
|
5651
5630
|
mediaType: part.content.content.source.media_type
|
|
5652
5631
|
});
|
|
5653
5632
|
controller.enqueue({
|
|
@@ -5692,16 +5671,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5692
5671
|
type: "tool-result",
|
|
5693
5672
|
toolCallId: part.tool_use_id,
|
|
5694
5673
|
toolName: toolNameMapping.toCustomToolName("web_search"),
|
|
5695
|
-
result: part.content.map((result) => {
|
|
5696
|
-
|
|
5697
|
-
|
|
5698
|
-
|
|
5699
|
-
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
type: result.type
|
|
5703
|
-
};
|
|
5704
|
-
}),
|
|
5674
|
+
result: part.content.map((result) => ({
|
|
5675
|
+
url: result.url,
|
|
5676
|
+
...result.title != null ? { title: result.title } : {},
|
|
5677
|
+
pageAge: result.page_age ?? null,
|
|
5678
|
+
encryptedContent: result.encrypted_content,
|
|
5679
|
+
type: result.type
|
|
5680
|
+
})),
|
|
5705
5681
|
...getAnthropicCallerMetadata(part.caller)
|
|
5706
5682
|
});
|
|
5707
5683
|
for (const result of part.content) {
|
|
@@ -5713,7 +5689,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5713
5689
|
...result.title != null ? { title: result.title } : {},
|
|
5714
5690
|
providerMetadata: {
|
|
5715
5691
|
anthropic: {
|
|
5716
|
-
pageAge:
|
|
5692
|
+
pageAge: result.page_age ?? null
|
|
5717
5693
|
}
|
|
5718
5694
|
}
|
|
5719
5695
|
});
|
|
@@ -5745,7 +5721,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5745
5721
|
stdout: part.content.stdout,
|
|
5746
5722
|
stderr: part.content.stderr,
|
|
5747
5723
|
return_code: part.content.return_code,
|
|
5748
|
-
content:
|
|
5724
|
+
content: part.content.content ?? []
|
|
5749
5725
|
}
|
|
5750
5726
|
});
|
|
5751
5727
|
} else if (part.content.type === "encrypted_code_execution_result") {
|
|
@@ -5758,7 +5734,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5758
5734
|
encrypted_stdout: part.content.encrypted_stdout,
|
|
5759
5735
|
stderr: part.content.stderr,
|
|
5760
5736
|
return_code: part.content.return_code,
|
|
5761
|
-
content:
|
|
5737
|
+
content: part.content.content ?? []
|
|
5762
5738
|
}
|
|
5763
5739
|
});
|
|
5764
5740
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -5942,7 +5918,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5942
5918
|
let memberInput = {};
|
|
5943
5919
|
try {
|
|
5944
5920
|
memberInput = contentBlock.input === "" ? {} : secureJsonParse2(contentBlock.input);
|
|
5945
|
-
} catch
|
|
5921
|
+
} catch {
|
|
5946
5922
|
memberInput = void 0;
|
|
5947
5923
|
}
|
|
5948
5924
|
contentBlock.input = memberInput === void 0 ? contentBlock.input : JSON.stringify(
|
|
@@ -5971,7 +5947,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5971
5947
|
...parsed
|
|
5972
5948
|
});
|
|
5973
5949
|
}
|
|
5974
|
-
} catch
|
|
5950
|
+
} catch {
|
|
5975
5951
|
}
|
|
5976
5952
|
}
|
|
5977
5953
|
controller.enqueue({
|
|
@@ -6060,7 +6036,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6060
6036
|
return;
|
|
6061
6037
|
}
|
|
6062
6038
|
if (isJsonResponseFromTool) {
|
|
6063
|
-
if (
|
|
6039
|
+
if (contentBlock?.type !== "text") {
|
|
6064
6040
|
return;
|
|
6065
6041
|
}
|
|
6066
6042
|
controller.enqueue({
|
|
@@ -6069,7 +6045,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6069
6045
|
delta
|
|
6070
6046
|
});
|
|
6071
6047
|
} else {
|
|
6072
|
-
if (
|
|
6048
|
+
if (contentBlock?.type !== "tool-call") {
|
|
6073
6049
|
return;
|
|
6074
6050
|
}
|
|
6075
6051
|
if (contentBlock.toolset != null) {
|
|
@@ -6092,7 +6068,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6092
6068
|
case "citations_delta": {
|
|
6093
6069
|
const citation = value.delta.citation;
|
|
6094
6070
|
const contentBlock = contentBlocks[value.index];
|
|
6095
|
-
if (
|
|
6071
|
+
if (contentBlock?.type === "text" && citation.type === "web_search_result_location") {
|
|
6096
6072
|
contentBlock.citations.push(citation);
|
|
6097
6073
|
}
|
|
6098
6074
|
const source = createCitationSource(
|
|
@@ -6131,8 +6107,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6131
6107
|
isMessageOpen = true;
|
|
6132
6108
|
activeMessageId = value.message.id;
|
|
6133
6109
|
usage.input_tokens = value.message.usage.input_tokens;
|
|
6134
|
-
usage.cache_read_input_tokens =
|
|
6135
|
-
usage.cache_creation_input_tokens =
|
|
6110
|
+
usage.cache_read_input_tokens = value.message.usage.cache_read_input_tokens ?? 0;
|
|
6111
|
+
usage.cache_creation_input_tokens = value.message.usage.cache_creation_input_tokens ?? 0;
|
|
6136
6112
|
rawUsage = {
|
|
6137
6113
|
...value.message.usage
|
|
6138
6114
|
};
|
|
@@ -6157,8 +6133,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6157
6133
|
}
|
|
6158
6134
|
controller.enqueue({
|
|
6159
6135
|
type: "response-metadata",
|
|
6160
|
-
id:
|
|
6161
|
-
modelId:
|
|
6136
|
+
id: value.message.id ?? void 0,
|
|
6137
|
+
modelId: value.message.model ?? void 0
|
|
6162
6138
|
});
|
|
6163
6139
|
if (value.message.content != null) {
|
|
6164
6140
|
for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
|
|
@@ -6170,7 +6146,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6170
6146
|
id: part.id,
|
|
6171
6147
|
toolName: part.name
|
|
6172
6148
|
});
|
|
6173
|
-
const inputStr = JSON.stringify(
|
|
6149
|
+
const inputStr = JSON.stringify(part.input ?? {});
|
|
6174
6150
|
controller.enqueue({
|
|
6175
6151
|
type: "tool-input-delta",
|
|
6176
6152
|
id: part.id,
|
|
@@ -6220,18 +6196,18 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6220
6196
|
finishReason: value.delta.stop_reason,
|
|
6221
6197
|
isJsonResponseFromTool
|
|
6222
6198
|
}),
|
|
6223
|
-
raw:
|
|
6199
|
+
raw: value.delta.stop_reason ?? void 0
|
|
6224
6200
|
};
|
|
6225
|
-
stopSequence =
|
|
6201
|
+
stopSequence = value.delta.stop_sequence ?? null;
|
|
6226
6202
|
stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
|
|
6227
6203
|
container = value.delta.container != null ? {
|
|
6228
6204
|
expiresAt: value.delta.container.expires_at,
|
|
6229
6205
|
id: value.delta.container.id,
|
|
6230
|
-
skills:
|
|
6206
|
+
skills: value.delta.container.skills?.map((skill) => ({
|
|
6231
6207
|
type: skill.type,
|
|
6232
6208
|
skillId: skill.skill_id,
|
|
6233
6209
|
version: skill.version
|
|
6234
|
-
}))
|
|
6210
|
+
})) ?? null
|
|
6235
6211
|
} : null;
|
|
6236
6212
|
if (value.context_management) {
|
|
6237
6213
|
contextManagement = mapAnthropicResponseContextManagement(
|
|
@@ -6254,7 +6230,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6254
6230
|
isMessageOpen = false;
|
|
6255
6231
|
activeMessageId = void 0;
|
|
6256
6232
|
const anthropicMetadata = {
|
|
6257
|
-
usage: rawUsage
|
|
6233
|
+
usage: rawUsage ?? null,
|
|
6258
6234
|
stopSequence,
|
|
6259
6235
|
...stopDetails != null ? { stopDetails } : {},
|
|
6260
6236
|
...inputTransformations != null ? { inputTransformations } : {},
|
|
@@ -6310,10 +6286,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6310
6286
|
try {
|
|
6311
6287
|
await firstChunkReader.read();
|
|
6312
6288
|
let result = await firstChunkReader.read();
|
|
6313
|
-
if (
|
|
6289
|
+
if (result.value?.type === "raw") {
|
|
6314
6290
|
result = await firstChunkReader.read();
|
|
6315
6291
|
}
|
|
6316
|
-
if (
|
|
6292
|
+
if (result.value?.type === "error") {
|
|
6317
6293
|
const error = result.value.error;
|
|
6318
6294
|
if (!isProviderStreamError(error)) {
|
|
6319
6295
|
throw new Error("Expected a normalized Anthropic stream error");
|
|
@@ -6322,10 +6298,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
6322
6298
|
message: error.message,
|
|
6323
6299
|
url,
|
|
6324
6300
|
requestBodyValues: body,
|
|
6325
|
-
statusCode:
|
|
6301
|
+
statusCode: error.statusCode ?? 500,
|
|
6326
6302
|
responseHeaders,
|
|
6327
6303
|
responseBody: JSON.stringify(error.data),
|
|
6328
|
-
isRetryable:
|
|
6304
|
+
isRetryable: error.isRetryable ?? false
|
|
6329
6305
|
});
|
|
6330
6306
|
}
|
|
6331
6307
|
} finally {
|
|
@@ -7357,7 +7333,6 @@ var AnthropicSkills = class {
|
|
|
7357
7333
|
};
|
|
7358
7334
|
}
|
|
7359
7335
|
async uploadSkill(params) {
|
|
7360
|
-
var _a, _b;
|
|
7361
7336
|
const warnings = [];
|
|
7362
7337
|
const formData = new FormData();
|
|
7363
7338
|
if (params.displayTitle != null) {
|
|
@@ -7383,8 +7358,8 @@ var AnthropicSkills = class {
|
|
|
7383
7358
|
version: response.latest_version,
|
|
7384
7359
|
headers
|
|
7385
7360
|
}) : {};
|
|
7386
|
-
const name =
|
|
7387
|
-
const description =
|
|
7361
|
+
const name = versionMetadata.name ?? response.name;
|
|
7362
|
+
const description = versionMetadata.description ?? response.description;
|
|
7388
7363
|
return {
|
|
7389
7364
|
providerReference: { anthropic: response.id },
|
|
7390
7365
|
...response.display_title != null ? { displayTitle: response.display_title } : {},
|