@pi-oxide/extension-js 0.12.0 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/worker.js ADDED
@@ -0,0 +1,4734 @@
1
+ import er, { setLogLevel as Ye, ExtensionSession as tr, registerJsCallBatch as rr, takeCachedVfsWriteBase64 as nr, webFsReadBase64 as sr, clearVfsWriteCache as ir } from "./extension_js.js";
2
+ const je = {
3
+ trace: 0,
4
+ debug: 1,
5
+ info: 2,
6
+ warn: 3,
7
+ error: 4,
8
+ none: 5
9
+ }, ar = [
10
+ "trace",
11
+ "debug",
12
+ "info",
13
+ "warn",
14
+ "error",
15
+ "none"
16
+ ];
17
+ function or(t) {
18
+ const e = Math.max(0, Math.min(5, Math.round(t)));
19
+ return ar[e] ?? "error";
20
+ }
21
+ let dt = "trace", Ke = null;
22
+ function cr(t) {
23
+ dt = t, Ke && Ke(je[t]);
24
+ }
25
+ function dr(t) {
26
+ Ke = t, t(je[dt]);
27
+ }
28
+ function lr(t) {
29
+ return je[t] >= je[dt];
30
+ }
31
+ function Nt(t, e = "info") {
32
+ var r;
33
+ if (t === null) return "null";
34
+ if (t === void 0) return "undefined";
35
+ if (typeof t == "string") return t;
36
+ if (typeof t == "number" || typeof t == "boolean")
37
+ return String(t);
38
+ if (typeof t == "bigint") return `${t}n`;
39
+ if (t instanceof Error) {
40
+ const n = e === "debug" || e === "trace" ? t.stack : (r = t.stack) == null ? void 0 : r.split(`
41
+ `)[0];
42
+ return JSON.stringify({ message: t.message, name: t.name, stack: n });
43
+ }
44
+ if (typeof t == "function") return "[Function]";
45
+ if (typeof t == "symbol") return String(t);
46
+ if (typeof t == "object")
47
+ try {
48
+ return JSON.stringify(t);
49
+ } catch (n) {
50
+ return n instanceof TypeError && n.message.includes("circular") ? "[Circular]" : `[Unserializable: ${n instanceof Error ? n.message : String(n)}]`;
51
+ }
52
+ return String(t);
53
+ }
54
+ function ur(t) {
55
+ return `[extension-js][${t}]`;
56
+ }
57
+ function fr(t, e) {
58
+ if (!t) return "";
59
+ const r = [];
60
+ try {
61
+ for (const [n, s] of Object.entries(t))
62
+ r.push(`${n}=${Nt(s, e)}`);
63
+ } catch {
64
+ return " metadata=[unreadable]";
65
+ }
66
+ return r.length > 0 ? ` ${r.join(" ")}` : "";
67
+ }
68
+ function _e(t, e) {
69
+ return e.length === 0 ? { event: t } : e.length === 1 && typeof e[0] == "object" && e[0] !== null && !Array.isArray(e[0]) ? { event: t, metadata: e[0] } : {
70
+ event: t,
71
+ metadata: { _args: e.map((r) => Nt(r)).join(" ") }
72
+ };
73
+ }
74
+ class lt {
75
+ constructor(e = "root") {
76
+ this.namespace = e;
77
+ }
78
+ log(e, r, n) {
79
+ try {
80
+ if (!lr(e)) return;
81
+ const s = ur(this.namespace), i = fr(n, e), c = `${s} ${r}${i}`;
82
+ switch (e) {
83
+ case "trace":
84
+ case "debug":
85
+ case "info":
86
+ console.log(c);
87
+ break;
88
+ case "warn":
89
+ console.warn(c);
90
+ break;
91
+ case "error":
92
+ console.error(c);
93
+ break;
94
+ case "none":
95
+ break;
96
+ default: {
97
+ const a = e;
98
+ break;
99
+ }
100
+ }
101
+ } catch {
102
+ }
103
+ }
104
+ trace(e, ...r) {
105
+ const { event: n, metadata: s } = _e(e, r);
106
+ this.log("trace", n, s);
107
+ }
108
+ debug(e, ...r) {
109
+ const { event: n, metadata: s } = _e(e, r);
110
+ this.log("debug", n, s);
111
+ }
112
+ info(e, ...r) {
113
+ const { event: n, metadata: s } = _e(e, r);
114
+ this.log("info", n, s);
115
+ }
116
+ warn(e, ...r) {
117
+ const { event: n, metadata: s } = _e(e, r);
118
+ this.log("warn", n, s);
119
+ }
120
+ error(e, ...r) {
121
+ const { event: n, metadata: s } = _e(e, r);
122
+ this.log("error", n, s);
123
+ }
124
+ child(e) {
125
+ return new lt(`${this.namespace}.${e}`);
126
+ }
127
+ timer(e, r, n = "info") {
128
+ const s = typeof performance < "u" && performance.now, i = s ? performance.now() : Date.now();
129
+ return (c) => {
130
+ try {
131
+ const a = s ? performance.now() : Date.now(), h = Math.round(a - i), d = {
132
+ ...r,
133
+ ...c,
134
+ duration_ms: h
135
+ };
136
+ this.log(n, e, d);
137
+ } catch {
138
+ }
139
+ };
140
+ }
141
+ }
142
+ const C = new lt("root");
143
+ function he(t) {
144
+ return t == null ? {} : t instanceof Map ? Object.fromEntries(
145
+ [...t.entries()].map(([e, r]) => [
146
+ e,
147
+ he(r)
148
+ ])
149
+ ) : Array.isArray(t) ? t.map(he) : t;
150
+ }
151
+ function hr(t) {
152
+ return {
153
+ action: t.action,
154
+ namespace: t.namespace,
155
+ name: t.name,
156
+ publicName: t.publicName,
157
+ description: t.description,
158
+ fields: t.fields,
159
+ aliases: (t.aliases ?? []).map((e) => ({
160
+ namespace: e.namespace,
161
+ name: e.name,
162
+ fields: e.fields
163
+ })),
164
+ paramsDoc: t.paramsDoc.map((e) => ({
165
+ name: e.name,
166
+ type: e.type,
167
+ required: e.required,
168
+ description: e.description
169
+ })),
170
+ returnsDoc: {
171
+ type: t.returnsDoc.type,
172
+ description: t.returnsDoc.description
173
+ },
174
+ errorCode: t.errorCode,
175
+ errorCategory: t.errorCategory ?? null,
176
+ permission: t.permission ?? null,
177
+ example: t.example ?? null,
178
+ prerequisites: t.prerequisites ?? null,
179
+ notes: t.notes ?? null,
180
+ tags: t.tags ?? null,
181
+ relatedApis: t.relatedApis ?? null
182
+ };
183
+ }
184
+ var E;
185
+ (function(t) {
186
+ t.assertEqual = (s) => {
187
+ };
188
+ function e(s) {
189
+ }
190
+ t.assertIs = e;
191
+ function r(s) {
192
+ throw new Error();
193
+ }
194
+ t.assertNever = r, t.arrayToEnum = (s) => {
195
+ const i = {};
196
+ for (const c of s)
197
+ i[c] = c;
198
+ return i;
199
+ }, t.getValidEnumValues = (s) => {
200
+ const i = t.objectKeys(s).filter((a) => typeof s[s[a]] != "number"), c = {};
201
+ for (const a of i)
202
+ c[a] = s[a];
203
+ return t.objectValues(c);
204
+ }, t.objectValues = (s) => t.objectKeys(s).map(function(i) {
205
+ return s[i];
206
+ }), t.objectKeys = typeof Object.keys == "function" ? (s) => Object.keys(s) : (s) => {
207
+ const i = [];
208
+ for (const c in s)
209
+ Object.prototype.hasOwnProperty.call(s, c) && i.push(c);
210
+ return i;
211
+ }, t.find = (s, i) => {
212
+ for (const c of s)
213
+ if (i(c))
214
+ return c;
215
+ }, t.isInteger = typeof Number.isInteger == "function" ? (s) => Number.isInteger(s) : (s) => typeof s == "number" && Number.isFinite(s) && Math.floor(s) === s;
216
+ function n(s, i = " | ") {
217
+ return s.map((c) => typeof c == "string" ? `'${c}'` : c).join(i);
218
+ }
219
+ t.joinValues = n, t.jsonStringifyReplacer = (s, i) => typeof i == "bigint" ? i.toString() : i;
220
+ })(E || (E = {}));
221
+ var _t;
222
+ (function(t) {
223
+ t.mergeShapes = (e, r) => ({
224
+ ...e,
225
+ ...r
226
+ // second overwrites first
227
+ });
228
+ })(_t || (_t = {}));
229
+ const g = E.arrayToEnum([
230
+ "string",
231
+ "nan",
232
+ "number",
233
+ "integer",
234
+ "float",
235
+ "boolean",
236
+ "date",
237
+ "bigint",
238
+ "symbol",
239
+ "function",
240
+ "undefined",
241
+ "null",
242
+ "array",
243
+ "object",
244
+ "unknown",
245
+ "promise",
246
+ "void",
247
+ "never",
248
+ "map",
249
+ "set"
250
+ ]), te = (t) => {
251
+ switch (typeof t) {
252
+ case "undefined":
253
+ return g.undefined;
254
+ case "string":
255
+ return g.string;
256
+ case "number":
257
+ return Number.isNaN(t) ? g.nan : g.number;
258
+ case "boolean":
259
+ return g.boolean;
260
+ case "function":
261
+ return g.function;
262
+ case "bigint":
263
+ return g.bigint;
264
+ case "symbol":
265
+ return g.symbol;
266
+ case "object":
267
+ return Array.isArray(t) ? g.array : t === null ? g.null : t.then && typeof t.then == "function" && t.catch && typeof t.catch == "function" ? g.promise : typeof Map < "u" && t instanceof Map ? g.map : typeof Set < "u" && t instanceof Set ? g.set : typeof Date < "u" && t instanceof Date ? g.date : g.object;
268
+ default:
269
+ return g.unknown;
270
+ }
271
+ }, u = E.arrayToEnum([
272
+ "invalid_type",
273
+ "invalid_literal",
274
+ "custom",
275
+ "invalid_union",
276
+ "invalid_union_discriminator",
277
+ "invalid_enum_value",
278
+ "unrecognized_keys",
279
+ "invalid_arguments",
280
+ "invalid_return_type",
281
+ "invalid_date",
282
+ "invalid_string",
283
+ "too_small",
284
+ "too_big",
285
+ "invalid_intersection_types",
286
+ "not_multiple_of",
287
+ "not_finite"
288
+ ]);
289
+ class j extends Error {
290
+ get errors() {
291
+ return this.issues;
292
+ }
293
+ constructor(e) {
294
+ super(), this.issues = [], this.addIssue = (n) => {
295
+ this.issues = [...this.issues, n];
296
+ }, this.addIssues = (n = []) => {
297
+ this.issues = [...this.issues, ...n];
298
+ };
299
+ const r = new.target.prototype;
300
+ Object.setPrototypeOf ? Object.setPrototypeOf(this, r) : this.__proto__ = r, this.name = "ZodError", this.issues = e;
301
+ }
302
+ format(e) {
303
+ const r = e || function(i) {
304
+ return i.message;
305
+ }, n = { _errors: [] }, s = (i) => {
306
+ for (const c of i.issues)
307
+ if (c.code === "invalid_union")
308
+ c.unionErrors.map(s);
309
+ else if (c.code === "invalid_return_type")
310
+ s(c.returnTypeError);
311
+ else if (c.code === "invalid_arguments")
312
+ s(c.argumentsError);
313
+ else if (c.path.length === 0)
314
+ n._errors.push(r(c));
315
+ else {
316
+ let a = n, h = 0;
317
+ for (; h < c.path.length; ) {
318
+ const d = c.path[h];
319
+ h === c.path.length - 1 ? (a[d] = a[d] || { _errors: [] }, a[d]._errors.push(r(c))) : a[d] = a[d] || { _errors: [] }, a = a[d], h++;
320
+ }
321
+ }
322
+ };
323
+ return s(this), n;
324
+ }
325
+ static assert(e) {
326
+ if (!(e instanceof j))
327
+ throw new Error(`Not a ZodError: ${e}`);
328
+ }
329
+ toString() {
330
+ return this.message;
331
+ }
332
+ get message() {
333
+ return JSON.stringify(this.issues, E.jsonStringifyReplacer, 2);
334
+ }
335
+ get isEmpty() {
336
+ return this.issues.length === 0;
337
+ }
338
+ flatten(e = (r) => r.message) {
339
+ const r = {}, n = [];
340
+ for (const s of this.issues)
341
+ if (s.path.length > 0) {
342
+ const i = s.path[0];
343
+ r[i] = r[i] || [], r[i].push(e(s));
344
+ } else
345
+ n.push(e(s));
346
+ return { formErrors: n, fieldErrors: r };
347
+ }
348
+ get formErrors() {
349
+ return this.flatten();
350
+ }
351
+ }
352
+ j.create = (t) => new j(t);
353
+ const xe = (t, e) => {
354
+ let r;
355
+ switch (t.code) {
356
+ case u.invalid_type:
357
+ t.received === g.undefined ? r = "Required" : r = `Expected ${t.expected}, received ${t.received}`;
358
+ break;
359
+ case u.invalid_literal:
360
+ r = `Invalid literal value, expected ${JSON.stringify(t.expected, E.jsonStringifyReplacer)}`;
361
+ break;
362
+ case u.unrecognized_keys:
363
+ r = `Unrecognized key(s) in object: ${E.joinValues(t.keys, ", ")}`;
364
+ break;
365
+ case u.invalid_union:
366
+ r = "Invalid input";
367
+ break;
368
+ case u.invalid_union_discriminator:
369
+ r = `Invalid discriminator value. Expected ${E.joinValues(t.options)}`;
370
+ break;
371
+ case u.invalid_enum_value:
372
+ r = `Invalid enum value. Expected ${E.joinValues(t.options)}, received '${t.received}'`;
373
+ break;
374
+ case u.invalid_arguments:
375
+ r = "Invalid function arguments";
376
+ break;
377
+ case u.invalid_return_type:
378
+ r = "Invalid function return type";
379
+ break;
380
+ case u.invalid_date:
381
+ r = "Invalid date";
382
+ break;
383
+ case u.invalid_string:
384
+ typeof t.validation == "object" ? "includes" in t.validation ? (r = `Invalid input: must include "${t.validation.includes}"`, typeof t.validation.position == "number" && (r = `${r} at one or more positions greater than or equal to ${t.validation.position}`)) : "startsWith" in t.validation ? r = `Invalid input: must start with "${t.validation.startsWith}"` : "endsWith" in t.validation ? r = `Invalid input: must end with "${t.validation.endsWith}"` : E.assertNever(t.validation) : t.validation !== "regex" ? r = `Invalid ${t.validation}` : r = "Invalid";
385
+ break;
386
+ case u.too_small:
387
+ t.type === "array" ? r = `Array must contain ${t.exact ? "exactly" : t.inclusive ? "at least" : "more than"} ${t.minimum} element(s)` : t.type === "string" ? r = `String must contain ${t.exact ? "exactly" : t.inclusive ? "at least" : "over"} ${t.minimum} character(s)` : t.type === "number" ? r = `Number must be ${t.exact ? "exactly equal to " : t.inclusive ? "greater than or equal to " : "greater than "}${t.minimum}` : t.type === "bigint" ? r = `Number must be ${t.exact ? "exactly equal to " : t.inclusive ? "greater than or equal to " : "greater than "}${t.minimum}` : t.type === "date" ? r = `Date must be ${t.exact ? "exactly equal to " : t.inclusive ? "greater than or equal to " : "greater than "}${new Date(Number(t.minimum))}` : r = "Invalid input";
388
+ break;
389
+ case u.too_big:
390
+ t.type === "array" ? r = `Array must contain ${t.exact ? "exactly" : t.inclusive ? "at most" : "less than"} ${t.maximum} element(s)` : t.type === "string" ? r = `String must contain ${t.exact ? "exactly" : t.inclusive ? "at most" : "under"} ${t.maximum} character(s)` : t.type === "number" ? r = `Number must be ${t.exact ? "exactly" : t.inclusive ? "less than or equal to" : "less than"} ${t.maximum}` : t.type === "bigint" ? r = `BigInt must be ${t.exact ? "exactly" : t.inclusive ? "less than or equal to" : "less than"} ${t.maximum}` : t.type === "date" ? r = `Date must be ${t.exact ? "exactly" : t.inclusive ? "smaller than or equal to" : "smaller than"} ${new Date(Number(t.maximum))}` : r = "Invalid input";
391
+ break;
392
+ case u.custom:
393
+ r = "Invalid input";
394
+ break;
395
+ case u.invalid_intersection_types:
396
+ r = "Intersection results could not be merged";
397
+ break;
398
+ case u.not_multiple_of:
399
+ r = `Number must be a multiple of ${t.multipleOf}`;
400
+ break;
401
+ case u.not_finite:
402
+ r = "Number must be finite";
403
+ break;
404
+ default:
405
+ r = e.defaultError, E.assertNever(t);
406
+ }
407
+ return { message: r };
408
+ };
409
+ let pr = xe;
410
+ function Qe() {
411
+ return pr;
412
+ }
413
+ const Xe = (t) => {
414
+ const { data: e, path: r, errorMaps: n, issueData: s } = t, i = [...r, ...s.path || []], c = {
415
+ ...s,
416
+ path: i
417
+ };
418
+ if (s.message !== void 0)
419
+ return {
420
+ ...s,
421
+ path: i,
422
+ message: s.message
423
+ };
424
+ let a = "";
425
+ const h = n.filter((d) => !!d).slice().reverse();
426
+ for (const d of h)
427
+ a = d(c, { data: e, defaultError: a }).message;
428
+ return {
429
+ ...s,
430
+ path: i,
431
+ message: a
432
+ };
433
+ };
434
+ function p(t, e) {
435
+ const r = Qe(), n = Xe({
436
+ issueData: e,
437
+ data: t.data,
438
+ path: t.path,
439
+ errorMaps: [
440
+ t.common.contextualErrorMap,
441
+ // contextual error map is first priority
442
+ t.schemaErrorMap,
443
+ // then schema-bound map if available
444
+ r,
445
+ // then global override map
446
+ r === xe ? void 0 : xe
447
+ // then global default map
448
+ ].filter((s) => !!s)
449
+ });
450
+ t.common.issues.push(n);
451
+ }
452
+ class $ {
453
+ constructor() {
454
+ this.value = "valid";
455
+ }
456
+ dirty() {
457
+ this.value === "valid" && (this.value = "dirty");
458
+ }
459
+ abort() {
460
+ this.value !== "aborted" && (this.value = "aborted");
461
+ }
462
+ static mergeArray(e, r) {
463
+ const n = [];
464
+ for (const s of r) {
465
+ if (s.status === "aborted")
466
+ return v;
467
+ s.status === "dirty" && e.dirty(), n.push(s.value);
468
+ }
469
+ return { status: e.value, value: n };
470
+ }
471
+ static async mergeObjectAsync(e, r) {
472
+ const n = [];
473
+ for (const s of r) {
474
+ const i = await s.key, c = await s.value;
475
+ n.push({
476
+ key: i,
477
+ value: c
478
+ });
479
+ }
480
+ return $.mergeObjectSync(e, n);
481
+ }
482
+ static mergeObjectSync(e, r) {
483
+ const n = {};
484
+ for (const s of r) {
485
+ const { key: i, value: c } = s;
486
+ if (i.status === "aborted" || c.status === "aborted")
487
+ return v;
488
+ i.status === "dirty" && e.dirty(), c.status === "dirty" && e.dirty(), i.value !== "__proto__" && (typeof c.value < "u" || s.alwaysSet) && (n[i.value] = c.value);
489
+ }
490
+ return { status: e.value, value: n };
491
+ }
492
+ }
493
+ const v = Object.freeze({
494
+ status: "aborted"
495
+ }), ve = (t) => ({ status: "dirty", value: t }), L = (t) => ({ status: "valid", value: t }), vt = (t) => t.status === "aborted", kt = (t) => t.status === "dirty", pe = (t) => t.status === "valid", De = (t) => typeof Promise < "u" && t instanceof Promise;
496
+ var y;
497
+ (function(t) {
498
+ t.errToObj = (e) => typeof e == "string" ? { message: e } : e || {}, t.toString = (e) => typeof e == "string" ? e : e == null ? void 0 : e.message;
499
+ })(y || (y = {}));
500
+ class z {
501
+ constructor(e, r, n, s) {
502
+ this._cachedPath = [], this.parent = e, this.data = r, this._path = n, this._key = s;
503
+ }
504
+ get path() {
505
+ return this._cachedPath.length || (Array.isArray(this._key) ? this._cachedPath.push(...this._path, ...this._key) : this._cachedPath.push(...this._path, this._key)), this._cachedPath;
506
+ }
507
+ }
508
+ const wt = (t, e) => {
509
+ if (pe(e))
510
+ return { success: !0, data: e.value };
511
+ if (!t.common.issues.length)
512
+ throw new Error("Validation failed but no issues detected.");
513
+ return {
514
+ success: !1,
515
+ get error() {
516
+ if (this._error)
517
+ return this._error;
518
+ const r = new j(t.common.issues);
519
+ return this._error = r, this._error;
520
+ }
521
+ };
522
+ };
523
+ function T(t) {
524
+ if (!t)
525
+ return {};
526
+ const { errorMap: e, invalid_type_error: r, required_error: n, description: s } = t;
527
+ if (e && (r || n))
528
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
529
+ return e ? { errorMap: e, description: s } : { errorMap: (c, a) => {
530
+ const { message: h } = t;
531
+ return c.code === "invalid_enum_value" ? { message: h ?? a.defaultError } : typeof a.data > "u" ? { message: h ?? n ?? a.defaultError } : c.code !== "invalid_type" ? { message: a.defaultError } : { message: h ?? r ?? a.defaultError };
532
+ }, description: s };
533
+ }
534
+ class S {
535
+ get description() {
536
+ return this._def.description;
537
+ }
538
+ _getType(e) {
539
+ return te(e.data);
540
+ }
541
+ _getOrReturnCtx(e, r) {
542
+ return r || {
543
+ common: e.parent.common,
544
+ data: e.data,
545
+ parsedType: te(e.data),
546
+ schemaErrorMap: this._def.errorMap,
547
+ path: e.path,
548
+ parent: e.parent
549
+ };
550
+ }
551
+ _processInputParams(e) {
552
+ return {
553
+ status: new $(),
554
+ ctx: {
555
+ common: e.parent.common,
556
+ data: e.data,
557
+ parsedType: te(e.data),
558
+ schemaErrorMap: this._def.errorMap,
559
+ path: e.path,
560
+ parent: e.parent
561
+ }
562
+ };
563
+ }
564
+ _parseSync(e) {
565
+ const r = this._parse(e);
566
+ if (De(r))
567
+ throw new Error("Synchronous parse encountered promise.");
568
+ return r;
569
+ }
570
+ _parseAsync(e) {
571
+ const r = this._parse(e);
572
+ return Promise.resolve(r);
573
+ }
574
+ parse(e, r) {
575
+ const n = this.safeParse(e, r);
576
+ if (n.success)
577
+ return n.data;
578
+ throw n.error;
579
+ }
580
+ safeParse(e, r) {
581
+ const n = {
582
+ common: {
583
+ issues: [],
584
+ async: (r == null ? void 0 : r.async) ?? !1,
585
+ contextualErrorMap: r == null ? void 0 : r.errorMap
586
+ },
587
+ path: (r == null ? void 0 : r.path) || [],
588
+ schemaErrorMap: this._def.errorMap,
589
+ parent: null,
590
+ data: e,
591
+ parsedType: te(e)
592
+ }, s = this._parseSync({ data: e, path: n.path, parent: n });
593
+ return wt(n, s);
594
+ }
595
+ "~validate"(e) {
596
+ var n, s;
597
+ const r = {
598
+ common: {
599
+ issues: [],
600
+ async: !!this["~standard"].async
601
+ },
602
+ path: [],
603
+ schemaErrorMap: this._def.errorMap,
604
+ parent: null,
605
+ data: e,
606
+ parsedType: te(e)
607
+ };
608
+ if (!this["~standard"].async)
609
+ try {
610
+ const i = this._parseSync({ data: e, path: [], parent: r });
611
+ return pe(i) ? {
612
+ value: i.value
613
+ } : {
614
+ issues: r.common.issues
615
+ };
616
+ } catch (i) {
617
+ (s = (n = i == null ? void 0 : i.message) == null ? void 0 : n.toLowerCase()) != null && s.includes("encountered") && (this["~standard"].async = !0), r.common = {
618
+ issues: [],
619
+ async: !0
620
+ };
621
+ }
622
+ return this._parseAsync({ data: e, path: [], parent: r }).then((i) => pe(i) ? {
623
+ value: i.value
624
+ } : {
625
+ issues: r.common.issues
626
+ });
627
+ }
628
+ async parseAsync(e, r) {
629
+ const n = await this.safeParseAsync(e, r);
630
+ if (n.success)
631
+ return n.data;
632
+ throw n.error;
633
+ }
634
+ async safeParseAsync(e, r) {
635
+ const n = {
636
+ common: {
637
+ issues: [],
638
+ contextualErrorMap: r == null ? void 0 : r.errorMap,
639
+ async: !0
640
+ },
641
+ path: (r == null ? void 0 : r.path) || [],
642
+ schemaErrorMap: this._def.errorMap,
643
+ parent: null,
644
+ data: e,
645
+ parsedType: te(e)
646
+ }, s = this._parse({ data: e, path: n.path, parent: n }), i = await (De(s) ? s : Promise.resolve(s));
647
+ return wt(n, i);
648
+ }
649
+ refine(e, r) {
650
+ const n = (s) => typeof r == "string" || typeof r > "u" ? { message: r } : typeof r == "function" ? r(s) : r;
651
+ return this._refinement((s, i) => {
652
+ const c = e(s), a = () => i.addIssue({
653
+ code: u.custom,
654
+ ...n(s)
655
+ });
656
+ return typeof Promise < "u" && c instanceof Promise ? c.then((h) => h ? !0 : (a(), !1)) : c ? !0 : (a(), !1);
657
+ });
658
+ }
659
+ refinement(e, r) {
660
+ return this._refinement((n, s) => e(n) ? !0 : (s.addIssue(typeof r == "function" ? r(n, s) : r), !1));
661
+ }
662
+ _refinement(e) {
663
+ return new Y({
664
+ schema: this,
665
+ typeName: k.ZodEffects,
666
+ effect: { type: "refinement", refinement: e }
667
+ });
668
+ }
669
+ superRefine(e) {
670
+ return this._refinement(e);
671
+ }
672
+ constructor(e) {
673
+ this.spa = this.safeParseAsync, this._def = e, this.parse = this.parse.bind(this), this.safeParse = this.safeParse.bind(this), this.parseAsync = this.parseAsync.bind(this), this.safeParseAsync = this.safeParseAsync.bind(this), this.spa = this.spa.bind(this), this.refine = this.refine.bind(this), this.refinement = this.refinement.bind(this), this.superRefine = this.superRefine.bind(this), this.optional = this.optional.bind(this), this.nullable = this.nullable.bind(this), this.nullish = this.nullish.bind(this), this.array = this.array.bind(this), this.promise = this.promise.bind(this), this.or = this.or.bind(this), this.and = this.and.bind(this), this.transform = this.transform.bind(this), this.brand = this.brand.bind(this), this.default = this.default.bind(this), this.catch = this.catch.bind(this), this.describe = this.describe.bind(this), this.pipe = this.pipe.bind(this), this.readonly = this.readonly.bind(this), this.isNullable = this.isNullable.bind(this), this.isOptional = this.isOptional.bind(this), this["~standard"] = {
674
+ version: 1,
675
+ vendor: "zod",
676
+ validate: (r) => this["~validate"](r)
677
+ };
678
+ }
679
+ optional() {
680
+ return V.create(this, this._def);
681
+ }
682
+ nullable() {
683
+ return se.create(this, this._def);
684
+ }
685
+ nullish() {
686
+ return this.nullable().optional();
687
+ }
688
+ array() {
689
+ return W.create(this);
690
+ }
691
+ promise() {
692
+ return ge.create(this, this._def);
693
+ }
694
+ or(e) {
695
+ return Ee.create([this, e], this._def);
696
+ }
697
+ and(e) {
698
+ return Re.create(this, e, this._def);
699
+ }
700
+ transform(e) {
701
+ return new Y({
702
+ ...T(this._def),
703
+ schema: this,
704
+ typeName: k.ZodEffects,
705
+ effect: { type: "transform", transform: e }
706
+ });
707
+ }
708
+ default(e) {
709
+ const r = typeof e == "function" ? e : () => e;
710
+ return new Ne({
711
+ ...T(this._def),
712
+ innerType: this,
713
+ defaultValue: r,
714
+ typeName: k.ZodDefault
715
+ });
716
+ }
717
+ brand() {
718
+ return new ut({
719
+ typeName: k.ZodBranded,
720
+ type: this,
721
+ ...T(this._def)
722
+ });
723
+ }
724
+ catch(e) {
725
+ const r = typeof e == "function" ? e : () => e;
726
+ return new Me({
727
+ ...T(this._def),
728
+ innerType: this,
729
+ catchValue: r,
730
+ typeName: k.ZodCatch
731
+ });
732
+ }
733
+ describe(e) {
734
+ const r = this.constructor;
735
+ return new r({
736
+ ...this._def,
737
+ description: e
738
+ });
739
+ }
740
+ pipe(e) {
741
+ return qe.create(this, e);
742
+ }
743
+ readonly() {
744
+ return Pe.create(this);
745
+ }
746
+ isOptional() {
747
+ return this.safeParse(void 0).success;
748
+ }
749
+ isNullable() {
750
+ return this.safeParse(null).success;
751
+ }
752
+ }
753
+ const mr = /^c[^\s-]{8,}$/i, gr = /^[0-9a-z]+$/, yr = /^[0-9A-HJKMNP-TV-Z]{26}$/i, br = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i, _r = /^[a-z0-9_-]{21}$/i, vr = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/, kr = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/, wr = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i, Tr = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
754
+ let Ge;
755
+ const xr = /^(?:(?: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])$/, Sr = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/, Ir = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/, Er = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/, Rr = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/, Ar = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/, Mt = "((\\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])))", Cr = new RegExp(`^${Mt}$`);
756
+ function Pt(t) {
757
+ let e = "[0-5]\\d";
758
+ t.precision ? e = `${e}\\.\\d{${t.precision}}` : t.precision == null && (e = `${e}(\\.\\d+)?`);
759
+ const r = t.precision ? "+" : "?";
760
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${e})${r}`;
761
+ }
762
+ function Or(t) {
763
+ return new RegExp(`^${Pt(t)}$`);
764
+ }
765
+ function Nr(t) {
766
+ let e = `${Mt}T${Pt(t)}`;
767
+ const r = [];
768
+ return r.push(t.local ? "Z?" : "Z"), t.offset && r.push("([+-]\\d{2}:?\\d{2})"), e = `${e}(${r.join("|")})`, new RegExp(`^${e}$`);
769
+ }
770
+ function Mr(t, e) {
771
+ return !!((e === "v4" || !e) && xr.test(t) || (e === "v6" || !e) && Ir.test(t));
772
+ }
773
+ function Pr(t, e) {
774
+ if (!vr.test(t))
775
+ return !1;
776
+ try {
777
+ const [r] = t.split(".");
778
+ if (!r)
779
+ return !1;
780
+ const n = r.replace(/-/g, "+").replace(/_/g, "/").padEnd(r.length + (4 - r.length % 4) % 4, "="), s = JSON.parse(atob(n));
781
+ return !(typeof s != "object" || s === null || "typ" in s && (s == null ? void 0 : s.typ) !== "JWT" || !s.alg || e && s.alg !== e);
782
+ } catch {
783
+ return !1;
784
+ }
785
+ }
786
+ function $r(t, e) {
787
+ return !!((e === "v4" || !e) && Sr.test(t) || (e === "v6" || !e) && Er.test(t));
788
+ }
789
+ class B extends S {
790
+ _parse(e) {
791
+ if (this._def.coerce && (e.data = String(e.data)), this._getType(e) !== g.string) {
792
+ const i = this._getOrReturnCtx(e);
793
+ return p(i, {
794
+ code: u.invalid_type,
795
+ expected: g.string,
796
+ received: i.parsedType
797
+ }), v;
798
+ }
799
+ const n = new $();
800
+ let s;
801
+ for (const i of this._def.checks)
802
+ if (i.kind === "min")
803
+ e.data.length < i.value && (s = this._getOrReturnCtx(e, s), p(s, {
804
+ code: u.too_small,
805
+ minimum: i.value,
806
+ type: "string",
807
+ inclusive: !0,
808
+ exact: !1,
809
+ message: i.message
810
+ }), n.dirty());
811
+ else if (i.kind === "max")
812
+ e.data.length > i.value && (s = this._getOrReturnCtx(e, s), p(s, {
813
+ code: u.too_big,
814
+ maximum: i.value,
815
+ type: "string",
816
+ inclusive: !0,
817
+ exact: !1,
818
+ message: i.message
819
+ }), n.dirty());
820
+ else if (i.kind === "length") {
821
+ const c = e.data.length > i.value, a = e.data.length < i.value;
822
+ (c || a) && (s = this._getOrReturnCtx(e, s), c ? p(s, {
823
+ code: u.too_big,
824
+ maximum: i.value,
825
+ type: "string",
826
+ inclusive: !0,
827
+ exact: !0,
828
+ message: i.message
829
+ }) : a && p(s, {
830
+ code: u.too_small,
831
+ minimum: i.value,
832
+ type: "string",
833
+ inclusive: !0,
834
+ exact: !0,
835
+ message: i.message
836
+ }), n.dirty());
837
+ } else if (i.kind === "email")
838
+ wr.test(e.data) || (s = this._getOrReturnCtx(e, s), p(s, {
839
+ validation: "email",
840
+ code: u.invalid_string,
841
+ message: i.message
842
+ }), n.dirty());
843
+ else if (i.kind === "emoji")
844
+ Ge || (Ge = new RegExp(Tr, "u")), Ge.test(e.data) || (s = this._getOrReturnCtx(e, s), p(s, {
845
+ validation: "emoji",
846
+ code: u.invalid_string,
847
+ message: i.message
848
+ }), n.dirty());
849
+ else if (i.kind === "uuid")
850
+ br.test(e.data) || (s = this._getOrReturnCtx(e, s), p(s, {
851
+ validation: "uuid",
852
+ code: u.invalid_string,
853
+ message: i.message
854
+ }), n.dirty());
855
+ else if (i.kind === "nanoid")
856
+ _r.test(e.data) || (s = this._getOrReturnCtx(e, s), p(s, {
857
+ validation: "nanoid",
858
+ code: u.invalid_string,
859
+ message: i.message
860
+ }), n.dirty());
861
+ else if (i.kind === "cuid")
862
+ mr.test(e.data) || (s = this._getOrReturnCtx(e, s), p(s, {
863
+ validation: "cuid",
864
+ code: u.invalid_string,
865
+ message: i.message
866
+ }), n.dirty());
867
+ else if (i.kind === "cuid2")
868
+ gr.test(e.data) || (s = this._getOrReturnCtx(e, s), p(s, {
869
+ validation: "cuid2",
870
+ code: u.invalid_string,
871
+ message: i.message
872
+ }), n.dirty());
873
+ else if (i.kind === "ulid")
874
+ yr.test(e.data) || (s = this._getOrReturnCtx(e, s), p(s, {
875
+ validation: "ulid",
876
+ code: u.invalid_string,
877
+ message: i.message
878
+ }), n.dirty());
879
+ else if (i.kind === "url")
880
+ try {
881
+ new URL(e.data);
882
+ } catch {
883
+ s = this._getOrReturnCtx(e, s), p(s, {
884
+ validation: "url",
885
+ code: u.invalid_string,
886
+ message: i.message
887
+ }), n.dirty();
888
+ }
889
+ else i.kind === "regex" ? (i.regex.lastIndex = 0, i.regex.test(e.data) || (s = this._getOrReturnCtx(e, s), p(s, {
890
+ validation: "regex",
891
+ code: u.invalid_string,
892
+ message: i.message
893
+ }), n.dirty())) : i.kind === "trim" ? e.data = e.data.trim() : i.kind === "includes" ? e.data.includes(i.value, i.position) || (s = this._getOrReturnCtx(e, s), p(s, {
894
+ code: u.invalid_string,
895
+ validation: { includes: i.value, position: i.position },
896
+ message: i.message
897
+ }), n.dirty()) : i.kind === "toLowerCase" ? e.data = e.data.toLowerCase() : i.kind === "toUpperCase" ? e.data = e.data.toUpperCase() : i.kind === "startsWith" ? e.data.startsWith(i.value) || (s = this._getOrReturnCtx(e, s), p(s, {
898
+ code: u.invalid_string,
899
+ validation: { startsWith: i.value },
900
+ message: i.message
901
+ }), n.dirty()) : i.kind === "endsWith" ? e.data.endsWith(i.value) || (s = this._getOrReturnCtx(e, s), p(s, {
902
+ code: u.invalid_string,
903
+ validation: { endsWith: i.value },
904
+ message: i.message
905
+ }), n.dirty()) : i.kind === "datetime" ? Nr(i).test(e.data) || (s = this._getOrReturnCtx(e, s), p(s, {
906
+ code: u.invalid_string,
907
+ validation: "datetime",
908
+ message: i.message
909
+ }), n.dirty()) : i.kind === "date" ? Cr.test(e.data) || (s = this._getOrReturnCtx(e, s), p(s, {
910
+ code: u.invalid_string,
911
+ validation: "date",
912
+ message: i.message
913
+ }), n.dirty()) : i.kind === "time" ? Or(i).test(e.data) || (s = this._getOrReturnCtx(e, s), p(s, {
914
+ code: u.invalid_string,
915
+ validation: "time",
916
+ message: i.message
917
+ }), n.dirty()) : i.kind === "duration" ? kr.test(e.data) || (s = this._getOrReturnCtx(e, s), p(s, {
918
+ validation: "duration",
919
+ code: u.invalid_string,
920
+ message: i.message
921
+ }), n.dirty()) : i.kind === "ip" ? Mr(e.data, i.version) || (s = this._getOrReturnCtx(e, s), p(s, {
922
+ validation: "ip",
923
+ code: u.invalid_string,
924
+ message: i.message
925
+ }), n.dirty()) : i.kind === "jwt" ? Pr(e.data, i.alg) || (s = this._getOrReturnCtx(e, s), p(s, {
926
+ validation: "jwt",
927
+ code: u.invalid_string,
928
+ message: i.message
929
+ }), n.dirty()) : i.kind === "cidr" ? $r(e.data, i.version) || (s = this._getOrReturnCtx(e, s), p(s, {
930
+ validation: "cidr",
931
+ code: u.invalid_string,
932
+ message: i.message
933
+ }), n.dirty()) : i.kind === "base64" ? Rr.test(e.data) || (s = this._getOrReturnCtx(e, s), p(s, {
934
+ validation: "base64",
935
+ code: u.invalid_string,
936
+ message: i.message
937
+ }), n.dirty()) : i.kind === "base64url" ? Ar.test(e.data) || (s = this._getOrReturnCtx(e, s), p(s, {
938
+ validation: "base64url",
939
+ code: u.invalid_string,
940
+ message: i.message
941
+ }), n.dirty()) : E.assertNever(i);
942
+ return { status: n.value, value: e.data };
943
+ }
944
+ _regex(e, r, n) {
945
+ return this.refinement((s) => e.test(s), {
946
+ validation: r,
947
+ code: u.invalid_string,
948
+ ...y.errToObj(n)
949
+ });
950
+ }
951
+ _addCheck(e) {
952
+ return new B({
953
+ ...this._def,
954
+ checks: [...this._def.checks, e]
955
+ });
956
+ }
957
+ email(e) {
958
+ return this._addCheck({ kind: "email", ...y.errToObj(e) });
959
+ }
960
+ url(e) {
961
+ return this._addCheck({ kind: "url", ...y.errToObj(e) });
962
+ }
963
+ emoji(e) {
964
+ return this._addCheck({ kind: "emoji", ...y.errToObj(e) });
965
+ }
966
+ uuid(e) {
967
+ return this._addCheck({ kind: "uuid", ...y.errToObj(e) });
968
+ }
969
+ nanoid(e) {
970
+ return this._addCheck({ kind: "nanoid", ...y.errToObj(e) });
971
+ }
972
+ cuid(e) {
973
+ return this._addCheck({ kind: "cuid", ...y.errToObj(e) });
974
+ }
975
+ cuid2(e) {
976
+ return this._addCheck({ kind: "cuid2", ...y.errToObj(e) });
977
+ }
978
+ ulid(e) {
979
+ return this._addCheck({ kind: "ulid", ...y.errToObj(e) });
980
+ }
981
+ base64(e) {
982
+ return this._addCheck({ kind: "base64", ...y.errToObj(e) });
983
+ }
984
+ base64url(e) {
985
+ return this._addCheck({
986
+ kind: "base64url",
987
+ ...y.errToObj(e)
988
+ });
989
+ }
990
+ jwt(e) {
991
+ return this._addCheck({ kind: "jwt", ...y.errToObj(e) });
992
+ }
993
+ ip(e) {
994
+ return this._addCheck({ kind: "ip", ...y.errToObj(e) });
995
+ }
996
+ cidr(e) {
997
+ return this._addCheck({ kind: "cidr", ...y.errToObj(e) });
998
+ }
999
+ datetime(e) {
1000
+ return typeof e == "string" ? this._addCheck({
1001
+ kind: "datetime",
1002
+ precision: null,
1003
+ offset: !1,
1004
+ local: !1,
1005
+ message: e
1006
+ }) : this._addCheck({
1007
+ kind: "datetime",
1008
+ precision: typeof (e == null ? void 0 : e.precision) > "u" ? null : e == null ? void 0 : e.precision,
1009
+ offset: (e == null ? void 0 : e.offset) ?? !1,
1010
+ local: (e == null ? void 0 : e.local) ?? !1,
1011
+ ...y.errToObj(e == null ? void 0 : e.message)
1012
+ });
1013
+ }
1014
+ date(e) {
1015
+ return this._addCheck({ kind: "date", message: e });
1016
+ }
1017
+ time(e) {
1018
+ return typeof e == "string" ? this._addCheck({
1019
+ kind: "time",
1020
+ precision: null,
1021
+ message: e
1022
+ }) : this._addCheck({
1023
+ kind: "time",
1024
+ precision: typeof (e == null ? void 0 : e.precision) > "u" ? null : e == null ? void 0 : e.precision,
1025
+ ...y.errToObj(e == null ? void 0 : e.message)
1026
+ });
1027
+ }
1028
+ duration(e) {
1029
+ return this._addCheck({ kind: "duration", ...y.errToObj(e) });
1030
+ }
1031
+ regex(e, r) {
1032
+ return this._addCheck({
1033
+ kind: "regex",
1034
+ regex: e,
1035
+ ...y.errToObj(r)
1036
+ });
1037
+ }
1038
+ includes(e, r) {
1039
+ return this._addCheck({
1040
+ kind: "includes",
1041
+ value: e,
1042
+ position: r == null ? void 0 : r.position,
1043
+ ...y.errToObj(r == null ? void 0 : r.message)
1044
+ });
1045
+ }
1046
+ startsWith(e, r) {
1047
+ return this._addCheck({
1048
+ kind: "startsWith",
1049
+ value: e,
1050
+ ...y.errToObj(r)
1051
+ });
1052
+ }
1053
+ endsWith(e, r) {
1054
+ return this._addCheck({
1055
+ kind: "endsWith",
1056
+ value: e,
1057
+ ...y.errToObj(r)
1058
+ });
1059
+ }
1060
+ min(e, r) {
1061
+ return this._addCheck({
1062
+ kind: "min",
1063
+ value: e,
1064
+ ...y.errToObj(r)
1065
+ });
1066
+ }
1067
+ max(e, r) {
1068
+ return this._addCheck({
1069
+ kind: "max",
1070
+ value: e,
1071
+ ...y.errToObj(r)
1072
+ });
1073
+ }
1074
+ length(e, r) {
1075
+ return this._addCheck({
1076
+ kind: "length",
1077
+ value: e,
1078
+ ...y.errToObj(r)
1079
+ });
1080
+ }
1081
+ /**
1082
+ * Equivalent to `.min(1)`
1083
+ */
1084
+ nonempty(e) {
1085
+ return this.min(1, y.errToObj(e));
1086
+ }
1087
+ trim() {
1088
+ return new B({
1089
+ ...this._def,
1090
+ checks: [...this._def.checks, { kind: "trim" }]
1091
+ });
1092
+ }
1093
+ toLowerCase() {
1094
+ return new B({
1095
+ ...this._def,
1096
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
1097
+ });
1098
+ }
1099
+ toUpperCase() {
1100
+ return new B({
1101
+ ...this._def,
1102
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
1103
+ });
1104
+ }
1105
+ get isDatetime() {
1106
+ return !!this._def.checks.find((e) => e.kind === "datetime");
1107
+ }
1108
+ get isDate() {
1109
+ return !!this._def.checks.find((e) => e.kind === "date");
1110
+ }
1111
+ get isTime() {
1112
+ return !!this._def.checks.find((e) => e.kind === "time");
1113
+ }
1114
+ get isDuration() {
1115
+ return !!this._def.checks.find((e) => e.kind === "duration");
1116
+ }
1117
+ get isEmail() {
1118
+ return !!this._def.checks.find((e) => e.kind === "email");
1119
+ }
1120
+ get isURL() {
1121
+ return !!this._def.checks.find((e) => e.kind === "url");
1122
+ }
1123
+ get isEmoji() {
1124
+ return !!this._def.checks.find((e) => e.kind === "emoji");
1125
+ }
1126
+ get isUUID() {
1127
+ return !!this._def.checks.find((e) => e.kind === "uuid");
1128
+ }
1129
+ get isNANOID() {
1130
+ return !!this._def.checks.find((e) => e.kind === "nanoid");
1131
+ }
1132
+ get isCUID() {
1133
+ return !!this._def.checks.find((e) => e.kind === "cuid");
1134
+ }
1135
+ get isCUID2() {
1136
+ return !!this._def.checks.find((e) => e.kind === "cuid2");
1137
+ }
1138
+ get isULID() {
1139
+ return !!this._def.checks.find((e) => e.kind === "ulid");
1140
+ }
1141
+ get isIP() {
1142
+ return !!this._def.checks.find((e) => e.kind === "ip");
1143
+ }
1144
+ get isCIDR() {
1145
+ return !!this._def.checks.find((e) => e.kind === "cidr");
1146
+ }
1147
+ get isBase64() {
1148
+ return !!this._def.checks.find((e) => e.kind === "base64");
1149
+ }
1150
+ get isBase64url() {
1151
+ return !!this._def.checks.find((e) => e.kind === "base64url");
1152
+ }
1153
+ get minLength() {
1154
+ let e = null;
1155
+ for (const r of this._def.checks)
1156
+ r.kind === "min" && (e === null || r.value > e) && (e = r.value);
1157
+ return e;
1158
+ }
1159
+ get maxLength() {
1160
+ let e = null;
1161
+ for (const r of this._def.checks)
1162
+ r.kind === "max" && (e === null || r.value < e) && (e = r.value);
1163
+ return e;
1164
+ }
1165
+ }
1166
+ B.create = (t) => new B({
1167
+ checks: [],
1168
+ typeName: k.ZodString,
1169
+ coerce: (t == null ? void 0 : t.coerce) ?? !1,
1170
+ ...T(t)
1171
+ });
1172
+ function Lr(t, e) {
1173
+ const r = (t.toString().split(".")[1] || "").length, n = (e.toString().split(".")[1] || "").length, s = r > n ? r : n, i = Number.parseInt(t.toFixed(s).replace(".", "")), c = Number.parseInt(e.toFixed(s).replace(".", ""));
1174
+ return i % c / 10 ** s;
1175
+ }
1176
+ class oe extends S {
1177
+ constructor() {
1178
+ super(...arguments), this.min = this.gte, this.max = this.lte, this.step = this.multipleOf;
1179
+ }
1180
+ _parse(e) {
1181
+ if (this._def.coerce && (e.data = Number(e.data)), this._getType(e) !== g.number) {
1182
+ const i = this._getOrReturnCtx(e);
1183
+ return p(i, {
1184
+ code: u.invalid_type,
1185
+ expected: g.number,
1186
+ received: i.parsedType
1187
+ }), v;
1188
+ }
1189
+ let n;
1190
+ const s = new $();
1191
+ for (const i of this._def.checks)
1192
+ i.kind === "int" ? E.isInteger(e.data) || (n = this._getOrReturnCtx(e, n), p(n, {
1193
+ code: u.invalid_type,
1194
+ expected: "integer",
1195
+ received: "float",
1196
+ message: i.message
1197
+ }), s.dirty()) : i.kind === "min" ? (i.inclusive ? e.data < i.value : e.data <= i.value) && (n = this._getOrReturnCtx(e, n), p(n, {
1198
+ code: u.too_small,
1199
+ minimum: i.value,
1200
+ type: "number",
1201
+ inclusive: i.inclusive,
1202
+ exact: !1,
1203
+ message: i.message
1204
+ }), s.dirty()) : i.kind === "max" ? (i.inclusive ? e.data > i.value : e.data >= i.value) && (n = this._getOrReturnCtx(e, n), p(n, {
1205
+ code: u.too_big,
1206
+ maximum: i.value,
1207
+ type: "number",
1208
+ inclusive: i.inclusive,
1209
+ exact: !1,
1210
+ message: i.message
1211
+ }), s.dirty()) : i.kind === "multipleOf" ? Lr(e.data, i.value) !== 0 && (n = this._getOrReturnCtx(e, n), p(n, {
1212
+ code: u.not_multiple_of,
1213
+ multipleOf: i.value,
1214
+ message: i.message
1215
+ }), s.dirty()) : i.kind === "finite" ? Number.isFinite(e.data) || (n = this._getOrReturnCtx(e, n), p(n, {
1216
+ code: u.not_finite,
1217
+ message: i.message
1218
+ }), s.dirty()) : E.assertNever(i);
1219
+ return { status: s.value, value: e.data };
1220
+ }
1221
+ gte(e, r) {
1222
+ return this.setLimit("min", e, !0, y.toString(r));
1223
+ }
1224
+ gt(e, r) {
1225
+ return this.setLimit("min", e, !1, y.toString(r));
1226
+ }
1227
+ lte(e, r) {
1228
+ return this.setLimit("max", e, !0, y.toString(r));
1229
+ }
1230
+ lt(e, r) {
1231
+ return this.setLimit("max", e, !1, y.toString(r));
1232
+ }
1233
+ setLimit(e, r, n, s) {
1234
+ return new oe({
1235
+ ...this._def,
1236
+ checks: [
1237
+ ...this._def.checks,
1238
+ {
1239
+ kind: e,
1240
+ value: r,
1241
+ inclusive: n,
1242
+ message: y.toString(s)
1243
+ }
1244
+ ]
1245
+ });
1246
+ }
1247
+ _addCheck(e) {
1248
+ return new oe({
1249
+ ...this._def,
1250
+ checks: [...this._def.checks, e]
1251
+ });
1252
+ }
1253
+ int(e) {
1254
+ return this._addCheck({
1255
+ kind: "int",
1256
+ message: y.toString(e)
1257
+ });
1258
+ }
1259
+ positive(e) {
1260
+ return this._addCheck({
1261
+ kind: "min",
1262
+ value: 0,
1263
+ inclusive: !1,
1264
+ message: y.toString(e)
1265
+ });
1266
+ }
1267
+ negative(e) {
1268
+ return this._addCheck({
1269
+ kind: "max",
1270
+ value: 0,
1271
+ inclusive: !1,
1272
+ message: y.toString(e)
1273
+ });
1274
+ }
1275
+ nonpositive(e) {
1276
+ return this._addCheck({
1277
+ kind: "max",
1278
+ value: 0,
1279
+ inclusive: !0,
1280
+ message: y.toString(e)
1281
+ });
1282
+ }
1283
+ nonnegative(e) {
1284
+ return this._addCheck({
1285
+ kind: "min",
1286
+ value: 0,
1287
+ inclusive: !0,
1288
+ message: y.toString(e)
1289
+ });
1290
+ }
1291
+ multipleOf(e, r) {
1292
+ return this._addCheck({
1293
+ kind: "multipleOf",
1294
+ value: e,
1295
+ message: y.toString(r)
1296
+ });
1297
+ }
1298
+ finite(e) {
1299
+ return this._addCheck({
1300
+ kind: "finite",
1301
+ message: y.toString(e)
1302
+ });
1303
+ }
1304
+ safe(e) {
1305
+ return this._addCheck({
1306
+ kind: "min",
1307
+ inclusive: !0,
1308
+ value: Number.MIN_SAFE_INTEGER,
1309
+ message: y.toString(e)
1310
+ })._addCheck({
1311
+ kind: "max",
1312
+ inclusive: !0,
1313
+ value: Number.MAX_SAFE_INTEGER,
1314
+ message: y.toString(e)
1315
+ });
1316
+ }
1317
+ get minValue() {
1318
+ let e = null;
1319
+ for (const r of this._def.checks)
1320
+ r.kind === "min" && (e === null || r.value > e) && (e = r.value);
1321
+ return e;
1322
+ }
1323
+ get maxValue() {
1324
+ let e = null;
1325
+ for (const r of this._def.checks)
1326
+ r.kind === "max" && (e === null || r.value < e) && (e = r.value);
1327
+ return e;
1328
+ }
1329
+ get isInt() {
1330
+ return !!this._def.checks.find((e) => e.kind === "int" || e.kind === "multipleOf" && E.isInteger(e.value));
1331
+ }
1332
+ get isFinite() {
1333
+ let e = null, r = null;
1334
+ for (const n of this._def.checks) {
1335
+ if (n.kind === "finite" || n.kind === "int" || n.kind === "multipleOf")
1336
+ return !0;
1337
+ n.kind === "min" ? (r === null || n.value > r) && (r = n.value) : n.kind === "max" && (e === null || n.value < e) && (e = n.value);
1338
+ }
1339
+ return Number.isFinite(r) && Number.isFinite(e);
1340
+ }
1341
+ }
1342
+ oe.create = (t) => new oe({
1343
+ checks: [],
1344
+ typeName: k.ZodNumber,
1345
+ coerce: (t == null ? void 0 : t.coerce) || !1,
1346
+ ...T(t)
1347
+ });
1348
+ class ce extends S {
1349
+ constructor() {
1350
+ super(...arguments), this.min = this.gte, this.max = this.lte;
1351
+ }
1352
+ _parse(e) {
1353
+ if (this._def.coerce)
1354
+ try {
1355
+ e.data = BigInt(e.data);
1356
+ } catch {
1357
+ return this._getInvalidInput(e);
1358
+ }
1359
+ if (this._getType(e) !== g.bigint)
1360
+ return this._getInvalidInput(e);
1361
+ let n;
1362
+ const s = new $();
1363
+ for (const i of this._def.checks)
1364
+ i.kind === "min" ? (i.inclusive ? e.data < i.value : e.data <= i.value) && (n = this._getOrReturnCtx(e, n), p(n, {
1365
+ code: u.too_small,
1366
+ type: "bigint",
1367
+ minimum: i.value,
1368
+ inclusive: i.inclusive,
1369
+ message: i.message
1370
+ }), s.dirty()) : i.kind === "max" ? (i.inclusive ? e.data > i.value : e.data >= i.value) && (n = this._getOrReturnCtx(e, n), p(n, {
1371
+ code: u.too_big,
1372
+ type: "bigint",
1373
+ maximum: i.value,
1374
+ inclusive: i.inclusive,
1375
+ message: i.message
1376
+ }), s.dirty()) : i.kind === "multipleOf" ? e.data % i.value !== BigInt(0) && (n = this._getOrReturnCtx(e, n), p(n, {
1377
+ code: u.not_multiple_of,
1378
+ multipleOf: i.value,
1379
+ message: i.message
1380
+ }), s.dirty()) : E.assertNever(i);
1381
+ return { status: s.value, value: e.data };
1382
+ }
1383
+ _getInvalidInput(e) {
1384
+ const r = this._getOrReturnCtx(e);
1385
+ return p(r, {
1386
+ code: u.invalid_type,
1387
+ expected: g.bigint,
1388
+ received: r.parsedType
1389
+ }), v;
1390
+ }
1391
+ gte(e, r) {
1392
+ return this.setLimit("min", e, !0, y.toString(r));
1393
+ }
1394
+ gt(e, r) {
1395
+ return this.setLimit("min", e, !1, y.toString(r));
1396
+ }
1397
+ lte(e, r) {
1398
+ return this.setLimit("max", e, !0, y.toString(r));
1399
+ }
1400
+ lt(e, r) {
1401
+ return this.setLimit("max", e, !1, y.toString(r));
1402
+ }
1403
+ setLimit(e, r, n, s) {
1404
+ return new ce({
1405
+ ...this._def,
1406
+ checks: [
1407
+ ...this._def.checks,
1408
+ {
1409
+ kind: e,
1410
+ value: r,
1411
+ inclusive: n,
1412
+ message: y.toString(s)
1413
+ }
1414
+ ]
1415
+ });
1416
+ }
1417
+ _addCheck(e) {
1418
+ return new ce({
1419
+ ...this._def,
1420
+ checks: [...this._def.checks, e]
1421
+ });
1422
+ }
1423
+ positive(e) {
1424
+ return this._addCheck({
1425
+ kind: "min",
1426
+ value: BigInt(0),
1427
+ inclusive: !1,
1428
+ message: y.toString(e)
1429
+ });
1430
+ }
1431
+ negative(e) {
1432
+ return this._addCheck({
1433
+ kind: "max",
1434
+ value: BigInt(0),
1435
+ inclusive: !1,
1436
+ message: y.toString(e)
1437
+ });
1438
+ }
1439
+ nonpositive(e) {
1440
+ return this._addCheck({
1441
+ kind: "max",
1442
+ value: BigInt(0),
1443
+ inclusive: !0,
1444
+ message: y.toString(e)
1445
+ });
1446
+ }
1447
+ nonnegative(e) {
1448
+ return this._addCheck({
1449
+ kind: "min",
1450
+ value: BigInt(0),
1451
+ inclusive: !0,
1452
+ message: y.toString(e)
1453
+ });
1454
+ }
1455
+ multipleOf(e, r) {
1456
+ return this._addCheck({
1457
+ kind: "multipleOf",
1458
+ value: e,
1459
+ message: y.toString(r)
1460
+ });
1461
+ }
1462
+ get minValue() {
1463
+ let e = null;
1464
+ for (const r of this._def.checks)
1465
+ r.kind === "min" && (e === null || r.value > e) && (e = r.value);
1466
+ return e;
1467
+ }
1468
+ get maxValue() {
1469
+ let e = null;
1470
+ for (const r of this._def.checks)
1471
+ r.kind === "max" && (e === null || r.value < e) && (e = r.value);
1472
+ return e;
1473
+ }
1474
+ }
1475
+ ce.create = (t) => new ce({
1476
+ checks: [],
1477
+ typeName: k.ZodBigInt,
1478
+ coerce: (t == null ? void 0 : t.coerce) ?? !1,
1479
+ ...T(t)
1480
+ });
1481
+ class Ze extends S {
1482
+ _parse(e) {
1483
+ if (this._def.coerce && (e.data = !!e.data), this._getType(e) !== g.boolean) {
1484
+ const n = this._getOrReturnCtx(e);
1485
+ return p(n, {
1486
+ code: u.invalid_type,
1487
+ expected: g.boolean,
1488
+ received: n.parsedType
1489
+ }), v;
1490
+ }
1491
+ return L(e.data);
1492
+ }
1493
+ }
1494
+ Ze.create = (t) => new Ze({
1495
+ typeName: k.ZodBoolean,
1496
+ coerce: (t == null ? void 0 : t.coerce) || !1,
1497
+ ...T(t)
1498
+ });
1499
+ class Se extends S {
1500
+ _parse(e) {
1501
+ if (this._def.coerce && (e.data = new Date(e.data)), this._getType(e) !== g.date) {
1502
+ const i = this._getOrReturnCtx(e);
1503
+ return p(i, {
1504
+ code: u.invalid_type,
1505
+ expected: g.date,
1506
+ received: i.parsedType
1507
+ }), v;
1508
+ }
1509
+ if (Number.isNaN(e.data.getTime())) {
1510
+ const i = this._getOrReturnCtx(e);
1511
+ return p(i, {
1512
+ code: u.invalid_date
1513
+ }), v;
1514
+ }
1515
+ const n = new $();
1516
+ let s;
1517
+ for (const i of this._def.checks)
1518
+ i.kind === "min" ? e.data.getTime() < i.value && (s = this._getOrReturnCtx(e, s), p(s, {
1519
+ code: u.too_small,
1520
+ message: i.message,
1521
+ inclusive: !0,
1522
+ exact: !1,
1523
+ minimum: i.value,
1524
+ type: "date"
1525
+ }), n.dirty()) : i.kind === "max" ? e.data.getTime() > i.value && (s = this._getOrReturnCtx(e, s), p(s, {
1526
+ code: u.too_big,
1527
+ message: i.message,
1528
+ inclusive: !0,
1529
+ exact: !1,
1530
+ maximum: i.value,
1531
+ type: "date"
1532
+ }), n.dirty()) : E.assertNever(i);
1533
+ return {
1534
+ status: n.value,
1535
+ value: new Date(e.data.getTime())
1536
+ };
1537
+ }
1538
+ _addCheck(e) {
1539
+ return new Se({
1540
+ ...this._def,
1541
+ checks: [...this._def.checks, e]
1542
+ });
1543
+ }
1544
+ min(e, r) {
1545
+ return this._addCheck({
1546
+ kind: "min",
1547
+ value: e.getTime(),
1548
+ message: y.toString(r)
1549
+ });
1550
+ }
1551
+ max(e, r) {
1552
+ return this._addCheck({
1553
+ kind: "max",
1554
+ value: e.getTime(),
1555
+ message: y.toString(r)
1556
+ });
1557
+ }
1558
+ get minDate() {
1559
+ let e = null;
1560
+ for (const r of this._def.checks)
1561
+ r.kind === "min" && (e === null || r.value > e) && (e = r.value);
1562
+ return e != null ? new Date(e) : null;
1563
+ }
1564
+ get maxDate() {
1565
+ let e = null;
1566
+ for (const r of this._def.checks)
1567
+ r.kind === "max" && (e === null || r.value < e) && (e = r.value);
1568
+ return e != null ? new Date(e) : null;
1569
+ }
1570
+ }
1571
+ Se.create = (t) => new Se({
1572
+ checks: [],
1573
+ coerce: (t == null ? void 0 : t.coerce) || !1,
1574
+ typeName: k.ZodDate,
1575
+ ...T(t)
1576
+ });
1577
+ class Tt extends S {
1578
+ _parse(e) {
1579
+ if (this._getType(e) !== g.symbol) {
1580
+ const n = this._getOrReturnCtx(e);
1581
+ return p(n, {
1582
+ code: u.invalid_type,
1583
+ expected: g.symbol,
1584
+ received: n.parsedType
1585
+ }), v;
1586
+ }
1587
+ return L(e.data);
1588
+ }
1589
+ }
1590
+ Tt.create = (t) => new Tt({
1591
+ typeName: k.ZodSymbol,
1592
+ ...T(t)
1593
+ });
1594
+ class We extends S {
1595
+ _parse(e) {
1596
+ if (this._getType(e) !== g.undefined) {
1597
+ const n = this._getOrReturnCtx(e);
1598
+ return p(n, {
1599
+ code: u.invalid_type,
1600
+ expected: g.undefined,
1601
+ received: n.parsedType
1602
+ }), v;
1603
+ }
1604
+ return L(e.data);
1605
+ }
1606
+ }
1607
+ We.create = (t) => new We({
1608
+ typeName: k.ZodUndefined,
1609
+ ...T(t)
1610
+ });
1611
+ class Ie extends S {
1612
+ _parse(e) {
1613
+ if (this._getType(e) !== g.null) {
1614
+ const n = this._getOrReturnCtx(e);
1615
+ return p(n, {
1616
+ code: u.invalid_type,
1617
+ expected: g.null,
1618
+ received: n.parsedType
1619
+ }), v;
1620
+ }
1621
+ return L(e.data);
1622
+ }
1623
+ }
1624
+ Ie.create = (t) => new Ie({
1625
+ typeName: k.ZodNull,
1626
+ ...T(t)
1627
+ });
1628
+ class et extends S {
1629
+ constructor() {
1630
+ super(...arguments), this._any = !0;
1631
+ }
1632
+ _parse(e) {
1633
+ return L(e.data);
1634
+ }
1635
+ }
1636
+ et.create = (t) => new et({
1637
+ typeName: k.ZodAny,
1638
+ ...T(t)
1639
+ });
1640
+ class ae extends S {
1641
+ constructor() {
1642
+ super(...arguments), this._unknown = !0;
1643
+ }
1644
+ _parse(e) {
1645
+ return L(e.data);
1646
+ }
1647
+ }
1648
+ ae.create = (t) => new ae({
1649
+ typeName: k.ZodUnknown,
1650
+ ...T(t)
1651
+ });
1652
+ class re extends S {
1653
+ _parse(e) {
1654
+ const r = this._getOrReturnCtx(e);
1655
+ return p(r, {
1656
+ code: u.invalid_type,
1657
+ expected: g.never,
1658
+ received: r.parsedType
1659
+ }), v;
1660
+ }
1661
+ }
1662
+ re.create = (t) => new re({
1663
+ typeName: k.ZodNever,
1664
+ ...T(t)
1665
+ });
1666
+ class tt extends S {
1667
+ _parse(e) {
1668
+ if (this._getType(e) !== g.undefined) {
1669
+ const n = this._getOrReturnCtx(e);
1670
+ return p(n, {
1671
+ code: u.invalid_type,
1672
+ expected: g.void,
1673
+ received: n.parsedType
1674
+ }), v;
1675
+ }
1676
+ return L(e.data);
1677
+ }
1678
+ }
1679
+ tt.create = (t) => new tt({
1680
+ typeName: k.ZodVoid,
1681
+ ...T(t)
1682
+ });
1683
+ class W extends S {
1684
+ _parse(e) {
1685
+ const { ctx: r, status: n } = this._processInputParams(e), s = this._def;
1686
+ if (r.parsedType !== g.array)
1687
+ return p(r, {
1688
+ code: u.invalid_type,
1689
+ expected: g.array,
1690
+ received: r.parsedType
1691
+ }), v;
1692
+ if (s.exactLength !== null) {
1693
+ const c = r.data.length > s.exactLength.value, a = r.data.length < s.exactLength.value;
1694
+ (c || a) && (p(r, {
1695
+ code: c ? u.too_big : u.too_small,
1696
+ minimum: a ? s.exactLength.value : void 0,
1697
+ maximum: c ? s.exactLength.value : void 0,
1698
+ type: "array",
1699
+ inclusive: !0,
1700
+ exact: !0,
1701
+ message: s.exactLength.message
1702
+ }), n.dirty());
1703
+ }
1704
+ if (s.minLength !== null && r.data.length < s.minLength.value && (p(r, {
1705
+ code: u.too_small,
1706
+ minimum: s.minLength.value,
1707
+ type: "array",
1708
+ inclusive: !0,
1709
+ exact: !1,
1710
+ message: s.minLength.message
1711
+ }), n.dirty()), s.maxLength !== null && r.data.length > s.maxLength.value && (p(r, {
1712
+ code: u.too_big,
1713
+ maximum: s.maxLength.value,
1714
+ type: "array",
1715
+ inclusive: !0,
1716
+ exact: !1,
1717
+ message: s.maxLength.message
1718
+ }), n.dirty()), r.common.async)
1719
+ return Promise.all([...r.data].map((c, a) => s.type._parseAsync(new z(r, c, r.path, a)))).then((c) => $.mergeArray(n, c));
1720
+ const i = [...r.data].map((c, a) => s.type._parseSync(new z(r, c, r.path, a)));
1721
+ return $.mergeArray(n, i);
1722
+ }
1723
+ get element() {
1724
+ return this._def.type;
1725
+ }
1726
+ min(e, r) {
1727
+ return new W({
1728
+ ...this._def,
1729
+ minLength: { value: e, message: y.toString(r) }
1730
+ });
1731
+ }
1732
+ max(e, r) {
1733
+ return new W({
1734
+ ...this._def,
1735
+ maxLength: { value: e, message: y.toString(r) }
1736
+ });
1737
+ }
1738
+ length(e, r) {
1739
+ return new W({
1740
+ ...this._def,
1741
+ exactLength: { value: e, message: y.toString(r) }
1742
+ });
1743
+ }
1744
+ nonempty(e) {
1745
+ return this.min(1, e);
1746
+ }
1747
+ }
1748
+ W.create = (t, e) => new W({
1749
+ type: t,
1750
+ minLength: null,
1751
+ maxLength: null,
1752
+ exactLength: null,
1753
+ typeName: k.ZodArray,
1754
+ ...T(e)
1755
+ });
1756
+ function ue(t) {
1757
+ if (t instanceof A) {
1758
+ const e = {};
1759
+ for (const r in t.shape) {
1760
+ const n = t.shape[r];
1761
+ e[r] = V.create(ue(n));
1762
+ }
1763
+ return new A({
1764
+ ...t._def,
1765
+ shape: () => e
1766
+ });
1767
+ } else return t instanceof W ? new W({
1768
+ ...t._def,
1769
+ type: ue(t.element)
1770
+ }) : t instanceof V ? V.create(ue(t.unwrap())) : t instanceof se ? se.create(ue(t.unwrap())) : t instanceof q ? q.create(t.items.map((e) => ue(e))) : t;
1771
+ }
1772
+ class A extends S {
1773
+ constructor() {
1774
+ super(...arguments), this._cached = null, this.nonstrict = this.passthrough, this.augment = this.extend;
1775
+ }
1776
+ _getCached() {
1777
+ if (this._cached !== null)
1778
+ return this._cached;
1779
+ const e = this._def.shape(), r = E.objectKeys(e);
1780
+ return this._cached = { shape: e, keys: r }, this._cached;
1781
+ }
1782
+ _parse(e) {
1783
+ if (this._getType(e) !== g.object) {
1784
+ const d = this._getOrReturnCtx(e);
1785
+ return p(d, {
1786
+ code: u.invalid_type,
1787
+ expected: g.object,
1788
+ received: d.parsedType
1789
+ }), v;
1790
+ }
1791
+ const { status: n, ctx: s } = this._processInputParams(e), { shape: i, keys: c } = this._getCached(), a = [];
1792
+ if (!(this._def.catchall instanceof re && this._def.unknownKeys === "strip"))
1793
+ for (const d in s.data)
1794
+ c.includes(d) || a.push(d);
1795
+ const h = [];
1796
+ for (const d of c) {
1797
+ const m = i[d], R = s.data[d];
1798
+ h.push({
1799
+ key: { status: "valid", value: d },
1800
+ value: m._parse(new z(s, R, s.path, d)),
1801
+ alwaysSet: d in s.data
1802
+ });
1803
+ }
1804
+ if (this._def.catchall instanceof re) {
1805
+ const d = this._def.unknownKeys;
1806
+ if (d === "passthrough")
1807
+ for (const m of a)
1808
+ h.push({
1809
+ key: { status: "valid", value: m },
1810
+ value: { status: "valid", value: s.data[m] }
1811
+ });
1812
+ else if (d === "strict")
1813
+ a.length > 0 && (p(s, {
1814
+ code: u.unrecognized_keys,
1815
+ keys: a
1816
+ }), n.dirty());
1817
+ else if (d !== "strip") throw new Error("Internal ZodObject error: invalid unknownKeys value.");
1818
+ } else {
1819
+ const d = this._def.catchall;
1820
+ for (const m of a) {
1821
+ const R = s.data[m];
1822
+ h.push({
1823
+ key: { status: "valid", value: m },
1824
+ value: d._parse(
1825
+ new z(s, R, s.path, m)
1826
+ //, ctx.child(key), value, getParsedType(value)
1827
+ ),
1828
+ alwaysSet: m in s.data
1829
+ });
1830
+ }
1831
+ }
1832
+ return s.common.async ? Promise.resolve().then(async () => {
1833
+ const d = [];
1834
+ for (const m of h) {
1835
+ const R = await m.key, P = await m.value;
1836
+ d.push({
1837
+ key: R,
1838
+ value: P,
1839
+ alwaysSet: m.alwaysSet
1840
+ });
1841
+ }
1842
+ return d;
1843
+ }).then((d) => $.mergeObjectSync(n, d)) : $.mergeObjectSync(n, h);
1844
+ }
1845
+ get shape() {
1846
+ return this._def.shape();
1847
+ }
1848
+ strict(e) {
1849
+ return y.errToObj, new A({
1850
+ ...this._def,
1851
+ unknownKeys: "strict",
1852
+ ...e !== void 0 ? {
1853
+ errorMap: (r, n) => {
1854
+ var i, c;
1855
+ const s = ((c = (i = this._def).errorMap) == null ? void 0 : c.call(i, r, n).message) ?? n.defaultError;
1856
+ return r.code === "unrecognized_keys" ? {
1857
+ message: y.errToObj(e).message ?? s
1858
+ } : {
1859
+ message: s
1860
+ };
1861
+ }
1862
+ } : {}
1863
+ });
1864
+ }
1865
+ strip() {
1866
+ return new A({
1867
+ ...this._def,
1868
+ unknownKeys: "strip"
1869
+ });
1870
+ }
1871
+ passthrough() {
1872
+ return new A({
1873
+ ...this._def,
1874
+ unknownKeys: "passthrough"
1875
+ });
1876
+ }
1877
+ // const AugmentFactory =
1878
+ // <Def extends ZodObjectDef>(def: Def) =>
1879
+ // <Augmentation extends ZodRawShape>(
1880
+ // augmentation: Augmentation
1881
+ // ): ZodObject<
1882
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
1883
+ // Def["unknownKeys"],
1884
+ // Def["catchall"]
1885
+ // > => {
1886
+ // return new ZodObject({
1887
+ // ...def,
1888
+ // shape: () => ({
1889
+ // ...def.shape(),
1890
+ // ...augmentation,
1891
+ // }),
1892
+ // }) as any;
1893
+ // };
1894
+ extend(e) {
1895
+ return new A({
1896
+ ...this._def,
1897
+ shape: () => ({
1898
+ ...this._def.shape(),
1899
+ ...e
1900
+ })
1901
+ });
1902
+ }
1903
+ /**
1904
+ * Prior to zod@1.0.12 there was a bug in the
1905
+ * inferred type of merged objects. Please
1906
+ * upgrade if you are experiencing issues.
1907
+ */
1908
+ merge(e) {
1909
+ return new A({
1910
+ unknownKeys: e._def.unknownKeys,
1911
+ catchall: e._def.catchall,
1912
+ shape: () => ({
1913
+ ...this._def.shape(),
1914
+ ...e._def.shape()
1915
+ }),
1916
+ typeName: k.ZodObject
1917
+ });
1918
+ }
1919
+ // merge<
1920
+ // Incoming extends AnyZodObject,
1921
+ // Augmentation extends Incoming["shape"],
1922
+ // NewOutput extends {
1923
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
1924
+ // ? Augmentation[k]["_output"]
1925
+ // : k extends keyof Output
1926
+ // ? Output[k]
1927
+ // : never;
1928
+ // },
1929
+ // NewInput extends {
1930
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
1931
+ // ? Augmentation[k]["_input"]
1932
+ // : k extends keyof Input
1933
+ // ? Input[k]
1934
+ // : never;
1935
+ // }
1936
+ // >(
1937
+ // merging: Incoming
1938
+ // ): ZodObject<
1939
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
1940
+ // Incoming["_def"]["unknownKeys"],
1941
+ // Incoming["_def"]["catchall"],
1942
+ // NewOutput,
1943
+ // NewInput
1944
+ // > {
1945
+ // const merged: any = new ZodObject({
1946
+ // unknownKeys: merging._def.unknownKeys,
1947
+ // catchall: merging._def.catchall,
1948
+ // shape: () =>
1949
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
1950
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
1951
+ // }) as any;
1952
+ // return merged;
1953
+ // }
1954
+ setKey(e, r) {
1955
+ return this.augment({ [e]: r });
1956
+ }
1957
+ // merge<Incoming extends AnyZodObject>(
1958
+ // merging: Incoming
1959
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
1960
+ // ZodObject<
1961
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
1962
+ // Incoming["_def"]["unknownKeys"],
1963
+ // Incoming["_def"]["catchall"]
1964
+ // > {
1965
+ // // const mergedShape = objectUtil.mergeShapes(
1966
+ // // this._def.shape(),
1967
+ // // merging._def.shape()
1968
+ // // );
1969
+ // const merged: any = new ZodObject({
1970
+ // unknownKeys: merging._def.unknownKeys,
1971
+ // catchall: merging._def.catchall,
1972
+ // shape: () =>
1973
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
1974
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
1975
+ // }) as any;
1976
+ // return merged;
1977
+ // }
1978
+ catchall(e) {
1979
+ return new A({
1980
+ ...this._def,
1981
+ catchall: e
1982
+ });
1983
+ }
1984
+ pick(e) {
1985
+ const r = {};
1986
+ for (const n of E.objectKeys(e))
1987
+ e[n] && this.shape[n] && (r[n] = this.shape[n]);
1988
+ return new A({
1989
+ ...this._def,
1990
+ shape: () => r
1991
+ });
1992
+ }
1993
+ omit(e) {
1994
+ const r = {};
1995
+ for (const n of E.objectKeys(this.shape))
1996
+ e[n] || (r[n] = this.shape[n]);
1997
+ return new A({
1998
+ ...this._def,
1999
+ shape: () => r
2000
+ });
2001
+ }
2002
+ /**
2003
+ * @deprecated
2004
+ */
2005
+ deepPartial() {
2006
+ return ue(this);
2007
+ }
2008
+ partial(e) {
2009
+ const r = {};
2010
+ for (const n of E.objectKeys(this.shape)) {
2011
+ const s = this.shape[n];
2012
+ e && !e[n] ? r[n] = s : r[n] = s.optional();
2013
+ }
2014
+ return new A({
2015
+ ...this._def,
2016
+ shape: () => r
2017
+ });
2018
+ }
2019
+ required(e) {
2020
+ const r = {};
2021
+ for (const n of E.objectKeys(this.shape))
2022
+ if (e && !e[n])
2023
+ r[n] = this.shape[n];
2024
+ else {
2025
+ let i = this.shape[n];
2026
+ for (; i instanceof V; )
2027
+ i = i._def.innerType;
2028
+ r[n] = i;
2029
+ }
2030
+ return new A({
2031
+ ...this._def,
2032
+ shape: () => r
2033
+ });
2034
+ }
2035
+ keyof() {
2036
+ return $t(E.objectKeys(this.shape));
2037
+ }
2038
+ }
2039
+ A.create = (t, e) => new A({
2040
+ shape: () => t,
2041
+ unknownKeys: "strip",
2042
+ catchall: re.create(),
2043
+ typeName: k.ZodObject,
2044
+ ...T(e)
2045
+ });
2046
+ A.strictCreate = (t, e) => new A({
2047
+ shape: () => t,
2048
+ unknownKeys: "strict",
2049
+ catchall: re.create(),
2050
+ typeName: k.ZodObject,
2051
+ ...T(e)
2052
+ });
2053
+ A.lazycreate = (t, e) => new A({
2054
+ shape: t,
2055
+ unknownKeys: "strip",
2056
+ catchall: re.create(),
2057
+ typeName: k.ZodObject,
2058
+ ...T(e)
2059
+ });
2060
+ class Ee extends S {
2061
+ _parse(e) {
2062
+ const { ctx: r } = this._processInputParams(e), n = this._def.options;
2063
+ function s(i) {
2064
+ for (const a of i)
2065
+ if (a.result.status === "valid")
2066
+ return a.result;
2067
+ for (const a of i)
2068
+ if (a.result.status === "dirty")
2069
+ return r.common.issues.push(...a.ctx.common.issues), a.result;
2070
+ const c = i.map((a) => new j(a.ctx.common.issues));
2071
+ return p(r, {
2072
+ code: u.invalid_union,
2073
+ unionErrors: c
2074
+ }), v;
2075
+ }
2076
+ if (r.common.async)
2077
+ return Promise.all(n.map(async (i) => {
2078
+ const c = {
2079
+ ...r,
2080
+ common: {
2081
+ ...r.common,
2082
+ issues: []
2083
+ },
2084
+ parent: null
2085
+ };
2086
+ return {
2087
+ result: await i._parseAsync({
2088
+ data: r.data,
2089
+ path: r.path,
2090
+ parent: c
2091
+ }),
2092
+ ctx: c
2093
+ };
2094
+ })).then(s);
2095
+ {
2096
+ let i;
2097
+ const c = [];
2098
+ for (const h of n) {
2099
+ const d = {
2100
+ ...r,
2101
+ common: {
2102
+ ...r.common,
2103
+ issues: []
2104
+ },
2105
+ parent: null
2106
+ }, m = h._parseSync({
2107
+ data: r.data,
2108
+ path: r.path,
2109
+ parent: d
2110
+ });
2111
+ if (m.status === "valid")
2112
+ return m;
2113
+ m.status === "dirty" && !i && (i = { result: m, ctx: d }), d.common.issues.length && c.push(d.common.issues);
2114
+ }
2115
+ if (i)
2116
+ return r.common.issues.push(...i.ctx.common.issues), i.result;
2117
+ const a = c.map((h) => new j(h));
2118
+ return p(r, {
2119
+ code: u.invalid_union,
2120
+ unionErrors: a
2121
+ }), v;
2122
+ }
2123
+ }
2124
+ get options() {
2125
+ return this._def.options;
2126
+ }
2127
+ }
2128
+ Ee.create = (t, e) => new Ee({
2129
+ options: t,
2130
+ typeName: k.ZodUnion,
2131
+ ...T(e)
2132
+ });
2133
+ const J = (t) => t instanceof Ce ? J(t.schema) : t instanceof Y ? J(t.innerType()) : t instanceof Oe ? [t.value] : t instanceof ne ? t.options : t instanceof st ? E.objectValues(t.enum) : t instanceof Ne ? J(t._def.innerType) : t instanceof We ? [void 0] : t instanceof Ie ? [null] : t instanceof V ? [void 0, ...J(t.unwrap())] : t instanceof se ? [null, ...J(t.unwrap())] : t instanceof ut || t instanceof Pe ? J(t.unwrap()) : t instanceof Me ? J(t._def.innerType) : [];
2134
+ class ze extends S {
2135
+ _parse(e) {
2136
+ const { ctx: r } = this._processInputParams(e);
2137
+ if (r.parsedType !== g.object)
2138
+ return p(r, {
2139
+ code: u.invalid_type,
2140
+ expected: g.object,
2141
+ received: r.parsedType
2142
+ }), v;
2143
+ const n = this.discriminator, s = r.data[n], i = this.optionsMap.get(s);
2144
+ return i ? r.common.async ? i._parseAsync({
2145
+ data: r.data,
2146
+ path: r.path,
2147
+ parent: r
2148
+ }) : i._parseSync({
2149
+ data: r.data,
2150
+ path: r.path,
2151
+ parent: r
2152
+ }) : (p(r, {
2153
+ code: u.invalid_union_discriminator,
2154
+ options: Array.from(this.optionsMap.keys()),
2155
+ path: [n]
2156
+ }), v);
2157
+ }
2158
+ get discriminator() {
2159
+ return this._def.discriminator;
2160
+ }
2161
+ get options() {
2162
+ return this._def.options;
2163
+ }
2164
+ get optionsMap() {
2165
+ return this._def.optionsMap;
2166
+ }
2167
+ /**
2168
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
2169
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
2170
+ * have a different value for each object in the union.
2171
+ * @param discriminator the name of the discriminator property
2172
+ * @param types an array of object schemas
2173
+ * @param params
2174
+ */
2175
+ static create(e, r, n) {
2176
+ const s = /* @__PURE__ */ new Map();
2177
+ for (const i of r) {
2178
+ const c = J(i.shape[e]);
2179
+ if (!c.length)
2180
+ throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);
2181
+ for (const a of c) {
2182
+ if (s.has(a))
2183
+ throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(a)}`);
2184
+ s.set(a, i);
2185
+ }
2186
+ }
2187
+ return new ze({
2188
+ typeName: k.ZodDiscriminatedUnion,
2189
+ discriminator: e,
2190
+ options: r,
2191
+ optionsMap: s,
2192
+ ...T(n)
2193
+ });
2194
+ }
2195
+ }
2196
+ function rt(t, e) {
2197
+ const r = te(t), n = te(e);
2198
+ if (t === e)
2199
+ return { valid: !0, data: t };
2200
+ if (r === g.object && n === g.object) {
2201
+ const s = E.objectKeys(e), i = E.objectKeys(t).filter((a) => s.indexOf(a) !== -1), c = { ...t, ...e };
2202
+ for (const a of i) {
2203
+ const h = rt(t[a], e[a]);
2204
+ if (!h.valid)
2205
+ return { valid: !1 };
2206
+ c[a] = h.data;
2207
+ }
2208
+ return { valid: !0, data: c };
2209
+ } else if (r === g.array && n === g.array) {
2210
+ if (t.length !== e.length)
2211
+ return { valid: !1 };
2212
+ const s = [];
2213
+ for (let i = 0; i < t.length; i++) {
2214
+ const c = t[i], a = e[i], h = rt(c, a);
2215
+ if (!h.valid)
2216
+ return { valid: !1 };
2217
+ s.push(h.data);
2218
+ }
2219
+ return { valid: !0, data: s };
2220
+ } else return r === g.date && n === g.date && +t == +e ? { valid: !0, data: t } : { valid: !1 };
2221
+ }
2222
+ class Re extends S {
2223
+ _parse(e) {
2224
+ const { status: r, ctx: n } = this._processInputParams(e), s = (i, c) => {
2225
+ if (vt(i) || vt(c))
2226
+ return v;
2227
+ const a = rt(i.value, c.value);
2228
+ return a.valid ? ((kt(i) || kt(c)) && r.dirty(), { status: r.value, value: a.data }) : (p(n, {
2229
+ code: u.invalid_intersection_types
2230
+ }), v);
2231
+ };
2232
+ return n.common.async ? Promise.all([
2233
+ this._def.left._parseAsync({
2234
+ data: n.data,
2235
+ path: n.path,
2236
+ parent: n
2237
+ }),
2238
+ this._def.right._parseAsync({
2239
+ data: n.data,
2240
+ path: n.path,
2241
+ parent: n
2242
+ })
2243
+ ]).then(([i, c]) => s(i, c)) : s(this._def.left._parseSync({
2244
+ data: n.data,
2245
+ path: n.path,
2246
+ parent: n
2247
+ }), this._def.right._parseSync({
2248
+ data: n.data,
2249
+ path: n.path,
2250
+ parent: n
2251
+ }));
2252
+ }
2253
+ }
2254
+ Re.create = (t, e, r) => new Re({
2255
+ left: t,
2256
+ right: e,
2257
+ typeName: k.ZodIntersection,
2258
+ ...T(r)
2259
+ });
2260
+ class q extends S {
2261
+ _parse(e) {
2262
+ const { status: r, ctx: n } = this._processInputParams(e);
2263
+ if (n.parsedType !== g.array)
2264
+ return p(n, {
2265
+ code: u.invalid_type,
2266
+ expected: g.array,
2267
+ received: n.parsedType
2268
+ }), v;
2269
+ if (n.data.length < this._def.items.length)
2270
+ return p(n, {
2271
+ code: u.too_small,
2272
+ minimum: this._def.items.length,
2273
+ inclusive: !0,
2274
+ exact: !1,
2275
+ type: "array"
2276
+ }), v;
2277
+ !this._def.rest && n.data.length > this._def.items.length && (p(n, {
2278
+ code: u.too_big,
2279
+ maximum: this._def.items.length,
2280
+ inclusive: !0,
2281
+ exact: !1,
2282
+ type: "array"
2283
+ }), r.dirty());
2284
+ const i = [...n.data].map((c, a) => {
2285
+ const h = this._def.items[a] || this._def.rest;
2286
+ return h ? h._parse(new z(n, c, n.path, a)) : null;
2287
+ }).filter((c) => !!c);
2288
+ return n.common.async ? Promise.all(i).then((c) => $.mergeArray(r, c)) : $.mergeArray(r, i);
2289
+ }
2290
+ get items() {
2291
+ return this._def.items;
2292
+ }
2293
+ rest(e) {
2294
+ return new q({
2295
+ ...this._def,
2296
+ rest: e
2297
+ });
2298
+ }
2299
+ }
2300
+ q.create = (t, e) => {
2301
+ if (!Array.isArray(t))
2302
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
2303
+ return new q({
2304
+ items: t,
2305
+ typeName: k.ZodTuple,
2306
+ rest: null,
2307
+ ...T(e)
2308
+ });
2309
+ };
2310
+ class Ae extends S {
2311
+ get keySchema() {
2312
+ return this._def.keyType;
2313
+ }
2314
+ get valueSchema() {
2315
+ return this._def.valueType;
2316
+ }
2317
+ _parse(e) {
2318
+ const { status: r, ctx: n } = this._processInputParams(e);
2319
+ if (n.parsedType !== g.object)
2320
+ return p(n, {
2321
+ code: u.invalid_type,
2322
+ expected: g.object,
2323
+ received: n.parsedType
2324
+ }), v;
2325
+ const s = [], i = this._def.keyType, c = this._def.valueType;
2326
+ for (const a in n.data)
2327
+ s.push({
2328
+ key: i._parse(new z(n, a, n.path, a)),
2329
+ value: c._parse(new z(n, n.data[a], n.path, a)),
2330
+ alwaysSet: a in n.data
2331
+ });
2332
+ return n.common.async ? $.mergeObjectAsync(r, s) : $.mergeObjectSync(r, s);
2333
+ }
2334
+ get element() {
2335
+ return this._def.valueType;
2336
+ }
2337
+ static create(e, r, n) {
2338
+ return r instanceof S ? new Ae({
2339
+ keyType: e,
2340
+ valueType: r,
2341
+ typeName: k.ZodRecord,
2342
+ ...T(n)
2343
+ }) : new Ae({
2344
+ keyType: B.create(),
2345
+ valueType: e,
2346
+ typeName: k.ZodRecord,
2347
+ ...T(r)
2348
+ });
2349
+ }
2350
+ }
2351
+ class nt extends S {
2352
+ get keySchema() {
2353
+ return this._def.keyType;
2354
+ }
2355
+ get valueSchema() {
2356
+ return this._def.valueType;
2357
+ }
2358
+ _parse(e) {
2359
+ const { status: r, ctx: n } = this._processInputParams(e);
2360
+ if (n.parsedType !== g.map)
2361
+ return p(n, {
2362
+ code: u.invalid_type,
2363
+ expected: g.map,
2364
+ received: n.parsedType
2365
+ }), v;
2366
+ const s = this._def.keyType, i = this._def.valueType, c = [...n.data.entries()].map(([a, h], d) => ({
2367
+ key: s._parse(new z(n, a, n.path, [d, "key"])),
2368
+ value: i._parse(new z(n, h, n.path, [d, "value"]))
2369
+ }));
2370
+ if (n.common.async) {
2371
+ const a = /* @__PURE__ */ new Map();
2372
+ return Promise.resolve().then(async () => {
2373
+ for (const h of c) {
2374
+ const d = await h.key, m = await h.value;
2375
+ if (d.status === "aborted" || m.status === "aborted")
2376
+ return v;
2377
+ (d.status === "dirty" || m.status === "dirty") && r.dirty(), a.set(d.value, m.value);
2378
+ }
2379
+ return { status: r.value, value: a };
2380
+ });
2381
+ } else {
2382
+ const a = /* @__PURE__ */ new Map();
2383
+ for (const h of c) {
2384
+ const d = h.key, m = h.value;
2385
+ if (d.status === "aborted" || m.status === "aborted")
2386
+ return v;
2387
+ (d.status === "dirty" || m.status === "dirty") && r.dirty(), a.set(d.value, m.value);
2388
+ }
2389
+ return { status: r.value, value: a };
2390
+ }
2391
+ }
2392
+ }
2393
+ nt.create = (t, e, r) => new nt({
2394
+ valueType: e,
2395
+ keyType: t,
2396
+ typeName: k.ZodMap,
2397
+ ...T(r)
2398
+ });
2399
+ class me extends S {
2400
+ _parse(e) {
2401
+ const { status: r, ctx: n } = this._processInputParams(e);
2402
+ if (n.parsedType !== g.set)
2403
+ return p(n, {
2404
+ code: u.invalid_type,
2405
+ expected: g.set,
2406
+ received: n.parsedType
2407
+ }), v;
2408
+ const s = this._def;
2409
+ s.minSize !== null && n.data.size < s.minSize.value && (p(n, {
2410
+ code: u.too_small,
2411
+ minimum: s.minSize.value,
2412
+ type: "set",
2413
+ inclusive: !0,
2414
+ exact: !1,
2415
+ message: s.minSize.message
2416
+ }), r.dirty()), s.maxSize !== null && n.data.size > s.maxSize.value && (p(n, {
2417
+ code: u.too_big,
2418
+ maximum: s.maxSize.value,
2419
+ type: "set",
2420
+ inclusive: !0,
2421
+ exact: !1,
2422
+ message: s.maxSize.message
2423
+ }), r.dirty());
2424
+ const i = this._def.valueType;
2425
+ function c(h) {
2426
+ const d = /* @__PURE__ */ new Set();
2427
+ for (const m of h) {
2428
+ if (m.status === "aborted")
2429
+ return v;
2430
+ m.status === "dirty" && r.dirty(), d.add(m.value);
2431
+ }
2432
+ return { status: r.value, value: d };
2433
+ }
2434
+ const a = [...n.data.values()].map((h, d) => i._parse(new z(n, h, n.path, d)));
2435
+ return n.common.async ? Promise.all(a).then((h) => c(h)) : c(a);
2436
+ }
2437
+ min(e, r) {
2438
+ return new me({
2439
+ ...this._def,
2440
+ minSize: { value: e, message: y.toString(r) }
2441
+ });
2442
+ }
2443
+ max(e, r) {
2444
+ return new me({
2445
+ ...this._def,
2446
+ maxSize: { value: e, message: y.toString(r) }
2447
+ });
2448
+ }
2449
+ size(e, r) {
2450
+ return this.min(e, r).max(e, r);
2451
+ }
2452
+ nonempty(e) {
2453
+ return this.min(1, e);
2454
+ }
2455
+ }
2456
+ me.create = (t, e) => new me({
2457
+ valueType: t,
2458
+ minSize: null,
2459
+ maxSize: null,
2460
+ typeName: k.ZodSet,
2461
+ ...T(e)
2462
+ });
2463
+ class we extends S {
2464
+ constructor() {
2465
+ super(...arguments), this.validate = this.implement;
2466
+ }
2467
+ _parse(e) {
2468
+ const { ctx: r } = this._processInputParams(e);
2469
+ if (r.parsedType !== g.function)
2470
+ return p(r, {
2471
+ code: u.invalid_type,
2472
+ expected: g.function,
2473
+ received: r.parsedType
2474
+ }), v;
2475
+ function n(a, h) {
2476
+ return Xe({
2477
+ data: a,
2478
+ path: r.path,
2479
+ errorMaps: [r.common.contextualErrorMap, r.schemaErrorMap, Qe(), xe].filter((d) => !!d),
2480
+ issueData: {
2481
+ code: u.invalid_arguments,
2482
+ argumentsError: h
2483
+ }
2484
+ });
2485
+ }
2486
+ function s(a, h) {
2487
+ return Xe({
2488
+ data: a,
2489
+ path: r.path,
2490
+ errorMaps: [r.common.contextualErrorMap, r.schemaErrorMap, Qe(), xe].filter((d) => !!d),
2491
+ issueData: {
2492
+ code: u.invalid_return_type,
2493
+ returnTypeError: h
2494
+ }
2495
+ });
2496
+ }
2497
+ const i = { errorMap: r.common.contextualErrorMap }, c = r.data;
2498
+ if (this._def.returns instanceof ge) {
2499
+ const a = this;
2500
+ return L(async function(...h) {
2501
+ const d = new j([]), m = await a._def.args.parseAsync(h, i).catch((X) => {
2502
+ throw d.addIssue(n(h, X)), d;
2503
+ }), R = await Reflect.apply(c, this, m);
2504
+ return await a._def.returns._def.type.parseAsync(R, i).catch((X) => {
2505
+ throw d.addIssue(s(R, X)), d;
2506
+ });
2507
+ });
2508
+ } else {
2509
+ const a = this;
2510
+ return L(function(...h) {
2511
+ const d = a._def.args.safeParse(h, i);
2512
+ if (!d.success)
2513
+ throw new j([n(h, d.error)]);
2514
+ const m = Reflect.apply(c, this, d.data), R = a._def.returns.safeParse(m, i);
2515
+ if (!R.success)
2516
+ throw new j([s(m, R.error)]);
2517
+ return R.data;
2518
+ });
2519
+ }
2520
+ }
2521
+ parameters() {
2522
+ return this._def.args;
2523
+ }
2524
+ returnType() {
2525
+ return this._def.returns;
2526
+ }
2527
+ args(...e) {
2528
+ return new we({
2529
+ ...this._def,
2530
+ args: q.create(e).rest(ae.create())
2531
+ });
2532
+ }
2533
+ returns(e) {
2534
+ return new we({
2535
+ ...this._def,
2536
+ returns: e
2537
+ });
2538
+ }
2539
+ implement(e) {
2540
+ return this.parse(e);
2541
+ }
2542
+ strictImplement(e) {
2543
+ return this.parse(e);
2544
+ }
2545
+ static create(e, r, n) {
2546
+ return new we({
2547
+ args: e || q.create([]).rest(ae.create()),
2548
+ returns: r || ae.create(),
2549
+ typeName: k.ZodFunction,
2550
+ ...T(n)
2551
+ });
2552
+ }
2553
+ }
2554
+ class Ce extends S {
2555
+ get schema() {
2556
+ return this._def.getter();
2557
+ }
2558
+ _parse(e) {
2559
+ const { ctx: r } = this._processInputParams(e);
2560
+ return this._def.getter()._parse({ data: r.data, path: r.path, parent: r });
2561
+ }
2562
+ }
2563
+ Ce.create = (t, e) => new Ce({
2564
+ getter: t,
2565
+ typeName: k.ZodLazy,
2566
+ ...T(e)
2567
+ });
2568
+ class Oe extends S {
2569
+ _parse(e) {
2570
+ if (e.data !== this._def.value) {
2571
+ const r = this._getOrReturnCtx(e);
2572
+ return p(r, {
2573
+ received: r.data,
2574
+ code: u.invalid_literal,
2575
+ expected: this._def.value
2576
+ }), v;
2577
+ }
2578
+ return { status: "valid", value: e.data };
2579
+ }
2580
+ get value() {
2581
+ return this._def.value;
2582
+ }
2583
+ }
2584
+ Oe.create = (t, e) => new Oe({
2585
+ value: t,
2586
+ typeName: k.ZodLiteral,
2587
+ ...T(e)
2588
+ });
2589
+ function $t(t, e) {
2590
+ return new ne({
2591
+ values: t,
2592
+ typeName: k.ZodEnum,
2593
+ ...T(e)
2594
+ });
2595
+ }
2596
+ class ne extends S {
2597
+ _parse(e) {
2598
+ if (typeof e.data != "string") {
2599
+ const r = this._getOrReturnCtx(e), n = this._def.values;
2600
+ return p(r, {
2601
+ expected: E.joinValues(n),
2602
+ received: r.parsedType,
2603
+ code: u.invalid_type
2604
+ }), v;
2605
+ }
2606
+ if (this._cache || (this._cache = new Set(this._def.values)), !this._cache.has(e.data)) {
2607
+ const r = this._getOrReturnCtx(e), n = this._def.values;
2608
+ return p(r, {
2609
+ received: r.data,
2610
+ code: u.invalid_enum_value,
2611
+ options: n
2612
+ }), v;
2613
+ }
2614
+ return L(e.data);
2615
+ }
2616
+ get options() {
2617
+ return this._def.values;
2618
+ }
2619
+ get enum() {
2620
+ const e = {};
2621
+ for (const r of this._def.values)
2622
+ e[r] = r;
2623
+ return e;
2624
+ }
2625
+ get Values() {
2626
+ const e = {};
2627
+ for (const r of this._def.values)
2628
+ e[r] = r;
2629
+ return e;
2630
+ }
2631
+ get Enum() {
2632
+ const e = {};
2633
+ for (const r of this._def.values)
2634
+ e[r] = r;
2635
+ return e;
2636
+ }
2637
+ extract(e, r = this._def) {
2638
+ return ne.create(e, {
2639
+ ...this._def,
2640
+ ...r
2641
+ });
2642
+ }
2643
+ exclude(e, r = this._def) {
2644
+ return ne.create(this.options.filter((n) => !e.includes(n)), {
2645
+ ...this._def,
2646
+ ...r
2647
+ });
2648
+ }
2649
+ }
2650
+ ne.create = $t;
2651
+ class st extends S {
2652
+ _parse(e) {
2653
+ const r = E.getValidEnumValues(this._def.values), n = this._getOrReturnCtx(e);
2654
+ if (n.parsedType !== g.string && n.parsedType !== g.number) {
2655
+ const s = E.objectValues(r);
2656
+ return p(n, {
2657
+ expected: E.joinValues(s),
2658
+ received: n.parsedType,
2659
+ code: u.invalid_type
2660
+ }), v;
2661
+ }
2662
+ if (this._cache || (this._cache = new Set(E.getValidEnumValues(this._def.values))), !this._cache.has(e.data)) {
2663
+ const s = E.objectValues(r);
2664
+ return p(n, {
2665
+ received: n.data,
2666
+ code: u.invalid_enum_value,
2667
+ options: s
2668
+ }), v;
2669
+ }
2670
+ return L(e.data);
2671
+ }
2672
+ get enum() {
2673
+ return this._def.values;
2674
+ }
2675
+ }
2676
+ st.create = (t, e) => new st({
2677
+ values: t,
2678
+ typeName: k.ZodNativeEnum,
2679
+ ...T(e)
2680
+ });
2681
+ class ge extends S {
2682
+ unwrap() {
2683
+ return this._def.type;
2684
+ }
2685
+ _parse(e) {
2686
+ const { ctx: r } = this._processInputParams(e);
2687
+ if (r.parsedType !== g.promise && r.common.async === !1)
2688
+ return p(r, {
2689
+ code: u.invalid_type,
2690
+ expected: g.promise,
2691
+ received: r.parsedType
2692
+ }), v;
2693
+ const n = r.parsedType === g.promise ? r.data : Promise.resolve(r.data);
2694
+ return L(n.then((s) => this._def.type.parseAsync(s, {
2695
+ path: r.path,
2696
+ errorMap: r.common.contextualErrorMap
2697
+ })));
2698
+ }
2699
+ }
2700
+ ge.create = (t, e) => new ge({
2701
+ type: t,
2702
+ typeName: k.ZodPromise,
2703
+ ...T(e)
2704
+ });
2705
+ class Y extends S {
2706
+ innerType() {
2707
+ return this._def.schema;
2708
+ }
2709
+ sourceType() {
2710
+ return this._def.schema._def.typeName === k.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
2711
+ }
2712
+ _parse(e) {
2713
+ const { status: r, ctx: n } = this._processInputParams(e), s = this._def.effect || null, i = {
2714
+ addIssue: (c) => {
2715
+ p(n, c), c.fatal ? r.abort() : r.dirty();
2716
+ },
2717
+ get path() {
2718
+ return n.path;
2719
+ }
2720
+ };
2721
+ if (i.addIssue = i.addIssue.bind(i), s.type === "preprocess") {
2722
+ const c = s.transform(n.data, i);
2723
+ if (n.common.async)
2724
+ return Promise.resolve(c).then(async (a) => {
2725
+ if (r.value === "aborted")
2726
+ return v;
2727
+ const h = await this._def.schema._parseAsync({
2728
+ data: a,
2729
+ path: n.path,
2730
+ parent: n
2731
+ });
2732
+ return h.status === "aborted" ? v : h.status === "dirty" || r.value === "dirty" ? ve(h.value) : h;
2733
+ });
2734
+ {
2735
+ if (r.value === "aborted")
2736
+ return v;
2737
+ const a = this._def.schema._parseSync({
2738
+ data: c,
2739
+ path: n.path,
2740
+ parent: n
2741
+ });
2742
+ return a.status === "aborted" ? v : a.status === "dirty" || r.value === "dirty" ? ve(a.value) : a;
2743
+ }
2744
+ }
2745
+ if (s.type === "refinement") {
2746
+ const c = (a) => {
2747
+ const h = s.refinement(a, i);
2748
+ if (n.common.async)
2749
+ return Promise.resolve(h);
2750
+ if (h instanceof Promise)
2751
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
2752
+ return a;
2753
+ };
2754
+ if (n.common.async === !1) {
2755
+ const a = this._def.schema._parseSync({
2756
+ data: n.data,
2757
+ path: n.path,
2758
+ parent: n
2759
+ });
2760
+ return a.status === "aborted" ? v : (a.status === "dirty" && r.dirty(), c(a.value), { status: r.value, value: a.value });
2761
+ } else
2762
+ return this._def.schema._parseAsync({ data: n.data, path: n.path, parent: n }).then((a) => a.status === "aborted" ? v : (a.status === "dirty" && r.dirty(), c(a.value).then(() => ({ status: r.value, value: a.value }))));
2763
+ }
2764
+ if (s.type === "transform")
2765
+ if (n.common.async === !1) {
2766
+ const c = this._def.schema._parseSync({
2767
+ data: n.data,
2768
+ path: n.path,
2769
+ parent: n
2770
+ });
2771
+ if (!pe(c))
2772
+ return v;
2773
+ const a = s.transform(c.value, i);
2774
+ if (a instanceof Promise)
2775
+ throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");
2776
+ return { status: r.value, value: a };
2777
+ } else
2778
+ return this._def.schema._parseAsync({ data: n.data, path: n.path, parent: n }).then((c) => pe(c) ? Promise.resolve(s.transform(c.value, i)).then((a) => ({
2779
+ status: r.value,
2780
+ value: a
2781
+ })) : v);
2782
+ E.assertNever(s);
2783
+ }
2784
+ }
2785
+ Y.create = (t, e, r) => new Y({
2786
+ schema: t,
2787
+ typeName: k.ZodEffects,
2788
+ effect: e,
2789
+ ...T(r)
2790
+ });
2791
+ Y.createWithPreprocess = (t, e, r) => new Y({
2792
+ schema: e,
2793
+ effect: { type: "preprocess", transform: t },
2794
+ typeName: k.ZodEffects,
2795
+ ...T(r)
2796
+ });
2797
+ class V extends S {
2798
+ _parse(e) {
2799
+ return this._getType(e) === g.undefined ? L(void 0) : this._def.innerType._parse(e);
2800
+ }
2801
+ unwrap() {
2802
+ return this._def.innerType;
2803
+ }
2804
+ }
2805
+ V.create = (t, e) => new V({
2806
+ innerType: t,
2807
+ typeName: k.ZodOptional,
2808
+ ...T(e)
2809
+ });
2810
+ class se extends S {
2811
+ _parse(e) {
2812
+ return this._getType(e) === g.null ? L(null) : this._def.innerType._parse(e);
2813
+ }
2814
+ unwrap() {
2815
+ return this._def.innerType;
2816
+ }
2817
+ }
2818
+ se.create = (t, e) => new se({
2819
+ innerType: t,
2820
+ typeName: k.ZodNullable,
2821
+ ...T(e)
2822
+ });
2823
+ class Ne extends S {
2824
+ _parse(e) {
2825
+ const { ctx: r } = this._processInputParams(e);
2826
+ let n = r.data;
2827
+ return r.parsedType === g.undefined && (n = this._def.defaultValue()), this._def.innerType._parse({
2828
+ data: n,
2829
+ path: r.path,
2830
+ parent: r
2831
+ });
2832
+ }
2833
+ removeDefault() {
2834
+ return this._def.innerType;
2835
+ }
2836
+ }
2837
+ Ne.create = (t, e) => new Ne({
2838
+ innerType: t,
2839
+ typeName: k.ZodDefault,
2840
+ defaultValue: typeof e.default == "function" ? e.default : () => e.default,
2841
+ ...T(e)
2842
+ });
2843
+ class Me extends S {
2844
+ _parse(e) {
2845
+ const { ctx: r } = this._processInputParams(e), n = {
2846
+ ...r,
2847
+ common: {
2848
+ ...r.common,
2849
+ issues: []
2850
+ }
2851
+ }, s = this._def.innerType._parse({
2852
+ data: n.data,
2853
+ path: n.path,
2854
+ parent: {
2855
+ ...n
2856
+ }
2857
+ });
2858
+ return De(s) ? s.then((i) => ({
2859
+ status: "valid",
2860
+ value: i.status === "valid" ? i.value : this._def.catchValue({
2861
+ get error() {
2862
+ return new j(n.common.issues);
2863
+ },
2864
+ input: n.data
2865
+ })
2866
+ })) : {
2867
+ status: "valid",
2868
+ value: s.status === "valid" ? s.value : this._def.catchValue({
2869
+ get error() {
2870
+ return new j(n.common.issues);
2871
+ },
2872
+ input: n.data
2873
+ })
2874
+ };
2875
+ }
2876
+ removeCatch() {
2877
+ return this._def.innerType;
2878
+ }
2879
+ }
2880
+ Me.create = (t, e) => new Me({
2881
+ innerType: t,
2882
+ typeName: k.ZodCatch,
2883
+ catchValue: typeof e.catch == "function" ? e.catch : () => e.catch,
2884
+ ...T(e)
2885
+ });
2886
+ class it extends S {
2887
+ _parse(e) {
2888
+ if (this._getType(e) !== g.nan) {
2889
+ const n = this._getOrReturnCtx(e);
2890
+ return p(n, {
2891
+ code: u.invalid_type,
2892
+ expected: g.nan,
2893
+ received: n.parsedType
2894
+ }), v;
2895
+ }
2896
+ return { status: "valid", value: e.data };
2897
+ }
2898
+ }
2899
+ it.create = (t) => new it({
2900
+ typeName: k.ZodNaN,
2901
+ ...T(t)
2902
+ });
2903
+ class ut extends S {
2904
+ _parse(e) {
2905
+ const { ctx: r } = this._processInputParams(e), n = r.data;
2906
+ return this._def.type._parse({
2907
+ data: n,
2908
+ path: r.path,
2909
+ parent: r
2910
+ });
2911
+ }
2912
+ unwrap() {
2913
+ return this._def.type;
2914
+ }
2915
+ }
2916
+ class qe extends S {
2917
+ _parse(e) {
2918
+ const { status: r, ctx: n } = this._processInputParams(e);
2919
+ if (n.common.async)
2920
+ return (async () => {
2921
+ const i = await this._def.in._parseAsync({
2922
+ data: n.data,
2923
+ path: n.path,
2924
+ parent: n
2925
+ });
2926
+ return i.status === "aborted" ? v : i.status === "dirty" ? (r.dirty(), ve(i.value)) : this._def.out._parseAsync({
2927
+ data: i.value,
2928
+ path: n.path,
2929
+ parent: n
2930
+ });
2931
+ })();
2932
+ {
2933
+ const s = this._def.in._parseSync({
2934
+ data: n.data,
2935
+ path: n.path,
2936
+ parent: n
2937
+ });
2938
+ return s.status === "aborted" ? v : s.status === "dirty" ? (r.dirty(), {
2939
+ status: "dirty",
2940
+ value: s.value
2941
+ }) : this._def.out._parseSync({
2942
+ data: s.value,
2943
+ path: n.path,
2944
+ parent: n
2945
+ });
2946
+ }
2947
+ }
2948
+ static create(e, r) {
2949
+ return new qe({
2950
+ in: e,
2951
+ out: r,
2952
+ typeName: k.ZodPipeline
2953
+ });
2954
+ }
2955
+ }
2956
+ class Pe extends S {
2957
+ _parse(e) {
2958
+ const r = this._def.innerType._parse(e), n = (s) => (pe(s) && (s.value = Object.freeze(s.value)), s);
2959
+ return De(r) ? r.then((s) => n(s)) : n(r);
2960
+ }
2961
+ unwrap() {
2962
+ return this._def.innerType;
2963
+ }
2964
+ }
2965
+ Pe.create = (t, e) => new Pe({
2966
+ innerType: t,
2967
+ typeName: k.ZodReadonly,
2968
+ ...T(e)
2969
+ });
2970
+ var k;
2971
+ (function(t) {
2972
+ t.ZodString = "ZodString", t.ZodNumber = "ZodNumber", t.ZodNaN = "ZodNaN", t.ZodBigInt = "ZodBigInt", t.ZodBoolean = "ZodBoolean", t.ZodDate = "ZodDate", t.ZodSymbol = "ZodSymbol", t.ZodUndefined = "ZodUndefined", t.ZodNull = "ZodNull", t.ZodAny = "ZodAny", t.ZodUnknown = "ZodUnknown", t.ZodNever = "ZodNever", t.ZodVoid = "ZodVoid", t.ZodArray = "ZodArray", t.ZodObject = "ZodObject", t.ZodUnion = "ZodUnion", t.ZodDiscriminatedUnion = "ZodDiscriminatedUnion", t.ZodIntersection = "ZodIntersection", t.ZodTuple = "ZodTuple", t.ZodRecord = "ZodRecord", t.ZodMap = "ZodMap", t.ZodSet = "ZodSet", t.ZodFunction = "ZodFunction", t.ZodLazy = "ZodLazy", t.ZodLiteral = "ZodLiteral", t.ZodEnum = "ZodEnum", t.ZodEffects = "ZodEffects", t.ZodNativeEnum = "ZodNativeEnum", t.ZodOptional = "ZodOptional", t.ZodNullable = "ZodNullable", t.ZodDefault = "ZodDefault", t.ZodCatch = "ZodCatch", t.ZodPromise = "ZodPromise", t.ZodBranded = "ZodBranded", t.ZodPipeline = "ZodPipeline", t.ZodReadonly = "ZodReadonly";
2973
+ })(k || (k = {}));
2974
+ const o = B.create, f = oe.create, H = ce.create, w = Ze.create, Lt = Ie.create, _ = ae.create;
2975
+ re.create;
2976
+ const I = W.create, l = A.create, x = Ee.create, jr = ze.create;
2977
+ Re.create;
2978
+ const Dr = q.create, b = Ae.create, Zr = Ce.create, Te = Oe.create, $e = ne.create;
2979
+ ge.create;
2980
+ V.create;
2981
+ se.create;
2982
+ const Q = Y.createWithPreprocess;
2983
+ function M(t, e = 0, r = 2) {
2984
+ if (e > r) return "...";
2985
+ if (t instanceof A) {
2986
+ const n = t.shape, s = Object.keys(n).filter((c) => !c.startsWith("__"));
2987
+ return s.length === 0 ? "{ }" : e >= r - 1 ? "{ ... }" : `{ ${s.map((c) => {
2988
+ const a = n[c], h = a instanceof V, d = M(h ? a.unwrap() : a, e + 1, r);
2989
+ return `${c}${h ? "?" : ""}: ${d}`;
2990
+ }).join(", ")} }`;
2991
+ }
2992
+ if (t instanceof Ee)
2993
+ return t.options.map((n) => M(n, e, r)).join(" or ");
2994
+ if (t instanceof B) return "string";
2995
+ if (t instanceof oe) return "number";
2996
+ if (t instanceof Ze) return "boolean";
2997
+ if (t instanceof ce) return "bigint";
2998
+ if (t instanceof Ie) return "null";
2999
+ if (t instanceof W) {
3000
+ const n = M(t.element, e + 1, r);
3001
+ return n === "unknown" || n === "any" ? "array" : `${n}[]`;
3002
+ }
3003
+ if (t instanceof q)
3004
+ return `[${t.items.map((n) => M(n, e + 1, r)).join(", ")}]`;
3005
+ if (t instanceof Ae) {
3006
+ const n = M(
3007
+ t._def.valueType,
3008
+ e + 1,
3009
+ r
3010
+ );
3011
+ return n === "unknown" || n === "any" ? "{ [key: string]: unknown }" : `{ [key: string]: ${n} }`;
3012
+ }
3013
+ return t instanceof V ? `${M(t.unwrap(), e, r)}?` : t instanceof Oe ? JSON.stringify(t.value) : t instanceof ne ? t.options.map((n) => `"${n}"`).join(" | ") : t instanceof et ? "any" : t instanceof ae ? "unknown" : t instanceof tt ? "void" : t instanceof We ? "undefined" : t instanceof Y ? M(t.innerType(), e, r) : t instanceof Ne ? M(t.removeDefault(), e, r) : t instanceof se ? `${M(t.unwrap(), e, r)} | null` : t instanceof Ce ? "lazy" : t instanceof ge ? `Promise<${M(t.unwrap(), e + 1, r)}>` : t instanceof we ? "function" : t instanceof Se ? "Date" : t instanceof nt ? "Map" : t instanceof me ? "Set" : t instanceof Re ? `${M(t._def.left, e, r)} & ${M(t._def.right, e, r)}` : t instanceof ze ? t.options.map((n) => M(n, e, r)).join(" or ") : t instanceof ut ? M(t.unwrap(), e, r) : t instanceof it ? "NaN" : t instanceof Me ? M(t.removeCatch(), e, r) : t instanceof qe ? M(t._def.in, e, r) : t instanceof Pe ? `readonly ${M(t.unwrap(), e, r)}` : "unknown";
3014
+ }
3015
+ function Wr(t) {
3016
+ return t === null ? "null" : t === void 0 ? "undefined" : Array.isArray(t) ? "array" : typeof t;
3017
+ }
3018
+ function Vr(t, e, r, n) {
3019
+ const s = r.filter((a) => a.path.length === 0), i = r.filter((a) => a.path.length > 0);
3020
+ if (s.length > 0 && i.length === 0) {
3021
+ const a = s.some((d) => d.code === "custom"), h = s.some(
3022
+ (d) => d.code !== "invalid_type" && d.code !== "invalid_literal" && d.code !== "invalid_union"
3023
+ );
3024
+ if (!a && !h) {
3025
+ const d = M(e), m = Wr(n);
3026
+ return `Invalid parameters for ${t}: expected ${d}${d === "{ }" ? " or no args" : ""}, received ${m}`;
3027
+ }
3028
+ }
3029
+ const c = r.map((a) => `at '${a.path.length > 0 ? a.path.join(".") : "root"}': ${a.message}`);
3030
+ return `Invalid parameters for ${t}: ${c.join("; ")}`;
3031
+ }
3032
+ const Fr = /* @__PURE__ */ new Set();
3033
+ function Ur(t) {
3034
+ return Fr.has(t);
3035
+ }
3036
+ const jt = /* @__PURE__ */ new Map();
3037
+ function Br(t, e) {
3038
+ jt.set(t, e);
3039
+ }
3040
+ function zr(t) {
3041
+ return jt.get(t);
3042
+ }
3043
+ function qr(t) {
3044
+ return t.startsWith("tab_") ? "required" : "active";
3045
+ }
3046
+ function Hr(t) {
3047
+ return t === "content-script" ? "content-script" : t === "main-thread" ? "main-thread" : t === "worker" ? "worker:default" : t.startsWith("worker:") ? t : "main-thread";
3048
+ }
3049
+ function Gr(t, e) {
3050
+ return e !== "main-thread" ? e : Ur(t) ? "content-script" : e;
3051
+ }
3052
+ function Jr(t, e) {
3053
+ return {
3054
+ endpoint: Hr(Gr(t, e)),
3055
+ tabPolicy: qr(t)
3056
+ };
3057
+ }
3058
+ function Yr(t) {
3059
+ for (const e of t)
3060
+ Br(e.action, Jr(e.action, e.owner));
3061
+ }
3062
+ const D = () => x([H(), f().finite()]).transform((t) => BigInt(t));
3063
+ l({
3064
+ key: o().describe("Storage key to retrieve")
3065
+ });
3066
+ l({
3067
+ key: o().describe("Storage key to set"),
3068
+ value: o().describe("Value to store")
3069
+ });
3070
+ l({
3071
+ key: o().describe("Storage key to delete")
3072
+ });
3073
+ l({});
3074
+ const Kr = l({
3075
+ items: b(o()).describe("Record of key-value string pairs to store")
3076
+ });
3077
+ Q((t) => t !== null && typeof t == "object" && !Array.isArray(t) && !("items" in t) ? { items: t } : t, Kr);
3078
+ const Qr = l({
3079
+ keys: I(o()).describe("Array of storage keys to retrieve"),
3080
+ defaults: b(o()).optional().describe("Default string values for missing keys")
3081
+ });
3082
+ Q(
3083
+ (t) => Array.isArray(t) ? { keys: t } : t,
3084
+ Qr
3085
+ );
3086
+ l({});
3087
+ const Xr = l({
3088
+ keys: I(o()).describe("Array of storage keys to delete")
3089
+ });
3090
+ Q(
3091
+ (t) => Array.isArray(t) ? { keys: t } : t,
3092
+ Xr
3093
+ );
3094
+ l({});
3095
+ l({});
3096
+ x([
3097
+ Dr([x([l({ text: o() }), o()])]),
3098
+ l({ text: o().optional(), value: o().optional() })
3099
+ ]);
3100
+ l({
3101
+ url: o().describe("URL to fetch"),
3102
+ method: o().default("GET").describe("HTTP method (GET, POST, PUT, DELETE, etc.)"),
3103
+ headers: b(o()).default({}).describe("Request headers as key-value pairs"),
3104
+ body: o().nullable().default(null).describe("Request body string"),
3105
+ timeout: D().default(30000n).describe("Timeout in milliseconds"),
3106
+ store: w().optional().describe(
3107
+ "When true, store binary responses as a handle instead of returning body bytes"
3108
+ ),
3109
+ options: l({}).passthrough().optional().describe("Fetch options")
3110
+ }).passthrough();
3111
+ l({
3112
+ duration: D().describe("Duration to sleep in milliseconds")
3113
+ });
3114
+ const K = () => o().regex(/^(?:f\d+_)?e\d+$/), en = 'use { refId: "e2" } or { label: "..." } object form, not positional arguments', ft = (t, e) => {
3115
+ if (t.__invalidPositional !== void 0) {
3116
+ e.addIssue({
3117
+ code: u.custom,
3118
+ message: en
3119
+ });
3120
+ return;
3121
+ }
3122
+ !t.refId && !t.label && e.addIssue({
3123
+ code: u.custom,
3124
+ message: "Either refId or label is required"
3125
+ });
3126
+ }, Dt = (t, e) => {
3127
+ t.x !== void 0 || t.y !== void 0 || ft(t, e);
3128
+ }, O = (t) => Q(
3129
+ (e) => typeof e == "string" || typeof e == "number" ? { __invalidPositional: e } : e,
3130
+ l({
3131
+ __invalidPositional: x([o(), f()]).optional().describe("Internal flag for positional argument rejection"),
3132
+ refId: K().optional().describe("Element reference ID (e.g. e2)"),
3133
+ label: o().optional().describe("Human-readable element label"),
3134
+ ...t
3135
+ }).superRefine(ft)
3136
+ ), be = {
3137
+ tabId: x([f(), H()]).optional().describe("Target tab ID")
3138
+ }, F = (t) => Q(
3139
+ (e) => typeof e == "string" || typeof e == "number" ? { __invalidPositional: e } : e,
3140
+ l({
3141
+ __invalidPositional: x([o(), f()]).optional().describe("Internal flag for positional argument rejection"),
3142
+ ...be,
3143
+ refId: K().optional().describe("Element reference ID (e.g. e2)"),
3144
+ label: o().optional().describe("Human-readable element label"),
3145
+ ...t
3146
+ }).superRefine(ft)
3147
+ );
3148
+ l({});
3149
+ l({});
3150
+ l({
3151
+ url: o().describe("URL to navigate to"),
3152
+ timeout: D().optional().describe("Navigation timeout in milliseconds"),
3153
+ waitUntil: $e(["load", "networkidle"]).optional().describe(
3154
+ "When to consider navigation complete: 'load' (tab status complete) or 'networkidle' (no in-flight requests for 500ms)"
3155
+ )
3156
+ });
3157
+ l({});
3158
+ l({});
3159
+ l({});
3160
+ l({
3161
+ duration: D().default(1000n).describe("Duration to wait in milliseconds")
3162
+ });
3163
+ O();
3164
+ const tn = (t, e) => {
3165
+ [t.url, t.path, t.handle].filter(
3166
+ (n) => typeof n == "string" && n.length > 0
3167
+ ).length !== 1 && e.addIssue({
3168
+ code: u.custom,
3169
+ message: "Each file entry requires exactly one of url, path, or handle"
3170
+ });
3171
+ }, Zt = l({
3172
+ name: o().optional().describe("File name including extension"),
3173
+ mimeType: o().optional().describe("MIME type (defaults to application/octet-stream)"),
3174
+ url: o().url().optional().describe("HTTP(S) URL to fetch in the target tab"),
3175
+ path: o().min(1).optional().describe("Virtual filesystem path (resolved in worker)"),
3176
+ handle: o().min(1).optional().describe("Binary handle from page.fetch({ store: true })")
3177
+ }).superRefine(tn), Wt = jr("kind", [
3178
+ l({
3179
+ kind: Te("bytes"),
3180
+ name: o().min(1),
3181
+ data: o().min(1),
3182
+ mimeType: o().optional()
3183
+ }),
3184
+ l({
3185
+ kind: Te("url"),
3186
+ url: o().url(),
3187
+ name: o().min(1),
3188
+ mimeType: o().optional()
3189
+ })
3190
+ ]);
3191
+ O({
3192
+ value: o().describe("Value to fill into the element")
3193
+ });
3194
+ const rn = O({
3195
+ files: I(Zt).min(1).describe("Files to attach to the input")
3196
+ });
3197
+ O({
3198
+ files: I(Wt).min(1).describe("Resolved files for content-script application")
3199
+ });
3200
+ O({
3201
+ text: o().describe("Text to type into the element")
3202
+ });
3203
+ O({
3204
+ text: o().describe("Text to append into the element")
3205
+ });
3206
+ l({
3207
+ refId: K().optional().describe(
3208
+ "Element reference ID to dispatch the key on (e.g. e2). Omit to dispatch on document."
3209
+ ),
3210
+ label: o().optional().describe("Human-readable element label. Omit to dispatch on document."),
3211
+ key: o().describe("Key to press (e.g. Enter, Escape, ArrowDown)")
3212
+ });
3213
+ O({
3214
+ value: x([
3215
+ o().describe("Value to select in the dropdown"),
3216
+ I(o()).describe(
3217
+ "Values to select in a multiple dropdown (empty array clears selection)"
3218
+ )
3219
+ ]).describe("Value (string) or values (array) to select in the dropdown")
3220
+ });
3221
+ O({
3222
+ value: o().describe(
3223
+ "Visible text of the option to select (matched case-insensitively)"
3224
+ )
3225
+ });
3226
+ O({
3227
+ checked: w().optional().describe("Desired checked state (true to check, false to uncheck)")
3228
+ });
3229
+ l({
3230
+ name: o().min(1).describe("The `name` attribute of the radio group to pick from"),
3231
+ value: o().describe("The `value` of the radio option to check")
3232
+ });
3233
+ O();
3234
+ l({});
3235
+ O();
3236
+ l({
3237
+ direction: o().default("down").describe("Scroll direction: up, down, left, or right"),
3238
+ amount: f().default(300).describe("Pixels to scroll")
3239
+ });
3240
+ Q(
3241
+ (t) => typeof t == "string" || typeof t == "number" ? { __invalidPositional: t } : t,
3242
+ l({
3243
+ __invalidPositional: x([o(), f()]).optional().describe("Internal flag for positional argument rejection"),
3244
+ refId: K().optional().describe("Element reference ID (e.g. e2)"),
3245
+ label: o().optional().describe("Human-readable element label"),
3246
+ x: f().optional().describe("X coordinate to scroll to"),
3247
+ y: f().optional().describe("Y coordinate to scroll to")
3248
+ }).superRefine(Dt)
3249
+ );
3250
+ O();
3251
+ l({
3252
+ selector: o().describe("CSS selector to find elements")
3253
+ });
3254
+ l({
3255
+ selector: o().describe("CSS selector for the root element(s) to introspect"),
3256
+ depth: f().int().min(0).max(10).default(2).describe("How many descendant levels to include (0 = root only)"),
3257
+ includeHidden: w().default(!0).describe(
3258
+ "Include elements hidden by CSS/aria (default true — this tool's purpose is to see what the curated snapshot filters out)"
3259
+ )
3260
+ });
3261
+ l({
3262
+ selector: o().describe("CSS selector to wait for"),
3263
+ timeout: D().default(30000n).describe("Timeout in milliseconds")
3264
+ });
3265
+ const nn = l({
3266
+ fields: I(o()).describe("Array of field names to extract")
3267
+ });
3268
+ Q(
3269
+ (t) => Array.isArray(t) ? { fields: t } : t,
3270
+ nn
3271
+ );
3272
+ x([
3273
+ f(),
3274
+ I(l({}).passthrough()),
3275
+ l({}).passthrough()
3276
+ ]);
3277
+ l({});
3278
+ l({
3279
+ active: w().optional().describe("Whether the tabs are active"),
3280
+ currentWindow: w().optional().describe("Whether the tabs are in the current window"),
3281
+ url: o().optional().describe("URL pattern to match tabs against")
3282
+ }).passthrough();
3283
+ Q(
3284
+ (t) => typeof t == "string" ? { url: t } : t,
3285
+ l({
3286
+ url: o().optional().describe("URL to open in the new tab"),
3287
+ active: w().optional().describe("Whether to focus the new tab")
3288
+ })
3289
+ );
3290
+ x([
3291
+ f(),
3292
+ I(
3293
+ l({
3294
+ id: f().optional(),
3295
+ tabId: f().optional(),
3296
+ tab_id: f().optional()
3297
+ }).passthrough()
3298
+ ),
3299
+ l({
3300
+ id: f().optional(),
3301
+ tabId: f().optional(),
3302
+ tab_id: f().optional()
3303
+ }).passthrough()
3304
+ ]);
3305
+ F();
3306
+ F({
3307
+ value: o().describe("Value to fill into the element")
3308
+ });
3309
+ const sn = F({
3310
+ files: I(Zt).min(1).describe("Files to attach to the input")
3311
+ });
3312
+ F({
3313
+ files: I(Wt).min(1).describe("Resolved files for content-script application")
3314
+ });
3315
+ Q(
3316
+ (t) => typeof t == "string" || typeof t == "number" ? { __invalidPositional: t } : t,
3317
+ l({
3318
+ __invalidPositional: x([o(), f()]).optional().describe("Internal flag for positional argument rejection"),
3319
+ ...be,
3320
+ refId: K().optional().describe("Element reference ID (e.g. e2)"),
3321
+ label: o().optional().describe("Human-readable element label"),
3322
+ x: f().optional().describe("X coordinate to scroll to"),
3323
+ y: f().optional().describe("Y coordinate to scroll to")
3324
+ }).superRefine(Dt)
3325
+ );
3326
+ F({
3327
+ text: o().describe("Text to type into the element")
3328
+ });
3329
+ l({
3330
+ ...be,
3331
+ key: o().describe("Key to press (e.g. Enter, Escape, ArrowDown)")
3332
+ });
3333
+ F({
3334
+ value: o().describe("Value to select in the dropdown")
3335
+ });
3336
+ F({
3337
+ value: o().describe(
3338
+ "Visible text of the option to select (matched case-insensitively)"
3339
+ )
3340
+ });
3341
+ F({
3342
+ checked: w().optional().describe("Desired checked state (true to check, false to uncheck)")
3343
+ });
3344
+ F();
3345
+ F();
3346
+ l({
3347
+ ...be,
3348
+ name: o().min(1).describe("The `name` attribute of the radio group to pick from"),
3349
+ value: o().describe("The `value` of the radio option to check")
3350
+ });
3351
+ l({
3352
+ ...be
3353
+ });
3354
+ l({
3355
+ ...be,
3356
+ direction: o().default("down").describe("Scroll direction: up, down, left, or right"),
3357
+ amount: f().default(300).describe("Pixels to scroll")
3358
+ });
3359
+ F();
3360
+ l({
3361
+ tabId: x([f(), H()]).optional().describe("Target tab ID"),
3362
+ script: o().optional().describe("Script to evaluate"),
3363
+ code: o().optional().describe("Alternative script code"),
3364
+ js: o().optional().describe("Alternative JS code")
3365
+ }).passthrough();
3366
+ l({
3367
+ tabId: x([f(), H()]).optional().describe("Target tab ID")
3368
+ }).passthrough();
3369
+ l({
3370
+ tabId: x([f(), H()]).optional().describe("Target tab ID")
3371
+ }).passthrough();
3372
+ l({
3373
+ tabId: x([f(), H()]).optional().describe("Target tab ID"),
3374
+ timeout: f().optional().describe("Timeout in milliseconds")
3375
+ }).passthrough();
3376
+ l({
3377
+ tabId: x([f(), H()]).optional().describe("Target tab ID"),
3378
+ url: o().optional().describe("URL to fetch"),
3379
+ options: l({}).passthrough().optional().describe("Fetch options")
3380
+ }).passthrough();
3381
+ l({
3382
+ tabId: x([f(), H()]).optional().describe("Target tab ID"),
3383
+ max_nodes: f().optional().describe("Maximum nodes to include"),
3384
+ options: l({}).passthrough().optional().describe("Snapshot options")
3385
+ }).passthrough();
3386
+ l({
3387
+ tabId: x([f(), H()]).optional().describe("Target tab ID"),
3388
+ max_nodes: f().optional().describe("Maximum nodes to include"),
3389
+ options: l({}).passthrough().optional().describe("Snapshot options")
3390
+ }).passthrough();
3391
+ l({
3392
+ tabId: x([f(), H()]).optional().describe("Target tab ID"),
3393
+ max_nodes: f().optional().describe("Maximum nodes to include"),
3394
+ options: l({}).passthrough().optional().describe("Snapshot options")
3395
+ }).passthrough();
3396
+ O();
3397
+ O();
3398
+ O({
3399
+ value: o().optional().describe("Value to fill into the element")
3400
+ });
3401
+ O({
3402
+ text: o().optional().describe("Text to type into the element")
3403
+ });
3404
+ l({
3405
+ key: o().optional().describe("Key to press (e.g. Enter, Escape, ArrowDown)")
3406
+ });
3407
+ O({
3408
+ value: o().optional().describe("Value to select in the dropdown")
3409
+ });
3410
+ O({
3411
+ checked: w().optional().describe("Desired checked state (true to check, false to uncheck)")
3412
+ });
3413
+ O();
3414
+ l({});
3415
+ l({
3416
+ direction: o().optional().describe("Scroll direction: up, down, left, or right"),
3417
+ amount: f().optional().describe("Pixels to scroll")
3418
+ });
3419
+ O();
3420
+ O({
3421
+ text: o().optional().describe("Text to append into the element")
3422
+ });
3423
+ l({});
3424
+ l({});
3425
+ l({
3426
+ duration: D().default(1000n).describe("Duration to wait in milliseconds")
3427
+ });
3428
+ l({
3429
+ interactive_only: w().default(!1).describe("Only include interactive elements"),
3430
+ max_nodes: D().default(500n).describe("Maximum number of nodes to include in snapshot")
3431
+ });
3432
+ l({
3433
+ interactive_only: w().default(!1).describe("Only include interactive elements"),
3434
+ max_nodes: D().default(500n).describe("Maximum number of nodes to include in snapshot")
3435
+ });
3436
+ l({
3437
+ interactive_only: w().default(!1).describe("Only include interactive elements"),
3438
+ max_nodes: D().default(500n).describe("Maximum number of nodes to include in snapshot")
3439
+ });
3440
+ l({
3441
+ interactive_only: w().default(!1).describe("Only include interactive elements"),
3442
+ max_nodes: D().default(500n).describe("Maximum number of nodes to include in snapshot")
3443
+ });
3444
+ l({
3445
+ snapshot: l({}).passthrough().describe("Raw DOM snapshot data to format"),
3446
+ format: o().optional().describe("Output format (e.g. markdown, html)")
3447
+ });
3448
+ l({
3449
+ max_nodes: f().optional().describe("Maximum nodes to include"),
3450
+ options: l({}).passthrough().optional().describe("Snapshot options")
3451
+ }).passthrough();
3452
+ l({
3453
+ max_nodes: f().optional().describe("Maximum nodes to include"),
3454
+ options: l({}).passthrough().optional().describe("Snapshot options")
3455
+ }).passthrough();
3456
+ l({
3457
+ max_nodes: f().optional().describe("Maximum nodes to include"),
3458
+ options: l({}).passthrough().optional().describe("Snapshot options")
3459
+ }).passthrough();
3460
+ const an = l({
3461
+ role: x([o(), I(o())]).optional().describe("Filter by ARIA role"),
3462
+ tag: x([o(), I(o())]).optional().describe("Filter by HTML tag"),
3463
+ text: o().optional().describe("Filter by text content (case-insensitive substring)"),
3464
+ name: o().optional().describe("Filter by accessible name (case-insensitive substring)"),
3465
+ interactiveOnly: w().optional().describe("Only include interactive elements"),
3466
+ href: o().optional().describe("Filter by href pattern (case-insensitive substring)"),
3467
+ src: o().optional().describe("Filter by src pattern (case-insensitive substring)"),
3468
+ limit: f().positive().optional().describe("Maximum filtered nodes to return")
3469
+ }).passthrough(), on = l({
3470
+ filter: an.optional().describe(
3471
+ "Semantic filter criteria"
3472
+ ),
3473
+ max_nodes: f().optional().describe("Maximum nodes to collect before filtering")
3474
+ }).passthrough();
3475
+ on.extend({
3476
+ tabId: f().describe("Tab ID")
3477
+ });
3478
+ const ee = l({
3479
+ path: o().describe("File or directory path")
3480
+ }), xt = l({
3481
+ from: o().describe("Source path"),
3482
+ to: o().describe("Destination path")
3483
+ }), le = l({
3484
+ path: o().describe("File path to write to"),
3485
+ data: o().describe("Data to write")
3486
+ }), cn = l({
3487
+ path: o().describe("File path to read from"),
3488
+ offset: D().describe("Byte offset to start reading"),
3489
+ len: f().describe("Number of bytes to read")
3490
+ }), dn = l({
3491
+ path: o().describe("File path to update"),
3492
+ offset: D().describe("Byte offset to start writing"),
3493
+ data: o().describe("Data to write")
3494
+ }), ln = l({
3495
+ path: o().describe("File path to hash"),
3496
+ algo: o().default("sha256").describe("Hash algorithm (e.g. sha256, md5)")
3497
+ });
3498
+ b(_());
3499
+ b(_());
3500
+ b(_());
3501
+ b(_());
3502
+ x([
3503
+ f(),
3504
+ b(_())
3505
+ ]);
3506
+ x([
3507
+ f(),
3508
+ b(_())
3509
+ ]);
3510
+ b(_());
3511
+ b(_());
3512
+ b(_());
3513
+ x([
3514
+ o(),
3515
+ b(_())
3516
+ ]);
3517
+ b(_());
3518
+ b(
3519
+ _()
3520
+ );
3521
+ b(_());
3522
+ b(_());
3523
+ b(_());
3524
+ x([
3525
+ o(),
3526
+ f(),
3527
+ b(_())
3528
+ ]);
3529
+ b(_());
3530
+ b(_());
3531
+ b(_());
3532
+ x([
3533
+ f(),
3534
+ b(_())
3535
+ ]);
3536
+ b(_());
3537
+ b(_());
3538
+ b(_());
3539
+ b(_());
3540
+ b(_());
3541
+ I(_());
3542
+ x([
3543
+ o(),
3544
+ b(_())
3545
+ ]);
3546
+ b(_());
3547
+ x([
3548
+ o(),
3549
+ b(_())
3550
+ ]);
3551
+ b(_());
3552
+ x([
3553
+ o(),
3554
+ b(_())
3555
+ ]);
3556
+ b(_());
3557
+ x([
3558
+ o(),
3559
+ b(_())
3560
+ ]);
3561
+ b(_());
3562
+ b(_());
3563
+ x([
3564
+ f(),
3565
+ b(_())
3566
+ ]);
3567
+ b(_());
3568
+ b(_());
3569
+ x([
3570
+ f(),
3571
+ b(_())
3572
+ ]);
3573
+ b(
3574
+ _()
3575
+ );
3576
+ x([
3577
+ o(),
3578
+ f(),
3579
+ b(_())
3580
+ ]);
3581
+ b(_());
3582
+ b(_());
3583
+ b(_());
3584
+ b(_());
3585
+ x([
3586
+ f(),
3587
+ b(_())
3588
+ ]);
3589
+ x([
3590
+ f(),
3591
+ b(_())
3592
+ ]);
3593
+ x([
3594
+ f(),
3595
+ b(_())
3596
+ ]);
3597
+ x([
3598
+ f(),
3599
+ b(_())
3600
+ ]);
3601
+ x([
3602
+ f(),
3603
+ b(_())
3604
+ ]);
3605
+ b(_());
3606
+ b(_());
3607
+ b(_());
3608
+ l({
3609
+ action: o().describe("Host action name"),
3610
+ params: l({}).passthrough().optional().describe("Parameters for the host action")
3611
+ }).passthrough();
3612
+ x([
3613
+ o(),
3614
+ f(),
3615
+ w(),
3616
+ Lt(),
3617
+ I(_()),
3618
+ b(_())
3619
+ ]);
3620
+ const un = l({
3621
+ ok: Te(!0).describe("Whether the action succeeded"),
3622
+ action: o().describe("Action identifier (e.g. 'page_fill')"),
3623
+ refId: K().optional().describe("Element reference ID that was acted upon (e.g. e2)"),
3624
+ tag: o().optional().describe("HTML tag name of the element"),
3625
+ role: o().optional().describe("ARIA role of the element"),
3626
+ name: o().optional().describe("Accessible name of the element"),
3627
+ value: x([o(), I(o())]).optional().describe(
3628
+ "Final value of the element after the action (string, or string[] for multi-select)"
3629
+ ),
3630
+ checked: w().optional().describe("Checked state after the action"),
3631
+ disabled: w().optional().describe("Whether the element is disabled"),
3632
+ readOnly: w().optional().describe("Whether the element is read-only"),
3633
+ text: o().optional().describe("Text content of the element"),
3634
+ key: o().optional().describe("Key that was pressed (for press actions)"),
3635
+ direction: o().optional().describe("Scroll direction (for scroll actions)"),
3636
+ amount: f().optional().describe("Scroll amount in pixels (for scroll actions)"),
3637
+ fileCount: f().optional().describe("Number of files attached (for setFiles actions)"),
3638
+ fileNames: I(o()).optional().describe("Names of attached files (for setFiles actions)"),
3639
+ observationId: o().optional().describe(
3640
+ "Opaque ID of the observation lease authorizing this action (snapshot-scoped)"
3641
+ ),
3642
+ dispatched: Te(!0).optional().describe(
3643
+ "True if the action was dispatched to the DOM. Does NOT prove the application accepted it."
3644
+ ),
3645
+ verification: Te("required").optional().describe(
3646
+ "Always 'required': a fresh observation is required to verify the effect."
3647
+ )
3648
+ });
3649
+ x([un, Lt()]);
3650
+ l({
3651
+ status: f().describe("HTTP response status code"),
3652
+ ok: w().describe("Whether the response status is 2xx"),
3653
+ headers: b(o()).describe("Response headers as key-value pairs"),
3654
+ body: o().optional().describe("Response body (omitted when bodyEncoding is handle)"),
3655
+ bodyEncoding: $e(["text", "base64", "handle"]).describe("Encoding of the body field"),
3656
+ handle: o().optional().describe("Binary handle when bodyEncoding is handle"),
3657
+ byteLength: f().describe("Length of the body in bytes"),
3658
+ contentType: o().describe("Response Content-Type header"),
3659
+ finalUrl: o().describe("Final URL after redirects")
3660
+ });
3661
+ l({
3662
+ data: l({}).passthrough().describe("Structured snapshot data"),
3663
+ text: o().describe("Plain text representation of the snapshot")
3664
+ });
3665
+ l({});
3666
+ l({
3667
+ tabId: f(),
3668
+ url: o(),
3669
+ title: o(),
3670
+ contentScript: $e(["connected", "missing"]),
3671
+ domApis: $e(["ok", "blocked"]),
3672
+ mutationsReady: w(),
3673
+ hint: o().optional(),
3674
+ recovery: I(o()).optional()
3675
+ });
3676
+ const fn = l({
3677
+ refId: K().describe("Element reference ID (e.g. e2)"),
3678
+ role: o().describe("ARIA role of the element"),
3679
+ tag: o().describe("HTML tag name"),
3680
+ name: o().optional().describe("Accessible name of the element"),
3681
+ text: o().optional().describe("Visible text content of the element"),
3682
+ value: o().optional().describe("Element value"),
3683
+ checked: w().optional().describe("Checked state"),
3684
+ disabled: w().optional().describe("Whether the element is disabled"),
3685
+ readOnly: w().optional().describe("Whether the element is read-only"),
3686
+ selected: w().optional().describe("For <option>: selected state"),
3687
+ href: o().optional().describe("Absolute URL for link elements"),
3688
+ src: o().optional().describe("Absolute URL for image elements"),
3689
+ alt: o().optional().describe("Alternative text for image elements"),
3690
+ title: o().optional().describe("Title attribute"),
3691
+ parentRefId: K().optional().describe("Reference ID of the parent container element"),
3692
+ postId: o().optional().describe("Stable post identifier from data-post-id attribute"),
3693
+ permalink: o().optional().describe("Stable permalink URL from anchor element"),
3694
+ imageUrls: I(o()).optional().describe("Image URLs contained within this element")
3695
+ });
3696
+ l({
3697
+ text: o().describe("Plain text representation of the page"),
3698
+ nodes: I(fn).describe("Array of interactive nodes"),
3699
+ url: o().describe("Current page URL"),
3700
+ title: o().describe("Current page title"),
3701
+ viewport: l({
3702
+ width: f().describe("Viewport width in pixels"),
3703
+ height: f().describe("Viewport height in pixels")
3704
+ }).describe("Viewport dimensions"),
3705
+ observationId: o().optional().describe(
3706
+ "Opaque ID of the observation lease granted by this snapshot. Pass to subsequent actions to prove they act on fresh observations."
3707
+ )
3708
+ });
3709
+ const Vt = l({
3710
+ refId: K().optional(),
3711
+ tag: o(),
3712
+ role: o().optional(),
3713
+ name: o().optional(),
3714
+ text: o().optional(),
3715
+ attributes: b(o()).optional().describe("All HTML attributes (raw)"),
3716
+ hidden: w().optional(),
3717
+ hiddenReason: $e([
3718
+ "display-none",
3719
+ "visibility-hidden",
3720
+ "aria-hidden",
3721
+ "opacity-zero",
3722
+ "hidden-attr",
3723
+ "inert"
3724
+ ]).optional(),
3725
+ value: o().optional(),
3726
+ checked: w().optional(),
3727
+ disabled: w().optional(),
3728
+ readOnly: w().optional(),
3729
+ selected: w().optional().describe("For <option>: selected state"),
3730
+ href: o().optional(),
3731
+ src: o().optional(),
3732
+ alt: o().optional(),
3733
+ accept: o().optional().describe("For input[type=file]: accepted MIME/extensions"),
3734
+ filesCount: f().optional().describe("For input[type=file]: selected file count"),
3735
+ children: I(Zr(() => Vt)).optional().describe("Nested descendants up to `depth`")
3736
+ });
3737
+ l({
3738
+ nodes: I(Vt),
3739
+ url: o(),
3740
+ title: o()
3741
+ });
3742
+ const Ft = l({
3743
+ id: f().optional().describe("Tab ID"),
3744
+ tabId: f().optional().describe("Tab ID (added by runner)"),
3745
+ index: f().optional().describe("Tab index in the window"),
3746
+ windowId: f().optional().describe("Window ID"),
3747
+ url: o().optional().describe("Tab URL"),
3748
+ title: o().optional().describe("Tab title"),
3749
+ status: o().optional().describe("Tab status (loading or complete)"),
3750
+ active: w().optional().describe("Whether the tab is active"),
3751
+ pinned: w().optional().describe("Whether the tab is pinned"),
3752
+ highlighted: w().optional().describe("Whether the tab is highlighted"),
3753
+ incognito: w().optional().describe("Whether the tab is incognito"),
3754
+ favIconUrl: o().optional().describe("Favicon URL"),
3755
+ audible: w().optional().describe("Whether the tab is audible"),
3756
+ groupId: f().optional().describe("Group ID"),
3757
+ openerTabId: f().optional().describe("Opener tab ID"),
3758
+ discarded: w().optional().describe("Whether the tab is discarded"),
3759
+ autoDiscardable: w().optional().describe("Whether the tab is auto-discardable"),
3760
+ width: f().optional().describe("Tab width"),
3761
+ height: f().optional().describe("Tab height"),
3762
+ sessionId: o().optional().describe("Session ID")
3763
+ }).passthrough(), hn = I(Ft), Ut = l({
3764
+ id: f().optional().describe("Window ID"),
3765
+ focused: w().optional().describe("Whether the window is focused"),
3766
+ top: f().optional().describe("Window top position"),
3767
+ left: f().optional().describe("Window left position"),
3768
+ width: f().optional().describe("Window width"),
3769
+ height: f().optional().describe("Window height"),
3770
+ tabs: hn.optional().describe(
3771
+ "Array of tabs in the window"
3772
+ ),
3773
+ incognito: w().optional().describe("Whether the window is incognito"),
3774
+ type: o().optional().describe("Window type"),
3775
+ state: o().optional().describe("Window state"),
3776
+ alwaysOnTop: w().optional().describe("Whether the window is always on top"),
3777
+ sessionId: o().optional().describe("Session ID")
3778
+ }).passthrough();
3779
+ I(Ut);
3780
+ const pn = l({
3781
+ name: o().describe("Cookie name"),
3782
+ value: o().describe("Cookie value"),
3783
+ domain: o().optional().describe("Cookie domain"),
3784
+ hostOnly: w().optional().describe("Whether the cookie is host-only"),
3785
+ path: o().optional().describe("Cookie path"),
3786
+ secure: w().optional().describe("Whether the cookie is secure"),
3787
+ httpOnly: w().optional().describe("Whether the cookie is HTTP-only"),
3788
+ sameSite: o().optional().describe("SameSite policy"),
3789
+ session: w().optional().describe("Whether the cookie is a session cookie"),
3790
+ expirationDate: f().optional().describe("Expiration date as Unix timestamp"),
3791
+ storeId: o().optional().describe("Store ID")
3792
+ }).nullable();
3793
+ I(
3794
+ pn.nullable().unwrap()
3795
+ );
3796
+ const mn = l({
3797
+ id: o().describe("Bookmark ID"),
3798
+ parentId: o().optional().describe("Parent folder ID"),
3799
+ index: f().optional().describe("Bookmark index"),
3800
+ url: o().optional().describe("Bookmark URL"),
3801
+ title: o().describe("Bookmark title"),
3802
+ dateAdded: f().optional().describe("Date added"),
3803
+ dateGroupModified: f().optional().describe("Date group modified"),
3804
+ children: I(l({ id: o() }).passthrough()).optional().describe("Child bookmarks")
3805
+ }).passthrough();
3806
+ I(mn);
3807
+ const gn = l({
3808
+ id: o().describe("History item ID"),
3809
+ url: o().optional().describe("URL"),
3810
+ title: o().optional().describe("Title"),
3811
+ lastVisitTime: f().optional().describe("Last visit time"),
3812
+ visitCount: f().optional().describe("Visit count"),
3813
+ typedCount: f().optional().describe("Typed count")
3814
+ }).passthrough();
3815
+ I(gn);
3816
+ const yn = l({
3817
+ frameId: f().describe("Frame ID"),
3818
+ result: _().optional().describe("Script result")
3819
+ });
3820
+ I(yn);
3821
+ o();
3822
+ w();
3823
+ x([o(), f()]);
3824
+ w();
3825
+ const bn = l({
3826
+ id: f().optional().describe("Group ID"),
3827
+ collapsed: w().optional().describe("Whether the group is collapsed"),
3828
+ color: o().optional().describe("Group color"),
3829
+ title: o().optional().describe("Group title"),
3830
+ windowId: f().optional().describe("Window ID")
3831
+ }).passthrough();
3832
+ I(bn);
3833
+ const _n = l({
3834
+ lastModified: f().optional().describe("Last modified time"),
3835
+ tab: Ft.optional().describe("Tab info"),
3836
+ window: Ut.optional().describe("Window info")
3837
+ }).passthrough(), vn = I(_n), kn = l({
3838
+ deviceName: o().optional().describe("Device name"),
3839
+ sessions: vn.optional().describe("Sessions")
3840
+ }).passthrough();
3841
+ I(kn);
3842
+ const wn = l({
3843
+ id: f().optional().describe("Download ID"),
3844
+ url: o().optional().describe("Download URL"),
3845
+ filename: o().optional().describe("Filename"),
3846
+ startTime: o().optional().describe("Start time"),
3847
+ endTime: o().optional().describe("End time"),
3848
+ state: o().optional().describe("Download state"),
3849
+ danger: o().optional().describe("Danger type"),
3850
+ paused: w().optional().describe("Whether the download is paused"),
3851
+ error: o().optional().describe("Error message"),
3852
+ bytesReceived: f().optional().describe("Bytes received"),
3853
+ totalBytes: f().optional().describe("Total bytes"),
3854
+ fileSize: f().optional().describe("File size"),
3855
+ mime: o().optional().describe("MIME type"),
3856
+ incognito: w().optional().describe("Whether the download is incognito"),
3857
+ referrer: o().optional().describe("Referrer URL"),
3858
+ byExtensionId: o().optional().describe("Extension ID"),
3859
+ byExtensionName: o().optional().describe("Extension name")
3860
+ }).passthrough();
3861
+ I(wn);
3862
+ f();
3863
+ l({
3864
+ archName: o().describe("CPU architecture"),
3865
+ modelName: o().describe("CPU model"),
3866
+ numOfProcessors: f().describe("Number of processors"),
3867
+ features: I(o()).describe("CPU features")
3868
+ });
3869
+ l({
3870
+ capacity: f().describe("Total memory capacity"),
3871
+ availableCapacity: f().describe("Available memory capacity")
3872
+ });
3873
+ I(
3874
+ l({
3875
+ id: o().describe("Storage ID"),
3876
+ name: o().describe("Storage name"),
3877
+ type: o().describe("Storage type"),
3878
+ capacity: f().describe("Storage capacity")
3879
+ })
3880
+ );
3881
+ C.child("tool-registry");
3882
+ const Ve = /* @__PURE__ */ new Map(), Fe = /* @__PURE__ */ new Map();
3883
+ function ht(t) {
3884
+ return t && t.length > 0 ? t : "__default__";
3885
+ }
3886
+ function Bt(t) {
3887
+ const e = ht(t);
3888
+ let r = Ve.get(e);
3889
+ return r || (r = /* @__PURE__ */ new Map(), Ve.set(e, r)), r;
3890
+ }
3891
+ function Tn(t, e, r) {
3892
+ const n = ht(t), s = (Fe.get(n) ?? 0) + 1;
3893
+ Fe.set(n, s);
3894
+ const i = `blob_${s}`;
3895
+ return Bt(t).set(i, {
3896
+ bytes: e,
3897
+ mimeType: r == null ? void 0 : r.mimeType,
3898
+ contentType: r == null ? void 0 : r.contentType
3899
+ }), i;
3900
+ }
3901
+ function xn(t, e) {
3902
+ const r = Bt(t), n = r.get(e) ?? null;
3903
+ return n && r.delete(e), n;
3904
+ }
3905
+ function Sn(t) {
3906
+ const e = ht(t);
3907
+ Ve.delete(e), Fe.delete(e);
3908
+ }
3909
+ function St() {
3910
+ Ve.clear(), Fe.clear();
3911
+ }
3912
+ const It = 8 * 1024;
3913
+ function In(t) {
3914
+ const e = atob(t), r = new Uint8Array(e.length);
3915
+ for (let n = 0; n < e.length; n++)
3916
+ r[n] = e.charCodeAt(n);
3917
+ return r;
3918
+ }
3919
+ function En(t) {
3920
+ let e = "";
3921
+ for (let r = 0; r < t.length; r += It) {
3922
+ const n = t.subarray(r, r + It);
3923
+ for (let s = 0; s < n.length; s++)
3924
+ e += String.fromCharCode(n[s]);
3925
+ }
3926
+ return btoa(e);
3927
+ }
3928
+ function Rn(t) {
3929
+ if (typeof t != "object" || t === null) return !1;
3930
+ const e = t;
3931
+ if (e.store === !0) return !0;
3932
+ const r = e.options;
3933
+ return typeof r == "object" && r !== null ? r.store === !0 : !1;
3934
+ }
3935
+ function zt(t, e, r) {
3936
+ if (!Rn(t) || typeof e != "object" || e === null || !("bodyEncoding" in e))
3937
+ return e;
3938
+ const n = e;
3939
+ if (n.bodyEncoding !== "base64" || !n.body)
3940
+ return e;
3941
+ const s = In(n.body), i = Tn(r, s, {
3942
+ contentType: n.contentType,
3943
+ mimeType: n.contentType
3944
+ }), { body: c, ...a } = n;
3945
+ return {
3946
+ ...a,
3947
+ bodyEncoding: "handle",
3948
+ handle: i
3949
+ };
3950
+ }
3951
+ function Et(t, e) {
3952
+ const n = (t.split(/[?#]/)[0] ?? t).split("/").filter(Boolean).pop();
3953
+ return n && n.length > 0 ? n : e;
3954
+ }
3955
+ function Je(t) {
3956
+ return {
3957
+ ok: !1,
3958
+ error: {
3959
+ message: t,
3960
+ code: "E_INVALID_PARAMS",
3961
+ category: "validation"
3962
+ }
3963
+ };
3964
+ }
3965
+ async function An(t, e, r, n) {
3966
+ var h;
3967
+ const i = (t === "tab_set_files" ? sn : rn).safeParse(e);
3968
+ if (!i.success)
3969
+ return Je(
3970
+ ((h = i.error.issues[0]) == null ? void 0 : h.message) ?? "Invalid setFiles params"
3971
+ );
3972
+ const c = i.data, a = [];
3973
+ for (const d of c.files) {
3974
+ if (d.url) {
3975
+ a.push({
3976
+ kind: "url",
3977
+ url: d.url,
3978
+ name: d.name ?? Et(d.url, "upload.bin"),
3979
+ mimeType: d.mimeType
3980
+ });
3981
+ continue;
3982
+ }
3983
+ if (d.path) {
3984
+ try {
3985
+ const m = await n(d.path);
3986
+ a.push({
3987
+ kind: "bytes",
3988
+ name: d.name ?? Et(d.path, "upload.bin"),
3989
+ data: m,
3990
+ mimeType: d.mimeType
3991
+ });
3992
+ } catch (m) {
3993
+ const R = m instanceof Error ? m.message : String(m);
3994
+ return Je(`Failed to read path ${d.path}: ${R}`);
3995
+ }
3996
+ continue;
3997
+ }
3998
+ if (d.handle) {
3999
+ const m = xn(r, d.handle);
4000
+ if (!m)
4001
+ return Je(`Unknown or expired handle: ${d.handle}`);
4002
+ a.push({
4003
+ kind: "bytes",
4004
+ name: d.name ?? d.handle,
4005
+ data: En(m.bytes),
4006
+ mimeType: d.mimeType ?? m.mimeType ?? m.contentType
4007
+ });
4008
+ }
4009
+ }
4010
+ return {
4011
+ ok: !0,
4012
+ value: {
4013
+ ...c,
4014
+ files: a
4015
+ }
4016
+ };
4017
+ }
4018
+ const Ue = /* @__PURE__ */ new Map();
4019
+ function Cn(t, e) {
4020
+ Ue.set(t, e);
4021
+ }
4022
+ function On(t) {
4023
+ const e = Ue.get(t);
4024
+ return e !== void 0 && Ue.delete(t), e;
4025
+ }
4026
+ function Nn() {
4027
+ Ue.clear();
4028
+ }
4029
+ const qt = /* @__PURE__ */ new Set(["page_set_files", "tab_set_files"]), Ht = /* @__PURE__ */ new Set(["page_fetch", "tab_fetch"]);
4030
+ let ie = null, at = !1;
4031
+ const fe = /* @__PURE__ */ new Map();
4032
+ function Be(t, e) {
4033
+ try {
4034
+ return t.postMessage(e), !0;
4035
+ } catch (r) {
4036
+ const n = r instanceof Error ? r.message : String(r);
4037
+ return C.error("port_post_failed", { error: n }), !1;
4038
+ }
4039
+ }
4040
+ const Rt = 1e3;
4041
+ function Gt(t, e, r) {
4042
+ e === "main-thread" || e === "content-script" ? Be(r, { type: "relayCancel", id: t, owner: e }) : Be(r, { type: "registryCallCancel", id: t });
4043
+ }
4044
+ function At(t, e) {
4045
+ for (const [r, n] of fe)
4046
+ clearTimeout(n.timeoutId), Gt(r, n.owner, n.port), n.settle({
4047
+ ok: !1,
4048
+ error: { message: e, code: t }
4049
+ }), fe.delete(r);
4050
+ }
4051
+ const ye = /* @__PURE__ */ new Map(), U = /* @__PURE__ */ new Map();
4052
+ let Ct = Promise.resolve(), Z = null;
4053
+ function Mn(t) {
4054
+ C.trace("sessionQueue_enqueue");
4055
+ const e = Ct.then(t);
4056
+ return Ct = e.then(
4057
+ () => {
4058
+ },
4059
+ () => {
4060
+ }
4061
+ ), e;
4062
+ }
4063
+ function Jt(t) {
4064
+ Z && (C.error("runCell_worker_failure", {
4065
+ runId: Z.runId,
4066
+ callId: Z.id,
4067
+ error: t
4068
+ }), self.postMessage({
4069
+ type: "error",
4070
+ id: Z.id,
4071
+ error: t,
4072
+ runId: Z.runId
4073
+ }), Z = null);
4074
+ }
4075
+ self.addEventListener("error", (t) => {
4076
+ const e = t.message || (t.error instanceof Error ? t.error.message : "Worker uncaught error");
4077
+ C.error("worker_uncaught_error", { error: e }), Jt(e);
4078
+ });
4079
+ self.addEventListener("unhandledrejection", (t) => {
4080
+ const e = t.reason, r = e instanceof Error ? e.message : String(e ?? "Unhandled rejection");
4081
+ C.error("worker_unhandled_rejection", { error: r }), Jt(r);
4082
+ });
4083
+ function Pn(t, e) {
4084
+ ye.set(t, e);
4085
+ }
4086
+ function N(t, e, r) {
4087
+ Pn(t, async (n, s) => {
4088
+ const i = e.safeParse(he(n));
4089
+ if (!i.success) {
4090
+ const c = Vr(
4091
+ t,
4092
+ e,
4093
+ i.error.issues,
4094
+ n
4095
+ ), a = new Error(c);
4096
+ throw a.code = "E_INVALID_PARAMS", a;
4097
+ }
4098
+ return await r(i.data, s);
4099
+ });
4100
+ }
4101
+ function $n() {
4102
+ const t = new Uint8Array(16);
4103
+ return crypto.getRandomValues(t), Array.from(t, (e) => e.toString(16).padStart(2, "0")).join("");
4104
+ }
4105
+ function Ln(t) {
4106
+ return or(t);
4107
+ }
4108
+ const ot = /* @__PURE__ */ new Map(), Le = /* @__PURE__ */ new Map();
4109
+ function jn(t, e) {
4110
+ var r;
4111
+ if (ot.has(t))
4112
+ throw new Error(`Worker port already registered for owner: ${t}`);
4113
+ if (typeof e.addEventListener != "function")
4114
+ throw new Error(
4115
+ `Worker port for owner "${t}" cannot receive responses`
4116
+ );
4117
+ ot.set(t, e), e.addEventListener("message", async (n) => {
4118
+ var i;
4119
+ const s = n.data;
4120
+ if (s !== null && (s.type === "asyncRelayResult" || s.type === "registryCallResult") && typeof s.id == "string") {
4121
+ ct(s.id, s.result);
4122
+ return;
4123
+ }
4124
+ if (s !== null && s.type === "registryCallCancel" && typeof s.id == "string") {
4125
+ (i = Le.get(s.id)) == null || i.abort(), Le.delete(s.id);
4126
+ return;
4127
+ }
4128
+ if (s !== null && s.type === "registryCall" && typeof s.id == "string" && typeof s.action == "string") {
4129
+ const c = s.id, a = new AbortController();
4130
+ Le.set(c, a);
4131
+ const h = ye.get(s.action);
4132
+ let d;
4133
+ if (!h)
4134
+ d = {
4135
+ ok: !1,
4136
+ error: {
4137
+ message: `Unknown worker action: ${s.action}`,
4138
+ code: "E_UNKNOWN"
4139
+ }
4140
+ };
4141
+ else
4142
+ try {
4143
+ const m = await h(s.params, {
4144
+ action: s.action,
4145
+ callId: s.callId,
4146
+ runId: s.runId,
4147
+ signal: a.signal
4148
+ });
4149
+ d = a.signal.aborted ? {
4150
+ ok: !1,
4151
+ error: { message: "Relay aborted", code: "E_ABORT" }
4152
+ } : { ok: !0, value: m };
4153
+ } catch (m) {
4154
+ d = {
4155
+ ok: !1,
4156
+ error: {
4157
+ message: m instanceof Error ? m.message : String(m),
4158
+ code: a.signal.aborted ? "E_ABORT" : "E_WORKER_HANDLER"
4159
+ }
4160
+ };
4161
+ }
4162
+ Le.delete(c), Be(e, { type: "registryCallResult", id: c, result: d }) || ct(c, {
4163
+ ok: !1,
4164
+ error: {
4165
+ message: "Failed to deliver worker handler response",
4166
+ code: "E_PORT"
4167
+ }
4168
+ });
4169
+ }
4170
+ }), (r = e.start) == null || r.call(e);
4171
+ }
4172
+ function ct(t, e) {
4173
+ C.trace("resolveAsyncRelayResult", { id: t });
4174
+ const r = fe.get(t);
4175
+ return r ? (r.settle(e), !0) : (C.warn("asyncRelayResult_no_pending_relay", { id: t }), !1);
4176
+ }
4177
+ function Dn(t) {
4178
+ if (t === "main-thread" || t === "content-script")
4179
+ return self;
4180
+ const e = ot.get(t);
4181
+ return e || null;
4182
+ }
4183
+ function Yt(t) {
4184
+ const { owner: e, action: r, tabPolicy: n, resolveTimeoutMs: s } = t, i = t.timeoutMs ?? ke;
4185
+ return (c, a) => {
4186
+ C.trace("safePostAsCall_invoke", {
4187
+ owner: e,
4188
+ action: r,
4189
+ callId: a == null ? void 0 : a.callId,
4190
+ runId: a == null ? void 0 : a.runId
4191
+ });
4192
+ const h = (s == null ? void 0 : s(c)) ?? i;
4193
+ return new Promise((d, m) => {
4194
+ var bt;
4195
+ if ((bt = a == null ? void 0 : a.signal) != null && bt.aborted) {
4196
+ const G = new Error(`Relay aborted for action: ${r}`);
4197
+ G.code = "E_ABORT", m(G);
4198
+ return;
4199
+ }
4200
+ const R = Dn(e);
4201
+ if (!R) {
4202
+ m(new Error(`No port available for action: ${r}`));
4203
+ return;
4204
+ }
4205
+ if (fe.size >= Rt) {
4206
+ m(
4207
+ new Error(
4208
+ `Too many pending calls (${Rt} limit exceeded). Action: ${r}`
4209
+ )
4210
+ );
4211
+ return;
4212
+ }
4213
+ const P = $n();
4214
+ let X = !1;
4215
+ const de = (G) => {
4216
+ X || (X = !0, clearTimeout(mt), a != null && a.signal && a.signal.removeEventListener("abort", He), fe.delete(P), G());
4217
+ }, pt = () => {
4218
+ Gt(P, e, R);
4219
+ }, He = () => {
4220
+ pt();
4221
+ const G = new Error(`Relay aborted for action: ${r}`);
4222
+ G.code = "E_ABORT", de(() => m(G));
4223
+ };
4224
+ a != null && a.signal && a.signal.addEventListener("abort", He);
4225
+ const mt = setTimeout(() => {
4226
+ pt(), de(() => m(new Error(`Relay timeout for action: ${r}`)));
4227
+ }, h);
4228
+ fe.set(P, {
4229
+ settle: (G) => de(() => d(G)),
4230
+ timeoutId: mt,
4231
+ abort: He,
4232
+ owner: e,
4233
+ port: R
4234
+ });
4235
+ const gt = a == null ? void 0 : a.runId, yt = a == null ? void 0 : a.callId;
4236
+ Be(R, {
4237
+ type: e === "main-thread" || e === "content-script" ? "asyncRelay" : "registryCall",
4238
+ id: P,
4239
+ owner: e,
4240
+ action: r,
4241
+ params: c,
4242
+ callId: yt,
4243
+ tabPolicy: n,
4244
+ command: { action: r, params: c, runId: gt, callId: yt },
4245
+ runId: gt
4246
+ }) || de(
4247
+ () => m(new Error(`Failed to post relay for action: ${r}`))
4248
+ );
4249
+ });
4250
+ };
4251
+ }
4252
+ const Zn = "worker", ke = 3e4, Ot = 5e3, Wn = 500, Vn = {
4253
+ page_goto: "timeout",
4254
+ page_wait_for: "timeout",
4255
+ tab_wait_for_load: "timeout",
4256
+ fetch: "timeout",
4257
+ sleep: "duration",
4258
+ page_wait: "duration",
4259
+ sidepanel_wait: "duration"
4260
+ }, Kt = /* @__PURE__ */ new Set(["page_goto"]);
4261
+ function Fn(t, e) {
4262
+ if (t === null || typeof t != "object" || Array.isArray(t))
4263
+ return null;
4264
+ const r = t[e];
4265
+ return typeof r == "bigint" ? Number(r) : typeof r == "number" && Number.isFinite(r) ? r : null;
4266
+ }
4267
+ function Un(t, e) {
4268
+ return Kt.has(t) ? e * 3 + Wn + Ot : e + Ot;
4269
+ }
4270
+ const Bn = 6e4;
4271
+ function Qt(t, e) {
4272
+ if (qt.has(t))
4273
+ return Bn;
4274
+ const r = Vn[t];
4275
+ if (!r) return ke;
4276
+ let n = Fn(e, r);
4277
+ return n === null && Kt.has(t) && (n = ke), n === null ? ke : Math.max(
4278
+ ke,
4279
+ Un(t, n)
4280
+ );
4281
+ }
4282
+ async function Xt(t, e, r) {
4283
+ if (!qt.has(t))
4284
+ return { ok: !0, params: e };
4285
+ if (!ie)
4286
+ return {
4287
+ ok: !1,
4288
+ error: { message: "Session not initialized", code: "E_INTERNAL" }
4289
+ };
4290
+ const n = await An(
4291
+ t,
4292
+ e,
4293
+ r,
4294
+ async (s) => {
4295
+ const i = nr(s);
4296
+ if (i !== void 0)
4297
+ return i;
4298
+ const c = On(s);
4299
+ return c !== void 0 ? c : await sr(s);
4300
+ }
4301
+ );
4302
+ return n.ok ? { ok: !0, params: n.value } : n;
4303
+ }
4304
+ function Jn(t, e) {
4305
+ t = he(t);
4306
+ const r = e == null ? void 0 : e.action;
4307
+ if (C.trace("extensionDispatch", {
4308
+ action: r,
4309
+ callId: e == null ? void 0 : e.callId,
4310
+ runId: e == null ? void 0 : e.runId
4311
+ }), !r)
4312
+ return Promise.resolve({
4313
+ ok: !1,
4314
+ error: {
4315
+ message: "Missing action in dispatch context",
4316
+ code: "E_MISSING_ACTION"
4317
+ }
4318
+ });
4319
+ const n = t;
4320
+ return (async () => {
4321
+ var h, d;
4322
+ const s = await Xt(
4323
+ r,
4324
+ t,
4325
+ e == null ? void 0 : e.runId
4326
+ );
4327
+ if (!s.ok)
4328
+ return s;
4329
+ if (t = s.params, ye.has(r)) {
4330
+ const m = ye.get(r), R = (e == null ? void 0 : e.signal) ?? (e != null && e.runId ? (h = U.get(e.runId)) == null ? void 0 : h.signal : void 0);
4331
+ return (async () => {
4332
+ try {
4333
+ return { ok: !0, value: await m(t, { ...e, signal: R }) };
4334
+ } catch (P) {
4335
+ const X = P instanceof Error ? P.message : String(P), de = typeof P == "object" && P !== null && "code" in P && typeof P.code == "string" ? P.code : "E_WORKER_HANDLER";
4336
+ return { ok: !1, error: { message: X, code: de } };
4337
+ }
4338
+ })();
4339
+ }
4340
+ const i = zr(r);
4341
+ if (!i)
4342
+ return Promise.resolve({
4343
+ ok: !1,
4344
+ error: {
4345
+ message: `No route registered for action: ${r}`,
4346
+ code: "E_NO_ROUTE"
4347
+ }
4348
+ });
4349
+ const a = await Yt({
4350
+ owner: i.endpoint,
4351
+ action: r,
4352
+ resolveTimeoutMs: (m) => Qt(r, m),
4353
+ tabPolicy: i.tabPolicy
4354
+ })(t, {
4355
+ ...e,
4356
+ signal: (e == null ? void 0 : e.signal) ?? (e != null && e.runId ? (d = U.get(e.runId)) == null ? void 0 : d.signal : void 0)
4357
+ });
4358
+ return Ht.has(r) && typeof a == "object" && a !== null && "ok" in a && a.ok ? {
4359
+ ok: !0,
4360
+ value: zt(
4361
+ n,
4362
+ a.value,
4363
+ e == null ? void 0 : e.runId
4364
+ )
4365
+ } : a;
4366
+ })();
4367
+ }
4368
+ function zn(t) {
4369
+ if (t.owner === Zn) {
4370
+ const e = ye.get(t.action);
4371
+ if (!e)
4372
+ throw new Error(
4373
+ `No worker-local handler registered for action: ${t.action}`
4374
+ );
4375
+ return async (r, n) => {
4376
+ var i;
4377
+ r = he(r);
4378
+ const s = (n == null ? void 0 : n.signal) ?? (n != null && n.runId ? (i = U.get(n.runId)) == null ? void 0 : i.signal : void 0);
4379
+ try {
4380
+ return { ok: !0, value: await e(r, {
4381
+ ...n,
4382
+ action: t.action,
4383
+ signal: s
4384
+ }) };
4385
+ } catch (c) {
4386
+ const a = c instanceof Error ? c.message : String(c), h = typeof c == "object" && c !== null && "code" in c && typeof c.code == "string" ? c.code : t.errorCode;
4387
+ return { ok: !1, error: { message: a, code: h } };
4388
+ }
4389
+ };
4390
+ } else {
4391
+ const e = Yt({
4392
+ owner: t.owner,
4393
+ action: t.action,
4394
+ resolveTimeoutMs: (r) => Qt(t.action, r)
4395
+ });
4396
+ return async (r, n) => {
4397
+ var c;
4398
+ const s = he(r), i = await Xt(
4399
+ t.action,
4400
+ s,
4401
+ n == null ? void 0 : n.runId
4402
+ );
4403
+ if (!i.ok)
4404
+ return i;
4405
+ try {
4406
+ const a = await e(i.params, {
4407
+ ...n,
4408
+ signal: (n == null ? void 0 : n.signal) ?? (n != null && n.runId ? (c = U.get(n.runId)) == null ? void 0 : c.signal : void 0)
4409
+ });
4410
+ return typeof a == "object" && a !== null && "ok" in a && a.ok && Ht.has(t.action) ? {
4411
+ ok: !0,
4412
+ value: zt(
4413
+ s,
4414
+ a.value,
4415
+ n == null ? void 0 : n.runId
4416
+ )
4417
+ } : a;
4418
+ } catch (a) {
4419
+ const h = a instanceof Error ? a.message : String(a), d = typeof a == "object" && a !== null && "code" in a && typeof a.code == "string" ? a.code : t.errorCode || "E_RELAY";
4420
+ return { ok: !1, error: { message: h, code: d } };
4421
+ }
4422
+ };
4423
+ }
4424
+ }
4425
+ function qn(t) {
4426
+ N(
4427
+ "exists",
4428
+ ee,
4429
+ (e) => t.fsExists(e)
4430
+ ), N(
4431
+ "stat",
4432
+ ee,
4433
+ (e) => t.fsStat(e)
4434
+ ), N(
4435
+ "read",
4436
+ ee,
4437
+ (e) => t.fsRead(e)
4438
+ ), N(
4439
+ "readText",
4440
+ ee,
4441
+ (e) => t.fsReadText(e)
4442
+ ), N(
4443
+ "readBase64",
4444
+ ee,
4445
+ (e) => t.fsReadBase64(e)
4446
+ ), N(
4447
+ "list",
4448
+ ee,
4449
+ (e) => t.fsList(e)
4450
+ ), N(
4451
+ "mkdir",
4452
+ ee,
4453
+ (e) => t.fsMkdir(e)
4454
+ ), N(
4455
+ "delete",
4456
+ ee,
4457
+ (e) => t.fsDelete(e)
4458
+ ), N(
4459
+ "copy",
4460
+ xt,
4461
+ (e) => t.fsCopy(e)
4462
+ ), N(
4463
+ "move",
4464
+ xt,
4465
+ (e) => t.fsMove(e)
4466
+ ), N(
4467
+ "write",
4468
+ le,
4469
+ (e) => t.fsWrite(e)
4470
+ ), N(
4471
+ "writeText",
4472
+ le,
4473
+ (e) => t.fsWriteText(e)
4474
+ ), N(
4475
+ "writeBase64",
4476
+ le,
4477
+ async (e) => {
4478
+ const r = e;
4479
+ return Cn(r.path, r.data), t.fsWriteBase64(r);
4480
+ }
4481
+ ), N(
4482
+ "append",
4483
+ le,
4484
+ (e) => t.fsAppend(e)
4485
+ ), N(
4486
+ "appendText",
4487
+ le,
4488
+ (e) => t.fsAppendText(e)
4489
+ ), N(
4490
+ "appendBase64",
4491
+ le,
4492
+ (e) => t.fsAppendBase64(e)
4493
+ ), N(
4494
+ "readRange",
4495
+ cn,
4496
+ (e) => t.fsReadRange(e)
4497
+ ), N(
4498
+ "update",
4499
+ dn,
4500
+ (e) => t.fsUpdate(e)
4501
+ ), N(
4502
+ "hash",
4503
+ ln,
4504
+ (e) => t.fsHash(e)
4505
+ );
4506
+ }
4507
+ async function Hn(t, e) {
4508
+ if (at) return;
4509
+ await er(), ie = new tr(), Ye(0), dr(Ye), C.trace("initWasm_start"), qn(ie), Yr(t);
4510
+ const n = t.map((i) => ({
4511
+ entry: hr(i),
4512
+ callback: zn(i)
4513
+ }));
4514
+ try {
4515
+ rr(n);
4516
+ } catch (i) {
4517
+ const c = i instanceof Error ? i.message : String(i);
4518
+ throw new Error(`Registry registration failed: ${c}`);
4519
+ }
4520
+ const { freezeManifest: s } = await import("./extension_js.js");
4521
+ try {
4522
+ s();
4523
+ } catch (i) {
4524
+ const c = i instanceof Error ? i.message : String(i);
4525
+ throw new Error(`Manifest freeze failed: ${c}`);
4526
+ }
4527
+ if (ie.injectRegistryBindings(), e) {
4528
+ const i = JSON.stringify(e);
4529
+ await ie.runCellAsync(
4530
+ `(function(){var r=globalThis.chrome&&globalThis.chrome.runtime;if(!r){r={};if(!globalThis.chrome)globalThis.chrome={};globalThis.chrome.runtime=r;}r.id=${i};})();`,
4531
+ "",
4532
+ "inject-runtime-id"
4533
+ );
4534
+ }
4535
+ at = !0, C.trace("initWasm_done");
4536
+ }
4537
+ self.onmessage = async (t) => {
4538
+ const e = t.data;
4539
+ if (C.trace("onmessage", {
4540
+ type: e.type,
4541
+ id: "id" in e ? e.id : void 0
4542
+ }), e.type === "asyncRelayResult") {
4543
+ C.trace("asyncRelayResult", { id: e.id }), ct(e.id, e.result);
4544
+ return;
4545
+ }
4546
+ if (e.type === "registerWorkerPort") {
4547
+ const n = t.ports[0];
4548
+ if (!n) {
4549
+ C.error("register_worker_port_missing", { owner: e.owner });
4550
+ return;
4551
+ }
4552
+ jn(e.owner, n);
4553
+ return;
4554
+ }
4555
+ if (e.type === "init") {
4556
+ try {
4557
+ await Hn(e.manifest, e.extensionId), self.postMessage({ type: "ready" });
4558
+ } catch (n) {
4559
+ const s = n instanceof Error ? n.message : String(n);
4560
+ C.error("worker_init_failed", { error: s }), self.postMessage({
4561
+ type: "error",
4562
+ error: `WASM init failed: ${s}`
4563
+ });
4564
+ }
4565
+ return;
4566
+ }
4567
+ if (e.type === "setLogLevel") {
4568
+ Ye(e.level), cr(Ln(e.level)), C.trace("set_log_level", { level: e.level });
4569
+ return;
4570
+ }
4571
+ if (!at || !ie) {
4572
+ self.postMessage({
4573
+ type: "error",
4574
+ id: e.id,
4575
+ error: "WASM not initialized"
4576
+ });
4577
+ return;
4578
+ }
4579
+ const r = ie;
4580
+ await Mn(async () => {
4581
+ switch (e.type) {
4582
+ case "runCell": {
4583
+ const n = e.runId, s = new AbortController();
4584
+ n && U.set(n, s), Z = { id: e.id, runId: n }, C.trace("runCell_start", {
4585
+ runId: n,
4586
+ callId: e.id,
4587
+ codeLen: e.code.length
4588
+ });
4589
+ try {
4590
+ const i = await r.runCellAsync(
4591
+ e.code,
4592
+ e.stdin || "",
4593
+ n || ""
4594
+ );
4595
+ C.trace("runCell_done", {
4596
+ runId: n,
4597
+ callId: e.id,
4598
+ status: i.status
4599
+ }), self.postMessage({
4600
+ type: "result",
4601
+ id: e.id,
4602
+ data: i,
4603
+ runId: n
4604
+ });
4605
+ } catch (i) {
4606
+ const c = i instanceof Error ? i.message : String(i), a = i instanceof Error ? i.name : void 0, h = i instanceof Error ? i.stack : void 0;
4607
+ let d;
4608
+ if (h) {
4609
+ const R = h.match(/:(\d+):\d+\)?$/m);
4610
+ R && (d = parseInt(R[1], 10));
4611
+ }
4612
+ C.error("runCell_error", { runId: n, error: c, name: a, line: d });
4613
+ const m = i instanceof Error ? {
4614
+ name: a,
4615
+ message: c,
4616
+ stack: h,
4617
+ ...d !== void 0 ? { line: d } : {}
4618
+ } : { message: c };
4619
+ self.postMessage({
4620
+ type: "error",
4621
+ id: e.id,
4622
+ error: m,
4623
+ runId: n
4624
+ });
4625
+ } finally {
4626
+ (Z == null ? void 0 : Z.id) === e.id && (Z = null), n && (U.delete(n), Sn(n));
4627
+ }
4628
+ break;
4629
+ }
4630
+ case "reset": {
4631
+ r.setAborted(!0);
4632
+ for (const n of U.values())
4633
+ n.abort();
4634
+ U.clear(), St(), Nn(), ir(), At("E_RESET", "Worker reset");
4635
+ try {
4636
+ r.reset(), self.postMessage({ type: "result", id: e.id, data: { ok: !0 } });
4637
+ } catch (n) {
4638
+ const s = n instanceof Error ? n.message : String(n);
4639
+ self.postMessage({ type: "error", id: e.id, error: s });
4640
+ }
4641
+ break;
4642
+ }
4643
+ case "stop": {
4644
+ r.setAborted(!0);
4645
+ for (const n of U.values())
4646
+ n.abort();
4647
+ U.clear(), St(), At("E_STOPPED", "Worker stopped"), self.postMessage({ type: "result", id: e.id, data: { ok: !0 } });
4648
+ break;
4649
+ }
4650
+ case "setFuelLimit": {
4651
+ try {
4652
+ r.set_fuel_limit(e.limit), e.id && self.postMessage({
4653
+ type: "result",
4654
+ id: e.id,
4655
+ data: { ok: !0 }
4656
+ });
4657
+ } catch (n) {
4658
+ if (e.id) {
4659
+ const s = n instanceof Error ? n.message : String(n);
4660
+ self.postMessage({ type: "error", id: e.id, error: s });
4661
+ }
4662
+ }
4663
+ break;
4664
+ }
4665
+ case "inspectGlobals": {
4666
+ try {
4667
+ const n = r.inspect_globals();
4668
+ self.postMessage({ type: "result", id: e.id, data: n });
4669
+ } catch (n) {
4670
+ const s = n instanceof Error ? n.message : String(n);
4671
+ self.postMessage({ type: "error", id: e.id, error: s });
4672
+ }
4673
+ break;
4674
+ }
4675
+ case "apiDocs": {
4676
+ try {
4677
+ const n = r.apiDocs(e.format);
4678
+ self.postMessage({ type: "result", id: e.id, data: n });
4679
+ } catch (n) {
4680
+ const s = n instanceof Error ? n.message : String(n);
4681
+ self.postMessage({ type: "error", id: e.id, error: s });
4682
+ }
4683
+ break;
4684
+ }
4685
+ case "loadLibrary": {
4686
+ try {
4687
+ const n = r.load_library(e.source);
4688
+ self.postMessage({ type: "result", id: e.id, data: n });
4689
+ } catch (n) {
4690
+ const s = n instanceof Error ? n.message : String(n);
4691
+ self.postMessage({ type: "error", id: e.id, error: s });
4692
+ }
4693
+ break;
4694
+ }
4695
+ case "fsCall": {
4696
+ const n = ye.get(e.action);
4697
+ if (!n) {
4698
+ self.postMessage({
4699
+ type: "error",
4700
+ id: e.id,
4701
+ error: `Unknown fs action: ${e.action}`
4702
+ });
4703
+ break;
4704
+ }
4705
+ try {
4706
+ const s = await n(e.params);
4707
+ self.postMessage({ type: "result", id: e.id, data: s });
4708
+ } catch (s) {
4709
+ const i = s instanceof Error ? s.message : String(s);
4710
+ self.postMessage({ type: "error", id: e.id, error: i });
4711
+ }
4712
+ break;
4713
+ }
4714
+ default: {
4715
+ C.error("unhandled_worker_message", {
4716
+ type: e.type
4717
+ });
4718
+ break;
4719
+ }
4720
+ }
4721
+ });
4722
+ };
4723
+ export {
4724
+ ke as DEFAULT_RELAY_TIMEOUT_MS,
4725
+ zn as createExecutableCallback,
4726
+ Jn as extensionDispatch,
4727
+ Pn as registerWorkerHandler,
4728
+ N as registerWorkerHandlerValidated,
4729
+ jn as registerWorkerPort,
4730
+ ct as resolveAsyncRelayResult,
4731
+ Qt as resolveRelayTimeoutMs,
4732
+ Yt as safePostAsCall,
4733
+ At as settleAllPendingRelays
4734
+ };