@ai-sdk/anthropic 4.0.83 → 4.0.84
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 +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +108 -92
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +33 -13
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +107 -91
- package/dist/internal/index.js.map +1 -1
- package/package.json +4 -3
- package/src/anthropic-api.ts +8 -0
- package/src/anthropic-language-model.ts +31 -8
- package/src/convert-to-anthropic-prompt.ts +22 -0
- package/src/get-cache-control.ts +15 -3
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Experimental_SandboxSession, FetchFunction, InferSchema, ProviderDefinedTool, Resolvable, Tool, ToolExecuteFunction, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@ai-sdk/provider-utils";
|
|
2
2
|
import { z } from "zod/v4";
|
|
3
|
-
import { FilesV4, FilesV4UploadFileCallOptions, FilesV4UploadFileResult, JSONObject, JSONSchema7, LanguageModelV4, LanguageModelV4CallOptions, LanguageModelV4GenerateResult, LanguageModelV4StreamResult, SharedV4ProviderMetadata, SharedV4Warning, SkillsV4 } from "@ai-sdk/provider";
|
|
3
|
+
import { FilesV4, FilesV4UploadFileCallOptions, FilesV4UploadFileResult, JSONObject, JSONSchema7, LanguageModelV4, LanguageModelV4CallOptions, LanguageModelV4FilePart, LanguageModelV4GenerateResult, LanguageModelV4StreamResult, SharedV4ProviderMetadata, SharedV4Warning, SkillsV4 } from "@ai-sdk/provider";
|
|
4
4
|
//#region src/anthropic-files.d.ts
|
|
5
5
|
interface AnthropicFilesConfig {
|
|
6
6
|
provider: string;
|
|
@@ -47,7 +47,7 @@ interface AnthropicToolChangeContent {
|
|
|
47
47
|
}
|
|
48
48
|
interface AnthropicUserMessage {
|
|
49
49
|
role: 'user';
|
|
50
|
-
content: Array<AnthropicTextContent | AnthropicImageContent | AnthropicDocumentContent | AnthropicContainerUploadContent | AnthropicToolResultContent>;
|
|
50
|
+
content: Array<AnthropicTextContent | AnthropicImageContent | AnthropicVideoContent | AnthropicDocumentContent | AnthropicContainerUploadContent | AnthropicToolResultContent>;
|
|
51
51
|
}
|
|
52
52
|
interface AnthropicAssistantMessage {
|
|
53
53
|
role: 'assistant';
|
|
@@ -108,6 +108,12 @@ interface AnthropicImageContent {
|
|
|
108
108
|
source: AnthropicContentSource;
|
|
109
109
|
cache_control: AnthropicCacheControl | undefined;
|
|
110
110
|
}
|
|
111
|
+
/** Video blocks supplied by compatible providers through custom media conversion. */
|
|
112
|
+
interface AnthropicVideoContent {
|
|
113
|
+
type: 'video';
|
|
114
|
+
source: AnthropicContentSource;
|
|
115
|
+
cache_control: AnthropicCacheControl | undefined;
|
|
116
|
+
}
|
|
111
117
|
interface AnthropicDocumentContent {
|
|
112
118
|
type: 'document';
|
|
113
119
|
source: AnthropicContentSource;
|
|
@@ -821,6 +827,23 @@ type Citation = NonNullable<(InferSchema<typeof anthropicResponseSchema>['conten
|
|
|
821
827
|
//#region src/anthropic-language-model-options.d.ts
|
|
822
828
|
type AnthropicModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-haiku-5-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | (string & {});
|
|
823
829
|
//#endregion
|
|
830
|
+
//#region src/get-cache-control.d.ts
|
|
831
|
+
declare class CacheControlValidator {
|
|
832
|
+
private readonly providerOptionsName;
|
|
833
|
+
private breakpointCount;
|
|
834
|
+
private warnings;
|
|
835
|
+
constructor(providerOptionsName?: string);
|
|
836
|
+
getCacheControl(providerMetadata: SharedV4ProviderMetadata | undefined, context: {
|
|
837
|
+
type: string;
|
|
838
|
+
canCache: boolean;
|
|
839
|
+
}): AnthropicCacheControl | undefined;
|
|
840
|
+
getWarnings(): SharedV4Warning[];
|
|
841
|
+
}
|
|
842
|
+
//#endregion
|
|
843
|
+
//#region src/convert-to-anthropic-prompt.d.ts
|
|
844
|
+
/** Return undefined to use the default file conversion. */
|
|
845
|
+
type AnthropicMediaPartConverter = (part: LanguageModelV4FilePart) => PromiseLike<Omit<AnthropicImageContent | AnthropicVideoContent, 'cache_control'> | undefined>;
|
|
846
|
+
//#endregion
|
|
824
847
|
//#region src/anthropic-language-model.d.ts
|
|
825
848
|
type AnthropicLanguageModelConfig = {
|
|
826
849
|
provider: string;
|
|
@@ -828,12 +851,20 @@ type AnthropicLanguageModelConfig = {
|
|
|
828
851
|
headers?: Resolvable<Record<string, string | undefined>>;
|
|
829
852
|
fetch?: FetchFunction;
|
|
830
853
|
buildRequestUrl?: (baseURL: string, isStreaming: boolean) => string;
|
|
854
|
+
/** Custom media conversion for compatible providers; undefined uses the default. */
|
|
855
|
+
convertMediaPart?: AnthropicMediaPartConverter;
|
|
831
856
|
transformRequestBody?: (args: Record<string, any>, betas: Set<string>) => Record<string, any>;
|
|
832
857
|
transformRequestHeaders?: (headers: Record<string, string | undefined>, providerOptions: LanguageModelV4CallOptions['providerOptions']) => Record<string, string | undefined> | PromiseLike<Record<string, string | undefined>>;
|
|
833
858
|
supportedUrls?: () => LanguageModelV4['supportedUrls'];
|
|
834
859
|
generateId?: () => string;
|
|
835
860
|
supportsNativeStructuredOutput?: boolean;
|
|
836
861
|
supportsStrictTools?: boolean;
|
|
862
|
+
/** Maximum temperature for compatible providers. Defaults to 1. */
|
|
863
|
+
maxTemperature?: number;
|
|
864
|
+
/** Preserve temperature and topP with thinking for compatible providers. */
|
|
865
|
+
supportsTemperatureAndTopPWithThinking?: boolean;
|
|
866
|
+
/** Cache option namespace for compatible providers. Defaults to anthropic. */
|
|
867
|
+
cacheControlProviderOptionsName?: string;
|
|
837
868
|
};
|
|
838
869
|
export declare class AnthropicLanguageModel implements LanguageModelV4 {
|
|
839
870
|
readonly specificationVersion = "v4";
|
|
@@ -2073,17 +2104,6 @@ export declare const anthropicTools: {
|
|
|
2073
2104
|
}[], {}>;
|
|
2074
2105
|
};
|
|
2075
2106
|
//#endregion
|
|
2076
|
-
//#region src/get-cache-control.d.ts
|
|
2077
|
-
declare class CacheControlValidator {
|
|
2078
|
-
private breakpointCount;
|
|
2079
|
-
private warnings;
|
|
2080
|
-
getCacheControl(providerMetadata: SharedV4ProviderMetadata | undefined, context: {
|
|
2081
|
-
type: string;
|
|
2082
|
-
canCache: boolean;
|
|
2083
|
-
}): AnthropicCacheControl | undefined;
|
|
2084
|
-
getWarnings(): SharedV4Warning[];
|
|
2085
|
-
}
|
|
2086
|
-
//#endregion
|
|
2087
2107
|
//#region src/anthropic-prepare-tools.d.ts
|
|
2088
2108
|
export declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, defaultEagerInputStreaming, rejectsForcedToolUse }: {
|
|
2089
2109
|
tools: LanguageModelV4CallOptions['tools'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["_$__anthropic_api0.AnthropicToolChoice","_$__anthropic_api0.AnthropicTextContent","_$__anthropic_api0.AnthropicMessage","SandboxSession","SandboxSession","_$__tool_computer_toolset_202608010.ComputerToolset_20260801Member"],"sources":["../../src/anthropic-files.ts","../../src/anthropic-api.ts","../../src/anthropic-language-model-options.ts","../../src/anthropic-language-model.ts","../../src/tool/computer-toolset_20260801.ts","../../src/tool/bash_20241022.ts","../../src/tool/bash_20250124.ts","../../src/anthropic-tools.ts","../../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["_$__anthropic_api0.AnthropicToolChoice","_$__anthropic_api0.AnthropicTextContent","_$__anthropic_api0.AnthropicMessage","SandboxSession","SandboxSession","_$__tool_computer_toolset_202608010.ComputerToolset_20260801Member"],"sources":["../../src/anthropic-files.ts","../../src/anthropic-api.ts","../../src/anthropic-language-model-options.ts","../../src/get-cache-control.ts","../../src/convert-to-anthropic-prompt.ts","../../src/anthropic-language-model.ts","../../src/tool/computer-toolset_20260801.ts","../../src/tool/bash_20241022.ts","../../src/tool/bash_20250124.ts","../../src/anthropic-tools.ts","../../src/anthropic-prepare-tools.ts","../../src/sanitize-json-schema.ts","../../src/skills/anthropic-skills.ts"],"mappings":";;;;UA+BU;EACR;EACA;EACA,eAAe;EACf,QAAQ;;qBAGG,0BAA0B;mBAOR;WANpB;MAEL;EAIyB,YAAA,QAAQ;EAE/B,aACJ,MACA,WACA,UACA,aACA,WACC,+BAA+B,QAAQ;;;;KCxChC,mBACR,uBACA,4BACA;KAEQ;EACV;EACA;;UAGe;EACf;EACA,SAAS,MAAM,uBAAuB;EACtC;EACA;IACE;;;;;;;;;;UAWa;EACf;EACA;IAAQ;IAAwB;;EAChC;;UAGe;EACf;EACA,SAAS,MACL,uBACA,wBACA,wBACA,2BACA,kCACA;;UAIW;EACf;EACA,SAAS,MACL,uBACA,2BACA,mCACA,2BACA,2BACA,gCACA,0CACA,qCACA,sCACA,uCACA,8CACA,oDACA,oCACA,6BACA,gCACA;;cAIO,gCAA8B,EAAA;;;;;;;;GAIzC,EAAA,KAAA;KAEU,2BAA2B,mBAC9B;EAEP;;UAGe;EACf;EACA;EACA;EACA,gBAAgB;;UAGD;EACf;EACA;EACA,YAAY;EACZ,eAAe;;UAGA;EACf;EACA;EACA;EAGA;;UAGe;EACf;EACA;EAGA;;KAGG;EAEC;EACA;EACA;;EAGA;EACA;;EAGA;EACA;EACA;;EAGA;EACA;;UAGW;EACf;EACA,QAAQ;EACR,eAAe;;;UAIA;EACf;EACA,QAAQ;EACR,eAAe;;UAGA;EACf;EACA,QAAQ;EACR;EACA;EACA;IAAc;;EACd,eAAe;;UAGA;EACf;EACA;EACA;;;;;;KAOU;EAEN;EACA;;EAGA;EACA;;EAGA;;UAGW;EACf;EACA;EACA;EACA;;;;;EAKA,SAAS;;;;;EAKT;EACA,eAAe;;UAGA;EACf;EACA;EACA;EAaA;EACA,SAAS;EACT,eAAe;;KAKZ,6BAA6B,KAChC;EAGA;;KAGG,8BAA8B,KACjC;EAGA;;KAGG,iCAAiC,KACpC;EAGA;;UAGe;EACf;EACA;;UAGe;EACf;EACA;;;;EAIA;EACA,kBAEI,MACI,6BACA,8BACA,iCACA;EAER;EACA,eAAe;;UAGA;EACf;EACA;EACA,SACI;IACE;IACA;IACA;IACA;IACA;;IAGA;IACA;;EAEN,SAAS;EACT,eAAe;;UAGA;EACf;EACA;EACA;IAEM;IACA,iBAAiB;MACf;MACA;;;IAIF;IACA;;EAEN,eAAe;;UAIA;EACf;EACA;EACA;IAEM;IACA;IACA;IACA;IACA,SAAS;MAAQ;MAA+B;;;IAGhD;IACA;IACA;IACA;IACA,SAAS;MAAQ;MAA+B;;;IAGhD;IACA;;EAEN,eAAe;;UAIA;EACf;EACA;EACA;IAEM;IACA;;IAGA;IACA;;IAGA;IACA;IACA;IACA;IACA;IACA;;IAGA;IACA;IACA;IACA;IACA;IACA;;EAEN,eAAe;;UAIA;EACf;EACA;EACA;IAEM;IACA;IACA;IACA;IACA;MACE;MACA;;;IAIF;IACA;;EAEN,eAAe;;UAGA;EACf;EACA;EACA;IAEM;IACA;IACA;;IAGA;IACA;IACA;;IAGA;;;;;;IAMA;;EAEN,eAAe;;UAGA;EACf;EACA;EACA;IAEM;IACA;IACA;IACA;MACE;MACA;MACA;QAAc;;MACd;QACM;QAAgB;QAA+B;;QAC/C;QAAc;QAA0B;;;;IAIhD;IACA;;EAEN,SAAS;EACT,eAAe;;UAEA;EACf;EACA;EACA;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Q,WAAW,8BAClB,QAAQ,QAAQ,WAAW"}
|
package/dist/internal/index.js
CHANGED
|
@@ -1134,17 +1134,19 @@ userId: z.string().optional() }).optional(),
|
|
|
1134
1134
|
//#endregion
|
|
1135
1135
|
//#region src/get-cache-control.ts
|
|
1136
1136
|
const MAX_CACHE_BREAKPOINTS = 4;
|
|
1137
|
-
function getCacheControl(providerMetadata) {
|
|
1137
|
+
function getCacheControl(providerMetadata, providerOptionsName) {
|
|
1138
|
+
const custom = providerMetadata?.[providerOptionsName];
|
|
1138
1139
|
const anthropic = providerMetadata?.anthropic;
|
|
1139
|
-
return anthropic?.cacheControl ?? anthropic?.cache_control;
|
|
1140
|
+
return custom?.cacheControl ?? custom?.cache_control ?? anthropic?.cacheControl ?? anthropic?.cache_control;
|
|
1140
1141
|
}
|
|
1141
1142
|
var CacheControlValidator = class {
|
|
1142
|
-
constructor() {
|
|
1143
|
+
constructor(providerOptionsName = "anthropic") {
|
|
1144
|
+
this.providerOptionsName = providerOptionsName;
|
|
1143
1145
|
this.breakpointCount = 0;
|
|
1144
1146
|
this.warnings = [];
|
|
1145
1147
|
}
|
|
1146
1148
|
getCacheControl(providerMetadata, context) {
|
|
1147
|
-
const cacheControlValue = getCacheControl(providerMetadata);
|
|
1149
|
+
const cacheControlValue = getCacheControl(providerMetadata, this.providerOptionsName);
|
|
1148
1150
|
if (!cacheControlValue) return;
|
|
1149
1151
|
if (!context.canCache) {
|
|
1150
1152
|
this.warnings.push({
|
|
@@ -2265,7 +2267,7 @@ function extractErrorValue(value) {
|
|
|
2265
2267
|
}
|
|
2266
2268
|
return {};
|
|
2267
2269
|
}
|
|
2268
|
-
async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cacheControlValidator, toolNameMapping, toolsetNames = {} }) {
|
|
2270
|
+
async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cacheControlValidator, toolNameMapping, toolsetNames = {}, convertMediaPart }) {
|
|
2269
2271
|
const betas = /* @__PURE__ */ new Set();
|
|
2270
2272
|
const blocks = groupIntoBlocks(prompt);
|
|
2271
2273
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -2394,107 +2396,118 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
|
|
|
2394
2396
|
cache_control: cacheControl
|
|
2395
2397
|
});
|
|
2396
2398
|
break;
|
|
2397
|
-
case "file":
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
reference: part.data.reference,
|
|
2401
|
-
provider: "anthropic"
|
|
2402
|
-
});
|
|
2403
|
-
betas.add("files-api-2025-04-14");
|
|
2404
|
-
if (await shouldUseContainerUpload(part.providerOptions)) anthropicContent.push({
|
|
2405
|
-
type: "container_upload",
|
|
2406
|
-
file_id: fileId
|
|
2407
|
-
});
|
|
2408
|
-
else if (getTopLevelMediaType(part.mediaType) === "image") anthropicContent.push({
|
|
2409
|
-
type: "image",
|
|
2410
|
-
source: {
|
|
2411
|
-
type: "file",
|
|
2412
|
-
file_id: fileId
|
|
2413
|
-
},
|
|
2414
|
-
cache_control: cacheControl
|
|
2415
|
-
});
|
|
2416
|
-
else anthropicContent.push({
|
|
2417
|
-
type: "document",
|
|
2418
|
-
source: {
|
|
2419
|
-
type: "file",
|
|
2420
|
-
file_id: fileId
|
|
2421
|
-
},
|
|
2422
|
-
cache_control: cacheControl
|
|
2423
|
-
});
|
|
2424
|
-
break;
|
|
2425
|
-
}
|
|
2426
|
-
case "text": {
|
|
2427
|
-
const enableCitations = await shouldEnableCitations(part.providerOptions);
|
|
2428
|
-
const metadata = await getDocumentMetadata(part.providerOptions);
|
|
2399
|
+
case "file": {
|
|
2400
|
+
const convertedPart = await convertMediaPart?.(part);
|
|
2401
|
+
if (convertedPart != null) {
|
|
2429
2402
|
anthropicContent.push({
|
|
2430
|
-
|
|
2431
|
-
source: {
|
|
2432
|
-
type: "text",
|
|
2433
|
-
media_type: "text/plain",
|
|
2434
|
-
data: part.data.text
|
|
2435
|
-
},
|
|
2436
|
-
title: metadata.title ?? part.filename,
|
|
2437
|
-
...metadata.context && { context: metadata.context },
|
|
2438
|
-
...enableCitations && { citations: { enabled: true } },
|
|
2403
|
+
...convertedPart,
|
|
2439
2404
|
cache_control: cacheControl
|
|
2440
2405
|
});
|
|
2441
2406
|
break;
|
|
2442
2407
|
}
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2408
|
+
switch (part.data.type) {
|
|
2409
|
+
case "reference": {
|
|
2410
|
+
const fileId = resolveProviderReference({
|
|
2411
|
+
reference: part.data.reference,
|
|
2412
|
+
provider: "anthropic"
|
|
2413
|
+
});
|
|
2414
|
+
betas.add("files-api-2025-04-14");
|
|
2415
|
+
if (await shouldUseContainerUpload(part.providerOptions)) anthropicContent.push({
|
|
2416
|
+
type: "container_upload",
|
|
2417
|
+
file_id: fileId
|
|
2418
|
+
});
|
|
2419
|
+
else if (getTopLevelMediaType(part.mediaType) === "image") anthropicContent.push({
|
|
2420
|
+
type: "image",
|
|
2421
|
+
source: {
|
|
2422
|
+
type: "file",
|
|
2423
|
+
file_id: fileId
|
|
2424
|
+
},
|
|
2425
|
+
cache_control: cacheControl
|
|
2426
|
+
});
|
|
2427
|
+
else anthropicContent.push({
|
|
2428
|
+
type: "document",
|
|
2429
|
+
source: {
|
|
2430
|
+
type: "file",
|
|
2431
|
+
file_id: fileId
|
|
2432
|
+
},
|
|
2433
|
+
cache_control: cacheControl
|
|
2434
|
+
});
|
|
2435
|
+
break;
|
|
2436
|
+
}
|
|
2437
|
+
case "text": {
|
|
2460
2438
|
const enableCitations = await shouldEnableCitations(part.providerOptions);
|
|
2461
2439
|
const metadata = await getDocumentMetadata(part.providerOptions);
|
|
2462
2440
|
anthropicContent.push({
|
|
2463
2441
|
type: "document",
|
|
2464
|
-
source:
|
|
2465
|
-
type: "
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
type: "base64",
|
|
2469
|
-
media_type: "application/pdf",
|
|
2470
|
-
data: convertToBase64(part.data.data)
|
|
2442
|
+
source: {
|
|
2443
|
+
type: "text",
|
|
2444
|
+
media_type: "text/plain",
|
|
2445
|
+
data: part.data.text
|
|
2471
2446
|
},
|
|
2472
2447
|
title: metadata.title ?? part.filename,
|
|
2473
2448
|
...metadata.context && { context: metadata.context },
|
|
2474
2449
|
...enableCitations && { citations: { enabled: true } },
|
|
2475
2450
|
cache_control: cacheControl
|
|
2476
2451
|
});
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2452
|
+
break;
|
|
2453
|
+
}
|
|
2454
|
+
case "url":
|
|
2455
|
+
case "data": {
|
|
2456
|
+
const topLevel = getTopLevelMediaType(part.mediaType);
|
|
2457
|
+
if (topLevel === "image") anthropicContent.push({
|
|
2458
|
+
type: "image",
|
|
2482
2459
|
source: part.data.type === "url" ? {
|
|
2483
2460
|
type: "url",
|
|
2484
2461
|
url: part.data.url.toString()
|
|
2485
2462
|
} : {
|
|
2486
|
-
type: "
|
|
2487
|
-
media_type:
|
|
2488
|
-
data:
|
|
2463
|
+
type: "base64",
|
|
2464
|
+
media_type: resolveFullMediaType({ part }),
|
|
2465
|
+
data: convertToBase64(part.data.data)
|
|
2489
2466
|
},
|
|
2490
|
-
title: metadata.title ?? part.filename,
|
|
2491
|
-
...metadata.context && { context: metadata.context },
|
|
2492
|
-
...enableCitations && { citations: { enabled: true } },
|
|
2493
2467
|
cache_control: cacheControl
|
|
2494
2468
|
});
|
|
2495
|
-
|
|
2496
|
-
|
|
2469
|
+
else if (topLevel === "application" && (part.data.type === "url" ? part.mediaType === "application/pdf" : resolveFullMediaType({ part }) === "application/pdf")) {
|
|
2470
|
+
betas.add("pdfs-2024-09-25");
|
|
2471
|
+
const enableCitations = await shouldEnableCitations(part.providerOptions);
|
|
2472
|
+
const metadata = await getDocumentMetadata(part.providerOptions);
|
|
2473
|
+
anthropicContent.push({
|
|
2474
|
+
type: "document",
|
|
2475
|
+
source: part.data.type === "url" ? {
|
|
2476
|
+
type: "url",
|
|
2477
|
+
url: part.data.url.toString()
|
|
2478
|
+
} : {
|
|
2479
|
+
type: "base64",
|
|
2480
|
+
media_type: "application/pdf",
|
|
2481
|
+
data: convertToBase64(part.data.data)
|
|
2482
|
+
},
|
|
2483
|
+
title: metadata.title ?? part.filename,
|
|
2484
|
+
...metadata.context && { context: metadata.context },
|
|
2485
|
+
...enableCitations && { citations: { enabled: true } },
|
|
2486
|
+
cache_control: cacheControl
|
|
2487
|
+
});
|
|
2488
|
+
} else if (part.mediaType === "text/plain") {
|
|
2489
|
+
const enableCitations = await shouldEnableCitations(part.providerOptions);
|
|
2490
|
+
const metadata = await getDocumentMetadata(part.providerOptions);
|
|
2491
|
+
anthropicContent.push({
|
|
2492
|
+
type: "document",
|
|
2493
|
+
source: part.data.type === "url" ? {
|
|
2494
|
+
type: "url",
|
|
2495
|
+
url: part.data.url.toString()
|
|
2496
|
+
} : {
|
|
2497
|
+
type: "text",
|
|
2498
|
+
media_type: "text/plain",
|
|
2499
|
+
data: convertBytesDataToString(part.data.data)
|
|
2500
|
+
},
|
|
2501
|
+
title: metadata.title ?? part.filename,
|
|
2502
|
+
...metadata.context && { context: metadata.context },
|
|
2503
|
+
...enableCitations && { citations: { enabled: true } },
|
|
2504
|
+
cache_control: cacheControl
|
|
2505
|
+
});
|
|
2506
|
+
} else throw new UnsupportedFunctionalityError({ functionality: `media type: ${part.mediaType}` });
|
|
2507
|
+
break;
|
|
2508
|
+
}
|
|
2497
2509
|
}
|
|
2510
|
+
break;
|
|
2498
2511
|
}
|
|
2499
2512
|
}
|
|
2500
2513
|
}
|
|
@@ -3564,18 +3577,20 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
3564
3577
|
type: "unsupported",
|
|
3565
3578
|
feature: "seed"
|
|
3566
3579
|
});
|
|
3567
|
-
|
|
3580
|
+
const maxTemperature = config.maxTemperature ?? 1;
|
|
3581
|
+
const temperatureProvider = config.maxTemperature == null ? "anthropic" : getProviderOptionsName(config.provider);
|
|
3582
|
+
if (temperature != null && temperature > maxTemperature) {
|
|
3568
3583
|
warnings.push({
|
|
3569
3584
|
type: "unsupported",
|
|
3570
3585
|
feature: "temperature",
|
|
3571
|
-
details: `${temperature} exceeds
|
|
3586
|
+
details: `${temperature} exceeds ${temperatureProvider} maximum of ${maxTemperature.toFixed(1)}. clamped to ${maxTemperature.toFixed(1)}`
|
|
3572
3587
|
});
|
|
3573
|
-
temperature =
|
|
3588
|
+
temperature = maxTemperature;
|
|
3574
3589
|
} else if (temperature != null && temperature < 0) {
|
|
3575
3590
|
warnings.push({
|
|
3576
3591
|
type: "unsupported",
|
|
3577
3592
|
feature: "temperature",
|
|
3578
|
-
details: `${temperature} is below
|
|
3593
|
+
details: `${temperature} is below ${temperatureProvider} minimum of 0. clamped to 0`
|
|
3579
3594
|
});
|
|
3580
3595
|
temperature = 0;
|
|
3581
3596
|
}
|
|
@@ -3661,7 +3676,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
3661
3676
|
argument: "providerOptions",
|
|
3662
3677
|
message: "Anthropic provider options `compaction` and `contextManagement` cannot be used together."
|
|
3663
3678
|
});
|
|
3664
|
-
const cacheControlValidator = new CacheControlValidator();
|
|
3679
|
+
const cacheControlValidator = new CacheControlValidator(config.cacheControlProviderOptionsName);
|
|
3665
3680
|
const toolNameMapping = createToolNameMapping({
|
|
3666
3681
|
tools,
|
|
3667
3682
|
providerToolNames: {
|
|
@@ -3697,7 +3712,8 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
3697
3712
|
warnings,
|
|
3698
3713
|
cacheControlValidator,
|
|
3699
3714
|
toolNameMapping,
|
|
3700
|
-
toolsetNames
|
|
3715
|
+
toolsetNames,
|
|
3716
|
+
convertMediaPart: config.convertMediaPart
|
|
3701
3717
|
});
|
|
3702
3718
|
if (isCustomReasoning(reasoning) && anthropicOptions?.effort == null) {
|
|
3703
3719
|
const reasoningConfig = resolveAnthropicReasoningConfig({
|
|
@@ -3869,7 +3885,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
3869
3885
|
};
|
|
3870
3886
|
thinkingBudget = 1024;
|
|
3871
3887
|
}
|
|
3872
|
-
if (baseArgs.temperature != null) {
|
|
3888
|
+
if (baseArgs.temperature != null && !config.supportsTemperatureAndTopPWithThinking) {
|
|
3873
3889
|
baseArgs.temperature = void 0;
|
|
3874
3890
|
warnings.push({
|
|
3875
3891
|
type: "unsupported",
|
|
@@ -3885,7 +3901,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
3885
3901
|
details: "topK is not supported when thinking is enabled"
|
|
3886
3902
|
});
|
|
3887
3903
|
}
|
|
3888
|
-
if (topP != null) {
|
|
3904
|
+
if (topP != null && !config.supportsTemperatureAndTopPWithThinking) {
|
|
3889
3905
|
baseArgs.top_p = void 0;
|
|
3890
3906
|
warnings.push({
|
|
3891
3907
|
type: "unsupported",
|