@eworkbase/plugin-ai-rules 0.1.0 → 0.2.1

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.
@@ -0,0 +1,4979 @@
1
+ import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ //#region ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
5
+ /**
6
+ * Creates a JSON scanner on the given text.
7
+ * If ignoreTrivia is set, whitespaces or comments are ignored.
8
+ */
9
+ function createScanner(text, ignoreTrivia = false) {
10
+ const len = text.length;
11
+ let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
12
+ function scanHexDigits(count, exact) {
13
+ let digits = 0;
14
+ let value = 0;
15
+ while (digits < count || !exact) {
16
+ let ch = text.charCodeAt(pos);
17
+ if (ch >= 48 && ch <= 57) value = value * 16 + ch - 48;
18
+ else if (ch >= 65 && ch <= 70) value = value * 16 + ch - 65 + 10;
19
+ else if (ch >= 97 && ch <= 102) value = value * 16 + ch - 97 + 10;
20
+ else break;
21
+ pos++;
22
+ digits++;
23
+ }
24
+ if (digits < count) value = -1;
25
+ return value;
26
+ }
27
+ function setPosition(newPosition) {
28
+ pos = newPosition;
29
+ value = "";
30
+ tokenOffset = 0;
31
+ token = 16;
32
+ scanError = 0;
33
+ }
34
+ function scanNumber() {
35
+ let start = pos;
36
+ if (text.charCodeAt(pos) === 48) pos++;
37
+ else {
38
+ pos++;
39
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) pos++;
40
+ }
41
+ if (pos < text.length && text.charCodeAt(pos) === 46) {
42
+ pos++;
43
+ if (pos < text.length && isDigit(text.charCodeAt(pos))) {
44
+ pos++;
45
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) pos++;
46
+ } else {
47
+ scanError = 3;
48
+ return text.substring(start, pos);
49
+ }
50
+ }
51
+ let end = pos;
52
+ if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
53
+ pos++;
54
+ if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) pos++;
55
+ if (pos < text.length && isDigit(text.charCodeAt(pos))) {
56
+ pos++;
57
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) pos++;
58
+ end = pos;
59
+ } else scanError = 3;
60
+ }
61
+ return text.substring(start, end);
62
+ }
63
+ function scanString() {
64
+ let result = "", start = pos;
65
+ while (true) {
66
+ if (pos >= len) {
67
+ result += text.substring(start, pos);
68
+ scanError = 2;
69
+ break;
70
+ }
71
+ const ch = text.charCodeAt(pos);
72
+ if (ch === 34) {
73
+ result += text.substring(start, pos);
74
+ pos++;
75
+ break;
76
+ }
77
+ if (ch === 92) {
78
+ result += text.substring(start, pos);
79
+ pos++;
80
+ if (pos >= len) {
81
+ scanError = 2;
82
+ break;
83
+ }
84
+ switch (text.charCodeAt(pos++)) {
85
+ case 34:
86
+ result += "\"";
87
+ break;
88
+ case 92:
89
+ result += "\\";
90
+ break;
91
+ case 47:
92
+ result += "/";
93
+ break;
94
+ case 98:
95
+ result += "\b";
96
+ break;
97
+ case 102:
98
+ result += "\f";
99
+ break;
100
+ case 110:
101
+ result += "\n";
102
+ break;
103
+ case 114:
104
+ result += "\r";
105
+ break;
106
+ case 116:
107
+ result += " ";
108
+ break;
109
+ case 117:
110
+ const ch3 = scanHexDigits(4, true);
111
+ if (ch3 >= 0) result += String.fromCharCode(ch3);
112
+ else scanError = 4;
113
+ break;
114
+ default: scanError = 5;
115
+ }
116
+ start = pos;
117
+ continue;
118
+ }
119
+ if (ch >= 0 && ch <= 31) {
120
+ if (isLineBreak(ch)) {
121
+ result += text.substring(start, pos);
122
+ scanError = 2;
123
+ break;
124
+ } else scanError = 6;
125
+ }
126
+ pos++;
127
+ }
128
+ return result;
129
+ }
130
+ function scanNext() {
131
+ value = "";
132
+ scanError = 0;
133
+ tokenOffset = pos;
134
+ lineStartOffset = lineNumber;
135
+ prevTokenLineStartOffset = tokenLineStartOffset;
136
+ if (pos >= len) {
137
+ tokenOffset = len;
138
+ return token = 17;
139
+ }
140
+ let code = text.charCodeAt(pos);
141
+ if (isWhiteSpace(code)) {
142
+ do {
143
+ pos++;
144
+ value += String.fromCharCode(code);
145
+ code = text.charCodeAt(pos);
146
+ } while (isWhiteSpace(code));
147
+ return token = 15;
148
+ }
149
+ if (isLineBreak(code)) {
150
+ pos++;
151
+ value += String.fromCharCode(code);
152
+ if (code === 13 && text.charCodeAt(pos) === 10) {
153
+ pos++;
154
+ value += "\n";
155
+ }
156
+ lineNumber++;
157
+ tokenLineStartOffset = pos;
158
+ return token = 14;
159
+ }
160
+ switch (code) {
161
+ case 123:
162
+ pos++;
163
+ return token = 1;
164
+ case 125:
165
+ pos++;
166
+ return token = 2;
167
+ case 91:
168
+ pos++;
169
+ return token = 3;
170
+ case 93:
171
+ pos++;
172
+ return token = 4;
173
+ case 58:
174
+ pos++;
175
+ return token = 6;
176
+ case 44:
177
+ pos++;
178
+ return token = 5;
179
+ case 34:
180
+ pos++;
181
+ value = scanString();
182
+ return token = 10;
183
+ case 47:
184
+ const start = pos - 1;
185
+ if (text.charCodeAt(pos + 1) === 47) {
186
+ pos += 2;
187
+ while (pos < len) {
188
+ if (isLineBreak(text.charCodeAt(pos))) break;
189
+ pos++;
190
+ }
191
+ value = text.substring(start, pos);
192
+ return token = 12;
193
+ }
194
+ if (text.charCodeAt(pos + 1) === 42) {
195
+ pos += 2;
196
+ const safeLength = len - 1;
197
+ let commentClosed = false;
198
+ while (pos < safeLength) {
199
+ const ch = text.charCodeAt(pos);
200
+ if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
201
+ pos += 2;
202
+ commentClosed = true;
203
+ break;
204
+ }
205
+ pos++;
206
+ if (isLineBreak(ch)) {
207
+ if (ch === 13 && text.charCodeAt(pos) === 10) pos++;
208
+ lineNumber++;
209
+ tokenLineStartOffset = pos;
210
+ }
211
+ }
212
+ if (!commentClosed) {
213
+ pos++;
214
+ scanError = 1;
215
+ }
216
+ value = text.substring(start, pos);
217
+ return token = 13;
218
+ }
219
+ value += String.fromCharCode(code);
220
+ pos++;
221
+ return token = 16;
222
+ case 45:
223
+ value += String.fromCharCode(code);
224
+ pos++;
225
+ if (pos === len || !isDigit(text.charCodeAt(pos))) return token = 16;
226
+ case 48:
227
+ case 49:
228
+ case 50:
229
+ case 51:
230
+ case 52:
231
+ case 53:
232
+ case 54:
233
+ case 55:
234
+ case 56:
235
+ case 57:
236
+ value += scanNumber();
237
+ return token = 11;
238
+ default:
239
+ while (pos < len && isUnknownContentCharacter(code)) {
240
+ pos++;
241
+ code = text.charCodeAt(pos);
242
+ }
243
+ if (tokenOffset !== pos) {
244
+ value = text.substring(tokenOffset, pos);
245
+ switch (value) {
246
+ case "true": return token = 8;
247
+ case "false": return token = 9;
248
+ case "null": return token = 7;
249
+ }
250
+ return token = 16;
251
+ }
252
+ value += String.fromCharCode(code);
253
+ pos++;
254
+ return token = 16;
255
+ }
256
+ }
257
+ function isUnknownContentCharacter(code) {
258
+ if (isWhiteSpace(code) || isLineBreak(code)) return false;
259
+ switch (code) {
260
+ case 125:
261
+ case 93:
262
+ case 123:
263
+ case 91:
264
+ case 34:
265
+ case 58:
266
+ case 44:
267
+ case 47: return false;
268
+ }
269
+ return true;
270
+ }
271
+ function scanNextNonTrivia() {
272
+ let result;
273
+ do
274
+ result = scanNext();
275
+ while (result >= 12 && result <= 15);
276
+ return result;
277
+ }
278
+ return {
279
+ setPosition,
280
+ getPosition: () => pos,
281
+ scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
282
+ getToken: () => token,
283
+ getTokenValue: () => value,
284
+ getTokenOffset: () => tokenOffset,
285
+ getTokenLength: () => pos - tokenOffset,
286
+ getTokenStartLine: () => lineStartOffset,
287
+ getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
288
+ getTokenError: () => scanError
289
+ };
290
+ }
291
+ function isWhiteSpace(ch) {
292
+ return ch === 32 || ch === 9;
293
+ }
294
+ function isLineBreak(ch) {
295
+ return ch === 10 || ch === 13;
296
+ }
297
+ function isDigit(ch) {
298
+ return ch >= 48 && ch <= 57;
299
+ }
300
+ var CharacterCodes;
301
+ (function(CharacterCodes) {
302
+ CharacterCodes[CharacterCodes["lineFeed"] = 10] = "lineFeed";
303
+ CharacterCodes[CharacterCodes["carriageReturn"] = 13] = "carriageReturn";
304
+ CharacterCodes[CharacterCodes["space"] = 32] = "space";
305
+ CharacterCodes[CharacterCodes["_0"] = 48] = "_0";
306
+ CharacterCodes[CharacterCodes["_1"] = 49] = "_1";
307
+ CharacterCodes[CharacterCodes["_2"] = 50] = "_2";
308
+ CharacterCodes[CharacterCodes["_3"] = 51] = "_3";
309
+ CharacterCodes[CharacterCodes["_4"] = 52] = "_4";
310
+ CharacterCodes[CharacterCodes["_5"] = 53] = "_5";
311
+ CharacterCodes[CharacterCodes["_6"] = 54] = "_6";
312
+ CharacterCodes[CharacterCodes["_7"] = 55] = "_7";
313
+ CharacterCodes[CharacterCodes["_8"] = 56] = "_8";
314
+ CharacterCodes[CharacterCodes["_9"] = 57] = "_9";
315
+ CharacterCodes[CharacterCodes["a"] = 97] = "a";
316
+ CharacterCodes[CharacterCodes["b"] = 98] = "b";
317
+ CharacterCodes[CharacterCodes["c"] = 99] = "c";
318
+ CharacterCodes[CharacterCodes["d"] = 100] = "d";
319
+ CharacterCodes[CharacterCodes["e"] = 101] = "e";
320
+ CharacterCodes[CharacterCodes["f"] = 102] = "f";
321
+ CharacterCodes[CharacterCodes["g"] = 103] = "g";
322
+ CharacterCodes[CharacterCodes["h"] = 104] = "h";
323
+ CharacterCodes[CharacterCodes["i"] = 105] = "i";
324
+ CharacterCodes[CharacterCodes["j"] = 106] = "j";
325
+ CharacterCodes[CharacterCodes["k"] = 107] = "k";
326
+ CharacterCodes[CharacterCodes["l"] = 108] = "l";
327
+ CharacterCodes[CharacterCodes["m"] = 109] = "m";
328
+ CharacterCodes[CharacterCodes["n"] = 110] = "n";
329
+ CharacterCodes[CharacterCodes["o"] = 111] = "o";
330
+ CharacterCodes[CharacterCodes["p"] = 112] = "p";
331
+ CharacterCodes[CharacterCodes["q"] = 113] = "q";
332
+ CharacterCodes[CharacterCodes["r"] = 114] = "r";
333
+ CharacterCodes[CharacterCodes["s"] = 115] = "s";
334
+ CharacterCodes[CharacterCodes["t"] = 116] = "t";
335
+ CharacterCodes[CharacterCodes["u"] = 117] = "u";
336
+ CharacterCodes[CharacterCodes["v"] = 118] = "v";
337
+ CharacterCodes[CharacterCodes["w"] = 119] = "w";
338
+ CharacterCodes[CharacterCodes["x"] = 120] = "x";
339
+ CharacterCodes[CharacterCodes["y"] = 121] = "y";
340
+ CharacterCodes[CharacterCodes["z"] = 122] = "z";
341
+ CharacterCodes[CharacterCodes["A"] = 65] = "A";
342
+ CharacterCodes[CharacterCodes["B"] = 66] = "B";
343
+ CharacterCodes[CharacterCodes["C"] = 67] = "C";
344
+ CharacterCodes[CharacterCodes["D"] = 68] = "D";
345
+ CharacterCodes[CharacterCodes["E"] = 69] = "E";
346
+ CharacterCodes[CharacterCodes["F"] = 70] = "F";
347
+ CharacterCodes[CharacterCodes["G"] = 71] = "G";
348
+ CharacterCodes[CharacterCodes["H"] = 72] = "H";
349
+ CharacterCodes[CharacterCodes["I"] = 73] = "I";
350
+ CharacterCodes[CharacterCodes["J"] = 74] = "J";
351
+ CharacterCodes[CharacterCodes["K"] = 75] = "K";
352
+ CharacterCodes[CharacterCodes["L"] = 76] = "L";
353
+ CharacterCodes[CharacterCodes["M"] = 77] = "M";
354
+ CharacterCodes[CharacterCodes["N"] = 78] = "N";
355
+ CharacterCodes[CharacterCodes["O"] = 79] = "O";
356
+ CharacterCodes[CharacterCodes["P"] = 80] = "P";
357
+ CharacterCodes[CharacterCodes["Q"] = 81] = "Q";
358
+ CharacterCodes[CharacterCodes["R"] = 82] = "R";
359
+ CharacterCodes[CharacterCodes["S"] = 83] = "S";
360
+ CharacterCodes[CharacterCodes["T"] = 84] = "T";
361
+ CharacterCodes[CharacterCodes["U"] = 85] = "U";
362
+ CharacterCodes[CharacterCodes["V"] = 86] = "V";
363
+ CharacterCodes[CharacterCodes["W"] = 87] = "W";
364
+ CharacterCodes[CharacterCodes["X"] = 88] = "X";
365
+ CharacterCodes[CharacterCodes["Y"] = 89] = "Y";
366
+ CharacterCodes[CharacterCodes["Z"] = 90] = "Z";
367
+ CharacterCodes[CharacterCodes["asterisk"] = 42] = "asterisk";
368
+ CharacterCodes[CharacterCodes["backslash"] = 92] = "backslash";
369
+ CharacterCodes[CharacterCodes["closeBrace"] = 125] = "closeBrace";
370
+ CharacterCodes[CharacterCodes["closeBracket"] = 93] = "closeBracket";
371
+ CharacterCodes[CharacterCodes["colon"] = 58] = "colon";
372
+ CharacterCodes[CharacterCodes["comma"] = 44] = "comma";
373
+ CharacterCodes[CharacterCodes["dot"] = 46] = "dot";
374
+ CharacterCodes[CharacterCodes["doubleQuote"] = 34] = "doubleQuote";
375
+ CharacterCodes[CharacterCodes["minus"] = 45] = "minus";
376
+ CharacterCodes[CharacterCodes["openBrace"] = 123] = "openBrace";
377
+ CharacterCodes[CharacterCodes["openBracket"] = 91] = "openBracket";
378
+ CharacterCodes[CharacterCodes["plus"] = 43] = "plus";
379
+ CharacterCodes[CharacterCodes["slash"] = 47] = "slash";
380
+ CharacterCodes[CharacterCodes["formFeed"] = 12] = "formFeed";
381
+ CharacterCodes[CharacterCodes["tab"] = 9] = "tab";
382
+ })(CharacterCodes || (CharacterCodes = {}));
383
+ new Array(20).fill(0).map((_, index) => {
384
+ return " ".repeat(index);
385
+ });
386
+ const maxCachedValues = 200;
387
+ new Array(maxCachedValues).fill(0).map((_, index) => {
388
+ return "\n" + " ".repeat(index);
389
+ }), new Array(maxCachedValues).fill(0).map((_, index) => {
390
+ return "\r" + " ".repeat(index);
391
+ }), new Array(maxCachedValues).fill(0).map((_, index) => {
392
+ return "\r\n" + " ".repeat(index);
393
+ }), new Array(maxCachedValues).fill(0).map((_, index) => {
394
+ return "\n" + " ".repeat(index);
395
+ }), new Array(maxCachedValues).fill(0).map((_, index) => {
396
+ return "\r" + " ".repeat(index);
397
+ }), new Array(maxCachedValues).fill(0).map((_, index) => {
398
+ return "\r\n" + " ".repeat(index);
399
+ });
400
+ //#endregion
401
+ //#region ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/parser.js
402
+ var ParseOptions;
403
+ (function(ParseOptions) {
404
+ ParseOptions.DEFAULT = { allowTrailingComma: false };
405
+ })(ParseOptions || (ParseOptions = {}));
406
+ /**
407
+ * Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
408
+ * Therefore always check the errors list to find out if the input was valid.
409
+ */
410
+ function parse$2(text, errors = [], options = ParseOptions.DEFAULT) {
411
+ let currentProperty = null;
412
+ let currentParent = [];
413
+ const previousParents = [];
414
+ function onValue(value) {
415
+ if (Array.isArray(currentParent)) currentParent.push(value);
416
+ else if (currentProperty !== null) currentParent[currentProperty] = value;
417
+ }
418
+ visit(text, {
419
+ onObjectBegin: () => {
420
+ const object = {};
421
+ onValue(object);
422
+ previousParents.push(currentParent);
423
+ currentParent = object;
424
+ currentProperty = null;
425
+ },
426
+ onObjectProperty: (name) => {
427
+ currentProperty = name;
428
+ },
429
+ onObjectEnd: () => {
430
+ currentParent = previousParents.pop();
431
+ },
432
+ onArrayBegin: () => {
433
+ const array = [];
434
+ onValue(array);
435
+ previousParents.push(currentParent);
436
+ currentParent = array;
437
+ currentProperty = null;
438
+ },
439
+ onArrayEnd: () => {
440
+ currentParent = previousParents.pop();
441
+ },
442
+ onLiteralValue: onValue,
443
+ onError: (error, offset, length) => {
444
+ errors.push({
445
+ error,
446
+ offset,
447
+ length
448
+ });
449
+ }
450
+ }, options);
451
+ return currentParent[0];
452
+ }
453
+ /**
454
+ * Parses the given text and invokes the visitor functions for each object, array and literal reached.
455
+ */
456
+ function visit(text, visitor, options = ParseOptions.DEFAULT) {
457
+ const _scanner = createScanner(text, false);
458
+ const _jsonPath = [];
459
+ let suppressedCallbacks = 0;
460
+ function toNoArgVisit(visitFunction) {
461
+ return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
462
+ }
463
+ function toOneArgVisit(visitFunction) {
464
+ return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
465
+ }
466
+ function toOneArgVisitWithPath(visitFunction) {
467
+ return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
468
+ }
469
+ function toBeginVisit(visitFunction) {
470
+ return visitFunction ? () => {
471
+ if (suppressedCallbacks > 0) suppressedCallbacks++;
472
+ else if (visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) === false) suppressedCallbacks = 1;
473
+ } : () => true;
474
+ }
475
+ function toEndVisit(visitFunction) {
476
+ return visitFunction ? () => {
477
+ if (suppressedCallbacks > 0) suppressedCallbacks--;
478
+ if (suppressedCallbacks === 0) visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
479
+ } : () => true;
480
+ }
481
+ const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
482
+ const disallowComments = options && options.disallowComments;
483
+ const allowTrailingComma = options && options.allowTrailingComma;
484
+ function scanNext() {
485
+ while (true) {
486
+ const token = _scanner.scan();
487
+ switch (_scanner.getTokenError()) {
488
+ case 4:
489
+ handleError(14);
490
+ break;
491
+ case 5:
492
+ handleError(15);
493
+ break;
494
+ case 3:
495
+ handleError(13);
496
+ break;
497
+ case 1:
498
+ if (!disallowComments) handleError(11);
499
+ break;
500
+ case 2:
501
+ handleError(12);
502
+ break;
503
+ case 6: handleError(16);
504
+ }
505
+ switch (token) {
506
+ case 12:
507
+ case 13:
508
+ if (disallowComments) handleError(10);
509
+ else onComment();
510
+ break;
511
+ case 16:
512
+ handleError(1);
513
+ break;
514
+ case 15:
515
+ case 14: break;
516
+ default: return token;
517
+ }
518
+ }
519
+ }
520
+ function handleError(error, skipUntilAfter = [], skipUntil = []) {
521
+ onError(error);
522
+ if (skipUntilAfter.length + skipUntil.length > 0) {
523
+ let token = _scanner.getToken();
524
+ while (token !== 17) {
525
+ if (skipUntilAfter.indexOf(token) !== -1) {
526
+ scanNext();
527
+ break;
528
+ } else if (skipUntil.indexOf(token) !== -1) break;
529
+ token = scanNext();
530
+ }
531
+ }
532
+ }
533
+ function parseString(isValue) {
534
+ const value = _scanner.getTokenValue();
535
+ if (isValue) onLiteralValue(value);
536
+ else {
537
+ onObjectProperty(value);
538
+ _jsonPath.push(value);
539
+ }
540
+ scanNext();
541
+ return true;
542
+ }
543
+ function parseLiteral() {
544
+ switch (_scanner.getToken()) {
545
+ case 11:
546
+ const tokenValue = _scanner.getTokenValue();
547
+ let value = Number(tokenValue);
548
+ if (isNaN(value)) {
549
+ handleError(2);
550
+ value = 0;
551
+ }
552
+ onLiteralValue(value);
553
+ break;
554
+ case 7:
555
+ onLiteralValue(null);
556
+ break;
557
+ case 8:
558
+ onLiteralValue(true);
559
+ break;
560
+ case 9:
561
+ onLiteralValue(false);
562
+ break;
563
+ default: return false;
564
+ }
565
+ scanNext();
566
+ return true;
567
+ }
568
+ function parseProperty() {
569
+ if (_scanner.getToken() !== 10) {
570
+ handleError(3, [], [2, 5]);
571
+ return false;
572
+ }
573
+ parseString(false);
574
+ if (_scanner.getToken() === 6) {
575
+ onSeparator(":");
576
+ scanNext();
577
+ if (!parseValue()) handleError(4, [], [2, 5]);
578
+ } else handleError(5, [], [2, 5]);
579
+ _jsonPath.pop();
580
+ return true;
581
+ }
582
+ function parseObject() {
583
+ onObjectBegin();
584
+ scanNext();
585
+ let needsComma = false;
586
+ while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
587
+ if (_scanner.getToken() === 5) {
588
+ if (!needsComma) handleError(4, [], []);
589
+ onSeparator(",");
590
+ scanNext();
591
+ if (_scanner.getToken() === 2 && allowTrailingComma) break;
592
+ } else if (needsComma) handleError(6, [], []);
593
+ if (!parseProperty()) handleError(4, [], [2, 5]);
594
+ needsComma = true;
595
+ }
596
+ onObjectEnd();
597
+ if (_scanner.getToken() !== 2) handleError(7, [2], []);
598
+ else scanNext();
599
+ return true;
600
+ }
601
+ function parseArray() {
602
+ onArrayBegin();
603
+ scanNext();
604
+ let isFirstElement = true;
605
+ let needsComma = false;
606
+ while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
607
+ if (_scanner.getToken() === 5) {
608
+ if (!needsComma) handleError(4, [], []);
609
+ onSeparator(",");
610
+ scanNext();
611
+ if (_scanner.getToken() === 4 && allowTrailingComma) break;
612
+ } else if (needsComma) handleError(6, [], []);
613
+ if (isFirstElement) {
614
+ _jsonPath.push(0);
615
+ isFirstElement = false;
616
+ } else _jsonPath[_jsonPath.length - 1]++;
617
+ if (!parseValue()) handleError(4, [], [4, 5]);
618
+ needsComma = true;
619
+ }
620
+ onArrayEnd();
621
+ if (!isFirstElement) _jsonPath.pop();
622
+ if (_scanner.getToken() !== 4) handleError(8, [4], []);
623
+ else scanNext();
624
+ return true;
625
+ }
626
+ function parseValue() {
627
+ switch (_scanner.getToken()) {
628
+ case 3: return parseArray();
629
+ case 1: return parseObject();
630
+ case 10: return parseString(true);
631
+ default: return parseLiteral();
632
+ }
633
+ }
634
+ scanNext();
635
+ if (_scanner.getToken() === 17) {
636
+ if (options.allowEmptyContent) return true;
637
+ handleError(4, [], []);
638
+ return false;
639
+ }
640
+ if (!parseValue()) {
641
+ handleError(4, [], []);
642
+ return false;
643
+ }
644
+ if (_scanner.getToken() !== 17) handleError(9, [], []);
645
+ return true;
646
+ }
647
+ //#endregion
648
+ //#region ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/main.js
649
+ var ScanError;
650
+ (function(ScanError) {
651
+ ScanError[ScanError["None"] = 0] = "None";
652
+ ScanError[ScanError["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
653
+ ScanError[ScanError["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
654
+ ScanError[ScanError["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
655
+ ScanError[ScanError["InvalidUnicode"] = 4] = "InvalidUnicode";
656
+ ScanError[ScanError["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
657
+ ScanError[ScanError["InvalidCharacter"] = 6] = "InvalidCharacter";
658
+ })(ScanError || (ScanError = {}));
659
+ var SyntaxKind;
660
+ (function(SyntaxKind) {
661
+ SyntaxKind[SyntaxKind["OpenBraceToken"] = 1] = "OpenBraceToken";
662
+ SyntaxKind[SyntaxKind["CloseBraceToken"] = 2] = "CloseBraceToken";
663
+ SyntaxKind[SyntaxKind["OpenBracketToken"] = 3] = "OpenBracketToken";
664
+ SyntaxKind[SyntaxKind["CloseBracketToken"] = 4] = "CloseBracketToken";
665
+ SyntaxKind[SyntaxKind["CommaToken"] = 5] = "CommaToken";
666
+ SyntaxKind[SyntaxKind["ColonToken"] = 6] = "ColonToken";
667
+ SyntaxKind[SyntaxKind["NullKeyword"] = 7] = "NullKeyword";
668
+ SyntaxKind[SyntaxKind["TrueKeyword"] = 8] = "TrueKeyword";
669
+ SyntaxKind[SyntaxKind["FalseKeyword"] = 9] = "FalseKeyword";
670
+ SyntaxKind[SyntaxKind["StringLiteral"] = 10] = "StringLiteral";
671
+ SyntaxKind[SyntaxKind["NumericLiteral"] = 11] = "NumericLiteral";
672
+ SyntaxKind[SyntaxKind["LineCommentTrivia"] = 12] = "LineCommentTrivia";
673
+ SyntaxKind[SyntaxKind["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
674
+ SyntaxKind[SyntaxKind["LineBreakTrivia"] = 14] = "LineBreakTrivia";
675
+ SyntaxKind[SyntaxKind["Trivia"] = 15] = "Trivia";
676
+ SyntaxKind[SyntaxKind["Unknown"] = 16] = "Unknown";
677
+ SyntaxKind[SyntaxKind["EOF"] = 17] = "EOF";
678
+ })(SyntaxKind || (SyntaxKind = {}));
679
+ /**
680
+ * Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
681
+ * Therefore, always check the errors list to find out if the input was valid.
682
+ */
683
+ const parse$1 = parse$2;
684
+ var ParseErrorCode;
685
+ (function(ParseErrorCode) {
686
+ ParseErrorCode[ParseErrorCode["InvalidSymbol"] = 1] = "InvalidSymbol";
687
+ ParseErrorCode[ParseErrorCode["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
688
+ ParseErrorCode[ParseErrorCode["PropertyNameExpected"] = 3] = "PropertyNameExpected";
689
+ ParseErrorCode[ParseErrorCode["ValueExpected"] = 4] = "ValueExpected";
690
+ ParseErrorCode[ParseErrorCode["ColonExpected"] = 5] = "ColonExpected";
691
+ ParseErrorCode[ParseErrorCode["CommaExpected"] = 6] = "CommaExpected";
692
+ ParseErrorCode[ParseErrorCode["CloseBraceExpected"] = 7] = "CloseBraceExpected";
693
+ ParseErrorCode[ParseErrorCode["CloseBracketExpected"] = 8] = "CloseBracketExpected";
694
+ ParseErrorCode[ParseErrorCode["EndOfFileExpected"] = 9] = "EndOfFileExpected";
695
+ ParseErrorCode[ParseErrorCode["InvalidCommentToken"] = 10] = "InvalidCommentToken";
696
+ ParseErrorCode[ParseErrorCode["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
697
+ ParseErrorCode[ParseErrorCode["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
698
+ ParseErrorCode[ParseErrorCode["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
699
+ ParseErrorCode[ParseErrorCode["InvalidUnicode"] = 14] = "InvalidUnicode";
700
+ ParseErrorCode[ParseErrorCode["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
701
+ ParseErrorCode[ParseErrorCode["InvalidCharacter"] = 16] = "InvalidCharacter";
702
+ })(ParseErrorCode || (ParseErrorCode = {}));
703
+ //#endregion
704
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.js
705
+ var _a$1;
706
+ function $constructor(name, initializer, params) {
707
+ function init(inst, def) {
708
+ if (!inst._zod) Object.defineProperty(inst, "_zod", {
709
+ value: {
710
+ def,
711
+ constr: _,
712
+ traits: /* @__PURE__ */ new Set()
713
+ },
714
+ enumerable: false
715
+ });
716
+ if (inst._zod.traits.has(name)) return;
717
+ inst._zod.traits.add(name);
718
+ initializer(inst, def);
719
+ const proto = _.prototype;
720
+ const keys = Object.keys(proto);
721
+ for (let i = 0; i < keys.length; i++) {
722
+ const k = keys[i];
723
+ if (!(k in inst)) inst[k] = proto[k].bind(inst);
724
+ }
725
+ }
726
+ const Parent = params?.Parent ?? Object;
727
+ class Definition extends Parent {}
728
+ Object.defineProperty(Definition, "name", { value: name });
729
+ function _(def) {
730
+ var _a;
731
+ const inst = params?.Parent ? new Definition() : this;
732
+ init(inst, def);
733
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
734
+ for (const fn of inst._zod.deferred) fn();
735
+ return inst;
736
+ }
737
+ Object.defineProperty(_, "init", { value: init });
738
+ Object.defineProperty(_, Symbol.hasInstance, { value: (inst) => {
739
+ if (params?.Parent && inst instanceof params.Parent) return true;
740
+ return inst?._zod?.traits?.has(name);
741
+ } });
742
+ Object.defineProperty(_, "name", { value: name });
743
+ return _;
744
+ }
745
+ var $ZodAsyncError = class extends Error {
746
+ constructor() {
747
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
748
+ }
749
+ };
750
+ var $ZodEncodeError = class extends Error {
751
+ constructor(name) {
752
+ super(`Encountered unidirectional transform during encode: ${name}`);
753
+ this.name = "ZodEncodeError";
754
+ }
755
+ };
756
+ (_a$1 = globalThis).__zod_globalConfig ?? (_a$1.__zod_globalConfig = {});
757
+ const globalConfig = globalThis.__zod_globalConfig;
758
+ function config(newConfig) {
759
+ if (newConfig) Object.assign(globalConfig, newConfig);
760
+ return globalConfig;
761
+ }
762
+ //#endregion
763
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/util.js
764
+ function getEnumValues(entries) {
765
+ const numericValues = Object.values(entries).filter((v) => typeof v === "number");
766
+ return Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
767
+ }
768
+ function jsonStringifyReplacer(_, value) {
769
+ if (typeof value === "bigint") return value.toString();
770
+ return value;
771
+ }
772
+ function cached(getter) {
773
+ return { get value() {
774
+ {
775
+ const value = getter();
776
+ Object.defineProperty(this, "value", { value });
777
+ return value;
778
+ }
779
+ } };
780
+ }
781
+ function nullish(input) {
782
+ return input === null || input === void 0;
783
+ }
784
+ function cleanRegex(source) {
785
+ const start = source.startsWith("^") ? 1 : 0;
786
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
787
+ return source.slice(start, end);
788
+ }
789
+ const EVALUATING = /* @__PURE__*/ Symbol("evaluating");
790
+ function defineLazy(object, key, getter) {
791
+ let value = void 0;
792
+ Object.defineProperty(object, key, {
793
+ get() {
794
+ if (value === EVALUATING) return;
795
+ if (value === void 0) {
796
+ value = EVALUATING;
797
+ value = getter();
798
+ }
799
+ return value;
800
+ },
801
+ set(v) {
802
+ Object.defineProperty(object, key, { value: v });
803
+ },
804
+ configurable: true
805
+ });
806
+ }
807
+ function assignProp(target, prop, value) {
808
+ Object.defineProperty(target, prop, {
809
+ value,
810
+ writable: true,
811
+ enumerable: true,
812
+ configurable: true
813
+ });
814
+ }
815
+ function mergeDefs(...defs) {
816
+ const mergedDescriptors = {};
817
+ for (const def of defs) {
818
+ const descriptors = Object.getOwnPropertyDescriptors(def);
819
+ Object.assign(mergedDescriptors, descriptors);
820
+ }
821
+ return Object.defineProperties({}, mergedDescriptors);
822
+ }
823
+ function esc(str) {
824
+ return JSON.stringify(str);
825
+ }
826
+ function slugify(input) {
827
+ return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
828
+ }
829
+ const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
830
+ function isObject(data) {
831
+ return typeof data === "object" && data !== null && !Array.isArray(data);
832
+ }
833
+ const allowsEval = /* @__PURE__*/ cached(() => {
834
+ if (globalConfig.jitless) return false;
835
+ if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false;
836
+ try {
837
+ new Function("");
838
+ return true;
839
+ } catch (_) {
840
+ return false;
841
+ }
842
+ });
843
+ function isPlainObject(o) {
844
+ if (isObject(o) === false) return false;
845
+ const ctor = o.constructor;
846
+ if (ctor === void 0) return true;
847
+ if (typeof ctor !== "function") return true;
848
+ const prot = ctor.prototype;
849
+ if (isObject(prot) === false) return false;
850
+ if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) return false;
851
+ return true;
852
+ }
853
+ function shallowClone(o) {
854
+ if (isPlainObject(o)) return { ...o };
855
+ if (Array.isArray(o)) return [...o];
856
+ if (o instanceof Map) return new Map(o);
857
+ if (o instanceof Set) return new Set(o);
858
+ return o;
859
+ }
860
+ const propertyKeyTypes = /* @__PURE__*/ new Set([
861
+ "string",
862
+ "number",
863
+ "symbol"
864
+ ]);
865
+ function escapeRegex(str) {
866
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
867
+ }
868
+ function clone(inst, def, params) {
869
+ const cl = new inst._zod.constr(def ?? inst._zod.def);
870
+ if (!def || params?.parent) cl._zod.parent = inst;
871
+ return cl;
872
+ }
873
+ function normalizeParams(_params) {
874
+ const params = _params;
875
+ if (!params) return {};
876
+ if (typeof params === "string") return { error: () => params };
877
+ if (params?.message !== void 0) {
878
+ if (params?.error !== void 0) throw new Error("Cannot specify both `message` and `error` params");
879
+ params.error = params.message;
880
+ }
881
+ delete params.message;
882
+ if (typeof params.error === "string") return {
883
+ ...params,
884
+ error: () => params.error
885
+ };
886
+ return params;
887
+ }
888
+ function optionalKeys(shape) {
889
+ return Object.keys(shape).filter((k) => {
890
+ return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
891
+ });
892
+ }
893
+ Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, -Number.MAX_VALUE, Number.MAX_VALUE;
894
+ function pick(schema, mask) {
895
+ const currDef = schema._zod.def;
896
+ const checks = currDef.checks;
897
+ if (checks && checks.length > 0) throw new Error(".pick() cannot be used on object schemas containing refinements");
898
+ return clone(schema, mergeDefs(schema._zod.def, {
899
+ get shape() {
900
+ const newShape = {};
901
+ for (const key in mask) {
902
+ if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
903
+ if (!mask[key]) continue;
904
+ newShape[key] = currDef.shape[key];
905
+ }
906
+ assignProp(this, "shape", newShape);
907
+ return newShape;
908
+ },
909
+ checks: []
910
+ }));
911
+ }
912
+ function omit(schema, mask) {
913
+ const currDef = schema._zod.def;
914
+ const checks = currDef.checks;
915
+ if (checks && checks.length > 0) throw new Error(".omit() cannot be used on object schemas containing refinements");
916
+ return clone(schema, mergeDefs(schema._zod.def, {
917
+ get shape() {
918
+ const newShape = { ...schema._zod.def.shape };
919
+ for (const key in mask) {
920
+ if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
921
+ if (!mask[key]) continue;
922
+ delete newShape[key];
923
+ }
924
+ assignProp(this, "shape", newShape);
925
+ return newShape;
926
+ },
927
+ checks: []
928
+ }));
929
+ }
930
+ function extend(schema, shape) {
931
+ if (!isPlainObject(shape)) throw new Error("Invalid input to extend: expected a plain object");
932
+ const checks = schema._zod.def.checks;
933
+ if (checks && checks.length > 0) {
934
+ const existingShape = schema._zod.def.shape;
935
+ for (const key in shape) if (Object.getOwnPropertyDescriptor(existingShape, key) !== void 0) throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
936
+ }
937
+ return clone(schema, mergeDefs(schema._zod.def, { get shape() {
938
+ const _shape = {
939
+ ...schema._zod.def.shape,
940
+ ...shape
941
+ };
942
+ assignProp(this, "shape", _shape);
943
+ return _shape;
944
+ } }));
945
+ }
946
+ function safeExtend(schema, shape) {
947
+ if (!isPlainObject(shape)) throw new Error("Invalid input to safeExtend: expected a plain object");
948
+ return clone(schema, mergeDefs(schema._zod.def, { get shape() {
949
+ const _shape = {
950
+ ...schema._zod.def.shape,
951
+ ...shape
952
+ };
953
+ assignProp(this, "shape", _shape);
954
+ return _shape;
955
+ } }));
956
+ }
957
+ function merge(a, b) {
958
+ if (a._zod.def.checks?.length) throw new Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");
959
+ return clone(a, mergeDefs(a._zod.def, {
960
+ get shape() {
961
+ const _shape = {
962
+ ...a._zod.def.shape,
963
+ ...b._zod.def.shape
964
+ };
965
+ assignProp(this, "shape", _shape);
966
+ return _shape;
967
+ },
968
+ get catchall() {
969
+ return b._zod.def.catchall;
970
+ },
971
+ checks: b._zod.def.checks ?? []
972
+ }));
973
+ }
974
+ function partial(Class, schema, mask) {
975
+ const checks = schema._zod.def.checks;
976
+ if (checks && checks.length > 0) throw new Error(".partial() cannot be used on object schemas containing refinements");
977
+ return clone(schema, mergeDefs(schema._zod.def, {
978
+ get shape() {
979
+ const oldShape = schema._zod.def.shape;
980
+ const shape = { ...oldShape };
981
+ if (mask) for (const key in mask) {
982
+ if (!(key in oldShape)) throw new Error(`Unrecognized key: "${key}"`);
983
+ if (!mask[key]) continue;
984
+ shape[key] = Class ? new Class({
985
+ type: "optional",
986
+ innerType: oldShape[key]
987
+ }) : oldShape[key];
988
+ }
989
+ else for (const key in oldShape) shape[key] = Class ? new Class({
990
+ type: "optional",
991
+ innerType: oldShape[key]
992
+ }) : oldShape[key];
993
+ assignProp(this, "shape", shape);
994
+ return shape;
995
+ },
996
+ checks: []
997
+ }));
998
+ }
999
+ function required(Class, schema, mask) {
1000
+ return clone(schema, mergeDefs(schema._zod.def, { get shape() {
1001
+ const oldShape = schema._zod.def.shape;
1002
+ const shape = { ...oldShape };
1003
+ if (mask) for (const key in mask) {
1004
+ if (!(key in shape)) throw new Error(`Unrecognized key: "${key}"`);
1005
+ if (!mask[key]) continue;
1006
+ shape[key] = new Class({
1007
+ type: "nonoptional",
1008
+ innerType: oldShape[key]
1009
+ });
1010
+ }
1011
+ else for (const key in oldShape) shape[key] = new Class({
1012
+ type: "nonoptional",
1013
+ innerType: oldShape[key]
1014
+ });
1015
+ assignProp(this, "shape", shape);
1016
+ return shape;
1017
+ } }));
1018
+ }
1019
+ function aborted(x, startIndex = 0) {
1020
+ if (x.aborted === true) return true;
1021
+ for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue !== true) return true;
1022
+ return false;
1023
+ }
1024
+ function explicitlyAborted(x, startIndex = 0) {
1025
+ if (x.aborted === true) return true;
1026
+ for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue === false) return true;
1027
+ return false;
1028
+ }
1029
+ function prefixIssues(path, issues) {
1030
+ return issues.map((iss) => {
1031
+ var _a;
1032
+ (_a = iss).path ?? (_a.path = []);
1033
+ iss.path.unshift(path);
1034
+ return iss;
1035
+ });
1036
+ }
1037
+ function unwrapMessage(message) {
1038
+ return typeof message === "string" ? message : message?.message;
1039
+ }
1040
+ function finalizeIssue(iss, ctx, config) {
1041
+ const message = iss.message ? iss.message : unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config.customError?.(iss)) ?? unwrapMessage(config.localeError?.(iss)) ?? "Invalid input";
1042
+ const { inst: _inst, continue: _continue, input: _input, ...rest } = iss;
1043
+ rest.path ?? (rest.path = []);
1044
+ rest.message = message;
1045
+ if (ctx?.reportInput) rest.input = _input;
1046
+ return rest;
1047
+ }
1048
+ function getLengthableOrigin(input) {
1049
+ if (Array.isArray(input)) return "array";
1050
+ if (typeof input === "string") return "string";
1051
+ return "unknown";
1052
+ }
1053
+ function issue(...args) {
1054
+ const [iss, input, inst] = args;
1055
+ if (typeof iss === "string") return {
1056
+ message: iss,
1057
+ code: "custom",
1058
+ input,
1059
+ inst
1060
+ };
1061
+ return { ...iss };
1062
+ }
1063
+ //#endregion
1064
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/errors.js
1065
+ const initializer$1 = (inst, def) => {
1066
+ inst.name = "$ZodError";
1067
+ Object.defineProperty(inst, "_zod", {
1068
+ value: inst._zod,
1069
+ enumerable: false
1070
+ });
1071
+ Object.defineProperty(inst, "issues", {
1072
+ value: def,
1073
+ enumerable: false
1074
+ });
1075
+ inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
1076
+ Object.defineProperty(inst, "toString", {
1077
+ value: () => inst.message,
1078
+ enumerable: false
1079
+ });
1080
+ };
1081
+ const $ZodError = $constructor("$ZodError", initializer$1);
1082
+ const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
1083
+ function flattenError(error, mapper = (issue) => issue.message) {
1084
+ const fieldErrors = {};
1085
+ const formErrors = [];
1086
+ for (const sub of error.issues) if (sub.path.length > 0) {
1087
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
1088
+ fieldErrors[sub.path[0]].push(mapper(sub));
1089
+ } else formErrors.push(mapper(sub));
1090
+ return {
1091
+ formErrors,
1092
+ fieldErrors
1093
+ };
1094
+ }
1095
+ function formatError(error, mapper = (issue) => issue.message) {
1096
+ const fieldErrors = { _errors: [] };
1097
+ const processError = (error, path = []) => {
1098
+ for (const issue of error.issues) if (issue.code === "invalid_union" && issue.errors.length) issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
1099
+ else if (issue.code === "invalid_key") processError({ issues: issue.issues }, [...path, ...issue.path]);
1100
+ else if (issue.code === "invalid_element") processError({ issues: issue.issues }, [...path, ...issue.path]);
1101
+ else {
1102
+ const fullpath = [...path, ...issue.path];
1103
+ if (fullpath.length === 0) fieldErrors._errors.push(mapper(issue));
1104
+ else {
1105
+ let curr = fieldErrors;
1106
+ let i = 0;
1107
+ while (i < fullpath.length) {
1108
+ const el = fullpath[i];
1109
+ if (!(i === fullpath.length - 1)) curr[el] = curr[el] || { _errors: [] };
1110
+ else {
1111
+ curr[el] = curr[el] || { _errors: [] };
1112
+ curr[el]._errors.push(mapper(issue));
1113
+ }
1114
+ curr = curr[el];
1115
+ i++;
1116
+ }
1117
+ }
1118
+ }
1119
+ };
1120
+ processError(error);
1121
+ return fieldErrors;
1122
+ }
1123
+ //#endregion
1124
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/parse.js
1125
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
1126
+ const ctx = _ctx ? {
1127
+ ..._ctx,
1128
+ async: false
1129
+ } : { async: false };
1130
+ const result = schema._zod.run({
1131
+ value,
1132
+ issues: []
1133
+ }, ctx);
1134
+ if (result instanceof Promise) throw new $ZodAsyncError();
1135
+ if (result.issues.length) {
1136
+ const e = new ((_params?.Err) ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
1137
+ captureStackTrace(e, _params?.callee);
1138
+ throw e;
1139
+ }
1140
+ return result.value;
1141
+ };
1142
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
1143
+ const ctx = _ctx ? {
1144
+ ..._ctx,
1145
+ async: true
1146
+ } : { async: true };
1147
+ let result = schema._zod.run({
1148
+ value,
1149
+ issues: []
1150
+ }, ctx);
1151
+ if (result instanceof Promise) result = await result;
1152
+ if (result.issues.length) {
1153
+ const e = new ((params?.Err) ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
1154
+ captureStackTrace(e, params?.callee);
1155
+ throw e;
1156
+ }
1157
+ return result.value;
1158
+ };
1159
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
1160
+ const ctx = _ctx ? {
1161
+ ..._ctx,
1162
+ async: false
1163
+ } : { async: false };
1164
+ const result = schema._zod.run({
1165
+ value,
1166
+ issues: []
1167
+ }, ctx);
1168
+ if (result instanceof Promise) throw new $ZodAsyncError();
1169
+ return result.issues.length ? {
1170
+ success: false,
1171
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
1172
+ } : {
1173
+ success: true,
1174
+ data: result.value
1175
+ };
1176
+ };
1177
+ const safeParse$1 = /* @__PURE__*/ _safeParse($ZodRealError);
1178
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
1179
+ const ctx = _ctx ? {
1180
+ ..._ctx,
1181
+ async: true
1182
+ } : { async: true };
1183
+ let result = schema._zod.run({
1184
+ value,
1185
+ issues: []
1186
+ }, ctx);
1187
+ if (result instanceof Promise) result = await result;
1188
+ return result.issues.length ? {
1189
+ success: false,
1190
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
1191
+ } : {
1192
+ success: true,
1193
+ data: result.value
1194
+ };
1195
+ };
1196
+ const safeParseAsync$1 = /* @__PURE__*/ _safeParseAsync($ZodRealError);
1197
+ const _encode = (_Err) => (schema, value, _ctx) => {
1198
+ const ctx = _ctx ? {
1199
+ ..._ctx,
1200
+ direction: "backward"
1201
+ } : { direction: "backward" };
1202
+ return _parse(_Err)(schema, value, ctx);
1203
+ };
1204
+ const _decode = (_Err) => (schema, value, _ctx) => {
1205
+ return _parse(_Err)(schema, value, _ctx);
1206
+ };
1207
+ const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
1208
+ const ctx = _ctx ? {
1209
+ ..._ctx,
1210
+ direction: "backward"
1211
+ } : { direction: "backward" };
1212
+ return _parseAsync(_Err)(schema, value, ctx);
1213
+ };
1214
+ const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
1215
+ return _parseAsync(_Err)(schema, value, _ctx);
1216
+ };
1217
+ const _safeEncode = (_Err) => (schema, value, _ctx) => {
1218
+ const ctx = _ctx ? {
1219
+ ..._ctx,
1220
+ direction: "backward"
1221
+ } : { direction: "backward" };
1222
+ return _safeParse(_Err)(schema, value, ctx);
1223
+ };
1224
+ const _safeDecode = (_Err) => (schema, value, _ctx) => {
1225
+ return _safeParse(_Err)(schema, value, _ctx);
1226
+ };
1227
+ const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
1228
+ const ctx = _ctx ? {
1229
+ ..._ctx,
1230
+ direction: "backward"
1231
+ } : { direction: "backward" };
1232
+ return _safeParseAsync(_Err)(schema, value, ctx);
1233
+ };
1234
+ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
1235
+ return _safeParseAsync(_Err)(schema, value, _ctx);
1236
+ };
1237
+ //#endregion
1238
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/regexes.js
1239
+ /**
1240
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
1241
+ * (timestamps embedded in the id). Use {@link cuid2} instead.
1242
+ * See https://github.com/paralleldrive/cuid.
1243
+ */
1244
+ const cuid = /^[cC][0-9a-z]{6,}$/;
1245
+ const cuid2 = /^[0-9a-z]+$/;
1246
+ const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
1247
+ const xid = /^[0-9a-vA-V]{20}$/;
1248
+ const ksuid = /^[A-Za-z0-9]{27}$/;
1249
+ const nanoid = /^[a-zA-Z0-9_-]{21}$/;
1250
+ /** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
1251
+ const duration$1 = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
1252
+ /** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
1253
+ const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
1254
+ /** Returns a regex for validating an RFC 9562/4122 UUID.
1255
+ *
1256
+ * @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
1257
+ const uuid = (version) => {
1258
+ if (!version) return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
1259
+ return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
1260
+ };
1261
+ /** Practical email validation */
1262
+ const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
1263
+ const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
1264
+ function emoji() {
1265
+ return new RegExp(_emoji$1, "u");
1266
+ }
1267
+ const 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])$/;
1268
+ const ipv6 = /^(([0-9a-fA-F]{1,4}:){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}|:))$/;
1269
+ const cidrv4 = /^((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])\/([0-9]|[1-2][0-9]|3[0-2])$/;
1270
+ const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
1271
+ const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
1272
+ const base64url = /^[A-Za-z0-9_-]*$/;
1273
+ const httpProtocol = /^https?$/;
1274
+ const e164 = /^\+[1-9]\d{6,14}$/;
1275
+ const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
1276
+ const date$1 = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
1277
+ function timeSource(args) {
1278
+ const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
1279
+ return typeof args.precision === "number" ? args.precision === -1 ? `${hhmm}` : args.precision === 0 ? `${hhmm}:[0-5]\\d` : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}` : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
1280
+ }
1281
+ function time$1(args) {
1282
+ return new RegExp(`^${timeSource(args)}$`);
1283
+ }
1284
+ function datetime$1(args) {
1285
+ const time = timeSource({ precision: args.precision });
1286
+ const opts = ["Z"];
1287
+ if (args.local) opts.push("");
1288
+ if (args.offset) opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
1289
+ const timeRegex = `${time}(?:${opts.join("|")})`;
1290
+ return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
1291
+ }
1292
+ const string$1 = (params) => {
1293
+ const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
1294
+ return new RegExp(`^${regex}$`);
1295
+ };
1296
+ const boolean$1 = /^(?:true|false)$/i;
1297
+ const lowercase = /^[^A-Z]*$/;
1298
+ const uppercase = /^[^a-z]*$/;
1299
+ //#endregion
1300
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/checks.js
1301
+ const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
1302
+ var _a;
1303
+ inst._zod ?? (inst._zod = {});
1304
+ inst._zod.def = def;
1305
+ (_a = inst._zod).onattach ?? (_a.onattach = []);
1306
+ });
1307
+ const $ZodCheckMaxLength = /*@__PURE__*/ $constructor("$ZodCheckMaxLength", (inst, def) => {
1308
+ var _a;
1309
+ $ZodCheck.init(inst, def);
1310
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
1311
+ const val = payload.value;
1312
+ return !nullish(val) && val.length !== void 0;
1313
+ });
1314
+ inst._zod.onattach.push((inst) => {
1315
+ const curr = inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
1316
+ if (def.maximum < curr) inst._zod.bag.maximum = def.maximum;
1317
+ });
1318
+ inst._zod.check = (payload) => {
1319
+ const input = payload.value;
1320
+ if (input.length <= def.maximum) return;
1321
+ const origin = getLengthableOrigin(input);
1322
+ payload.issues.push({
1323
+ origin,
1324
+ code: "too_big",
1325
+ maximum: def.maximum,
1326
+ inclusive: true,
1327
+ input,
1328
+ inst,
1329
+ continue: !def.abort
1330
+ });
1331
+ };
1332
+ });
1333
+ const $ZodCheckMinLength = /*@__PURE__*/ $constructor("$ZodCheckMinLength", (inst, def) => {
1334
+ var _a;
1335
+ $ZodCheck.init(inst, def);
1336
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
1337
+ const val = payload.value;
1338
+ return !nullish(val) && val.length !== void 0;
1339
+ });
1340
+ inst._zod.onattach.push((inst) => {
1341
+ const curr = inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
1342
+ if (def.minimum > curr) inst._zod.bag.minimum = def.minimum;
1343
+ });
1344
+ inst._zod.check = (payload) => {
1345
+ const input = payload.value;
1346
+ if (input.length >= def.minimum) return;
1347
+ const origin = getLengthableOrigin(input);
1348
+ payload.issues.push({
1349
+ origin,
1350
+ code: "too_small",
1351
+ minimum: def.minimum,
1352
+ inclusive: true,
1353
+ input,
1354
+ inst,
1355
+ continue: !def.abort
1356
+ });
1357
+ };
1358
+ });
1359
+ const $ZodCheckLengthEquals = /*@__PURE__*/ $constructor("$ZodCheckLengthEquals", (inst, def) => {
1360
+ var _a;
1361
+ $ZodCheck.init(inst, def);
1362
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
1363
+ const val = payload.value;
1364
+ return !nullish(val) && val.length !== void 0;
1365
+ });
1366
+ inst._zod.onattach.push((inst) => {
1367
+ const bag = inst._zod.bag;
1368
+ bag.minimum = def.length;
1369
+ bag.maximum = def.length;
1370
+ bag.length = def.length;
1371
+ });
1372
+ inst._zod.check = (payload) => {
1373
+ const input = payload.value;
1374
+ const length = input.length;
1375
+ if (length === def.length) return;
1376
+ const origin = getLengthableOrigin(input);
1377
+ const tooBig = length > def.length;
1378
+ payload.issues.push({
1379
+ origin,
1380
+ ...tooBig ? {
1381
+ code: "too_big",
1382
+ maximum: def.length
1383
+ } : {
1384
+ code: "too_small",
1385
+ minimum: def.length
1386
+ },
1387
+ inclusive: true,
1388
+ exact: true,
1389
+ input: payload.value,
1390
+ inst,
1391
+ continue: !def.abort
1392
+ });
1393
+ };
1394
+ });
1395
+ const $ZodCheckStringFormat = /*@__PURE__*/ $constructor("$ZodCheckStringFormat", (inst, def) => {
1396
+ var _a, _b;
1397
+ $ZodCheck.init(inst, def);
1398
+ inst._zod.onattach.push((inst) => {
1399
+ const bag = inst._zod.bag;
1400
+ bag.format = def.format;
1401
+ if (def.pattern) {
1402
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
1403
+ bag.patterns.add(def.pattern);
1404
+ }
1405
+ });
1406
+ if (def.pattern) (_a = inst._zod).check ?? (_a.check = (payload) => {
1407
+ def.pattern.lastIndex = 0;
1408
+ if (def.pattern.test(payload.value)) return;
1409
+ payload.issues.push({
1410
+ origin: "string",
1411
+ code: "invalid_format",
1412
+ format: def.format,
1413
+ input: payload.value,
1414
+ ...def.pattern ? { pattern: def.pattern.toString() } : {},
1415
+ inst,
1416
+ continue: !def.abort
1417
+ });
1418
+ });
1419
+ else (_b = inst._zod).check ?? (_b.check = () => {});
1420
+ });
1421
+ const $ZodCheckRegex = /*@__PURE__*/ $constructor("$ZodCheckRegex", (inst, def) => {
1422
+ $ZodCheckStringFormat.init(inst, def);
1423
+ inst._zod.check = (payload) => {
1424
+ def.pattern.lastIndex = 0;
1425
+ if (def.pattern.test(payload.value)) return;
1426
+ payload.issues.push({
1427
+ origin: "string",
1428
+ code: "invalid_format",
1429
+ format: "regex",
1430
+ input: payload.value,
1431
+ pattern: def.pattern.toString(),
1432
+ inst,
1433
+ continue: !def.abort
1434
+ });
1435
+ };
1436
+ });
1437
+ const $ZodCheckLowerCase = /*@__PURE__*/ $constructor("$ZodCheckLowerCase", (inst, def) => {
1438
+ def.pattern ?? (def.pattern = lowercase);
1439
+ $ZodCheckStringFormat.init(inst, def);
1440
+ });
1441
+ const $ZodCheckUpperCase = /*@__PURE__*/ $constructor("$ZodCheckUpperCase", (inst, def) => {
1442
+ def.pattern ?? (def.pattern = uppercase);
1443
+ $ZodCheckStringFormat.init(inst, def);
1444
+ });
1445
+ const $ZodCheckIncludes = /*@__PURE__*/ $constructor("$ZodCheckIncludes", (inst, def) => {
1446
+ $ZodCheck.init(inst, def);
1447
+ const escapedRegex = escapeRegex(def.includes);
1448
+ const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
1449
+ def.pattern = pattern;
1450
+ inst._zod.onattach.push((inst) => {
1451
+ const bag = inst._zod.bag;
1452
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
1453
+ bag.patterns.add(pattern);
1454
+ });
1455
+ inst._zod.check = (payload) => {
1456
+ if (payload.value.includes(def.includes, def.position)) return;
1457
+ payload.issues.push({
1458
+ origin: "string",
1459
+ code: "invalid_format",
1460
+ format: "includes",
1461
+ includes: def.includes,
1462
+ input: payload.value,
1463
+ inst,
1464
+ continue: !def.abort
1465
+ });
1466
+ };
1467
+ });
1468
+ const $ZodCheckStartsWith = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (inst, def) => {
1469
+ $ZodCheck.init(inst, def);
1470
+ const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
1471
+ def.pattern ?? (def.pattern = pattern);
1472
+ inst._zod.onattach.push((inst) => {
1473
+ const bag = inst._zod.bag;
1474
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
1475
+ bag.patterns.add(pattern);
1476
+ });
1477
+ inst._zod.check = (payload) => {
1478
+ if (payload.value.startsWith(def.prefix)) return;
1479
+ payload.issues.push({
1480
+ origin: "string",
1481
+ code: "invalid_format",
1482
+ format: "starts_with",
1483
+ prefix: def.prefix,
1484
+ input: payload.value,
1485
+ inst,
1486
+ continue: !def.abort
1487
+ });
1488
+ };
1489
+ });
1490
+ const $ZodCheckEndsWith = /*@__PURE__*/ $constructor("$ZodCheckEndsWith", (inst, def) => {
1491
+ $ZodCheck.init(inst, def);
1492
+ const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
1493
+ def.pattern ?? (def.pattern = pattern);
1494
+ inst._zod.onattach.push((inst) => {
1495
+ const bag = inst._zod.bag;
1496
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
1497
+ bag.patterns.add(pattern);
1498
+ });
1499
+ inst._zod.check = (payload) => {
1500
+ if (payload.value.endsWith(def.suffix)) return;
1501
+ payload.issues.push({
1502
+ origin: "string",
1503
+ code: "invalid_format",
1504
+ format: "ends_with",
1505
+ suffix: def.suffix,
1506
+ input: payload.value,
1507
+ inst,
1508
+ continue: !def.abort
1509
+ });
1510
+ };
1511
+ });
1512
+ const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (inst, def) => {
1513
+ $ZodCheck.init(inst, def);
1514
+ inst._zod.check = (payload) => {
1515
+ payload.value = def.tx(payload.value);
1516
+ };
1517
+ });
1518
+ //#endregion
1519
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/doc.js
1520
+ var Doc = class {
1521
+ constructor(args = []) {
1522
+ this.content = [];
1523
+ this.indent = 0;
1524
+ if (this) this.args = args;
1525
+ }
1526
+ indented(fn) {
1527
+ this.indent += 1;
1528
+ fn(this);
1529
+ this.indent -= 1;
1530
+ }
1531
+ write(arg) {
1532
+ if (typeof arg === "function") {
1533
+ arg(this, { execution: "sync" });
1534
+ arg(this, { execution: "async" });
1535
+ return;
1536
+ }
1537
+ const lines = arg.split("\n").filter((x) => x);
1538
+ const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
1539
+ const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
1540
+ for (const line of dedented) this.content.push(line);
1541
+ }
1542
+ compile() {
1543
+ const F = Function;
1544
+ const args = this?.args;
1545
+ const lines = [...(this?.content ?? [``]).map((x) => ` ${x}`)];
1546
+ return new F(...args, lines.join("\n"));
1547
+ }
1548
+ };
1549
+ //#endregion
1550
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/versions.js
1551
+ const version = {
1552
+ major: 4,
1553
+ minor: 4,
1554
+ patch: 3
1555
+ };
1556
+ //#endregion
1557
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/schemas.js
1558
+ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
1559
+ var _a;
1560
+ inst ?? (inst = {});
1561
+ inst._zod.def = def;
1562
+ inst._zod.bag = inst._zod.bag || {};
1563
+ inst._zod.version = version;
1564
+ const checks = [...inst._zod.def.checks ?? []];
1565
+ if (inst._zod.traits.has("$ZodCheck")) checks.unshift(inst);
1566
+ for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
1567
+ if (checks.length === 0) {
1568
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
1569
+ inst._zod.deferred?.push(() => {
1570
+ inst._zod.run = inst._zod.parse;
1571
+ });
1572
+ } else {
1573
+ const runChecks = (payload, checks, ctx) => {
1574
+ let isAborted = aborted(payload);
1575
+ let asyncResult;
1576
+ for (const ch of checks) {
1577
+ if (ch._zod.def.when) {
1578
+ if (explicitlyAborted(payload)) continue;
1579
+ if (!ch._zod.def.when(payload)) continue;
1580
+ } else if (isAborted) continue;
1581
+ const currLen = payload.issues.length;
1582
+ const _ = ch._zod.check(payload);
1583
+ if (_ instanceof Promise && ctx?.async === false) throw new $ZodAsyncError();
1584
+ if (asyncResult || _ instanceof Promise) asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
1585
+ await _;
1586
+ if (payload.issues.length === currLen) return;
1587
+ if (!isAborted) isAborted = aborted(payload, currLen);
1588
+ });
1589
+ else {
1590
+ if (payload.issues.length === currLen) continue;
1591
+ if (!isAborted) isAborted = aborted(payload, currLen);
1592
+ }
1593
+ }
1594
+ if (asyncResult) return asyncResult.then(() => {
1595
+ return payload;
1596
+ });
1597
+ return payload;
1598
+ };
1599
+ const handleCanaryResult = (canary, payload, ctx) => {
1600
+ if (aborted(canary)) {
1601
+ canary.aborted = true;
1602
+ return canary;
1603
+ }
1604
+ const checkResult = runChecks(payload, checks, ctx);
1605
+ if (checkResult instanceof Promise) {
1606
+ if (ctx.async === false) throw new $ZodAsyncError();
1607
+ return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
1608
+ }
1609
+ return inst._zod.parse(checkResult, ctx);
1610
+ };
1611
+ inst._zod.run = (payload, ctx) => {
1612
+ if (ctx.skipChecks) return inst._zod.parse(payload, ctx);
1613
+ if (ctx.direction === "backward") {
1614
+ const canary = inst._zod.parse({
1615
+ value: payload.value,
1616
+ issues: []
1617
+ }, {
1618
+ ...ctx,
1619
+ skipChecks: true
1620
+ });
1621
+ if (canary instanceof Promise) return canary.then((canary) => {
1622
+ return handleCanaryResult(canary, payload, ctx);
1623
+ });
1624
+ return handleCanaryResult(canary, payload, ctx);
1625
+ }
1626
+ const result = inst._zod.parse(payload, ctx);
1627
+ if (result instanceof Promise) {
1628
+ if (ctx.async === false) throw new $ZodAsyncError();
1629
+ return result.then((result) => runChecks(result, checks, ctx));
1630
+ }
1631
+ return runChecks(result, checks, ctx);
1632
+ };
1633
+ }
1634
+ defineLazy(inst, "~standard", () => ({
1635
+ validate: (value) => {
1636
+ try {
1637
+ const r = safeParse$1(inst, value);
1638
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
1639
+ } catch (_) {
1640
+ return safeParseAsync$1(inst, value).then((r) => r.success ? { value: r.data } : { issues: r.error?.issues });
1641
+ }
1642
+ },
1643
+ vendor: "zod",
1644
+ version: 1
1645
+ }));
1646
+ });
1647
+ const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
1648
+ $ZodType.init(inst, def);
1649
+ inst._zod.pattern = [...inst?._zod.bag?.patterns ?? []].pop() ?? string$1(inst._zod.bag);
1650
+ inst._zod.parse = (payload, _) => {
1651
+ if (def.coerce) try {
1652
+ payload.value = String(payload.value);
1653
+ } catch (_) {}
1654
+ if (typeof payload.value === "string") return payload;
1655
+ payload.issues.push({
1656
+ expected: "string",
1657
+ code: "invalid_type",
1658
+ input: payload.value,
1659
+ inst
1660
+ });
1661
+ return payload;
1662
+ };
1663
+ });
1664
+ const $ZodStringFormat = /*@__PURE__*/ $constructor("$ZodStringFormat", (inst, def) => {
1665
+ $ZodCheckStringFormat.init(inst, def);
1666
+ $ZodString.init(inst, def);
1667
+ });
1668
+ const $ZodGUID = /*@__PURE__*/ $constructor("$ZodGUID", (inst, def) => {
1669
+ def.pattern ?? (def.pattern = guid);
1670
+ $ZodStringFormat.init(inst, def);
1671
+ });
1672
+ const $ZodUUID = /*@__PURE__*/ $constructor("$ZodUUID", (inst, def) => {
1673
+ if (def.version) {
1674
+ const v = {
1675
+ v1: 1,
1676
+ v2: 2,
1677
+ v3: 3,
1678
+ v4: 4,
1679
+ v5: 5,
1680
+ v6: 6,
1681
+ v7: 7,
1682
+ v8: 8
1683
+ }[def.version];
1684
+ if (v === void 0) throw new Error(`Invalid UUID version: "${def.version}"`);
1685
+ def.pattern ?? (def.pattern = uuid(v));
1686
+ } else def.pattern ?? (def.pattern = uuid());
1687
+ $ZodStringFormat.init(inst, def);
1688
+ });
1689
+ const $ZodEmail = /*@__PURE__*/ $constructor("$ZodEmail", (inst, def) => {
1690
+ def.pattern ?? (def.pattern = email);
1691
+ $ZodStringFormat.init(inst, def);
1692
+ });
1693
+ const $ZodURL = /*@__PURE__*/ $constructor("$ZodURL", (inst, def) => {
1694
+ $ZodStringFormat.init(inst, def);
1695
+ inst._zod.check = (payload) => {
1696
+ try {
1697
+ const trimmed = payload.value.trim();
1698
+ if (!def.normalize && def.protocol?.source === httpProtocol.source) {
1699
+ if (!/^https?:\/\//i.test(trimmed)) {
1700
+ payload.issues.push({
1701
+ code: "invalid_format",
1702
+ format: "url",
1703
+ note: "Invalid URL format",
1704
+ input: payload.value,
1705
+ inst,
1706
+ continue: !def.abort
1707
+ });
1708
+ return;
1709
+ }
1710
+ }
1711
+ const url = new URL(trimmed);
1712
+ if (def.hostname) {
1713
+ def.hostname.lastIndex = 0;
1714
+ if (!def.hostname.test(url.hostname)) payload.issues.push({
1715
+ code: "invalid_format",
1716
+ format: "url",
1717
+ note: "Invalid hostname",
1718
+ pattern: def.hostname.source,
1719
+ input: payload.value,
1720
+ inst,
1721
+ continue: !def.abort
1722
+ });
1723
+ }
1724
+ if (def.protocol) {
1725
+ def.protocol.lastIndex = 0;
1726
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) payload.issues.push({
1727
+ code: "invalid_format",
1728
+ format: "url",
1729
+ note: "Invalid protocol",
1730
+ pattern: def.protocol.source,
1731
+ input: payload.value,
1732
+ inst,
1733
+ continue: !def.abort
1734
+ });
1735
+ }
1736
+ if (def.normalize) payload.value = url.href;
1737
+ else payload.value = trimmed;
1738
+ return;
1739
+ } catch (_) {
1740
+ payload.issues.push({
1741
+ code: "invalid_format",
1742
+ format: "url",
1743
+ input: payload.value,
1744
+ inst,
1745
+ continue: !def.abort
1746
+ });
1747
+ }
1748
+ };
1749
+ });
1750
+ const $ZodEmoji = /*@__PURE__*/ $constructor("$ZodEmoji", (inst, def) => {
1751
+ def.pattern ?? (def.pattern = emoji());
1752
+ $ZodStringFormat.init(inst, def);
1753
+ });
1754
+ const $ZodNanoID = /*@__PURE__*/ $constructor("$ZodNanoID", (inst, def) => {
1755
+ def.pattern ?? (def.pattern = nanoid);
1756
+ $ZodStringFormat.init(inst, def);
1757
+ });
1758
+ /**
1759
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
1760
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
1761
+ * See https://github.com/paralleldrive/cuid.
1762
+ */
1763
+ const $ZodCUID = /*@__PURE__*/ $constructor("$ZodCUID", (inst, def) => {
1764
+ def.pattern ?? (def.pattern = cuid);
1765
+ $ZodStringFormat.init(inst, def);
1766
+ });
1767
+ const $ZodCUID2 = /*@__PURE__*/ $constructor("$ZodCUID2", (inst, def) => {
1768
+ def.pattern ?? (def.pattern = cuid2);
1769
+ $ZodStringFormat.init(inst, def);
1770
+ });
1771
+ const $ZodULID = /*@__PURE__*/ $constructor("$ZodULID", (inst, def) => {
1772
+ def.pattern ?? (def.pattern = ulid);
1773
+ $ZodStringFormat.init(inst, def);
1774
+ });
1775
+ const $ZodXID = /*@__PURE__*/ $constructor("$ZodXID", (inst, def) => {
1776
+ def.pattern ?? (def.pattern = xid);
1777
+ $ZodStringFormat.init(inst, def);
1778
+ });
1779
+ const $ZodKSUID = /*@__PURE__*/ $constructor("$ZodKSUID", (inst, def) => {
1780
+ def.pattern ?? (def.pattern = ksuid);
1781
+ $ZodStringFormat.init(inst, def);
1782
+ });
1783
+ const $ZodISODateTime = /*@__PURE__*/ $constructor("$ZodISODateTime", (inst, def) => {
1784
+ def.pattern ?? (def.pattern = datetime$1(def));
1785
+ $ZodStringFormat.init(inst, def);
1786
+ });
1787
+ const $ZodISODate = /*@__PURE__*/ $constructor("$ZodISODate", (inst, def) => {
1788
+ def.pattern ?? (def.pattern = date$1);
1789
+ $ZodStringFormat.init(inst, def);
1790
+ });
1791
+ const $ZodISOTime = /*@__PURE__*/ $constructor("$ZodISOTime", (inst, def) => {
1792
+ def.pattern ?? (def.pattern = time$1(def));
1793
+ $ZodStringFormat.init(inst, def);
1794
+ });
1795
+ const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def) => {
1796
+ def.pattern ?? (def.pattern = duration$1);
1797
+ $ZodStringFormat.init(inst, def);
1798
+ });
1799
+ const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def) => {
1800
+ def.pattern ?? (def.pattern = ipv4);
1801
+ $ZodStringFormat.init(inst, def);
1802
+ inst._zod.bag.format = `ipv4`;
1803
+ });
1804
+ const $ZodIPv6 = /*@__PURE__*/ $constructor("$ZodIPv6", (inst, def) => {
1805
+ def.pattern ?? (def.pattern = ipv6);
1806
+ $ZodStringFormat.init(inst, def);
1807
+ inst._zod.bag.format = `ipv6`;
1808
+ inst._zod.check = (payload) => {
1809
+ try {
1810
+ new URL(`http://[${payload.value}]`);
1811
+ } catch {
1812
+ payload.issues.push({
1813
+ code: "invalid_format",
1814
+ format: "ipv6",
1815
+ input: payload.value,
1816
+ inst,
1817
+ continue: !def.abort
1818
+ });
1819
+ }
1820
+ };
1821
+ });
1822
+ const $ZodCIDRv4 = /*@__PURE__*/ $constructor("$ZodCIDRv4", (inst, def) => {
1823
+ def.pattern ?? (def.pattern = cidrv4);
1824
+ $ZodStringFormat.init(inst, def);
1825
+ });
1826
+ const $ZodCIDRv6 = /*@__PURE__*/ $constructor("$ZodCIDRv6", (inst, def) => {
1827
+ def.pattern ?? (def.pattern = cidrv6);
1828
+ $ZodStringFormat.init(inst, def);
1829
+ inst._zod.check = (payload) => {
1830
+ const parts = payload.value.split("/");
1831
+ try {
1832
+ if (parts.length !== 2) throw new Error();
1833
+ const [address, prefix] = parts;
1834
+ if (!prefix) throw new Error();
1835
+ const prefixNum = Number(prefix);
1836
+ if (`${prefixNum}` !== prefix) throw new Error();
1837
+ if (prefixNum < 0 || prefixNum > 128) throw new Error();
1838
+ new URL(`http://[${address}]`);
1839
+ } catch {
1840
+ payload.issues.push({
1841
+ code: "invalid_format",
1842
+ format: "cidrv6",
1843
+ input: payload.value,
1844
+ inst,
1845
+ continue: !def.abort
1846
+ });
1847
+ }
1848
+ };
1849
+ });
1850
+ function isValidBase64(data) {
1851
+ if (data === "") return true;
1852
+ if (/\s/.test(data)) return false;
1853
+ if (data.length % 4 !== 0) return false;
1854
+ try {
1855
+ atob(data);
1856
+ return true;
1857
+ } catch {
1858
+ return false;
1859
+ }
1860
+ }
1861
+ const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def) => {
1862
+ def.pattern ?? (def.pattern = base64);
1863
+ $ZodStringFormat.init(inst, def);
1864
+ inst._zod.bag.contentEncoding = "base64";
1865
+ inst._zod.check = (payload) => {
1866
+ if (isValidBase64(payload.value)) return;
1867
+ payload.issues.push({
1868
+ code: "invalid_format",
1869
+ format: "base64",
1870
+ input: payload.value,
1871
+ inst,
1872
+ continue: !def.abort
1873
+ });
1874
+ };
1875
+ });
1876
+ function isValidBase64URL(data) {
1877
+ if (!base64url.test(data)) return false;
1878
+ const base64 = data.replace(/[-_]/g, (c) => c === "-" ? "+" : "/");
1879
+ return isValidBase64(base64.padEnd(Math.ceil(base64.length / 4) * 4, "="));
1880
+ }
1881
+ const $ZodBase64URL = /*@__PURE__*/ $constructor("$ZodBase64URL", (inst, def) => {
1882
+ def.pattern ?? (def.pattern = base64url);
1883
+ $ZodStringFormat.init(inst, def);
1884
+ inst._zod.bag.contentEncoding = "base64url";
1885
+ inst._zod.check = (payload) => {
1886
+ if (isValidBase64URL(payload.value)) return;
1887
+ payload.issues.push({
1888
+ code: "invalid_format",
1889
+ format: "base64url",
1890
+ input: payload.value,
1891
+ inst,
1892
+ continue: !def.abort
1893
+ });
1894
+ };
1895
+ });
1896
+ const $ZodE164 = /*@__PURE__*/ $constructor("$ZodE164", (inst, def) => {
1897
+ def.pattern ?? (def.pattern = e164);
1898
+ $ZodStringFormat.init(inst, def);
1899
+ });
1900
+ function isValidJWT(token, algorithm = null) {
1901
+ try {
1902
+ const tokensParts = token.split(".");
1903
+ if (tokensParts.length !== 3) return false;
1904
+ const [header] = tokensParts;
1905
+ if (!header) return false;
1906
+ const parsedHeader = JSON.parse(atob(header));
1907
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT") return false;
1908
+ if (!parsedHeader.alg) return false;
1909
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm)) return false;
1910
+ return true;
1911
+ } catch {
1912
+ return false;
1913
+ }
1914
+ }
1915
+ const $ZodJWT = /*@__PURE__*/ $constructor("$ZodJWT", (inst, def) => {
1916
+ $ZodStringFormat.init(inst, def);
1917
+ inst._zod.check = (payload) => {
1918
+ if (isValidJWT(payload.value, def.alg)) return;
1919
+ payload.issues.push({
1920
+ code: "invalid_format",
1921
+ format: "jwt",
1922
+ input: payload.value,
1923
+ inst,
1924
+ continue: !def.abort
1925
+ });
1926
+ };
1927
+ });
1928
+ const $ZodBoolean = /*@__PURE__*/ $constructor("$ZodBoolean", (inst, def) => {
1929
+ $ZodType.init(inst, def);
1930
+ inst._zod.pattern = boolean$1;
1931
+ inst._zod.parse = (payload, _ctx) => {
1932
+ if (def.coerce) try {
1933
+ payload.value = Boolean(payload.value);
1934
+ } catch (_) {}
1935
+ const input = payload.value;
1936
+ if (typeof input === "boolean") return payload;
1937
+ payload.issues.push({
1938
+ expected: "boolean",
1939
+ code: "invalid_type",
1940
+ input,
1941
+ inst
1942
+ });
1943
+ return payload;
1944
+ };
1945
+ });
1946
+ const $ZodUnknown = /*@__PURE__*/ $constructor("$ZodUnknown", (inst, def) => {
1947
+ $ZodType.init(inst, def);
1948
+ inst._zod.parse = (payload) => payload;
1949
+ });
1950
+ const $ZodNever = /*@__PURE__*/ $constructor("$ZodNever", (inst, def) => {
1951
+ $ZodType.init(inst, def);
1952
+ inst._zod.parse = (payload, _ctx) => {
1953
+ payload.issues.push({
1954
+ expected: "never",
1955
+ code: "invalid_type",
1956
+ input: payload.value,
1957
+ inst
1958
+ });
1959
+ return payload;
1960
+ };
1961
+ });
1962
+ function handleArrayResult(result, final, index) {
1963
+ if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
1964
+ final.value[index] = result.value;
1965
+ }
1966
+ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
1967
+ $ZodType.init(inst, def);
1968
+ inst._zod.parse = (payload, ctx) => {
1969
+ const input = payload.value;
1970
+ if (!Array.isArray(input)) {
1971
+ payload.issues.push({
1972
+ expected: "array",
1973
+ code: "invalid_type",
1974
+ input,
1975
+ inst
1976
+ });
1977
+ return payload;
1978
+ }
1979
+ payload.value = Array(input.length);
1980
+ const proms = [];
1981
+ for (let i = 0; i < input.length; i++) {
1982
+ const item = input[i];
1983
+ const result = def.element._zod.run({
1984
+ value: item,
1985
+ issues: []
1986
+ }, ctx);
1987
+ if (result instanceof Promise) proms.push(result.then((result) => handleArrayResult(result, payload, i)));
1988
+ else handleArrayResult(result, payload, i);
1989
+ }
1990
+ if (proms.length) return Promise.all(proms).then(() => payload);
1991
+ return payload;
1992
+ };
1993
+ });
1994
+ function handlePropertyResult(result, final, key, input, isOptionalIn, isOptionalOut) {
1995
+ const isPresent = key in input;
1996
+ if (result.issues.length) {
1997
+ if (isOptionalIn && isOptionalOut && !isPresent) return;
1998
+ final.issues.push(...prefixIssues(key, result.issues));
1999
+ }
2000
+ if (!isPresent && !isOptionalIn) {
2001
+ if (!result.issues.length) final.issues.push({
2002
+ code: "invalid_type",
2003
+ expected: "nonoptional",
2004
+ input: void 0,
2005
+ path: [key]
2006
+ });
2007
+ return;
2008
+ }
2009
+ if (result.value === void 0) {
2010
+ if (isPresent) final.value[key] = void 0;
2011
+ } else final.value[key] = result.value;
2012
+ }
2013
+ function normalizeDef(def) {
2014
+ const keys = Object.keys(def.shape);
2015
+ for (const k of keys) if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
2016
+ const okeys = optionalKeys(def.shape);
2017
+ return {
2018
+ ...def,
2019
+ keys,
2020
+ keySet: new Set(keys),
2021
+ numKeys: keys.length,
2022
+ optionalKeys: new Set(okeys)
2023
+ };
2024
+ }
2025
+ function handleCatchall(proms, input, payload, ctx, def, inst) {
2026
+ const unrecognized = [];
2027
+ const keySet = def.keySet;
2028
+ const _catchall = def.catchall._zod;
2029
+ const t = _catchall.def.type;
2030
+ const isOptionalIn = _catchall.optin === "optional";
2031
+ const isOptionalOut = _catchall.optout === "optional";
2032
+ for (const key in input) {
2033
+ if (key === "__proto__") continue;
2034
+ if (keySet.has(key)) continue;
2035
+ if (t === "never") {
2036
+ unrecognized.push(key);
2037
+ continue;
2038
+ }
2039
+ const r = _catchall.run({
2040
+ value: input[key],
2041
+ issues: []
2042
+ }, ctx);
2043
+ if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut)));
2044
+ else handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut);
2045
+ }
2046
+ if (unrecognized.length) payload.issues.push({
2047
+ code: "unrecognized_keys",
2048
+ keys: unrecognized,
2049
+ input,
2050
+ inst
2051
+ });
2052
+ if (!proms.length) return payload;
2053
+ return Promise.all(proms).then(() => {
2054
+ return payload;
2055
+ });
2056
+ }
2057
+ const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
2058
+ $ZodType.init(inst, def);
2059
+ if (!Object.getOwnPropertyDescriptor(def, "shape")?.get) {
2060
+ const sh = def.shape;
2061
+ Object.defineProperty(def, "shape", { get: () => {
2062
+ const newSh = { ...sh };
2063
+ Object.defineProperty(def, "shape", { value: newSh });
2064
+ return newSh;
2065
+ } });
2066
+ }
2067
+ const _normalized = cached(() => normalizeDef(def));
2068
+ defineLazy(inst._zod, "propValues", () => {
2069
+ const shape = def.shape;
2070
+ const propValues = {};
2071
+ for (const key in shape) {
2072
+ const field = shape[key]._zod;
2073
+ if (field.values) {
2074
+ propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
2075
+ for (const v of field.values) propValues[key].add(v);
2076
+ }
2077
+ }
2078
+ return propValues;
2079
+ });
2080
+ const isObject$1 = isObject;
2081
+ const catchall = def.catchall;
2082
+ let value;
2083
+ inst._zod.parse = (payload, ctx) => {
2084
+ value ?? (value = _normalized.value);
2085
+ const input = payload.value;
2086
+ if (!isObject$1(input)) {
2087
+ payload.issues.push({
2088
+ expected: "object",
2089
+ code: "invalid_type",
2090
+ input,
2091
+ inst
2092
+ });
2093
+ return payload;
2094
+ }
2095
+ payload.value = {};
2096
+ const proms = [];
2097
+ const shape = value.shape;
2098
+ for (const key of value.keys) {
2099
+ const el = shape[key];
2100
+ const isOptionalIn = el._zod.optin === "optional";
2101
+ const isOptionalOut = el._zod.optout === "optional";
2102
+ const r = el._zod.run({
2103
+ value: input[key],
2104
+ issues: []
2105
+ }, ctx);
2106
+ if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut)));
2107
+ else handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut);
2108
+ }
2109
+ if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
2110
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
2111
+ };
2112
+ });
2113
+ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) => {
2114
+ $ZodObject.init(inst, def);
2115
+ const superParse = inst._zod.parse;
2116
+ const _normalized = cached(() => normalizeDef(def));
2117
+ const generateFastpass = (shape) => {
2118
+ const doc = new Doc([
2119
+ "shape",
2120
+ "payload",
2121
+ "ctx"
2122
+ ]);
2123
+ const normalized = _normalized.value;
2124
+ const parseStr = (key) => {
2125
+ const k = esc(key);
2126
+ return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
2127
+ };
2128
+ doc.write(`const input = payload.value;`);
2129
+ const ids = Object.create(null);
2130
+ let counter = 0;
2131
+ for (const key of normalized.keys) ids[key] = `key_${counter++}`;
2132
+ doc.write(`const newResult = {};`);
2133
+ for (const key of normalized.keys) {
2134
+ const id = ids[key];
2135
+ const k = esc(key);
2136
+ const schema = shape[key];
2137
+ const isOptionalIn = schema?._zod?.optin === "optional";
2138
+ const isOptionalOut = schema?._zod?.optout === "optional";
2139
+ doc.write(`const ${id} = ${parseStr(key)};`);
2140
+ if (isOptionalIn && isOptionalOut) doc.write(`
2141
+ if (${id}.issues.length) {
2142
+ if (${k} in input) {
2143
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
2144
+ ...iss,
2145
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
2146
+ })));
2147
+ }
2148
+ }
2149
+
2150
+ if (${id}.value === undefined) {
2151
+ if (${k} in input) {
2152
+ newResult[${k}] = undefined;
2153
+ }
2154
+ } else {
2155
+ newResult[${k}] = ${id}.value;
2156
+ }
2157
+
2158
+ `);
2159
+ else if (!isOptionalIn) doc.write(`
2160
+ const ${id}_present = ${k} in input;
2161
+ if (${id}.issues.length) {
2162
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
2163
+ ...iss,
2164
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
2165
+ })));
2166
+ }
2167
+ if (!${id}_present && !${id}.issues.length) {
2168
+ payload.issues.push({
2169
+ code: "invalid_type",
2170
+ expected: "nonoptional",
2171
+ input: undefined,
2172
+ path: [${k}]
2173
+ });
2174
+ }
2175
+
2176
+ if (${id}_present) {
2177
+ if (${id}.value === undefined) {
2178
+ newResult[${k}] = undefined;
2179
+ } else {
2180
+ newResult[${k}] = ${id}.value;
2181
+ }
2182
+ }
2183
+
2184
+ `);
2185
+ else doc.write(`
2186
+ if (${id}.issues.length) {
2187
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
2188
+ ...iss,
2189
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
2190
+ })));
2191
+ }
2192
+
2193
+ if (${id}.value === undefined) {
2194
+ if (${k} in input) {
2195
+ newResult[${k}] = undefined;
2196
+ }
2197
+ } else {
2198
+ newResult[${k}] = ${id}.value;
2199
+ }
2200
+
2201
+ `);
2202
+ }
2203
+ doc.write(`payload.value = newResult;`);
2204
+ doc.write(`return payload;`);
2205
+ const fn = doc.compile();
2206
+ return (payload, ctx) => fn(shape, payload, ctx);
2207
+ };
2208
+ let fastpass;
2209
+ const isObject$2 = isObject;
2210
+ const jit = !globalConfig.jitless;
2211
+ const fastEnabled = jit && allowsEval.value;
2212
+ const catchall = def.catchall;
2213
+ let value;
2214
+ inst._zod.parse = (payload, ctx) => {
2215
+ value ?? (value = _normalized.value);
2216
+ const input = payload.value;
2217
+ if (!isObject$2(input)) {
2218
+ payload.issues.push({
2219
+ expected: "object",
2220
+ code: "invalid_type",
2221
+ input,
2222
+ inst
2223
+ });
2224
+ return payload;
2225
+ }
2226
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
2227
+ if (!fastpass) fastpass = generateFastpass(def.shape);
2228
+ payload = fastpass(payload, ctx);
2229
+ if (!catchall) return payload;
2230
+ return handleCatchall([], input, payload, ctx, value, inst);
2231
+ }
2232
+ return superParse(payload, ctx);
2233
+ };
2234
+ });
2235
+ function handleUnionResults(results, final, inst, ctx) {
2236
+ for (const result of results) if (result.issues.length === 0) {
2237
+ final.value = result.value;
2238
+ return final;
2239
+ }
2240
+ const nonaborted = results.filter((r) => !aborted(r));
2241
+ if (nonaborted.length === 1) {
2242
+ final.value = nonaborted[0].value;
2243
+ return nonaborted[0];
2244
+ }
2245
+ final.issues.push({
2246
+ code: "invalid_union",
2247
+ input: final.value,
2248
+ inst,
2249
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
2250
+ });
2251
+ return final;
2252
+ }
2253
+ const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
2254
+ $ZodType.init(inst, def);
2255
+ defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0);
2256
+ defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
2257
+ defineLazy(inst._zod, "values", () => {
2258
+ if (def.options.every((o) => o._zod.values)) return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
2259
+ });
2260
+ defineLazy(inst._zod, "pattern", () => {
2261
+ if (def.options.every((o) => o._zod.pattern)) {
2262
+ const patterns = def.options.map((o) => o._zod.pattern);
2263
+ return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
2264
+ }
2265
+ });
2266
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
2267
+ inst._zod.parse = (payload, ctx) => {
2268
+ if (first) return first(payload, ctx);
2269
+ let async = false;
2270
+ const results = [];
2271
+ for (const option of def.options) {
2272
+ const result = option._zod.run({
2273
+ value: payload.value,
2274
+ issues: []
2275
+ }, ctx);
2276
+ if (result instanceof Promise) {
2277
+ results.push(result);
2278
+ async = true;
2279
+ } else {
2280
+ if (result.issues.length === 0) return result;
2281
+ results.push(result);
2282
+ }
2283
+ }
2284
+ if (!async) return handleUnionResults(results, payload, inst, ctx);
2285
+ return Promise.all(results).then((results) => {
2286
+ return handleUnionResults(results, payload, inst, ctx);
2287
+ });
2288
+ };
2289
+ });
2290
+ const $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
2291
+ $ZodType.init(inst, def);
2292
+ inst._zod.parse = (payload, ctx) => {
2293
+ const input = payload.value;
2294
+ const left = def.left._zod.run({
2295
+ value: input,
2296
+ issues: []
2297
+ }, ctx);
2298
+ const right = def.right._zod.run({
2299
+ value: input,
2300
+ issues: []
2301
+ }, ctx);
2302
+ if (left instanceof Promise || right instanceof Promise) return Promise.all([left, right]).then(([left, right]) => {
2303
+ return handleIntersectionResults(payload, left, right);
2304
+ });
2305
+ return handleIntersectionResults(payload, left, right);
2306
+ };
2307
+ });
2308
+ function mergeValues(a, b) {
2309
+ if (a === b) return {
2310
+ valid: true,
2311
+ data: a
2312
+ };
2313
+ if (a instanceof Date && b instanceof Date && +a === +b) return {
2314
+ valid: true,
2315
+ data: a
2316
+ };
2317
+ if (isPlainObject(a) && isPlainObject(b)) {
2318
+ const bKeys = Object.keys(b);
2319
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
2320
+ const newObj = {
2321
+ ...a,
2322
+ ...b
2323
+ };
2324
+ for (const key of sharedKeys) {
2325
+ const sharedValue = mergeValues(a[key], b[key]);
2326
+ if (!sharedValue.valid) return {
2327
+ valid: false,
2328
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
2329
+ };
2330
+ newObj[key] = sharedValue.data;
2331
+ }
2332
+ return {
2333
+ valid: true,
2334
+ data: newObj
2335
+ };
2336
+ }
2337
+ if (Array.isArray(a) && Array.isArray(b)) {
2338
+ if (a.length !== b.length) return {
2339
+ valid: false,
2340
+ mergeErrorPath: []
2341
+ };
2342
+ const newArray = [];
2343
+ for (let index = 0; index < a.length; index++) {
2344
+ const itemA = a[index];
2345
+ const itemB = b[index];
2346
+ const sharedValue = mergeValues(itemA, itemB);
2347
+ if (!sharedValue.valid) return {
2348
+ valid: false,
2349
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
2350
+ };
2351
+ newArray.push(sharedValue.data);
2352
+ }
2353
+ return {
2354
+ valid: true,
2355
+ data: newArray
2356
+ };
2357
+ }
2358
+ return {
2359
+ valid: false,
2360
+ mergeErrorPath: []
2361
+ };
2362
+ }
2363
+ function handleIntersectionResults(result, left, right) {
2364
+ const unrecKeys = /* @__PURE__ */ new Map();
2365
+ let unrecIssue;
2366
+ for (const iss of left.issues) if (iss.code === "unrecognized_keys") {
2367
+ unrecIssue ?? (unrecIssue = iss);
2368
+ for (const k of iss.keys) {
2369
+ if (!unrecKeys.has(k)) unrecKeys.set(k, {});
2370
+ unrecKeys.get(k).l = true;
2371
+ }
2372
+ } else result.issues.push(iss);
2373
+ for (const iss of right.issues) if (iss.code === "unrecognized_keys") for (const k of iss.keys) {
2374
+ if (!unrecKeys.has(k)) unrecKeys.set(k, {});
2375
+ unrecKeys.get(k).r = true;
2376
+ }
2377
+ else result.issues.push(iss);
2378
+ const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
2379
+ if (bothKeys.length && unrecIssue) result.issues.push({
2380
+ ...unrecIssue,
2381
+ keys: bothKeys
2382
+ });
2383
+ if (aborted(result)) return result;
2384
+ const merged = mergeValues(left.value, right.value);
2385
+ if (!merged.valid) throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
2386
+ result.value = merged.data;
2387
+ return result;
2388
+ }
2389
+ const $ZodEnum = /*@__PURE__*/ $constructor("$ZodEnum", (inst, def) => {
2390
+ $ZodType.init(inst, def);
2391
+ const values = getEnumValues(def.entries);
2392
+ const valuesSet = new Set(values);
2393
+ inst._zod.values = valuesSet;
2394
+ inst._zod.pattern = new RegExp(`^(${values.filter((k) => propertyKeyTypes.has(typeof k)).map((o) => typeof o === "string" ? escapeRegex(o) : o.toString()).join("|")})$`);
2395
+ inst._zod.parse = (payload, _ctx) => {
2396
+ const input = payload.value;
2397
+ if (valuesSet.has(input)) return payload;
2398
+ payload.issues.push({
2399
+ code: "invalid_value",
2400
+ values,
2401
+ input,
2402
+ inst
2403
+ });
2404
+ return payload;
2405
+ };
2406
+ });
2407
+ const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def) => {
2408
+ $ZodType.init(inst, def);
2409
+ inst._zod.optin = "optional";
2410
+ inst._zod.parse = (payload, ctx) => {
2411
+ if (ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
2412
+ const _out = def.transform(payload.value, payload);
2413
+ if (ctx.async) return (_out instanceof Promise ? _out : Promise.resolve(_out)).then((output) => {
2414
+ payload.value = output;
2415
+ payload.fallback = true;
2416
+ return payload;
2417
+ });
2418
+ if (_out instanceof Promise) throw new $ZodAsyncError();
2419
+ payload.value = _out;
2420
+ payload.fallback = true;
2421
+ return payload;
2422
+ };
2423
+ });
2424
+ function handleOptionalResult(result, input) {
2425
+ if (input === void 0 && (result.issues.length || result.fallback)) return {
2426
+ issues: [],
2427
+ value: void 0
2428
+ };
2429
+ return result;
2430
+ }
2431
+ const $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def) => {
2432
+ $ZodType.init(inst, def);
2433
+ inst._zod.optin = "optional";
2434
+ inst._zod.optout = "optional";
2435
+ defineLazy(inst._zod, "values", () => {
2436
+ return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, void 0]) : void 0;
2437
+ });
2438
+ defineLazy(inst._zod, "pattern", () => {
2439
+ const pattern = def.innerType._zod.pattern;
2440
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
2441
+ });
2442
+ inst._zod.parse = (payload, ctx) => {
2443
+ if (def.innerType._zod.optin === "optional") {
2444
+ const input = payload.value;
2445
+ const result = def.innerType._zod.run(payload, ctx);
2446
+ if (result instanceof Promise) return result.then((r) => handleOptionalResult(r, input));
2447
+ return handleOptionalResult(result, input);
2448
+ }
2449
+ if (payload.value === void 0) return payload;
2450
+ return def.innerType._zod.run(payload, ctx);
2451
+ };
2452
+ });
2453
+ const $ZodExactOptional = /*@__PURE__*/ $constructor("$ZodExactOptional", (inst, def) => {
2454
+ $ZodOptional.init(inst, def);
2455
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2456
+ defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
2457
+ inst._zod.parse = (payload, ctx) => {
2458
+ return def.innerType._zod.run(payload, ctx);
2459
+ };
2460
+ });
2461
+ const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def) => {
2462
+ $ZodType.init(inst, def);
2463
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
2464
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
2465
+ defineLazy(inst._zod, "pattern", () => {
2466
+ const pattern = def.innerType._zod.pattern;
2467
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
2468
+ });
2469
+ defineLazy(inst._zod, "values", () => {
2470
+ return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, null]) : void 0;
2471
+ });
2472
+ inst._zod.parse = (payload, ctx) => {
2473
+ if (payload.value === null) return payload;
2474
+ return def.innerType._zod.run(payload, ctx);
2475
+ };
2476
+ });
2477
+ const $ZodDefault = /*@__PURE__*/ $constructor("$ZodDefault", (inst, def) => {
2478
+ $ZodType.init(inst, def);
2479
+ inst._zod.optin = "optional";
2480
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2481
+ inst._zod.parse = (payload, ctx) => {
2482
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
2483
+ if (payload.value === void 0) {
2484
+ payload.value = def.defaultValue;
2485
+ /**
2486
+ * $ZodDefault returns the default value immediately in forward direction.
2487
+ * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
2488
+ return payload;
2489
+ }
2490
+ const result = def.innerType._zod.run(payload, ctx);
2491
+ if (result instanceof Promise) return result.then((result) => handleDefaultResult(result, def));
2492
+ return handleDefaultResult(result, def);
2493
+ };
2494
+ });
2495
+ function handleDefaultResult(payload, def) {
2496
+ if (payload.value === void 0) payload.value = def.defaultValue;
2497
+ return payload;
2498
+ }
2499
+ const $ZodPrefault = /*@__PURE__*/ $constructor("$ZodPrefault", (inst, def) => {
2500
+ $ZodType.init(inst, def);
2501
+ inst._zod.optin = "optional";
2502
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2503
+ inst._zod.parse = (payload, ctx) => {
2504
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
2505
+ if (payload.value === void 0) payload.value = def.defaultValue;
2506
+ return def.innerType._zod.run(payload, ctx);
2507
+ };
2508
+ });
2509
+ const $ZodNonOptional = /*@__PURE__*/ $constructor("$ZodNonOptional", (inst, def) => {
2510
+ $ZodType.init(inst, def);
2511
+ defineLazy(inst._zod, "values", () => {
2512
+ const v = def.innerType._zod.values;
2513
+ return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
2514
+ });
2515
+ inst._zod.parse = (payload, ctx) => {
2516
+ const result = def.innerType._zod.run(payload, ctx);
2517
+ if (result instanceof Promise) return result.then((result) => handleNonOptionalResult(result, inst));
2518
+ return handleNonOptionalResult(result, inst);
2519
+ };
2520
+ });
2521
+ function handleNonOptionalResult(payload, inst) {
2522
+ if (!payload.issues.length && payload.value === void 0) payload.issues.push({
2523
+ code: "invalid_type",
2524
+ expected: "nonoptional",
2525
+ input: payload.value,
2526
+ inst
2527
+ });
2528
+ return payload;
2529
+ }
2530
+ const $ZodCatch = /*@__PURE__*/ $constructor("$ZodCatch", (inst, def) => {
2531
+ $ZodType.init(inst, def);
2532
+ inst._zod.optin = "optional";
2533
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
2534
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2535
+ inst._zod.parse = (payload, ctx) => {
2536
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
2537
+ const result = def.innerType._zod.run(payload, ctx);
2538
+ if (result instanceof Promise) return result.then((result) => {
2539
+ payload.value = result.value;
2540
+ if (result.issues.length) {
2541
+ payload.value = def.catchValue({
2542
+ ...payload,
2543
+ error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
2544
+ input: payload.value
2545
+ });
2546
+ payload.issues = [];
2547
+ payload.fallback = true;
2548
+ }
2549
+ return payload;
2550
+ });
2551
+ payload.value = result.value;
2552
+ if (result.issues.length) {
2553
+ payload.value = def.catchValue({
2554
+ ...payload,
2555
+ error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
2556
+ input: payload.value
2557
+ });
2558
+ payload.issues = [];
2559
+ payload.fallback = true;
2560
+ }
2561
+ return payload;
2562
+ };
2563
+ });
2564
+ const $ZodPipe = /*@__PURE__*/ $constructor("$ZodPipe", (inst, def) => {
2565
+ $ZodType.init(inst, def);
2566
+ defineLazy(inst._zod, "values", () => def.in._zod.values);
2567
+ defineLazy(inst._zod, "optin", () => def.in._zod.optin);
2568
+ defineLazy(inst._zod, "optout", () => def.out._zod.optout);
2569
+ defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
2570
+ inst._zod.parse = (payload, ctx) => {
2571
+ if (ctx.direction === "backward") {
2572
+ const right = def.out._zod.run(payload, ctx);
2573
+ if (right instanceof Promise) return right.then((right) => handlePipeResult(right, def.in, ctx));
2574
+ return handlePipeResult(right, def.in, ctx);
2575
+ }
2576
+ const left = def.in._zod.run(payload, ctx);
2577
+ if (left instanceof Promise) return left.then((left) => handlePipeResult(left, def.out, ctx));
2578
+ return handlePipeResult(left, def.out, ctx);
2579
+ };
2580
+ });
2581
+ function handlePipeResult(left, next, ctx) {
2582
+ if (left.issues.length) {
2583
+ left.aborted = true;
2584
+ return left;
2585
+ }
2586
+ return next._zod.run({
2587
+ value: left.value,
2588
+ issues: left.issues,
2589
+ fallback: left.fallback
2590
+ }, ctx);
2591
+ }
2592
+ const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
2593
+ $ZodType.init(inst, def);
2594
+ defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
2595
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2596
+ defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
2597
+ defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
2598
+ inst._zod.parse = (payload, ctx) => {
2599
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
2600
+ const result = def.innerType._zod.run(payload, ctx);
2601
+ if (result instanceof Promise) return result.then(handleReadonlyResult);
2602
+ return handleReadonlyResult(result);
2603
+ };
2604
+ });
2605
+ function handleReadonlyResult(payload) {
2606
+ payload.value = Object.freeze(payload.value);
2607
+ return payload;
2608
+ }
2609
+ const $ZodCustom = /*@__PURE__*/ $constructor("$ZodCustom", (inst, def) => {
2610
+ $ZodCheck.init(inst, def);
2611
+ $ZodType.init(inst, def);
2612
+ inst._zod.parse = (payload, _) => {
2613
+ return payload;
2614
+ };
2615
+ inst._zod.check = (payload) => {
2616
+ const input = payload.value;
2617
+ const r = def.fn(input);
2618
+ if (r instanceof Promise) return r.then((r) => handleRefineResult(r, payload, input, inst));
2619
+ handleRefineResult(r, payload, input, inst);
2620
+ };
2621
+ });
2622
+ function handleRefineResult(result, payload, input, inst) {
2623
+ if (!result) {
2624
+ const _iss = {
2625
+ code: "custom",
2626
+ input,
2627
+ inst,
2628
+ path: [...inst._zod.def.path ?? []],
2629
+ continue: !inst._zod.def.abort
2630
+ };
2631
+ if (inst._zod.def.params) _iss.params = inst._zod.def.params;
2632
+ payload.issues.push(issue(_iss));
2633
+ }
2634
+ }
2635
+ //#endregion
2636
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/registries.js
2637
+ var _a;
2638
+ var $ZodRegistry = class {
2639
+ constructor() {
2640
+ this._map = /* @__PURE__ */ new WeakMap();
2641
+ this._idmap = /* @__PURE__ */ new Map();
2642
+ }
2643
+ add(schema, ..._meta) {
2644
+ const meta = _meta[0];
2645
+ this._map.set(schema, meta);
2646
+ if (meta && typeof meta === "object" && "id" in meta) this._idmap.set(meta.id, schema);
2647
+ return this;
2648
+ }
2649
+ clear() {
2650
+ this._map = /* @__PURE__ */ new WeakMap();
2651
+ this._idmap = /* @__PURE__ */ new Map();
2652
+ return this;
2653
+ }
2654
+ remove(schema) {
2655
+ const meta = this._map.get(schema);
2656
+ if (meta && typeof meta === "object" && "id" in meta) this._idmap.delete(meta.id);
2657
+ this._map.delete(schema);
2658
+ return this;
2659
+ }
2660
+ get(schema) {
2661
+ const p = schema._zod.parent;
2662
+ if (p) {
2663
+ const pm = { ...this.get(p) ?? {} };
2664
+ delete pm.id;
2665
+ const f = {
2666
+ ...pm,
2667
+ ...this._map.get(schema)
2668
+ };
2669
+ return Object.keys(f).length ? f : void 0;
2670
+ }
2671
+ return this._map.get(schema);
2672
+ }
2673
+ has(schema) {
2674
+ return this._map.has(schema);
2675
+ }
2676
+ };
2677
+ function registry() {
2678
+ return new $ZodRegistry();
2679
+ }
2680
+ (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
2681
+ const globalRegistry = globalThis.__zod_globalRegistry;
2682
+ //#endregion
2683
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/api.js
2684
+ // @__NO_SIDE_EFFECTS__
2685
+ function _string(Class, params) {
2686
+ return new Class({
2687
+ type: "string",
2688
+ ...normalizeParams(params)
2689
+ });
2690
+ }
2691
+ // @__NO_SIDE_EFFECTS__
2692
+ function _email(Class, params) {
2693
+ return new Class({
2694
+ type: "string",
2695
+ format: "email",
2696
+ check: "string_format",
2697
+ abort: false,
2698
+ ...normalizeParams(params)
2699
+ });
2700
+ }
2701
+ // @__NO_SIDE_EFFECTS__
2702
+ function _guid(Class, params) {
2703
+ return new Class({
2704
+ type: "string",
2705
+ format: "guid",
2706
+ check: "string_format",
2707
+ abort: false,
2708
+ ...normalizeParams(params)
2709
+ });
2710
+ }
2711
+ // @__NO_SIDE_EFFECTS__
2712
+ function _uuid(Class, params) {
2713
+ return new Class({
2714
+ type: "string",
2715
+ format: "uuid",
2716
+ check: "string_format",
2717
+ abort: false,
2718
+ ...normalizeParams(params)
2719
+ });
2720
+ }
2721
+ // @__NO_SIDE_EFFECTS__
2722
+ function _uuidv4(Class, params) {
2723
+ return new Class({
2724
+ type: "string",
2725
+ format: "uuid",
2726
+ check: "string_format",
2727
+ abort: false,
2728
+ version: "v4",
2729
+ ...normalizeParams(params)
2730
+ });
2731
+ }
2732
+ // @__NO_SIDE_EFFECTS__
2733
+ function _uuidv6(Class, params) {
2734
+ return new Class({
2735
+ type: "string",
2736
+ format: "uuid",
2737
+ check: "string_format",
2738
+ abort: false,
2739
+ version: "v6",
2740
+ ...normalizeParams(params)
2741
+ });
2742
+ }
2743
+ // @__NO_SIDE_EFFECTS__
2744
+ function _uuidv7(Class, params) {
2745
+ return new Class({
2746
+ type: "string",
2747
+ format: "uuid",
2748
+ check: "string_format",
2749
+ abort: false,
2750
+ version: "v7",
2751
+ ...normalizeParams(params)
2752
+ });
2753
+ }
2754
+ // @__NO_SIDE_EFFECTS__
2755
+ function _url(Class, params) {
2756
+ return new Class({
2757
+ type: "string",
2758
+ format: "url",
2759
+ check: "string_format",
2760
+ abort: false,
2761
+ ...normalizeParams(params)
2762
+ });
2763
+ }
2764
+ // @__NO_SIDE_EFFECTS__
2765
+ function _emoji(Class, params) {
2766
+ return new Class({
2767
+ type: "string",
2768
+ format: "emoji",
2769
+ check: "string_format",
2770
+ abort: false,
2771
+ ...normalizeParams(params)
2772
+ });
2773
+ }
2774
+ // @__NO_SIDE_EFFECTS__
2775
+ function _nanoid(Class, params) {
2776
+ return new Class({
2777
+ type: "string",
2778
+ format: "nanoid",
2779
+ check: "string_format",
2780
+ abort: false,
2781
+ ...normalizeParams(params)
2782
+ });
2783
+ }
2784
+ /**
2785
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
2786
+ * (timestamps embedded in the id). Use {@link _cuid2} instead.
2787
+ * See https://github.com/paralleldrive/cuid.
2788
+ */
2789
+ // @__NO_SIDE_EFFECTS__
2790
+ function _cuid(Class, params) {
2791
+ return new Class({
2792
+ type: "string",
2793
+ format: "cuid",
2794
+ check: "string_format",
2795
+ abort: false,
2796
+ ...normalizeParams(params)
2797
+ });
2798
+ }
2799
+ // @__NO_SIDE_EFFECTS__
2800
+ function _cuid2(Class, params) {
2801
+ return new Class({
2802
+ type: "string",
2803
+ format: "cuid2",
2804
+ check: "string_format",
2805
+ abort: false,
2806
+ ...normalizeParams(params)
2807
+ });
2808
+ }
2809
+ // @__NO_SIDE_EFFECTS__
2810
+ function _ulid(Class, params) {
2811
+ return new Class({
2812
+ type: "string",
2813
+ format: "ulid",
2814
+ check: "string_format",
2815
+ abort: false,
2816
+ ...normalizeParams(params)
2817
+ });
2818
+ }
2819
+ // @__NO_SIDE_EFFECTS__
2820
+ function _xid(Class, params) {
2821
+ return new Class({
2822
+ type: "string",
2823
+ format: "xid",
2824
+ check: "string_format",
2825
+ abort: false,
2826
+ ...normalizeParams(params)
2827
+ });
2828
+ }
2829
+ // @__NO_SIDE_EFFECTS__
2830
+ function _ksuid(Class, params) {
2831
+ return new Class({
2832
+ type: "string",
2833
+ format: "ksuid",
2834
+ check: "string_format",
2835
+ abort: false,
2836
+ ...normalizeParams(params)
2837
+ });
2838
+ }
2839
+ // @__NO_SIDE_EFFECTS__
2840
+ function _ipv4(Class, params) {
2841
+ return new Class({
2842
+ type: "string",
2843
+ format: "ipv4",
2844
+ check: "string_format",
2845
+ abort: false,
2846
+ ...normalizeParams(params)
2847
+ });
2848
+ }
2849
+ // @__NO_SIDE_EFFECTS__
2850
+ function _ipv6(Class, params) {
2851
+ return new Class({
2852
+ type: "string",
2853
+ format: "ipv6",
2854
+ check: "string_format",
2855
+ abort: false,
2856
+ ...normalizeParams(params)
2857
+ });
2858
+ }
2859
+ // @__NO_SIDE_EFFECTS__
2860
+ function _cidrv4(Class, params) {
2861
+ return new Class({
2862
+ type: "string",
2863
+ format: "cidrv4",
2864
+ check: "string_format",
2865
+ abort: false,
2866
+ ...normalizeParams(params)
2867
+ });
2868
+ }
2869
+ // @__NO_SIDE_EFFECTS__
2870
+ function _cidrv6(Class, params) {
2871
+ return new Class({
2872
+ type: "string",
2873
+ format: "cidrv6",
2874
+ check: "string_format",
2875
+ abort: false,
2876
+ ...normalizeParams(params)
2877
+ });
2878
+ }
2879
+ // @__NO_SIDE_EFFECTS__
2880
+ function _base64(Class, params) {
2881
+ return new Class({
2882
+ type: "string",
2883
+ format: "base64",
2884
+ check: "string_format",
2885
+ abort: false,
2886
+ ...normalizeParams(params)
2887
+ });
2888
+ }
2889
+ // @__NO_SIDE_EFFECTS__
2890
+ function _base64url(Class, params) {
2891
+ return new Class({
2892
+ type: "string",
2893
+ format: "base64url",
2894
+ check: "string_format",
2895
+ abort: false,
2896
+ ...normalizeParams(params)
2897
+ });
2898
+ }
2899
+ // @__NO_SIDE_EFFECTS__
2900
+ function _e164(Class, params) {
2901
+ return new Class({
2902
+ type: "string",
2903
+ format: "e164",
2904
+ check: "string_format",
2905
+ abort: false,
2906
+ ...normalizeParams(params)
2907
+ });
2908
+ }
2909
+ // @__NO_SIDE_EFFECTS__
2910
+ function _jwt(Class, params) {
2911
+ return new Class({
2912
+ type: "string",
2913
+ format: "jwt",
2914
+ check: "string_format",
2915
+ abort: false,
2916
+ ...normalizeParams(params)
2917
+ });
2918
+ }
2919
+ // @__NO_SIDE_EFFECTS__
2920
+ function _isoDateTime(Class, params) {
2921
+ return new Class({
2922
+ type: "string",
2923
+ format: "datetime",
2924
+ check: "string_format",
2925
+ offset: false,
2926
+ local: false,
2927
+ precision: null,
2928
+ ...normalizeParams(params)
2929
+ });
2930
+ }
2931
+ // @__NO_SIDE_EFFECTS__
2932
+ function _isoDate(Class, params) {
2933
+ return new Class({
2934
+ type: "string",
2935
+ format: "date",
2936
+ check: "string_format",
2937
+ ...normalizeParams(params)
2938
+ });
2939
+ }
2940
+ // @__NO_SIDE_EFFECTS__
2941
+ function _isoTime(Class, params) {
2942
+ return new Class({
2943
+ type: "string",
2944
+ format: "time",
2945
+ check: "string_format",
2946
+ precision: null,
2947
+ ...normalizeParams(params)
2948
+ });
2949
+ }
2950
+ // @__NO_SIDE_EFFECTS__
2951
+ function _isoDuration(Class, params) {
2952
+ return new Class({
2953
+ type: "string",
2954
+ format: "duration",
2955
+ check: "string_format",
2956
+ ...normalizeParams(params)
2957
+ });
2958
+ }
2959
+ // @__NO_SIDE_EFFECTS__
2960
+ function _boolean(Class, params) {
2961
+ return new Class({
2962
+ type: "boolean",
2963
+ ...normalizeParams(params)
2964
+ });
2965
+ }
2966
+ // @__NO_SIDE_EFFECTS__
2967
+ function _unknown(Class) {
2968
+ return new Class({ type: "unknown" });
2969
+ }
2970
+ // @__NO_SIDE_EFFECTS__
2971
+ function _never(Class, params) {
2972
+ return new Class({
2973
+ type: "never",
2974
+ ...normalizeParams(params)
2975
+ });
2976
+ }
2977
+ // @__NO_SIDE_EFFECTS__
2978
+ function _maxLength(maximum, params) {
2979
+ return new $ZodCheckMaxLength({
2980
+ check: "max_length",
2981
+ ...normalizeParams(params),
2982
+ maximum
2983
+ });
2984
+ }
2985
+ // @__NO_SIDE_EFFECTS__
2986
+ function _minLength(minimum, params) {
2987
+ return new $ZodCheckMinLength({
2988
+ check: "min_length",
2989
+ ...normalizeParams(params),
2990
+ minimum
2991
+ });
2992
+ }
2993
+ // @__NO_SIDE_EFFECTS__
2994
+ function _length(length, params) {
2995
+ return new $ZodCheckLengthEquals({
2996
+ check: "length_equals",
2997
+ ...normalizeParams(params),
2998
+ length
2999
+ });
3000
+ }
3001
+ // @__NO_SIDE_EFFECTS__
3002
+ function _regex(pattern, params) {
3003
+ return new $ZodCheckRegex({
3004
+ check: "string_format",
3005
+ format: "regex",
3006
+ ...normalizeParams(params),
3007
+ pattern
3008
+ });
3009
+ }
3010
+ // @__NO_SIDE_EFFECTS__
3011
+ function _lowercase(params) {
3012
+ return new $ZodCheckLowerCase({
3013
+ check: "string_format",
3014
+ format: "lowercase",
3015
+ ...normalizeParams(params)
3016
+ });
3017
+ }
3018
+ // @__NO_SIDE_EFFECTS__
3019
+ function _uppercase(params) {
3020
+ return new $ZodCheckUpperCase({
3021
+ check: "string_format",
3022
+ format: "uppercase",
3023
+ ...normalizeParams(params)
3024
+ });
3025
+ }
3026
+ // @__NO_SIDE_EFFECTS__
3027
+ function _includes(includes, params) {
3028
+ return new $ZodCheckIncludes({
3029
+ check: "string_format",
3030
+ format: "includes",
3031
+ ...normalizeParams(params),
3032
+ includes
3033
+ });
3034
+ }
3035
+ // @__NO_SIDE_EFFECTS__
3036
+ function _startsWith(prefix, params) {
3037
+ return new $ZodCheckStartsWith({
3038
+ check: "string_format",
3039
+ format: "starts_with",
3040
+ ...normalizeParams(params),
3041
+ prefix
3042
+ });
3043
+ }
3044
+ // @__NO_SIDE_EFFECTS__
3045
+ function _endsWith(suffix, params) {
3046
+ return new $ZodCheckEndsWith({
3047
+ check: "string_format",
3048
+ format: "ends_with",
3049
+ ...normalizeParams(params),
3050
+ suffix
3051
+ });
3052
+ }
3053
+ // @__NO_SIDE_EFFECTS__
3054
+ function _overwrite(tx) {
3055
+ return new $ZodCheckOverwrite({
3056
+ check: "overwrite",
3057
+ tx
3058
+ });
3059
+ }
3060
+ // @__NO_SIDE_EFFECTS__
3061
+ function _normalize(form) {
3062
+ return /* @__PURE__ */ _overwrite((input) => input.normalize(form));
3063
+ }
3064
+ // @__NO_SIDE_EFFECTS__
3065
+ function _trim() {
3066
+ return /* @__PURE__ */ _overwrite((input) => input.trim());
3067
+ }
3068
+ // @__NO_SIDE_EFFECTS__
3069
+ function _toLowerCase() {
3070
+ return /* @__PURE__ */ _overwrite((input) => input.toLowerCase());
3071
+ }
3072
+ // @__NO_SIDE_EFFECTS__
3073
+ function _toUpperCase() {
3074
+ return /* @__PURE__ */ _overwrite((input) => input.toUpperCase());
3075
+ }
3076
+ // @__NO_SIDE_EFFECTS__
3077
+ function _slugify() {
3078
+ return /* @__PURE__ */ _overwrite((input) => slugify(input));
3079
+ }
3080
+ // @__NO_SIDE_EFFECTS__
3081
+ function _array(Class, element, params) {
3082
+ return new Class({
3083
+ type: "array",
3084
+ element,
3085
+ ...normalizeParams(params)
3086
+ });
3087
+ }
3088
+ // @__NO_SIDE_EFFECTS__
3089
+ function _refine(Class, fn, _params) {
3090
+ return new Class({
3091
+ type: "custom",
3092
+ check: "custom",
3093
+ fn,
3094
+ ...normalizeParams(_params)
3095
+ });
3096
+ }
3097
+ // @__NO_SIDE_EFFECTS__
3098
+ function _superRefine(fn, params) {
3099
+ const ch = /* @__PURE__ */ _check((payload) => {
3100
+ payload.addIssue = (issue$2) => {
3101
+ if (typeof issue$2 === "string") payload.issues.push(issue(issue$2, payload.value, ch._zod.def));
3102
+ else {
3103
+ const _issue = issue$2;
3104
+ if (_issue.fatal) _issue.continue = false;
3105
+ _issue.code ?? (_issue.code = "custom");
3106
+ _issue.input ?? (_issue.input = payload.value);
3107
+ _issue.inst ?? (_issue.inst = ch);
3108
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
3109
+ payload.issues.push(issue(_issue));
3110
+ }
3111
+ };
3112
+ return fn(payload.value, payload);
3113
+ }, params);
3114
+ return ch;
3115
+ }
3116
+ // @__NO_SIDE_EFFECTS__
3117
+ function _check(fn, params) {
3118
+ const ch = new $ZodCheck({
3119
+ check: "custom",
3120
+ ...normalizeParams(params)
3121
+ });
3122
+ ch._zod.check = fn;
3123
+ return ch;
3124
+ }
3125
+ //#endregion
3126
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/to-json-schema.js
3127
+ function initializeContext(params) {
3128
+ let target = params?.target ?? "draft-2020-12";
3129
+ if (target === "draft-4") target = "draft-04";
3130
+ if (target === "draft-7") target = "draft-07";
3131
+ return {
3132
+ processors: params.processors ?? {},
3133
+ metadataRegistry: params?.metadata ?? globalRegistry,
3134
+ target,
3135
+ unrepresentable: params?.unrepresentable ?? "throw",
3136
+ override: params?.override ?? (() => {}),
3137
+ io: params?.io ?? "output",
3138
+ counter: 0,
3139
+ seen: /* @__PURE__ */ new Map(),
3140
+ cycles: params?.cycles ?? "ref",
3141
+ reused: params?.reused ?? "inline",
3142
+ external: params?.external ?? void 0
3143
+ };
3144
+ }
3145
+ function process(schema, ctx, _params = {
3146
+ path: [],
3147
+ schemaPath: []
3148
+ }) {
3149
+ var _a;
3150
+ const def = schema._zod.def;
3151
+ const seen = ctx.seen.get(schema);
3152
+ if (seen) {
3153
+ seen.count++;
3154
+ if (_params.schemaPath.includes(schema)) seen.cycle = _params.path;
3155
+ return seen.schema;
3156
+ }
3157
+ const result = {
3158
+ schema: {},
3159
+ count: 1,
3160
+ cycle: void 0,
3161
+ path: _params.path
3162
+ };
3163
+ ctx.seen.set(schema, result);
3164
+ const overrideSchema = schema._zod.toJSONSchema?.();
3165
+ if (overrideSchema) result.schema = overrideSchema;
3166
+ else {
3167
+ const params = {
3168
+ ..._params,
3169
+ schemaPath: [..._params.schemaPath, schema],
3170
+ path: _params.path
3171
+ };
3172
+ if (schema._zod.processJSONSchema) schema._zod.processJSONSchema(ctx, result.schema, params);
3173
+ else {
3174
+ const _json = result.schema;
3175
+ const processor = ctx.processors[def.type];
3176
+ if (!processor) throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
3177
+ processor(schema, ctx, _json, params);
3178
+ }
3179
+ const parent = schema._zod.parent;
3180
+ if (parent) {
3181
+ if (!result.ref) result.ref = parent;
3182
+ process(parent, ctx, params);
3183
+ ctx.seen.get(parent).isParent = true;
3184
+ }
3185
+ }
3186
+ const meta = ctx.metadataRegistry.get(schema);
3187
+ if (meta) Object.assign(result.schema, meta);
3188
+ if (ctx.io === "input" && isTransforming(schema)) {
3189
+ delete result.schema.examples;
3190
+ delete result.schema.default;
3191
+ }
3192
+ if (ctx.io === "input" && "_prefault" in result.schema) (_a = result.schema).default ?? (_a.default = result.schema._prefault);
3193
+ delete result.schema._prefault;
3194
+ return ctx.seen.get(schema).schema;
3195
+ }
3196
+ function extractDefs(ctx, schema) {
3197
+ const root = ctx.seen.get(schema);
3198
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
3199
+ const idToSchema = /* @__PURE__ */ new Map();
3200
+ for (const entry of ctx.seen.entries()) {
3201
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
3202
+ if (id) {
3203
+ const existing = idToSchema.get(id);
3204
+ if (existing && existing !== entry[0]) throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
3205
+ idToSchema.set(id, entry[0]);
3206
+ }
3207
+ }
3208
+ const makeURI = (entry) => {
3209
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
3210
+ if (ctx.external) {
3211
+ const externalId = ctx.external.registry.get(entry[0])?.id;
3212
+ const uriGenerator = ctx.external.uri ?? ((id) => id);
3213
+ if (externalId) return { ref: uriGenerator(externalId) };
3214
+ const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
3215
+ entry[1].defId = id;
3216
+ return {
3217
+ defId: id,
3218
+ ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}`
3219
+ };
3220
+ }
3221
+ if (entry[1] === root) return { ref: "#" };
3222
+ const defUriPrefix = `#/${defsSegment}/`;
3223
+ const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
3224
+ return {
3225
+ defId,
3226
+ ref: defUriPrefix + defId
3227
+ };
3228
+ };
3229
+ const extractToDef = (entry) => {
3230
+ if (entry[1].schema.$ref) return;
3231
+ const seen = entry[1];
3232
+ const { ref, defId } = makeURI(entry);
3233
+ seen.def = { ...seen.schema };
3234
+ if (defId) seen.defId = defId;
3235
+ const schema = seen.schema;
3236
+ for (const key in schema) delete schema[key];
3237
+ schema.$ref = ref;
3238
+ };
3239
+ if (ctx.cycles === "throw") for (const entry of ctx.seen.entries()) {
3240
+ const seen = entry[1];
3241
+ if (seen.cycle) throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
3242
+
3243
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
3244
+ }
3245
+ for (const entry of ctx.seen.entries()) {
3246
+ const seen = entry[1];
3247
+ if (schema === entry[0]) {
3248
+ extractToDef(entry);
3249
+ continue;
3250
+ }
3251
+ if (ctx.external) {
3252
+ const ext = ctx.external.registry.get(entry[0])?.id;
3253
+ if (schema !== entry[0] && ext) {
3254
+ extractToDef(entry);
3255
+ continue;
3256
+ }
3257
+ }
3258
+ if (ctx.metadataRegistry.get(entry[0])?.id) {
3259
+ extractToDef(entry);
3260
+ continue;
3261
+ }
3262
+ if (seen.cycle) {
3263
+ extractToDef(entry);
3264
+ continue;
3265
+ }
3266
+ if (seen.count > 1) {
3267
+ if (ctx.reused === "ref") {
3268
+ extractToDef(entry);
3269
+ continue;
3270
+ }
3271
+ }
3272
+ }
3273
+ }
3274
+ function finalize(ctx, schema) {
3275
+ const root = ctx.seen.get(schema);
3276
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
3277
+ const flattenRef = (zodSchema) => {
3278
+ const seen = ctx.seen.get(zodSchema);
3279
+ if (seen.ref === null) return;
3280
+ const schema = seen.def ?? seen.schema;
3281
+ const _cached = { ...schema };
3282
+ const ref = seen.ref;
3283
+ seen.ref = null;
3284
+ if (ref) {
3285
+ flattenRef(ref);
3286
+ const refSeen = ctx.seen.get(ref);
3287
+ const refSchema = refSeen.schema;
3288
+ if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
3289
+ schema.allOf = schema.allOf ?? [];
3290
+ schema.allOf.push(refSchema);
3291
+ } else Object.assign(schema, refSchema);
3292
+ Object.assign(schema, _cached);
3293
+ if (zodSchema._zod.parent === ref) for (const key in schema) {
3294
+ if (key === "$ref" || key === "allOf") continue;
3295
+ if (!(key in _cached)) delete schema[key];
3296
+ }
3297
+ if (refSchema.$ref && refSeen.def) for (const key in schema) {
3298
+ if (key === "$ref" || key === "allOf") continue;
3299
+ if (key in refSeen.def && JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])) delete schema[key];
3300
+ }
3301
+ }
3302
+ const parent = zodSchema._zod.parent;
3303
+ if (parent && parent !== ref) {
3304
+ flattenRef(parent);
3305
+ const parentSeen = ctx.seen.get(parent);
3306
+ if (parentSeen?.schema.$ref) {
3307
+ schema.$ref = parentSeen.schema.$ref;
3308
+ if (parentSeen.def) for (const key in schema) {
3309
+ if (key === "$ref" || key === "allOf") continue;
3310
+ if (key in parentSeen.def && JSON.stringify(schema[key]) === JSON.stringify(parentSeen.def[key])) delete schema[key];
3311
+ }
3312
+ }
3313
+ }
3314
+ ctx.override({
3315
+ zodSchema,
3316
+ jsonSchema: schema,
3317
+ path: seen.path ?? []
3318
+ });
3319
+ };
3320
+ for (const entry of [...ctx.seen.entries()].reverse()) flattenRef(entry[0]);
3321
+ const result = {};
3322
+ if (ctx.target === "draft-2020-12") result.$schema = "https://json-schema.org/draft/2020-12/schema";
3323
+ else if (ctx.target === "draft-07") result.$schema = "http://json-schema.org/draft-07/schema#";
3324
+ else if (ctx.target === "draft-04") result.$schema = "http://json-schema.org/draft-04/schema#";
3325
+ else if (ctx.target === "openapi-3.0") {}
3326
+ if (ctx.external?.uri) {
3327
+ const id = ctx.external.registry.get(schema)?.id;
3328
+ if (!id) throw new Error("Schema is missing an `id` property");
3329
+ result.$id = ctx.external.uri(id);
3330
+ }
3331
+ Object.assign(result, root.def ?? root.schema);
3332
+ const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
3333
+ if (rootMetaId !== void 0 && result.id === rootMetaId) delete result.id;
3334
+ const defs = ctx.external?.defs ?? {};
3335
+ for (const entry of ctx.seen.entries()) {
3336
+ const seen = entry[1];
3337
+ if (seen.def && seen.defId) {
3338
+ if (seen.def.id === seen.defId) delete seen.def.id;
3339
+ defs[seen.defId] = seen.def;
3340
+ }
3341
+ }
3342
+ if (ctx.external) {} else if (Object.keys(defs).length > 0) {
3343
+ if (ctx.target === "draft-2020-12") result.$defs = defs;
3344
+ else result.definitions = defs;
3345
+ }
3346
+ try {
3347
+ const finalized = JSON.parse(JSON.stringify(result));
3348
+ Object.defineProperty(finalized, "~standard", {
3349
+ value: {
3350
+ ...schema["~standard"],
3351
+ jsonSchema: {
3352
+ input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
3353
+ output: createStandardJSONSchemaMethod(schema, "output", ctx.processors)
3354
+ }
3355
+ },
3356
+ enumerable: false,
3357
+ writable: false
3358
+ });
3359
+ return finalized;
3360
+ } catch (_err) {
3361
+ throw new Error("Error converting schema to JSON.");
3362
+ }
3363
+ }
3364
+ function isTransforming(_schema, _ctx) {
3365
+ const ctx = _ctx ?? { seen: /* @__PURE__ */ new Set() };
3366
+ if (ctx.seen.has(_schema)) return false;
3367
+ ctx.seen.add(_schema);
3368
+ const def = _schema._zod.def;
3369
+ if (def.type === "transform") return true;
3370
+ if (def.type === "array") return isTransforming(def.element, ctx);
3371
+ if (def.type === "set") return isTransforming(def.valueType, ctx);
3372
+ if (def.type === "lazy") return isTransforming(def.getter(), ctx);
3373
+ if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault") return isTransforming(def.innerType, ctx);
3374
+ if (def.type === "intersection") return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
3375
+ if (def.type === "record" || def.type === "map") return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
3376
+ if (def.type === "pipe") {
3377
+ if (_schema._zod.traits.has("$ZodCodec")) return true;
3378
+ return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
3379
+ }
3380
+ if (def.type === "object") {
3381
+ for (const key in def.shape) if (isTransforming(def.shape[key], ctx)) return true;
3382
+ return false;
3383
+ }
3384
+ if (def.type === "union") {
3385
+ for (const option of def.options) if (isTransforming(option, ctx)) return true;
3386
+ return false;
3387
+ }
3388
+ if (def.type === "tuple") {
3389
+ for (const item of def.items) if (isTransforming(item, ctx)) return true;
3390
+ if (def.rest && isTransforming(def.rest, ctx)) return true;
3391
+ return false;
3392
+ }
3393
+ return false;
3394
+ }
3395
+ /**
3396
+ * Creates a toJSONSchema method for a schema instance.
3397
+ * This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
3398
+ */
3399
+ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
3400
+ const ctx = initializeContext({
3401
+ ...params,
3402
+ processors
3403
+ });
3404
+ process(schema, ctx);
3405
+ extractDefs(ctx, schema);
3406
+ return finalize(ctx, schema);
3407
+ };
3408
+ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
3409
+ const { libraryOptions, target } = params ?? {};
3410
+ const ctx = initializeContext({
3411
+ ...libraryOptions ?? {},
3412
+ target,
3413
+ io,
3414
+ processors
3415
+ });
3416
+ process(schema, ctx);
3417
+ extractDefs(ctx, schema);
3418
+ return finalize(ctx, schema);
3419
+ };
3420
+ //#endregion
3421
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/json-schema-processors.js
3422
+ const formatMap = {
3423
+ guid: "uuid",
3424
+ url: "uri",
3425
+ datetime: "date-time",
3426
+ json_string: "json-string",
3427
+ regex: ""
3428
+ };
3429
+ const stringProcessor = (schema, ctx, _json, _params) => {
3430
+ const json = _json;
3431
+ json.type = "string";
3432
+ const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
3433
+ if (typeof minimum === "number") json.minLength = minimum;
3434
+ if (typeof maximum === "number") json.maxLength = maximum;
3435
+ if (format) {
3436
+ json.format = formatMap[format] ?? format;
3437
+ if (json.format === "") delete json.format;
3438
+ if (format === "time") delete json.format;
3439
+ }
3440
+ if (contentEncoding) json.contentEncoding = contentEncoding;
3441
+ if (patterns && patterns.size > 0) {
3442
+ const regexes = [...patterns];
3443
+ if (regexes.length === 1) json.pattern = regexes[0].source;
3444
+ else if (regexes.length > 1) json.allOf = [...regexes.map((regex) => ({
3445
+ ...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
3446
+ pattern: regex.source
3447
+ }))];
3448
+ }
3449
+ };
3450
+ const booleanProcessor = (_schema, _ctx, json, _params) => {
3451
+ json.type = "boolean";
3452
+ };
3453
+ const neverProcessor = (_schema, _ctx, json, _params) => {
3454
+ json.not = {};
3455
+ };
3456
+ const enumProcessor = (schema, _ctx, json, _params) => {
3457
+ const def = schema._zod.def;
3458
+ const values = getEnumValues(def.entries);
3459
+ if (values.every((v) => typeof v === "number")) json.type = "number";
3460
+ if (values.every((v) => typeof v === "string")) json.type = "string";
3461
+ json.enum = values;
3462
+ };
3463
+ const customProcessor = (_schema, ctx, _json, _params) => {
3464
+ if (ctx.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
3465
+ };
3466
+ const transformProcessor = (_schema, ctx, _json, _params) => {
3467
+ if (ctx.unrepresentable === "throw") throw new Error("Transforms cannot be represented in JSON Schema");
3468
+ };
3469
+ const arrayProcessor = (schema, ctx, _json, params) => {
3470
+ const json = _json;
3471
+ const def = schema._zod.def;
3472
+ const { minimum, maximum } = schema._zod.bag;
3473
+ if (typeof minimum === "number") json.minItems = minimum;
3474
+ if (typeof maximum === "number") json.maxItems = maximum;
3475
+ json.type = "array";
3476
+ json.items = process(def.element, ctx, {
3477
+ ...params,
3478
+ path: [...params.path, "items"]
3479
+ });
3480
+ };
3481
+ const objectProcessor = (schema, ctx, _json, params) => {
3482
+ const json = _json;
3483
+ const def = schema._zod.def;
3484
+ json.type = "object";
3485
+ json.properties = {};
3486
+ const shape = def.shape;
3487
+ for (const key in shape) json.properties[key] = process(shape[key], ctx, {
3488
+ ...params,
3489
+ path: [
3490
+ ...params.path,
3491
+ "properties",
3492
+ key
3493
+ ]
3494
+ });
3495
+ const allKeys = new Set(Object.keys(shape));
3496
+ const requiredKeys = new Set([...allKeys].filter((key) => {
3497
+ const v = def.shape[key]._zod;
3498
+ if (ctx.io === "input") return v.optin === void 0;
3499
+ else return v.optout === void 0;
3500
+ }));
3501
+ if (requiredKeys.size > 0) json.required = Array.from(requiredKeys);
3502
+ if (def.catchall?._zod.def.type === "never") json.additionalProperties = false;
3503
+ else if (!def.catchall) {
3504
+ if (ctx.io === "output") json.additionalProperties = false;
3505
+ } else if (def.catchall) json.additionalProperties = process(def.catchall, ctx, {
3506
+ ...params,
3507
+ path: [...params.path, "additionalProperties"]
3508
+ });
3509
+ };
3510
+ const unionProcessor = (schema, ctx, json, params) => {
3511
+ const def = schema._zod.def;
3512
+ const isExclusive = def.inclusive === false;
3513
+ const options = def.options.map((x, i) => process(x, ctx, {
3514
+ ...params,
3515
+ path: [
3516
+ ...params.path,
3517
+ isExclusive ? "oneOf" : "anyOf",
3518
+ i
3519
+ ]
3520
+ }));
3521
+ if (isExclusive) json.oneOf = options;
3522
+ else json.anyOf = options;
3523
+ };
3524
+ const intersectionProcessor = (schema, ctx, json, params) => {
3525
+ const def = schema._zod.def;
3526
+ const a = process(def.left, ctx, {
3527
+ ...params,
3528
+ path: [
3529
+ ...params.path,
3530
+ "allOf",
3531
+ 0
3532
+ ]
3533
+ });
3534
+ const b = process(def.right, ctx, {
3535
+ ...params,
3536
+ path: [
3537
+ ...params.path,
3538
+ "allOf",
3539
+ 1
3540
+ ]
3541
+ });
3542
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
3543
+ json.allOf = [...isSimpleIntersection(a) ? a.allOf : [a], ...isSimpleIntersection(b) ? b.allOf : [b]];
3544
+ };
3545
+ const nullableProcessor = (schema, ctx, json, params) => {
3546
+ const def = schema._zod.def;
3547
+ const inner = process(def.innerType, ctx, params);
3548
+ const seen = ctx.seen.get(schema);
3549
+ if (ctx.target === "openapi-3.0") {
3550
+ seen.ref = def.innerType;
3551
+ json.nullable = true;
3552
+ } else json.anyOf = [inner, { type: "null" }];
3553
+ };
3554
+ const nonoptionalProcessor = (schema, ctx, _json, params) => {
3555
+ const def = schema._zod.def;
3556
+ process(def.innerType, ctx, params);
3557
+ const seen = ctx.seen.get(schema);
3558
+ seen.ref = def.innerType;
3559
+ };
3560
+ const defaultProcessor = (schema, ctx, json, params) => {
3561
+ const def = schema._zod.def;
3562
+ process(def.innerType, ctx, params);
3563
+ const seen = ctx.seen.get(schema);
3564
+ seen.ref = def.innerType;
3565
+ json.default = JSON.parse(JSON.stringify(def.defaultValue));
3566
+ };
3567
+ const prefaultProcessor = (schema, ctx, json, params) => {
3568
+ const def = schema._zod.def;
3569
+ process(def.innerType, ctx, params);
3570
+ const seen = ctx.seen.get(schema);
3571
+ seen.ref = def.innerType;
3572
+ if (ctx.io === "input") json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
3573
+ };
3574
+ const catchProcessor = (schema, ctx, json, params) => {
3575
+ const def = schema._zod.def;
3576
+ process(def.innerType, ctx, params);
3577
+ const seen = ctx.seen.get(schema);
3578
+ seen.ref = def.innerType;
3579
+ let catchValue;
3580
+ try {
3581
+ catchValue = def.catchValue(void 0);
3582
+ } catch {
3583
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
3584
+ }
3585
+ json.default = catchValue;
3586
+ };
3587
+ const pipeProcessor = (schema, ctx, _json, params) => {
3588
+ const def = schema._zod.def;
3589
+ const inIsTransform = def.in._zod.traits.has("$ZodTransform");
3590
+ const innerType = ctx.io === "input" ? inIsTransform ? def.out : def.in : def.out;
3591
+ process(innerType, ctx, params);
3592
+ const seen = ctx.seen.get(schema);
3593
+ seen.ref = innerType;
3594
+ };
3595
+ const readonlyProcessor = (schema, ctx, json, params) => {
3596
+ const def = schema._zod.def;
3597
+ process(def.innerType, ctx, params);
3598
+ const seen = ctx.seen.get(schema);
3599
+ seen.ref = def.innerType;
3600
+ json.readOnly = true;
3601
+ };
3602
+ const optionalProcessor = (schema, ctx, _json, params) => {
3603
+ const def = schema._zod.def;
3604
+ process(def.innerType, ctx, params);
3605
+ const seen = ctx.seen.get(schema);
3606
+ seen.ref = def.innerType;
3607
+ };
3608
+ //#endregion
3609
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/iso.js
3610
+ const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
3611
+ $ZodISODateTime.init(inst, def);
3612
+ ZodStringFormat.init(inst, def);
3613
+ });
3614
+ function datetime(params) {
3615
+ return /* @__PURE__ */ _isoDateTime(ZodISODateTime, params);
3616
+ }
3617
+ const ZodISODate = /*@__PURE__*/ $constructor("ZodISODate", (inst, def) => {
3618
+ $ZodISODate.init(inst, def);
3619
+ ZodStringFormat.init(inst, def);
3620
+ });
3621
+ function date(params) {
3622
+ return /* @__PURE__ */ _isoDate(ZodISODate, params);
3623
+ }
3624
+ const ZodISOTime = /*@__PURE__*/ $constructor("ZodISOTime", (inst, def) => {
3625
+ $ZodISOTime.init(inst, def);
3626
+ ZodStringFormat.init(inst, def);
3627
+ });
3628
+ function time(params) {
3629
+ return /* @__PURE__ */ _isoTime(ZodISOTime, params);
3630
+ }
3631
+ const ZodISODuration = /*@__PURE__*/ $constructor("ZodISODuration", (inst, def) => {
3632
+ $ZodISODuration.init(inst, def);
3633
+ ZodStringFormat.init(inst, def);
3634
+ });
3635
+ function duration(params) {
3636
+ return /* @__PURE__ */ _isoDuration(ZodISODuration, params);
3637
+ }
3638
+ //#endregion
3639
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/errors.js
3640
+ const initializer = (inst, issues) => {
3641
+ $ZodError.init(inst, issues);
3642
+ inst.name = "ZodError";
3643
+ Object.defineProperties(inst, {
3644
+ format: { value: (mapper) => formatError(inst, mapper) },
3645
+ flatten: { value: (mapper) => flattenError(inst, mapper) },
3646
+ addIssue: { value: (issue) => {
3647
+ inst.issues.push(issue);
3648
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
3649
+ } },
3650
+ addIssues: { value: (issues) => {
3651
+ inst.issues.push(...issues);
3652
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
3653
+ } },
3654
+ isEmpty: { get() {
3655
+ return inst.issues.length === 0;
3656
+ } }
3657
+ });
3658
+ };
3659
+ const ZodRealError = /*@__PURE__*/ $constructor("ZodError", initializer, { Parent: Error });
3660
+ //#endregion
3661
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/parse.js
3662
+ const parse = /* @__PURE__ */ _parse(ZodRealError);
3663
+ const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
3664
+ const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
3665
+ const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
3666
+ const encode = /* @__PURE__ */ _encode(ZodRealError);
3667
+ const decode = /* @__PURE__ */ _decode(ZodRealError);
3668
+ const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
3669
+ const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
3670
+ const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
3671
+ const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
3672
+ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
3673
+ const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
3674
+ //#endregion
3675
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/schemas.js
3676
+ const _installedGroups = /* @__PURE__ */ new WeakMap();
3677
+ function _installLazyMethods(inst, group, methods) {
3678
+ const proto = Object.getPrototypeOf(inst);
3679
+ let installed = _installedGroups.get(proto);
3680
+ if (!installed) {
3681
+ installed = /* @__PURE__ */ new Set();
3682
+ _installedGroups.set(proto, installed);
3683
+ }
3684
+ if (installed.has(group)) return;
3685
+ installed.add(group);
3686
+ for (const key in methods) {
3687
+ const fn = methods[key];
3688
+ Object.defineProperty(proto, key, {
3689
+ configurable: true,
3690
+ enumerable: false,
3691
+ get() {
3692
+ const bound = fn.bind(this);
3693
+ Object.defineProperty(this, key, {
3694
+ configurable: true,
3695
+ writable: true,
3696
+ enumerable: true,
3697
+ value: bound
3698
+ });
3699
+ return bound;
3700
+ },
3701
+ set(v) {
3702
+ Object.defineProperty(this, key, {
3703
+ configurable: true,
3704
+ writable: true,
3705
+ enumerable: true,
3706
+ value: v
3707
+ });
3708
+ }
3709
+ });
3710
+ }
3711
+ }
3712
+ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
3713
+ $ZodType.init(inst, def);
3714
+ Object.assign(inst["~standard"], { jsonSchema: {
3715
+ input: createStandardJSONSchemaMethod(inst, "input"),
3716
+ output: createStandardJSONSchemaMethod(inst, "output")
3717
+ } });
3718
+ inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
3719
+ inst.def = def;
3720
+ inst.type = def.type;
3721
+ Object.defineProperty(inst, "_def", { value: def });
3722
+ inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
3723
+ inst.safeParse = (data, params) => safeParse(inst, data, params);
3724
+ inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
3725
+ inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
3726
+ inst.spa = inst.safeParseAsync;
3727
+ inst.encode = (data, params) => encode(inst, data, params);
3728
+ inst.decode = (data, params) => decode(inst, data, params);
3729
+ inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
3730
+ inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
3731
+ inst.safeEncode = (data, params) => safeEncode(inst, data, params);
3732
+ inst.safeDecode = (data, params) => safeDecode(inst, data, params);
3733
+ inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
3734
+ inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
3735
+ _installLazyMethods(inst, "ZodType", {
3736
+ check(...chks) {
3737
+ const def = this.def;
3738
+ return this.clone(mergeDefs(def, { checks: [...def.checks ?? [], ...chks.map((ch) => typeof ch === "function" ? { _zod: {
3739
+ check: ch,
3740
+ def: { check: "custom" },
3741
+ onattach: []
3742
+ } } : ch)] }), { parent: true });
3743
+ },
3744
+ with(...chks) {
3745
+ return this.check(...chks);
3746
+ },
3747
+ clone(def, params) {
3748
+ return clone(this, def, params);
3749
+ },
3750
+ brand() {
3751
+ return this;
3752
+ },
3753
+ register(reg, meta) {
3754
+ reg.add(this, meta);
3755
+ return this;
3756
+ },
3757
+ refine(check, params) {
3758
+ return this.check(refine(check, params));
3759
+ },
3760
+ superRefine(refinement, params) {
3761
+ return this.check(superRefine(refinement, params));
3762
+ },
3763
+ overwrite(fn) {
3764
+ return this.check(/* @__PURE__ */ _overwrite(fn));
3765
+ },
3766
+ optional() {
3767
+ return optional(this);
3768
+ },
3769
+ exactOptional() {
3770
+ return exactOptional(this);
3771
+ },
3772
+ nullable() {
3773
+ return nullable(this);
3774
+ },
3775
+ nullish() {
3776
+ return optional(nullable(this));
3777
+ },
3778
+ nonoptional(params) {
3779
+ return nonoptional(this, params);
3780
+ },
3781
+ array() {
3782
+ return array(this);
3783
+ },
3784
+ or(arg) {
3785
+ return union([this, arg]);
3786
+ },
3787
+ and(arg) {
3788
+ return intersection(this, arg);
3789
+ },
3790
+ transform(tx) {
3791
+ return pipe(this, transform(tx));
3792
+ },
3793
+ default(d) {
3794
+ return _default(this, d);
3795
+ },
3796
+ prefault(d) {
3797
+ return prefault(this, d);
3798
+ },
3799
+ catch(params) {
3800
+ return _catch(this, params);
3801
+ },
3802
+ pipe(target) {
3803
+ return pipe(this, target);
3804
+ },
3805
+ readonly() {
3806
+ return readonly(this);
3807
+ },
3808
+ describe(description) {
3809
+ const cl = this.clone();
3810
+ globalRegistry.add(cl, { description });
3811
+ return cl;
3812
+ },
3813
+ meta(...args) {
3814
+ if (args.length === 0) return globalRegistry.get(this);
3815
+ const cl = this.clone();
3816
+ globalRegistry.add(cl, args[0]);
3817
+ return cl;
3818
+ },
3819
+ isOptional() {
3820
+ return this.safeParse(void 0).success;
3821
+ },
3822
+ isNullable() {
3823
+ return this.safeParse(null).success;
3824
+ },
3825
+ apply(fn) {
3826
+ return fn(this);
3827
+ }
3828
+ });
3829
+ Object.defineProperty(inst, "description", {
3830
+ get() {
3831
+ return globalRegistry.get(inst)?.description;
3832
+ },
3833
+ configurable: true
3834
+ });
3835
+ return inst;
3836
+ });
3837
+ /** @internal */
3838
+ const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
3839
+ $ZodString.init(inst, def);
3840
+ ZodType.init(inst, def);
3841
+ inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json, params);
3842
+ const bag = inst._zod.bag;
3843
+ inst.format = bag.format ?? null;
3844
+ inst.minLength = bag.minimum ?? null;
3845
+ inst.maxLength = bag.maximum ?? null;
3846
+ _installLazyMethods(inst, "_ZodString", {
3847
+ regex(...args) {
3848
+ return this.check(/* @__PURE__ */ _regex(...args));
3849
+ },
3850
+ includes(...args) {
3851
+ return this.check(/* @__PURE__ */ _includes(...args));
3852
+ },
3853
+ startsWith(...args) {
3854
+ return this.check(/* @__PURE__ */ _startsWith(...args));
3855
+ },
3856
+ endsWith(...args) {
3857
+ return this.check(/* @__PURE__ */ _endsWith(...args));
3858
+ },
3859
+ min(...args) {
3860
+ return this.check(/* @__PURE__ */ _minLength(...args));
3861
+ },
3862
+ max(...args) {
3863
+ return this.check(/* @__PURE__ */ _maxLength(...args));
3864
+ },
3865
+ length(...args) {
3866
+ return this.check(/* @__PURE__ */ _length(...args));
3867
+ },
3868
+ nonempty(...args) {
3869
+ return this.check(/* @__PURE__ */ _minLength(1, ...args));
3870
+ },
3871
+ lowercase(params) {
3872
+ return this.check(/* @__PURE__ */ _lowercase(params));
3873
+ },
3874
+ uppercase(params) {
3875
+ return this.check(/* @__PURE__ */ _uppercase(params));
3876
+ },
3877
+ trim() {
3878
+ return this.check(/* @__PURE__ */ _trim());
3879
+ },
3880
+ normalize(...args) {
3881
+ return this.check(/* @__PURE__ */ _normalize(...args));
3882
+ },
3883
+ toLowerCase() {
3884
+ return this.check(/* @__PURE__ */ _toLowerCase());
3885
+ },
3886
+ toUpperCase() {
3887
+ return this.check(/* @__PURE__ */ _toUpperCase());
3888
+ },
3889
+ slugify() {
3890
+ return this.check(/* @__PURE__ */ _slugify());
3891
+ }
3892
+ });
3893
+ });
3894
+ const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def) => {
3895
+ $ZodString.init(inst, def);
3896
+ _ZodString.init(inst, def);
3897
+ inst.email = (params) => inst.check(/* @__PURE__ */ _email(ZodEmail, params));
3898
+ inst.url = (params) => inst.check(/* @__PURE__ */ _url(ZodURL, params));
3899
+ inst.jwt = (params) => inst.check(/* @__PURE__ */ _jwt(ZodJWT, params));
3900
+ inst.emoji = (params) => inst.check(/* @__PURE__ */ _emoji(ZodEmoji, params));
3901
+ inst.guid = (params) => inst.check(/* @__PURE__ */ _guid(ZodGUID, params));
3902
+ inst.uuid = (params) => inst.check(/* @__PURE__ */ _uuid(ZodUUID, params));
3903
+ inst.uuidv4 = (params) => inst.check(/* @__PURE__ */ _uuidv4(ZodUUID, params));
3904
+ inst.uuidv6 = (params) => inst.check(/* @__PURE__ */ _uuidv6(ZodUUID, params));
3905
+ inst.uuidv7 = (params) => inst.check(/* @__PURE__ */ _uuidv7(ZodUUID, params));
3906
+ inst.nanoid = (params) => inst.check(/* @__PURE__ */ _nanoid(ZodNanoID, params));
3907
+ inst.guid = (params) => inst.check(/* @__PURE__ */ _guid(ZodGUID, params));
3908
+ inst.cuid = (params) => inst.check(/* @__PURE__ */ _cuid(ZodCUID, params));
3909
+ inst.cuid2 = (params) => inst.check(/* @__PURE__ */ _cuid2(ZodCUID2, params));
3910
+ inst.ulid = (params) => inst.check(/* @__PURE__ */ _ulid(ZodULID, params));
3911
+ inst.base64 = (params) => inst.check(/* @__PURE__ */ _base64(ZodBase64, params));
3912
+ inst.base64url = (params) => inst.check(/* @__PURE__ */ _base64url(ZodBase64URL, params));
3913
+ inst.xid = (params) => inst.check(/* @__PURE__ */ _xid(ZodXID, params));
3914
+ inst.ksuid = (params) => inst.check(/* @__PURE__ */ _ksuid(ZodKSUID, params));
3915
+ inst.ipv4 = (params) => inst.check(/* @__PURE__ */ _ipv4(ZodIPv4, params));
3916
+ inst.ipv6 = (params) => inst.check(/* @__PURE__ */ _ipv6(ZodIPv6, params));
3917
+ inst.cidrv4 = (params) => inst.check(/* @__PURE__ */ _cidrv4(ZodCIDRv4, params));
3918
+ inst.cidrv6 = (params) => inst.check(/* @__PURE__ */ _cidrv6(ZodCIDRv6, params));
3919
+ inst.e164 = (params) => inst.check(/* @__PURE__ */ _e164(ZodE164, params));
3920
+ inst.datetime = (params) => inst.check(datetime(params));
3921
+ inst.date = (params) => inst.check(date(params));
3922
+ inst.time = (params) => inst.check(time(params));
3923
+ inst.duration = (params) => inst.check(duration(params));
3924
+ });
3925
+ function string(params) {
3926
+ return /* @__PURE__ */ _string(ZodString, params);
3927
+ }
3928
+ const ZodStringFormat = /*@__PURE__*/ $constructor("ZodStringFormat", (inst, def) => {
3929
+ $ZodStringFormat.init(inst, def);
3930
+ _ZodString.init(inst, def);
3931
+ });
3932
+ const ZodEmail = /*@__PURE__*/ $constructor("ZodEmail", (inst, def) => {
3933
+ $ZodEmail.init(inst, def);
3934
+ ZodStringFormat.init(inst, def);
3935
+ });
3936
+ const ZodGUID = /*@__PURE__*/ $constructor("ZodGUID", (inst, def) => {
3937
+ $ZodGUID.init(inst, def);
3938
+ ZodStringFormat.init(inst, def);
3939
+ });
3940
+ const ZodUUID = /*@__PURE__*/ $constructor("ZodUUID", (inst, def) => {
3941
+ $ZodUUID.init(inst, def);
3942
+ ZodStringFormat.init(inst, def);
3943
+ });
3944
+ const ZodURL = /*@__PURE__*/ $constructor("ZodURL", (inst, def) => {
3945
+ $ZodURL.init(inst, def);
3946
+ ZodStringFormat.init(inst, def);
3947
+ });
3948
+ const ZodEmoji = /*@__PURE__*/ $constructor("ZodEmoji", (inst, def) => {
3949
+ $ZodEmoji.init(inst, def);
3950
+ ZodStringFormat.init(inst, def);
3951
+ });
3952
+ const ZodNanoID = /*@__PURE__*/ $constructor("ZodNanoID", (inst, def) => {
3953
+ $ZodNanoID.init(inst, def);
3954
+ ZodStringFormat.init(inst, def);
3955
+ });
3956
+ /**
3957
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
3958
+ * (timestamps embedded in the id). Use {@link ZodCUID2} instead.
3959
+ * See https://github.com/paralleldrive/cuid.
3960
+ */
3961
+ const ZodCUID = /*@__PURE__*/ $constructor("ZodCUID", (inst, def) => {
3962
+ $ZodCUID.init(inst, def);
3963
+ ZodStringFormat.init(inst, def);
3964
+ });
3965
+ const ZodCUID2 = /*@__PURE__*/ $constructor("ZodCUID2", (inst, def) => {
3966
+ $ZodCUID2.init(inst, def);
3967
+ ZodStringFormat.init(inst, def);
3968
+ });
3969
+ const ZodULID = /*@__PURE__*/ $constructor("ZodULID", (inst, def) => {
3970
+ $ZodULID.init(inst, def);
3971
+ ZodStringFormat.init(inst, def);
3972
+ });
3973
+ const ZodXID = /*@__PURE__*/ $constructor("ZodXID", (inst, def) => {
3974
+ $ZodXID.init(inst, def);
3975
+ ZodStringFormat.init(inst, def);
3976
+ });
3977
+ const ZodKSUID = /*@__PURE__*/ $constructor("ZodKSUID", (inst, def) => {
3978
+ $ZodKSUID.init(inst, def);
3979
+ ZodStringFormat.init(inst, def);
3980
+ });
3981
+ const ZodIPv4 = /*@__PURE__*/ $constructor("ZodIPv4", (inst, def) => {
3982
+ $ZodIPv4.init(inst, def);
3983
+ ZodStringFormat.init(inst, def);
3984
+ });
3985
+ const ZodIPv6 = /*@__PURE__*/ $constructor("ZodIPv6", (inst, def) => {
3986
+ $ZodIPv6.init(inst, def);
3987
+ ZodStringFormat.init(inst, def);
3988
+ });
3989
+ const ZodCIDRv4 = /*@__PURE__*/ $constructor("ZodCIDRv4", (inst, def) => {
3990
+ $ZodCIDRv4.init(inst, def);
3991
+ ZodStringFormat.init(inst, def);
3992
+ });
3993
+ const ZodCIDRv6 = /*@__PURE__*/ $constructor("ZodCIDRv6", (inst, def) => {
3994
+ $ZodCIDRv6.init(inst, def);
3995
+ ZodStringFormat.init(inst, def);
3996
+ });
3997
+ const ZodBase64 = /*@__PURE__*/ $constructor("ZodBase64", (inst, def) => {
3998
+ $ZodBase64.init(inst, def);
3999
+ ZodStringFormat.init(inst, def);
4000
+ });
4001
+ const ZodBase64URL = /*@__PURE__*/ $constructor("ZodBase64URL", (inst, def) => {
4002
+ $ZodBase64URL.init(inst, def);
4003
+ ZodStringFormat.init(inst, def);
4004
+ });
4005
+ const ZodE164 = /*@__PURE__*/ $constructor("ZodE164", (inst, def) => {
4006
+ $ZodE164.init(inst, def);
4007
+ ZodStringFormat.init(inst, def);
4008
+ });
4009
+ const ZodJWT = /*@__PURE__*/ $constructor("ZodJWT", (inst, def) => {
4010
+ $ZodJWT.init(inst, def);
4011
+ ZodStringFormat.init(inst, def);
4012
+ });
4013
+ const ZodBoolean = /*@__PURE__*/ $constructor("ZodBoolean", (inst, def) => {
4014
+ $ZodBoolean.init(inst, def);
4015
+ ZodType.init(inst, def);
4016
+ inst._zod.processJSONSchema = (ctx, json, params) => booleanProcessor(inst, ctx, json, params);
4017
+ });
4018
+ function boolean(params) {
4019
+ return /* @__PURE__ */ _boolean(ZodBoolean, params);
4020
+ }
4021
+ const ZodUnknown = /*@__PURE__*/ $constructor("ZodUnknown", (inst, def) => {
4022
+ $ZodUnknown.init(inst, def);
4023
+ ZodType.init(inst, def);
4024
+ inst._zod.processJSONSchema = (ctx, json, params) => void 0;
4025
+ });
4026
+ function unknown() {
4027
+ return /* @__PURE__ */ _unknown(ZodUnknown);
4028
+ }
4029
+ const ZodNever = /*@__PURE__*/ $constructor("ZodNever", (inst, def) => {
4030
+ $ZodNever.init(inst, def);
4031
+ ZodType.init(inst, def);
4032
+ inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json, params);
4033
+ });
4034
+ function never(params) {
4035
+ return /* @__PURE__ */ _never(ZodNever, params);
4036
+ }
4037
+ const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def) => {
4038
+ $ZodArray.init(inst, def);
4039
+ ZodType.init(inst, def);
4040
+ inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
4041
+ inst.element = def.element;
4042
+ _installLazyMethods(inst, "ZodArray", {
4043
+ min(n, params) {
4044
+ return this.check(/* @__PURE__ */ _minLength(n, params));
4045
+ },
4046
+ nonempty(params) {
4047
+ return this.check(/* @__PURE__ */ _minLength(1, params));
4048
+ },
4049
+ max(n, params) {
4050
+ return this.check(/* @__PURE__ */ _maxLength(n, params));
4051
+ },
4052
+ length(n, params) {
4053
+ return this.check(/* @__PURE__ */ _length(n, params));
4054
+ },
4055
+ unwrap() {
4056
+ return this.element;
4057
+ }
4058
+ });
4059
+ });
4060
+ function array(element, params) {
4061
+ return /* @__PURE__ */ _array(ZodArray, element, params);
4062
+ }
4063
+ const ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def) => {
4064
+ $ZodObjectJIT.init(inst, def);
4065
+ ZodType.init(inst, def);
4066
+ inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
4067
+ defineLazy(inst, "shape", () => {
4068
+ return def.shape;
4069
+ });
4070
+ _installLazyMethods(inst, "ZodObject", {
4071
+ keyof() {
4072
+ return _enum(Object.keys(this._zod.def.shape));
4073
+ },
4074
+ catchall(catchall) {
4075
+ return this.clone({
4076
+ ...this._zod.def,
4077
+ catchall
4078
+ });
4079
+ },
4080
+ passthrough() {
4081
+ return this.clone({
4082
+ ...this._zod.def,
4083
+ catchall: unknown()
4084
+ });
4085
+ },
4086
+ loose() {
4087
+ return this.clone({
4088
+ ...this._zod.def,
4089
+ catchall: unknown()
4090
+ });
4091
+ },
4092
+ strict() {
4093
+ return this.clone({
4094
+ ...this._zod.def,
4095
+ catchall: never()
4096
+ });
4097
+ },
4098
+ strip() {
4099
+ return this.clone({
4100
+ ...this._zod.def,
4101
+ catchall: void 0
4102
+ });
4103
+ },
4104
+ extend(incoming) {
4105
+ return extend(this, incoming);
4106
+ },
4107
+ safeExtend(incoming) {
4108
+ return safeExtend(this, incoming);
4109
+ },
4110
+ merge(other) {
4111
+ return merge(this, other);
4112
+ },
4113
+ pick(mask) {
4114
+ return pick(this, mask);
4115
+ },
4116
+ omit(mask) {
4117
+ return omit(this, mask);
4118
+ },
4119
+ partial(...args) {
4120
+ return partial(ZodOptional, this, args[0]);
4121
+ },
4122
+ required(...args) {
4123
+ return required(ZodNonOptional, this, args[0]);
4124
+ }
4125
+ });
4126
+ });
4127
+ function object(shape, params) {
4128
+ const def = {
4129
+ type: "object",
4130
+ shape: shape ?? {},
4131
+ ...normalizeParams(params)
4132
+ };
4133
+ return new ZodObject(def);
4134
+ }
4135
+ const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
4136
+ $ZodUnion.init(inst, def);
4137
+ ZodType.init(inst, def);
4138
+ inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
4139
+ inst.options = def.options;
4140
+ });
4141
+ function union(options, params) {
4142
+ return new ZodUnion({
4143
+ type: "union",
4144
+ options,
4145
+ ...normalizeParams(params)
4146
+ });
4147
+ }
4148
+ const ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
4149
+ $ZodIntersection.init(inst, def);
4150
+ ZodType.init(inst, def);
4151
+ inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
4152
+ });
4153
+ function intersection(left, right) {
4154
+ return new ZodIntersection({
4155
+ type: "intersection",
4156
+ left,
4157
+ right
4158
+ });
4159
+ }
4160
+ const ZodEnum = /*@__PURE__*/ $constructor("ZodEnum", (inst, def) => {
4161
+ $ZodEnum.init(inst, def);
4162
+ ZodType.init(inst, def);
4163
+ inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json, params);
4164
+ inst.enum = def.entries;
4165
+ inst.options = Object.values(def.entries);
4166
+ const keys = new Set(Object.keys(def.entries));
4167
+ inst.extract = (values, params) => {
4168
+ const newEntries = {};
4169
+ for (const value of values) if (keys.has(value)) newEntries[value] = def.entries[value];
4170
+ else throw new Error(`Key ${value} not found in enum`);
4171
+ return new ZodEnum({
4172
+ ...def,
4173
+ checks: [],
4174
+ ...normalizeParams(params),
4175
+ entries: newEntries
4176
+ });
4177
+ };
4178
+ inst.exclude = (values, params) => {
4179
+ const newEntries = { ...def.entries };
4180
+ for (const value of values) if (keys.has(value)) delete newEntries[value];
4181
+ else throw new Error(`Key ${value} not found in enum`);
4182
+ return new ZodEnum({
4183
+ ...def,
4184
+ checks: [],
4185
+ ...normalizeParams(params),
4186
+ entries: newEntries
4187
+ });
4188
+ };
4189
+ });
4190
+ function _enum(values, params) {
4191
+ const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
4192
+ return new ZodEnum({
4193
+ type: "enum",
4194
+ entries,
4195
+ ...normalizeParams(params)
4196
+ });
4197
+ }
4198
+ const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
4199
+ $ZodTransform.init(inst, def);
4200
+ ZodType.init(inst, def);
4201
+ inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx, json, params);
4202
+ inst._zod.parse = (payload, _ctx) => {
4203
+ if (_ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
4204
+ payload.addIssue = (issue$1) => {
4205
+ if (typeof issue$1 === "string") payload.issues.push(issue(issue$1, payload.value, def));
4206
+ else {
4207
+ const _issue = issue$1;
4208
+ if (_issue.fatal) _issue.continue = false;
4209
+ _issue.code ?? (_issue.code = "custom");
4210
+ _issue.input ?? (_issue.input = payload.value);
4211
+ _issue.inst ?? (_issue.inst = inst);
4212
+ payload.issues.push(issue(_issue));
4213
+ }
4214
+ };
4215
+ const output = def.transform(payload.value, payload);
4216
+ if (output instanceof Promise) return output.then((output) => {
4217
+ payload.value = output;
4218
+ payload.fallback = true;
4219
+ return payload;
4220
+ });
4221
+ payload.value = output;
4222
+ payload.fallback = true;
4223
+ return payload;
4224
+ };
4225
+ });
4226
+ function transform(fn) {
4227
+ return new ZodTransform({
4228
+ type: "transform",
4229
+ transform: fn
4230
+ });
4231
+ }
4232
+ const ZodOptional = /*@__PURE__*/ $constructor("ZodOptional", (inst, def) => {
4233
+ $ZodOptional.init(inst, def);
4234
+ ZodType.init(inst, def);
4235
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
4236
+ inst.unwrap = () => inst._zod.def.innerType;
4237
+ });
4238
+ function optional(innerType) {
4239
+ return new ZodOptional({
4240
+ type: "optional",
4241
+ innerType
4242
+ });
4243
+ }
4244
+ const ZodExactOptional = /*@__PURE__*/ $constructor("ZodExactOptional", (inst, def) => {
4245
+ $ZodExactOptional.init(inst, def);
4246
+ ZodType.init(inst, def);
4247
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
4248
+ inst.unwrap = () => inst._zod.def.innerType;
4249
+ });
4250
+ function exactOptional(innerType) {
4251
+ return new ZodExactOptional({
4252
+ type: "optional",
4253
+ innerType
4254
+ });
4255
+ }
4256
+ const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
4257
+ $ZodNullable.init(inst, def);
4258
+ ZodType.init(inst, def);
4259
+ inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
4260
+ inst.unwrap = () => inst._zod.def.innerType;
4261
+ });
4262
+ function nullable(innerType) {
4263
+ return new ZodNullable({
4264
+ type: "nullable",
4265
+ innerType
4266
+ });
4267
+ }
4268
+ const ZodDefault = /*@__PURE__*/ $constructor("ZodDefault", (inst, def) => {
4269
+ $ZodDefault.init(inst, def);
4270
+ ZodType.init(inst, def);
4271
+ inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
4272
+ inst.unwrap = () => inst._zod.def.innerType;
4273
+ inst.removeDefault = inst.unwrap;
4274
+ });
4275
+ function _default(innerType, defaultValue) {
4276
+ return new ZodDefault({
4277
+ type: "default",
4278
+ innerType,
4279
+ get defaultValue() {
4280
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
4281
+ }
4282
+ });
4283
+ }
4284
+ const ZodPrefault = /*@__PURE__*/ $constructor("ZodPrefault", (inst, def) => {
4285
+ $ZodPrefault.init(inst, def);
4286
+ ZodType.init(inst, def);
4287
+ inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
4288
+ inst.unwrap = () => inst._zod.def.innerType;
4289
+ });
4290
+ function prefault(innerType, defaultValue) {
4291
+ return new ZodPrefault({
4292
+ type: "prefault",
4293
+ innerType,
4294
+ get defaultValue() {
4295
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
4296
+ }
4297
+ });
4298
+ }
4299
+ const ZodNonOptional = /*@__PURE__*/ $constructor("ZodNonOptional", (inst, def) => {
4300
+ $ZodNonOptional.init(inst, def);
4301
+ ZodType.init(inst, def);
4302
+ inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
4303
+ inst.unwrap = () => inst._zod.def.innerType;
4304
+ });
4305
+ function nonoptional(innerType, params) {
4306
+ return new ZodNonOptional({
4307
+ type: "nonoptional",
4308
+ innerType,
4309
+ ...normalizeParams(params)
4310
+ });
4311
+ }
4312
+ const ZodCatch = /*@__PURE__*/ $constructor("ZodCatch", (inst, def) => {
4313
+ $ZodCatch.init(inst, def);
4314
+ ZodType.init(inst, def);
4315
+ inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
4316
+ inst.unwrap = () => inst._zod.def.innerType;
4317
+ inst.removeCatch = inst.unwrap;
4318
+ });
4319
+ function _catch(innerType, catchValue) {
4320
+ return new ZodCatch({
4321
+ type: "catch",
4322
+ innerType,
4323
+ catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
4324
+ });
4325
+ }
4326
+ const ZodPipe = /*@__PURE__*/ $constructor("ZodPipe", (inst, def) => {
4327
+ $ZodPipe.init(inst, def);
4328
+ ZodType.init(inst, def);
4329
+ inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
4330
+ inst.in = def.in;
4331
+ inst.out = def.out;
4332
+ });
4333
+ function pipe(in_, out) {
4334
+ return new ZodPipe({
4335
+ type: "pipe",
4336
+ in: in_,
4337
+ out
4338
+ });
4339
+ }
4340
+ const ZodReadonly = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
4341
+ $ZodReadonly.init(inst, def);
4342
+ ZodType.init(inst, def);
4343
+ inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
4344
+ inst.unwrap = () => inst._zod.def.innerType;
4345
+ });
4346
+ function readonly(innerType) {
4347
+ return new ZodReadonly({
4348
+ type: "readonly",
4349
+ innerType
4350
+ });
4351
+ }
4352
+ const ZodCustom = /*@__PURE__*/ $constructor("ZodCustom", (inst, def) => {
4353
+ $ZodCustom.init(inst, def);
4354
+ ZodType.init(inst, def);
4355
+ inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx, json, params);
4356
+ });
4357
+ function refine(fn, _params = {}) {
4358
+ return /* @__PURE__ */ _refine(ZodCustom, fn, _params);
4359
+ }
4360
+ function superRefine(fn, params) {
4361
+ return /* @__PURE__ */ _superRefine(fn, params);
4362
+ }
4363
+ //#endregion
4364
+ //#region ../plugin-sdk/dist/index.js
4365
+ const PLUGIN_ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
4366
+ function definePlugin(definition) {
4367
+ validateDefinition(definition);
4368
+ return Object.freeze({
4369
+ ...definition,
4370
+ dependencies: Object.freeze([...definition.dependencies ?? []])
4371
+ });
4372
+ }
4373
+ function validateDefinition(definition) {
4374
+ if (!isRecord$1(definition)) throw new TypeError("definePlugin requires a plugin definition object.");
4375
+ if (typeof definition.id !== "string" || !PLUGIN_ID_PATTERN.test(definition.id)) throw new TypeError("Plugin id must use lowercase kebab-case.");
4376
+ if (typeof definition.setup !== "function") throw new TypeError("Plugin setup must be a function.");
4377
+ if (typeof definition.title !== "string" || definition.title.trim() === "") throw new TypeError("Plugin title must be a non-empty string.");
4378
+ const dependencies = definition.dependencies ?? [];
4379
+ if (!Array.isArray(dependencies) || dependencies.some((id) => typeof id !== "string" || !PLUGIN_ID_PATTERN.test(id) || id === definition.id) || new Set(dependencies).size !== dependencies.length) throw new TypeError("Plugin dependencies must be unique plugin ids and cannot include itself.");
4380
+ }
4381
+ function isRecord$1(value) {
4382
+ return value !== null && typeof value === "object" && !Array.isArray(value);
4383
+ }
4384
+ let PluginCommandEffect = /* @__PURE__ */ function(PluginCommandEffect) {
4385
+ PluginCommandEffect["Immediate"] = "immediate";
4386
+ PluginCommandEffect["LongRunning"] = "longRunning";
4387
+ return PluginCommandEffect;
4388
+ }({});
4389
+ let PluginCommandTransaction = /* @__PURE__ */ function(PluginCommandTransaction) {
4390
+ PluginCommandTransaction["None"] = "none";
4391
+ PluginCommandTransaction["ProjectMutation"] = "projectMutation";
4392
+ return PluginCommandTransaction;
4393
+ }({});
4394
+ let PluginSharedChangeKind = /* @__PURE__ */ function(PluginSharedChangeKind) {
4395
+ PluginSharedChangeKind["None"] = "none";
4396
+ PluginSharedChangeKind["Files"] = "files";
4397
+ return PluginSharedChangeKind;
4398
+ }({});
4399
+ let PluginContextExposure = /* @__PURE__ */ function(PluginContextExposure) {
4400
+ PluginContextExposure["Agent"] = "agent";
4401
+ PluginContextExposure["Internal"] = "internal";
4402
+ return PluginContextExposure;
4403
+ }({});
4404
+ //#endregion
4405
+ //#region src/plugin.ts
4406
+ /**
4407
+ * Uses Rulesync as the replaceable engine for project AI rules and client files.
4408
+ */
4409
+ const RULESYNC_PROGRAM = "rulesync";
4410
+ const RULESYNC_TIMEOUT_MILLISECONDS = 9e5;
4411
+ const RULES_DIRECTORY = "rules";
4412
+ const MCP_SERVER_NAME = "workbase";
4413
+ const MCP_PLUGIN_ID = "ai-mcp";
4414
+ const MCP_CONTEXT_ID = "client-configuration";
4415
+ const MAXIMUM_RESULT_TEXT_LENGTH = 5e4;
4416
+ const DEFAULT_TARGETS = ["codexcli", "claudecode"];
4417
+ const DEFAULT_FEATURES = [
4418
+ "rules",
4419
+ "mcp",
4420
+ "commands",
4421
+ "subagents",
4422
+ "skills"
4423
+ ];
4424
+ const CONFIGURATION_INPUT_SCHEMA = object({
4425
+ autoSync: boolean(),
4426
+ features: array(string().trim().min(1)).min(1),
4427
+ targets: array(string().trim().min(1)).min(1)
4428
+ }).strict();
4429
+ var plugin_default = definePlugin({
4430
+ id: "ai-rules",
4431
+ title: "AI Rules",
4432
+ setup(context, hooks) {
4433
+ const rulesRoot = path.join(context.project.root, RULES_DIRECTORY);
4434
+ let config = resolveConfig(context.config);
4435
+ const paths = resolvePaths({
4436
+ rulesRoot,
4437
+ workspaceRoot: context.workspace.root
4438
+ });
4439
+ const status = () => buildStatus({
4440
+ config,
4441
+ paths,
4442
+ state: context.services.store.getState()
4443
+ });
4444
+ const record = (result, invocation) => {
4445
+ invocation?.report?.({
4446
+ success: result.success,
4447
+ summary: result.operation,
4448
+ command: result.command,
4449
+ standardOutput: result.standardOutput,
4450
+ standardError: result.standardError,
4451
+ warnings: result.warnings
4452
+ });
4453
+ const lastOperation = {
4454
+ completedAt: result.completedAt,
4455
+ operation: result.operation,
4456
+ success: result.success
4457
+ };
4458
+ context.services.store.setState({ lastOperation });
4459
+ return result;
4460
+ };
4461
+ const runSimple = async ({ argumentsList, invocation, operation }) => record(await runRulesync({
4462
+ argumentsList,
4463
+ currentDirectory: paths.sourceRoot,
4464
+ invocation,
4465
+ operation
4466
+ }), invocation);
4467
+ const runGenerate = async (mode, invocation, features) => record(await generateRules({
4468
+ config,
4469
+ features,
4470
+ invocation,
4471
+ mode,
4472
+ paths
4473
+ }), invocation);
4474
+ const runSynchronization = async ({ initializationResult, invocation, operation, sourceArguments }) => record(await synchronizeRules({
4475
+ config,
4476
+ initializationResult,
4477
+ invocation,
4478
+ operation,
4479
+ paths,
4480
+ sourceArguments
4481
+ }), invocation);
4482
+ const initialize = async (invocation) => {
4483
+ mkdirSync(paths.sourceRoot, { recursive: true });
4484
+ const initializationResult = await runRulesync({
4485
+ argumentsList: ["--json", "init"],
4486
+ currentDirectory: paths.sourceRoot,
4487
+ invocation,
4488
+ operation: "initialize"
4489
+ });
4490
+ const result = initializationResult.success ? await runSynchronization({
4491
+ initializationResult,
4492
+ invocation,
4493
+ operation: "initialize"
4494
+ }) : record(createWorkflowResult({
4495
+ initialization: initializationResult,
4496
+ operation: "initialize"
4497
+ }), invocation);
4498
+ requireSuccessfulOperation(result);
4499
+ return {
4500
+ result,
4501
+ status: status()
4502
+ };
4503
+ };
4504
+ hooks.onWorkspaceProvision.tap("initialize", async (_payload, invocation) => {
4505
+ const result = isConfigured(paths) ? await runSynchronization({
4506
+ invocation,
4507
+ operation: "sync",
4508
+ sourceArguments: ["--frozen"]
4509
+ }) : (await initialize(invocation)).result;
4510
+ requireSuccessfulOperation(result);
4511
+ return {
4512
+ standardOutput: "AI Rules 已初始化。",
4513
+ warnings: result.warnings
4514
+ };
4515
+ });
4516
+ hooks.onWorkspaceActivate.tap("auto-sync", async (_payload, invocation) => {
4517
+ if (!isConfigured(paths)) requireSuccessfulOperation(missingConfigurationResult("sync", paths));
4518
+ if (!config.autoSync) return;
4519
+ const result = await runSynchronization({
4520
+ invocation,
4521
+ operation: "sync",
4522
+ sourceArguments: ["--frozen"]
4523
+ });
4524
+ requireSuccessfulOperation(result);
4525
+ return {
4526
+ standardOutput: "AI Rules 已自动同步。",
4527
+ warnings: result.warnings
4528
+ };
4529
+ });
4530
+ hooks.registerStatus({
4531
+ description: "返回 Rulesync 配置、同步目标和最近一次执行结果。",
4532
+ id: "sync",
4533
+ label: "AI Rules",
4534
+ resolve: () => status()
4535
+ });
4536
+ hooks.registerStatus({
4537
+ description: "只读校验已选择客户端是否已注入当前 Workbase MCP 连接。",
4538
+ id: "mcp",
4539
+ label: "MCP 注入",
4540
+ resolve: async (_input, invocation) => {
4541
+ const result = await generateRules({
4542
+ config,
4543
+ features: ["mcp"],
4544
+ invocation,
4545
+ mode: "preview",
4546
+ paths
4547
+ });
4548
+ const details = isRecord(result.details) ? result.details.data : null;
4549
+ requireSuccessfulOperation(result);
4550
+ if (!isRecord(details) || typeof details.hasDiff !== "boolean") throw new Error("Rulesync 未返回 MCP 客户端配置的差异状态。");
4551
+ return {
4552
+ injected: !details.hasDiff,
4553
+ targets: [...config.targets]
4554
+ };
4555
+ }
4556
+ });
4557
+ hooks.registerAgentContext({
4558
+ exposure: PluginContextExposure.Agent,
4559
+ description: "返回 AI Rules 的源目录、生成目标和同步状态,不包含规则正文。",
4560
+ id: "configuration",
4561
+ title: "AI Rules 配置上下文",
4562
+ resolve: () => status()
4563
+ });
4564
+ hooks.registerCommand({
4565
+ id: "configuration.save",
4566
+ input: CONFIGURATION_INPUT_SCHEMA,
4567
+ title: "保存 AI Rules 配置",
4568
+ description: "保存目标客户端、同步内容和自动同步设置。",
4569
+ transaction: PluginCommandTransaction.ProjectMutation,
4570
+ plan: () => ({
4571
+ kind: PluginSharedChangeKind.Files,
4572
+ paths: ["plugins/ai-rules/config.yaml"]
4573
+ }),
4574
+ run: async (input, invocation) => {
4575
+ const next = CONFIGURATION_INPUT_SCHEMA.parse(input);
4576
+ config = resolveConfig(await invocation.services.config.replace({
4577
+ autoSync: next.autoSync,
4578
+ features: uniqueStrings(next.features),
4579
+ targets: uniqueStrings(next.targets)
4580
+ }));
4581
+ invocation.services.toast.show("AI Rules 配置已保存。", "success");
4582
+ return status();
4583
+ }
4584
+ });
4585
+ hooks.registerCommand({
4586
+ id: "initialize",
4587
+ title: "初始化 AI Rules",
4588
+ description: "在项目 rules 目录创建 Rulesync 配置,准备来源并同步当前 Workspace。",
4589
+ transaction: PluginCommandTransaction.ProjectMutation,
4590
+ plan: () => ({ kind: PluginSharedChangeKind.None }),
4591
+ run: async (_input, invocation) => {
4592
+ return initialize(invocation);
4593
+ }
4594
+ });
4595
+ hooks.registerCommand({
4596
+ agent: {
4597
+ callable: true,
4598
+ readOnly: true
4599
+ },
4600
+ id: "doctor",
4601
+ title: "检查 AI Rules 配置",
4602
+ description: "运行 Rulesync doctor,只读诊断配置、目标和源目录。",
4603
+ run: async (_input, invocation) => {
4604
+ return {
4605
+ result: await runSimple({
4606
+ argumentsList: ["--json", "doctor"],
4607
+ invocation,
4608
+ operation: "doctor"
4609
+ }),
4610
+ status: status()
4611
+ };
4612
+ }
4613
+ });
4614
+ hooks.registerCommand({
4615
+ agent: {
4616
+ callable: true,
4617
+ readOnly: true
4618
+ },
4619
+ id: "preview",
4620
+ title: "预览 AI Rules 同步",
4621
+ description: "使用 Rulesync dry-run 预览将生成或更新的客户端文件。",
4622
+ run: async (_input, invocation) => ({
4623
+ result: await runGenerate("preview", invocation),
4624
+ status: status()
4625
+ })
4626
+ });
4627
+ hooks.registerCommand({
4628
+ agent: {
4629
+ callable: true,
4630
+ readOnly: true
4631
+ },
4632
+ id: "check",
4633
+ title: "校验 AI Rules 同步状态",
4634
+ description: "检查当前客户端文件是否与 Rulesync 源保持一致。",
4635
+ run: async (_input, invocation) => ({
4636
+ result: await runGenerate("check", invocation),
4637
+ status: status()
4638
+ })
4639
+ });
4640
+ hooks.registerCommand({
4641
+ effect: PluginCommandEffect.LongRunning,
4642
+ id: "install",
4643
+ title: "安装 AI Rules 来源",
4644
+ description: "根据 rulesync.jsonc 和锁文件安装或恢复声明的规则与 Skills 来源。",
4645
+ transaction: PluginCommandTransaction.ProjectMutation,
4646
+ plan: () => ({ kind: PluginSharedChangeKind.None }),
4647
+ run: async (_input, invocation) => {
4648
+ const result = await runSimple({
4649
+ argumentsList: ["--json", "install"],
4650
+ invocation,
4651
+ operation: "install"
4652
+ });
4653
+ requireSuccessfulOperation(result);
4654
+ return {
4655
+ result,
4656
+ status: status()
4657
+ };
4658
+ }
4659
+ });
4660
+ hooks.registerCommand({
4661
+ effect: PluginCommandEffect.LongRunning,
4662
+ id: "sources.update",
4663
+ title: "更新 AI Rules 远端来源",
4664
+ description: "重新解析远端引用并更新锁文件、规则与 Skills。",
4665
+ transaction: PluginCommandTransaction.ProjectMutation,
4666
+ plan: () => ({ kind: PluginSharedChangeKind.None }),
4667
+ run: async (_input, invocation) => {
4668
+ const result = await runSynchronization({
4669
+ invocation,
4670
+ operation: "sources.update",
4671
+ sourceArguments: ["--update"]
4672
+ });
4673
+ requireSuccessfulOperation(result);
4674
+ return {
4675
+ result,
4676
+ status: status()
4677
+ };
4678
+ }
4679
+ });
4680
+ hooks.registerCommand({
4681
+ effect: PluginCommandEffect.LongRunning,
4682
+ id: "sync",
4683
+ title: "同步 AI Rules",
4684
+ description: "组装 Rules、MCP、Commands、Subagents 和 Skills 并写入当前 Workspace。",
4685
+ transaction: PluginCommandTransaction.ProjectMutation,
4686
+ plan: () => ({ kind: PluginSharedChangeKind.None }),
4687
+ run: async (_input, invocation) => {
4688
+ const result = await runSynchronization({
4689
+ invocation,
4690
+ operation: "sync"
4691
+ });
4692
+ requireSuccessfulOperation(result);
4693
+ return {
4694
+ result,
4695
+ status: status()
4696
+ };
4697
+ }
4698
+ });
4699
+ hooks.registerCommand({
4700
+ effect: PluginCommandEffect.LongRunning,
4701
+ id: "mcp.inject",
4702
+ title: "注入 Workbase MCP",
4703
+ description: "通过 Rulesync 将当前 Workbase MCP 写入已配置的 AI 客户端。",
4704
+ run: async (_input, invocation) => {
4705
+ const result = await runGenerate("mcp.inject", invocation, ["mcp"]);
4706
+ requireSuccessfulOperation(result);
4707
+ return {
4708
+ result,
4709
+ status: status()
4710
+ };
4711
+ }
4712
+ });
4713
+ hooks.registerView({
4714
+ description: "诊断、预览并同步当前 Workspace 的 AI 客户端上下文。",
4715
+ entry: "dist/ui/index.html",
4716
+ id: "workspace",
4717
+ slot: "workspace.tab"
4718
+ });
4719
+ }
4720
+ });
4721
+ async function generateRules({ config, features: requestedFeatures, invocation, mode, paths }) {
4722
+ if (!isConfigured(paths)) return missingConfigurationResult(mode, paths);
4723
+ let features = requestedFeatures ?? config.features;
4724
+ const warnings = [];
4725
+ const includesMcp = features.includes("mcp");
4726
+ const mcpInputRoot = includesMcp ? createMcpInputRoot(paths, await resolveMcpConfiguration(invocation)) : null;
4727
+ const inputRoot = mcpInputRoot ?? paths.sourceRoot;
4728
+ if (includesMcp && !mcpInputRoot) {
4729
+ features = features.filter((feature) => feature !== "mcp");
4730
+ warnings.push("Workbase MCP 当前不可用,本次未修改 MCP 客户端配置。");
4731
+ }
4732
+ if (features.length === 0) return {
4733
+ command: RULESYNC_PROGRAM,
4734
+ completedAt: (/* @__PURE__ */ new Date()).toISOString(),
4735
+ details: null,
4736
+ operation: mode,
4737
+ standardError: "Workbase MCP 当前不可用,未修改客户端配置。",
4738
+ standardOutput: "",
4739
+ success: false,
4740
+ warnings
4741
+ };
4742
+ const argumentsList = [
4743
+ "--json",
4744
+ "generate",
4745
+ "--targets",
4746
+ config.targets.join(","),
4747
+ "--features",
4748
+ features.join(","),
4749
+ "--input-root",
4750
+ inputRoot,
4751
+ "--output-roots",
4752
+ paths.workspaceRoot
4753
+ ];
4754
+ if (mode === "preview") argumentsList.push("--dry-run");
4755
+ if (mode === "check") argumentsList.push("--check");
4756
+ try {
4757
+ return {
4758
+ ...await runRulesync({
4759
+ argumentsList,
4760
+ currentDirectory: paths.sourceRoot,
4761
+ invocation,
4762
+ operation: mode
4763
+ }),
4764
+ warnings
4765
+ };
4766
+ } finally {
4767
+ if (mcpInputRoot) rmSync(mcpInputRoot, {
4768
+ force: true,
4769
+ recursive: true
4770
+ });
4771
+ }
4772
+ }
4773
+ async function synchronizeRules({ config, initializationResult, invocation, operation, paths, sourceArguments = [] }) {
4774
+ if (!isConfigured(paths)) return missingConfigurationResult(operation, paths);
4775
+ const sources = await runRulesync({
4776
+ argumentsList: [
4777
+ "--json",
4778
+ "install",
4779
+ ...sourceArguments
4780
+ ],
4781
+ currentDirectory: paths.sourceRoot,
4782
+ invocation,
4783
+ operation
4784
+ });
4785
+ if (!sources.success) return createWorkflowResult({
4786
+ initialization: initializationResult,
4787
+ operation,
4788
+ sources
4789
+ });
4790
+ return createWorkflowResult({
4791
+ generation: await generateRules({
4792
+ config,
4793
+ invocation,
4794
+ mode: "sync",
4795
+ paths
4796
+ }),
4797
+ initialization: initializationResult,
4798
+ operation,
4799
+ sources
4800
+ });
4801
+ }
4802
+ function createWorkflowResult({ generation, initialization, operation, sources }) {
4803
+ const results = [
4804
+ initialization,
4805
+ sources,
4806
+ generation
4807
+ ].filter((result) => result !== void 0);
4808
+ const finalResult = results.at(-1);
4809
+ return {
4810
+ command: results.map(({ command }) => command).filter(Boolean).join(" → "),
4811
+ completedAt: finalResult?.completedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4812
+ details: {
4813
+ generation: generation?.details ?? null,
4814
+ initialization: initialization?.details ?? null,
4815
+ sources: sources?.details ?? null
4816
+ },
4817
+ operation,
4818
+ standardError: joinResultText(results.map(({ standardError }) => standardError)),
4819
+ standardOutput: joinResultText(results.map(({ standardOutput }) => standardOutput)),
4820
+ success: results.length > 0 && results.every(({ success }) => success),
4821
+ warnings: uniqueStrings(results.flatMap(({ warnings }) => warnings))
4822
+ };
4823
+ }
4824
+ function joinResultText(values) {
4825
+ return values.map((value) => value.trim()).filter(Boolean).join("\n");
4826
+ }
4827
+ async function runRulesync({ argumentsList, currentDirectory, invocation, operation }) {
4828
+ return normalizeResult(operation, await invocation.process.run({
4829
+ arguments: argumentsList,
4830
+ currentDirectory,
4831
+ environment: { NO_COLOR: "1" },
4832
+ program: RULESYNC_PROGRAM,
4833
+ timeoutMilliseconds: RULESYNC_TIMEOUT_MILLISECONDS
4834
+ }, invocation.signal));
4835
+ }
4836
+ function normalizeResult(operation, result) {
4837
+ return {
4838
+ command: result.command,
4839
+ completedAt: (/* @__PURE__ */ new Date()).toISOString(),
4840
+ details: parseJsonOutput(result),
4841
+ operation,
4842
+ standardError: truncate(result.standardError),
4843
+ standardOutput: truncate(result.standardOutput),
4844
+ success: !result.failed,
4845
+ warnings: []
4846
+ };
4847
+ }
4848
+ function parseJsonOutput(result) {
4849
+ const candidates = [result.standardOutput, result.standardError].map((value) => value.trim()).filter(Boolean);
4850
+ for (const candidate of candidates) try {
4851
+ return JSON.parse(candidate);
4852
+ } catch {}
4853
+ return null;
4854
+ }
4855
+ async function resolveMcpConfiguration(invocation) {
4856
+ try {
4857
+ const value = await invocation.services.capabilities.resolveContext({
4858
+ id: MCP_CONTEXT_ID,
4859
+ pluginId: MCP_PLUGIN_ID
4860
+ });
4861
+ if (!isRecord(value)) return null;
4862
+ const endpoint = value.endpoint;
4863
+ const token = value.token;
4864
+ return typeof endpoint === "string" && typeof token === "string" ? {
4865
+ endpoint,
4866
+ token
4867
+ } : null;
4868
+ } catch {
4869
+ return null;
4870
+ }
4871
+ }
4872
+ function createMcpInputRoot(paths, configuration) {
4873
+ if (!configuration) return null;
4874
+ const temporaryRoot = mkdtempSync(path.join(os.tmpdir(), "workbase-ai-rules-"));
4875
+ const rulesRoot = path.join(temporaryRoot, ".rulesync");
4876
+ const mcpPath = path.join(rulesRoot, "mcp.jsonc");
4877
+ try {
4878
+ cpSync(path.join(paths.sourceRoot, ".rulesync"), rulesRoot, { recursive: true });
4879
+ const source = readMcpSource(rulesRoot);
4880
+ const mcpServers = isRecord(source.mcpServers) ? source.mcpServers : {};
4881
+ const merged = {
4882
+ ...source,
4883
+ $schema: source.$schema ?? "https://github.com/dyoshikawa/rulesync/releases/latest/download/mcp-schema.json",
4884
+ mcpServers: {
4885
+ ...mcpServers,
4886
+ [MCP_SERVER_NAME]: {
4887
+ description: "当前 Workbase Workspace 的插件能力与系统上下文",
4888
+ headers: { Authorization: `Bearer ${configuration.token}` },
4889
+ type: "http",
4890
+ url: configuration.endpoint
4891
+ }
4892
+ }
4893
+ };
4894
+ writeFileSync(mcpPath, `${JSON.stringify(merged, null, 2)}\n`, "utf8");
4895
+ return temporaryRoot;
4896
+ } catch (error) {
4897
+ rmSync(temporaryRoot, {
4898
+ force: true,
4899
+ recursive: true
4900
+ });
4901
+ throw error;
4902
+ }
4903
+ }
4904
+ function readMcpSource(sourceRoot) {
4905
+ const sourcePath = [path.join(sourceRoot, "mcp.jsonc"), path.join(sourceRoot, "mcp.json")].find(existsSync);
4906
+ if (!sourcePath) return {};
4907
+ const errors = [];
4908
+ const value = parse$1(readFileSync(sourcePath, "utf8"), errors, { allowTrailingComma: true });
4909
+ if (errors.length > 0 || !isRecord(value)) throw new Error(`Rulesync MCP 配置无法解析:${sourcePath}`);
4910
+ return value;
4911
+ }
4912
+ function buildStatus({ config, paths, state }) {
4913
+ return {
4914
+ autoSync: config.autoSync,
4915
+ configured: isConfigured(paths),
4916
+ configPath: paths.configPath,
4917
+ features: [...config.features],
4918
+ lastOperation: isStoredOperation(state.lastOperation) ? state.lastOperation : null,
4919
+ sourceRoot: paths.sourceRoot,
4920
+ targets: [...config.targets],
4921
+ workspaceRoot: paths.workspaceRoot
4922
+ };
4923
+ }
4924
+ function resolveConfig(config) {
4925
+ return {
4926
+ autoSync: typeof config.autoSync === "boolean" ? config.autoSync : true,
4927
+ features: stringList(config.features, DEFAULT_FEATURES),
4928
+ targets: stringList(config.targets, DEFAULT_TARGETS)
4929
+ };
4930
+ }
4931
+ function stringList(value, fallback) {
4932
+ if (!Array.isArray(value)) return fallback;
4933
+ const values = value.filter((entry) => typeof entry === "string").map((entry) => entry.trim()).filter(Boolean);
4934
+ return values.length > 0 ? uniqueStrings(values) : fallback;
4935
+ }
4936
+ function uniqueStrings(values) {
4937
+ return [...new Set(values)];
4938
+ }
4939
+ function resolvePaths({ rulesRoot, workspaceRoot }) {
4940
+ return {
4941
+ configPath: path.join(rulesRoot, "rulesync.jsonc"),
4942
+ sourceRoot: rulesRoot,
4943
+ workspaceRoot
4944
+ };
4945
+ }
4946
+ function isConfigured(paths) {
4947
+ return existsSync(paths.configPath) && existsSync(path.join(paths.sourceRoot, ".rulesync"));
4948
+ }
4949
+ function missingConfigurationResult(operation, paths) {
4950
+ return {
4951
+ command: RULESYNC_PROGRAM,
4952
+ completedAt: (/* @__PURE__ */ new Date()).toISOString(),
4953
+ details: null,
4954
+ operation,
4955
+ standardError: `请先初始化 AI Rules:${paths.configPath}`,
4956
+ standardOutput: "",
4957
+ success: false,
4958
+ warnings: []
4959
+ };
4960
+ }
4961
+ function requireSuccessfulOperation(result) {
4962
+ if (result.success) return;
4963
+ throw Object.assign(new Error(result.standardError || result.standardOutput || `Rulesync ${result.operation} failed.`), {
4964
+ code: "rulesync_failed",
4965
+ details: { operationResult: result },
4966
+ retryable: false
4967
+ });
4968
+ }
4969
+ function isStoredOperation(value) {
4970
+ return isRecord(value) && typeof value.completedAt === "string" && typeof value.operation === "string" && typeof value.success === "boolean";
4971
+ }
4972
+ function isRecord(value) {
4973
+ return value !== null && typeof value === "object" && !Array.isArray(value);
4974
+ }
4975
+ function truncate(value) {
4976
+ return value.length <= MAXIMUM_RESULT_TEXT_LENGTH ? value : `${value.slice(0, MAXIMUM_RESULT_TEXT_LENGTH)}\n[后续输出已截断]`;
4977
+ }
4978
+ //#endregion
4979
+ export { plugin_default as default };