@ax-llm/ax 11.0.55 → 11.0.57

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/index.d.cts CHANGED
@@ -166,6 +166,7 @@ type AxModelInfo = {
166
166
  aliases?: string[];
167
167
  hasThinkingBudget?: boolean;
168
168
  hasShowThoughts?: boolean;
169
+ maxTokens?: number;
169
170
  };
170
171
  type AxTokenUsage = {
171
172
  promptTokens: number;
@@ -386,6 +387,8 @@ interface AxAIServiceImpl<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TCha
386
387
  }
387
388
 
388
389
  declare enum AxAIAnthropicModel {
390
+ Claude4Opus = "claude-opus-4-20250514",
391
+ Claude4Sonnet = "claude-sonnet-4-20250514",
389
392
  Claude37Sonnet = "claude-3-7-sonnet-latest",
390
393
  Claude35Sonnet = "claude-3-5-sonnet-latest",
391
394
  Claude35Haiku = "claude-3-5-haiku-latest",
package/index.d.ts CHANGED
@@ -166,6 +166,7 @@ type AxModelInfo = {
166
166
  aliases?: string[];
167
167
  hasThinkingBudget?: boolean;
168
168
  hasShowThoughts?: boolean;
169
+ maxTokens?: number;
169
170
  };
170
171
  type AxTokenUsage = {
171
172
  promptTokens: number;
@@ -386,6 +387,8 @@ interface AxAIServiceImpl<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TCha
386
387
  }
387
388
 
388
389
  declare enum AxAIAnthropicModel {
390
+ Claude4Opus = "claude-opus-4-20250514",
391
+ Claude4Sonnet = "claude-sonnet-4-20250514",
389
392
  Claude37Sonnet = "claude-3-7-sonnet-latest",
390
393
  Claude35Sonnet = "claude-3-5-sonnet-latest",
391
394
  Claude35Haiku = "claude-3-5-haiku-latest",
package/index.js CHANGED
@@ -1425,6 +1425,8 @@ var GoogleVertexAuth = class {
1425
1425
 
1426
1426
  // ai/anthropic/types.ts
1427
1427
  var AxAIAnthropicModel = /* @__PURE__ */ ((AxAIAnthropicModel2) => {
1428
+ AxAIAnthropicModel2["Claude4Opus"] = "claude-opus-4-20250514";
1429
+ AxAIAnthropicModel2["Claude4Sonnet"] = "claude-sonnet-4-20250514";
1428
1430
  AxAIAnthropicModel2["Claude37Sonnet"] = "claude-3-7-sonnet-latest";
1429
1431
  AxAIAnthropicModel2["Claude35Sonnet"] = "claude-3-5-sonnet-latest";
1430
1432
  AxAIAnthropicModel2["Claude35Haiku"] = "claude-3-5-haiku-latest";
@@ -1447,50 +1449,80 @@ var AxAIAnthropicVertexModel = /* @__PURE__ */ ((AxAIAnthropicVertexModel2) => {
1447
1449
 
1448
1450
  // ai/anthropic/info.ts
1449
1451
  var axModelInfoAnthropic = [
1450
- // 35
1452
+ // 4
1453
+ {
1454
+ name: "claude-opus-4-20250514" /* Claude4Opus */,
1455
+ currency: "usd",
1456
+ promptTokenCostPer1M: 15,
1457
+ completionTokenCostPer1M: 75,
1458
+ maxTokens: 32e3
1459
+ },
1460
+ {
1461
+ name: "claude-sonnet-4-20250514" /* Claude4Sonnet */,
1462
+ currency: "usd",
1463
+ promptTokenCostPer1M: 3,
1464
+ completionTokenCostPer1M: 15,
1465
+ maxTokens: 64e3
1466
+ },
1467
+ // 3.7
1468
+ {
1469
+ name: "claude-3-7-sonnet-latest" /* Claude37Sonnet */,
1470
+ currency: "usd",
1471
+ promptTokenCostPer1M: 3,
1472
+ completionTokenCostPer1M: 15,
1473
+ maxTokens: 64e3
1474
+ },
1475
+ // 3.5
1451
1476
  {
1452
1477
  name: "claude-3-5-sonnet-latest" /* Claude35Sonnet */,
1453
1478
  currency: "usd",
1454
1479
  promptTokenCostPer1M: 3,
1455
- completionTokenCostPer1M: 15
1480
+ completionTokenCostPer1M: 15,
1481
+ maxTokens: 8192
1456
1482
  },
1457
1483
  {
1458
1484
  name: "claude-3-5-haiku-latest" /* Claude35Haiku */,
1459
1485
  currency: "usd",
1460
1486
  promptTokenCostPer1M: 0.8,
1461
- completionTokenCostPer1M: 4
1487
+ completionTokenCostPer1M: 4,
1488
+ maxTokens: 8192
1462
1489
  },
1463
1490
  // 3
1464
1491
  {
1465
1492
  name: "claude-3-opus-latest" /* Claude3Opus */,
1466
1493
  currency: "usd",
1467
1494
  promptTokenCostPer1M: 15,
1468
- completionTokenCostPer1M: 75
1495
+ completionTokenCostPer1M: 75,
1496
+ maxTokens: 4096
1469
1497
  },
1470
1498
  {
1471
1499
  name: "claude-3-sonnet-20240229" /* Claude3Sonnet */,
1472
1500
  currency: "usd",
1473
1501
  promptTokenCostPer1M: 3,
1474
- completionTokenCostPer1M: 15
1502
+ completionTokenCostPer1M: 15,
1503
+ maxTokens: 4096
1475
1504
  },
1476
1505
  {
1477
1506
  name: "claude-3-haiku-20240307" /* Claude3Haiku */,
1478
1507
  currency: "usd",
1479
1508
  promptTokenCostPer1M: 0.25,
1480
- completionTokenCostPer1M: 1.25
1509
+ completionTokenCostPer1M: 1.25,
1510
+ maxTokens: 4096
1481
1511
  },
1482
- // 21
1512
+ // 2.1
1483
1513
  {
1484
1514
  name: "claude-2.1" /* Claude21 */,
1485
1515
  currency: "usd",
1486
1516
  promptTokenCostPer1M: 8,
1487
- completionTokenCostPer1M: 25
1517
+ completionTokenCostPer1M: 25,
1518
+ maxTokens: 4096
1488
1519
  },
1489
1520
  {
1490
1521
  name: "claude-instant-1.2" /* ClaudeInstant12 */,
1491
1522
  currency: "usd",
1492
1523
  promptTokenCostPer1M: 0.8,
1493
- completionTokenCostPer1M: 2.24
1524
+ completionTokenCostPer1M: 2.24,
1525
+ maxTokens: 4096
1494
1526
  }
1495
1527
  ];
1496
1528
 
@@ -1515,7 +1547,7 @@ var AxAIAnthropicImpl = class {
1515
1547
  getModelConfig() {
1516
1548
  const { config } = this;
1517
1549
  return {
1518
- maxTokens: config.maxTokens,
1550
+ maxTokens: config.maxTokens ?? 4096,
1519
1551
  temperature: config.temperature,
1520
1552
  topP: config.topP,
1521
1553
  topK: config.topK,
@@ -1578,13 +1610,18 @@ var AxAIAnthropicImpl = class {
1578
1610
  input_schema: v.parameters
1579
1611
  })
1580
1612
  );
1613
+ const maxTokens = req.modelConfig?.maxTokens ?? this.config.maxTokens;
1614
+ const stopSequences = req.modelConfig?.stopSequences ?? this.config.stopSequences;
1615
+ const temperature = req.modelConfig?.temperature ?? this.config.temperature;
1616
+ const topP = req.modelConfig?.topP ?? this.config.topP;
1617
+ const topK = req.modelConfig?.topK ?? this.config.topK;
1581
1618
  const reqValue = {
1582
1619
  ...this.isVertex ? { anthropic_version: "vertex-2023-10-16" } : { model },
1583
- max_tokens: req.modelConfig?.maxTokens ?? this.config.maxTokens,
1584
- stop_sequences: req.modelConfig?.stopSequences ?? this.config.stopSequences,
1585
- temperature: req.modelConfig?.temperature ?? this.config.temperature,
1586
- top_p: req.modelConfig?.topP ?? this.config.topP,
1587
- top_k: req.modelConfig?.topK ?? this.config.topK,
1620
+ ...maxTokens ? { max_tokens: maxTokens } : {},
1621
+ ...stopSequences && stopSequences.length > 0 ? { stop_sequences: stopSequences } : {},
1622
+ ...temperature ? { temperature } : {},
1623
+ ...topP ? { top_p: topP } : {},
1624
+ ...topK ? { top_k: topK } : {},
1588
1625
  ...toolsChoice,
1589
1626
  ...tools && tools.length > 0 ? { tools } : {},
1590
1627
  ...stream ? { stream: true } : {},
@@ -6730,6 +6767,9 @@ function getFieldProcessingMessage(field, resultText) {
6730
6767
  var validateJSONSchema = (schema) => {
6731
6768
  const errors = [];
6732
6769
  const validateSchemaObject = (schema2, path = "") => {
6770
+ if (!schema2 || typeof schema2 !== "object") {
6771
+ return;
6772
+ }
6733
6773
  const validTypes = [
6734
6774
  "array",
6735
6775
  "integer",
@@ -6739,38 +6779,155 @@ var validateJSONSchema = (schema) => {
6739
6779
  "null",
6740
6780
  "object"
6741
6781
  ];
6782
+ if (schema2.anyOf && Array.isArray(schema2.anyOf)) {
6783
+ if (schema2.anyOf.length === 0) {
6784
+ errors.push({
6785
+ path: path || "root",
6786
+ issue: "anyOf array is empty",
6787
+ fix: "Add at least one schema to the anyOf array",
6788
+ example: 'anyOf: [{ type: "string" }, { type: "null" }]'
6789
+ });
6790
+ }
6791
+ schema2.anyOf.forEach((subSchema, index) => {
6792
+ validateSchemaObject(subSchema, `${path}anyOf[${index}].`);
6793
+ });
6794
+ return;
6795
+ }
6796
+ if (schema2.oneOf && Array.isArray(schema2.oneOf)) {
6797
+ if (schema2.oneOf.length === 0) {
6798
+ errors.push({
6799
+ path: path || "root",
6800
+ issue: "oneOf array is empty",
6801
+ fix: "Add at least one schema to the oneOf array",
6802
+ example: 'oneOf: [{ type: "string" }, { type: "number" }]'
6803
+ });
6804
+ }
6805
+ schema2.oneOf.forEach((subSchema, index) => {
6806
+ validateSchemaObject(subSchema, `${path}oneOf[${index}].`);
6807
+ });
6808
+ return;
6809
+ }
6810
+ if (schema2.allOf && Array.isArray(schema2.allOf)) {
6811
+ if (schema2.allOf.length === 0) {
6812
+ errors.push({
6813
+ path: path || "root",
6814
+ issue: "allOf array is empty",
6815
+ fix: "Add at least one schema to the allOf array",
6816
+ example: 'allOf: [{ type: "object" }, { properties: { name: { type: "string" } } }]'
6817
+ });
6818
+ }
6819
+ schema2.allOf.forEach((subSchema, index) => {
6820
+ validateSchemaObject(subSchema, `${path}allOf[${index}].`);
6821
+ });
6822
+ return;
6823
+ }
6824
+ if (!schema2.type) {
6825
+ return;
6826
+ }
6742
6827
  if (!validTypes.includes(schema2.type)) {
6743
- errors.push(`Invalid type '${schema2.type}' at ${path || "root"}`);
6828
+ errors.push({
6829
+ path: path || "root",
6830
+ issue: `Invalid type '${schema2.type}'`,
6831
+ fix: `Change type to one of: ${validTypes.join(", ")}`,
6832
+ example: `{ type: "string" } or { type: "object" }`
6833
+ });
6744
6834
  return;
6745
6835
  }
6746
- if (schema2.type === "object" && schema2.properties) {
6747
- if (typeof schema2.properties !== "object" || Array.isArray(schema2.properties)) {
6748
- errors.push(`Invalid properties object at ${path || "root"}`);
6749
- } else {
6750
- for (const key in schema2.properties) {
6751
- const value = schema2.properties[key];
6752
- if (typeof value !== "object") {
6753
- errors.push(`Invalid schema object at ${path}${key}`);
6754
- continue;
6836
+ if (schema2.type === "object") {
6837
+ if (schema2.properties) {
6838
+ if (typeof schema2.properties !== "object" || Array.isArray(schema2.properties)) {
6839
+ errors.push({
6840
+ path: path || "root",
6841
+ issue: "properties must be an object, not an array or primitive",
6842
+ fix: "Change properties to be an object with property names as keys",
6843
+ example: 'properties: { name: { type: "string" }, age: { type: "number" } }'
6844
+ });
6845
+ } else {
6846
+ for (const key in schema2.properties) {
6847
+ const value = schema2.properties[key];
6848
+ if (value === void 0 || value === null) {
6849
+ continue;
6850
+ }
6851
+ if (typeof value !== "object") {
6852
+ errors.push({
6853
+ path: `${path}${key}`,
6854
+ issue: `Property schema must be an object, got ${typeof value}`,
6855
+ fix: "Define the property as a proper schema object",
6856
+ example: `${key}: { type: "string", description: "..." }`
6857
+ });
6858
+ continue;
6859
+ }
6860
+ validateSchemaObject(value, `${path}${key}.`);
6755
6861
  }
6756
- validateSchemaObject(value, `${path}${key}.`);
6757
6862
  }
6758
6863
  }
6759
- if (schema2.required && !Array.isArray(schema2.required)) {
6760
- errors.push(`'required' should be an array at ${path || "root"}`);
6864
+ if (schema2.required) {
6865
+ if (!Array.isArray(schema2.required)) {
6866
+ errors.push({
6867
+ path: path || "root",
6868
+ issue: `'required' must be an array, got ${typeof schema2.required}`,
6869
+ fix: "Change required to be an array of property names",
6870
+ example: 'required: ["name", "email"] instead of required: "name,email"'
6871
+ });
6872
+ } else if (schema2.required.length === 0) {
6873
+ } else {
6874
+ if (schema2.properties) {
6875
+ for (const requiredProp of schema2.required) {
6876
+ if (typeof requiredProp !== "string") {
6877
+ errors.push({
6878
+ path: `${path}required`,
6879
+ issue: `Required property names must be strings, got ${typeof requiredProp}`,
6880
+ fix: "Ensure all items in required array are strings",
6881
+ example: 'required: ["name", "email"] not required: [123, "email"]'
6882
+ });
6883
+ } else if (!(requiredProp in schema2.properties)) {
6884
+ errors.push({
6885
+ path: `${path}required`,
6886
+ issue: `Required property '${requiredProp}' is not defined in properties`,
6887
+ fix: `Either add '${requiredProp}' to properties or remove it from required`,
6888
+ example: `properties: { ${requiredProp}: { type: "string" } }`
6889
+ });
6890
+ }
6891
+ }
6892
+ }
6893
+ }
6761
6894
  }
6762
6895
  }
6763
- if (schema2.type === "array" && schema2.items) {
6764
- if (typeof schema2.items !== "object") {
6765
- errors.push(`Invalid items schema at ${path || "root"}`);
6766
- } else {
6767
- validateSchemaObject(schema2.items, `${path}items.`);
6896
+ if (schema2.type === "array") {
6897
+ if (schema2.items) {
6898
+ if (typeof schema2.items !== "object") {
6899
+ errors.push({
6900
+ path: `${path}items`,
6901
+ issue: `Array items schema must be an object, got ${typeof schema2.items}`,
6902
+ fix: "Define items as a proper schema object",
6903
+ example: 'items: { type: "string" } or items: { type: "object", properties: {...} }'
6904
+ });
6905
+ } else {
6906
+ validateSchemaObject(schema2.items, `${path}items.`);
6907
+ }
6768
6908
  }
6769
6909
  }
6770
6910
  };
6771
6911
  validateSchemaObject(schema);
6772
6912
  if (errors.length > 0) {
6773
- throw new Error(errors.join("; "));
6913
+ const errorMessage = [
6914
+ "JSON Schema validation failed:",
6915
+ "",
6916
+ ...errors.map((error, index) => {
6917
+ const parts = [
6918
+ `${index + 1}. Path: ${error.path}`,
6919
+ ` Issue: ${error.issue}`,
6920
+ ` Fix: ${error.fix}`
6921
+ ];
6922
+ if (error.example) {
6923
+ parts.push(` Example: ${error.example}`);
6924
+ }
6925
+ return parts.join("\n");
6926
+ }),
6927
+ "",
6928
+ "Please fix these issues and try again."
6929
+ ].join("\n");
6930
+ throw new Error(errorMessage);
6774
6931
  }
6775
6932
  };
6776
6933