@nocobase/plugin-ai 2.0.0-alpha.60 → 2.0.0-alpha.62

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 (85) hide show
  1. package/dist/externalVersion.js +11 -11
  2. package/dist/node_modules/@langchain/anthropic/package.json +1 -1
  3. package/dist/node_modules/@langchain/core/package.json +1 -1
  4. package/dist/node_modules/@langchain/deepseek/package.json +1 -1
  5. package/dist/node_modules/@langchain/google-genai/package.json +1 -1
  6. package/dist/node_modules/@langchain/ollama/index.cjs +2 -2
  7. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/Options.js +1 -0
  8. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/Refs.js +1 -0
  9. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/getRelativePath.js +12 -0
  10. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/index.js +1 -0
  11. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/parseDef.js +5 -11
  12. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/parsers/any.js +16 -2
  13. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/parsers/array.js +2 -2
  14. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/parsers/effects.js +2 -1
  15. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/parsers/map.js +3 -2
  16. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/parsers/never.js +10 -4
  17. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/parsers/object.js +1 -2
  18. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/parsers/optional.js +3 -2
  19. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/parsers/record.js +8 -7
  20. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/parsers/string.js +0 -1
  21. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/parsers/undefined.js +3 -2
  22. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/parsers/unknown.js +3 -2
  23. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/selectParser.js +41 -42
  24. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/cjs/zodToJsonSchema.js +24 -3
  25. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/Options.js +1 -0
  26. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/Refs.js +1 -0
  27. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/getRelativePath.js +8 -0
  28. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/index.js +1 -0
  29. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/parseDef.js +4 -10
  30. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/parsers/any.js +16 -2
  31. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/parsers/array.js +1 -1
  32. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js +2 -1
  33. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/parsers/map.js +3 -2
  34. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/parsers/never.js +10 -4
  35. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/parsers/object.js +1 -2
  36. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js +3 -2
  37. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/parsers/record.js +3 -2
  38. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/parsers/string.js +0 -1
  39. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js +3 -2
  40. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js +3 -2
  41. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/selectParser.js +5 -6
  42. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js +24 -3
  43. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/Options.d.ts +2 -1
  44. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/Refs.d.ts +4 -1
  45. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/errorMessages.d.ts +5 -1
  46. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/getRelativePath.d.ts +1 -0
  47. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/index.d.ts +1 -0
  48. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parseDef.d.ts +1 -1
  49. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/any.d.ts +5 -2
  50. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/array.d.ts +1 -1
  51. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/bigint.d.ts +1 -1
  52. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/branded.d.ts +1 -1
  53. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/catch.d.ts +1 -1
  54. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/date.d.ts +1 -1
  55. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/default.d.ts +1 -1
  56. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/effects.d.ts +1 -1
  57. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/enum.d.ts +1 -1
  58. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/intersection.d.ts +1 -1
  59. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/literal.d.ts +1 -1
  60. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/map.d.ts +1 -1
  61. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/nativeEnum.d.ts +1 -1
  62. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/never.d.ts +4 -2
  63. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/nullable.d.ts +1 -1
  64. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/number.d.ts +1 -1
  65. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/object.d.ts +1 -1
  66. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/optional.d.ts +1 -1
  67. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/pipeline.d.ts +1 -1
  68. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/promise.d.ts +1 -1
  69. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/readonly.d.ts +1 -1
  70. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/record.d.ts +1 -1
  71. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/set.d.ts +1 -1
  72. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/string.d.ts +1 -1
  73. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/tuple.d.ts +1 -1
  74. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/undefined.d.ts +4 -2
  75. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/union.d.ts +1 -1
  76. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/parsers/unknown.d.ts +4 -2
  77. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/selectParser.d.ts +1 -1
  78. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/dist/types/zodToJsonSchema.d.ts +1 -1
  79. package/dist/node_modules/@langchain/ollama/node_modules/zod-to-json-schema/package.json +7 -8
  80. package/dist/node_modules/@langchain/ollama/package.json +1 -1
  81. package/dist/node_modules/@langchain/openai/package.json +1 -1
  82. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  83. package/dist/node_modules/zod/package.json +1 -1
  84. package/dist/node_modules/zod-to-json-schema/package.json +1 -1
  85. package/package.json +2 -2
@@ -37,6 +37,7 @@ exports.defaultOptions = {
37
37
  emailStrategy: "format:email",
38
38
  base64Strategy: "contentEncoding:base64",
39
39
  nameStrategy: "ref",
40
+ openAiAnyTypeName: "OpenAiAnyType"
40
41
  };
41
42
  const getDefaultOptions = (options) => (typeof options === "string"
42
43
  ? {
@@ -9,6 +9,7 @@ const getRefs = (options) => {
9
9
  : _options.basePath;
10
10
  return {
11
11
  ..._options,
12
+ flags: { hasReferencedOpenAiAnyType: false },
12
13
  currentPath: currentPath,
13
14
  propertyPath: undefined,
14
15
  seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRelativePath = void 0;
4
+ const getRelativePath = (pathA, pathB) => {
5
+ let i = 0;
6
+ for (; i < pathA.length && i < pathB.length; i++) {
7
+ if (pathA[i] !== pathB[i])
8
+ break;
9
+ }
10
+ return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
11
+ };
12
+ exports.getRelativePath = getRelativePath;
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./Options.js"), exports);
18
18
  __exportStar(require("./Refs.js"), exports);
19
19
  __exportStar(require("./errorMessages.js"), exports);
20
+ __exportStar(require("./getRelativePath.js"), exports);
20
21
  __exportStar(require("./parseDef.js"), exports);
21
22
  __exportStar(require("./parseTypes.js"), exports);
22
23
  __exportStar(require("./parsers/any.js"), exports);
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseDef = void 0;
4
4
  const Options_js_1 = require("./Options.js");
5
5
  const selectParser_js_1 = require("./selectParser.js");
6
+ const getRelativePath_js_1 = require("./getRelativePath.js");
7
+ const any_js_1 = require("./parsers/any.js");
6
8
  function parseDef(def, refs, forceResolution = false) {
7
9
  const seenItem = refs.seen.get(def);
8
10
  if (refs.override) {
@@ -41,26 +43,18 @@ const get$ref = (item, refs) => {
41
43
  case "root":
42
44
  return { $ref: item.path.join("/") };
43
45
  case "relative":
44
- return { $ref: getRelativePath(refs.currentPath, item.path) };
46
+ return { $ref: (0, getRelativePath_js_1.getRelativePath)(refs.currentPath, item.path) };
45
47
  case "none":
46
48
  case "seen": {
47
49
  if (item.path.length < refs.currentPath.length &&
48
50
  item.path.every((value, index) => refs.currentPath[index] === value)) {
49
51
  console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
50
- return {};
52
+ return (0, any_js_1.parseAnyDef)(refs);
51
53
  }
52
- return refs.$refStrategy === "seen" ? {} : undefined;
54
+ return refs.$refStrategy === "seen" ? (0, any_js_1.parseAnyDef)(refs) : undefined;
53
55
  }
54
56
  }
55
57
  };
56
- const getRelativePath = (pathA, pathB) => {
57
- let i = 0;
58
- for (; i < pathA.length && i < pathB.length; i++) {
59
- if (pathA[i] !== pathB[i])
60
- break;
61
- }
62
- return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
63
- };
64
58
  const addMeta = (def, refs, jsonSchema) => {
65
59
  if (def.description) {
66
60
  jsonSchema.description = def.description;
@@ -1,7 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseAnyDef = void 0;
4
- function parseAnyDef() {
5
- return {};
4
+ const getRelativePath_js_1 = require("../getRelativePath.js");
5
+ function parseAnyDef(refs) {
6
+ if (refs.target !== "openAi") {
7
+ return {};
8
+ }
9
+ const anyDefinitionPath = [
10
+ ...refs.basePath,
11
+ refs.definitionPath,
12
+ refs.openAiAnyTypeName,
13
+ ];
14
+ refs.flags.hasReferencedOpenAiAnyType = true;
15
+ return {
16
+ $ref: refs.$refStrategy === "relative"
17
+ ? (0, getRelativePath_js_1.getRelativePath)(anyDefinitionPath, refs.currentPath)
18
+ : anyDefinitionPath.join("/"),
19
+ };
6
20
  }
7
21
  exports.parseAnyDef = parseAnyDef;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseArrayDef = void 0;
4
- const zod_1 = require("zod");
4
+ const v3_1 = require("zod/v3");
5
5
  const errorMessages_js_1 = require("../errorMessages.js");
6
6
  const parseDef_js_1 = require("../parseDef.js");
7
7
  function parseArrayDef(def, refs) {
@@ -9,7 +9,7 @@ function parseArrayDef(def, refs) {
9
9
  type: "array",
10
10
  };
11
11
  if (def.type?._def &&
12
- def.type?._def?.typeName !== zod_1.ZodFirstPartyTypeKind.ZodAny) {
12
+ def.type?._def?.typeName !== v3_1.ZodFirstPartyTypeKind.ZodAny) {
13
13
  res.items = (0, parseDef_js_1.parseDef)(def.type._def, {
14
14
  ...refs,
15
15
  currentPath: [...refs.currentPath, "items"],
@@ -2,9 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseEffectsDef = void 0;
4
4
  const parseDef_js_1 = require("../parseDef.js");
5
+ const any_js_1 = require("./any.js");
5
6
  function parseEffectsDef(_def, refs) {
6
7
  return refs.effectStrategy === "input"
7
8
  ? (0, parseDef_js_1.parseDef)(_def.schema._def, refs)
8
- : {};
9
+ : (0, any_js_1.parseAnyDef)(refs);
9
10
  }
10
11
  exports.parseEffectsDef = parseEffectsDef;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMapDef = void 0;
4
4
  const parseDef_js_1 = require("../parseDef.js");
5
5
  const record_js_1 = require("./record.js");
6
+ const any_js_1 = require("./any.js");
6
7
  function parseMapDef(def, refs) {
7
8
  if (refs.mapStrategy === "record") {
8
9
  return (0, record_js_1.parseRecordDef)(def, refs);
@@ -10,11 +11,11 @@ function parseMapDef(def, refs) {
10
11
  const keys = (0, parseDef_js_1.parseDef)(def.keyType._def, {
11
12
  ...refs,
12
13
  currentPath: [...refs.currentPath, "items", "items", "0"],
13
- }) || {};
14
+ }) || (0, any_js_1.parseAnyDef)(refs);
14
15
  const values = (0, parseDef_js_1.parseDef)(def.valueType._def, {
15
16
  ...refs,
16
17
  currentPath: [...refs.currentPath, "items", "items", "1"],
17
- }) || {};
18
+ }) || (0, any_js_1.parseAnyDef)(refs);
18
19
  return {
19
20
  type: "array",
20
21
  maxItems: 125,
@@ -1,9 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseNeverDef = void 0;
4
- function parseNeverDef() {
5
- return {
6
- not: {},
7
- };
4
+ const any_js_1 = require("./any.js");
5
+ function parseNeverDef(refs) {
6
+ return refs.target === "openAi"
7
+ ? undefined
8
+ : {
9
+ not: (0, any_js_1.parseAnyDef)({
10
+ ...refs,
11
+ currentPath: [...refs.currentPath, "not"],
12
+ }),
13
+ };
8
14
  }
9
15
  exports.parseNeverDef = parseNeverDef;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseObjectDef = void 0;
4
- const zod_1 = require("zod");
5
4
  const parseDef_js_1 = require("../parseDef.js");
6
5
  function parseObjectDef(def, refs) {
7
6
  const forceOptionalIntoNullable = refs.target === "openAi";
@@ -18,7 +17,7 @@ function parseObjectDef(def, refs) {
18
17
  }
19
18
  let propOptional = safeIsOptional(propDef);
20
19
  if (propOptional && forceOptionalIntoNullable) {
21
- if (propDef instanceof zod_1.ZodOptional) {
20
+ if (propDef._def.typeName === "ZodOptional") {
22
21
  propDef = propDef._def.innerType;
23
22
  }
24
23
  if (!propDef.isNullable()) {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseOptionalDef = void 0;
4
4
  const parseDef_js_1 = require("../parseDef.js");
5
+ const any_js_1 = require("./any.js");
5
6
  const parseOptionalDef = (def, refs) => {
6
7
  if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
7
8
  return (0, parseDef_js_1.parseDef)(def.innerType._def, refs);
@@ -14,11 +15,11 @@ const parseOptionalDef = (def, refs) => {
14
15
  ? {
15
16
  anyOf: [
16
17
  {
17
- not: {},
18
+ not: (0, any_js_1.parseAnyDef)(refs),
18
19
  },
19
20
  innerSchema,
20
21
  ],
21
22
  }
22
- : {};
23
+ : (0, any_js_1.parseAnyDef)(refs);
23
24
  };
24
25
  exports.parseOptionalDef = parseOptionalDef;
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseRecordDef = void 0;
4
- const zod_1 = require("zod");
4
+ const v3_1 = require("zod/v3");
5
5
  const parseDef_js_1 = require("../parseDef.js");
6
6
  const string_js_1 = require("./string.js");
7
7
  const branded_js_1 = require("./branded.js");
8
+ const any_js_1 = require("./any.js");
8
9
  function parseRecordDef(def, refs) {
9
10
  if (refs.target === "openAi") {
10
11
  console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
11
12
  }
12
13
  if (refs.target === "openApi3" &&
13
- def.keyType?._def.typeName === zod_1.ZodFirstPartyTypeKind.ZodEnum) {
14
+ def.keyType?._def.typeName === v3_1.ZodFirstPartyTypeKind.ZodEnum) {
14
15
  return {
15
16
  type: "object",
16
17
  required: def.keyType._def.values,
@@ -19,7 +20,7 @@ function parseRecordDef(def, refs) {
19
20
  [key]: (0, parseDef_js_1.parseDef)(def.valueType._def, {
20
21
  ...refs,
21
22
  currentPath: [...refs.currentPath, "properties", key],
22
- }) ?? {},
23
+ }) ?? (0, any_js_1.parseAnyDef)(refs),
23
24
  }), {}),
24
25
  additionalProperties: refs.rejectedAdditionalProperties,
25
26
  };
@@ -34,7 +35,7 @@ function parseRecordDef(def, refs) {
34
35
  if (refs.target === "openApi3") {
35
36
  return schema;
36
37
  }
37
- if (def.keyType?._def.typeName === zod_1.ZodFirstPartyTypeKind.ZodString &&
38
+ if (def.keyType?._def.typeName === v3_1.ZodFirstPartyTypeKind.ZodString &&
38
39
  def.keyType._def.checks?.length) {
39
40
  const { type, ...keyType } = (0, string_js_1.parseStringDef)(def.keyType._def, refs);
40
41
  return {
@@ -42,7 +43,7 @@ function parseRecordDef(def, refs) {
42
43
  propertyNames: keyType,
43
44
  };
44
45
  }
45
- else if (def.keyType?._def.typeName === zod_1.ZodFirstPartyTypeKind.ZodEnum) {
46
+ else if (def.keyType?._def.typeName === v3_1.ZodFirstPartyTypeKind.ZodEnum) {
46
47
  return {
47
48
  ...schema,
48
49
  propertyNames: {
@@ -50,8 +51,8 @@ function parseRecordDef(def, refs) {
50
51
  },
51
52
  };
52
53
  }
53
- else if (def.keyType?._def.typeName === zod_1.ZodFirstPartyTypeKind.ZodBranded &&
54
- def.keyType._def.type._def.typeName === zod_1.ZodFirstPartyTypeKind.ZodString &&
54
+ else if (def.keyType?._def.typeName === v3_1.ZodFirstPartyTypeKind.ZodBranded &&
55
+ def.keyType._def.type._def.typeName === v3_1.ZodFirstPartyTypeKind.ZodString &&
55
56
  def.keyType._def.type._def.checks?.length) {
56
57
  const { type, ...keyType } = (0, branded_js_1.parseBrandedDef)(def.keyType._def, refs);
57
58
  return {
@@ -187,7 +187,6 @@ function parseStringDef(def, refs) {
187
187
  case "trim":
188
188
  break;
189
189
  default:
190
- /* c8 ignore next */
191
190
  ((_) => { })(check);
192
191
  }
193
192
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseUndefinedDef = void 0;
4
- function parseUndefinedDef() {
4
+ const any_js_1 = require("./any.js");
5
+ function parseUndefinedDef(refs) {
5
6
  return {
6
- not: {},
7
+ not: (0, any_js_1.parseAnyDef)(refs),
7
8
  };
8
9
  }
9
10
  exports.parseUndefinedDef = parseUndefinedDef;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseUnknownDef = void 0;
4
- function parseUnknownDef() {
5
- return {};
4
+ const any_js_1 = require("./any.js");
5
+ function parseUnknownDef(refs) {
6
+ return (0, any_js_1.parseAnyDef)(refs);
6
7
  }
7
8
  exports.parseUnknownDef = parseUnknownDef;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.selectParser = void 0;
4
- const zod_1 = require("zod");
4
+ const v3_1 = require("zod/v3");
5
5
  const any_js_1 = require("./parsers/any.js");
6
6
  const array_js_1 = require("./parsers/array.js");
7
7
  const bigint_js_1 = require("./parsers/bigint.js");
@@ -34,76 +34,75 @@ const unknown_js_1 = require("./parsers/unknown.js");
34
34
  const readonly_js_1 = require("./parsers/readonly.js");
35
35
  const selectParser = (def, typeName, refs) => {
36
36
  switch (typeName) {
37
- case zod_1.ZodFirstPartyTypeKind.ZodString:
37
+ case v3_1.ZodFirstPartyTypeKind.ZodString:
38
38
  return (0, string_js_1.parseStringDef)(def, refs);
39
- case zod_1.ZodFirstPartyTypeKind.ZodNumber:
39
+ case v3_1.ZodFirstPartyTypeKind.ZodNumber:
40
40
  return (0, number_js_1.parseNumberDef)(def, refs);
41
- case zod_1.ZodFirstPartyTypeKind.ZodObject:
41
+ case v3_1.ZodFirstPartyTypeKind.ZodObject:
42
42
  return (0, object_js_1.parseObjectDef)(def, refs);
43
- case zod_1.ZodFirstPartyTypeKind.ZodBigInt:
43
+ case v3_1.ZodFirstPartyTypeKind.ZodBigInt:
44
44
  return (0, bigint_js_1.parseBigintDef)(def, refs);
45
- case zod_1.ZodFirstPartyTypeKind.ZodBoolean:
45
+ case v3_1.ZodFirstPartyTypeKind.ZodBoolean:
46
46
  return (0, boolean_js_1.parseBooleanDef)();
47
- case zod_1.ZodFirstPartyTypeKind.ZodDate:
47
+ case v3_1.ZodFirstPartyTypeKind.ZodDate:
48
48
  return (0, date_js_1.parseDateDef)(def, refs);
49
- case zod_1.ZodFirstPartyTypeKind.ZodUndefined:
50
- return (0, undefined_js_1.parseUndefinedDef)();
51
- case zod_1.ZodFirstPartyTypeKind.ZodNull:
49
+ case v3_1.ZodFirstPartyTypeKind.ZodUndefined:
50
+ return (0, undefined_js_1.parseUndefinedDef)(refs);
51
+ case v3_1.ZodFirstPartyTypeKind.ZodNull:
52
52
  return (0, null_js_1.parseNullDef)(refs);
53
- case zod_1.ZodFirstPartyTypeKind.ZodArray:
53
+ case v3_1.ZodFirstPartyTypeKind.ZodArray:
54
54
  return (0, array_js_1.parseArrayDef)(def, refs);
55
- case zod_1.ZodFirstPartyTypeKind.ZodUnion:
56
- case zod_1.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
55
+ case v3_1.ZodFirstPartyTypeKind.ZodUnion:
56
+ case v3_1.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
57
57
  return (0, union_js_1.parseUnionDef)(def, refs);
58
- case zod_1.ZodFirstPartyTypeKind.ZodIntersection:
58
+ case v3_1.ZodFirstPartyTypeKind.ZodIntersection:
59
59
  return (0, intersection_js_1.parseIntersectionDef)(def, refs);
60
- case zod_1.ZodFirstPartyTypeKind.ZodTuple:
60
+ case v3_1.ZodFirstPartyTypeKind.ZodTuple:
61
61
  return (0, tuple_js_1.parseTupleDef)(def, refs);
62
- case zod_1.ZodFirstPartyTypeKind.ZodRecord:
62
+ case v3_1.ZodFirstPartyTypeKind.ZodRecord:
63
63
  return (0, record_js_1.parseRecordDef)(def, refs);
64
- case zod_1.ZodFirstPartyTypeKind.ZodLiteral:
64
+ case v3_1.ZodFirstPartyTypeKind.ZodLiteral:
65
65
  return (0, literal_js_1.parseLiteralDef)(def, refs);
66
- case zod_1.ZodFirstPartyTypeKind.ZodEnum:
66
+ case v3_1.ZodFirstPartyTypeKind.ZodEnum:
67
67
  return (0, enum_js_1.parseEnumDef)(def);
68
- case zod_1.ZodFirstPartyTypeKind.ZodNativeEnum:
68
+ case v3_1.ZodFirstPartyTypeKind.ZodNativeEnum:
69
69
  return (0, nativeEnum_js_1.parseNativeEnumDef)(def);
70
- case zod_1.ZodFirstPartyTypeKind.ZodNullable:
70
+ case v3_1.ZodFirstPartyTypeKind.ZodNullable:
71
71
  return (0, nullable_js_1.parseNullableDef)(def, refs);
72
- case zod_1.ZodFirstPartyTypeKind.ZodOptional:
72
+ case v3_1.ZodFirstPartyTypeKind.ZodOptional:
73
73
  return (0, optional_js_1.parseOptionalDef)(def, refs);
74
- case zod_1.ZodFirstPartyTypeKind.ZodMap:
74
+ case v3_1.ZodFirstPartyTypeKind.ZodMap:
75
75
  return (0, map_js_1.parseMapDef)(def, refs);
76
- case zod_1.ZodFirstPartyTypeKind.ZodSet:
76
+ case v3_1.ZodFirstPartyTypeKind.ZodSet:
77
77
  return (0, set_js_1.parseSetDef)(def, refs);
78
- case zod_1.ZodFirstPartyTypeKind.ZodLazy:
78
+ case v3_1.ZodFirstPartyTypeKind.ZodLazy:
79
79
  return () => def.getter()._def;
80
- case zod_1.ZodFirstPartyTypeKind.ZodPromise:
80
+ case v3_1.ZodFirstPartyTypeKind.ZodPromise:
81
81
  return (0, promise_js_1.parsePromiseDef)(def, refs);
82
- case zod_1.ZodFirstPartyTypeKind.ZodNaN:
83
- case zod_1.ZodFirstPartyTypeKind.ZodNever:
84
- return (0, never_js_1.parseNeverDef)();
85
- case zod_1.ZodFirstPartyTypeKind.ZodEffects:
82
+ case v3_1.ZodFirstPartyTypeKind.ZodNaN:
83
+ case v3_1.ZodFirstPartyTypeKind.ZodNever:
84
+ return (0, never_js_1.parseNeverDef)(refs);
85
+ case v3_1.ZodFirstPartyTypeKind.ZodEffects:
86
86
  return (0, effects_js_1.parseEffectsDef)(def, refs);
87
- case zod_1.ZodFirstPartyTypeKind.ZodAny:
88
- return (0, any_js_1.parseAnyDef)();
89
- case zod_1.ZodFirstPartyTypeKind.ZodUnknown:
90
- return (0, unknown_js_1.parseUnknownDef)();
91
- case zod_1.ZodFirstPartyTypeKind.ZodDefault:
87
+ case v3_1.ZodFirstPartyTypeKind.ZodAny:
88
+ return (0, any_js_1.parseAnyDef)(refs);
89
+ case v3_1.ZodFirstPartyTypeKind.ZodUnknown:
90
+ return (0, unknown_js_1.parseUnknownDef)(refs);
91
+ case v3_1.ZodFirstPartyTypeKind.ZodDefault:
92
92
  return (0, default_js_1.parseDefaultDef)(def, refs);
93
- case zod_1.ZodFirstPartyTypeKind.ZodBranded:
93
+ case v3_1.ZodFirstPartyTypeKind.ZodBranded:
94
94
  return (0, branded_js_1.parseBrandedDef)(def, refs);
95
- case zod_1.ZodFirstPartyTypeKind.ZodReadonly:
95
+ case v3_1.ZodFirstPartyTypeKind.ZodReadonly:
96
96
  return (0, readonly_js_1.parseReadonlyDef)(def, refs);
97
- case zod_1.ZodFirstPartyTypeKind.ZodCatch:
97
+ case v3_1.ZodFirstPartyTypeKind.ZodCatch:
98
98
  return (0, catch_js_1.parseCatchDef)(def, refs);
99
- case zod_1.ZodFirstPartyTypeKind.ZodPipeline:
99
+ case v3_1.ZodFirstPartyTypeKind.ZodPipeline:
100
100
  return (0, pipeline_js_1.parsePipelineDef)(def, refs);
101
- case zod_1.ZodFirstPartyTypeKind.ZodFunction:
102
- case zod_1.ZodFirstPartyTypeKind.ZodVoid:
103
- case zod_1.ZodFirstPartyTypeKind.ZodSymbol:
101
+ case v3_1.ZodFirstPartyTypeKind.ZodFunction:
102
+ case v3_1.ZodFirstPartyTypeKind.ZodVoid:
103
+ case v3_1.ZodFirstPartyTypeKind.ZodSymbol:
104
104
  return undefined;
105
105
  default:
106
- /* c8 ignore next */
107
106
  return ((_) => undefined)(typeName);
108
107
  }
109
108
  };
@@ -3,15 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.zodToJsonSchema = void 0;
4
4
  const parseDef_js_1 = require("./parseDef.js");
5
5
  const Refs_js_1 = require("./Refs.js");
6
+ const any_js_1 = require("./parsers/any.js");
6
7
  const zodToJsonSchema = (schema, options) => {
7
8
  const refs = (0, Refs_js_1.getRefs)(options);
8
- const definitions = typeof options === "object" && options.definitions
9
+ let definitions = typeof options === "object" && options.definitions
9
10
  ? Object.entries(options.definitions).reduce((acc, [name, schema]) => ({
10
11
  ...acc,
11
12
  [name]: (0, parseDef_js_1.parseDef)(schema._def, {
12
13
  ...refs,
13
14
  currentPath: [...refs.basePath, refs.definitionPath, name],
14
- }, true) ?? {},
15
+ }, true) ?? (0, any_js_1.parseAnyDef)(refs),
15
16
  }), {})
16
17
  : undefined;
17
18
  const name = typeof options === "string"
@@ -24,7 +25,7 @@ const zodToJsonSchema = (schema, options) => {
24
25
  : {
25
26
  ...refs,
26
27
  currentPath: [...refs.basePath, refs.definitionPath, name],
27
- }, false) ?? {};
28
+ }, false) ?? (0, any_js_1.parseAnyDef)(refs);
28
29
  const title = typeof options === "object" &&
29
30
  options.name !== undefined &&
30
31
  options.nameStrategy === "title"
@@ -33,6 +34,26 @@ const zodToJsonSchema = (schema, options) => {
33
34
  if (title !== undefined) {
34
35
  main.title = title;
35
36
  }
37
+ if (refs.flags.hasReferencedOpenAiAnyType) {
38
+ if (!definitions) {
39
+ definitions = {};
40
+ }
41
+ if (!definitions[refs.openAiAnyTypeName]) {
42
+ definitions[refs.openAiAnyTypeName] = {
43
+ // Skipping "object" as no properties can be defined and additionalProperties must be "false"
44
+ type: ["string", "number", "integer", "boolean", "array", "null"],
45
+ items: {
46
+ $ref: refs.$refStrategy === "relative"
47
+ ? "1"
48
+ : [
49
+ ...refs.basePath,
50
+ refs.definitionPath,
51
+ refs.openAiAnyTypeName,
52
+ ].join("/"),
53
+ },
54
+ };
55
+ }
56
+ }
36
57
  const combined = name === undefined
37
58
  ? definitions
38
59
  ? {
@@ -33,6 +33,7 @@ export const defaultOptions = {
33
33
  emailStrategy: "format:email",
34
34
  base64Strategy: "contentEncoding:base64",
35
35
  nameStrategy: "ref",
36
+ openAiAnyTypeName: "OpenAiAnyType"
36
37
  };
37
38
  export const getDefaultOptions = (options) => (typeof options === "string"
38
39
  ? {
@@ -6,6 +6,7 @@ export const getRefs = (options) => {
6
6
  : _options.basePath;
7
7
  return {
8
8
  ..._options,
9
+ flags: { hasReferencedOpenAiAnyType: false },
9
10
  currentPath: currentPath,
10
11
  propertyPath: undefined,
11
12
  seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
@@ -0,0 +1,8 @@
1
+ export const getRelativePath = (pathA, pathB) => {
2
+ let i = 0;
3
+ for (; i < pathA.length && i < pathB.length; i++) {
4
+ if (pathA[i] !== pathB[i])
5
+ break;
6
+ }
7
+ return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
8
+ };
@@ -1,6 +1,7 @@
1
1
  export * from "./Options.js";
2
2
  export * from "./Refs.js";
3
3
  export * from "./errorMessages.js";
4
+ export * from "./getRelativePath.js";
4
5
  export * from "./parseDef.js";
5
6
  export * from "./parseTypes.js";
6
7
  export * from "./parsers/any.js";
@@ -1,5 +1,7 @@
1
1
  import { ignoreOverride } from "./Options.js";
2
2
  import { selectParser } from "./selectParser.js";
3
+ import { getRelativePath } from "./getRelativePath.js";
4
+ import { parseAnyDef } from "./parsers/any.js";
3
5
  export function parseDef(def, refs, forceResolution = false) {
4
6
  const seenItem = refs.seen.get(def);
5
7
  if (refs.override) {
@@ -43,20 +45,12 @@ const get$ref = (item, refs) => {
43
45
  if (item.path.length < refs.currentPath.length &&
44
46
  item.path.every((value, index) => refs.currentPath[index] === value)) {
45
47
  console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
46
- return {};
48
+ return parseAnyDef(refs);
47
49
  }
48
- return refs.$refStrategy === "seen" ? {} : undefined;
50
+ return refs.$refStrategy === "seen" ? parseAnyDef(refs) : undefined;
49
51
  }
50
52
  }
51
53
  };
52
- const getRelativePath = (pathA, pathB) => {
53
- let i = 0;
54
- for (; i < pathA.length && i < pathB.length; i++) {
55
- if (pathA[i] !== pathB[i])
56
- break;
57
- }
58
- return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
59
- };
60
54
  const addMeta = (def, refs, jsonSchema) => {
61
55
  if (def.description) {
62
56
  jsonSchema.description = def.description;
@@ -1,3 +1,17 @@
1
- export function parseAnyDef() {
2
- return {};
1
+ import { getRelativePath } from "../getRelativePath.js";
2
+ export function parseAnyDef(refs) {
3
+ if (refs.target !== "openAi") {
4
+ return {};
5
+ }
6
+ const anyDefinitionPath = [
7
+ ...refs.basePath,
8
+ refs.definitionPath,
9
+ refs.openAiAnyTypeName,
10
+ ];
11
+ refs.flags.hasReferencedOpenAiAnyType = true;
12
+ return {
13
+ $ref: refs.$refStrategy === "relative"
14
+ ? getRelativePath(anyDefinitionPath, refs.currentPath)
15
+ : anyDefinitionPath.join("/"),
16
+ };
3
17
  }
@@ -1,4 +1,4 @@
1
- import { ZodFirstPartyTypeKind } from "zod";
1
+ import { ZodFirstPartyTypeKind } from "zod/v3";
2
2
  import { setResponseValueAndErrors } from "../errorMessages.js";
3
3
  import { parseDef } from "../parseDef.js";
4
4
  export function parseArrayDef(def, refs) {
@@ -1,6 +1,7 @@
1
1
  import { parseDef } from "../parseDef.js";
2
+ import { parseAnyDef } from "./any.js";
2
3
  export function parseEffectsDef(_def, refs) {
3
4
  return refs.effectStrategy === "input"
4
5
  ? parseDef(_def.schema._def, refs)
5
- : {};
6
+ : parseAnyDef(refs);
6
7
  }
@@ -1,5 +1,6 @@
1
1
  import { parseDef } from "../parseDef.js";
2
2
  import { parseRecordDef } from "./record.js";
3
+ import { parseAnyDef } from "./any.js";
3
4
  export function parseMapDef(def, refs) {
4
5
  if (refs.mapStrategy === "record") {
5
6
  return parseRecordDef(def, refs);
@@ -7,11 +8,11 @@ export function parseMapDef(def, refs) {
7
8
  const keys = parseDef(def.keyType._def, {
8
9
  ...refs,
9
10
  currentPath: [...refs.currentPath, "items", "items", "0"],
10
- }) || {};
11
+ }) || parseAnyDef(refs);
11
12
  const values = parseDef(def.valueType._def, {
12
13
  ...refs,
13
14
  currentPath: [...refs.currentPath, "items", "items", "1"],
14
- }) || {};
15
+ }) || parseAnyDef(refs);
15
16
  return {
16
17
  type: "array",
17
18
  maxItems: 125,
@@ -1,5 +1,11 @@
1
- export function parseNeverDef() {
2
- return {
3
- not: {},
4
- };
1
+ import { parseAnyDef } from "./any.js";
2
+ export function parseNeverDef(refs) {
3
+ return refs.target === "openAi"
4
+ ? undefined
5
+ : {
6
+ not: parseAnyDef({
7
+ ...refs,
8
+ currentPath: [...refs.currentPath, "not"],
9
+ }),
10
+ };
5
11
  }