@core-ai/anthropic 0.17.0 → 0.19.0
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/dist/index.js +36 -15
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
getProviderMetadata,
|
|
9
9
|
ValidationError,
|
|
10
10
|
safeParseJsonObject,
|
|
11
|
+
validateInputModalities,
|
|
11
12
|
zodSchemaToJsonSchema
|
|
12
13
|
} from "@core-ai/core-ai";
|
|
13
14
|
|
|
@@ -179,6 +180,7 @@ function getAnthropicErrorType(error) {
|
|
|
179
180
|
|
|
180
181
|
// src/model-capabilities.ts
|
|
181
182
|
import {
|
|
183
|
+
MULTIMODAL_INPUT_MODALITIES,
|
|
182
184
|
stripModelDateSuffix
|
|
183
185
|
} from "@core-ai/core-ai";
|
|
184
186
|
var STANDARD_EFFORTS = [
|
|
@@ -201,7 +203,8 @@ function createCapabilities(supportedEfforts) {
|
|
|
201
203
|
supportedEfforts,
|
|
202
204
|
restrictsSamplingParams: true,
|
|
203
205
|
supportedToolChoices: ["auto", "none"]
|
|
204
|
-
}
|
|
206
|
+
},
|
|
207
|
+
modalities: MULTIMODAL_INPUT_MODALITIES
|
|
205
208
|
};
|
|
206
209
|
}
|
|
207
210
|
var STANDARD_CAPABILITIES = createCapabilities(STANDARD_EFFORTS);
|
|
@@ -210,6 +213,7 @@ var ADAPTIVE_MAX_EFFORT_MODELS = /* @__PURE__ */ new Set([
|
|
|
210
213
|
"claude-fable-5",
|
|
211
214
|
"claude-mythos-5",
|
|
212
215
|
"claude-mythos-preview",
|
|
216
|
+
"claude-opus-5",
|
|
213
217
|
"claude-opus-4-8",
|
|
214
218
|
"claude-opus-4-7",
|
|
215
219
|
"claude-opus-4-6",
|
|
@@ -236,6 +240,7 @@ var ALWAYS_RESTRICTED_SAMPLING_MODELS = /* @__PURE__ */ new Set([
|
|
|
236
240
|
"claude-fable-5",
|
|
237
241
|
"claude-mythos-5",
|
|
238
242
|
"claude-mythos-preview",
|
|
243
|
+
"claude-opus-5",
|
|
239
244
|
"claude-opus-4-8",
|
|
240
245
|
"claude-opus-4-7",
|
|
241
246
|
"claude-sonnet-5"
|
|
@@ -446,6 +451,9 @@ function convertUserContentPart(part) {
|
|
|
446
451
|
}
|
|
447
452
|
};
|
|
448
453
|
}
|
|
454
|
+
if (part.type === "audio") {
|
|
455
|
+
throw new ValidationError("Anthropic does not support audio input");
|
|
456
|
+
}
|
|
449
457
|
if (part.mimeType !== "application/pdf") {
|
|
450
458
|
throw new Error(
|
|
451
459
|
"Anthropic only supports PDF file content in this abstraction"
|
|
@@ -545,7 +553,7 @@ function isObjectSchema(value) {
|
|
|
545
553
|
function isJsonObject(value) {
|
|
546
554
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
547
555
|
}
|
|
548
|
-
function createGenerateRequest(modelId, defaultMaxTokens, options, provider = DEFAULT_PROVIDER_ID, useStrictToolSchemas = true) {
|
|
556
|
+
function createGenerateRequest(modelId, defaultMaxTokens, options, provider = DEFAULT_PROVIDER_ID, useStrictToolSchemas = true, adapterOptions = {}) {
|
|
549
557
|
const anthropicOptions = parseAnthropicGenerateProviderOptions(
|
|
550
558
|
options.providerOptions
|
|
551
559
|
);
|
|
@@ -555,11 +563,12 @@ function createGenerateRequest(modelId, defaultMaxTokens, options, provider = DE
|
|
|
555
563
|
options,
|
|
556
564
|
anthropicOptions,
|
|
557
565
|
provider,
|
|
558
|
-
useStrictToolSchemas
|
|
566
|
+
useStrictToolSchemas,
|
|
567
|
+
adapterOptions
|
|
559
568
|
);
|
|
560
569
|
return mapAnthropicProviderOptionsToRequest(baseRequest, anthropicOptions);
|
|
561
570
|
}
|
|
562
|
-
function createStreamRequest(modelId, defaultMaxTokens, options, provider = DEFAULT_PROVIDER_ID, useStrictToolSchemas = true) {
|
|
571
|
+
function createStreamRequest(modelId, defaultMaxTokens, options, provider = DEFAULT_PROVIDER_ID, useStrictToolSchemas = true, adapterOptions = {}) {
|
|
563
572
|
const anthropicOptions = parseAnthropicGenerateProviderOptions(
|
|
564
573
|
options.providerOptions
|
|
565
574
|
);
|
|
@@ -570,26 +579,36 @@ function createStreamRequest(modelId, defaultMaxTokens, options, provider = DEFA
|
|
|
570
579
|
options,
|
|
571
580
|
anthropicOptions,
|
|
572
581
|
provider,
|
|
573
|
-
useStrictToolSchemas
|
|
582
|
+
useStrictToolSchemas,
|
|
583
|
+
adapterOptions
|
|
574
584
|
),
|
|
575
585
|
stream: true
|
|
576
586
|
};
|
|
577
587
|
return mapAnthropicProviderOptionsToRequest(baseRequest, anthropicOptions);
|
|
578
588
|
}
|
|
579
|
-
function createRequestBase(modelId, defaultMaxTokens, options, anthropicOptions, provider, useStrictToolSchemas) {
|
|
589
|
+
function createRequestBase(modelId, defaultMaxTokens, options, anthropicOptions, provider, useStrictToolSchemas, adapterOptions) {
|
|
580
590
|
const maxTokens = options.maxTokens ?? defaultMaxTokens;
|
|
591
|
+
const capabilities = adapterOptions.capabilities ?? getAnthropicModelCapabilities(modelId);
|
|
581
592
|
validateAnthropicReasoningConfig(
|
|
582
593
|
modelId,
|
|
583
594
|
maxTokens,
|
|
584
595
|
options,
|
|
585
596
|
anthropicOptions,
|
|
586
|
-
provider
|
|
597
|
+
provider,
|
|
598
|
+
capabilities
|
|
587
599
|
);
|
|
600
|
+
validateInputModalities({
|
|
601
|
+
messages: options.messages,
|
|
602
|
+
capabilities,
|
|
603
|
+
modelId,
|
|
604
|
+
providerId: provider
|
|
605
|
+
});
|
|
588
606
|
const converted = convertMessages(options.messages);
|
|
589
607
|
const reasoningFields = mapReasoningToRequestFields(
|
|
590
608
|
modelId,
|
|
591
609
|
maxTokens,
|
|
592
|
-
options
|
|
610
|
+
options,
|
|
611
|
+
capabilities
|
|
593
612
|
);
|
|
594
613
|
return {
|
|
595
614
|
model: modelId,
|
|
@@ -608,7 +627,7 @@ function mapSamplingToRequestFields(options) {
|
|
|
608
627
|
...options.topP !== void 0 ? { top_p: options.topP } : {}
|
|
609
628
|
};
|
|
610
629
|
}
|
|
611
|
-
function validateAnthropicReasoningConfig(modelId, maxTokens, options, anthropicOptions, provider) {
|
|
630
|
+
function validateAnthropicReasoningConfig(modelId, maxTokens, options, anthropicOptions, provider, capabilities) {
|
|
612
631
|
const alwaysRestrictsSampling = restrictsAnthropicSamplingParamsAlways(modelId);
|
|
613
632
|
if (alwaysRestrictsSampling && options.temperature !== void 0 && options.temperature !== 1) {
|
|
614
633
|
throw new ValidationError(
|
|
@@ -641,7 +660,6 @@ function validateAnthropicReasoningConfig(modelId, maxTokens, options, anthropic
|
|
|
641
660
|
provider
|
|
642
661
|
);
|
|
643
662
|
}
|
|
644
|
-
const capabilities = getAnthropicModelCapabilities(modelId);
|
|
645
663
|
if (options.temperature !== void 0 && (!alwaysRestrictsSampling || options.temperature !== 1)) {
|
|
646
664
|
throw new ValidationError(
|
|
647
665
|
`Anthropic model "${modelId}" does not support temperature when reasoning is enabled`,
|
|
@@ -672,12 +690,11 @@ function validateAnthropicReasoningConfig(modelId, maxTokens, options, anthropic
|
|
|
672
690
|
);
|
|
673
691
|
}
|
|
674
692
|
}
|
|
675
|
-
function mapReasoningToRequestFields(modelId, maxTokens, options) {
|
|
693
|
+
function mapReasoningToRequestFields(modelId, maxTokens, options, capabilities) {
|
|
676
694
|
if (!options.reasoning) {
|
|
677
695
|
return {};
|
|
678
696
|
}
|
|
679
697
|
const thinkingMode = getAnthropicThinkingMode(modelId);
|
|
680
|
-
const capabilities = getAnthropicModelCapabilities(modelId);
|
|
681
698
|
const effort = clampReasoningEffort(
|
|
682
699
|
options.reasoning.effort,
|
|
683
700
|
capabilities.reasoning.supportedEfforts
|
|
@@ -1019,6 +1036,8 @@ function createAnthropicChatModel(client, modelId, modelOptions = {}) {
|
|
|
1019
1036
|
const defaultMaxTokens = modelOptions.defaultMaxTokens ?? 4096;
|
|
1020
1037
|
const provider = modelOptions.providerId ?? DEFAULT_PROVIDER_ID;
|
|
1021
1038
|
const useStrictToolSchemas = modelOptions.useStrictToolSchemas ?? true;
|
|
1039
|
+
const capabilities = getAnthropicModelCapabilities(modelId);
|
|
1040
|
+
const adapterOptions = { capabilities };
|
|
1022
1041
|
async function callAnthropicMessagesApi(request, betas, signal) {
|
|
1023
1042
|
try {
|
|
1024
1043
|
return await client.messages.create(request, {
|
|
@@ -1039,7 +1058,8 @@ function createAnthropicChatModel(client, modelId, modelOptions = {}) {
|
|
|
1039
1058
|
defaultMaxTokens,
|
|
1040
1059
|
options,
|
|
1041
1060
|
provider,
|
|
1042
|
-
useStrictToolSchemas
|
|
1061
|
+
useStrictToolSchemas,
|
|
1062
|
+
adapterOptions
|
|
1043
1063
|
);
|
|
1044
1064
|
const response = await callAnthropicMessagesApi(request, getAnthropicRequestBetas(modelId, options), options.signal);
|
|
1045
1065
|
return mapGenerateResponse(response);
|
|
@@ -1050,7 +1070,8 @@ function createAnthropicChatModel(client, modelId, modelOptions = {}) {
|
|
|
1050
1070
|
defaultMaxTokens,
|
|
1051
1071
|
options,
|
|
1052
1072
|
provider,
|
|
1053
|
-
useStrictToolSchemas
|
|
1073
|
+
useStrictToolSchemas,
|
|
1074
|
+
adapterOptions
|
|
1054
1075
|
);
|
|
1055
1076
|
return createChatStream(
|
|
1056
1077
|
async () => transformStream(
|
|
@@ -1066,7 +1087,7 @@ function createAnthropicChatModel(client, modelId, modelOptions = {}) {
|
|
|
1066
1087
|
return {
|
|
1067
1088
|
provider,
|
|
1068
1089
|
modelId,
|
|
1069
|
-
capabilities
|
|
1090
|
+
capabilities,
|
|
1070
1091
|
generate: generateChat,
|
|
1071
1092
|
stream: streamChat,
|
|
1072
1093
|
async generateObject(options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@core-ai/anthropic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Anthropic provider package for @core-ai/core-ai",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Omnifact (https://omnifact.ai)",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@anthropic-ai/sdk": "^0.110.0",
|
|
48
|
-
"@core-ai/core-ai": "^0.
|
|
48
|
+
"@core-ai/core-ai": "^0.19.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"zod": "^4.0.0"
|