@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.cjs CHANGED
@@ -6892,6 +6892,9 @@ function getFieldProcessingMessage(field, resultText) {
6892
6892
  var validateJSONSchema = (schema) => {
6893
6893
  const errors = [];
6894
6894
  const validateSchemaObject = (schema2, path = "") => {
6895
+ if (!schema2 || typeof schema2 !== "object") {
6896
+ return;
6897
+ }
6895
6898
  const validTypes = [
6896
6899
  "array",
6897
6900
  "integer",
@@ -6901,38 +6904,155 @@ var validateJSONSchema = (schema) => {
6901
6904
  "null",
6902
6905
  "object"
6903
6906
  ];
6907
+ if (schema2.anyOf && Array.isArray(schema2.anyOf)) {
6908
+ if (schema2.anyOf.length === 0) {
6909
+ errors.push({
6910
+ path: path || "root",
6911
+ issue: "anyOf array is empty",
6912
+ fix: "Add at least one schema to the anyOf array",
6913
+ example: 'anyOf: [{ type: "string" }, { type: "null" }]'
6914
+ });
6915
+ }
6916
+ schema2.anyOf.forEach((subSchema, index) => {
6917
+ validateSchemaObject(subSchema, `${path}anyOf[${index}].`);
6918
+ });
6919
+ return;
6920
+ }
6921
+ if (schema2.oneOf && Array.isArray(schema2.oneOf)) {
6922
+ if (schema2.oneOf.length === 0) {
6923
+ errors.push({
6924
+ path: path || "root",
6925
+ issue: "oneOf array is empty",
6926
+ fix: "Add at least one schema to the oneOf array",
6927
+ example: 'oneOf: [{ type: "string" }, { type: "number" }]'
6928
+ });
6929
+ }
6930
+ schema2.oneOf.forEach((subSchema, index) => {
6931
+ validateSchemaObject(subSchema, `${path}oneOf[${index}].`);
6932
+ });
6933
+ return;
6934
+ }
6935
+ if (schema2.allOf && Array.isArray(schema2.allOf)) {
6936
+ if (schema2.allOf.length === 0) {
6937
+ errors.push({
6938
+ path: path || "root",
6939
+ issue: "allOf array is empty",
6940
+ fix: "Add at least one schema to the allOf array",
6941
+ example: 'allOf: [{ type: "object" }, { properties: { name: { type: "string" } } }]'
6942
+ });
6943
+ }
6944
+ schema2.allOf.forEach((subSchema, index) => {
6945
+ validateSchemaObject(subSchema, `${path}allOf[${index}].`);
6946
+ });
6947
+ return;
6948
+ }
6949
+ if (!schema2.type) {
6950
+ return;
6951
+ }
6904
6952
  if (!validTypes.includes(schema2.type)) {
6905
- errors.push(`Invalid type '${schema2.type}' at ${path || "root"}`);
6953
+ errors.push({
6954
+ path: path || "root",
6955
+ issue: `Invalid type '${schema2.type}'`,
6956
+ fix: `Change type to one of: ${validTypes.join(", ")}`,
6957
+ example: `{ type: "string" } or { type: "object" }`
6958
+ });
6906
6959
  return;
6907
6960
  }
6908
- if (schema2.type === "object" && schema2.properties) {
6909
- if (typeof schema2.properties !== "object" || Array.isArray(schema2.properties)) {
6910
- errors.push(`Invalid properties object at ${path || "root"}`);
6911
- } else {
6912
- for (const key in schema2.properties) {
6913
- const value = schema2.properties[key];
6914
- if (typeof value !== "object") {
6915
- errors.push(`Invalid schema object at ${path}${key}`);
6916
- continue;
6961
+ if (schema2.type === "object") {
6962
+ if (schema2.properties) {
6963
+ if (typeof schema2.properties !== "object" || Array.isArray(schema2.properties)) {
6964
+ errors.push({
6965
+ path: path || "root",
6966
+ issue: "properties must be an object, not an array or primitive",
6967
+ fix: "Change properties to be an object with property names as keys",
6968
+ example: 'properties: { name: { type: "string" }, age: { type: "number" } }'
6969
+ });
6970
+ } else {
6971
+ for (const key in schema2.properties) {
6972
+ const value = schema2.properties[key];
6973
+ if (value === void 0 || value === null) {
6974
+ continue;
6975
+ }
6976
+ if (typeof value !== "object") {
6977
+ errors.push({
6978
+ path: `${path}${key}`,
6979
+ issue: `Property schema must be an object, got ${typeof value}`,
6980
+ fix: "Define the property as a proper schema object",
6981
+ example: `${key}: { type: "string", description: "..." }`
6982
+ });
6983
+ continue;
6984
+ }
6985
+ validateSchemaObject(value, `${path}${key}.`);
6917
6986
  }
6918
- validateSchemaObject(value, `${path}${key}.`);
6919
6987
  }
6920
6988
  }
6921
- if (schema2.required && !Array.isArray(schema2.required)) {
6922
- errors.push(`'required' should be an array at ${path || "root"}`);
6989
+ if (schema2.required) {
6990
+ if (!Array.isArray(schema2.required)) {
6991
+ errors.push({
6992
+ path: path || "root",
6993
+ issue: `'required' must be an array, got ${typeof schema2.required}`,
6994
+ fix: "Change required to be an array of property names",
6995
+ example: 'required: ["name", "email"] instead of required: "name,email"'
6996
+ });
6997
+ } else if (schema2.required.length === 0) {
6998
+ } else {
6999
+ if (schema2.properties) {
7000
+ for (const requiredProp of schema2.required) {
7001
+ if (typeof requiredProp !== "string") {
7002
+ errors.push({
7003
+ path: `${path}required`,
7004
+ issue: `Required property names must be strings, got ${typeof requiredProp}`,
7005
+ fix: "Ensure all items in required array are strings",
7006
+ example: 'required: ["name", "email"] not required: [123, "email"]'
7007
+ });
7008
+ } else if (!(requiredProp in schema2.properties)) {
7009
+ errors.push({
7010
+ path: `${path}required`,
7011
+ issue: `Required property '${requiredProp}' is not defined in properties`,
7012
+ fix: `Either add '${requiredProp}' to properties or remove it from required`,
7013
+ example: `properties: { ${requiredProp}: { type: "string" } }`
7014
+ });
7015
+ }
7016
+ }
7017
+ }
7018
+ }
6923
7019
  }
6924
7020
  }
6925
- if (schema2.type === "array" && schema2.items) {
6926
- if (typeof schema2.items !== "object") {
6927
- errors.push(`Invalid items schema at ${path || "root"}`);
6928
- } else {
6929
- validateSchemaObject(schema2.items, `${path}items.`);
7021
+ if (schema2.type === "array") {
7022
+ if (schema2.items) {
7023
+ if (typeof schema2.items !== "object") {
7024
+ errors.push({
7025
+ path: `${path}items`,
7026
+ issue: `Array items schema must be an object, got ${typeof schema2.items}`,
7027
+ fix: "Define items as a proper schema object",
7028
+ example: 'items: { type: "string" } or items: { type: "object", properties: {...} }'
7029
+ });
7030
+ } else {
7031
+ validateSchemaObject(schema2.items, `${path}items.`);
7032
+ }
6930
7033
  }
6931
7034
  }
6932
7035
  };
6933
7036
  validateSchemaObject(schema);
6934
7037
  if (errors.length > 0) {
6935
- throw new Error(errors.join("; "));
7038
+ const errorMessage = [
7039
+ "JSON Schema validation failed:",
7040
+ "",
7041
+ ...errors.map((error, index) => {
7042
+ const parts = [
7043
+ `${index + 1}. Path: ${error.path}`,
7044
+ ` Issue: ${error.issue}`,
7045
+ ` Fix: ${error.fix}`
7046
+ ];
7047
+ if (error.example) {
7048
+ parts.push(` Example: ${error.example}`);
7049
+ }
7050
+ return parts.join("\n");
7051
+ }),
7052
+ "",
7053
+ "Please fix these issues and try again."
7054
+ ].join("\n");
7055
+ throw new Error(errorMessage);
6936
7056
  }
6937
7057
  };
6938
7058