@ax-llm/ax 11.0.55 → 11.0.56

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.js CHANGED
@@ -6730,6 +6730,9 @@ function getFieldProcessingMessage(field, resultText) {
6730
6730
  var validateJSONSchema = (schema) => {
6731
6731
  const errors = [];
6732
6732
  const validateSchemaObject = (schema2, path = "") => {
6733
+ if (!schema2 || typeof schema2 !== "object") {
6734
+ return;
6735
+ }
6733
6736
  const validTypes = [
6734
6737
  "array",
6735
6738
  "integer",
@@ -6739,38 +6742,155 @@ var validateJSONSchema = (schema) => {
6739
6742
  "null",
6740
6743
  "object"
6741
6744
  ];
6745
+ if (schema2.anyOf && Array.isArray(schema2.anyOf)) {
6746
+ if (schema2.anyOf.length === 0) {
6747
+ errors.push({
6748
+ path: path || "root",
6749
+ issue: "anyOf array is empty",
6750
+ fix: "Add at least one schema to the anyOf array",
6751
+ example: 'anyOf: [{ type: "string" }, { type: "null" }]'
6752
+ });
6753
+ }
6754
+ schema2.anyOf.forEach((subSchema, index) => {
6755
+ validateSchemaObject(subSchema, `${path}anyOf[${index}].`);
6756
+ });
6757
+ return;
6758
+ }
6759
+ if (schema2.oneOf && Array.isArray(schema2.oneOf)) {
6760
+ if (schema2.oneOf.length === 0) {
6761
+ errors.push({
6762
+ path: path || "root",
6763
+ issue: "oneOf array is empty",
6764
+ fix: "Add at least one schema to the oneOf array",
6765
+ example: 'oneOf: [{ type: "string" }, { type: "number" }]'
6766
+ });
6767
+ }
6768
+ schema2.oneOf.forEach((subSchema, index) => {
6769
+ validateSchemaObject(subSchema, `${path}oneOf[${index}].`);
6770
+ });
6771
+ return;
6772
+ }
6773
+ if (schema2.allOf && Array.isArray(schema2.allOf)) {
6774
+ if (schema2.allOf.length === 0) {
6775
+ errors.push({
6776
+ path: path || "root",
6777
+ issue: "allOf array is empty",
6778
+ fix: "Add at least one schema to the allOf array",
6779
+ example: 'allOf: [{ type: "object" }, { properties: { name: { type: "string" } } }]'
6780
+ });
6781
+ }
6782
+ schema2.allOf.forEach((subSchema, index) => {
6783
+ validateSchemaObject(subSchema, `${path}allOf[${index}].`);
6784
+ });
6785
+ return;
6786
+ }
6787
+ if (!schema2.type) {
6788
+ return;
6789
+ }
6742
6790
  if (!validTypes.includes(schema2.type)) {
6743
- errors.push(`Invalid type '${schema2.type}' at ${path || "root"}`);
6791
+ errors.push({
6792
+ path: path || "root",
6793
+ issue: `Invalid type '${schema2.type}'`,
6794
+ fix: `Change type to one of: ${validTypes.join(", ")}`,
6795
+ example: `{ type: "string" } or { type: "object" }`
6796
+ });
6744
6797
  return;
6745
6798
  }
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;
6799
+ if (schema2.type === "object") {
6800
+ if (schema2.properties) {
6801
+ if (typeof schema2.properties !== "object" || Array.isArray(schema2.properties)) {
6802
+ errors.push({
6803
+ path: path || "root",
6804
+ issue: "properties must be an object, not an array or primitive",
6805
+ fix: "Change properties to be an object with property names as keys",
6806
+ example: 'properties: { name: { type: "string" }, age: { type: "number" } }'
6807
+ });
6808
+ } else {
6809
+ for (const key in schema2.properties) {
6810
+ const value = schema2.properties[key];
6811
+ if (value === void 0 || value === null) {
6812
+ continue;
6813
+ }
6814
+ if (typeof value !== "object") {
6815
+ errors.push({
6816
+ path: `${path}${key}`,
6817
+ issue: `Property schema must be an object, got ${typeof value}`,
6818
+ fix: "Define the property as a proper schema object",
6819
+ example: `${key}: { type: "string", description: "..." }`
6820
+ });
6821
+ continue;
6822
+ }
6823
+ validateSchemaObject(value, `${path}${key}.`);
6755
6824
  }
6756
- validateSchemaObject(value, `${path}${key}.`);
6757
6825
  }
6758
6826
  }
6759
- if (schema2.required && !Array.isArray(schema2.required)) {
6760
- errors.push(`'required' should be an array at ${path || "root"}`);
6827
+ if (schema2.required) {
6828
+ if (!Array.isArray(schema2.required)) {
6829
+ errors.push({
6830
+ path: path || "root",
6831
+ issue: `'required' must be an array, got ${typeof schema2.required}`,
6832
+ fix: "Change required to be an array of property names",
6833
+ example: 'required: ["name", "email"] instead of required: "name,email"'
6834
+ });
6835
+ } else if (schema2.required.length === 0) {
6836
+ } else {
6837
+ if (schema2.properties) {
6838
+ for (const requiredProp of schema2.required) {
6839
+ if (typeof requiredProp !== "string") {
6840
+ errors.push({
6841
+ path: `${path}required`,
6842
+ issue: `Required property names must be strings, got ${typeof requiredProp}`,
6843
+ fix: "Ensure all items in required array are strings",
6844
+ example: 'required: ["name", "email"] not required: [123, "email"]'
6845
+ });
6846
+ } else if (!(requiredProp in schema2.properties)) {
6847
+ errors.push({
6848
+ path: `${path}required`,
6849
+ issue: `Required property '${requiredProp}' is not defined in properties`,
6850
+ fix: `Either add '${requiredProp}' to properties or remove it from required`,
6851
+ example: `properties: { ${requiredProp}: { type: "string" } }`
6852
+ });
6853
+ }
6854
+ }
6855
+ }
6856
+ }
6761
6857
  }
6762
6858
  }
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.`);
6859
+ if (schema2.type === "array") {
6860
+ if (schema2.items) {
6861
+ if (typeof schema2.items !== "object") {
6862
+ errors.push({
6863
+ path: `${path}items`,
6864
+ issue: `Array items schema must be an object, got ${typeof schema2.items}`,
6865
+ fix: "Define items as a proper schema object",
6866
+ example: 'items: { type: "string" } or items: { type: "object", properties: {...} }'
6867
+ });
6868
+ } else {
6869
+ validateSchemaObject(schema2.items, `${path}items.`);
6870
+ }
6768
6871
  }
6769
6872
  }
6770
6873
  };
6771
6874
  validateSchemaObject(schema);
6772
6875
  if (errors.length > 0) {
6773
- throw new Error(errors.join("; "));
6876
+ const errorMessage = [
6877
+ "JSON Schema validation failed:",
6878
+ "",
6879
+ ...errors.map((error, index) => {
6880
+ const parts = [
6881
+ `${index + 1}. Path: ${error.path}`,
6882
+ ` Issue: ${error.issue}`,
6883
+ ` Fix: ${error.fix}`
6884
+ ];
6885
+ if (error.example) {
6886
+ parts.push(` Example: ${error.example}`);
6887
+ }
6888
+ return parts.join("\n");
6889
+ }),
6890
+ "",
6891
+ "Please fix these issues and try again."
6892
+ ].join("\n");
6893
+ throw new Error(errorMessage);
6774
6894
  }
6775
6895
  };
6776
6896