@pi-oxide/extension-js 0.6.0 → 0.8.1

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