@core-ai/anthropic 0.18.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.
Files changed (2) hide show
  1. package/dist/index.js +34 -15
  2. 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);
@@ -448,6 +451,9 @@ function convertUserContentPart(part) {
448
451
  }
449
452
  };
450
453
  }
454
+ if (part.type === "audio") {
455
+ throw new ValidationError("Anthropic does not support audio input");
456
+ }
451
457
  if (part.mimeType !== "application/pdf") {
452
458
  throw new Error(
453
459
  "Anthropic only supports PDF file content in this abstraction"
@@ -547,7 +553,7 @@ function isObjectSchema(value) {
547
553
  function isJsonObject(value) {
548
554
  return value !== null && typeof value === "object" && !Array.isArray(value);
549
555
  }
550
- function createGenerateRequest(modelId, defaultMaxTokens, options, provider = DEFAULT_PROVIDER_ID, useStrictToolSchemas = true) {
556
+ function createGenerateRequest(modelId, defaultMaxTokens, options, provider = DEFAULT_PROVIDER_ID, useStrictToolSchemas = true, adapterOptions = {}) {
551
557
  const anthropicOptions = parseAnthropicGenerateProviderOptions(
552
558
  options.providerOptions
553
559
  );
@@ -557,11 +563,12 @@ function createGenerateRequest(modelId, defaultMaxTokens, options, provider = DE
557
563
  options,
558
564
  anthropicOptions,
559
565
  provider,
560
- useStrictToolSchemas
566
+ useStrictToolSchemas,
567
+ adapterOptions
561
568
  );
562
569
  return mapAnthropicProviderOptionsToRequest(baseRequest, anthropicOptions);
563
570
  }
564
- function createStreamRequest(modelId, defaultMaxTokens, options, provider = DEFAULT_PROVIDER_ID, useStrictToolSchemas = true) {
571
+ function createStreamRequest(modelId, defaultMaxTokens, options, provider = DEFAULT_PROVIDER_ID, useStrictToolSchemas = true, adapterOptions = {}) {
565
572
  const anthropicOptions = parseAnthropicGenerateProviderOptions(
566
573
  options.providerOptions
567
574
  );
@@ -572,26 +579,36 @@ function createStreamRequest(modelId, defaultMaxTokens, options, provider = DEFA
572
579
  options,
573
580
  anthropicOptions,
574
581
  provider,
575
- useStrictToolSchemas
582
+ useStrictToolSchemas,
583
+ adapterOptions
576
584
  ),
577
585
  stream: true
578
586
  };
579
587
  return mapAnthropicProviderOptionsToRequest(baseRequest, anthropicOptions);
580
588
  }
581
- function createRequestBase(modelId, defaultMaxTokens, options, anthropicOptions, provider, useStrictToolSchemas) {
589
+ function createRequestBase(modelId, defaultMaxTokens, options, anthropicOptions, provider, useStrictToolSchemas, adapterOptions) {
582
590
  const maxTokens = options.maxTokens ?? defaultMaxTokens;
591
+ const capabilities = adapterOptions.capabilities ?? getAnthropicModelCapabilities(modelId);
583
592
  validateAnthropicReasoningConfig(
584
593
  modelId,
585
594
  maxTokens,
586
595
  options,
587
596
  anthropicOptions,
588
- provider
597
+ provider,
598
+ capabilities
589
599
  );
600
+ validateInputModalities({
601
+ messages: options.messages,
602
+ capabilities,
603
+ modelId,
604
+ providerId: provider
605
+ });
590
606
  const converted = convertMessages(options.messages);
591
607
  const reasoningFields = mapReasoningToRequestFields(
592
608
  modelId,
593
609
  maxTokens,
594
- options
610
+ options,
611
+ capabilities
595
612
  );
596
613
  return {
597
614
  model: modelId,
@@ -610,7 +627,7 @@ function mapSamplingToRequestFields(options) {
610
627
  ...options.topP !== void 0 ? { top_p: options.topP } : {}
611
628
  };
612
629
  }
613
- function validateAnthropicReasoningConfig(modelId, maxTokens, options, anthropicOptions, provider) {
630
+ function validateAnthropicReasoningConfig(modelId, maxTokens, options, anthropicOptions, provider, capabilities) {
614
631
  const alwaysRestrictsSampling = restrictsAnthropicSamplingParamsAlways(modelId);
615
632
  if (alwaysRestrictsSampling && options.temperature !== void 0 && options.temperature !== 1) {
616
633
  throw new ValidationError(
@@ -643,7 +660,6 @@ function validateAnthropicReasoningConfig(modelId, maxTokens, options, anthropic
643
660
  provider
644
661
  );
645
662
  }
646
- const capabilities = getAnthropicModelCapabilities(modelId);
647
663
  if (options.temperature !== void 0 && (!alwaysRestrictsSampling || options.temperature !== 1)) {
648
664
  throw new ValidationError(
649
665
  `Anthropic model "${modelId}" does not support temperature when reasoning is enabled`,
@@ -674,12 +690,11 @@ function validateAnthropicReasoningConfig(modelId, maxTokens, options, anthropic
674
690
  );
675
691
  }
676
692
  }
677
- function mapReasoningToRequestFields(modelId, maxTokens, options) {
693
+ function mapReasoningToRequestFields(modelId, maxTokens, options, capabilities) {
678
694
  if (!options.reasoning) {
679
695
  return {};
680
696
  }
681
697
  const thinkingMode = getAnthropicThinkingMode(modelId);
682
- const capabilities = getAnthropicModelCapabilities(modelId);
683
698
  const effort = clampReasoningEffort(
684
699
  options.reasoning.effort,
685
700
  capabilities.reasoning.supportedEfforts
@@ -1021,6 +1036,8 @@ function createAnthropicChatModel(client, modelId, modelOptions = {}) {
1021
1036
  const defaultMaxTokens = modelOptions.defaultMaxTokens ?? 4096;
1022
1037
  const provider = modelOptions.providerId ?? DEFAULT_PROVIDER_ID;
1023
1038
  const useStrictToolSchemas = modelOptions.useStrictToolSchemas ?? true;
1039
+ const capabilities = getAnthropicModelCapabilities(modelId);
1040
+ const adapterOptions = { capabilities };
1024
1041
  async function callAnthropicMessagesApi(request, betas, signal) {
1025
1042
  try {
1026
1043
  return await client.messages.create(request, {
@@ -1041,7 +1058,8 @@ function createAnthropicChatModel(client, modelId, modelOptions = {}) {
1041
1058
  defaultMaxTokens,
1042
1059
  options,
1043
1060
  provider,
1044
- useStrictToolSchemas
1061
+ useStrictToolSchemas,
1062
+ adapterOptions
1045
1063
  );
1046
1064
  const response = await callAnthropicMessagesApi(request, getAnthropicRequestBetas(modelId, options), options.signal);
1047
1065
  return mapGenerateResponse(response);
@@ -1052,7 +1070,8 @@ function createAnthropicChatModel(client, modelId, modelOptions = {}) {
1052
1070
  defaultMaxTokens,
1053
1071
  options,
1054
1072
  provider,
1055
- useStrictToolSchemas
1073
+ useStrictToolSchemas,
1074
+ adapterOptions
1056
1075
  );
1057
1076
  return createChatStream(
1058
1077
  async () => transformStream(
@@ -1068,7 +1087,7 @@ function createAnthropicChatModel(client, modelId, modelOptions = {}) {
1068
1087
  return {
1069
1088
  provider,
1070
1089
  modelId,
1071
- capabilities: getAnthropicModelCapabilities(modelId),
1090
+ capabilities,
1072
1091
  generate: generateChat,
1073
1092
  stream: streamChat,
1074
1093
  async generateObject(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@core-ai/anthropic",
3
- "version": "0.18.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.18.0"
48
+ "@core-ai/core-ai": "^0.19.0"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "zod": "^4.0.0"