@freesyntax/notch-cli 0.5.16 → 0.5.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apply-patch-EBZ5VLO7.js +15 -0
- package/dist/chunk-3QUV4JEX.js +162 -0
- package/dist/chunk-6CZCFY6H.js +98 -0
- package/dist/chunk-6U3ZAGYA.js +38 -0
- package/dist/chunk-75K7DQVI.js +630 -0
- package/dist/chunk-C4CPDDMN.js +246 -0
- package/dist/chunk-CQMAVWLJ.js +134 -0
- package/dist/chunk-FAULT7VE.js +139 -0
- package/dist/chunk-FFB7GK3Y.js +72 -0
- package/dist/chunk-GBZGR6ID.js +174 -0
- package/dist/chunk-KZAS754V.js +118 -0
- package/dist/chunk-O3WZW7GS.js +35 -0
- package/dist/chunk-TH6GKC7E.js +315 -0
- package/dist/chunk-UR4XL6OM.js +104 -0
- package/dist/chunk-W4FAGQFL.js +171 -0
- package/dist/chunk-YAYPQTOU.js +53 -0
- package/dist/edit-FXWXOFAF.js +7 -0
- package/dist/git-XVWI2BT7.js +7 -0
- package/dist/github-DOZ2MVQE.js +7 -0
- package/dist/glob-XSBN4MDB.js +7 -0
- package/dist/grep-2A42QPWM.js +7 -0
- package/dist/index.js +1751 -3214
- package/dist/lsp-WUEGBQ3F.js +7 -0
- package/dist/notebook-5U6PAF6M.js +7 -0
- package/dist/plugins-GJIUZCJ5.js +7 -0
- package/dist/read-LY2VGCZY.js +7 -0
- package/dist/server-4JRQH3DT.js +1479 -0
- package/dist/shell-RGXMLRLH.js +7 -0
- package/dist/task-VIJ3N5EB.js +11 -0
- package/dist/tools-XKVTMNR5.js +31 -0
- package/dist/web-fetch-XOH5PUCP.js +7 -0
- package/dist/write-DOLDW7HM.js +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,1479 @@
|
|
|
1
|
+
import "./chunk-3RG5ZIWI.js";
|
|
2
|
+
|
|
3
|
+
// src/mcp/server.ts
|
|
4
|
+
import readline from "readline";
|
|
5
|
+
|
|
6
|
+
// node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
7
|
+
var ignoreOverride = /* @__PURE__ */ Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
8
|
+
var defaultOptions = {
|
|
9
|
+
name: void 0,
|
|
10
|
+
$refStrategy: "root",
|
|
11
|
+
basePath: ["#"],
|
|
12
|
+
effectStrategy: "input",
|
|
13
|
+
pipeStrategy: "all",
|
|
14
|
+
dateStrategy: "format:date-time",
|
|
15
|
+
mapStrategy: "entries",
|
|
16
|
+
removeAdditionalStrategy: "passthrough",
|
|
17
|
+
allowedAdditionalProperties: true,
|
|
18
|
+
rejectedAdditionalProperties: false,
|
|
19
|
+
definitionPath: "definitions",
|
|
20
|
+
target: "jsonSchema7",
|
|
21
|
+
strictUnions: false,
|
|
22
|
+
definitions: {},
|
|
23
|
+
errorMessages: false,
|
|
24
|
+
markdownDescription: false,
|
|
25
|
+
patternStrategy: "escape",
|
|
26
|
+
applyRegexFlags: false,
|
|
27
|
+
emailStrategy: "format:email",
|
|
28
|
+
base64Strategy: "contentEncoding:base64",
|
|
29
|
+
nameStrategy: "ref",
|
|
30
|
+
openAiAnyTypeName: "OpenAiAnyType"
|
|
31
|
+
};
|
|
32
|
+
var getDefaultOptions = (options) => typeof options === "string" ? {
|
|
33
|
+
...defaultOptions,
|
|
34
|
+
name: options
|
|
35
|
+
} : {
|
|
36
|
+
...defaultOptions,
|
|
37
|
+
...options
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// node_modules/zod-to-json-schema/dist/esm/Refs.js
|
|
41
|
+
var getRefs = (options) => {
|
|
42
|
+
const _options = getDefaultOptions(options);
|
|
43
|
+
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
44
|
+
return {
|
|
45
|
+
..._options,
|
|
46
|
+
flags: { hasReferencedOpenAiAnyType: false },
|
|
47
|
+
currentPath,
|
|
48
|
+
propertyPath: void 0,
|
|
49
|
+
seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
|
|
50
|
+
def._def,
|
|
51
|
+
{
|
|
52
|
+
def: def._def,
|
|
53
|
+
path: [..._options.basePath, _options.definitionPath, name],
|
|
54
|
+
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
55
|
+
jsonSchema: void 0
|
|
56
|
+
}
|
|
57
|
+
]))
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// node_modules/zod-to-json-schema/dist/esm/errorMessages.js
|
|
62
|
+
function addErrorMessage(res, key, errorMessage, refs) {
|
|
63
|
+
if (!refs?.errorMessages)
|
|
64
|
+
return;
|
|
65
|
+
if (errorMessage) {
|
|
66
|
+
res.errorMessage = {
|
|
67
|
+
...res.errorMessage,
|
|
68
|
+
[key]: errorMessage
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
|
|
73
|
+
res[key] = value;
|
|
74
|
+
addErrorMessage(res, key, errorMessage, refs);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// node_modules/zod-to-json-schema/dist/esm/getRelativePath.js
|
|
78
|
+
var getRelativePath = (pathA, pathB) => {
|
|
79
|
+
let i = 0;
|
|
80
|
+
for (; i < pathA.length && i < pathB.length; i++) {
|
|
81
|
+
if (pathA[i] !== pathB[i])
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
88
|
+
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind3 } from "zod/v3";
|
|
89
|
+
|
|
90
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/any.js
|
|
91
|
+
function parseAnyDef(refs) {
|
|
92
|
+
if (refs.target !== "openAi") {
|
|
93
|
+
return {};
|
|
94
|
+
}
|
|
95
|
+
const anyDefinitionPath = [
|
|
96
|
+
...refs.basePath,
|
|
97
|
+
refs.definitionPath,
|
|
98
|
+
refs.openAiAnyTypeName
|
|
99
|
+
];
|
|
100
|
+
refs.flags.hasReferencedOpenAiAnyType = true;
|
|
101
|
+
return {
|
|
102
|
+
$ref: refs.$refStrategy === "relative" ? getRelativePath(anyDefinitionPath, refs.currentPath) : anyDefinitionPath.join("/")
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/array.js
|
|
107
|
+
import { ZodFirstPartyTypeKind } from "zod/v3";
|
|
108
|
+
function parseArrayDef(def, refs) {
|
|
109
|
+
const res = {
|
|
110
|
+
type: "array"
|
|
111
|
+
};
|
|
112
|
+
if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) {
|
|
113
|
+
res.items = parseDef(def.type._def, {
|
|
114
|
+
...refs,
|
|
115
|
+
currentPath: [...refs.currentPath, "items"]
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (def.minLength) {
|
|
119
|
+
setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
|
|
120
|
+
}
|
|
121
|
+
if (def.maxLength) {
|
|
122
|
+
setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
|
|
123
|
+
}
|
|
124
|
+
if (def.exactLength) {
|
|
125
|
+
setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
|
|
126
|
+
setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
|
|
127
|
+
}
|
|
128
|
+
return res;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js
|
|
132
|
+
function parseBigintDef(def, refs) {
|
|
133
|
+
const res = {
|
|
134
|
+
type: "integer",
|
|
135
|
+
format: "int64"
|
|
136
|
+
};
|
|
137
|
+
if (!def.checks)
|
|
138
|
+
return res;
|
|
139
|
+
for (const check of def.checks) {
|
|
140
|
+
switch (check.kind) {
|
|
141
|
+
case "min":
|
|
142
|
+
if (refs.target === "jsonSchema7") {
|
|
143
|
+
if (check.inclusive) {
|
|
144
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
145
|
+
} else {
|
|
146
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
if (!check.inclusive) {
|
|
150
|
+
res.exclusiveMinimum = true;
|
|
151
|
+
}
|
|
152
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
153
|
+
}
|
|
154
|
+
break;
|
|
155
|
+
case "max":
|
|
156
|
+
if (refs.target === "jsonSchema7") {
|
|
157
|
+
if (check.inclusive) {
|
|
158
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
159
|
+
} else {
|
|
160
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
if (!check.inclusive) {
|
|
164
|
+
res.exclusiveMaximum = true;
|
|
165
|
+
}
|
|
166
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
167
|
+
}
|
|
168
|
+
break;
|
|
169
|
+
case "multipleOf":
|
|
170
|
+
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return res;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
|
|
178
|
+
function parseBooleanDef() {
|
|
179
|
+
return {
|
|
180
|
+
type: "boolean"
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/branded.js
|
|
185
|
+
function parseBrandedDef(_def, refs) {
|
|
186
|
+
return parseDef(_def.type._def, refs);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/catch.js
|
|
190
|
+
var parseCatchDef = (def, refs) => {
|
|
191
|
+
return parseDef(def.innerType._def, refs);
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/date.js
|
|
195
|
+
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
196
|
+
const strategy = overrideDateStrategy ?? refs.dateStrategy;
|
|
197
|
+
if (Array.isArray(strategy)) {
|
|
198
|
+
return {
|
|
199
|
+
anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
switch (strategy) {
|
|
203
|
+
case "string":
|
|
204
|
+
case "format:date-time":
|
|
205
|
+
return {
|
|
206
|
+
type: "string",
|
|
207
|
+
format: "date-time"
|
|
208
|
+
};
|
|
209
|
+
case "format:date":
|
|
210
|
+
return {
|
|
211
|
+
type: "string",
|
|
212
|
+
format: "date"
|
|
213
|
+
};
|
|
214
|
+
case "integer":
|
|
215
|
+
return integerDateParser(def, refs);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
var integerDateParser = (def, refs) => {
|
|
219
|
+
const res = {
|
|
220
|
+
type: "integer",
|
|
221
|
+
format: "unix-time"
|
|
222
|
+
};
|
|
223
|
+
if (refs.target === "openApi3") {
|
|
224
|
+
return res;
|
|
225
|
+
}
|
|
226
|
+
for (const check of def.checks) {
|
|
227
|
+
switch (check.kind) {
|
|
228
|
+
case "min":
|
|
229
|
+
setResponseValueAndErrors(
|
|
230
|
+
res,
|
|
231
|
+
"minimum",
|
|
232
|
+
check.value,
|
|
233
|
+
// This is in milliseconds
|
|
234
|
+
check.message,
|
|
235
|
+
refs
|
|
236
|
+
);
|
|
237
|
+
break;
|
|
238
|
+
case "max":
|
|
239
|
+
setResponseValueAndErrors(
|
|
240
|
+
res,
|
|
241
|
+
"maximum",
|
|
242
|
+
check.value,
|
|
243
|
+
// This is in milliseconds
|
|
244
|
+
check.message,
|
|
245
|
+
refs
|
|
246
|
+
);
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return res;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/default.js
|
|
254
|
+
function parseDefaultDef(_def, refs) {
|
|
255
|
+
return {
|
|
256
|
+
...parseDef(_def.innerType._def, refs),
|
|
257
|
+
default: _def.defaultValue()
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/effects.js
|
|
262
|
+
function parseEffectsDef(_def, refs) {
|
|
263
|
+
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : parseAnyDef(refs);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/enum.js
|
|
267
|
+
function parseEnumDef(def) {
|
|
268
|
+
return {
|
|
269
|
+
type: "string",
|
|
270
|
+
enum: Array.from(def.values)
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
|
|
275
|
+
var isJsonSchema7AllOfType = (type) => {
|
|
276
|
+
if ("type" in type && type.type === "string")
|
|
277
|
+
return false;
|
|
278
|
+
return "allOf" in type;
|
|
279
|
+
};
|
|
280
|
+
function parseIntersectionDef(def, refs) {
|
|
281
|
+
const allOf = [
|
|
282
|
+
parseDef(def.left._def, {
|
|
283
|
+
...refs,
|
|
284
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
285
|
+
}),
|
|
286
|
+
parseDef(def.right._def, {
|
|
287
|
+
...refs,
|
|
288
|
+
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
289
|
+
})
|
|
290
|
+
].filter((x) => !!x);
|
|
291
|
+
let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : void 0;
|
|
292
|
+
const mergedAllOf = [];
|
|
293
|
+
allOf.forEach((schema) => {
|
|
294
|
+
if (isJsonSchema7AllOfType(schema)) {
|
|
295
|
+
mergedAllOf.push(...schema.allOf);
|
|
296
|
+
if (schema.unevaluatedProperties === void 0) {
|
|
297
|
+
unevaluatedProperties = void 0;
|
|
298
|
+
}
|
|
299
|
+
} else {
|
|
300
|
+
let nestedSchema = schema;
|
|
301
|
+
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
302
|
+
const { additionalProperties, ...rest } = schema;
|
|
303
|
+
nestedSchema = rest;
|
|
304
|
+
} else {
|
|
305
|
+
unevaluatedProperties = void 0;
|
|
306
|
+
}
|
|
307
|
+
mergedAllOf.push(nestedSchema);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
return mergedAllOf.length ? {
|
|
311
|
+
allOf: mergedAllOf,
|
|
312
|
+
...unevaluatedProperties
|
|
313
|
+
} : void 0;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/literal.js
|
|
317
|
+
function parseLiteralDef(def, refs) {
|
|
318
|
+
const parsedType = typeof def.value;
|
|
319
|
+
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
320
|
+
return {
|
|
321
|
+
type: Array.isArray(def.value) ? "array" : "object"
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
if (refs.target === "openApi3") {
|
|
325
|
+
return {
|
|
326
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
327
|
+
enum: [def.value]
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
332
|
+
const: def.value
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
337
|
+
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2 } from "zod/v3";
|
|
338
|
+
|
|
339
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/string.js
|
|
340
|
+
var emojiRegex = void 0;
|
|
341
|
+
var zodPatterns = {
|
|
342
|
+
/**
|
|
343
|
+
* `c` was changed to `[cC]` to replicate /i flag
|
|
344
|
+
*/
|
|
345
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
346
|
+
cuid2: /^[0-9a-z]+$/,
|
|
347
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
348
|
+
/**
|
|
349
|
+
* `a-z` was added to replicate /i flag
|
|
350
|
+
*/
|
|
351
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
352
|
+
/**
|
|
353
|
+
* Constructed a valid Unicode RegExp
|
|
354
|
+
*
|
|
355
|
+
* Lazily instantiate since this type of regex isn't supported
|
|
356
|
+
* in all envs (e.g. React Native).
|
|
357
|
+
*
|
|
358
|
+
* See:
|
|
359
|
+
* https://github.com/colinhacks/zod/issues/2433
|
|
360
|
+
* Fix in Zod:
|
|
361
|
+
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
362
|
+
*/
|
|
363
|
+
emoji: () => {
|
|
364
|
+
if (emojiRegex === void 0) {
|
|
365
|
+
emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
366
|
+
}
|
|
367
|
+
return emojiRegex;
|
|
368
|
+
},
|
|
369
|
+
/**
|
|
370
|
+
* Unused
|
|
371
|
+
*/
|
|
372
|
+
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}$/,
|
|
373
|
+
/**
|
|
374
|
+
* Unused
|
|
375
|
+
*/
|
|
376
|
+
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])$/,
|
|
377
|
+
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])$/,
|
|
378
|
+
/**
|
|
379
|
+
* Unused
|
|
380
|
+
*/
|
|
381
|
+
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})))$/,
|
|
382
|
+
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])$/,
|
|
383
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
384
|
+
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
385
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
386
|
+
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
387
|
+
};
|
|
388
|
+
function parseStringDef(def, refs) {
|
|
389
|
+
const res = {
|
|
390
|
+
type: "string"
|
|
391
|
+
};
|
|
392
|
+
if (def.checks) {
|
|
393
|
+
for (const check of def.checks) {
|
|
394
|
+
switch (check.kind) {
|
|
395
|
+
case "min":
|
|
396
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
397
|
+
break;
|
|
398
|
+
case "max":
|
|
399
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
400
|
+
break;
|
|
401
|
+
case "email":
|
|
402
|
+
switch (refs.emailStrategy) {
|
|
403
|
+
case "format:email":
|
|
404
|
+
addFormat(res, "email", check.message, refs);
|
|
405
|
+
break;
|
|
406
|
+
case "format:idn-email":
|
|
407
|
+
addFormat(res, "idn-email", check.message, refs);
|
|
408
|
+
break;
|
|
409
|
+
case "pattern:zod":
|
|
410
|
+
addPattern(res, zodPatterns.email, check.message, refs);
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
break;
|
|
414
|
+
case "url":
|
|
415
|
+
addFormat(res, "uri", check.message, refs);
|
|
416
|
+
break;
|
|
417
|
+
case "uuid":
|
|
418
|
+
addFormat(res, "uuid", check.message, refs);
|
|
419
|
+
break;
|
|
420
|
+
case "regex":
|
|
421
|
+
addPattern(res, check.regex, check.message, refs);
|
|
422
|
+
break;
|
|
423
|
+
case "cuid":
|
|
424
|
+
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
425
|
+
break;
|
|
426
|
+
case "cuid2":
|
|
427
|
+
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
428
|
+
break;
|
|
429
|
+
case "startsWith":
|
|
430
|
+
addPattern(res, RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`), check.message, refs);
|
|
431
|
+
break;
|
|
432
|
+
case "endsWith":
|
|
433
|
+
addPattern(res, RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`), check.message, refs);
|
|
434
|
+
break;
|
|
435
|
+
case "datetime":
|
|
436
|
+
addFormat(res, "date-time", check.message, refs);
|
|
437
|
+
break;
|
|
438
|
+
case "date":
|
|
439
|
+
addFormat(res, "date", check.message, refs);
|
|
440
|
+
break;
|
|
441
|
+
case "time":
|
|
442
|
+
addFormat(res, "time", check.message, refs);
|
|
443
|
+
break;
|
|
444
|
+
case "duration":
|
|
445
|
+
addFormat(res, "duration", check.message, refs);
|
|
446
|
+
break;
|
|
447
|
+
case "length":
|
|
448
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
449
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
450
|
+
break;
|
|
451
|
+
case "includes": {
|
|
452
|
+
addPattern(res, RegExp(escapeLiteralCheckValue(check.value, refs)), check.message, refs);
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
case "ip": {
|
|
456
|
+
if (check.version !== "v6") {
|
|
457
|
+
addFormat(res, "ipv4", check.message, refs);
|
|
458
|
+
}
|
|
459
|
+
if (check.version !== "v4") {
|
|
460
|
+
addFormat(res, "ipv6", check.message, refs);
|
|
461
|
+
}
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
case "base64url":
|
|
465
|
+
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
466
|
+
break;
|
|
467
|
+
case "jwt":
|
|
468
|
+
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
469
|
+
break;
|
|
470
|
+
case "cidr": {
|
|
471
|
+
if (check.version !== "v6") {
|
|
472
|
+
addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
473
|
+
}
|
|
474
|
+
if (check.version !== "v4") {
|
|
475
|
+
addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
476
|
+
}
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
case "emoji":
|
|
480
|
+
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
481
|
+
break;
|
|
482
|
+
case "ulid": {
|
|
483
|
+
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
484
|
+
break;
|
|
485
|
+
}
|
|
486
|
+
case "base64": {
|
|
487
|
+
switch (refs.base64Strategy) {
|
|
488
|
+
case "format:binary": {
|
|
489
|
+
addFormat(res, "binary", check.message, refs);
|
|
490
|
+
break;
|
|
491
|
+
}
|
|
492
|
+
case "contentEncoding:base64": {
|
|
493
|
+
setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
|
|
494
|
+
break;
|
|
495
|
+
}
|
|
496
|
+
case "pattern:zod": {
|
|
497
|
+
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
498
|
+
break;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
case "nanoid": {
|
|
504
|
+
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
505
|
+
}
|
|
506
|
+
case "toLowerCase":
|
|
507
|
+
case "toUpperCase":
|
|
508
|
+
case "trim":
|
|
509
|
+
break;
|
|
510
|
+
default:
|
|
511
|
+
/* @__PURE__ */ ((_) => {
|
|
512
|
+
})(check);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return res;
|
|
517
|
+
}
|
|
518
|
+
function escapeLiteralCheckValue(literal, refs) {
|
|
519
|
+
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
520
|
+
}
|
|
521
|
+
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
522
|
+
function escapeNonAlphaNumeric(source) {
|
|
523
|
+
let result = "";
|
|
524
|
+
for (let i = 0; i < source.length; i++) {
|
|
525
|
+
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
526
|
+
result += "\\";
|
|
527
|
+
}
|
|
528
|
+
result += source[i];
|
|
529
|
+
}
|
|
530
|
+
return result;
|
|
531
|
+
}
|
|
532
|
+
function addFormat(schema, value, message, refs) {
|
|
533
|
+
if (schema.format || schema.anyOf?.some((x) => x.format)) {
|
|
534
|
+
if (!schema.anyOf) {
|
|
535
|
+
schema.anyOf = [];
|
|
536
|
+
}
|
|
537
|
+
if (schema.format) {
|
|
538
|
+
schema.anyOf.push({
|
|
539
|
+
format: schema.format,
|
|
540
|
+
...schema.errorMessage && refs.errorMessages && {
|
|
541
|
+
errorMessage: { format: schema.errorMessage.format }
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
delete schema.format;
|
|
545
|
+
if (schema.errorMessage) {
|
|
546
|
+
delete schema.errorMessage.format;
|
|
547
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
548
|
+
delete schema.errorMessage;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
schema.anyOf.push({
|
|
553
|
+
format: value,
|
|
554
|
+
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
555
|
+
});
|
|
556
|
+
} else {
|
|
557
|
+
setResponseValueAndErrors(schema, "format", value, message, refs);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
function addPattern(schema, regex, message, refs) {
|
|
561
|
+
if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {
|
|
562
|
+
if (!schema.allOf) {
|
|
563
|
+
schema.allOf = [];
|
|
564
|
+
}
|
|
565
|
+
if (schema.pattern) {
|
|
566
|
+
schema.allOf.push({
|
|
567
|
+
pattern: schema.pattern,
|
|
568
|
+
...schema.errorMessage && refs.errorMessages && {
|
|
569
|
+
errorMessage: { pattern: schema.errorMessage.pattern }
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
delete schema.pattern;
|
|
573
|
+
if (schema.errorMessage) {
|
|
574
|
+
delete schema.errorMessage.pattern;
|
|
575
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
576
|
+
delete schema.errorMessage;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
schema.allOf.push({
|
|
581
|
+
pattern: stringifyRegExpWithFlags(regex, refs),
|
|
582
|
+
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
583
|
+
});
|
|
584
|
+
} else {
|
|
585
|
+
setResponseValueAndErrors(schema, "pattern", stringifyRegExpWithFlags(regex, refs), message, refs);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
function stringifyRegExpWithFlags(regex, refs) {
|
|
589
|
+
if (!refs.applyRegexFlags || !regex.flags) {
|
|
590
|
+
return regex.source;
|
|
591
|
+
}
|
|
592
|
+
const flags = {
|
|
593
|
+
i: regex.flags.includes("i"),
|
|
594
|
+
m: regex.flags.includes("m"),
|
|
595
|
+
s: regex.flags.includes("s")
|
|
596
|
+
// `.` matches newlines
|
|
597
|
+
};
|
|
598
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
599
|
+
let pattern = "";
|
|
600
|
+
let isEscaped = false;
|
|
601
|
+
let inCharGroup = false;
|
|
602
|
+
let inCharRange = false;
|
|
603
|
+
for (let i = 0; i < source.length; i++) {
|
|
604
|
+
if (isEscaped) {
|
|
605
|
+
pattern += source[i];
|
|
606
|
+
isEscaped = false;
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
if (flags.i) {
|
|
610
|
+
if (inCharGroup) {
|
|
611
|
+
if (source[i].match(/[a-z]/)) {
|
|
612
|
+
if (inCharRange) {
|
|
613
|
+
pattern += source[i];
|
|
614
|
+
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
615
|
+
inCharRange = false;
|
|
616
|
+
} else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
|
|
617
|
+
pattern += source[i];
|
|
618
|
+
inCharRange = true;
|
|
619
|
+
} else {
|
|
620
|
+
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
621
|
+
}
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
624
|
+
} else if (source[i].match(/[a-z]/)) {
|
|
625
|
+
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (flags.m) {
|
|
630
|
+
if (source[i] === "^") {
|
|
631
|
+
pattern += `(^|(?<=[\r
|
|
632
|
+
]))`;
|
|
633
|
+
continue;
|
|
634
|
+
} else if (source[i] === "$") {
|
|
635
|
+
pattern += `($|(?=[\r
|
|
636
|
+
]))`;
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
if (flags.s && source[i] === ".") {
|
|
641
|
+
pattern += inCharGroup ? `${source[i]}\r
|
|
642
|
+
` : `[${source[i]}\r
|
|
643
|
+
]`;
|
|
644
|
+
continue;
|
|
645
|
+
}
|
|
646
|
+
pattern += source[i];
|
|
647
|
+
if (source[i] === "\\") {
|
|
648
|
+
isEscaped = true;
|
|
649
|
+
} else if (inCharGroup && source[i] === "]") {
|
|
650
|
+
inCharGroup = false;
|
|
651
|
+
} else if (!inCharGroup && source[i] === "[") {
|
|
652
|
+
inCharGroup = true;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
try {
|
|
656
|
+
new RegExp(pattern);
|
|
657
|
+
} catch {
|
|
658
|
+
console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
|
|
659
|
+
return regex.source;
|
|
660
|
+
}
|
|
661
|
+
return pattern;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
665
|
+
function parseRecordDef(def, refs) {
|
|
666
|
+
if (refs.target === "openAi") {
|
|
667
|
+
console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
|
|
668
|
+
}
|
|
669
|
+
if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
670
|
+
return {
|
|
671
|
+
type: "object",
|
|
672
|
+
required: def.keyType._def.values,
|
|
673
|
+
properties: def.keyType._def.values.reduce((acc, key) => ({
|
|
674
|
+
...acc,
|
|
675
|
+
[key]: parseDef(def.valueType._def, {
|
|
676
|
+
...refs,
|
|
677
|
+
currentPath: [...refs.currentPath, "properties", key]
|
|
678
|
+
}) ?? parseAnyDef(refs)
|
|
679
|
+
}), {}),
|
|
680
|
+
additionalProperties: refs.rejectedAdditionalProperties
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
const schema = {
|
|
684
|
+
type: "object",
|
|
685
|
+
additionalProperties: parseDef(def.valueType._def, {
|
|
686
|
+
...refs,
|
|
687
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
688
|
+
}) ?? refs.allowedAdditionalProperties
|
|
689
|
+
};
|
|
690
|
+
if (refs.target === "openApi3") {
|
|
691
|
+
return schema;
|
|
692
|
+
}
|
|
693
|
+
if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.checks?.length) {
|
|
694
|
+
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
695
|
+
return {
|
|
696
|
+
...schema,
|
|
697
|
+
propertyNames: keyType
|
|
698
|
+
};
|
|
699
|
+
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
700
|
+
return {
|
|
701
|
+
...schema,
|
|
702
|
+
propertyNames: {
|
|
703
|
+
enum: def.keyType._def.values
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.type._def.checks?.length) {
|
|
707
|
+
const { type, ...keyType } = parseBrandedDef(def.keyType._def, refs);
|
|
708
|
+
return {
|
|
709
|
+
...schema,
|
|
710
|
+
propertyNames: keyType
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
return schema;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/map.js
|
|
717
|
+
function parseMapDef(def, refs) {
|
|
718
|
+
if (refs.mapStrategy === "record") {
|
|
719
|
+
return parseRecordDef(def, refs);
|
|
720
|
+
}
|
|
721
|
+
const keys = parseDef(def.keyType._def, {
|
|
722
|
+
...refs,
|
|
723
|
+
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
724
|
+
}) || parseAnyDef(refs);
|
|
725
|
+
const values = parseDef(def.valueType._def, {
|
|
726
|
+
...refs,
|
|
727
|
+
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
728
|
+
}) || parseAnyDef(refs);
|
|
729
|
+
return {
|
|
730
|
+
type: "array",
|
|
731
|
+
maxItems: 125,
|
|
732
|
+
items: {
|
|
733
|
+
type: "array",
|
|
734
|
+
items: [keys, values],
|
|
735
|
+
minItems: 2,
|
|
736
|
+
maxItems: 2
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
|
|
742
|
+
function parseNativeEnumDef(def) {
|
|
743
|
+
const object = def.values;
|
|
744
|
+
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
745
|
+
return typeof object[object[key]] !== "number";
|
|
746
|
+
});
|
|
747
|
+
const actualValues = actualKeys.map((key) => object[key]);
|
|
748
|
+
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
749
|
+
return {
|
|
750
|
+
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
751
|
+
enum: actualValues
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/never.js
|
|
756
|
+
function parseNeverDef(refs) {
|
|
757
|
+
return refs.target === "openAi" ? void 0 : {
|
|
758
|
+
not: parseAnyDef({
|
|
759
|
+
...refs,
|
|
760
|
+
currentPath: [...refs.currentPath, "not"]
|
|
761
|
+
})
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/null.js
|
|
766
|
+
function parseNullDef(refs) {
|
|
767
|
+
return refs.target === "openApi3" ? {
|
|
768
|
+
enum: ["null"],
|
|
769
|
+
nullable: true
|
|
770
|
+
} : {
|
|
771
|
+
type: "null"
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/union.js
|
|
776
|
+
var primitiveMappings = {
|
|
777
|
+
ZodString: "string",
|
|
778
|
+
ZodNumber: "number",
|
|
779
|
+
ZodBigInt: "integer",
|
|
780
|
+
ZodBoolean: "boolean",
|
|
781
|
+
ZodNull: "null"
|
|
782
|
+
};
|
|
783
|
+
function parseUnionDef(def, refs) {
|
|
784
|
+
if (refs.target === "openApi3")
|
|
785
|
+
return asAnyOf(def, refs);
|
|
786
|
+
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
787
|
+
if (options.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))) {
|
|
788
|
+
const types = options.reduce((types2, x) => {
|
|
789
|
+
const type = primitiveMappings[x._def.typeName];
|
|
790
|
+
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
791
|
+
}, []);
|
|
792
|
+
return {
|
|
793
|
+
type: types.length > 1 ? types : types[0]
|
|
794
|
+
};
|
|
795
|
+
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
796
|
+
const types = options.reduce((acc, x) => {
|
|
797
|
+
const type = typeof x._def.value;
|
|
798
|
+
switch (type) {
|
|
799
|
+
case "string":
|
|
800
|
+
case "number":
|
|
801
|
+
case "boolean":
|
|
802
|
+
return [...acc, type];
|
|
803
|
+
case "bigint":
|
|
804
|
+
return [...acc, "integer"];
|
|
805
|
+
case "object":
|
|
806
|
+
if (x._def.value === null)
|
|
807
|
+
return [...acc, "null"];
|
|
808
|
+
case "symbol":
|
|
809
|
+
case "undefined":
|
|
810
|
+
case "function":
|
|
811
|
+
default:
|
|
812
|
+
return acc;
|
|
813
|
+
}
|
|
814
|
+
}, []);
|
|
815
|
+
if (types.length === options.length) {
|
|
816
|
+
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
817
|
+
return {
|
|
818
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
819
|
+
enum: options.reduce((acc, x) => {
|
|
820
|
+
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
821
|
+
}, [])
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
825
|
+
return {
|
|
826
|
+
type: "string",
|
|
827
|
+
enum: options.reduce((acc, x) => [
|
|
828
|
+
...acc,
|
|
829
|
+
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
830
|
+
], [])
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
return asAnyOf(def, refs);
|
|
834
|
+
}
|
|
835
|
+
var asAnyOf = (def, refs) => {
|
|
836
|
+
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
|
|
837
|
+
...refs,
|
|
838
|
+
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
839
|
+
})).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
|
|
840
|
+
return anyOf.length ? { anyOf } : void 0;
|
|
841
|
+
};
|
|
842
|
+
|
|
843
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
|
|
844
|
+
function parseNullableDef(def, refs) {
|
|
845
|
+
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
846
|
+
if (refs.target === "openApi3") {
|
|
847
|
+
return {
|
|
848
|
+
type: primitiveMappings[def.innerType._def.typeName],
|
|
849
|
+
nullable: true
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
return {
|
|
853
|
+
type: [
|
|
854
|
+
primitiveMappings[def.innerType._def.typeName],
|
|
855
|
+
"null"
|
|
856
|
+
]
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
if (refs.target === "openApi3") {
|
|
860
|
+
const base2 = parseDef(def.innerType._def, {
|
|
861
|
+
...refs,
|
|
862
|
+
currentPath: [...refs.currentPath]
|
|
863
|
+
});
|
|
864
|
+
if (base2 && "$ref" in base2)
|
|
865
|
+
return { allOf: [base2], nullable: true };
|
|
866
|
+
return base2 && { ...base2, nullable: true };
|
|
867
|
+
}
|
|
868
|
+
const base = parseDef(def.innerType._def, {
|
|
869
|
+
...refs,
|
|
870
|
+
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
871
|
+
});
|
|
872
|
+
return base && { anyOf: [base, { type: "null" }] };
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/number.js
|
|
876
|
+
function parseNumberDef(def, refs) {
|
|
877
|
+
const res = {
|
|
878
|
+
type: "number"
|
|
879
|
+
};
|
|
880
|
+
if (!def.checks)
|
|
881
|
+
return res;
|
|
882
|
+
for (const check of def.checks) {
|
|
883
|
+
switch (check.kind) {
|
|
884
|
+
case "int":
|
|
885
|
+
res.type = "integer";
|
|
886
|
+
addErrorMessage(res, "type", check.message, refs);
|
|
887
|
+
break;
|
|
888
|
+
case "min":
|
|
889
|
+
if (refs.target === "jsonSchema7") {
|
|
890
|
+
if (check.inclusive) {
|
|
891
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
892
|
+
} else {
|
|
893
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
894
|
+
}
|
|
895
|
+
} else {
|
|
896
|
+
if (!check.inclusive) {
|
|
897
|
+
res.exclusiveMinimum = true;
|
|
898
|
+
}
|
|
899
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
900
|
+
}
|
|
901
|
+
break;
|
|
902
|
+
case "max":
|
|
903
|
+
if (refs.target === "jsonSchema7") {
|
|
904
|
+
if (check.inclusive) {
|
|
905
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
906
|
+
} else {
|
|
907
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
908
|
+
}
|
|
909
|
+
} else {
|
|
910
|
+
if (!check.inclusive) {
|
|
911
|
+
res.exclusiveMaximum = true;
|
|
912
|
+
}
|
|
913
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
914
|
+
}
|
|
915
|
+
break;
|
|
916
|
+
case "multipleOf":
|
|
917
|
+
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
918
|
+
break;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
return res;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/object.js
|
|
925
|
+
function parseObjectDef(def, refs) {
|
|
926
|
+
const forceOptionalIntoNullable = refs.target === "openAi";
|
|
927
|
+
const result = {
|
|
928
|
+
type: "object",
|
|
929
|
+
properties: {}
|
|
930
|
+
};
|
|
931
|
+
const required = [];
|
|
932
|
+
const shape = def.shape();
|
|
933
|
+
for (const propName in shape) {
|
|
934
|
+
let propDef = shape[propName];
|
|
935
|
+
if (propDef === void 0 || propDef._def === void 0) {
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
938
|
+
let propOptional = safeIsOptional(propDef);
|
|
939
|
+
if (propOptional && forceOptionalIntoNullable) {
|
|
940
|
+
if (propDef._def.typeName === "ZodOptional") {
|
|
941
|
+
propDef = propDef._def.innerType;
|
|
942
|
+
}
|
|
943
|
+
if (!propDef.isNullable()) {
|
|
944
|
+
propDef = propDef.nullable();
|
|
945
|
+
}
|
|
946
|
+
propOptional = false;
|
|
947
|
+
}
|
|
948
|
+
const parsedDef = parseDef(propDef._def, {
|
|
949
|
+
...refs,
|
|
950
|
+
currentPath: [...refs.currentPath, "properties", propName],
|
|
951
|
+
propertyPath: [...refs.currentPath, "properties", propName]
|
|
952
|
+
});
|
|
953
|
+
if (parsedDef === void 0) {
|
|
954
|
+
continue;
|
|
955
|
+
}
|
|
956
|
+
result.properties[propName] = parsedDef;
|
|
957
|
+
if (!propOptional) {
|
|
958
|
+
required.push(propName);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
if (required.length) {
|
|
962
|
+
result.required = required;
|
|
963
|
+
}
|
|
964
|
+
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
965
|
+
if (additionalProperties !== void 0) {
|
|
966
|
+
result.additionalProperties = additionalProperties;
|
|
967
|
+
}
|
|
968
|
+
return result;
|
|
969
|
+
}
|
|
970
|
+
function decideAdditionalProperties(def, refs) {
|
|
971
|
+
if (def.catchall._def.typeName !== "ZodNever") {
|
|
972
|
+
return parseDef(def.catchall._def, {
|
|
973
|
+
...refs,
|
|
974
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
switch (def.unknownKeys) {
|
|
978
|
+
case "passthrough":
|
|
979
|
+
return refs.allowedAdditionalProperties;
|
|
980
|
+
case "strict":
|
|
981
|
+
return refs.rejectedAdditionalProperties;
|
|
982
|
+
case "strip":
|
|
983
|
+
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
function safeIsOptional(schema) {
|
|
987
|
+
try {
|
|
988
|
+
return schema.isOptional();
|
|
989
|
+
} catch {
|
|
990
|
+
return true;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
|
|
995
|
+
var parseOptionalDef = (def, refs) => {
|
|
996
|
+
if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
|
|
997
|
+
return parseDef(def.innerType._def, refs);
|
|
998
|
+
}
|
|
999
|
+
const innerSchema = parseDef(def.innerType._def, {
|
|
1000
|
+
...refs,
|
|
1001
|
+
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
1002
|
+
});
|
|
1003
|
+
return innerSchema ? {
|
|
1004
|
+
anyOf: [
|
|
1005
|
+
{
|
|
1006
|
+
not: parseAnyDef(refs)
|
|
1007
|
+
},
|
|
1008
|
+
innerSchema
|
|
1009
|
+
]
|
|
1010
|
+
} : parseAnyDef(refs);
|
|
1011
|
+
};
|
|
1012
|
+
|
|
1013
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
|
|
1014
|
+
var parsePipelineDef = (def, refs) => {
|
|
1015
|
+
if (refs.pipeStrategy === "input") {
|
|
1016
|
+
return parseDef(def.in._def, refs);
|
|
1017
|
+
} else if (refs.pipeStrategy === "output") {
|
|
1018
|
+
return parseDef(def.out._def, refs);
|
|
1019
|
+
}
|
|
1020
|
+
const a = parseDef(def.in._def, {
|
|
1021
|
+
...refs,
|
|
1022
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1023
|
+
});
|
|
1024
|
+
const b = parseDef(def.out._def, {
|
|
1025
|
+
...refs,
|
|
1026
|
+
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
1027
|
+
});
|
|
1028
|
+
return {
|
|
1029
|
+
allOf: [a, b].filter((x) => x !== void 0)
|
|
1030
|
+
};
|
|
1031
|
+
};
|
|
1032
|
+
|
|
1033
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/promise.js
|
|
1034
|
+
function parsePromiseDef(def, refs) {
|
|
1035
|
+
return parseDef(def.type._def, refs);
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/set.js
|
|
1039
|
+
function parseSetDef(def, refs) {
|
|
1040
|
+
const items = parseDef(def.valueType._def, {
|
|
1041
|
+
...refs,
|
|
1042
|
+
currentPath: [...refs.currentPath, "items"]
|
|
1043
|
+
});
|
|
1044
|
+
const schema = {
|
|
1045
|
+
type: "array",
|
|
1046
|
+
uniqueItems: true,
|
|
1047
|
+
items
|
|
1048
|
+
};
|
|
1049
|
+
if (def.minSize) {
|
|
1050
|
+
setResponseValueAndErrors(schema, "minItems", def.minSize.value, def.minSize.message, refs);
|
|
1051
|
+
}
|
|
1052
|
+
if (def.maxSize) {
|
|
1053
|
+
setResponseValueAndErrors(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
1054
|
+
}
|
|
1055
|
+
return schema;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
|
|
1059
|
+
function parseTupleDef(def, refs) {
|
|
1060
|
+
if (def.rest) {
|
|
1061
|
+
return {
|
|
1062
|
+
type: "array",
|
|
1063
|
+
minItems: def.items.length,
|
|
1064
|
+
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1065
|
+
...refs,
|
|
1066
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1067
|
+
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], []),
|
|
1068
|
+
additionalItems: parseDef(def.rest._def, {
|
|
1069
|
+
...refs,
|
|
1070
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
1071
|
+
})
|
|
1072
|
+
};
|
|
1073
|
+
} else {
|
|
1074
|
+
return {
|
|
1075
|
+
type: "array",
|
|
1076
|
+
minItems: def.items.length,
|
|
1077
|
+
maxItems: def.items.length,
|
|
1078
|
+
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1079
|
+
...refs,
|
|
1080
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1081
|
+
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], [])
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
|
|
1087
|
+
function parseUndefinedDef(refs) {
|
|
1088
|
+
return {
|
|
1089
|
+
not: parseAnyDef(refs)
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js
|
|
1094
|
+
function parseUnknownDef(refs) {
|
|
1095
|
+
return parseAnyDef(refs);
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
// node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js
|
|
1099
|
+
var parseReadonlyDef = (def, refs) => {
|
|
1100
|
+
return parseDef(def.innerType._def, refs);
|
|
1101
|
+
};
|
|
1102
|
+
|
|
1103
|
+
// node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
1104
|
+
var selectParser = (def, typeName, refs) => {
|
|
1105
|
+
switch (typeName) {
|
|
1106
|
+
case ZodFirstPartyTypeKind3.ZodString:
|
|
1107
|
+
return parseStringDef(def, refs);
|
|
1108
|
+
case ZodFirstPartyTypeKind3.ZodNumber:
|
|
1109
|
+
return parseNumberDef(def, refs);
|
|
1110
|
+
case ZodFirstPartyTypeKind3.ZodObject:
|
|
1111
|
+
return parseObjectDef(def, refs);
|
|
1112
|
+
case ZodFirstPartyTypeKind3.ZodBigInt:
|
|
1113
|
+
return parseBigintDef(def, refs);
|
|
1114
|
+
case ZodFirstPartyTypeKind3.ZodBoolean:
|
|
1115
|
+
return parseBooleanDef();
|
|
1116
|
+
case ZodFirstPartyTypeKind3.ZodDate:
|
|
1117
|
+
return parseDateDef(def, refs);
|
|
1118
|
+
case ZodFirstPartyTypeKind3.ZodUndefined:
|
|
1119
|
+
return parseUndefinedDef(refs);
|
|
1120
|
+
case ZodFirstPartyTypeKind3.ZodNull:
|
|
1121
|
+
return parseNullDef(refs);
|
|
1122
|
+
case ZodFirstPartyTypeKind3.ZodArray:
|
|
1123
|
+
return parseArrayDef(def, refs);
|
|
1124
|
+
case ZodFirstPartyTypeKind3.ZodUnion:
|
|
1125
|
+
case ZodFirstPartyTypeKind3.ZodDiscriminatedUnion:
|
|
1126
|
+
return parseUnionDef(def, refs);
|
|
1127
|
+
case ZodFirstPartyTypeKind3.ZodIntersection:
|
|
1128
|
+
return parseIntersectionDef(def, refs);
|
|
1129
|
+
case ZodFirstPartyTypeKind3.ZodTuple:
|
|
1130
|
+
return parseTupleDef(def, refs);
|
|
1131
|
+
case ZodFirstPartyTypeKind3.ZodRecord:
|
|
1132
|
+
return parseRecordDef(def, refs);
|
|
1133
|
+
case ZodFirstPartyTypeKind3.ZodLiteral:
|
|
1134
|
+
return parseLiteralDef(def, refs);
|
|
1135
|
+
case ZodFirstPartyTypeKind3.ZodEnum:
|
|
1136
|
+
return parseEnumDef(def);
|
|
1137
|
+
case ZodFirstPartyTypeKind3.ZodNativeEnum:
|
|
1138
|
+
return parseNativeEnumDef(def);
|
|
1139
|
+
case ZodFirstPartyTypeKind3.ZodNullable:
|
|
1140
|
+
return parseNullableDef(def, refs);
|
|
1141
|
+
case ZodFirstPartyTypeKind3.ZodOptional:
|
|
1142
|
+
return parseOptionalDef(def, refs);
|
|
1143
|
+
case ZodFirstPartyTypeKind3.ZodMap:
|
|
1144
|
+
return parseMapDef(def, refs);
|
|
1145
|
+
case ZodFirstPartyTypeKind3.ZodSet:
|
|
1146
|
+
return parseSetDef(def, refs);
|
|
1147
|
+
case ZodFirstPartyTypeKind3.ZodLazy:
|
|
1148
|
+
return () => def.getter()._def;
|
|
1149
|
+
case ZodFirstPartyTypeKind3.ZodPromise:
|
|
1150
|
+
return parsePromiseDef(def, refs);
|
|
1151
|
+
case ZodFirstPartyTypeKind3.ZodNaN:
|
|
1152
|
+
case ZodFirstPartyTypeKind3.ZodNever:
|
|
1153
|
+
return parseNeverDef(refs);
|
|
1154
|
+
case ZodFirstPartyTypeKind3.ZodEffects:
|
|
1155
|
+
return parseEffectsDef(def, refs);
|
|
1156
|
+
case ZodFirstPartyTypeKind3.ZodAny:
|
|
1157
|
+
return parseAnyDef(refs);
|
|
1158
|
+
case ZodFirstPartyTypeKind3.ZodUnknown:
|
|
1159
|
+
return parseUnknownDef(refs);
|
|
1160
|
+
case ZodFirstPartyTypeKind3.ZodDefault:
|
|
1161
|
+
return parseDefaultDef(def, refs);
|
|
1162
|
+
case ZodFirstPartyTypeKind3.ZodBranded:
|
|
1163
|
+
return parseBrandedDef(def, refs);
|
|
1164
|
+
case ZodFirstPartyTypeKind3.ZodReadonly:
|
|
1165
|
+
return parseReadonlyDef(def, refs);
|
|
1166
|
+
case ZodFirstPartyTypeKind3.ZodCatch:
|
|
1167
|
+
return parseCatchDef(def, refs);
|
|
1168
|
+
case ZodFirstPartyTypeKind3.ZodPipeline:
|
|
1169
|
+
return parsePipelineDef(def, refs);
|
|
1170
|
+
case ZodFirstPartyTypeKind3.ZodFunction:
|
|
1171
|
+
case ZodFirstPartyTypeKind3.ZodVoid:
|
|
1172
|
+
case ZodFirstPartyTypeKind3.ZodSymbol:
|
|
1173
|
+
return void 0;
|
|
1174
|
+
default:
|
|
1175
|
+
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
1176
|
+
}
|
|
1177
|
+
};
|
|
1178
|
+
|
|
1179
|
+
// node_modules/zod-to-json-schema/dist/esm/parseDef.js
|
|
1180
|
+
function parseDef(def, refs, forceResolution = false) {
|
|
1181
|
+
const seenItem = refs.seen.get(def);
|
|
1182
|
+
if (refs.override) {
|
|
1183
|
+
const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
|
|
1184
|
+
if (overrideResult !== ignoreOverride) {
|
|
1185
|
+
return overrideResult;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
if (seenItem && !forceResolution) {
|
|
1189
|
+
const seenSchema = get$ref(seenItem, refs);
|
|
1190
|
+
if (seenSchema !== void 0) {
|
|
1191
|
+
return seenSchema;
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
1195
|
+
refs.seen.set(def, newItem);
|
|
1196
|
+
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
1197
|
+
const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
1198
|
+
if (jsonSchema) {
|
|
1199
|
+
addMeta(def, refs, jsonSchema);
|
|
1200
|
+
}
|
|
1201
|
+
if (refs.postProcess) {
|
|
1202
|
+
const postProcessResult = refs.postProcess(jsonSchema, def, refs);
|
|
1203
|
+
newItem.jsonSchema = jsonSchema;
|
|
1204
|
+
return postProcessResult;
|
|
1205
|
+
}
|
|
1206
|
+
newItem.jsonSchema = jsonSchema;
|
|
1207
|
+
return jsonSchema;
|
|
1208
|
+
}
|
|
1209
|
+
var get$ref = (item, refs) => {
|
|
1210
|
+
switch (refs.$refStrategy) {
|
|
1211
|
+
case "root":
|
|
1212
|
+
return { $ref: item.path.join("/") };
|
|
1213
|
+
case "relative":
|
|
1214
|
+
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
1215
|
+
case "none":
|
|
1216
|
+
case "seen": {
|
|
1217
|
+
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
1218
|
+
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
1219
|
+
return parseAnyDef(refs);
|
|
1220
|
+
}
|
|
1221
|
+
return refs.$refStrategy === "seen" ? parseAnyDef(refs) : void 0;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
var addMeta = (def, refs, jsonSchema) => {
|
|
1226
|
+
if (def.description) {
|
|
1227
|
+
jsonSchema.description = def.description;
|
|
1228
|
+
if (refs.markdownDescription) {
|
|
1229
|
+
jsonSchema.markdownDescription = def.description;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
return jsonSchema;
|
|
1233
|
+
};
|
|
1234
|
+
|
|
1235
|
+
// node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
|
|
1236
|
+
var zodToJsonSchema = (schema, options) => {
|
|
1237
|
+
const refs = getRefs(options);
|
|
1238
|
+
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name2, schema2]) => ({
|
|
1239
|
+
...acc,
|
|
1240
|
+
[name2]: parseDef(schema2._def, {
|
|
1241
|
+
...refs,
|
|
1242
|
+
currentPath: [...refs.basePath, refs.definitionPath, name2]
|
|
1243
|
+
}, true) ?? parseAnyDef(refs)
|
|
1244
|
+
}), {}) : void 0;
|
|
1245
|
+
const name = typeof options === "string" ? options : options?.nameStrategy === "title" ? void 0 : options?.name;
|
|
1246
|
+
const main = parseDef(schema._def, name === void 0 ? refs : {
|
|
1247
|
+
...refs,
|
|
1248
|
+
currentPath: [...refs.basePath, refs.definitionPath, name]
|
|
1249
|
+
}, false) ?? parseAnyDef(refs);
|
|
1250
|
+
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
1251
|
+
if (title !== void 0) {
|
|
1252
|
+
main.title = title;
|
|
1253
|
+
}
|
|
1254
|
+
if (refs.flags.hasReferencedOpenAiAnyType) {
|
|
1255
|
+
if (!definitions) {
|
|
1256
|
+
definitions = {};
|
|
1257
|
+
}
|
|
1258
|
+
if (!definitions[refs.openAiAnyTypeName]) {
|
|
1259
|
+
definitions[refs.openAiAnyTypeName] = {
|
|
1260
|
+
// Skipping "object" as no properties can be defined and additionalProperties must be "false"
|
|
1261
|
+
type: ["string", "number", "integer", "boolean", "array", "null"],
|
|
1262
|
+
items: {
|
|
1263
|
+
$ref: refs.$refStrategy === "relative" ? "1" : [
|
|
1264
|
+
...refs.basePath,
|
|
1265
|
+
refs.definitionPath,
|
|
1266
|
+
refs.openAiAnyTypeName
|
|
1267
|
+
].join("/")
|
|
1268
|
+
}
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
const combined = name === void 0 ? definitions ? {
|
|
1273
|
+
...main,
|
|
1274
|
+
[refs.definitionPath]: definitions
|
|
1275
|
+
} : main : {
|
|
1276
|
+
$ref: [
|
|
1277
|
+
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
1278
|
+
refs.definitionPath,
|
|
1279
|
+
name
|
|
1280
|
+
].join("/"),
|
|
1281
|
+
[refs.definitionPath]: {
|
|
1282
|
+
...definitions,
|
|
1283
|
+
[name]: main
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
if (refs.target === "jsonSchema7") {
|
|
1287
|
+
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
1288
|
+
} else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
|
|
1289
|
+
combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
1290
|
+
}
|
|
1291
|
+
if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) {
|
|
1292
|
+
console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
|
|
1293
|
+
}
|
|
1294
|
+
return combined;
|
|
1295
|
+
};
|
|
1296
|
+
|
|
1297
|
+
// src/mcp/server.ts
|
|
1298
|
+
var RPC_ERR = {
|
|
1299
|
+
PARSE_ERROR: -32700,
|
|
1300
|
+
INVALID_REQUEST: -32600,
|
|
1301
|
+
METHOD_NOT_FOUND: -32601,
|
|
1302
|
+
INVALID_PARAMS: -32602,
|
|
1303
|
+
INTERNAL_ERROR: -32603
|
|
1304
|
+
};
|
|
1305
|
+
function writeMessage(msg) {
|
|
1306
|
+
process.stdout.write(JSON.stringify(msg) + "\n");
|
|
1307
|
+
}
|
|
1308
|
+
function logStderr(msg) {
|
|
1309
|
+
process.stderr.write(`[notch-mcp] ${msg}
|
|
1310
|
+
`);
|
|
1311
|
+
}
|
|
1312
|
+
function toolsToMcpList(tools) {
|
|
1313
|
+
return tools.map((t) => ({
|
|
1314
|
+
name: t.name,
|
|
1315
|
+
description: t.description,
|
|
1316
|
+
inputSchema: zodToJsonSchema(t.parameters, { target: "openApi3" })
|
|
1317
|
+
}));
|
|
1318
|
+
}
|
|
1319
|
+
async function runMcpServer(opts) {
|
|
1320
|
+
const toolsModule = await import("./tools-XKVTMNR5.js");
|
|
1321
|
+
const { pluginManager } = await import("./plugins-GJIUZCJ5.js");
|
|
1322
|
+
if (opts.includePlugins !== false) {
|
|
1323
|
+
try {
|
|
1324
|
+
await pluginManager.init(opts.cwd, (m) => logStderr(m));
|
|
1325
|
+
} catch (err) {
|
|
1326
|
+
logStderr(`plugin init failed: ${err.message}`);
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
const getTools = () => toolsModule.listToolNames().map((name) => ({ name, desc: toolsModule.describeTools() })).filter(() => true);
|
|
1330
|
+
const { readTool } = await import("./read-LY2VGCZY.js");
|
|
1331
|
+
const { writeTool } = await import("./write-DOLDW7HM.js");
|
|
1332
|
+
const { editTool } = await import("./edit-FXWXOFAF.js");
|
|
1333
|
+
const { applyPatchTool } = await import("./apply-patch-EBZ5VLO7.js");
|
|
1334
|
+
const { shellTool } = await import("./shell-RGXMLRLH.js");
|
|
1335
|
+
const { gitTool } = await import("./git-XVWI2BT7.js");
|
|
1336
|
+
const { githubTool } = await import("./github-DOZ2MVQE.js");
|
|
1337
|
+
const { grepTool } = await import("./grep-2A42QPWM.js");
|
|
1338
|
+
const { globTool } = await import("./glob-XSBN4MDB.js");
|
|
1339
|
+
const { webFetchTool } = await import("./web-fetch-XOH5PUCP.js");
|
|
1340
|
+
const { lspTool } = await import("./lsp-WUEGBQ3F.js");
|
|
1341
|
+
const { notebookTool } = await import("./notebook-5U6PAF6M.js");
|
|
1342
|
+
const { taskTool } = await import("./task-VIJ3N5EB.js");
|
|
1343
|
+
const exposed = [
|
|
1344
|
+
readTool,
|
|
1345
|
+
writeTool,
|
|
1346
|
+
editTool,
|
|
1347
|
+
applyPatchTool,
|
|
1348
|
+
shellTool,
|
|
1349
|
+
gitTool,
|
|
1350
|
+
githubTool,
|
|
1351
|
+
grepTool,
|
|
1352
|
+
globTool,
|
|
1353
|
+
webFetchTool,
|
|
1354
|
+
lspTool,
|
|
1355
|
+
notebookTool,
|
|
1356
|
+
taskTool
|
|
1357
|
+
];
|
|
1358
|
+
if (opts.includePlugins !== false) {
|
|
1359
|
+
exposed.push(...pluginManager.getTools());
|
|
1360
|
+
}
|
|
1361
|
+
const toolByName = new Map(exposed.map((t) => [t.name, t]));
|
|
1362
|
+
const mcpTools = toolsToMcpList(exposed);
|
|
1363
|
+
const toolCtx = {
|
|
1364
|
+
cwd: opts.cwd,
|
|
1365
|
+
requireConfirm: false,
|
|
1366
|
+
confirm: async () => true,
|
|
1367
|
+
log: (m) => logStderr(m)
|
|
1368
|
+
};
|
|
1369
|
+
let initialized = false;
|
|
1370
|
+
logStderr(`ready \u2014 ${exposed.length} tools on stdio (version ${opts.version})`);
|
|
1371
|
+
void getTools;
|
|
1372
|
+
const rl = readline.createInterface({ input: process.stdin, terminal: false });
|
|
1373
|
+
rl.on("line", async (line) => {
|
|
1374
|
+
const trimmed = line.trim();
|
|
1375
|
+
if (!trimmed) return;
|
|
1376
|
+
let req;
|
|
1377
|
+
try {
|
|
1378
|
+
req = JSON.parse(trimmed);
|
|
1379
|
+
} catch (err) {
|
|
1380
|
+
writeMessage({
|
|
1381
|
+
jsonrpc: "2.0",
|
|
1382
|
+
id: null,
|
|
1383
|
+
error: { code: RPC_ERR.PARSE_ERROR, message: `parse error: ${err.message}` }
|
|
1384
|
+
});
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1387
|
+
if (req.id === void 0 || req.id === null) {
|
|
1388
|
+
if (req.method === "notifications/initialized") {
|
|
1389
|
+
initialized = true;
|
|
1390
|
+
} else if (req.method === "notifications/cancelled") {
|
|
1391
|
+
} else {
|
|
1392
|
+
logStderr(`ignored notification: ${req.method}`);
|
|
1393
|
+
}
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
const reply = (result) => writeMessage({ jsonrpc: "2.0", id: req.id, result });
|
|
1397
|
+
const fail = (code, message, data) => writeMessage({ jsonrpc: "2.0", id: req.id, error: { code, message, data } });
|
|
1398
|
+
try {
|
|
1399
|
+
switch (req.method) {
|
|
1400
|
+
case "initialize": {
|
|
1401
|
+
reply({
|
|
1402
|
+
protocolVersion: "2024-11-05",
|
|
1403
|
+
capabilities: {
|
|
1404
|
+
tools: { listChanged: false }
|
|
1405
|
+
},
|
|
1406
|
+
serverInfo: {
|
|
1407
|
+
name: "notch-cli",
|
|
1408
|
+
version: opts.version
|
|
1409
|
+
},
|
|
1410
|
+
instructions: "Notch CLI exposes its code-editing tool registry over MCP. Prefer apply_patch for multi-file edits and edit for surgical single-line changes. The caller is responsible for approval and sandboxing."
|
|
1411
|
+
});
|
|
1412
|
+
break;
|
|
1413
|
+
}
|
|
1414
|
+
case "ping": {
|
|
1415
|
+
reply({});
|
|
1416
|
+
break;
|
|
1417
|
+
}
|
|
1418
|
+
case "tools/list": {
|
|
1419
|
+
reply({ tools: mcpTools });
|
|
1420
|
+
break;
|
|
1421
|
+
}
|
|
1422
|
+
case "tools/call": {
|
|
1423
|
+
const params = req.params;
|
|
1424
|
+
if (!params?.name) {
|
|
1425
|
+
fail(RPC_ERR.INVALID_PARAMS, '"name" is required');
|
|
1426
|
+
break;
|
|
1427
|
+
}
|
|
1428
|
+
const tool = toolByName.get(params.name);
|
|
1429
|
+
if (!tool) {
|
|
1430
|
+
fail(RPC_ERR.METHOD_NOT_FOUND, `tool not found: ${params.name}`);
|
|
1431
|
+
break;
|
|
1432
|
+
}
|
|
1433
|
+
if (!initialized) {
|
|
1434
|
+
logStderr(`tools/call before initialized notification \u2014 proceeding anyway`);
|
|
1435
|
+
}
|
|
1436
|
+
try {
|
|
1437
|
+
const parseResult = tool.parameters.safeParse(params.arguments ?? {});
|
|
1438
|
+
if (!parseResult.success) {
|
|
1439
|
+
reply({
|
|
1440
|
+
content: [{ type: "text", text: `Invalid arguments: ${parseResult.error.message}` }],
|
|
1441
|
+
isError: true
|
|
1442
|
+
});
|
|
1443
|
+
break;
|
|
1444
|
+
}
|
|
1445
|
+
const result = await tool.execute(parseResult.data, toolCtx);
|
|
1446
|
+
reply({
|
|
1447
|
+
content: [{ type: "text", text: result.content }],
|
|
1448
|
+
isError: result.isError ?? false
|
|
1449
|
+
});
|
|
1450
|
+
} catch (err) {
|
|
1451
|
+
reply({
|
|
1452
|
+
content: [{ type: "text", text: `Tool error: ${err.message}` }],
|
|
1453
|
+
isError: true
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
break;
|
|
1457
|
+
}
|
|
1458
|
+
case "shutdown": {
|
|
1459
|
+
reply({});
|
|
1460
|
+
setTimeout(() => process.exit(0), 50);
|
|
1461
|
+
break;
|
|
1462
|
+
}
|
|
1463
|
+
default:
|
|
1464
|
+
fail(RPC_ERR.METHOD_NOT_FOUND, `method not found: ${req.method}`);
|
|
1465
|
+
}
|
|
1466
|
+
} catch (err) {
|
|
1467
|
+
fail(RPC_ERR.INTERNAL_ERROR, `internal error: ${err.message}`);
|
|
1468
|
+
}
|
|
1469
|
+
});
|
|
1470
|
+
rl.on("close", () => {
|
|
1471
|
+
logStderr("stdin closed, exiting");
|
|
1472
|
+
process.exit(0);
|
|
1473
|
+
});
|
|
1474
|
+
await new Promise(() => {
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
export {
|
|
1478
|
+
runMcpServer
|
|
1479
|
+
};
|