@core-ai/anthropic 0.24.0 → 0.26.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.d.ts CHANGED
@@ -16,12 +16,10 @@ type AnthropicChatProviderOptions = {
16
16
  };
17
17
  /**
18
18
  * Factory options for sibling packages that compose Anthropic chat.
19
- * Not part of {@link createAnthropic} / {@link AnthropicProviderOptions}
20
- * first-party Anthropic always uses strict tool schemas.
19
+ * Not part of {@link createAnthropic} / {@link AnthropicProviderOptions}.
21
20
  */
22
21
  type AnthropicChatProviderFactoryOptions = {
23
22
  providerId?: string;
24
- useStrictToolSchemas?: boolean;
25
23
  };
26
24
  type AnthropicChatProvider = {
27
25
  chatModel(modelId: string): ChatModel;
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  ValidationError,
10
10
  safeParseJsonObject,
11
11
  validateInputModalities,
12
+ validateToolSchemaStrictness,
12
13
  zodSchemaToJsonSchema
13
14
  } from "@core-ai/core-ai";
14
15
 
@@ -191,6 +192,8 @@ function getAnthropicErrorType(error) {
191
192
  // src/model-capabilities.ts
192
193
  import {
193
194
  MULTIMODAL_INPUT_MODALITIES,
195
+ SUPPORTED_TOOL_SCHEMA_STRICTNESS,
196
+ UNSUPPORTED_TOOL_SCHEMA_STRICTNESS,
194
197
  stripModelDateSuffix
195
198
  } from "@core-ai/core-ai";
196
199
  var STANDARD_EFFORTS = [
@@ -206,7 +209,7 @@ var MAX_EFFORTS = [
206
209
  "high",
207
210
  "max"
208
211
  ];
209
- function createCapabilities(supportedEfforts) {
212
+ function createCapabilities(supportedEfforts, supportsStrictToolSchemas) {
210
213
  return {
211
214
  reasoning: {
212
215
  mode: "optional",
@@ -214,11 +217,19 @@ function createCapabilities(supportedEfforts) {
214
217
  restrictsSamplingParams: true,
215
218
  supportedToolChoices: ["auto", "none"]
216
219
  },
217
- modalities: MULTIMODAL_INPUT_MODALITIES
220
+ modalities: MULTIMODAL_INPUT_MODALITIES,
221
+ tools: {
222
+ // The cap is enforced by the API but absent from Anthropic's docs
223
+ // pages; the rejection reads: 'Too many strict tools (22). The
224
+ // maximum number of strict tools supported is 20. Try reducing
225
+ // the number of tools marked as strict.'
226
+ strictSchemas: supportsStrictToolSchemas ? {
227
+ ...SUPPORTED_TOOL_SCHEMA_STRICTNESS,
228
+ maxStrictTools: 20
229
+ } : UNSUPPORTED_TOOL_SCHEMA_STRICTNESS
230
+ }
218
231
  };
219
232
  }
220
- var STANDARD_CAPABILITIES = createCapabilities(STANDARD_EFFORTS);
221
- var MAX_EFFORT_CAPABILITIES = createCapabilities(MAX_EFFORTS);
222
233
  var ADAPTIVE_MAX_EFFORT_MODELS = /* @__PURE__ */ new Set([
223
234
  "claude-fable-5",
224
235
  "claude-mythos-5",
@@ -230,6 +241,23 @@ var ADAPTIVE_MAX_EFFORT_MODELS = /* @__PURE__ */ new Set([
230
241
  "claude-sonnet-5",
231
242
  "claude-sonnet-4-6"
232
243
  ]);
244
+ var NON_STRICT_TOOL_SCHEMA_MODELS = /* @__PURE__ */ new Set([
245
+ "claude-opus-4-1",
246
+ "claude-opus-4",
247
+ "claude-sonnet-4",
248
+ "claude-sonnet-3-7",
249
+ "claude-3-7-sonnet",
250
+ "claude-3-5-sonnet",
251
+ "claude-3-5-haiku",
252
+ "claude-3-opus",
253
+ "claude-3-sonnet",
254
+ "claude-3-haiku",
255
+ "claude-2.1",
256
+ "claude-2.0",
257
+ "claude-2",
258
+ "claude-instant-1.2",
259
+ "claude-instant-1"
260
+ ]);
233
261
  var MANUAL_THINKING_MODELS = /* @__PURE__ */ new Set([
234
262
  "claude-opus-4-5",
235
263
  "claude-sonnet-4-5",
@@ -269,10 +297,11 @@ var ANTHROPIC_MANUAL_BUDGET_MAP = {
269
297
  max: 65536
270
298
  };
271
299
  function getAnthropicModelCapabilities(modelId) {
272
- if (supportsAnthropicMaxEffort(modelId) || getAnthropicThinkingMode(modelId) === "manual") {
273
- return MAX_EFFORT_CAPABILITIES;
274
- }
275
- return STANDARD_CAPABILITIES;
300
+ const supportedEfforts = supportsAnthropicMaxEffort(modelId) || getAnthropicThinkingMode(modelId) === "manual" ? MAX_EFFORTS : STANDARD_EFFORTS;
301
+ return createCapabilities(
302
+ supportedEfforts,
303
+ supportsAnthropicStrictToolSchemas(modelId)
304
+ );
276
305
  }
277
306
  function normalizeModelId(modelId) {
278
307
  return stripModelDateSuffix(modelId);
@@ -283,6 +312,9 @@ function getAnthropicThinkingMode(modelId) {
283
312
  function supportsAnthropicMaxEffort(modelId) {
284
313
  return ADAPTIVE_MAX_EFFORT_MODELS.has(normalizeModelId(modelId));
285
314
  }
315
+ function supportsAnthropicStrictToolSchemas(modelId) {
316
+ return !NON_STRICT_TOOL_SCHEMA_MODELS.has(normalizeModelId(modelId));
317
+ }
286
318
  function requiresAnthropicInterleavedThinkingBeta(modelId) {
287
319
  return MANUAL_INTERLEAVED_THINKING_MODELS.has(normalizeModelId(modelId));
288
320
  }
@@ -478,14 +510,15 @@ function convertUserContentPart(part) {
478
510
  }
479
511
  };
480
512
  }
481
- function convertTools(tools, useStrictToolSchemas = true) {
513
+ function convertTools(tools) {
482
514
  return Object.values(tools).map((tool) => {
483
- const schema = toAnthropicJsonSchema(tool.parameters);
515
+ const strict = tool.strict === true;
516
+ const schema = strict ? toAnthropicJsonSchema(tool.parameters) : zodSchemaToJsonSchema(tool.parameters);
484
517
  return {
485
518
  name: tool.name,
486
519
  description: tool.description,
487
520
  input_schema: schema,
488
- ...useStrictToolSchemas ? { strict: true } : {}
521
+ ...strict ? { strict: true } : {}
489
522
  };
490
523
  });
491
524
  }
@@ -552,6 +585,10 @@ function normalizeAnthropicJsonValue(value) {
552
585
  }
553
586
  normalized[key] = normalizeAnthropicJsonValue(child);
554
587
  }
588
+ if (Array.isArray(normalized.oneOf) && normalized.anyOf === void 0) {
589
+ normalized.anyOf = normalized.oneOf;
590
+ delete normalized.oneOf;
591
+ }
555
592
  if (isObjectSchema(normalized)) {
556
593
  normalized.additionalProperties = false;
557
594
  }
@@ -563,7 +600,7 @@ function isObjectSchema(value) {
563
600
  function isJsonObject(value) {
564
601
  return value !== null && typeof value === "object" && !Array.isArray(value);
565
602
  }
566
- function createGenerateRequest(modelId, defaultMaxTokens, options, provider = DEFAULT_PROVIDER_ID, useStrictToolSchemas = true, adapterOptions = {}) {
603
+ function createGenerateRequest(modelId, defaultMaxTokens, options, provider = DEFAULT_PROVIDER_ID, adapterOptions = {}) {
567
604
  const anthropicOptions = parseAnthropicGenerateProviderOptions(
568
605
  options.providerOptions
569
606
  );
@@ -573,12 +610,11 @@ function createGenerateRequest(modelId, defaultMaxTokens, options, provider = DE
573
610
  options,
574
611
  anthropicOptions,
575
612
  provider,
576
- useStrictToolSchemas,
577
613
  adapterOptions
578
614
  );
579
615
  return mapAnthropicProviderOptionsToRequest(baseRequest, anthropicOptions);
580
616
  }
581
- function createStreamRequest(modelId, defaultMaxTokens, options, provider = DEFAULT_PROVIDER_ID, useStrictToolSchemas = true, adapterOptions = {}) {
617
+ function createStreamRequest(modelId, defaultMaxTokens, options, provider = DEFAULT_PROVIDER_ID, adapterOptions = {}) {
582
618
  const anthropicOptions = parseAnthropicGenerateProviderOptions(
583
619
  options.providerOptions
584
620
  );
@@ -589,14 +625,13 @@ function createStreamRequest(modelId, defaultMaxTokens, options, provider = DEFA
589
625
  options,
590
626
  anthropicOptions,
591
627
  provider,
592
- useStrictToolSchemas,
593
628
  adapterOptions
594
629
  ),
595
630
  stream: true
596
631
  };
597
632
  return mapAnthropicProviderOptionsToRequest(baseRequest, anthropicOptions);
598
633
  }
599
- function createRequestBase(modelId, defaultMaxTokens, options, anthropicOptions, provider, useStrictToolSchemas, adapterOptions) {
634
+ function createRequestBase(modelId, defaultMaxTokens, options, anthropicOptions, provider, adapterOptions) {
600
635
  const maxTokens = options.maxTokens ?? defaultMaxTokens;
601
636
  const capabilities = adapterOptions.capabilities ?? getAnthropicModelCapabilities(modelId);
602
637
  validateAnthropicReasoningConfig(
@@ -620,12 +655,20 @@ function createRequestBase(modelId, defaultMaxTokens, options, anthropicOptions,
620
655
  options,
621
656
  capabilities
622
657
  );
658
+ if (options.tools) {
659
+ validateToolSchemaStrictness({
660
+ tools: options.tools,
661
+ capabilities,
662
+ providerId: provider,
663
+ modelId
664
+ });
665
+ }
623
666
  return {
624
667
  model: modelId,
625
668
  messages: converted.messages,
626
669
  max_tokens: maxTokens,
627
670
  ...converted.system ? { system: converted.system } : {},
628
- ...options.tools && Object.keys(options.tools).length > 0 ? { tools: convertTools(options.tools, useStrictToolSchemas) } : {},
671
+ ...options.tools && Object.keys(options.tools).length > 0 ? { tools: convertTools(options.tools) } : {},
629
672
  ...options.toolChoice ? { tool_choice: convertToolChoice(options.toolChoice) } : {},
630
673
  ...reasoningFields,
631
674
  ...mapSamplingToRequestFields(options)
@@ -1045,7 +1088,6 @@ import {
1045
1088
  function createAnthropicChatModel(client, modelId, modelOptions = {}) {
1046
1089
  const defaultMaxTokens = modelOptions.defaultMaxTokens ?? 4096;
1047
1090
  const provider = modelOptions.providerId ?? DEFAULT_PROVIDER_ID;
1048
- const useStrictToolSchemas = modelOptions.useStrictToolSchemas ?? true;
1049
1091
  const capabilities = getAnthropicModelCapabilities(modelId);
1050
1092
  const adapterOptions = { capabilities };
1051
1093
  async function callAnthropicMessagesApi(request, betas, signal) {
@@ -1068,7 +1110,6 @@ function createAnthropicChatModel(client, modelId, modelOptions = {}) {
1068
1110
  defaultMaxTokens,
1069
1111
  options,
1070
1112
  provider,
1071
- useStrictToolSchemas,
1072
1113
  adapterOptions
1073
1114
  );
1074
1115
  const response = await callAnthropicMessagesApi(request, getAnthropicRequestBetas(modelId, options), options.signal);
@@ -1080,7 +1121,6 @@ function createAnthropicChatModel(client, modelId, modelOptions = {}) {
1080
1121
  defaultMaxTokens,
1081
1122
  options,
1082
1123
  provider,
1083
- useStrictToolSchemas,
1084
1124
  adapterOptions
1085
1125
  );
1086
1126
  return createChatStream(
@@ -1259,12 +1299,10 @@ function createAnthropicChatProvider(options = {}, factoryOptions = {}) {
1259
1299
  });
1260
1300
  const defaultMaxTokens = options.defaultMaxTokens ?? 4096;
1261
1301
  const providerId = factoryOptions.providerId ?? DEFAULT_PROVIDER_ID;
1262
- const useStrictToolSchemas = factoryOptions.useStrictToolSchemas ?? true;
1263
1302
  return {
1264
1303
  chatModel: (modelId) => createAnthropicChatModel(client, modelId, {
1265
1304
  defaultMaxTokens,
1266
- providerId,
1267
- useStrictToolSchemas
1305
+ providerId
1268
1306
  })
1269
1307
  };
1270
1308
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@core-ai/anthropic",
3
- "version": "0.24.0",
3
+ "version": "0.26.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.24.0"
48
+ "@core-ai/core-ai": "^0.26.0"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "zod": "^4.0.0"