@ai-sdk/anthropic 4.0.83 → 4.0.85
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 +21 -0
- package/dist/index.d.ts +138 -176
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +147 -134
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +43 -23
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +145 -132
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +48 -4
- package/package.json +4 -3
- package/src/anthropic-api.ts +152 -130
- package/src/anthropic-batch.ts +8 -7
- package/src/anthropic-language-model-options.ts +417 -398
- package/src/anthropic-language-model.ts +31 -8
- package/src/convert-to-anthropic-prompt.ts +24 -2
- package/src/get-cache-control.ts +15 -3
- package/src/skills/anthropic-skills.ts +1 -11
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APICallError, InvalidArgumentError, InvalidResponseDataError, NoSuchModelError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
|
|
2
|
-
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonLinesResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, experimental_toolCaller, generateId, getFromApi, getTopLevelMediaType, isCustomReasoning, isNonNullable, isProviderStreamError, isRecord, lazySchema, loadApiKey, loadOptionalSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, normalizeBatchRequestCounts, normalizeHeaders, parseProviderOptions, postFormDataToApi, postJsonToApi, resolve, resolveFullMediaType, resolveProviderReference, safeValidateTypes, secureJsonParse, serializeModelOptions, validateBaseURL, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
2
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonLinesResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, encodePathSegment, experimental_toolCaller, generateId, getFromApi, getTopLevelMediaType, isCustomReasoning, isNonNullable, isProviderStreamError, isRecord, lazySchema, loadApiKey, loadOptionalSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, normalizeBatchRequestCounts, normalizeHeaders, parseProviderOptions, postFormDataToApi, postJsonToApi, resolve, resolveFullMediaType, resolveProviderReference, safeValidateTypes, secureJsonParse, serializeModelOptions, validateBaseURL, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
3
3
|
import { Experimental_DecisionLanguageModel } from "@ai-sdk/provider-utils/experimental-decision";
|
|
4
4
|
import { z } from "zod/v4";
|
|
5
5
|
//#region src/anthropic-error.ts
|
|
@@ -96,18 +96,19 @@ function mapAnthropicCitation(citation, documents) {
|
|
|
96
96
|
}
|
|
97
97
|
//#endregion
|
|
98
98
|
//#region src/anthropic-api.ts
|
|
99
|
-
const anthropicFallbackContentSchema = z.object({
|
|
99
|
+
const anthropicFallbackContentSchema = () => z.object({
|
|
100
100
|
type: z.literal("fallback"),
|
|
101
101
|
from: z.object({ model: z.string() }),
|
|
102
102
|
to: z.object({ model: z.string() })
|
|
103
103
|
});
|
|
104
|
-
const
|
|
104
|
+
const anthropicFallbackContentSchemaValidator = lazySchema(() => zodSchema(anthropicFallbackContentSchema()));
|
|
105
|
+
const anthropicStopDetailsSchema = () => z.object({
|
|
105
106
|
type: z.string(),
|
|
106
107
|
category: z.string().nullish(),
|
|
107
108
|
explanation: z.string().nullish(),
|
|
108
109
|
recommended_model: z.string().nullish()
|
|
109
110
|
});
|
|
110
|
-
const anthropicSafeguardResultSchema = z.object({
|
|
111
|
+
const anthropicSafeguardResultSchema = () => z.object({
|
|
111
112
|
type: z.string(),
|
|
112
113
|
status: z.object({
|
|
113
114
|
type: z.string(),
|
|
@@ -118,7 +119,7 @@ const anthropicSafeguardResultSchema = z.object({
|
|
|
118
119
|
})).nullish()
|
|
119
120
|
})
|
|
120
121
|
});
|
|
121
|
-
const anthropicToolCallCallerSchema = z.union([
|
|
122
|
+
const anthropicToolCallCallerSchema = () => z.union([
|
|
122
123
|
z.object({
|
|
123
124
|
type: z.literal("code_execution_20250825"),
|
|
124
125
|
tool_id: z.string()
|
|
@@ -129,7 +130,7 @@ const anthropicToolCallCallerSchema = z.union([
|
|
|
129
130
|
}),
|
|
130
131
|
z.object({ type: z.literal("direct") })
|
|
131
132
|
]);
|
|
132
|
-
const anthropicCitationSchema = z.discriminatedUnion("type", [
|
|
133
|
+
const anthropicCitationSchema = () => z.discriminatedUnion("type", [
|
|
133
134
|
z.object({
|
|
134
135
|
type: z.literal("web_search_result_location"),
|
|
135
136
|
cited_text: z.string(),
|
|
@@ -174,12 +175,12 @@ const anthropicCitationSchema = z.discriminatedUnion("type", [
|
|
|
174
175
|
end_block_index: z.number()
|
|
175
176
|
})
|
|
176
177
|
]);
|
|
177
|
-
const anthropicMcpToolResultContentSchema = z.union([z.string(), z.array(z.union([z.string(), z.object({
|
|
178
|
+
const anthropicMcpToolResultContentSchema = () => z.union([z.string(), z.array(z.union([z.string(), z.object({
|
|
178
179
|
type: z.literal("text"),
|
|
179
180
|
text: z.string(),
|
|
180
181
|
citations: z.array(z.json()).nullable().optional()
|
|
181
182
|
})]))]);
|
|
182
|
-
const anthropicInputTransformationSchema = z.object({
|
|
183
|
+
const anthropicInputTransformationSchema = () => z.object({
|
|
183
184
|
type: z.string(),
|
|
184
185
|
path: z.string(),
|
|
185
186
|
reason: z.string()
|
|
@@ -192,7 +193,7 @@ const anthropicResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
192
193
|
z.object({
|
|
193
194
|
type: z.literal("text"),
|
|
194
195
|
text: z.string(),
|
|
195
|
-
citations: z.array(anthropicCitationSchema).nullable().optional()
|
|
196
|
+
citations: z.array(anthropicCitationSchema()).nullable().optional()
|
|
196
197
|
}),
|
|
197
198
|
z.object({
|
|
198
199
|
type: z.literal("thinking"),
|
|
@@ -213,7 +214,7 @@ const anthropicResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
213
214
|
id: z.string(),
|
|
214
215
|
name: z.string(),
|
|
215
216
|
input: z.unknown(),
|
|
216
|
-
caller: anthropicToolCallCallerSchema.optional(),
|
|
217
|
+
caller: anthropicToolCallCallerSchema().optional(),
|
|
217
218
|
toolset_name: z.string().nullish()
|
|
218
219
|
}),
|
|
219
220
|
z.object({
|
|
@@ -221,7 +222,7 @@ const anthropicResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
221
222
|
id: z.string(),
|
|
222
223
|
name: z.string(),
|
|
223
224
|
input: z.record(z.string(), z.unknown()).nullish(),
|
|
224
|
-
caller: anthropicToolCallCallerSchema.optional()
|
|
225
|
+
caller: anthropicToolCallCallerSchema().optional()
|
|
225
226
|
}),
|
|
226
227
|
z.object({
|
|
227
228
|
type: z.literal("mcp_tool_use"),
|
|
@@ -234,12 +235,12 @@ const anthropicResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
234
235
|
type: z.literal("mcp_tool_result"),
|
|
235
236
|
tool_use_id: z.string(),
|
|
236
237
|
is_error: z.boolean(),
|
|
237
|
-
content: anthropicMcpToolResultContentSchema
|
|
238
|
+
content: anthropicMcpToolResultContentSchema()
|
|
238
239
|
}),
|
|
239
240
|
z.object({
|
|
240
241
|
type: z.literal("web_fetch_tool_result"),
|
|
241
242
|
tool_use_id: z.string(),
|
|
242
|
-
caller: anthropicToolCallCallerSchema.optional(),
|
|
243
|
+
caller: anthropicToolCallCallerSchema().optional(),
|
|
243
244
|
content: z.union([z.object({
|
|
244
245
|
type: z.literal("web_fetch_result"),
|
|
245
246
|
url: z.string(),
|
|
@@ -266,7 +267,7 @@ const anthropicResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
266
267
|
z.object({
|
|
267
268
|
type: z.literal("web_search_tool_result"),
|
|
268
269
|
tool_use_id: z.string(),
|
|
269
|
-
caller: anthropicToolCallCallerSchema.optional(),
|
|
270
|
+
caller: anthropicToolCallCallerSchema().optional(),
|
|
270
271
|
content: z.union([z.array(z.object({
|
|
271
272
|
type: z.literal("web_search_result"),
|
|
272
273
|
url: z.string(),
|
|
@@ -393,13 +394,13 @@ const anthropicResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
393
394
|
})
|
|
394
395
|
])
|
|
395
396
|
}),
|
|
396
|
-
anthropicFallbackContentSchema
|
|
397
|
+
anthropicFallbackContentSchema()
|
|
397
398
|
])),
|
|
398
399
|
stop_reason: z.string().nullish(),
|
|
399
400
|
stop_sequence: z.string().nullish(),
|
|
400
|
-
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
401
|
-
input_transformations: z.array(anthropicInputTransformationSchema).nullish(),
|
|
402
|
-
safeguard_results: z.array(anthropicSafeguardResultSchema).nullish(),
|
|
401
|
+
stop_details: anthropicStopDetailsSchema().nullish(),
|
|
402
|
+
input_transformations: z.array(anthropicInputTransformationSchema()).nullish(),
|
|
403
|
+
safeguard_results: z.array(anthropicSafeguardResultSchema()).nullish(),
|
|
403
404
|
usage: z.looseObject({
|
|
404
405
|
input_tokens: z.number(),
|
|
405
406
|
output_tokens: z.number(),
|
|
@@ -460,11 +461,11 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
|
|
|
460
461
|
id: z.string(),
|
|
461
462
|
name: z.string(),
|
|
462
463
|
input: z.unknown(),
|
|
463
|
-
caller: anthropicToolCallCallerSchema.optional(),
|
|
464
|
+
caller: anthropicToolCallCallerSchema().optional(),
|
|
464
465
|
toolset_name: z.string().nullish()
|
|
465
466
|
})])).nullish(),
|
|
466
467
|
stop_reason: z.string().nullish(),
|
|
467
|
-
input_transformations: z.array(anthropicInputTransformationSchema).nullish(),
|
|
468
|
+
input_transformations: z.array(anthropicInputTransformationSchema()).nullish(),
|
|
468
469
|
container: z.object({
|
|
469
470
|
expires_at: z.string(),
|
|
470
471
|
id: z.string()
|
|
@@ -488,7 +489,7 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
|
|
|
488
489
|
id: z.string(),
|
|
489
490
|
name: z.string(),
|
|
490
491
|
input: z.record(z.string(), z.unknown()).optional(),
|
|
491
|
-
caller: anthropicToolCallCallerSchema.optional(),
|
|
492
|
+
caller: anthropicToolCallCallerSchema().optional(),
|
|
492
493
|
toolset_name: z.string().nullish()
|
|
493
494
|
}),
|
|
494
495
|
z.object({
|
|
@@ -505,7 +506,7 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
|
|
|
505
506
|
id: z.string(),
|
|
506
507
|
name: z.string(),
|
|
507
508
|
input: z.record(z.string(), z.unknown()).nullish(),
|
|
508
|
-
caller: anthropicToolCallCallerSchema.optional()
|
|
509
|
+
caller: anthropicToolCallCallerSchema().optional()
|
|
509
510
|
}),
|
|
510
511
|
z.object({
|
|
511
512
|
type: z.literal("mcp_tool_use"),
|
|
@@ -518,12 +519,12 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
|
|
|
518
519
|
type: z.literal("mcp_tool_result"),
|
|
519
520
|
tool_use_id: z.string(),
|
|
520
521
|
is_error: z.boolean(),
|
|
521
|
-
content: anthropicMcpToolResultContentSchema
|
|
522
|
+
content: anthropicMcpToolResultContentSchema()
|
|
522
523
|
}),
|
|
523
524
|
z.object({
|
|
524
525
|
type: z.literal("web_fetch_tool_result"),
|
|
525
526
|
tool_use_id: z.string(),
|
|
526
|
-
caller: anthropicToolCallCallerSchema.optional(),
|
|
527
|
+
caller: anthropicToolCallCallerSchema().optional(),
|
|
527
528
|
content: z.union([z.object({
|
|
528
529
|
type: z.literal("web_fetch_result"),
|
|
529
530
|
url: z.string(),
|
|
@@ -550,7 +551,7 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
|
|
|
550
551
|
z.object({
|
|
551
552
|
type: z.literal("web_search_tool_result"),
|
|
552
553
|
tool_use_id: z.string(),
|
|
553
|
-
caller: anthropicToolCallCallerSchema.optional(),
|
|
554
|
+
caller: anthropicToolCallCallerSchema().optional(),
|
|
554
555
|
content: z.union([z.array(z.object({
|
|
555
556
|
type: z.literal("web_search_result"),
|
|
556
557
|
url: z.string(),
|
|
@@ -673,7 +674,7 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
|
|
|
673
674
|
})
|
|
674
675
|
])
|
|
675
676
|
}),
|
|
676
|
-
anthropicFallbackContentSchema
|
|
677
|
+
anthropicFallbackContentSchema()
|
|
677
678
|
])
|
|
678
679
|
}),
|
|
679
680
|
z.object({
|
|
@@ -702,7 +703,7 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
|
|
|
702
703
|
}),
|
|
703
704
|
z.object({
|
|
704
705
|
type: z.literal("citations_delta"),
|
|
705
|
-
citation: anthropicCitationSchema
|
|
706
|
+
citation: anthropicCitationSchema()
|
|
706
707
|
})
|
|
707
708
|
])
|
|
708
709
|
}),
|
|
@@ -726,8 +727,8 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
|
|
|
726
727
|
delta: z.object({
|
|
727
728
|
stop_reason: z.string().nullish(),
|
|
728
729
|
stop_sequence: z.string().nullish(),
|
|
729
|
-
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
730
|
-
safeguard_results: z.array(anthropicSafeguardResultSchema).nullish(),
|
|
730
|
+
stop_details: anthropicStopDetailsSchema().nullish(),
|
|
731
|
+
safeguard_results: z.array(anthropicSafeguardResultSchema()).nullish(),
|
|
731
732
|
container: z.object({
|
|
732
733
|
expires_at: z.string(),
|
|
733
734
|
id: z.string(),
|
|
@@ -758,7 +759,7 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
|
|
|
758
759
|
cache_read_input_tokens: z.number().nullish()
|
|
759
760
|
})).nullish()
|
|
760
761
|
}),
|
|
761
|
-
input_transformations: z.array(anthropicInputTransformationSchema).nullish(),
|
|
762
|
+
input_transformations: z.array(anthropicInputTransformationSchema()).nullish(),
|
|
762
763
|
context_management: z.object({ applied_edits: z.array(z.union([
|
|
763
764
|
z.object({
|
|
764
765
|
type: z.literal("clear_tool_uses_20250919"),
|
|
@@ -786,7 +787,7 @@ const anthropicReasoningMetadataSchema = lazySchema(() => zodSchema(z.object({
|
|
|
786
787
|
* Anthropic file part provider options for document-specific features.
|
|
787
788
|
* These options apply to individual file parts (documents).
|
|
788
789
|
*/
|
|
789
|
-
const anthropicFilePartProviderOptions = z.object({
|
|
790
|
+
const anthropicFilePartProviderOptions = lazySchema(() => zodSchema(z.object({
|
|
790
791
|
/**
|
|
791
792
|
* Upload this file into the code execution container instead of sending it as
|
|
792
793
|
* a normal document or image content block.
|
|
@@ -812,11 +813,11 @@ enabled: z.boolean() }).optional(),
|
|
|
812
813
|
* Useful for storing document metadata as text or stringified JSON.
|
|
813
814
|
*/
|
|
814
815
|
context: z.string().optional()
|
|
815
|
-
});
|
|
816
|
+
})));
|
|
816
817
|
/**
|
|
817
818
|
* Anthropic provider options for system messages.
|
|
818
819
|
*/
|
|
819
|
-
const anthropicSystemMessageProviderOptions = z.object({
|
|
820
|
+
const anthropicSystemMessageProviderOptions = lazySchema(() => zodSchema(z.object({
|
|
820
821
|
/**
|
|
821
822
|
* Controls when an ephemeral mid-conversation system message is cleared.
|
|
822
823
|
*
|
|
@@ -859,8 +860,8 @@ const anthropicSystemMessageProviderOptions = z.object({
|
|
|
859
860
|
type: z.literal("tool_removal"),
|
|
860
861
|
toolName: z.string()
|
|
861
862
|
})])).optional()
|
|
862
|
-
});
|
|
863
|
-
const anthropicLanguageModelOptions = z.object({
|
|
863
|
+
})));
|
|
864
|
+
const anthropicLanguageModelOptions = lazySchema(() => zodSchema(z.object({
|
|
864
865
|
/**
|
|
865
866
|
* Whether to send reasoning to the model.
|
|
866
867
|
*
|
|
@@ -1131,21 +1132,23 @@ userId: z.string().optional() }).optional(),
|
|
|
1131
1132
|
instructions: z.string().optional()
|
|
1132
1133
|
})
|
|
1133
1134
|
])) }).optional()
|
|
1134
|
-
});
|
|
1135
|
+
})));
|
|
1135
1136
|
//#endregion
|
|
1136
1137
|
//#region src/get-cache-control.ts
|
|
1137
1138
|
const MAX_CACHE_BREAKPOINTS = 4;
|
|
1138
|
-
function getCacheControl(providerMetadata) {
|
|
1139
|
+
function getCacheControl(providerMetadata, providerOptionsName) {
|
|
1140
|
+
const custom = providerMetadata?.[providerOptionsName];
|
|
1139
1141
|
const anthropic = providerMetadata?.anthropic;
|
|
1140
|
-
return anthropic?.cacheControl ?? anthropic?.cache_control;
|
|
1142
|
+
return custom?.cacheControl ?? custom?.cache_control ?? anthropic?.cacheControl ?? anthropic?.cache_control;
|
|
1141
1143
|
}
|
|
1142
1144
|
var CacheControlValidator = class {
|
|
1143
|
-
constructor() {
|
|
1145
|
+
constructor(providerOptionsName = "anthropic") {
|
|
1146
|
+
this.providerOptionsName = providerOptionsName;
|
|
1144
1147
|
this.breakpointCount = 0;
|
|
1145
1148
|
this.warnings = [];
|
|
1146
1149
|
}
|
|
1147
1150
|
getCacheControl(providerMetadata, context) {
|
|
1148
|
-
const cacheControlValue = getCacheControl(providerMetadata);
|
|
1151
|
+
const cacheControlValue = getCacheControl(providerMetadata, this.providerOptionsName);
|
|
1149
1152
|
if (!cacheControlValue) return;
|
|
1150
1153
|
if (!context.canCache) {
|
|
1151
1154
|
this.warnings.push({
|
|
@@ -2266,7 +2269,7 @@ function extractErrorValue(value) {
|
|
|
2266
2269
|
}
|
|
2267
2270
|
return {};
|
|
2268
2271
|
}
|
|
2269
|
-
async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cacheControlValidator, toolNameMapping, toolsetNames = {} }) {
|
|
2272
|
+
async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cacheControlValidator, toolNameMapping, toolsetNames = {}, convertMediaPart }) {
|
|
2270
2273
|
const betas = /* @__PURE__ */ new Set();
|
|
2271
2274
|
const blocks = groupIntoBlocks(prompt);
|
|
2272
2275
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -2395,107 +2398,118 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
|
|
|
2395
2398
|
cache_control: cacheControl
|
|
2396
2399
|
});
|
|
2397
2400
|
break;
|
|
2398
|
-
case "file":
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
reference: part.data.reference,
|
|
2402
|
-
provider: "anthropic"
|
|
2403
|
-
});
|
|
2404
|
-
betas.add("files-api-2025-04-14");
|
|
2405
|
-
if (await shouldUseContainerUpload(part.providerOptions)) anthropicContent.push({
|
|
2406
|
-
type: "container_upload",
|
|
2407
|
-
file_id: fileId
|
|
2408
|
-
});
|
|
2409
|
-
else if (getTopLevelMediaType(part.mediaType) === "image") anthropicContent.push({
|
|
2410
|
-
type: "image",
|
|
2411
|
-
source: {
|
|
2412
|
-
type: "file",
|
|
2413
|
-
file_id: fileId
|
|
2414
|
-
},
|
|
2415
|
-
cache_control: cacheControl
|
|
2416
|
-
});
|
|
2417
|
-
else anthropicContent.push({
|
|
2418
|
-
type: "document",
|
|
2419
|
-
source: {
|
|
2420
|
-
type: "file",
|
|
2421
|
-
file_id: fileId
|
|
2422
|
-
},
|
|
2423
|
-
cache_control: cacheControl
|
|
2424
|
-
});
|
|
2425
|
-
break;
|
|
2426
|
-
}
|
|
2427
|
-
case "text": {
|
|
2428
|
-
const enableCitations = await shouldEnableCitations(part.providerOptions);
|
|
2429
|
-
const metadata = await getDocumentMetadata(part.providerOptions);
|
|
2401
|
+
case "file": {
|
|
2402
|
+
const convertedPart = await convertMediaPart?.(part);
|
|
2403
|
+
if (convertedPart != null) {
|
|
2430
2404
|
anthropicContent.push({
|
|
2431
|
-
|
|
2432
|
-
source: {
|
|
2433
|
-
type: "text",
|
|
2434
|
-
media_type: "text/plain",
|
|
2435
|
-
data: part.data.text
|
|
2436
|
-
},
|
|
2437
|
-
title: metadata.title ?? part.filename,
|
|
2438
|
-
...metadata.context && { context: metadata.context },
|
|
2439
|
-
...enableCitations && { citations: { enabled: true } },
|
|
2405
|
+
...convertedPart,
|
|
2440
2406
|
cache_control: cacheControl
|
|
2441
2407
|
});
|
|
2442
2408
|
break;
|
|
2443
2409
|
}
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2410
|
+
switch (part.data.type) {
|
|
2411
|
+
case "reference": {
|
|
2412
|
+
const fileId = resolveProviderReference({
|
|
2413
|
+
reference: part.data.reference,
|
|
2414
|
+
provider: "anthropic"
|
|
2415
|
+
});
|
|
2416
|
+
betas.add("files-api-2025-04-14");
|
|
2417
|
+
if (await shouldUseContainerUpload(part.providerOptions)) anthropicContent.push({
|
|
2418
|
+
type: "container_upload",
|
|
2419
|
+
file_id: fileId
|
|
2420
|
+
});
|
|
2421
|
+
else if (getTopLevelMediaType(part.mediaType) === "image") anthropicContent.push({
|
|
2422
|
+
type: "image",
|
|
2423
|
+
source: {
|
|
2424
|
+
type: "file",
|
|
2425
|
+
file_id: fileId
|
|
2426
|
+
},
|
|
2427
|
+
cache_control: cacheControl
|
|
2428
|
+
});
|
|
2429
|
+
else anthropicContent.push({
|
|
2430
|
+
type: "document",
|
|
2431
|
+
source: {
|
|
2432
|
+
type: "file",
|
|
2433
|
+
file_id: fileId
|
|
2434
|
+
},
|
|
2435
|
+
cache_control: cacheControl
|
|
2436
|
+
});
|
|
2437
|
+
break;
|
|
2438
|
+
}
|
|
2439
|
+
case "text": {
|
|
2461
2440
|
const enableCitations = await shouldEnableCitations(part.providerOptions);
|
|
2462
2441
|
const metadata = await getDocumentMetadata(part.providerOptions);
|
|
2463
2442
|
anthropicContent.push({
|
|
2464
2443
|
type: "document",
|
|
2465
|
-
source:
|
|
2466
|
-
type: "
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
type: "base64",
|
|
2470
|
-
media_type: "application/pdf",
|
|
2471
|
-
data: convertToBase64(part.data.data)
|
|
2444
|
+
source: {
|
|
2445
|
+
type: "text",
|
|
2446
|
+
media_type: "text/plain",
|
|
2447
|
+
data: part.data.text
|
|
2472
2448
|
},
|
|
2473
2449
|
title: metadata.title ?? part.filename,
|
|
2474
2450
|
...metadata.context && { context: metadata.context },
|
|
2475
2451
|
...enableCitations && { citations: { enabled: true } },
|
|
2476
2452
|
cache_control: cacheControl
|
|
2477
2453
|
});
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2454
|
+
break;
|
|
2455
|
+
}
|
|
2456
|
+
case "url":
|
|
2457
|
+
case "data": {
|
|
2458
|
+
const topLevel = getTopLevelMediaType(part.mediaType);
|
|
2459
|
+
if (topLevel === "image") anthropicContent.push({
|
|
2460
|
+
type: "image",
|
|
2483
2461
|
source: part.data.type === "url" ? {
|
|
2484
2462
|
type: "url",
|
|
2485
2463
|
url: part.data.url.toString()
|
|
2486
2464
|
} : {
|
|
2487
|
-
type: "
|
|
2488
|
-
media_type:
|
|
2489
|
-
data:
|
|
2465
|
+
type: "base64",
|
|
2466
|
+
media_type: resolveFullMediaType({ part }),
|
|
2467
|
+
data: convertToBase64(part.data.data)
|
|
2490
2468
|
},
|
|
2491
|
-
title: metadata.title ?? part.filename,
|
|
2492
|
-
...metadata.context && { context: metadata.context },
|
|
2493
|
-
...enableCitations && { citations: { enabled: true } },
|
|
2494
2469
|
cache_control: cacheControl
|
|
2495
2470
|
});
|
|
2496
|
-
|
|
2497
|
-
|
|
2471
|
+
else if (topLevel === "application" && (part.data.type === "url" ? part.mediaType === "application/pdf" : resolveFullMediaType({ part }) === "application/pdf")) {
|
|
2472
|
+
betas.add("pdfs-2024-09-25");
|
|
2473
|
+
const enableCitations = await shouldEnableCitations(part.providerOptions);
|
|
2474
|
+
const metadata = await getDocumentMetadata(part.providerOptions);
|
|
2475
|
+
anthropicContent.push({
|
|
2476
|
+
type: "document",
|
|
2477
|
+
source: part.data.type === "url" ? {
|
|
2478
|
+
type: "url",
|
|
2479
|
+
url: part.data.url.toString()
|
|
2480
|
+
} : {
|
|
2481
|
+
type: "base64",
|
|
2482
|
+
media_type: "application/pdf",
|
|
2483
|
+
data: convertToBase64(part.data.data)
|
|
2484
|
+
},
|
|
2485
|
+
title: metadata.title ?? part.filename,
|
|
2486
|
+
...metadata.context && { context: metadata.context },
|
|
2487
|
+
...enableCitations && { citations: { enabled: true } },
|
|
2488
|
+
cache_control: cacheControl
|
|
2489
|
+
});
|
|
2490
|
+
} else if (part.mediaType === "text/plain") {
|
|
2491
|
+
const enableCitations = await shouldEnableCitations(part.providerOptions);
|
|
2492
|
+
const metadata = await getDocumentMetadata(part.providerOptions);
|
|
2493
|
+
anthropicContent.push({
|
|
2494
|
+
type: "document",
|
|
2495
|
+
source: part.data.type === "url" ? {
|
|
2496
|
+
type: "url",
|
|
2497
|
+
url: part.data.url.toString()
|
|
2498
|
+
} : {
|
|
2499
|
+
type: "text",
|
|
2500
|
+
media_type: "text/plain",
|
|
2501
|
+
data: convertBytesDataToString(part.data.data)
|
|
2502
|
+
},
|
|
2503
|
+
title: metadata.title ?? part.filename,
|
|
2504
|
+
...metadata.context && { context: metadata.context },
|
|
2505
|
+
...enableCitations && { citations: { enabled: true } },
|
|
2506
|
+
cache_control: cacheControl
|
|
2507
|
+
});
|
|
2508
|
+
} else throw new UnsupportedFunctionalityError({ functionality: `media type: ${part.mediaType}` });
|
|
2509
|
+
break;
|
|
2510
|
+
}
|
|
2498
2511
|
}
|
|
2512
|
+
break;
|
|
2499
2513
|
}
|
|
2500
2514
|
}
|
|
2501
2515
|
}
|
|
@@ -2732,7 +2746,7 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
|
|
|
2732
2746
|
if (part.kind !== "anthropic.fallback") break;
|
|
2733
2747
|
const fallbackMetadata = await safeValidateTypes({
|
|
2734
2748
|
value: part.providerOptions?.anthropic,
|
|
2735
|
-
schema:
|
|
2749
|
+
schema: anthropicFallbackContentSchemaValidator
|
|
2736
2750
|
});
|
|
2737
2751
|
if (!fallbackMetadata.success) {
|
|
2738
2752
|
warnings.push({
|
|
@@ -3565,18 +3579,20 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
3565
3579
|
type: "unsupported",
|
|
3566
3580
|
feature: "seed"
|
|
3567
3581
|
});
|
|
3568
|
-
|
|
3582
|
+
const maxTemperature = config.maxTemperature ?? 1;
|
|
3583
|
+
const temperatureProvider = config.maxTemperature == null ? "anthropic" : getProviderOptionsName(config.provider);
|
|
3584
|
+
if (temperature != null && temperature > maxTemperature) {
|
|
3569
3585
|
warnings.push({
|
|
3570
3586
|
type: "unsupported",
|
|
3571
3587
|
feature: "temperature",
|
|
3572
|
-
details: `${temperature} exceeds
|
|
3588
|
+
details: `${temperature} exceeds ${temperatureProvider} maximum of ${maxTemperature.toFixed(1)}. clamped to ${maxTemperature.toFixed(1)}`
|
|
3573
3589
|
});
|
|
3574
|
-
temperature =
|
|
3590
|
+
temperature = maxTemperature;
|
|
3575
3591
|
} else if (temperature != null && temperature < 0) {
|
|
3576
3592
|
warnings.push({
|
|
3577
3593
|
type: "unsupported",
|
|
3578
3594
|
feature: "temperature",
|
|
3579
|
-
details: `${temperature} is below
|
|
3595
|
+
details: `${temperature} is below ${temperatureProvider} minimum of 0. clamped to 0`
|
|
3580
3596
|
});
|
|
3581
3597
|
temperature = 0;
|
|
3582
3598
|
}
|
|
@@ -3662,7 +3678,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
3662
3678
|
argument: "providerOptions",
|
|
3663
3679
|
message: "Anthropic provider options `compaction` and `contextManagement` cannot be used together."
|
|
3664
3680
|
});
|
|
3665
|
-
const cacheControlValidator = new CacheControlValidator();
|
|
3681
|
+
const cacheControlValidator = new CacheControlValidator(config.cacheControlProviderOptionsName);
|
|
3666
3682
|
const toolNameMapping = createToolNameMapping({
|
|
3667
3683
|
tools,
|
|
3668
3684
|
providerToolNames: {
|
|
@@ -3698,7 +3714,8 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
3698
3714
|
warnings,
|
|
3699
3715
|
cacheControlValidator,
|
|
3700
3716
|
toolNameMapping,
|
|
3701
|
-
toolsetNames
|
|
3717
|
+
toolsetNames,
|
|
3718
|
+
convertMediaPart: config.convertMediaPart
|
|
3702
3719
|
});
|
|
3703
3720
|
if (isCustomReasoning(reasoning) && anthropicOptions?.effort == null) {
|
|
3704
3721
|
const reasoningConfig = resolveAnthropicReasoningConfig({
|
|
@@ -3870,7 +3887,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
3870
3887
|
};
|
|
3871
3888
|
thinkingBudget = 1024;
|
|
3872
3889
|
}
|
|
3873
|
-
if (baseArgs.temperature != null) {
|
|
3890
|
+
if (baseArgs.temperature != null && !config.supportsTemperatureAndTopPWithThinking) {
|
|
3874
3891
|
baseArgs.temperature = void 0;
|
|
3875
3892
|
warnings.push({
|
|
3876
3893
|
type: "unsupported",
|
|
@@ -3886,7 +3903,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
3886
3903
|
details: "topK is not supported when thinking is enabled"
|
|
3887
3904
|
});
|
|
3888
3905
|
}
|
|
3889
|
-
if (topP != null) {
|
|
3906
|
+
if (topP != null && !config.supportsTemperatureAndTopPWithThinking) {
|
|
3890
3907
|
baseArgs.top_p = void 0;
|
|
3891
3908
|
warnings.push({
|
|
3892
3909
|
type: "unsupported",
|
|
@@ -5541,7 +5558,7 @@ function mapAnthropicStopDetails$1(stopDetails) {
|
|
|
5541
5558
|
//#endregion
|
|
5542
5559
|
//#region src/anthropic-batch.ts
|
|
5543
5560
|
const anthropicBatchRequestIdPattern = /^[A-Za-z0-9_-]{1,64}$/;
|
|
5544
|
-
const anthropicBatchProviderOptionsSchema =
|
|
5561
|
+
const anthropicBatchProviderOptionsSchema = lazySchema(() => zodSchema(z.object({ anthropicBeta: z.array(z.string()).optional() })));
|
|
5545
5562
|
const anthropicBatchResponseZodSchema = () => z.object({
|
|
5546
5563
|
id: z.string(),
|
|
5547
5564
|
type: z.literal("message_batch"),
|
|
@@ -6887,10 +6904,6 @@ const anthropicSkillVersionResponseSchema = lazySchema(() => zodSchema(z.object(
|
|
|
6887
6904
|
})));
|
|
6888
6905
|
//#endregion
|
|
6889
6906
|
//#region src/skills/anthropic-skills.ts
|
|
6890
|
-
function encodePathSegment(value) {
|
|
6891
|
-
const encodedValue = encodeURIComponent(value);
|
|
6892
|
-
return encodedValue === "." ? "%252E" : encodedValue === ".." ? "%252E%252E" : encodedValue;
|
|
6893
|
-
}
|
|
6894
6907
|
var AnthropicSkills = class {
|
|
6895
6908
|
get provider() {
|
|
6896
6909
|
return this.config.provider;
|
|
@@ -6957,7 +6970,7 @@ var AnthropicSkills = class {
|
|
|
6957
6970
|
};
|
|
6958
6971
|
//#endregion
|
|
6959
6972
|
//#region src/version.ts
|
|
6960
|
-
const VERSION = "4.0.
|
|
6973
|
+
const VERSION = "4.0.85";
|
|
6961
6974
|
//#endregion
|
|
6962
6975
|
//#region src/anthropic-provider.ts
|
|
6963
6976
|
const ANTHROPIC_API_URL = "https://api.anthropic.com";
|