@tonyclaw/agent-inspector 4.0.7 → 4.0.9

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 (119) hide show
  1. package/.output/backend/nitro.json +1 -1
  2. package/.output/cli.js +915 -25970
  3. package/.output/server/_chunks/ssr-renderer.mjs +1 -38
  4. package/.output/server/_libs/@opentelemetry/semantic-conventions+[...].mjs +1 -2658
  5. package/.output/server/_libs/agent-base.mjs +2 -234
  6. package/.output/server/_libs/ajv-formats.mjs +1 -330
  7. package/.output/server/_libs/ajv.mjs +8 -6080
  8. package/.output/server/_libs/anthropic-ai__sdk.mjs +19 -6021
  9. package/.output/server/_libs/atomically.mjs +1 -155
  10. package/.output/server/_libs/base64-js.mjs +1 -102
  11. package/.output/server/_libs/bignumber.js.mjs +1 -1353
  12. package/.output/server/_libs/buffer-equal-constant-time.mjs +1 -38
  13. package/.output/server/_libs/conf.mjs +1 -635
  14. package/.output/server/_libs/cookie-es.mjs +1 -44
  15. package/.output/server/_libs/core-util-is.mjs +1 -75
  16. package/.output/server/_libs/data-uri-to-buffer.mjs +1 -39
  17. package/.output/server/_libs/debounce-fn.mjs +1 -69
  18. package/.output/server/_libs/debug.mjs +5 -547
  19. package/.output/server/_libs/dot-prop.mjs +1 -265
  20. package/.output/server/_libs/ecdsa-sig-formatter.mjs +1 -162
  21. package/.output/server/_libs/env-paths.mjs +1 -57
  22. package/.output/server/_libs/extend.mjs +1 -94
  23. package/.output/server/_libs/fast-deep-equal.mjs +1 -38
  24. package/.output/server/_libs/fast-uri.mjs +1 -812
  25. package/.output/server/_libs/fetch-blob.mjs +1 -287
  26. package/.output/server/_libs/formdata-polyfill.mjs +9 -86
  27. package/.output/server/_libs/gaxios.mjs +5 -926
  28. package/.output/server/_libs/gcp-metadata.mjs +1 -322
  29. package/.output/server/_libs/google-auth-library.mjs +16 -6339
  30. package/.output/server/_libs/google-logging-utils.mjs +1 -385
  31. package/.output/server/_libs/google__genai.mjs +13 -18034
  32. package/.output/server/_libs/h3-v2.mjs +2 -287
  33. package/.output/server/_libs/h3.mjs +2 -408
  34. package/.output/server/_libs/has-flag.mjs +1 -16
  35. package/.output/server/_libs/https-proxy-agent.mjs +7 -280
  36. package/.output/server/_libs/immediate.mjs +1 -74
  37. package/.output/server/_libs/inherits.mjs +1 -50
  38. package/.output/server/_libs/isarray.mjs +1 -14
  39. package/.output/server/_libs/isbot.mjs +1 -20
  40. package/.output/server/_libs/json-bigint.mjs +8 -413
  41. package/.output/server/_libs/json-schema-traverse.mjs +1 -91
  42. package/.output/server/_libs/jszip.mjs +2 -3051
  43. package/.output/server/_libs/jwa.mjs +3 -233
  44. package/.output/server/_libs/jws.mjs +1 -298
  45. package/.output/server/_libs/lie.mjs +1 -273
  46. package/.output/server/_libs/mariozechner__pi-agent-core.mjs +1 -824
  47. package/.output/server/_libs/mariozechner__pi-ai.mjs +34 -22887
  48. package/.output/server/_libs/mimic-function.mjs +2 -47
  49. package/.output/server/_libs/mistralai__mistralai.mjs +7 -32045
  50. package/.output/server/_libs/modelcontextprotocol__core.mjs +1 -1121
  51. package/.output/server/_libs/modelcontextprotocol__server.mjs +13 -13205
  52. package/.output/server/_libs/ms.mjs +1 -120
  53. package/.output/server/_libs/node-domexception.mjs +1 -17
  54. package/.output/server/_libs/node-fetch.mjs +4 -1578
  55. package/.output/server/_libs/ohash.mjs +1 -1
  56. package/.output/server/_libs/openai.mjs +23 -6766
  57. package/.output/server/_libs/opentelemetry__api.mjs +1 -1678
  58. package/.output/server/_libs/p-retry.mjs +1 -87
  59. package/.output/server/_libs/pako.mjs +1 -4223
  60. package/.output/server/_libs/partial-json.mjs +2 -244
  61. package/.output/server/_libs/process-nextick-args.mjs +1 -48
  62. package/.output/server/_libs/react-dom.mjs +62 -10778
  63. package/.output/server/_libs/react.mjs +1 -519
  64. package/.output/server/_libs/readable-stream.mjs +1 -1518
  65. package/.output/server/_libs/retry.mjs +1 -236
  66. package/.output/server/_libs/rou3.mjs +1 -14
  67. package/.output/server/_libs/safe-buffer.mjs +1 -126
  68. package/.output/server/_libs/semver.mjs +1 -1938
  69. package/.output/server/_libs/seroval-plugins.mjs +1 -58
  70. package/.output/server/_libs/seroval.mjs +3 -1775
  71. package/.output/server/_libs/setimmediate.mjs +1 -152
  72. package/.output/server/_libs/srvx.mjs +4 -1390
  73. package/.output/server/_libs/stubborn-fs.mjs +1 -91
  74. package/.output/server/_libs/stubborn-utils.mjs +1 -66
  75. package/.output/server/_libs/supports-color.mjs +1 -108
  76. package/.output/server/_libs/tanstack__history.mjs +1 -230
  77. package/.output/server/_libs/tanstack__react-router.mjs +1 -848
  78. package/.output/server/_libs/tanstack__react-store.mjs +1 -1
  79. package/.output/server/_libs/tanstack__router-core.mjs +1 -4839
  80. package/.output/server/_libs/typebox.mjs +3 -6596
  81. package/.output/server/_libs/ufo.mjs +1 -54
  82. package/.output/server/_libs/uint8array-extras.mjs +1 -69
  83. package/.output/server/_libs/util-deprecate.mjs +1 -12
  84. package/.output/server/_libs/web-streams-polyfill.mjs +1 -4282
  85. package/.output/server/_libs/when-exit.mjs +1 -53
  86. package/.output/server/_libs/ws.mjs +7 -3715
  87. package/.output/server/_libs/zod-to-json-schema.mjs +5 -1207
  88. package/.output/server/_libs/zod.mjs +59 -9958
  89. package/.output/server/_ssr/empty-plugin-adapters-C3Q1xu4u.mjs +1 -0
  90. package/.output/server/_ssr/index.mjs +2 -1512
  91. package/.output/server/_ssr/publicBasePathContext--TAQS2_5.mjs +1 -0
  92. package/.output/server/_ssr/router-zSWaME0l.mjs +341 -0
  93. package/.output/server/_ssr/start-PDVGOqUN.mjs +1 -0
  94. package/.output/server/_tanstack-start-manifest_v-D7cKwKzM.mjs +1 -0
  95. package/.output/server/index.mjs +1 -320
  96. package/.output/ui/assets/{CompareDrawer-fWsmegqc.js → CompareDrawer-C6KvvPtJ.js} +1 -1
  97. package/.output/ui/assets/{InspectorPet-Z9XIA0t8.js → InspectorPet-CSH6OAhB.js} +1 -1
  98. package/.output/ui/assets/{ProxyViewerContainer-DhIB_ZAU.js → ProxyViewerContainer-vPd7g0Xn.js} +4 -4
  99. package/.output/ui/assets/{ReplayDialog-w_3PENIi.js → ReplayDialog-DbXUcT39.js} +1 -1
  100. package/.output/ui/assets/{RequestAnatomy-Dix0D4G6.js → RequestAnatomy-BWOCIN7J.js} +1 -1
  101. package/.output/ui/assets/{ResponseView-BtlbxW2o.js → ResponseView-BqDbTzFs.js} +1 -1
  102. package/.output/ui/assets/{StreamingChunkSequence-BqNQJASb.js → StreamingChunkSequence-UHl2g6w6.js} +1 -1
  103. package/.output/ui/assets/{_sessionId-DPiw4uu2.js → _sessionId-B2S61lDJ.js} +1 -1
  104. package/.output/ui/assets/{_sessionId-Bo9J8C5J.js → _sessionId-CS6hqj8-.js} +1 -1
  105. package/.output/ui/assets/{index-BL5id77_.js → index-C6V66rNI.js} +1 -1
  106. package/.output/ui/assets/{index-icwV1YtX.js → index-DY5xBYHr.js} +1 -1
  107. package/.output/ui/assets/{index-Wd6TK76x.js → index-DgyIeqyV.js} +2 -2
  108. package/.output/ui/assets/{index-CWSVfojK.js → index-HLs5jTyi.js} +1 -1
  109. package/.output/ui/assets/{json-viewer-Cpr3uw1I.js → json-viewer-i5LcN8e7.js} +1 -1
  110. package/.output/ui/assets/{jszip.min-Cncg6JOi.js → jszip.min-yNpb9qnf.js} +1 -1
  111. package/.output/ui/index.html +1 -1
  112. package/.output/workers/logFinalizer.worker.js +41 -17739
  113. package/.output/workers/sessionWorkerEntry.js +41 -17735
  114. package/package.json +7 -7
  115. package/.output/server/_ssr/empty-plugin-adapters-BFgPZ6_d.mjs +0 -6
  116. package/.output/server/_ssr/publicBasePathContext-IH2ilOfu.mjs +0 -176
  117. package/.output/server/_ssr/router-weYHAqCb.mjs +0 -27177
  118. package/.output/server/_ssr/start-COQu_AgD.mjs +0 -57
  119. package/.output/server/_tanstack-start-manifest_v-ClTaMkEj.mjs +0 -4
@@ -1,1207 +1,5 @@
1
- import { V as ZodFirstPartyTypeKind } from "./zod.mjs";
2
- const ignoreOverride = /* @__PURE__ */ Symbol("Let zodToJsonSchema decide on which parser to use");
3
- const defaultOptions = {
4
- name: void 0,
5
- $refStrategy: "root",
6
- basePath: ["#"],
7
- effectStrategy: "input",
8
- pipeStrategy: "all",
9
- dateStrategy: "format:date-time",
10
- mapStrategy: "entries",
11
- removeAdditionalStrategy: "passthrough",
12
- allowedAdditionalProperties: true,
13
- rejectedAdditionalProperties: false,
14
- definitionPath: "definitions",
15
- target: "jsonSchema7",
16
- strictUnions: false,
17
- definitions: {},
18
- errorMessages: false,
19
- markdownDescription: false,
20
- patternStrategy: "escape",
21
- applyRegexFlags: false,
22
- emailStrategy: "format:email",
23
- base64Strategy: "contentEncoding:base64",
24
- nameStrategy: "ref",
25
- openAiAnyTypeName: "OpenAiAnyType"
26
- };
27
- const getDefaultOptions = (options) => typeof options === "string" ? {
28
- ...defaultOptions,
29
- name: options
30
- } : {
31
- ...defaultOptions,
32
- ...options
33
- };
34
- const getRefs = (options) => {
35
- const _options = getDefaultOptions(options);
36
- const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
37
- return {
38
- ..._options,
39
- flags: { hasReferencedOpenAiAnyType: false },
40
- currentPath,
41
- propertyPath: void 0,
42
- seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
43
- def._def,
44
- {
45
- def: def._def,
46
- path: [..._options.basePath, _options.definitionPath, name],
47
- // Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
48
- jsonSchema: void 0
49
- }
50
- ]))
51
- };
52
- };
53
- function addErrorMessage(res, key, errorMessage, refs) {
54
- if (!refs?.errorMessages)
55
- return;
56
- if (errorMessage) {
57
- res.errorMessage = {
58
- ...res.errorMessage,
59
- [key]: errorMessage
60
- };
61
- }
62
- }
63
- function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
64
- res[key] = value;
65
- addErrorMessage(res, key, errorMessage, refs);
66
- }
67
- const getRelativePath = (pathA, pathB) => {
68
- let i = 0;
69
- for (; i < pathA.length && i < pathB.length; i++) {
70
- if (pathA[i] !== pathB[i])
71
- break;
72
- }
73
- return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
74
- };
75
- function parseAnyDef(refs) {
76
- if (refs.target !== "openAi") {
77
- return {};
78
- }
79
- const anyDefinitionPath = [
80
- ...refs.basePath,
81
- refs.definitionPath,
82
- refs.openAiAnyTypeName
83
- ];
84
- refs.flags.hasReferencedOpenAiAnyType = true;
85
- return {
86
- $ref: refs.$refStrategy === "relative" ? getRelativePath(anyDefinitionPath, refs.currentPath) : anyDefinitionPath.join("/")
87
- };
88
- }
89
- function parseArrayDef(def, refs) {
90
- const res = {
91
- type: "array"
92
- };
93
- if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) {
94
- res.items = parseDef(def.type._def, {
95
- ...refs,
96
- currentPath: [...refs.currentPath, "items"]
97
- });
98
- }
99
- if (def.minLength) {
100
- setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
101
- }
102
- if (def.maxLength) {
103
- setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
104
- }
105
- if (def.exactLength) {
106
- setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
107
- setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
108
- }
109
- return res;
110
- }
111
- function parseBigintDef(def, refs) {
112
- const res = {
113
- type: "integer",
114
- format: "int64"
115
- };
116
- if (!def.checks)
117
- return res;
118
- for (const check of def.checks) {
119
- switch (check.kind) {
120
- case "min":
121
- if (refs.target === "jsonSchema7") {
122
- if (check.inclusive) {
123
- setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
124
- } else {
125
- setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
126
- }
127
- } else {
128
- if (!check.inclusive) {
129
- res.exclusiveMinimum = true;
130
- }
131
- setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
132
- }
133
- break;
134
- case "max":
135
- if (refs.target === "jsonSchema7") {
136
- if (check.inclusive) {
137
- setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
138
- } else {
139
- setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
140
- }
141
- } else {
142
- if (!check.inclusive) {
143
- res.exclusiveMaximum = true;
144
- }
145
- setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
146
- }
147
- break;
148
- case "multipleOf":
149
- setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
150
- break;
151
- }
152
- }
153
- return res;
154
- }
155
- function parseBooleanDef() {
156
- return {
157
- type: "boolean"
158
- };
159
- }
160
- function parseBrandedDef(_def, refs) {
161
- return parseDef(_def.type._def, refs);
162
- }
163
- const parseCatchDef = (def, refs) => {
164
- return parseDef(def.innerType._def, refs);
165
- };
166
- function parseDateDef(def, refs, overrideDateStrategy) {
167
- const strategy = overrideDateStrategy ?? refs.dateStrategy;
168
- if (Array.isArray(strategy)) {
169
- return {
170
- anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
171
- };
172
- }
173
- switch (strategy) {
174
- case "string":
175
- case "format:date-time":
176
- return {
177
- type: "string",
178
- format: "date-time"
179
- };
180
- case "format:date":
181
- return {
182
- type: "string",
183
- format: "date"
184
- };
185
- case "integer":
186
- return integerDateParser(def, refs);
187
- }
188
- }
189
- const integerDateParser = (def, refs) => {
190
- const res = {
191
- type: "integer",
192
- format: "unix-time"
193
- };
194
- if (refs.target === "openApi3") {
195
- return res;
196
- }
197
- for (const check of def.checks) {
198
- switch (check.kind) {
199
- case "min":
200
- setResponseValueAndErrors(
201
- res,
202
- "minimum",
203
- check.value,
204
- // This is in milliseconds
205
- check.message,
206
- refs
207
- );
208
- break;
209
- case "max":
210
- setResponseValueAndErrors(
211
- res,
212
- "maximum",
213
- check.value,
214
- // This is in milliseconds
215
- check.message,
216
- refs
217
- );
218
- break;
219
- }
220
- }
221
- return res;
222
- };
223
- function parseDefaultDef(_def, refs) {
224
- return {
225
- ...parseDef(_def.innerType._def, refs),
226
- default: _def.defaultValue()
227
- };
228
- }
229
- function parseEffectsDef(_def, refs) {
230
- return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : parseAnyDef(refs);
231
- }
232
- function parseEnumDef(def) {
233
- return {
234
- type: "string",
235
- enum: Array.from(def.values)
236
- };
237
- }
238
- const isJsonSchema7AllOfType = (type) => {
239
- if ("type" in type && type.type === "string")
240
- return false;
241
- return "allOf" in type;
242
- };
243
- function parseIntersectionDef(def, refs) {
244
- const allOf = [
245
- parseDef(def.left._def, {
246
- ...refs,
247
- currentPath: [...refs.currentPath, "allOf", "0"]
248
- }),
249
- parseDef(def.right._def, {
250
- ...refs,
251
- currentPath: [...refs.currentPath, "allOf", "1"]
252
- })
253
- ].filter((x) => !!x);
254
- let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : void 0;
255
- const mergedAllOf = [];
256
- allOf.forEach((schema) => {
257
- if (isJsonSchema7AllOfType(schema)) {
258
- mergedAllOf.push(...schema.allOf);
259
- if (schema.unevaluatedProperties === void 0) {
260
- unevaluatedProperties = void 0;
261
- }
262
- } else {
263
- let nestedSchema = schema;
264
- if ("additionalProperties" in schema && schema.additionalProperties === false) {
265
- const { additionalProperties, ...rest } = schema;
266
- nestedSchema = rest;
267
- } else {
268
- unevaluatedProperties = void 0;
269
- }
270
- mergedAllOf.push(nestedSchema);
271
- }
272
- });
273
- return mergedAllOf.length ? {
274
- allOf: mergedAllOf,
275
- ...unevaluatedProperties
276
- } : void 0;
277
- }
278
- function parseLiteralDef(def, refs) {
279
- const parsedType = typeof def.value;
280
- if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
281
- return {
282
- type: Array.isArray(def.value) ? "array" : "object"
283
- };
284
- }
285
- if (refs.target === "openApi3") {
286
- return {
287
- type: parsedType === "bigint" ? "integer" : parsedType,
288
- enum: [def.value]
289
- };
290
- }
291
- return {
292
- type: parsedType === "bigint" ? "integer" : parsedType,
293
- const: def.value
294
- };
295
- }
296
- let emojiRegex = void 0;
297
- const zodPatterns = {
298
- /**
299
- * `c` was changed to `[cC]` to replicate /i flag
300
- */
301
- cuid: /^[cC][^\s-]{8,}$/,
302
- cuid2: /^[0-9a-z]+$/,
303
- ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
304
- /**
305
- * `a-z` was added to replicate /i flag
306
- */
307
- email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
308
- /**
309
- * Constructed a valid Unicode RegExp
310
- *
311
- * Lazily instantiate since this type of regex isn't supported
312
- * in all envs (e.g. React Native).
313
- *
314
- * See:
315
- * https://github.com/colinhacks/zod/issues/2433
316
- * Fix in Zod:
317
- * https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
318
- */
319
- emoji: () => {
320
- if (emojiRegex === void 0) {
321
- emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
322
- }
323
- return emojiRegex;
324
- },
325
- /**
326
- * Unused
327
- */
328
- uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
329
- /**
330
- * Unused
331
- */
332
- ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
333
- ipv4Cidr: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,
334
- /**
335
- * Unused
336
- */
337
- ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
338
- ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
339
- base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
340
- base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
341
- nanoid: /^[a-zA-Z0-9_-]{21}$/,
342
- jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
343
- };
344
- function parseStringDef(def, refs) {
345
- const res = {
346
- type: "string"
347
- };
348
- if (def.checks) {
349
- for (const check of def.checks) {
350
- switch (check.kind) {
351
- case "min":
352
- setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
353
- break;
354
- case "max":
355
- setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
356
- break;
357
- case "email":
358
- switch (refs.emailStrategy) {
359
- case "format:email":
360
- addFormat(res, "email", check.message, refs);
361
- break;
362
- case "format:idn-email":
363
- addFormat(res, "idn-email", check.message, refs);
364
- break;
365
- case "pattern:zod":
366
- addPattern(res, zodPatterns.email, check.message, refs);
367
- break;
368
- }
369
- break;
370
- case "url":
371
- addFormat(res, "uri", check.message, refs);
372
- break;
373
- case "uuid":
374
- addFormat(res, "uuid", check.message, refs);
375
- break;
376
- case "regex":
377
- addPattern(res, check.regex, check.message, refs);
378
- break;
379
- case "cuid":
380
- addPattern(res, zodPatterns.cuid, check.message, refs);
381
- break;
382
- case "cuid2":
383
- addPattern(res, zodPatterns.cuid2, check.message, refs);
384
- break;
385
- case "startsWith":
386
- addPattern(res, RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`), check.message, refs);
387
- break;
388
- case "endsWith":
389
- addPattern(res, RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`), check.message, refs);
390
- break;
391
- case "datetime":
392
- addFormat(res, "date-time", check.message, refs);
393
- break;
394
- case "date":
395
- addFormat(res, "date", check.message, refs);
396
- break;
397
- case "time":
398
- addFormat(res, "time", check.message, refs);
399
- break;
400
- case "duration":
401
- addFormat(res, "duration", check.message, refs);
402
- break;
403
- case "length":
404
- setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
405
- setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
406
- break;
407
- case "includes": {
408
- addPattern(res, RegExp(escapeLiteralCheckValue(check.value, refs)), check.message, refs);
409
- break;
410
- }
411
- case "ip": {
412
- if (check.version !== "v6") {
413
- addFormat(res, "ipv4", check.message, refs);
414
- }
415
- if (check.version !== "v4") {
416
- addFormat(res, "ipv6", check.message, refs);
417
- }
418
- break;
419
- }
420
- case "base64url":
421
- addPattern(res, zodPatterns.base64url, check.message, refs);
422
- break;
423
- case "jwt":
424
- addPattern(res, zodPatterns.jwt, check.message, refs);
425
- break;
426
- case "cidr": {
427
- if (check.version !== "v6") {
428
- addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
429
- }
430
- if (check.version !== "v4") {
431
- addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
432
- }
433
- break;
434
- }
435
- case "emoji":
436
- addPattern(res, zodPatterns.emoji(), check.message, refs);
437
- break;
438
- case "ulid": {
439
- addPattern(res, zodPatterns.ulid, check.message, refs);
440
- break;
441
- }
442
- case "base64": {
443
- switch (refs.base64Strategy) {
444
- case "format:binary": {
445
- addFormat(res, "binary", check.message, refs);
446
- break;
447
- }
448
- case "contentEncoding:base64": {
449
- setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
450
- break;
451
- }
452
- case "pattern:zod": {
453
- addPattern(res, zodPatterns.base64, check.message, refs);
454
- break;
455
- }
456
- }
457
- break;
458
- }
459
- case "nanoid": {
460
- addPattern(res, zodPatterns.nanoid, check.message, refs);
461
- }
462
- }
463
- }
464
- }
465
- return res;
466
- }
467
- function escapeLiteralCheckValue(literal, refs) {
468
- return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
469
- }
470
- const ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
471
- function escapeNonAlphaNumeric(source) {
472
- let result = "";
473
- for (let i = 0; i < source.length; i++) {
474
- if (!ALPHA_NUMERIC.has(source[i])) {
475
- result += "\\";
476
- }
477
- result += source[i];
478
- }
479
- return result;
480
- }
481
- function addFormat(schema, value, message, refs) {
482
- if (schema.format || schema.anyOf?.some((x) => x.format)) {
483
- if (!schema.anyOf) {
484
- schema.anyOf = [];
485
- }
486
- if (schema.format) {
487
- schema.anyOf.push({
488
- format: schema.format,
489
- ...schema.errorMessage && refs.errorMessages && {
490
- errorMessage: { format: schema.errorMessage.format }
491
- }
492
- });
493
- delete schema.format;
494
- if (schema.errorMessage) {
495
- delete schema.errorMessage.format;
496
- if (Object.keys(schema.errorMessage).length === 0) {
497
- delete schema.errorMessage;
498
- }
499
- }
500
- }
501
- schema.anyOf.push({
502
- format: value,
503
- ...message && refs.errorMessages && { errorMessage: { format: message } }
504
- });
505
- } else {
506
- setResponseValueAndErrors(schema, "format", value, message, refs);
507
- }
508
- }
509
- function addPattern(schema, regex, message, refs) {
510
- if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {
511
- if (!schema.allOf) {
512
- schema.allOf = [];
513
- }
514
- if (schema.pattern) {
515
- schema.allOf.push({
516
- pattern: schema.pattern,
517
- ...schema.errorMessage && refs.errorMessages && {
518
- errorMessage: { pattern: schema.errorMessage.pattern }
519
- }
520
- });
521
- delete schema.pattern;
522
- if (schema.errorMessage) {
523
- delete schema.errorMessage.pattern;
524
- if (Object.keys(schema.errorMessage).length === 0) {
525
- delete schema.errorMessage;
526
- }
527
- }
528
- }
529
- schema.allOf.push({
530
- pattern: stringifyRegExpWithFlags(regex, refs),
531
- ...message && refs.errorMessages && { errorMessage: { pattern: message } }
532
- });
533
- } else {
534
- setResponseValueAndErrors(schema, "pattern", stringifyRegExpWithFlags(regex, refs), message, refs);
535
- }
536
- }
537
- function stringifyRegExpWithFlags(regex, refs) {
538
- if (!refs.applyRegexFlags || !regex.flags) {
539
- return regex.source;
540
- }
541
- const flags = {
542
- i: regex.flags.includes("i"),
543
- m: regex.flags.includes("m"),
544
- s: regex.flags.includes("s")
545
- // `.` matches newlines
546
- };
547
- const source = flags.i ? regex.source.toLowerCase() : regex.source;
548
- let pattern = "";
549
- let isEscaped = false;
550
- let inCharGroup = false;
551
- let inCharRange = false;
552
- for (let i = 0; i < source.length; i++) {
553
- if (isEscaped) {
554
- pattern += source[i];
555
- isEscaped = false;
556
- continue;
557
- }
558
- if (flags.i) {
559
- if (inCharGroup) {
560
- if (source[i].match(/[a-z]/)) {
561
- if (inCharRange) {
562
- pattern += source[i];
563
- pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
564
- inCharRange = false;
565
- } else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
566
- pattern += source[i];
567
- inCharRange = true;
568
- } else {
569
- pattern += `${source[i]}${source[i].toUpperCase()}`;
570
- }
571
- continue;
572
- }
573
- } else if (source[i].match(/[a-z]/)) {
574
- pattern += `[${source[i]}${source[i].toUpperCase()}]`;
575
- continue;
576
- }
577
- }
578
- if (flags.m) {
579
- if (source[i] === "^") {
580
- pattern += `(^|(?<=[\r
581
- ]))`;
582
- continue;
583
- } else if (source[i] === "$") {
584
- pattern += `($|(?=[\r
585
- ]))`;
586
- continue;
587
- }
588
- }
589
- if (flags.s && source[i] === ".") {
590
- pattern += inCharGroup ? `${source[i]}\r
591
- ` : `[${source[i]}\r
592
- ]`;
593
- continue;
594
- }
595
- pattern += source[i];
596
- if (source[i] === "\\") {
597
- isEscaped = true;
598
- } else if (inCharGroup && source[i] === "]") {
599
- inCharGroup = false;
600
- } else if (!inCharGroup && source[i] === "[") {
601
- inCharGroup = true;
602
- }
603
- }
604
- try {
605
- new RegExp(pattern);
606
- } catch {
607
- console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
608
- return regex.source;
609
- }
610
- return pattern;
611
- }
612
- function parseRecordDef(def, refs) {
613
- if (refs.target === "openAi") {
614
- console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
615
- }
616
- if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) {
617
- return {
618
- type: "object",
619
- required: def.keyType._def.values,
620
- properties: def.keyType._def.values.reduce((acc, key) => ({
621
- ...acc,
622
- [key]: parseDef(def.valueType._def, {
623
- ...refs,
624
- currentPath: [...refs.currentPath, "properties", key]
625
- }) ?? parseAnyDef(refs)
626
- }), {}),
627
- additionalProperties: refs.rejectedAdditionalProperties
628
- };
629
- }
630
- const schema = {
631
- type: "object",
632
- additionalProperties: parseDef(def.valueType._def, {
633
- ...refs,
634
- currentPath: [...refs.currentPath, "additionalProperties"]
635
- }) ?? refs.allowedAdditionalProperties
636
- };
637
- if (refs.target === "openApi3") {
638
- return schema;
639
- }
640
- if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.checks?.length) {
641
- const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
642
- return {
643
- ...schema,
644
- propertyNames: keyType
645
- };
646
- } else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) {
647
- return {
648
- ...schema,
649
- propertyNames: {
650
- enum: def.keyType._def.values
651
- }
652
- };
653
- } else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.type._def.checks?.length) {
654
- const { type, ...keyType } = parseBrandedDef(def.keyType._def, refs);
655
- return {
656
- ...schema,
657
- propertyNames: keyType
658
- };
659
- }
660
- return schema;
661
- }
662
- function parseMapDef(def, refs) {
663
- if (refs.mapStrategy === "record") {
664
- return parseRecordDef(def, refs);
665
- }
666
- const keys = parseDef(def.keyType._def, {
667
- ...refs,
668
- currentPath: [...refs.currentPath, "items", "items", "0"]
669
- }) || parseAnyDef(refs);
670
- const values = parseDef(def.valueType._def, {
671
- ...refs,
672
- currentPath: [...refs.currentPath, "items", "items", "1"]
673
- }) || parseAnyDef(refs);
674
- return {
675
- type: "array",
676
- maxItems: 125,
677
- items: {
678
- type: "array",
679
- items: [keys, values],
680
- minItems: 2,
681
- maxItems: 2
682
- }
683
- };
684
- }
685
- function parseNativeEnumDef(def) {
686
- const object = def.values;
687
- const actualKeys = Object.keys(def.values).filter((key) => {
688
- return typeof object[object[key]] !== "number";
689
- });
690
- const actualValues = actualKeys.map((key) => object[key]);
691
- const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
692
- return {
693
- type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
694
- enum: actualValues
695
- };
696
- }
697
- function parseNeverDef(refs) {
698
- return refs.target === "openAi" ? void 0 : {
699
- not: parseAnyDef({
700
- ...refs,
701
- currentPath: [...refs.currentPath, "not"]
702
- })
703
- };
704
- }
705
- function parseNullDef(refs) {
706
- return refs.target === "openApi3" ? {
707
- enum: ["null"],
708
- nullable: true
709
- } : {
710
- type: "null"
711
- };
712
- }
713
- const primitiveMappings = {
714
- ZodString: "string",
715
- ZodNumber: "number",
716
- ZodBigInt: "integer",
717
- ZodBoolean: "boolean",
718
- ZodNull: "null"
719
- };
720
- function parseUnionDef(def, refs) {
721
- if (refs.target === "openApi3")
722
- return asAnyOf(def, refs);
723
- const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
724
- if (options.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))) {
725
- const types = options.reduce((types2, x) => {
726
- const type = primitiveMappings[x._def.typeName];
727
- return type && !types2.includes(type) ? [...types2, type] : types2;
728
- }, []);
729
- return {
730
- type: types.length > 1 ? types : types[0]
731
- };
732
- } else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
733
- const types = options.reduce((acc, x) => {
734
- const type = typeof x._def.value;
735
- switch (type) {
736
- case "string":
737
- case "number":
738
- case "boolean":
739
- return [...acc, type];
740
- case "bigint":
741
- return [...acc, "integer"];
742
- case "object":
743
- if (x._def.value === null)
744
- return [...acc, "null"];
745
- case "symbol":
746
- case "undefined":
747
- case "function":
748
- default:
749
- return acc;
750
- }
751
- }, []);
752
- if (types.length === options.length) {
753
- const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
754
- return {
755
- type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
756
- enum: options.reduce((acc, x) => {
757
- return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
758
- }, [])
759
- };
760
- }
761
- } else if (options.every((x) => x._def.typeName === "ZodEnum")) {
762
- return {
763
- type: "string",
764
- enum: options.reduce((acc, x) => [
765
- ...acc,
766
- ...x._def.values.filter((x2) => !acc.includes(x2))
767
- ], [])
768
- };
769
- }
770
- return asAnyOf(def, refs);
771
- }
772
- const asAnyOf = (def, refs) => {
773
- const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
774
- ...refs,
775
- currentPath: [...refs.currentPath, "anyOf", `${i}`]
776
- })).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
777
- return anyOf.length ? { anyOf } : void 0;
778
- };
779
- function parseNullableDef(def, refs) {
780
- if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
781
- if (refs.target === "openApi3") {
782
- return {
783
- type: primitiveMappings[def.innerType._def.typeName],
784
- nullable: true
785
- };
786
- }
787
- return {
788
- type: [
789
- primitiveMappings[def.innerType._def.typeName],
790
- "null"
791
- ]
792
- };
793
- }
794
- if (refs.target === "openApi3") {
795
- const base2 = parseDef(def.innerType._def, {
796
- ...refs,
797
- currentPath: [...refs.currentPath]
798
- });
799
- if (base2 && "$ref" in base2)
800
- return { allOf: [base2], nullable: true };
801
- return base2 && { ...base2, nullable: true };
802
- }
803
- const base = parseDef(def.innerType._def, {
804
- ...refs,
805
- currentPath: [...refs.currentPath, "anyOf", "0"]
806
- });
807
- return base && { anyOf: [base, { type: "null" }] };
808
- }
809
- function parseNumberDef(def, refs) {
810
- const res = {
811
- type: "number"
812
- };
813
- if (!def.checks)
814
- return res;
815
- for (const check of def.checks) {
816
- switch (check.kind) {
817
- case "int":
818
- res.type = "integer";
819
- addErrorMessage(res, "type", check.message, refs);
820
- break;
821
- case "min":
822
- if (refs.target === "jsonSchema7") {
823
- if (check.inclusive) {
824
- setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
825
- } else {
826
- setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
827
- }
828
- } else {
829
- if (!check.inclusive) {
830
- res.exclusiveMinimum = true;
831
- }
832
- setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
833
- }
834
- break;
835
- case "max":
836
- if (refs.target === "jsonSchema7") {
837
- if (check.inclusive) {
838
- setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
839
- } else {
840
- setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
841
- }
842
- } else {
843
- if (!check.inclusive) {
844
- res.exclusiveMaximum = true;
845
- }
846
- setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
847
- }
848
- break;
849
- case "multipleOf":
850
- setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
851
- break;
852
- }
853
- }
854
- return res;
855
- }
856
- function parseObjectDef(def, refs) {
857
- const forceOptionalIntoNullable = refs.target === "openAi";
858
- const result = {
859
- type: "object",
860
- properties: {}
861
- };
862
- const required = [];
863
- const shape = def.shape();
864
- for (const propName in shape) {
865
- let propDef = shape[propName];
866
- if (propDef === void 0 || propDef._def === void 0) {
867
- continue;
868
- }
869
- let propOptional = safeIsOptional(propDef);
870
- if (propOptional && forceOptionalIntoNullable) {
871
- if (propDef._def.typeName === "ZodOptional") {
872
- propDef = propDef._def.innerType;
873
- }
874
- if (!propDef.isNullable()) {
875
- propDef = propDef.nullable();
876
- }
877
- propOptional = false;
878
- }
879
- const parsedDef = parseDef(propDef._def, {
880
- ...refs,
881
- currentPath: [...refs.currentPath, "properties", propName],
882
- propertyPath: [...refs.currentPath, "properties", propName]
883
- });
884
- if (parsedDef === void 0) {
885
- continue;
886
- }
887
- result.properties[propName] = parsedDef;
888
- if (!propOptional) {
889
- required.push(propName);
890
- }
891
- }
892
- if (required.length) {
893
- result.required = required;
894
- }
895
- const additionalProperties = decideAdditionalProperties(def, refs);
896
- if (additionalProperties !== void 0) {
897
- result.additionalProperties = additionalProperties;
898
- }
899
- return result;
900
- }
901
- function decideAdditionalProperties(def, refs) {
902
- if (def.catchall._def.typeName !== "ZodNever") {
903
- return parseDef(def.catchall._def, {
904
- ...refs,
905
- currentPath: [...refs.currentPath, "additionalProperties"]
906
- });
907
- }
908
- switch (def.unknownKeys) {
909
- case "passthrough":
910
- return refs.allowedAdditionalProperties;
911
- case "strict":
912
- return refs.rejectedAdditionalProperties;
913
- case "strip":
914
- return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
915
- }
916
- }
917
- function safeIsOptional(schema) {
918
- try {
919
- return schema.isOptional();
920
- } catch {
921
- return true;
922
- }
923
- }
924
- const parseOptionalDef = (def, refs) => {
925
- if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
926
- return parseDef(def.innerType._def, refs);
927
- }
928
- const innerSchema = parseDef(def.innerType._def, {
929
- ...refs,
930
- currentPath: [...refs.currentPath, "anyOf", "1"]
931
- });
932
- return innerSchema ? {
933
- anyOf: [
934
- {
935
- not: parseAnyDef(refs)
936
- },
937
- innerSchema
938
- ]
939
- } : parseAnyDef(refs);
940
- };
941
- const parsePipelineDef = (def, refs) => {
942
- if (refs.pipeStrategy === "input") {
943
- return parseDef(def.in._def, refs);
944
- } else if (refs.pipeStrategy === "output") {
945
- return parseDef(def.out._def, refs);
946
- }
947
- const a = parseDef(def.in._def, {
948
- ...refs,
949
- currentPath: [...refs.currentPath, "allOf", "0"]
950
- });
951
- const b = parseDef(def.out._def, {
952
- ...refs,
953
- currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
954
- });
955
- return {
956
- allOf: [a, b].filter((x) => x !== void 0)
957
- };
958
- };
959
- function parsePromiseDef(def, refs) {
960
- return parseDef(def.type._def, refs);
961
- }
962
- function parseSetDef(def, refs) {
963
- const items = parseDef(def.valueType._def, {
964
- ...refs,
965
- currentPath: [...refs.currentPath, "items"]
966
- });
967
- const schema = {
968
- type: "array",
969
- uniqueItems: true,
970
- items
971
- };
972
- if (def.minSize) {
973
- setResponseValueAndErrors(schema, "minItems", def.minSize.value, def.minSize.message, refs);
974
- }
975
- if (def.maxSize) {
976
- setResponseValueAndErrors(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
977
- }
978
- return schema;
979
- }
980
- function parseTupleDef(def, refs) {
981
- if (def.rest) {
982
- return {
983
- type: "array",
984
- minItems: def.items.length,
985
- items: def.items.map((x, i) => parseDef(x._def, {
986
- ...refs,
987
- currentPath: [...refs.currentPath, "items", `${i}`]
988
- })).reduce((acc, x) => x === void 0 ? acc : [...acc, x], []),
989
- additionalItems: parseDef(def.rest._def, {
990
- ...refs,
991
- currentPath: [...refs.currentPath, "additionalItems"]
992
- })
993
- };
994
- } else {
995
- return {
996
- type: "array",
997
- minItems: def.items.length,
998
- maxItems: def.items.length,
999
- items: def.items.map((x, i) => parseDef(x._def, {
1000
- ...refs,
1001
- currentPath: [...refs.currentPath, "items", `${i}`]
1002
- })).reduce((acc, x) => x === void 0 ? acc : [...acc, x], [])
1003
- };
1004
- }
1005
- }
1006
- function parseUndefinedDef(refs) {
1007
- return {
1008
- not: parseAnyDef(refs)
1009
- };
1010
- }
1011
- function parseUnknownDef(refs) {
1012
- return parseAnyDef(refs);
1013
- }
1014
- const parseReadonlyDef = (def, refs) => {
1015
- return parseDef(def.innerType._def, refs);
1016
- };
1017
- const selectParser = (def, typeName, refs) => {
1018
- switch (typeName) {
1019
- case ZodFirstPartyTypeKind.ZodString:
1020
- return parseStringDef(def, refs);
1021
- case ZodFirstPartyTypeKind.ZodNumber:
1022
- return parseNumberDef(def, refs);
1023
- case ZodFirstPartyTypeKind.ZodObject:
1024
- return parseObjectDef(def, refs);
1025
- case ZodFirstPartyTypeKind.ZodBigInt:
1026
- return parseBigintDef(def, refs);
1027
- case ZodFirstPartyTypeKind.ZodBoolean:
1028
- return parseBooleanDef();
1029
- case ZodFirstPartyTypeKind.ZodDate:
1030
- return parseDateDef(def, refs);
1031
- case ZodFirstPartyTypeKind.ZodUndefined:
1032
- return parseUndefinedDef(refs);
1033
- case ZodFirstPartyTypeKind.ZodNull:
1034
- return parseNullDef(refs);
1035
- case ZodFirstPartyTypeKind.ZodArray:
1036
- return parseArrayDef(def, refs);
1037
- case ZodFirstPartyTypeKind.ZodUnion:
1038
- case ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
1039
- return parseUnionDef(def, refs);
1040
- case ZodFirstPartyTypeKind.ZodIntersection:
1041
- return parseIntersectionDef(def, refs);
1042
- case ZodFirstPartyTypeKind.ZodTuple:
1043
- return parseTupleDef(def, refs);
1044
- case ZodFirstPartyTypeKind.ZodRecord:
1045
- return parseRecordDef(def, refs);
1046
- case ZodFirstPartyTypeKind.ZodLiteral:
1047
- return parseLiteralDef(def, refs);
1048
- case ZodFirstPartyTypeKind.ZodEnum:
1049
- return parseEnumDef(def);
1050
- case ZodFirstPartyTypeKind.ZodNativeEnum:
1051
- return parseNativeEnumDef(def);
1052
- case ZodFirstPartyTypeKind.ZodNullable:
1053
- return parseNullableDef(def, refs);
1054
- case ZodFirstPartyTypeKind.ZodOptional:
1055
- return parseOptionalDef(def, refs);
1056
- case ZodFirstPartyTypeKind.ZodMap:
1057
- return parseMapDef(def, refs);
1058
- case ZodFirstPartyTypeKind.ZodSet:
1059
- return parseSetDef(def, refs);
1060
- case ZodFirstPartyTypeKind.ZodLazy:
1061
- return () => def.getter()._def;
1062
- case ZodFirstPartyTypeKind.ZodPromise:
1063
- return parsePromiseDef(def, refs);
1064
- case ZodFirstPartyTypeKind.ZodNaN:
1065
- case ZodFirstPartyTypeKind.ZodNever:
1066
- return parseNeverDef(refs);
1067
- case ZodFirstPartyTypeKind.ZodEffects:
1068
- return parseEffectsDef(def, refs);
1069
- case ZodFirstPartyTypeKind.ZodAny:
1070
- return parseAnyDef(refs);
1071
- case ZodFirstPartyTypeKind.ZodUnknown:
1072
- return parseUnknownDef(refs);
1073
- case ZodFirstPartyTypeKind.ZodDefault:
1074
- return parseDefaultDef(def, refs);
1075
- case ZodFirstPartyTypeKind.ZodBranded:
1076
- return parseBrandedDef(def, refs);
1077
- case ZodFirstPartyTypeKind.ZodReadonly:
1078
- return parseReadonlyDef(def, refs);
1079
- case ZodFirstPartyTypeKind.ZodCatch:
1080
- return parseCatchDef(def, refs);
1081
- case ZodFirstPartyTypeKind.ZodPipeline:
1082
- return parsePipelineDef(def, refs);
1083
- case ZodFirstPartyTypeKind.ZodFunction:
1084
- case ZodFirstPartyTypeKind.ZodVoid:
1085
- case ZodFirstPartyTypeKind.ZodSymbol:
1086
- return void 0;
1087
- default:
1088
- return /* @__PURE__ */ ((_) => void 0)();
1089
- }
1090
- };
1091
- function parseDef(def, refs, forceResolution = false) {
1092
- const seenItem = refs.seen.get(def);
1093
- if (refs.override) {
1094
- const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
1095
- if (overrideResult !== ignoreOverride) {
1096
- return overrideResult;
1097
- }
1098
- }
1099
- if (seenItem && !forceResolution) {
1100
- const seenSchema = get$ref(seenItem, refs);
1101
- if (seenSchema !== void 0) {
1102
- return seenSchema;
1103
- }
1104
- }
1105
- const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
1106
- refs.seen.set(def, newItem);
1107
- const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
1108
- const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
1109
- if (jsonSchema) {
1110
- addMeta(def, refs, jsonSchema);
1111
- }
1112
- if (refs.postProcess) {
1113
- const postProcessResult = refs.postProcess(jsonSchema, def, refs);
1114
- newItem.jsonSchema = jsonSchema;
1115
- return postProcessResult;
1116
- }
1117
- newItem.jsonSchema = jsonSchema;
1118
- return jsonSchema;
1119
- }
1120
- const get$ref = (item, refs) => {
1121
- switch (refs.$refStrategy) {
1122
- case "root":
1123
- return { $ref: item.path.join("/") };
1124
- case "relative":
1125
- return { $ref: getRelativePath(refs.currentPath, item.path) };
1126
- case "none":
1127
- case "seen": {
1128
- if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
1129
- console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
1130
- return parseAnyDef(refs);
1131
- }
1132
- return refs.$refStrategy === "seen" ? parseAnyDef(refs) : void 0;
1133
- }
1134
- }
1135
- };
1136
- const addMeta = (def, refs, jsonSchema) => {
1137
- if (def.description) {
1138
- jsonSchema.description = def.description;
1139
- if (refs.markdownDescription) {
1140
- jsonSchema.markdownDescription = def.description;
1141
- }
1142
- }
1143
- return jsonSchema;
1144
- };
1145
- const zodToJsonSchema = (schema, options) => {
1146
- const refs = getRefs(options);
1147
- let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name2, schema2]) => ({
1148
- ...acc,
1149
- [name2]: parseDef(schema2._def, {
1150
- ...refs,
1151
- currentPath: [...refs.basePath, refs.definitionPath, name2]
1152
- }, true) ?? parseAnyDef(refs)
1153
- }), {}) : void 0;
1154
- const name = typeof options === "string" ? options : options?.nameStrategy === "title" ? void 0 : options?.name;
1155
- const main = parseDef(schema._def, name === void 0 ? refs : {
1156
- ...refs,
1157
- currentPath: [...refs.basePath, refs.definitionPath, name]
1158
- }, false) ?? parseAnyDef(refs);
1159
- const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
1160
- if (title !== void 0) {
1161
- main.title = title;
1162
- }
1163
- if (refs.flags.hasReferencedOpenAiAnyType) {
1164
- if (!definitions) {
1165
- definitions = {};
1166
- }
1167
- if (!definitions[refs.openAiAnyTypeName]) {
1168
- definitions[refs.openAiAnyTypeName] = {
1169
- // Skipping "object" as no properties can be defined and additionalProperties must be "false"
1170
- type: ["string", "number", "integer", "boolean", "array", "null"],
1171
- items: {
1172
- $ref: refs.$refStrategy === "relative" ? "1" : [
1173
- ...refs.basePath,
1174
- refs.definitionPath,
1175
- refs.openAiAnyTypeName
1176
- ].join("/")
1177
- }
1178
- };
1179
- }
1180
- }
1181
- const combined = name === void 0 ? definitions ? {
1182
- ...main,
1183
- [refs.definitionPath]: definitions
1184
- } : main : {
1185
- $ref: [
1186
- ...refs.$refStrategy === "relative" ? [] : refs.basePath,
1187
- refs.definitionPath,
1188
- name
1189
- ].join("/"),
1190
- [refs.definitionPath]: {
1191
- ...definitions,
1192
- [name]: main
1193
- }
1194
- };
1195
- if (refs.target === "jsonSchema7") {
1196
- combined.$schema = "http://json-schema.org/draft-07/schema#";
1197
- } else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
1198
- combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
1199
- }
1200
- if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) {
1201
- console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
1202
- }
1203
- return combined;
1204
- };
1205
- export {
1206
- zodToJsonSchema as z
1207
- };
1
+ import{V as o}from"./zod.mjs";const $=Symbol("Let zodToJsonSchema decide on which parser to use"),A={name:void 0,$refStrategy:"root",basePath:["#"],effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",removeAdditionalStrategy:"passthrough",allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:"definitions",target:"jsonSchema7",strictUnions:!1,definitions:{},errorMessages:!1,markdownDescription:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref",openAiAnyTypeName:"OpenAiAnyType"},x=e=>typeof e=="string"?{...A,name:e}:{...A,...e},D=e=>{const t=x(e),n=t.name!==void 0?[...t.basePath,t.definitionPath,t.name]:t.basePath;return{...t,flags:{hasReferencedOpenAiAnyType:!1},currentPath:n,propertyPath:void 0,seen:new Map(Object.entries(t.definitions).map(([a,r])=>[r._def,{def:r._def,path:[...t.basePath,t.definitionPath,a],jsonSchema:void 0}]))}};function Z(e,t,n,a){a?.errorMessages&&n&&(e.errorMessage={...e.errorMessage,[t]:n})}function p(e,t,n,a,r){e[t]=n,Z(e,t,a,r)}const S=(e,t)=>{let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];n++);return[(e.length-n).toString(),...t.slice(n)].join("/")};function d(e){if(e.target!=="openAi")return{};const t=[...e.basePath,e.definitionPath,e.openAiAnyTypeName];return e.flags.hasReferencedOpenAiAnyType=!0,{$ref:e.$refStrategy==="relative"?S(t,e.currentPath):t.join("/")}}function M(e,t){const n={type:"array"};return e.type?._def&&e.type?._def?.typeName!==o.ZodAny&&(n.items=c(e.type._def,{...t,currentPath:[...t.currentPath,"items"]})),e.minLength&&p(n,"minItems",e.minLength.value,e.minLength.message,t),e.maxLength&&p(n,"maxItems",e.maxLength.value,e.maxLength.message,t),e.exactLength&&(p(n,"minItems",e.exactLength.value,e.exactLength.message,t),p(n,"maxItems",e.exactLength.value,e.exactLength.message,t)),n}function w(e,t){const n={type:"integer",format:"int64"};if(!e.checks)return n;for(const a of e.checks)switch(a.kind){case"min":t.target==="jsonSchema7"?a.inclusive?p(n,"minimum",a.value,a.message,t):p(n,"exclusiveMinimum",a.value,a.message,t):(a.inclusive||(n.exclusiveMinimum=!0),p(n,"minimum",a.value,a.message,t));break;case"max":t.target==="jsonSchema7"?a.inclusive?p(n,"maximum",a.value,a.message,t):p(n,"exclusiveMaximum",a.value,a.message,t):(a.inclusive||(n.exclusiveMaximum=!0),p(n,"maximum",a.value,a.message,t));break;case"multipleOf":p(n,"multipleOf",a.value,a.message,t);break}return n}function z(){return{type:"boolean"}}function O(e,t){return c(e.type._def,t)}const L=(e,t)=>c(e.innerType._def,t);function T(e,t,n){const a=n??t.dateStrategy;if(Array.isArray(a))return{anyOf:a.map((r,i)=>T(e,t,r))};switch(a){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":return F(e,t)}}const F=(e,t)=>{const n={type:"integer",format:"unix-time"};if(t.target==="openApi3")return n;for(const a of e.checks)switch(a.kind){case"min":p(n,"minimum",a.value,a.message,t);break;case"max":p(n,"maximum",a.value,a.message,t);break}return n};function I(e,t){return{...c(e.innerType._def,t),default:e.defaultValue()}}function E(e,t){return t.effectStrategy==="input"?c(e.schema._def,t):d(t)}function R(e){return{type:"string",enum:Array.from(e.values)}}const C=e=>"type"in e&&e.type==="string"?!1:"allOf"in e;function U(e,t){const n=[c(e.left._def,{...t,currentPath:[...t.currentPath,"allOf","0"]}),c(e.right._def,{...t,currentPath:[...t.currentPath,"allOf","1"]})].filter(i=>!!i);let a=t.target==="jsonSchema2019-09"?{unevaluatedProperties:!1}:void 0;const r=[];return n.forEach(i=>{if(C(i))r.push(...i.allOf),i.unevaluatedProperties===void 0&&(a=void 0);else{let u=i;if("additionalProperties"in i&&i.additionalProperties===!1){const{additionalProperties:l,...s}=i;u=s}else a=void 0;r.push(u)}}),r.length?{allOf:r,...a}:void 0}function B(e,t){const n=typeof e.value;return n!=="bigint"&&n!=="number"&&n!=="boolean"&&n!=="string"?{type:Array.isArray(e.value)?"array":"object"}:t.target==="openApi3"?{type:n==="bigint"?"integer":n,enum:[e.value]}:{type:n==="bigint"?"integer":n,const:e.value}}let v;const g={cuid:/^[cC][^\s-]{8,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,email:/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,emoji:()=>(v===void 0&&(v=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),v),uuid:/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,ipv4:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ipv4Cidr:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,ipv6:/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,ipv6Cidr:/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64:/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,base64url:/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,nanoid:/^[a-zA-Z0-9_-]{21}$/,jwt:/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/};function j(e,t){const n={type:"string"};if(e.checks)for(const a of e.checks)switch(a.kind){case"min":p(n,"minLength",typeof n.minLength=="number"?Math.max(n.minLength,a.value):a.value,a.message,t);break;case"max":p(n,"maxLength",typeof n.maxLength=="number"?Math.min(n.maxLength,a.value):a.value,a.message,t);break;case"email":switch(t.emailStrategy){case"format:email":y(n,"email",a.message,t);break;case"format:idn-email":y(n,"idn-email",a.message,t);break;case"pattern:zod":m(n,g.email,a.message,t);break}break;case"url":y(n,"uri",a.message,t);break;case"uuid":y(n,"uuid",a.message,t);break;case"regex":m(n,a.regex,a.message,t);break;case"cuid":m(n,g.cuid,a.message,t);break;case"cuid2":m(n,g.cuid2,a.message,t);break;case"startsWith":m(n,RegExp(`^${P(a.value,t)}`),a.message,t);break;case"endsWith":m(n,RegExp(`${P(a.value,t)}$`),a.message,t);break;case"datetime":y(n,"date-time",a.message,t);break;case"date":y(n,"date",a.message,t);break;case"time":y(n,"time",a.message,t);break;case"duration":y(n,"duration",a.message,t);break;case"length":p(n,"minLength",typeof n.minLength=="number"?Math.max(n.minLength,a.value):a.value,a.message,t),p(n,"maxLength",typeof n.maxLength=="number"?Math.min(n.maxLength,a.value):a.value,a.message,t);break;case"includes":{m(n,RegExp(P(a.value,t)),a.message,t);break}case"ip":{a.version!=="v6"&&y(n,"ipv4",a.message,t),a.version!=="v4"&&y(n,"ipv6",a.message,t);break}case"base64url":m(n,g.base64url,a.message,t);break;case"jwt":m(n,g.jwt,a.message,t);break;case"cidr":{a.version!=="v6"&&m(n,g.ipv4Cidr,a.message,t),a.version!=="v4"&&m(n,g.ipv6Cidr,a.message,t);break}case"emoji":m(n,g.emoji(),a.message,t);break;case"ulid":{m(n,g.ulid,a.message,t);break}case"base64":{switch(t.base64Strategy){case"format:binary":{y(n,"binary",a.message,t);break}case"contentEncoding:base64":{p(n,"contentEncoding","base64",a.message,t);break}case"pattern:zod":{m(n,g.base64,a.message,t);break}}break}case"nanoid":m(n,g.nanoid,a.message,t)}return n}function P(e,t){return t.patternStrategy==="escape"?q(e):e}const V=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function q(e){let t="";for(let n=0;n<e.length;n++)V.has(e[n])||(t+="\\"),t+=e[n];return t}function y(e,t,n,a){e.format||e.anyOf?.some(r=>r.format)?(e.anyOf||(e.anyOf=[]),e.format&&(e.anyOf.push({format:e.format,...e.errorMessage&&a.errorMessages&&{errorMessage:{format:e.errorMessage.format}}}),delete e.format,e.errorMessage&&(delete e.errorMessage.format,Object.keys(e.errorMessage).length===0&&delete e.errorMessage)),e.anyOf.push({format:t,...n&&a.errorMessages&&{errorMessage:{format:n}}})):p(e,"format",t,n,a)}function m(e,t,n,a){e.pattern||e.allOf?.some(r=>r.pattern)?(e.allOf||(e.allOf=[]),e.pattern&&(e.allOf.push({pattern:e.pattern,...e.errorMessage&&a.errorMessages&&{errorMessage:{pattern:e.errorMessage.pattern}}}),delete e.pattern,e.errorMessage&&(delete e.errorMessage.pattern,Object.keys(e.errorMessage).length===0&&delete e.errorMessage)),e.allOf.push({pattern:k(t,a),...n&&a.errorMessages&&{errorMessage:{pattern:n}}})):p(e,"pattern",k(t,a),n,a)}function k(e,t){if(!t.applyRegexFlags||!e.flags)return e.source;const n={i:e.flags.includes("i"),m:e.flags.includes("m"),s:e.flags.includes("s")},a=n.i?e.source.toLowerCase():e.source;let r="",i=!1,u=!1,l=!1;for(let s=0;s<a.length;s++){if(i){r+=a[s],i=!1;continue}if(n.i){if(u){if(a[s].match(/[a-z]/)){l?(r+=a[s],r+=`${a[s-2]}-${a[s]}`.toUpperCase(),l=!1):a[s+1]==="-"&&a[s+2]?.match(/[a-z]/)?(r+=a[s],l=!0):r+=`${a[s]}${a[s].toUpperCase()}`;continue}}else if(a[s].match(/[a-z]/)){r+=`[${a[s]}${a[s].toUpperCase()}]`;continue}}if(n.m){if(a[s]==="^"){r+=`(^|(?<=[\r
2
+ ]))`;continue}else if(a[s]==="$"){r+=`($|(?=[\r
3
+ ]))`;continue}}if(n.s&&a[s]==="."){r+=u?`${a[s]}\r
4
+ `:`[${a[s]}\r
5
+ ]`;continue}r+=a[s],a[s]==="\\"?i=!0:u&&a[s]==="]"?u=!1:!u&&a[s]==="["&&(u=!0)}try{new RegExp(r)}catch{return console.warn(`Could not convert regex pattern at ${t.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),e.source}return r}function N(e,t){if(t.target==="openAi"&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),t.target==="openApi3"&&e.keyType?._def.typeName===o.ZodEnum)return{type:"object",required:e.keyType._def.values,properties:e.keyType._def.values.reduce((a,r)=>({...a,[r]:c(e.valueType._def,{...t,currentPath:[...t.currentPath,"properties",r]})??d(t)}),{}),additionalProperties:t.rejectedAdditionalProperties};const n={type:"object",additionalProperties:c(e.valueType._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??t.allowedAdditionalProperties};if(t.target==="openApi3")return n;if(e.keyType?._def.typeName===o.ZodString&&e.keyType._def.checks?.length){const{type:a,...r}=j(e.keyType._def,t);return{...n,propertyNames:r}}else{if(e.keyType?._def.typeName===o.ZodEnum)return{...n,propertyNames:{enum:e.keyType._def.values}};if(e.keyType?._def.typeName===o.ZodBranded&&e.keyType._def.type._def.typeName===o.ZodString&&e.keyType._def.type._def.checks?.length){const{type:a,...r}=O(e.keyType._def,t);return{...n,propertyNames:r}}}return n}function K(e,t){if(t.mapStrategy==="record")return N(e,t);const n=c(e.keyType._def,{...t,currentPath:[...t.currentPath,"items","items","0"]})||d(t),a=c(e.valueType._def,{...t,currentPath:[...t.currentPath,"items","items","1"]})||d(t);return{type:"array",maxItems:125,items:{type:"array",items:[n,a],minItems:2,maxItems:2}}}function J(e){const t=e.values,a=Object.keys(e.values).filter(i=>typeof t[t[i]]!="number").map(i=>t[i]),r=Array.from(new Set(a.map(i=>typeof i)));return{type:r.length===1?r[0]==="string"?"string":"number":["string","number"],enum:a}}function W(e){return e.target==="openAi"?void 0:{not:d({...e,currentPath:[...e.currentPath,"not"]})}}function G(e){return e.target==="openApi3"?{enum:["null"],nullable:!0}:{type:"null"}}const b={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function H(e,t){if(t.target==="openApi3")return _(e,t);const n=e.options instanceof Map?Array.from(e.options.values()):e.options;if(n.every(a=>a._def.typeName in b&&(!a._def.checks||!a._def.checks.length))){const a=n.reduce((r,i)=>{const u=b[i._def.typeName];return u&&!r.includes(u)?[...r,u]:r},[]);return{type:a.length>1?a:a[0]}}else if(n.every(a=>a._def.typeName==="ZodLiteral"&&!a.description)){const a=n.reduce((r,i)=>{const u=typeof i._def.value;switch(u){case"string":case"number":case"boolean":return[...r,u];case"bigint":return[...r,"integer"];case"object":if(i._def.value===null)return[...r,"null"];default:return r}},[]);if(a.length===n.length){const r=a.filter((i,u,l)=>l.indexOf(i)===u);return{type:r.length>1?r:r[0],enum:n.reduce((i,u)=>i.includes(u._def.value)?i:[...i,u._def.value],[])}}}else if(n.every(a=>a._def.typeName==="ZodEnum"))return{type:"string",enum:n.reduce((a,r)=>[...a,...r._def.values.filter(i=>!a.includes(i))],[])};return _(e,t)}const _=(e,t)=>{const n=(e.options instanceof Map?Array.from(e.options.values()):e.options).map((a,r)=>c(a._def,{...t,currentPath:[...t.currentPath,"anyOf",`${r}`]})).filter(a=>!!a&&(!t.strictUnions||typeof a=="object"&&Object.keys(a).length>0));return n.length?{anyOf:n}:void 0};function Q(e,t){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(e.innerType._def.typeName)&&(!e.innerType._def.checks||!e.innerType._def.checks.length))return t.target==="openApi3"?{type:b[e.innerType._def.typeName],nullable:!0}:{type:[b[e.innerType._def.typeName],"null"]};if(t.target==="openApi3"){const a=c(e.innerType._def,{...t,currentPath:[...t.currentPath]});return a&&"$ref"in a?{allOf:[a],nullable:!0}:a&&{...a,nullable:!0}}const n=c(e.innerType._def,{...t,currentPath:[...t.currentPath,"anyOf","0"]});return n&&{anyOf:[n,{type:"null"}]}}function X(e,t){const n={type:"number"};if(!e.checks)return n;for(const a of e.checks)switch(a.kind){case"int":n.type="integer",Z(n,"type",a.message,t);break;case"min":t.target==="jsonSchema7"?a.inclusive?p(n,"minimum",a.value,a.message,t):p(n,"exclusiveMinimum",a.value,a.message,t):(a.inclusive||(n.exclusiveMinimum=!0),p(n,"minimum",a.value,a.message,t));break;case"max":t.target==="jsonSchema7"?a.inclusive?p(n,"maximum",a.value,a.message,t):p(n,"exclusiveMaximum",a.value,a.message,t):(a.inclusive||(n.exclusiveMaximum=!0),p(n,"maximum",a.value,a.message,t));break;case"multipleOf":p(n,"multipleOf",a.value,a.message,t);break}return n}function Y(e,t){const n=t.target==="openAi",a={type:"object",properties:{}},r=[],i=e.shape();for(const l in i){let s=i[l];if(s===void 0||s._def===void 0)continue;let f=te(s);f&&n&&(s._def.typeName==="ZodOptional"&&(s=s._def.innerType),s.isNullable()||(s=s.nullable()),f=!1);const h=c(s._def,{...t,currentPath:[...t.currentPath,"properties",l],propertyPath:[...t.currentPath,"properties",l]});h!==void 0&&(a.properties[l]=h,f||r.push(l))}r.length&&(a.required=r);const u=ee(e,t);return u!==void 0&&(a.additionalProperties=u),a}function ee(e,t){if(e.catchall._def.typeName!=="ZodNever")return c(e.catchall._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]});switch(e.unknownKeys){case"passthrough":return t.allowedAdditionalProperties;case"strict":return t.rejectedAdditionalProperties;case"strip":return t.removeAdditionalStrategy==="strict"?t.allowedAdditionalProperties:t.rejectedAdditionalProperties}}function te(e){try{return e.isOptional()}catch{return!0}}const ne=(e,t)=>{if(t.currentPath.toString()===t.propertyPath?.toString())return c(e.innerType._def,t);const n=c(e.innerType._def,{...t,currentPath:[...t.currentPath,"anyOf","1"]});return n?{anyOf:[{not:d(t)},n]}:d(t)},ae=(e,t)=>{if(t.pipeStrategy==="input")return c(e.in._def,t);if(t.pipeStrategy==="output")return c(e.out._def,t);const n=c(e.in._def,{...t,currentPath:[...t.currentPath,"allOf","0"]}),a=c(e.out._def,{...t,currentPath:[...t.currentPath,"allOf",n?"1":"0"]});return{allOf:[n,a].filter(r=>r!==void 0)}};function re(e,t){return c(e.type._def,t)}function ie(e,t){const a={type:"array",uniqueItems:!0,items:c(e.valueType._def,{...t,currentPath:[...t.currentPath,"items"]})};return e.minSize&&p(a,"minItems",e.minSize.value,e.minSize.message,t),e.maxSize&&p(a,"maxItems",e.maxSize.value,e.maxSize.message,t),a}function oe(e,t){return e.rest?{type:"array",minItems:e.items.length,items:e.items.map((n,a)=>c(n._def,{...t,currentPath:[...t.currentPath,"items",`${a}`]})).reduce((n,a)=>a===void 0?n:[...n,a],[]),additionalItems:c(e.rest._def,{...t,currentPath:[...t.currentPath,"additionalItems"]})}:{type:"array",minItems:e.items.length,maxItems:e.items.length,items:e.items.map((n,a)=>c(n._def,{...t,currentPath:[...t.currentPath,"items",`${a}`]})).reduce((n,a)=>a===void 0?n:[...n,a],[])}}function se(e){return{not:d(e)}}function ue(e){return d(e)}const ce=(e,t)=>c(e.innerType._def,t),le=(e,t,n)=>{switch(t){case o.ZodString:return j(e,n);case o.ZodNumber:return X(e,n);case o.ZodObject:return Y(e,n);case o.ZodBigInt:return w(e,n);case o.ZodBoolean:return z();case o.ZodDate:return T(e,n);case o.ZodUndefined:return se(n);case o.ZodNull:return G(n);case o.ZodArray:return M(e,n);case o.ZodUnion:case o.ZodDiscriminatedUnion:return H(e,n);case o.ZodIntersection:return U(e,n);case o.ZodTuple:return oe(e,n);case o.ZodRecord:return N(e,n);case o.ZodLiteral:return B(e,n);case o.ZodEnum:return R(e);case o.ZodNativeEnum:return J(e);case o.ZodNullable:return Q(e,n);case o.ZodOptional:return ne(e,n);case o.ZodMap:return K(e,n);case o.ZodSet:return ie(e,n);case o.ZodLazy:return()=>e.getter()._def;case o.ZodPromise:return re(e,n);case o.ZodNaN:case o.ZodNever:return W(n);case o.ZodEffects:return E(e,n);case o.ZodAny:return d(n);case o.ZodUnknown:return ue(n);case o.ZodDefault:return I(e,n);case o.ZodBranded:return O(e,n);case o.ZodReadonly:return ce(e,n);case o.ZodCatch:return L(e,n);case o.ZodPipeline:return ae(e,n);case o.ZodFunction:case o.ZodVoid:case o.ZodSymbol:return;default:return(a=>{})()}};function c(e,t,n=!1){const a=t.seen.get(e);if(t.override){const l=t.override?.(e,t,a,n);if(l!==$)return l}if(a&&!n){const l=pe(a,t);if(l!==void 0)return l}const r={def:e,path:t.currentPath,jsonSchema:void 0};t.seen.set(e,r);const i=le(e,e.typeName,t),u=typeof i=="function"?c(i(),t):i;if(u&&me(e,t,u),t.postProcess){const l=t.postProcess(u,e,t);return r.jsonSchema=u,l}return r.jsonSchema=u,u}const pe=(e,t)=>{switch(t.$refStrategy){case"root":return{$ref:e.path.join("/")};case"relative":return{$ref:S(t.currentPath,e.path)};case"none":case"seen":return e.path.length<t.currentPath.length&&e.path.every((n,a)=>t.currentPath[a]===n)?(console.warn(`Recursive reference detected at ${t.currentPath.join("/")}! Defaulting to any`),d(t)):t.$refStrategy==="seen"?d(t):void 0}},me=(e,t,n)=>(e.description&&(n.description=e.description,t.markdownDescription&&(n.markdownDescription=e.description)),n),ge=(e,t)=>{const n=D(t);let a=typeof t=="object"&&t.definitions?Object.entries(t.definitions).reduce((s,[f,h])=>({...s,[f]:c(h._def,{...n,currentPath:[...n.basePath,n.definitionPath,f]},!0)??d(n)}),{}):void 0;const r=typeof t=="string"?t:t?.nameStrategy==="title"?void 0:t?.name,i=c(e._def,r===void 0?n:{...n,currentPath:[...n.basePath,n.definitionPath,r]},!1)??d(n),u=typeof t=="object"&&t.name!==void 0&&t.nameStrategy==="title"?t.name:void 0;u!==void 0&&(i.title=u),n.flags.hasReferencedOpenAiAnyType&&(a||(a={}),a[n.openAiAnyTypeName]||(a[n.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:n.$refStrategy==="relative"?"1":[...n.basePath,n.definitionPath,n.openAiAnyTypeName].join("/")}}));const l=r===void 0?a?{...i,[n.definitionPath]:a}:i:{$ref:[...n.$refStrategy==="relative"?[]:n.basePath,n.definitionPath,r].join("/"),[n.definitionPath]:{...a,[r]:i}};return n.target==="jsonSchema7"?l.$schema="http://json-schema.org/draft-07/schema#":(n.target==="jsonSchema2019-09"||n.target==="openAi")&&(l.$schema="https://json-schema.org/draft/2019-09/schema#"),n.target==="openAi"&&("anyOf"in l||"oneOf"in l||"allOf"in l||"type"in l&&Array.isArray(l.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),l};export{ge as z};