@flowingspring/dsh-voco 0.3.3 → 0.3.4

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.
@@ -1,13 +1,4303 @@
1
1
  import { VoiceTaskId, VoiceTaskMessageId } from "./voice.js";
2
2
  import { createRequire } from "node:module";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
+ import "@deepseek-ai/cordis";
4
5
  import z from "@deepseek-ai/schemastery";
5
6
  import { extname, relative, resolve, sep } from "node:path";
6
7
  import { open, readdir, realpath, stat } from "node:fs/promises";
7
- import { createUserMessage } from "@deepseek-ai/dsh-llm";
8
+ import { installModelSelection } from "@deepseek-ai/dsh-agent";
9
+ import { ReasoningEffortId, createUserMessage } from "@deepseek-ai/dsh-llm";
8
10
  import { resolveSessionPreset } from "@deepseek-ai/dsh-agent-presets";
9
- import { KNOWN_SESSION_EVENT_TYPES, SessionId, foldRequestHeader } from "@deepseek-ai/dsh-session";
10
11
  import { defineTool } from "@deepseek-ai/dsh-tools";
12
+ import { KNOWN_SESSION_EVENT_TYPES, SessionId, foldRequestHeader, snapshotJsonValue } from "@deepseek-ai/dsh-session";
13
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.js
14
+ var _a$1;
15
+ function $constructor(name, initializer, params) {
16
+ function init(inst, def) {
17
+ if (!inst._zod) Object.defineProperty(inst, "_zod", {
18
+ value: {
19
+ def,
20
+ constr: _,
21
+ traits: /* @__PURE__ */ new Set()
22
+ },
23
+ enumerable: false
24
+ });
25
+ if (inst._zod.traits.has(name)) return;
26
+ inst._zod.traits.add(name);
27
+ initializer(inst, def);
28
+ const proto = _.prototype;
29
+ const keys = Object.keys(proto);
30
+ for (let i = 0; i < keys.length; i++) {
31
+ const k = keys[i];
32
+ if (!(k in inst)) inst[k] = proto[k].bind(inst);
33
+ }
34
+ }
35
+ const Parent = params?.Parent ?? Object;
36
+ class Definition extends Parent {}
37
+ Object.defineProperty(Definition, "name", { value: name });
38
+ function _(def) {
39
+ var _a;
40
+ const inst = params?.Parent ? new Definition() : this;
41
+ init(inst, def);
42
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
43
+ for (const fn of inst._zod.deferred) fn();
44
+ return inst;
45
+ }
46
+ Object.defineProperty(_, "init", { value: init });
47
+ Object.defineProperty(_, Symbol.hasInstance, { value: (inst) => {
48
+ if (params?.Parent && inst instanceof params.Parent) return true;
49
+ return inst?._zod?.traits?.has(name);
50
+ } });
51
+ Object.defineProperty(_, "name", { value: name });
52
+ return _;
53
+ }
54
+ var $ZodAsyncError = class extends Error {
55
+ constructor() {
56
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
57
+ }
58
+ };
59
+ var $ZodEncodeError = class extends Error {
60
+ constructor(name) {
61
+ super(`Encountered unidirectional transform during encode: ${name}`);
62
+ this.name = "ZodEncodeError";
63
+ }
64
+ };
65
+ (_a$1 = globalThis).__zod_globalConfig ?? (_a$1.__zod_globalConfig = {});
66
+ const globalConfig = globalThis.__zod_globalConfig;
67
+ function config(newConfig) {
68
+ if (newConfig) Object.assign(globalConfig, newConfig);
69
+ return globalConfig;
70
+ }
71
+ //#endregion
72
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/util.js
73
+ function getEnumValues(entries) {
74
+ const numericValues = Object.values(entries).filter((v) => typeof v === "number");
75
+ return Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
76
+ }
77
+ function jsonStringifyReplacer(_, value) {
78
+ if (typeof value === "bigint") return value.toString();
79
+ return value;
80
+ }
81
+ function cached(getter) {
82
+ return { get value() {
83
+ {
84
+ const value = getter();
85
+ Object.defineProperty(this, "value", { value });
86
+ return value;
87
+ }
88
+ } };
89
+ }
90
+ function nullish(input) {
91
+ return input === null || input === void 0;
92
+ }
93
+ function cleanRegex(source) {
94
+ const start = source.startsWith("^") ? 1 : 0;
95
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
96
+ return source.slice(start, end);
97
+ }
98
+ function floatSafeRemainder(val, step) {
99
+ const ratio = val / step;
100
+ const roundedRatio = Math.round(ratio);
101
+ const tolerance = Number.EPSILON * Math.max(Math.abs(ratio), 1);
102
+ if (Math.abs(ratio - roundedRatio) < tolerance) return 0;
103
+ return ratio - roundedRatio;
104
+ }
105
+ const EVALUATING = /* @__PURE__*/ Symbol("evaluating");
106
+ function defineLazy(object, key, getter) {
107
+ let value = void 0;
108
+ Object.defineProperty(object, key, {
109
+ get() {
110
+ if (value === EVALUATING) return;
111
+ if (value === void 0) {
112
+ value = EVALUATING;
113
+ value = getter();
114
+ }
115
+ return value;
116
+ },
117
+ set(v) {
118
+ Object.defineProperty(object, key, { value: v });
119
+ },
120
+ configurable: true
121
+ });
122
+ }
123
+ function assignProp(target, prop, value) {
124
+ Object.defineProperty(target, prop, {
125
+ value,
126
+ writable: true,
127
+ enumerable: true,
128
+ configurable: true
129
+ });
130
+ }
131
+ function mergeDefs(...defs) {
132
+ const mergedDescriptors = {};
133
+ for (const def of defs) {
134
+ const descriptors = Object.getOwnPropertyDescriptors(def);
135
+ Object.assign(mergedDescriptors, descriptors);
136
+ }
137
+ return Object.defineProperties({}, mergedDescriptors);
138
+ }
139
+ function esc(str) {
140
+ return JSON.stringify(str);
141
+ }
142
+ function slugify(input) {
143
+ return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
144
+ }
145
+ const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
146
+ function isObject(data) {
147
+ return typeof data === "object" && data !== null && !Array.isArray(data);
148
+ }
149
+ const allowsEval = /* @__PURE__*/ cached(() => {
150
+ if (globalConfig.jitless) return false;
151
+ if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false;
152
+ try {
153
+ new Function("");
154
+ return true;
155
+ } catch (_) {
156
+ return false;
157
+ }
158
+ });
159
+ function isPlainObject(o) {
160
+ if (isObject(o) === false) return false;
161
+ const ctor = o.constructor;
162
+ if (ctor === void 0) return true;
163
+ if (typeof ctor !== "function") return true;
164
+ const prot = ctor.prototype;
165
+ if (isObject(prot) === false) return false;
166
+ if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) return false;
167
+ return true;
168
+ }
169
+ function shallowClone(o) {
170
+ if (isPlainObject(o)) return { ...o };
171
+ if (Array.isArray(o)) return [...o];
172
+ if (o instanceof Map) return new Map(o);
173
+ if (o instanceof Set) return new Set(o);
174
+ return o;
175
+ }
176
+ const propertyKeyTypes = /* @__PURE__*/ new Set([
177
+ "string",
178
+ "number",
179
+ "symbol"
180
+ ]);
181
+ function escapeRegex(str) {
182
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
183
+ }
184
+ function clone(inst, def, params) {
185
+ const cl = new inst._zod.constr(def ?? inst._zod.def);
186
+ if (!def || params?.parent) cl._zod.parent = inst;
187
+ return cl;
188
+ }
189
+ function normalizeParams(_params) {
190
+ const params = _params;
191
+ if (!params) return {};
192
+ if (typeof params === "string") return { error: () => params };
193
+ if (params?.message !== void 0) {
194
+ if (params?.error !== void 0) throw new Error("Cannot specify both `message` and `error` params");
195
+ params.error = params.message;
196
+ }
197
+ delete params.message;
198
+ if (typeof params.error === "string") return {
199
+ ...params,
200
+ error: () => params.error
201
+ };
202
+ return params;
203
+ }
204
+ function optionalKeys(shape) {
205
+ return Object.keys(shape).filter((k) => {
206
+ return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
207
+ });
208
+ }
209
+ const NUMBER_FORMAT_RANGES = {
210
+ safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
211
+ int32: [-2147483648, 2147483647],
212
+ uint32: [0, 4294967295],
213
+ float32: [-34028234663852886e22, 34028234663852886e22],
214
+ float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
215
+ };
216
+ function pick(schema, mask) {
217
+ const currDef = schema._zod.def;
218
+ const checks = currDef.checks;
219
+ if (checks && checks.length > 0) throw new Error(".pick() cannot be used on object schemas containing refinements");
220
+ return clone(schema, mergeDefs(schema._zod.def, {
221
+ get shape() {
222
+ const newShape = {};
223
+ for (const key in mask) {
224
+ if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
225
+ if (!mask[key]) continue;
226
+ newShape[key] = currDef.shape[key];
227
+ }
228
+ assignProp(this, "shape", newShape);
229
+ return newShape;
230
+ },
231
+ checks: []
232
+ }));
233
+ }
234
+ function omit(schema, mask) {
235
+ const currDef = schema._zod.def;
236
+ const checks = currDef.checks;
237
+ if (checks && checks.length > 0) throw new Error(".omit() cannot be used on object schemas containing refinements");
238
+ return clone(schema, mergeDefs(schema._zod.def, {
239
+ get shape() {
240
+ const newShape = { ...schema._zod.def.shape };
241
+ for (const key in mask) {
242
+ if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
243
+ if (!mask[key]) continue;
244
+ delete newShape[key];
245
+ }
246
+ assignProp(this, "shape", newShape);
247
+ return newShape;
248
+ },
249
+ checks: []
250
+ }));
251
+ }
252
+ function extend(schema, shape) {
253
+ if (!isPlainObject(shape)) throw new Error("Invalid input to extend: expected a plain object");
254
+ const checks = schema._zod.def.checks;
255
+ if (checks && checks.length > 0) {
256
+ const existingShape = schema._zod.def.shape;
257
+ for (const key in shape) if (Object.getOwnPropertyDescriptor(existingShape, key) !== void 0) throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
258
+ }
259
+ return clone(schema, mergeDefs(schema._zod.def, { get shape() {
260
+ const _shape = {
261
+ ...schema._zod.def.shape,
262
+ ...shape
263
+ };
264
+ assignProp(this, "shape", _shape);
265
+ return _shape;
266
+ } }));
267
+ }
268
+ function safeExtend(schema, shape) {
269
+ if (!isPlainObject(shape)) throw new Error("Invalid input to safeExtend: expected a plain object");
270
+ return clone(schema, mergeDefs(schema._zod.def, { get shape() {
271
+ const _shape = {
272
+ ...schema._zod.def.shape,
273
+ ...shape
274
+ };
275
+ assignProp(this, "shape", _shape);
276
+ return _shape;
277
+ } }));
278
+ }
279
+ function merge(a, b) {
280
+ if (a._zod.def.checks?.length) throw new Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");
281
+ return clone(a, mergeDefs(a._zod.def, {
282
+ get shape() {
283
+ const _shape = {
284
+ ...a._zod.def.shape,
285
+ ...b._zod.def.shape
286
+ };
287
+ assignProp(this, "shape", _shape);
288
+ return _shape;
289
+ },
290
+ get catchall() {
291
+ return b._zod.def.catchall;
292
+ },
293
+ checks: b._zod.def.checks ?? []
294
+ }));
295
+ }
296
+ function partial(Class, schema, mask) {
297
+ const checks = schema._zod.def.checks;
298
+ if (checks && checks.length > 0) throw new Error(".partial() cannot be used on object schemas containing refinements");
299
+ return clone(schema, mergeDefs(schema._zod.def, {
300
+ get shape() {
301
+ const oldShape = schema._zod.def.shape;
302
+ const shape = { ...oldShape };
303
+ if (mask) for (const key in mask) {
304
+ if (!(key in oldShape)) throw new Error(`Unrecognized key: "${key}"`);
305
+ if (!mask[key]) continue;
306
+ shape[key] = Class ? new Class({
307
+ type: "optional",
308
+ innerType: oldShape[key]
309
+ }) : oldShape[key];
310
+ }
311
+ else for (const key in oldShape) shape[key] = Class ? new Class({
312
+ type: "optional",
313
+ innerType: oldShape[key]
314
+ }) : oldShape[key];
315
+ assignProp(this, "shape", shape);
316
+ return shape;
317
+ },
318
+ checks: []
319
+ }));
320
+ }
321
+ function required(Class, schema, mask) {
322
+ return clone(schema, mergeDefs(schema._zod.def, { get shape() {
323
+ const oldShape = schema._zod.def.shape;
324
+ const shape = { ...oldShape };
325
+ if (mask) for (const key in mask) {
326
+ if (!(key in shape)) throw new Error(`Unrecognized key: "${key}"`);
327
+ if (!mask[key]) continue;
328
+ shape[key] = new Class({
329
+ type: "nonoptional",
330
+ innerType: oldShape[key]
331
+ });
332
+ }
333
+ else for (const key in oldShape) shape[key] = new Class({
334
+ type: "nonoptional",
335
+ innerType: oldShape[key]
336
+ });
337
+ assignProp(this, "shape", shape);
338
+ return shape;
339
+ } }));
340
+ }
341
+ function aborted(x, startIndex = 0) {
342
+ if (x.aborted === true) return true;
343
+ for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue !== true) return true;
344
+ return false;
345
+ }
346
+ function explicitlyAborted(x, startIndex = 0) {
347
+ if (x.aborted === true) return true;
348
+ for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue === false) return true;
349
+ return false;
350
+ }
351
+ function prefixIssues(path, issues) {
352
+ return issues.map((iss) => {
353
+ var _a;
354
+ (_a = iss).path ?? (_a.path = []);
355
+ iss.path.unshift(path);
356
+ return iss;
357
+ });
358
+ }
359
+ function unwrapMessage(message) {
360
+ return typeof message === "string" ? message : message?.message;
361
+ }
362
+ function finalizeIssue(iss, ctx, config) {
363
+ const message = iss.message ? iss.message : unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config.customError?.(iss)) ?? unwrapMessage(config.localeError?.(iss)) ?? "Invalid input";
364
+ const { inst: _inst, continue: _continue, input: _input, ...rest } = iss;
365
+ rest.path ?? (rest.path = []);
366
+ rest.message = message;
367
+ if (ctx?.reportInput) rest.input = _input;
368
+ return rest;
369
+ }
370
+ function getLengthableOrigin(input) {
371
+ if (Array.isArray(input)) return "array";
372
+ if (typeof input === "string") return "string";
373
+ return "unknown";
374
+ }
375
+ function issue(...args) {
376
+ const [iss, input, inst] = args;
377
+ if (typeof iss === "string") return {
378
+ message: iss,
379
+ code: "custom",
380
+ input,
381
+ inst
382
+ };
383
+ return { ...iss };
384
+ }
385
+ //#endregion
386
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/errors.js
387
+ const initializer$1 = (inst, def) => {
388
+ inst.name = "$ZodError";
389
+ Object.defineProperty(inst, "_zod", {
390
+ value: inst._zod,
391
+ enumerable: false
392
+ });
393
+ Object.defineProperty(inst, "issues", {
394
+ value: def,
395
+ enumerable: false
396
+ });
397
+ inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
398
+ Object.defineProperty(inst, "toString", {
399
+ value: () => inst.message,
400
+ enumerable: false
401
+ });
402
+ };
403
+ const $ZodError = $constructor("$ZodError", initializer$1);
404
+ const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
405
+ function flattenError(error, mapper = (issue) => issue.message) {
406
+ const fieldErrors = {};
407
+ const formErrors = [];
408
+ for (const sub of error.issues) if (sub.path.length > 0) {
409
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
410
+ fieldErrors[sub.path[0]].push(mapper(sub));
411
+ } else formErrors.push(mapper(sub));
412
+ return {
413
+ formErrors,
414
+ fieldErrors
415
+ };
416
+ }
417
+ function formatError(error, mapper = (issue) => issue.message) {
418
+ const fieldErrors = { _errors: [] };
419
+ const processError = (error, path = []) => {
420
+ for (const issue of error.issues) if (issue.code === "invalid_union" && issue.errors.length) issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
421
+ else if (issue.code === "invalid_key") processError({ issues: issue.issues }, [...path, ...issue.path]);
422
+ else if (issue.code === "invalid_element") processError({ issues: issue.issues }, [...path, ...issue.path]);
423
+ else {
424
+ const fullpath = [...path, ...issue.path];
425
+ if (fullpath.length === 0) fieldErrors._errors.push(mapper(issue));
426
+ else {
427
+ let curr = fieldErrors;
428
+ let i = 0;
429
+ while (i < fullpath.length) {
430
+ const el = fullpath[i];
431
+ if (!(i === fullpath.length - 1)) curr[el] = curr[el] || { _errors: [] };
432
+ else {
433
+ curr[el] = curr[el] || { _errors: [] };
434
+ curr[el]._errors.push(mapper(issue));
435
+ }
436
+ curr = curr[el];
437
+ i++;
438
+ }
439
+ }
440
+ }
441
+ };
442
+ processError(error);
443
+ return fieldErrors;
444
+ }
445
+ //#endregion
446
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/parse.js
447
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
448
+ const ctx = _ctx ? {
449
+ ..._ctx,
450
+ async: false
451
+ } : { async: false };
452
+ const result = schema._zod.run({
453
+ value,
454
+ issues: []
455
+ }, ctx);
456
+ if (result instanceof Promise) throw new $ZodAsyncError();
457
+ if (result.issues.length) {
458
+ const e = new ((_params?.Err) ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
459
+ captureStackTrace(e, _params?.callee);
460
+ throw e;
461
+ }
462
+ return result.value;
463
+ };
464
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
465
+ const ctx = _ctx ? {
466
+ ..._ctx,
467
+ async: true
468
+ } : { async: true };
469
+ let result = schema._zod.run({
470
+ value,
471
+ issues: []
472
+ }, ctx);
473
+ if (result instanceof Promise) result = await result;
474
+ if (result.issues.length) {
475
+ const e = new ((params?.Err) ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
476
+ captureStackTrace(e, params?.callee);
477
+ throw e;
478
+ }
479
+ return result.value;
480
+ };
481
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
482
+ const ctx = _ctx ? {
483
+ ..._ctx,
484
+ async: false
485
+ } : { async: false };
486
+ const result = schema._zod.run({
487
+ value,
488
+ issues: []
489
+ }, ctx);
490
+ if (result instanceof Promise) throw new $ZodAsyncError();
491
+ return result.issues.length ? {
492
+ success: false,
493
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
494
+ } : {
495
+ success: true,
496
+ data: result.value
497
+ };
498
+ };
499
+ const safeParse$1 = /* @__PURE__*/ _safeParse($ZodRealError);
500
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
501
+ const ctx = _ctx ? {
502
+ ..._ctx,
503
+ async: true
504
+ } : { async: true };
505
+ let result = schema._zod.run({
506
+ value,
507
+ issues: []
508
+ }, ctx);
509
+ if (result instanceof Promise) result = await result;
510
+ return result.issues.length ? {
511
+ success: false,
512
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
513
+ } : {
514
+ success: true,
515
+ data: result.value
516
+ };
517
+ };
518
+ const safeParseAsync$1 = /* @__PURE__*/ _safeParseAsync($ZodRealError);
519
+ const _encode = (_Err) => (schema, value, _ctx) => {
520
+ const ctx = _ctx ? {
521
+ ..._ctx,
522
+ direction: "backward"
523
+ } : { direction: "backward" };
524
+ return _parse(_Err)(schema, value, ctx);
525
+ };
526
+ const _decode = (_Err) => (schema, value, _ctx) => {
527
+ return _parse(_Err)(schema, value, _ctx);
528
+ };
529
+ const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
530
+ const ctx = _ctx ? {
531
+ ..._ctx,
532
+ direction: "backward"
533
+ } : { direction: "backward" };
534
+ return _parseAsync(_Err)(schema, value, ctx);
535
+ };
536
+ const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
537
+ return _parseAsync(_Err)(schema, value, _ctx);
538
+ };
539
+ const _safeEncode = (_Err) => (schema, value, _ctx) => {
540
+ const ctx = _ctx ? {
541
+ ..._ctx,
542
+ direction: "backward"
543
+ } : { direction: "backward" };
544
+ return _safeParse(_Err)(schema, value, ctx);
545
+ };
546
+ const _safeDecode = (_Err) => (schema, value, _ctx) => {
547
+ return _safeParse(_Err)(schema, value, _ctx);
548
+ };
549
+ const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
550
+ const ctx = _ctx ? {
551
+ ..._ctx,
552
+ direction: "backward"
553
+ } : { direction: "backward" };
554
+ return _safeParseAsync(_Err)(schema, value, ctx);
555
+ };
556
+ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
557
+ return _safeParseAsync(_Err)(schema, value, _ctx);
558
+ };
559
+ //#endregion
560
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/regexes.js
561
+ /**
562
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
563
+ * (timestamps embedded in the id). Use {@link cuid2} instead.
564
+ * See https://github.com/paralleldrive/cuid.
565
+ */
566
+ const cuid = /^[cC][0-9a-z]{6,}$/;
567
+ const cuid2 = /^[0-9a-z]+$/;
568
+ const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
569
+ const xid = /^[0-9a-vA-V]{20}$/;
570
+ const ksuid = /^[A-Za-z0-9]{27}$/;
571
+ const nanoid = /^[a-zA-Z0-9_-]{21}$/;
572
+ /** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
573
+ const duration$1 = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
574
+ /** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
575
+ const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
576
+ /** Returns a regex for validating an RFC 9562/4122 UUID.
577
+ *
578
+ * @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
579
+ const uuid = (version) => {
580
+ if (!version) return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
581
+ return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
582
+ };
583
+ /** Practical email validation */
584
+ const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
585
+ const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
586
+ function emoji() {
587
+ return new RegExp(_emoji$1, "u");
588
+ }
589
+ const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
590
+ const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
591
+ const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
592
+ const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
593
+ const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
594
+ const base64url = /^[A-Za-z0-9_-]*$/;
595
+ const httpProtocol = /^https?$/;
596
+ const e164 = /^\+[1-9]\d{6,14}$/;
597
+ const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
598
+ const date$1 = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
599
+ function timeSource(args) {
600
+ const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
601
+ return typeof args.precision === "number" ? args.precision === -1 ? `${hhmm}` : args.precision === 0 ? `${hhmm}:[0-5]\\d` : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}` : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
602
+ }
603
+ function time$1(args) {
604
+ return new RegExp(`^${timeSource(args)}$`);
605
+ }
606
+ function datetime$1(args) {
607
+ const time = timeSource({ precision: args.precision });
608
+ const opts = ["Z"];
609
+ if (args.local) opts.push("");
610
+ if (args.offset) opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
611
+ const timeRegex = `${time}(?:${opts.join("|")})`;
612
+ return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
613
+ }
614
+ const string$1 = (params) => {
615
+ const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
616
+ return new RegExp(`^${regex}$`);
617
+ };
618
+ const integer = /^-?\d+$/;
619
+ const number$1 = /^-?\d+(?:\.\d+)?$/;
620
+ const boolean$1 = /^(?:true|false)$/i;
621
+ const lowercase = /^[^A-Z]*$/;
622
+ const uppercase = /^[^a-z]*$/;
623
+ //#endregion
624
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/checks.js
625
+ const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
626
+ var _a;
627
+ inst._zod ?? (inst._zod = {});
628
+ inst._zod.def = def;
629
+ (_a = inst._zod).onattach ?? (_a.onattach = []);
630
+ });
631
+ const numericOriginMap = {
632
+ number: "number",
633
+ bigint: "bigint",
634
+ object: "date"
635
+ };
636
+ const $ZodCheckLessThan = /*@__PURE__*/ $constructor("$ZodCheckLessThan", (inst, def) => {
637
+ $ZodCheck.init(inst, def);
638
+ const origin = numericOriginMap[typeof def.value];
639
+ inst._zod.onattach.push((inst) => {
640
+ const bag = inst._zod.bag;
641
+ const curr = (def.inclusive ? bag.maximum : bag.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
642
+ if (def.value < curr) {
643
+ if (def.inclusive) bag.maximum = def.value;
644
+ else bag.exclusiveMaximum = def.value;
645
+ }
646
+ });
647
+ inst._zod.check = (payload) => {
648
+ if (def.inclusive ? payload.value <= def.value : payload.value < def.value) return;
649
+ payload.issues.push({
650
+ origin,
651
+ code: "too_big",
652
+ maximum: typeof def.value === "object" ? def.value.getTime() : def.value,
653
+ input: payload.value,
654
+ inclusive: def.inclusive,
655
+ inst,
656
+ continue: !def.abort
657
+ });
658
+ };
659
+ });
660
+ const $ZodCheckGreaterThan = /*@__PURE__*/ $constructor("$ZodCheckGreaterThan", (inst, def) => {
661
+ $ZodCheck.init(inst, def);
662
+ const origin = numericOriginMap[typeof def.value];
663
+ inst._zod.onattach.push((inst) => {
664
+ const bag = inst._zod.bag;
665
+ const curr = (def.inclusive ? bag.minimum : bag.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
666
+ if (def.value > curr) {
667
+ if (def.inclusive) bag.minimum = def.value;
668
+ else bag.exclusiveMinimum = def.value;
669
+ }
670
+ });
671
+ inst._zod.check = (payload) => {
672
+ if (def.inclusive ? payload.value >= def.value : payload.value > def.value) return;
673
+ payload.issues.push({
674
+ origin,
675
+ code: "too_small",
676
+ minimum: typeof def.value === "object" ? def.value.getTime() : def.value,
677
+ input: payload.value,
678
+ inclusive: def.inclusive,
679
+ inst,
680
+ continue: !def.abort
681
+ });
682
+ };
683
+ });
684
+ const $ZodCheckMultipleOf = /*@__PURE__*/ $constructor("$ZodCheckMultipleOf", (inst, def) => {
685
+ $ZodCheck.init(inst, def);
686
+ inst._zod.onattach.push((inst) => {
687
+ var _a;
688
+ (_a = inst._zod.bag).multipleOf ?? (_a.multipleOf = def.value);
689
+ });
690
+ inst._zod.check = (payload) => {
691
+ if (typeof payload.value !== typeof def.value) throw new Error("Cannot mix number and bigint in multiple_of check.");
692
+ if (typeof payload.value === "bigint" ? payload.value % def.value === BigInt(0) : floatSafeRemainder(payload.value, def.value) === 0) return;
693
+ payload.issues.push({
694
+ origin: typeof payload.value,
695
+ code: "not_multiple_of",
696
+ divisor: def.value,
697
+ input: payload.value,
698
+ inst,
699
+ continue: !def.abort
700
+ });
701
+ };
702
+ });
703
+ const $ZodCheckNumberFormat = /*@__PURE__*/ $constructor("$ZodCheckNumberFormat", (inst, def) => {
704
+ $ZodCheck.init(inst, def);
705
+ def.format = def.format || "float64";
706
+ const isInt = def.format?.includes("int");
707
+ const origin = isInt ? "int" : "number";
708
+ const [minimum, maximum] = NUMBER_FORMAT_RANGES[def.format];
709
+ inst._zod.onattach.push((inst) => {
710
+ const bag = inst._zod.bag;
711
+ bag.format = def.format;
712
+ bag.minimum = minimum;
713
+ bag.maximum = maximum;
714
+ if (isInt) bag.pattern = integer;
715
+ });
716
+ inst._zod.check = (payload) => {
717
+ const input = payload.value;
718
+ if (isInt) {
719
+ if (!Number.isInteger(input)) {
720
+ payload.issues.push({
721
+ expected: origin,
722
+ format: def.format,
723
+ code: "invalid_type",
724
+ continue: false,
725
+ input,
726
+ inst
727
+ });
728
+ return;
729
+ }
730
+ if (!Number.isSafeInteger(input)) {
731
+ if (input > 0) payload.issues.push({
732
+ input,
733
+ code: "too_big",
734
+ maximum: Number.MAX_SAFE_INTEGER,
735
+ note: "Integers must be within the safe integer range.",
736
+ inst,
737
+ origin,
738
+ inclusive: true,
739
+ continue: !def.abort
740
+ });
741
+ else payload.issues.push({
742
+ input,
743
+ code: "too_small",
744
+ minimum: Number.MIN_SAFE_INTEGER,
745
+ note: "Integers must be within the safe integer range.",
746
+ inst,
747
+ origin,
748
+ inclusive: true,
749
+ continue: !def.abort
750
+ });
751
+ return;
752
+ }
753
+ }
754
+ if (input < minimum) payload.issues.push({
755
+ origin: "number",
756
+ input,
757
+ code: "too_small",
758
+ minimum,
759
+ inclusive: true,
760
+ inst,
761
+ continue: !def.abort
762
+ });
763
+ if (input > maximum) payload.issues.push({
764
+ origin: "number",
765
+ input,
766
+ code: "too_big",
767
+ maximum,
768
+ inclusive: true,
769
+ inst,
770
+ continue: !def.abort
771
+ });
772
+ };
773
+ });
774
+ const $ZodCheckMaxLength = /*@__PURE__*/ $constructor("$ZodCheckMaxLength", (inst, def) => {
775
+ var _a;
776
+ $ZodCheck.init(inst, def);
777
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
778
+ const val = payload.value;
779
+ return !nullish(val) && val.length !== void 0;
780
+ });
781
+ inst._zod.onattach.push((inst) => {
782
+ const curr = inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
783
+ if (def.maximum < curr) inst._zod.bag.maximum = def.maximum;
784
+ });
785
+ inst._zod.check = (payload) => {
786
+ const input = payload.value;
787
+ if (input.length <= def.maximum) return;
788
+ const origin = getLengthableOrigin(input);
789
+ payload.issues.push({
790
+ origin,
791
+ code: "too_big",
792
+ maximum: def.maximum,
793
+ inclusive: true,
794
+ input,
795
+ inst,
796
+ continue: !def.abort
797
+ });
798
+ };
799
+ });
800
+ const $ZodCheckMinLength = /*@__PURE__*/ $constructor("$ZodCheckMinLength", (inst, def) => {
801
+ var _a;
802
+ $ZodCheck.init(inst, def);
803
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
804
+ const val = payload.value;
805
+ return !nullish(val) && val.length !== void 0;
806
+ });
807
+ inst._zod.onattach.push((inst) => {
808
+ const curr = inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
809
+ if (def.minimum > curr) inst._zod.bag.minimum = def.minimum;
810
+ });
811
+ inst._zod.check = (payload) => {
812
+ const input = payload.value;
813
+ if (input.length >= def.minimum) return;
814
+ const origin = getLengthableOrigin(input);
815
+ payload.issues.push({
816
+ origin,
817
+ code: "too_small",
818
+ minimum: def.minimum,
819
+ inclusive: true,
820
+ input,
821
+ inst,
822
+ continue: !def.abort
823
+ });
824
+ };
825
+ });
826
+ const $ZodCheckLengthEquals = /*@__PURE__*/ $constructor("$ZodCheckLengthEquals", (inst, def) => {
827
+ var _a;
828
+ $ZodCheck.init(inst, def);
829
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
830
+ const val = payload.value;
831
+ return !nullish(val) && val.length !== void 0;
832
+ });
833
+ inst._zod.onattach.push((inst) => {
834
+ const bag = inst._zod.bag;
835
+ bag.minimum = def.length;
836
+ bag.maximum = def.length;
837
+ bag.length = def.length;
838
+ });
839
+ inst._zod.check = (payload) => {
840
+ const input = payload.value;
841
+ const length = input.length;
842
+ if (length === def.length) return;
843
+ const origin = getLengthableOrigin(input);
844
+ const tooBig = length > def.length;
845
+ payload.issues.push({
846
+ origin,
847
+ ...tooBig ? {
848
+ code: "too_big",
849
+ maximum: def.length
850
+ } : {
851
+ code: "too_small",
852
+ minimum: def.length
853
+ },
854
+ inclusive: true,
855
+ exact: true,
856
+ input: payload.value,
857
+ inst,
858
+ continue: !def.abort
859
+ });
860
+ };
861
+ });
862
+ const $ZodCheckStringFormat = /*@__PURE__*/ $constructor("$ZodCheckStringFormat", (inst, def) => {
863
+ var _a, _b;
864
+ $ZodCheck.init(inst, def);
865
+ inst._zod.onattach.push((inst) => {
866
+ const bag = inst._zod.bag;
867
+ bag.format = def.format;
868
+ if (def.pattern) {
869
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
870
+ bag.patterns.add(def.pattern);
871
+ }
872
+ });
873
+ if (def.pattern) (_a = inst._zod).check ?? (_a.check = (payload) => {
874
+ def.pattern.lastIndex = 0;
875
+ if (def.pattern.test(payload.value)) return;
876
+ payload.issues.push({
877
+ origin: "string",
878
+ code: "invalid_format",
879
+ format: def.format,
880
+ input: payload.value,
881
+ ...def.pattern ? { pattern: def.pattern.toString() } : {},
882
+ inst,
883
+ continue: !def.abort
884
+ });
885
+ });
886
+ else (_b = inst._zod).check ?? (_b.check = () => {});
887
+ });
888
+ const $ZodCheckRegex = /*@__PURE__*/ $constructor("$ZodCheckRegex", (inst, def) => {
889
+ $ZodCheckStringFormat.init(inst, def);
890
+ inst._zod.check = (payload) => {
891
+ def.pattern.lastIndex = 0;
892
+ if (def.pattern.test(payload.value)) return;
893
+ payload.issues.push({
894
+ origin: "string",
895
+ code: "invalid_format",
896
+ format: "regex",
897
+ input: payload.value,
898
+ pattern: def.pattern.toString(),
899
+ inst,
900
+ continue: !def.abort
901
+ });
902
+ };
903
+ });
904
+ const $ZodCheckLowerCase = /*@__PURE__*/ $constructor("$ZodCheckLowerCase", (inst, def) => {
905
+ def.pattern ?? (def.pattern = lowercase);
906
+ $ZodCheckStringFormat.init(inst, def);
907
+ });
908
+ const $ZodCheckUpperCase = /*@__PURE__*/ $constructor("$ZodCheckUpperCase", (inst, def) => {
909
+ def.pattern ?? (def.pattern = uppercase);
910
+ $ZodCheckStringFormat.init(inst, def);
911
+ });
912
+ const $ZodCheckIncludes = /*@__PURE__*/ $constructor("$ZodCheckIncludes", (inst, def) => {
913
+ $ZodCheck.init(inst, def);
914
+ const escapedRegex = escapeRegex(def.includes);
915
+ const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
916
+ def.pattern = pattern;
917
+ inst._zod.onattach.push((inst) => {
918
+ const bag = inst._zod.bag;
919
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
920
+ bag.patterns.add(pattern);
921
+ });
922
+ inst._zod.check = (payload) => {
923
+ if (payload.value.includes(def.includes, def.position)) return;
924
+ payload.issues.push({
925
+ origin: "string",
926
+ code: "invalid_format",
927
+ format: "includes",
928
+ includes: def.includes,
929
+ input: payload.value,
930
+ inst,
931
+ continue: !def.abort
932
+ });
933
+ };
934
+ });
935
+ const $ZodCheckStartsWith = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (inst, def) => {
936
+ $ZodCheck.init(inst, def);
937
+ const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
938
+ def.pattern ?? (def.pattern = pattern);
939
+ inst._zod.onattach.push((inst) => {
940
+ const bag = inst._zod.bag;
941
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
942
+ bag.patterns.add(pattern);
943
+ });
944
+ inst._zod.check = (payload) => {
945
+ if (payload.value.startsWith(def.prefix)) return;
946
+ payload.issues.push({
947
+ origin: "string",
948
+ code: "invalid_format",
949
+ format: "starts_with",
950
+ prefix: def.prefix,
951
+ input: payload.value,
952
+ inst,
953
+ continue: !def.abort
954
+ });
955
+ };
956
+ });
957
+ const $ZodCheckEndsWith = /*@__PURE__*/ $constructor("$ZodCheckEndsWith", (inst, def) => {
958
+ $ZodCheck.init(inst, def);
959
+ const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
960
+ def.pattern ?? (def.pattern = pattern);
961
+ inst._zod.onattach.push((inst) => {
962
+ const bag = inst._zod.bag;
963
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
964
+ bag.patterns.add(pattern);
965
+ });
966
+ inst._zod.check = (payload) => {
967
+ if (payload.value.endsWith(def.suffix)) return;
968
+ payload.issues.push({
969
+ origin: "string",
970
+ code: "invalid_format",
971
+ format: "ends_with",
972
+ suffix: def.suffix,
973
+ input: payload.value,
974
+ inst,
975
+ continue: !def.abort
976
+ });
977
+ };
978
+ });
979
+ const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (inst, def) => {
980
+ $ZodCheck.init(inst, def);
981
+ inst._zod.check = (payload) => {
982
+ payload.value = def.tx(payload.value);
983
+ };
984
+ });
985
+ //#endregion
986
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/doc.js
987
+ var Doc = class {
988
+ constructor(args = []) {
989
+ this.content = [];
990
+ this.indent = 0;
991
+ if (this) this.args = args;
992
+ }
993
+ indented(fn) {
994
+ this.indent += 1;
995
+ fn(this);
996
+ this.indent -= 1;
997
+ }
998
+ write(arg) {
999
+ if (typeof arg === "function") {
1000
+ arg(this, { execution: "sync" });
1001
+ arg(this, { execution: "async" });
1002
+ return;
1003
+ }
1004
+ const lines = arg.split("\n").filter((x) => x);
1005
+ const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
1006
+ const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
1007
+ for (const line of dedented) this.content.push(line);
1008
+ }
1009
+ compile() {
1010
+ const F = Function;
1011
+ const args = this?.args;
1012
+ const lines = [...(this?.content ?? [``]).map((x) => ` ${x}`)];
1013
+ return new F(...args, lines.join("\n"));
1014
+ }
1015
+ };
1016
+ //#endregion
1017
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/versions.js
1018
+ const version = {
1019
+ major: 4,
1020
+ minor: 4,
1021
+ patch: 3
1022
+ };
1023
+ //#endregion
1024
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/schemas.js
1025
+ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
1026
+ var _a;
1027
+ inst ?? (inst = {});
1028
+ inst._zod.def = def;
1029
+ inst._zod.bag = inst._zod.bag || {};
1030
+ inst._zod.version = version;
1031
+ const checks = [...inst._zod.def.checks ?? []];
1032
+ if (inst._zod.traits.has("$ZodCheck")) checks.unshift(inst);
1033
+ for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
1034
+ if (checks.length === 0) {
1035
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
1036
+ inst._zod.deferred?.push(() => {
1037
+ inst._zod.run = inst._zod.parse;
1038
+ });
1039
+ } else {
1040
+ const runChecks = (payload, checks, ctx) => {
1041
+ let isAborted = aborted(payload);
1042
+ let asyncResult;
1043
+ for (const ch of checks) {
1044
+ if (ch._zod.def.when) {
1045
+ if (explicitlyAborted(payload)) continue;
1046
+ if (!ch._zod.def.when(payload)) continue;
1047
+ } else if (isAborted) continue;
1048
+ const currLen = payload.issues.length;
1049
+ const _ = ch._zod.check(payload);
1050
+ if (_ instanceof Promise && ctx?.async === false) throw new $ZodAsyncError();
1051
+ if (asyncResult || _ instanceof Promise) asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
1052
+ await _;
1053
+ if (payload.issues.length === currLen) return;
1054
+ if (!isAborted) isAborted = aborted(payload, currLen);
1055
+ });
1056
+ else {
1057
+ if (payload.issues.length === currLen) continue;
1058
+ if (!isAborted) isAborted = aborted(payload, currLen);
1059
+ }
1060
+ }
1061
+ if (asyncResult) return asyncResult.then(() => {
1062
+ return payload;
1063
+ });
1064
+ return payload;
1065
+ };
1066
+ const handleCanaryResult = (canary, payload, ctx) => {
1067
+ if (aborted(canary)) {
1068
+ canary.aborted = true;
1069
+ return canary;
1070
+ }
1071
+ const checkResult = runChecks(payload, checks, ctx);
1072
+ if (checkResult instanceof Promise) {
1073
+ if (ctx.async === false) throw new $ZodAsyncError();
1074
+ return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
1075
+ }
1076
+ return inst._zod.parse(checkResult, ctx);
1077
+ };
1078
+ inst._zod.run = (payload, ctx) => {
1079
+ if (ctx.skipChecks) return inst._zod.parse(payload, ctx);
1080
+ if (ctx.direction === "backward") {
1081
+ const canary = inst._zod.parse({
1082
+ value: payload.value,
1083
+ issues: []
1084
+ }, {
1085
+ ...ctx,
1086
+ skipChecks: true
1087
+ });
1088
+ if (canary instanceof Promise) return canary.then((canary) => {
1089
+ return handleCanaryResult(canary, payload, ctx);
1090
+ });
1091
+ return handleCanaryResult(canary, payload, ctx);
1092
+ }
1093
+ const result = inst._zod.parse(payload, ctx);
1094
+ if (result instanceof Promise) {
1095
+ if (ctx.async === false) throw new $ZodAsyncError();
1096
+ return result.then((result) => runChecks(result, checks, ctx));
1097
+ }
1098
+ return runChecks(result, checks, ctx);
1099
+ };
1100
+ }
1101
+ defineLazy(inst, "~standard", () => ({
1102
+ validate: (value) => {
1103
+ try {
1104
+ const r = safeParse$1(inst, value);
1105
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
1106
+ } catch (_) {
1107
+ return safeParseAsync$1(inst, value).then((r) => r.success ? { value: r.data } : { issues: r.error?.issues });
1108
+ }
1109
+ },
1110
+ vendor: "zod",
1111
+ version: 1
1112
+ }));
1113
+ });
1114
+ const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
1115
+ $ZodType.init(inst, def);
1116
+ inst._zod.pattern = [...inst?._zod.bag?.patterns ?? []].pop() ?? string$1(inst._zod.bag);
1117
+ inst._zod.parse = (payload, _) => {
1118
+ if (def.coerce) try {
1119
+ payload.value = String(payload.value);
1120
+ } catch (_) {}
1121
+ if (typeof payload.value === "string") return payload;
1122
+ payload.issues.push({
1123
+ expected: "string",
1124
+ code: "invalid_type",
1125
+ input: payload.value,
1126
+ inst
1127
+ });
1128
+ return payload;
1129
+ };
1130
+ });
1131
+ const $ZodStringFormat = /*@__PURE__*/ $constructor("$ZodStringFormat", (inst, def) => {
1132
+ $ZodCheckStringFormat.init(inst, def);
1133
+ $ZodString.init(inst, def);
1134
+ });
1135
+ const $ZodGUID = /*@__PURE__*/ $constructor("$ZodGUID", (inst, def) => {
1136
+ def.pattern ?? (def.pattern = guid);
1137
+ $ZodStringFormat.init(inst, def);
1138
+ });
1139
+ const $ZodUUID = /*@__PURE__*/ $constructor("$ZodUUID", (inst, def) => {
1140
+ if (def.version) {
1141
+ const v = {
1142
+ v1: 1,
1143
+ v2: 2,
1144
+ v3: 3,
1145
+ v4: 4,
1146
+ v5: 5,
1147
+ v6: 6,
1148
+ v7: 7,
1149
+ v8: 8
1150
+ }[def.version];
1151
+ if (v === void 0) throw new Error(`Invalid UUID version: "${def.version}"`);
1152
+ def.pattern ?? (def.pattern = uuid(v));
1153
+ } else def.pattern ?? (def.pattern = uuid());
1154
+ $ZodStringFormat.init(inst, def);
1155
+ });
1156
+ const $ZodEmail = /*@__PURE__*/ $constructor("$ZodEmail", (inst, def) => {
1157
+ def.pattern ?? (def.pattern = email);
1158
+ $ZodStringFormat.init(inst, def);
1159
+ });
1160
+ const $ZodURL = /*@__PURE__*/ $constructor("$ZodURL", (inst, def) => {
1161
+ $ZodStringFormat.init(inst, def);
1162
+ inst._zod.check = (payload) => {
1163
+ try {
1164
+ const trimmed = payload.value.trim();
1165
+ if (!def.normalize && def.protocol?.source === httpProtocol.source) {
1166
+ if (!/^https?:\/\//i.test(trimmed)) {
1167
+ payload.issues.push({
1168
+ code: "invalid_format",
1169
+ format: "url",
1170
+ note: "Invalid URL format",
1171
+ input: payload.value,
1172
+ inst,
1173
+ continue: !def.abort
1174
+ });
1175
+ return;
1176
+ }
1177
+ }
1178
+ const url = new URL(trimmed);
1179
+ if (def.hostname) {
1180
+ def.hostname.lastIndex = 0;
1181
+ if (!def.hostname.test(url.hostname)) payload.issues.push({
1182
+ code: "invalid_format",
1183
+ format: "url",
1184
+ note: "Invalid hostname",
1185
+ pattern: def.hostname.source,
1186
+ input: payload.value,
1187
+ inst,
1188
+ continue: !def.abort
1189
+ });
1190
+ }
1191
+ if (def.protocol) {
1192
+ def.protocol.lastIndex = 0;
1193
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) payload.issues.push({
1194
+ code: "invalid_format",
1195
+ format: "url",
1196
+ note: "Invalid protocol",
1197
+ pattern: def.protocol.source,
1198
+ input: payload.value,
1199
+ inst,
1200
+ continue: !def.abort
1201
+ });
1202
+ }
1203
+ if (def.normalize) payload.value = url.href;
1204
+ else payload.value = trimmed;
1205
+ return;
1206
+ } catch (_) {
1207
+ payload.issues.push({
1208
+ code: "invalid_format",
1209
+ format: "url",
1210
+ input: payload.value,
1211
+ inst,
1212
+ continue: !def.abort
1213
+ });
1214
+ }
1215
+ };
1216
+ });
1217
+ const $ZodEmoji = /*@__PURE__*/ $constructor("$ZodEmoji", (inst, def) => {
1218
+ def.pattern ?? (def.pattern = emoji());
1219
+ $ZodStringFormat.init(inst, def);
1220
+ });
1221
+ const $ZodNanoID = /*@__PURE__*/ $constructor("$ZodNanoID", (inst, def) => {
1222
+ def.pattern ?? (def.pattern = nanoid);
1223
+ $ZodStringFormat.init(inst, def);
1224
+ });
1225
+ /**
1226
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
1227
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
1228
+ * See https://github.com/paralleldrive/cuid.
1229
+ */
1230
+ const $ZodCUID = /*@__PURE__*/ $constructor("$ZodCUID", (inst, def) => {
1231
+ def.pattern ?? (def.pattern = cuid);
1232
+ $ZodStringFormat.init(inst, def);
1233
+ });
1234
+ const $ZodCUID2 = /*@__PURE__*/ $constructor("$ZodCUID2", (inst, def) => {
1235
+ def.pattern ?? (def.pattern = cuid2);
1236
+ $ZodStringFormat.init(inst, def);
1237
+ });
1238
+ const $ZodULID = /*@__PURE__*/ $constructor("$ZodULID", (inst, def) => {
1239
+ def.pattern ?? (def.pattern = ulid);
1240
+ $ZodStringFormat.init(inst, def);
1241
+ });
1242
+ const $ZodXID = /*@__PURE__*/ $constructor("$ZodXID", (inst, def) => {
1243
+ def.pattern ?? (def.pattern = xid);
1244
+ $ZodStringFormat.init(inst, def);
1245
+ });
1246
+ const $ZodKSUID = /*@__PURE__*/ $constructor("$ZodKSUID", (inst, def) => {
1247
+ def.pattern ?? (def.pattern = ksuid);
1248
+ $ZodStringFormat.init(inst, def);
1249
+ });
1250
+ const $ZodISODateTime = /*@__PURE__*/ $constructor("$ZodISODateTime", (inst, def) => {
1251
+ def.pattern ?? (def.pattern = datetime$1(def));
1252
+ $ZodStringFormat.init(inst, def);
1253
+ });
1254
+ const $ZodISODate = /*@__PURE__*/ $constructor("$ZodISODate", (inst, def) => {
1255
+ def.pattern ?? (def.pattern = date$1);
1256
+ $ZodStringFormat.init(inst, def);
1257
+ });
1258
+ const $ZodISOTime = /*@__PURE__*/ $constructor("$ZodISOTime", (inst, def) => {
1259
+ def.pattern ?? (def.pattern = time$1(def));
1260
+ $ZodStringFormat.init(inst, def);
1261
+ });
1262
+ const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def) => {
1263
+ def.pattern ?? (def.pattern = duration$1);
1264
+ $ZodStringFormat.init(inst, def);
1265
+ });
1266
+ const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def) => {
1267
+ def.pattern ?? (def.pattern = ipv4);
1268
+ $ZodStringFormat.init(inst, def);
1269
+ inst._zod.bag.format = `ipv4`;
1270
+ });
1271
+ const $ZodIPv6 = /*@__PURE__*/ $constructor("$ZodIPv6", (inst, def) => {
1272
+ def.pattern ?? (def.pattern = ipv6);
1273
+ $ZodStringFormat.init(inst, def);
1274
+ inst._zod.bag.format = `ipv6`;
1275
+ inst._zod.check = (payload) => {
1276
+ try {
1277
+ new URL(`http://[${payload.value}]`);
1278
+ } catch {
1279
+ payload.issues.push({
1280
+ code: "invalid_format",
1281
+ format: "ipv6",
1282
+ input: payload.value,
1283
+ inst,
1284
+ continue: !def.abort
1285
+ });
1286
+ }
1287
+ };
1288
+ });
1289
+ const $ZodCIDRv4 = /*@__PURE__*/ $constructor("$ZodCIDRv4", (inst, def) => {
1290
+ def.pattern ?? (def.pattern = cidrv4);
1291
+ $ZodStringFormat.init(inst, def);
1292
+ });
1293
+ const $ZodCIDRv6 = /*@__PURE__*/ $constructor("$ZodCIDRv6", (inst, def) => {
1294
+ def.pattern ?? (def.pattern = cidrv6);
1295
+ $ZodStringFormat.init(inst, def);
1296
+ inst._zod.check = (payload) => {
1297
+ const parts = payload.value.split("/");
1298
+ try {
1299
+ if (parts.length !== 2) throw new Error();
1300
+ const [address, prefix] = parts;
1301
+ if (!prefix) throw new Error();
1302
+ const prefixNum = Number(prefix);
1303
+ if (`${prefixNum}` !== prefix) throw new Error();
1304
+ if (prefixNum < 0 || prefixNum > 128) throw new Error();
1305
+ new URL(`http://[${address}]`);
1306
+ } catch {
1307
+ payload.issues.push({
1308
+ code: "invalid_format",
1309
+ format: "cidrv6",
1310
+ input: payload.value,
1311
+ inst,
1312
+ continue: !def.abort
1313
+ });
1314
+ }
1315
+ };
1316
+ });
1317
+ function isValidBase64(data) {
1318
+ if (data === "") return true;
1319
+ if (/\s/.test(data)) return false;
1320
+ if (data.length % 4 !== 0) return false;
1321
+ try {
1322
+ atob(data);
1323
+ return true;
1324
+ } catch {
1325
+ return false;
1326
+ }
1327
+ }
1328
+ const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def) => {
1329
+ def.pattern ?? (def.pattern = base64);
1330
+ $ZodStringFormat.init(inst, def);
1331
+ inst._zod.bag.contentEncoding = "base64";
1332
+ inst._zod.check = (payload) => {
1333
+ if (isValidBase64(payload.value)) return;
1334
+ payload.issues.push({
1335
+ code: "invalid_format",
1336
+ format: "base64",
1337
+ input: payload.value,
1338
+ inst,
1339
+ continue: !def.abort
1340
+ });
1341
+ };
1342
+ });
1343
+ function isValidBase64URL(data) {
1344
+ if (!base64url.test(data)) return false;
1345
+ const base64 = data.replace(/[-_]/g, (c) => c === "-" ? "+" : "/");
1346
+ return isValidBase64(base64.padEnd(Math.ceil(base64.length / 4) * 4, "="));
1347
+ }
1348
+ const $ZodBase64URL = /*@__PURE__*/ $constructor("$ZodBase64URL", (inst, def) => {
1349
+ def.pattern ?? (def.pattern = base64url);
1350
+ $ZodStringFormat.init(inst, def);
1351
+ inst._zod.bag.contentEncoding = "base64url";
1352
+ inst._zod.check = (payload) => {
1353
+ if (isValidBase64URL(payload.value)) return;
1354
+ payload.issues.push({
1355
+ code: "invalid_format",
1356
+ format: "base64url",
1357
+ input: payload.value,
1358
+ inst,
1359
+ continue: !def.abort
1360
+ });
1361
+ };
1362
+ });
1363
+ const $ZodE164 = /*@__PURE__*/ $constructor("$ZodE164", (inst, def) => {
1364
+ def.pattern ?? (def.pattern = e164);
1365
+ $ZodStringFormat.init(inst, def);
1366
+ });
1367
+ function isValidJWT(token, algorithm = null) {
1368
+ try {
1369
+ const tokensParts = token.split(".");
1370
+ if (tokensParts.length !== 3) return false;
1371
+ const [header] = tokensParts;
1372
+ if (!header) return false;
1373
+ const parsedHeader = JSON.parse(atob(header));
1374
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT") return false;
1375
+ if (!parsedHeader.alg) return false;
1376
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm)) return false;
1377
+ return true;
1378
+ } catch {
1379
+ return false;
1380
+ }
1381
+ }
1382
+ const $ZodJWT = /*@__PURE__*/ $constructor("$ZodJWT", (inst, def) => {
1383
+ $ZodStringFormat.init(inst, def);
1384
+ inst._zod.check = (payload) => {
1385
+ if (isValidJWT(payload.value, def.alg)) return;
1386
+ payload.issues.push({
1387
+ code: "invalid_format",
1388
+ format: "jwt",
1389
+ input: payload.value,
1390
+ inst,
1391
+ continue: !def.abort
1392
+ });
1393
+ };
1394
+ });
1395
+ const $ZodNumber = /*@__PURE__*/ $constructor("$ZodNumber", (inst, def) => {
1396
+ $ZodType.init(inst, def);
1397
+ inst._zod.pattern = inst._zod.bag.pattern ?? number$1;
1398
+ inst._zod.parse = (payload, _ctx) => {
1399
+ if (def.coerce) try {
1400
+ payload.value = Number(payload.value);
1401
+ } catch (_) {}
1402
+ const input = payload.value;
1403
+ if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) return payload;
1404
+ const received = typeof input === "number" ? Number.isNaN(input) ? "NaN" : !Number.isFinite(input) ? "Infinity" : void 0 : void 0;
1405
+ payload.issues.push({
1406
+ expected: "number",
1407
+ code: "invalid_type",
1408
+ input,
1409
+ inst,
1410
+ ...received ? { received } : {}
1411
+ });
1412
+ return payload;
1413
+ };
1414
+ });
1415
+ const $ZodNumberFormat = /*@__PURE__*/ $constructor("$ZodNumberFormat", (inst, def) => {
1416
+ $ZodCheckNumberFormat.init(inst, def);
1417
+ $ZodNumber.init(inst, def);
1418
+ });
1419
+ const $ZodBoolean = /*@__PURE__*/ $constructor("$ZodBoolean", (inst, def) => {
1420
+ $ZodType.init(inst, def);
1421
+ inst._zod.pattern = boolean$1;
1422
+ inst._zod.parse = (payload, _ctx) => {
1423
+ if (def.coerce) try {
1424
+ payload.value = Boolean(payload.value);
1425
+ } catch (_) {}
1426
+ const input = payload.value;
1427
+ if (typeof input === "boolean") return payload;
1428
+ payload.issues.push({
1429
+ expected: "boolean",
1430
+ code: "invalid_type",
1431
+ input,
1432
+ inst
1433
+ });
1434
+ return payload;
1435
+ };
1436
+ });
1437
+ const $ZodUnknown = /*@__PURE__*/ $constructor("$ZodUnknown", (inst, def) => {
1438
+ $ZodType.init(inst, def);
1439
+ inst._zod.parse = (payload) => payload;
1440
+ });
1441
+ const $ZodNever = /*@__PURE__*/ $constructor("$ZodNever", (inst, def) => {
1442
+ $ZodType.init(inst, def);
1443
+ inst._zod.parse = (payload, _ctx) => {
1444
+ payload.issues.push({
1445
+ expected: "never",
1446
+ code: "invalid_type",
1447
+ input: payload.value,
1448
+ inst
1449
+ });
1450
+ return payload;
1451
+ };
1452
+ });
1453
+ function handleArrayResult(result, final, index) {
1454
+ if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
1455
+ final.value[index] = result.value;
1456
+ }
1457
+ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
1458
+ $ZodType.init(inst, def);
1459
+ inst._zod.parse = (payload, ctx) => {
1460
+ const input = payload.value;
1461
+ if (!Array.isArray(input)) {
1462
+ payload.issues.push({
1463
+ expected: "array",
1464
+ code: "invalid_type",
1465
+ input,
1466
+ inst
1467
+ });
1468
+ return payload;
1469
+ }
1470
+ payload.value = Array(input.length);
1471
+ const proms = [];
1472
+ for (let i = 0; i < input.length; i++) {
1473
+ const item = input[i];
1474
+ const result = def.element._zod.run({
1475
+ value: item,
1476
+ issues: []
1477
+ }, ctx);
1478
+ if (result instanceof Promise) proms.push(result.then((result) => handleArrayResult(result, payload, i)));
1479
+ else handleArrayResult(result, payload, i);
1480
+ }
1481
+ if (proms.length) return Promise.all(proms).then(() => payload);
1482
+ return payload;
1483
+ };
1484
+ });
1485
+ function handlePropertyResult(result, final, key, input, isOptionalIn, isOptionalOut) {
1486
+ const isPresent = key in input;
1487
+ if (result.issues.length) {
1488
+ if (isOptionalIn && isOptionalOut && !isPresent) return;
1489
+ final.issues.push(...prefixIssues(key, result.issues));
1490
+ }
1491
+ if (!isPresent && !isOptionalIn) {
1492
+ if (!result.issues.length) final.issues.push({
1493
+ code: "invalid_type",
1494
+ expected: "nonoptional",
1495
+ input: void 0,
1496
+ path: [key]
1497
+ });
1498
+ return;
1499
+ }
1500
+ if (result.value === void 0) {
1501
+ if (isPresent) final.value[key] = void 0;
1502
+ } else final.value[key] = result.value;
1503
+ }
1504
+ function normalizeDef(def) {
1505
+ const keys = Object.keys(def.shape);
1506
+ for (const k of keys) if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
1507
+ const okeys = optionalKeys(def.shape);
1508
+ return {
1509
+ ...def,
1510
+ keys,
1511
+ keySet: new Set(keys),
1512
+ numKeys: keys.length,
1513
+ optionalKeys: new Set(okeys)
1514
+ };
1515
+ }
1516
+ function handleCatchall(proms, input, payload, ctx, def, inst) {
1517
+ const unrecognized = [];
1518
+ const keySet = def.keySet;
1519
+ const _catchall = def.catchall._zod;
1520
+ const t = _catchall.def.type;
1521
+ const isOptionalIn = _catchall.optin === "optional";
1522
+ const isOptionalOut = _catchall.optout === "optional";
1523
+ for (const key in input) {
1524
+ if (key === "__proto__") continue;
1525
+ if (keySet.has(key)) continue;
1526
+ if (t === "never") {
1527
+ unrecognized.push(key);
1528
+ continue;
1529
+ }
1530
+ const r = _catchall.run({
1531
+ value: input[key],
1532
+ issues: []
1533
+ }, ctx);
1534
+ if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut)));
1535
+ else handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut);
1536
+ }
1537
+ if (unrecognized.length) payload.issues.push({
1538
+ code: "unrecognized_keys",
1539
+ keys: unrecognized,
1540
+ input,
1541
+ inst
1542
+ });
1543
+ if (!proms.length) return payload;
1544
+ return Promise.all(proms).then(() => {
1545
+ return payload;
1546
+ });
1547
+ }
1548
+ const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
1549
+ $ZodType.init(inst, def);
1550
+ if (!Object.getOwnPropertyDescriptor(def, "shape")?.get) {
1551
+ const sh = def.shape;
1552
+ Object.defineProperty(def, "shape", { get: () => {
1553
+ const newSh = { ...sh };
1554
+ Object.defineProperty(def, "shape", { value: newSh });
1555
+ return newSh;
1556
+ } });
1557
+ }
1558
+ const _normalized = cached(() => normalizeDef(def));
1559
+ defineLazy(inst._zod, "propValues", () => {
1560
+ const shape = def.shape;
1561
+ const propValues = {};
1562
+ for (const key in shape) {
1563
+ const field = shape[key]._zod;
1564
+ if (field.values) {
1565
+ propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
1566
+ for (const v of field.values) propValues[key].add(v);
1567
+ }
1568
+ }
1569
+ return propValues;
1570
+ });
1571
+ const isObject$1 = isObject;
1572
+ const catchall = def.catchall;
1573
+ let value;
1574
+ inst._zod.parse = (payload, ctx) => {
1575
+ value ?? (value = _normalized.value);
1576
+ const input = payload.value;
1577
+ if (!isObject$1(input)) {
1578
+ payload.issues.push({
1579
+ expected: "object",
1580
+ code: "invalid_type",
1581
+ input,
1582
+ inst
1583
+ });
1584
+ return payload;
1585
+ }
1586
+ payload.value = {};
1587
+ const proms = [];
1588
+ const shape = value.shape;
1589
+ for (const key of value.keys) {
1590
+ const el = shape[key];
1591
+ const isOptionalIn = el._zod.optin === "optional";
1592
+ const isOptionalOut = el._zod.optout === "optional";
1593
+ const r = el._zod.run({
1594
+ value: input[key],
1595
+ issues: []
1596
+ }, ctx);
1597
+ if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut)));
1598
+ else handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut);
1599
+ }
1600
+ if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
1601
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
1602
+ };
1603
+ });
1604
+ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) => {
1605
+ $ZodObject.init(inst, def);
1606
+ const superParse = inst._zod.parse;
1607
+ const _normalized = cached(() => normalizeDef(def));
1608
+ const generateFastpass = (shape) => {
1609
+ const doc = new Doc([
1610
+ "shape",
1611
+ "payload",
1612
+ "ctx"
1613
+ ]);
1614
+ const normalized = _normalized.value;
1615
+ const parseStr = (key) => {
1616
+ const k = esc(key);
1617
+ return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
1618
+ };
1619
+ doc.write(`const input = payload.value;`);
1620
+ const ids = Object.create(null);
1621
+ let counter = 0;
1622
+ for (const key of normalized.keys) ids[key] = `key_${counter++}`;
1623
+ doc.write(`const newResult = {};`);
1624
+ for (const key of normalized.keys) {
1625
+ const id = ids[key];
1626
+ const k = esc(key);
1627
+ const schema = shape[key];
1628
+ const isOptionalIn = schema?._zod?.optin === "optional";
1629
+ const isOptionalOut = schema?._zod?.optout === "optional";
1630
+ doc.write(`const ${id} = ${parseStr(key)};`);
1631
+ if (isOptionalIn && isOptionalOut) doc.write(`
1632
+ if (${id}.issues.length) {
1633
+ if (${k} in input) {
1634
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1635
+ ...iss,
1636
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
1637
+ })));
1638
+ }
1639
+ }
1640
+
1641
+ if (${id}.value === undefined) {
1642
+ if (${k} in input) {
1643
+ newResult[${k}] = undefined;
1644
+ }
1645
+ } else {
1646
+ newResult[${k}] = ${id}.value;
1647
+ }
1648
+
1649
+ `);
1650
+ else if (!isOptionalIn) doc.write(`
1651
+ const ${id}_present = ${k} in input;
1652
+ if (${id}.issues.length) {
1653
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1654
+ ...iss,
1655
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
1656
+ })));
1657
+ }
1658
+ if (!${id}_present && !${id}.issues.length) {
1659
+ payload.issues.push({
1660
+ code: "invalid_type",
1661
+ expected: "nonoptional",
1662
+ input: undefined,
1663
+ path: [${k}]
1664
+ });
1665
+ }
1666
+
1667
+ if (${id}_present) {
1668
+ if (${id}.value === undefined) {
1669
+ newResult[${k}] = undefined;
1670
+ } else {
1671
+ newResult[${k}] = ${id}.value;
1672
+ }
1673
+ }
1674
+
1675
+ `);
1676
+ else doc.write(`
1677
+ if (${id}.issues.length) {
1678
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1679
+ ...iss,
1680
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
1681
+ })));
1682
+ }
1683
+
1684
+ if (${id}.value === undefined) {
1685
+ if (${k} in input) {
1686
+ newResult[${k}] = undefined;
1687
+ }
1688
+ } else {
1689
+ newResult[${k}] = ${id}.value;
1690
+ }
1691
+
1692
+ `);
1693
+ }
1694
+ doc.write(`payload.value = newResult;`);
1695
+ doc.write(`return payload;`);
1696
+ const fn = doc.compile();
1697
+ return (payload, ctx) => fn(shape, payload, ctx);
1698
+ };
1699
+ let fastpass;
1700
+ const isObject$2 = isObject;
1701
+ const jit = !globalConfig.jitless;
1702
+ const fastEnabled = jit && allowsEval.value;
1703
+ const catchall = def.catchall;
1704
+ let value;
1705
+ inst._zod.parse = (payload, ctx) => {
1706
+ value ?? (value = _normalized.value);
1707
+ const input = payload.value;
1708
+ if (!isObject$2(input)) {
1709
+ payload.issues.push({
1710
+ expected: "object",
1711
+ code: "invalid_type",
1712
+ input,
1713
+ inst
1714
+ });
1715
+ return payload;
1716
+ }
1717
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
1718
+ if (!fastpass) fastpass = generateFastpass(def.shape);
1719
+ payload = fastpass(payload, ctx);
1720
+ if (!catchall) return payload;
1721
+ return handleCatchall([], input, payload, ctx, value, inst);
1722
+ }
1723
+ return superParse(payload, ctx);
1724
+ };
1725
+ });
1726
+ function handleUnionResults(results, final, inst, ctx) {
1727
+ for (const result of results) if (result.issues.length === 0) {
1728
+ final.value = result.value;
1729
+ return final;
1730
+ }
1731
+ const nonaborted = results.filter((r) => !aborted(r));
1732
+ if (nonaborted.length === 1) {
1733
+ final.value = nonaborted[0].value;
1734
+ return nonaborted[0];
1735
+ }
1736
+ final.issues.push({
1737
+ code: "invalid_union",
1738
+ input: final.value,
1739
+ inst,
1740
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
1741
+ });
1742
+ return final;
1743
+ }
1744
+ const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
1745
+ $ZodType.init(inst, def);
1746
+ defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0);
1747
+ defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
1748
+ defineLazy(inst._zod, "values", () => {
1749
+ if (def.options.every((o) => o._zod.values)) return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
1750
+ });
1751
+ defineLazy(inst._zod, "pattern", () => {
1752
+ if (def.options.every((o) => o._zod.pattern)) {
1753
+ const patterns = def.options.map((o) => o._zod.pattern);
1754
+ return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
1755
+ }
1756
+ });
1757
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
1758
+ inst._zod.parse = (payload, ctx) => {
1759
+ if (first) return first(payload, ctx);
1760
+ let async = false;
1761
+ const results = [];
1762
+ for (const option of def.options) {
1763
+ const result = option._zod.run({
1764
+ value: payload.value,
1765
+ issues: []
1766
+ }, ctx);
1767
+ if (result instanceof Promise) {
1768
+ results.push(result);
1769
+ async = true;
1770
+ } else {
1771
+ if (result.issues.length === 0) return result;
1772
+ results.push(result);
1773
+ }
1774
+ }
1775
+ if (!async) return handleUnionResults(results, payload, inst, ctx);
1776
+ return Promise.all(results).then((results) => {
1777
+ return handleUnionResults(results, payload, inst, ctx);
1778
+ });
1779
+ };
1780
+ });
1781
+ const $ZodDiscriminatedUnion = /*@__PURE__*/ $constructor("$ZodDiscriminatedUnion", (inst, def) => {
1782
+ def.inclusive = false;
1783
+ $ZodUnion.init(inst, def);
1784
+ const _super = inst._zod.parse;
1785
+ defineLazy(inst._zod, "propValues", () => {
1786
+ const propValues = {};
1787
+ for (const option of def.options) {
1788
+ const pv = option._zod.propValues;
1789
+ if (!pv || Object.keys(pv).length === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
1790
+ for (const [k, v] of Object.entries(pv)) {
1791
+ if (!propValues[k]) propValues[k] = /* @__PURE__ */ new Set();
1792
+ for (const val of v) propValues[k].add(val);
1793
+ }
1794
+ }
1795
+ return propValues;
1796
+ });
1797
+ const disc = cached(() => {
1798
+ const opts = def.options;
1799
+ const map = /* @__PURE__ */ new Map();
1800
+ for (const o of opts) {
1801
+ const values = o._zod.propValues?.[def.discriminator];
1802
+ if (!values || values.size === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
1803
+ for (const v of values) {
1804
+ if (map.has(v)) throw new Error(`Duplicate discriminator value "${String(v)}"`);
1805
+ map.set(v, o);
1806
+ }
1807
+ }
1808
+ return map;
1809
+ });
1810
+ inst._zod.parse = (payload, ctx) => {
1811
+ const input = payload.value;
1812
+ if (!isObject(input)) {
1813
+ payload.issues.push({
1814
+ code: "invalid_type",
1815
+ expected: "object",
1816
+ input,
1817
+ inst
1818
+ });
1819
+ return payload;
1820
+ }
1821
+ const opt = disc.value.get(input?.[def.discriminator]);
1822
+ if (opt) return opt._zod.run(payload, ctx);
1823
+ if (def.unionFallback || ctx.direction === "backward") return _super(payload, ctx);
1824
+ payload.issues.push({
1825
+ code: "invalid_union",
1826
+ errors: [],
1827
+ note: "No matching discriminator",
1828
+ discriminator: def.discriminator,
1829
+ options: Array.from(disc.value.keys()),
1830
+ input,
1831
+ path: [def.discriminator],
1832
+ inst
1833
+ });
1834
+ return payload;
1835
+ };
1836
+ });
1837
+ const $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
1838
+ $ZodType.init(inst, def);
1839
+ inst._zod.parse = (payload, ctx) => {
1840
+ const input = payload.value;
1841
+ const left = def.left._zod.run({
1842
+ value: input,
1843
+ issues: []
1844
+ }, ctx);
1845
+ const right = def.right._zod.run({
1846
+ value: input,
1847
+ issues: []
1848
+ }, ctx);
1849
+ if (left instanceof Promise || right instanceof Promise) return Promise.all([left, right]).then(([left, right]) => {
1850
+ return handleIntersectionResults(payload, left, right);
1851
+ });
1852
+ return handleIntersectionResults(payload, left, right);
1853
+ };
1854
+ });
1855
+ function mergeValues(a, b) {
1856
+ if (a === b) return {
1857
+ valid: true,
1858
+ data: a
1859
+ };
1860
+ if (a instanceof Date && b instanceof Date && +a === +b) return {
1861
+ valid: true,
1862
+ data: a
1863
+ };
1864
+ if (isPlainObject(a) && isPlainObject(b)) {
1865
+ const bKeys = Object.keys(b);
1866
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
1867
+ const newObj = {
1868
+ ...a,
1869
+ ...b
1870
+ };
1871
+ for (const key of sharedKeys) {
1872
+ const sharedValue = mergeValues(a[key], b[key]);
1873
+ if (!sharedValue.valid) return {
1874
+ valid: false,
1875
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
1876
+ };
1877
+ newObj[key] = sharedValue.data;
1878
+ }
1879
+ return {
1880
+ valid: true,
1881
+ data: newObj
1882
+ };
1883
+ }
1884
+ if (Array.isArray(a) && Array.isArray(b)) {
1885
+ if (a.length !== b.length) return {
1886
+ valid: false,
1887
+ mergeErrorPath: []
1888
+ };
1889
+ const newArray = [];
1890
+ for (let index = 0; index < a.length; index++) {
1891
+ const itemA = a[index];
1892
+ const itemB = b[index];
1893
+ const sharedValue = mergeValues(itemA, itemB);
1894
+ if (!sharedValue.valid) return {
1895
+ valid: false,
1896
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
1897
+ };
1898
+ newArray.push(sharedValue.data);
1899
+ }
1900
+ return {
1901
+ valid: true,
1902
+ data: newArray
1903
+ };
1904
+ }
1905
+ return {
1906
+ valid: false,
1907
+ mergeErrorPath: []
1908
+ };
1909
+ }
1910
+ function handleIntersectionResults(result, left, right) {
1911
+ const unrecKeys = /* @__PURE__ */ new Map();
1912
+ let unrecIssue;
1913
+ for (const iss of left.issues) if (iss.code === "unrecognized_keys") {
1914
+ unrecIssue ?? (unrecIssue = iss);
1915
+ for (const k of iss.keys) {
1916
+ if (!unrecKeys.has(k)) unrecKeys.set(k, {});
1917
+ unrecKeys.get(k).l = true;
1918
+ }
1919
+ } else result.issues.push(iss);
1920
+ for (const iss of right.issues) if (iss.code === "unrecognized_keys") for (const k of iss.keys) {
1921
+ if (!unrecKeys.has(k)) unrecKeys.set(k, {});
1922
+ unrecKeys.get(k).r = true;
1923
+ }
1924
+ else result.issues.push(iss);
1925
+ const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
1926
+ if (bothKeys.length && unrecIssue) result.issues.push({
1927
+ ...unrecIssue,
1928
+ keys: bothKeys
1929
+ });
1930
+ if (aborted(result)) return result;
1931
+ const merged = mergeValues(left.value, right.value);
1932
+ if (!merged.valid) throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
1933
+ result.value = merged.data;
1934
+ return result;
1935
+ }
1936
+ const $ZodEnum = /*@__PURE__*/ $constructor("$ZodEnum", (inst, def) => {
1937
+ $ZodType.init(inst, def);
1938
+ const values = getEnumValues(def.entries);
1939
+ const valuesSet = new Set(values);
1940
+ inst._zod.values = valuesSet;
1941
+ inst._zod.pattern = new RegExp(`^(${values.filter((k) => propertyKeyTypes.has(typeof k)).map((o) => typeof o === "string" ? escapeRegex(o) : o.toString()).join("|")})$`);
1942
+ inst._zod.parse = (payload, _ctx) => {
1943
+ const input = payload.value;
1944
+ if (valuesSet.has(input)) return payload;
1945
+ payload.issues.push({
1946
+ code: "invalid_value",
1947
+ values,
1948
+ input,
1949
+ inst
1950
+ });
1951
+ return payload;
1952
+ };
1953
+ });
1954
+ const $ZodLiteral = /*@__PURE__*/ $constructor("$ZodLiteral", (inst, def) => {
1955
+ $ZodType.init(inst, def);
1956
+ if (def.values.length === 0) throw new Error("Cannot create literal schema with no valid values");
1957
+ const values = new Set(def.values);
1958
+ inst._zod.values = values;
1959
+ inst._zod.pattern = new RegExp(`^(${def.values.map((o) => typeof o === "string" ? escapeRegex(o) : o ? escapeRegex(o.toString()) : String(o)).join("|")})$`);
1960
+ inst._zod.parse = (payload, _ctx) => {
1961
+ const input = payload.value;
1962
+ if (values.has(input)) return payload;
1963
+ payload.issues.push({
1964
+ code: "invalid_value",
1965
+ values: def.values,
1966
+ input,
1967
+ inst
1968
+ });
1969
+ return payload;
1970
+ };
1971
+ });
1972
+ const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def) => {
1973
+ $ZodType.init(inst, def);
1974
+ inst._zod.optin = "optional";
1975
+ inst._zod.parse = (payload, ctx) => {
1976
+ if (ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
1977
+ const _out = def.transform(payload.value, payload);
1978
+ if (ctx.async) return (_out instanceof Promise ? _out : Promise.resolve(_out)).then((output) => {
1979
+ payload.value = output;
1980
+ payload.fallback = true;
1981
+ return payload;
1982
+ });
1983
+ if (_out instanceof Promise) throw new $ZodAsyncError();
1984
+ payload.value = _out;
1985
+ payload.fallback = true;
1986
+ return payload;
1987
+ };
1988
+ });
1989
+ function handleOptionalResult(result, input) {
1990
+ if (input === void 0 && (result.issues.length || result.fallback)) return {
1991
+ issues: [],
1992
+ value: void 0
1993
+ };
1994
+ return result;
1995
+ }
1996
+ const $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def) => {
1997
+ $ZodType.init(inst, def);
1998
+ inst._zod.optin = "optional";
1999
+ inst._zod.optout = "optional";
2000
+ defineLazy(inst._zod, "values", () => {
2001
+ return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, void 0]) : void 0;
2002
+ });
2003
+ defineLazy(inst._zod, "pattern", () => {
2004
+ const pattern = def.innerType._zod.pattern;
2005
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
2006
+ });
2007
+ inst._zod.parse = (payload, ctx) => {
2008
+ if (def.innerType._zod.optin === "optional") {
2009
+ const input = payload.value;
2010
+ const result = def.innerType._zod.run(payload, ctx);
2011
+ if (result instanceof Promise) return result.then((r) => handleOptionalResult(r, input));
2012
+ return handleOptionalResult(result, input);
2013
+ }
2014
+ if (payload.value === void 0) return payload;
2015
+ return def.innerType._zod.run(payload, ctx);
2016
+ };
2017
+ });
2018
+ const $ZodExactOptional = /*@__PURE__*/ $constructor("$ZodExactOptional", (inst, def) => {
2019
+ $ZodOptional.init(inst, def);
2020
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2021
+ defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
2022
+ inst._zod.parse = (payload, ctx) => {
2023
+ return def.innerType._zod.run(payload, ctx);
2024
+ };
2025
+ });
2026
+ const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def) => {
2027
+ $ZodType.init(inst, def);
2028
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
2029
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
2030
+ defineLazy(inst._zod, "pattern", () => {
2031
+ const pattern = def.innerType._zod.pattern;
2032
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
2033
+ });
2034
+ defineLazy(inst._zod, "values", () => {
2035
+ return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, null]) : void 0;
2036
+ });
2037
+ inst._zod.parse = (payload, ctx) => {
2038
+ if (payload.value === null) return payload;
2039
+ return def.innerType._zod.run(payload, ctx);
2040
+ };
2041
+ });
2042
+ const $ZodDefault = /*@__PURE__*/ $constructor("$ZodDefault", (inst, def) => {
2043
+ $ZodType.init(inst, def);
2044
+ inst._zod.optin = "optional";
2045
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2046
+ inst._zod.parse = (payload, ctx) => {
2047
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
2048
+ if (payload.value === void 0) {
2049
+ payload.value = def.defaultValue;
2050
+ /**
2051
+ * $ZodDefault returns the default value immediately in forward direction.
2052
+ * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
2053
+ return payload;
2054
+ }
2055
+ const result = def.innerType._zod.run(payload, ctx);
2056
+ if (result instanceof Promise) return result.then((result) => handleDefaultResult(result, def));
2057
+ return handleDefaultResult(result, def);
2058
+ };
2059
+ });
2060
+ function handleDefaultResult(payload, def) {
2061
+ if (payload.value === void 0) payload.value = def.defaultValue;
2062
+ return payload;
2063
+ }
2064
+ const $ZodPrefault = /*@__PURE__*/ $constructor("$ZodPrefault", (inst, def) => {
2065
+ $ZodType.init(inst, def);
2066
+ inst._zod.optin = "optional";
2067
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2068
+ inst._zod.parse = (payload, ctx) => {
2069
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
2070
+ if (payload.value === void 0) payload.value = def.defaultValue;
2071
+ return def.innerType._zod.run(payload, ctx);
2072
+ };
2073
+ });
2074
+ const $ZodNonOptional = /*@__PURE__*/ $constructor("$ZodNonOptional", (inst, def) => {
2075
+ $ZodType.init(inst, def);
2076
+ defineLazy(inst._zod, "values", () => {
2077
+ const v = def.innerType._zod.values;
2078
+ return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
2079
+ });
2080
+ inst._zod.parse = (payload, ctx) => {
2081
+ const result = def.innerType._zod.run(payload, ctx);
2082
+ if (result instanceof Promise) return result.then((result) => handleNonOptionalResult(result, inst));
2083
+ return handleNonOptionalResult(result, inst);
2084
+ };
2085
+ });
2086
+ function handleNonOptionalResult(payload, inst) {
2087
+ if (!payload.issues.length && payload.value === void 0) payload.issues.push({
2088
+ code: "invalid_type",
2089
+ expected: "nonoptional",
2090
+ input: payload.value,
2091
+ inst
2092
+ });
2093
+ return payload;
2094
+ }
2095
+ const $ZodCatch = /*@__PURE__*/ $constructor("$ZodCatch", (inst, def) => {
2096
+ $ZodType.init(inst, def);
2097
+ inst._zod.optin = "optional";
2098
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
2099
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2100
+ inst._zod.parse = (payload, ctx) => {
2101
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
2102
+ const result = def.innerType._zod.run(payload, ctx);
2103
+ if (result instanceof Promise) return result.then((result) => {
2104
+ payload.value = result.value;
2105
+ if (result.issues.length) {
2106
+ payload.value = def.catchValue({
2107
+ ...payload,
2108
+ error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
2109
+ input: payload.value
2110
+ });
2111
+ payload.issues = [];
2112
+ payload.fallback = true;
2113
+ }
2114
+ return payload;
2115
+ });
2116
+ payload.value = result.value;
2117
+ if (result.issues.length) {
2118
+ payload.value = def.catchValue({
2119
+ ...payload,
2120
+ error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
2121
+ input: payload.value
2122
+ });
2123
+ payload.issues = [];
2124
+ payload.fallback = true;
2125
+ }
2126
+ return payload;
2127
+ };
2128
+ });
2129
+ const $ZodPipe = /*@__PURE__*/ $constructor("$ZodPipe", (inst, def) => {
2130
+ $ZodType.init(inst, def);
2131
+ defineLazy(inst._zod, "values", () => def.in._zod.values);
2132
+ defineLazy(inst._zod, "optin", () => def.in._zod.optin);
2133
+ defineLazy(inst._zod, "optout", () => def.out._zod.optout);
2134
+ defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
2135
+ inst._zod.parse = (payload, ctx) => {
2136
+ if (ctx.direction === "backward") {
2137
+ const right = def.out._zod.run(payload, ctx);
2138
+ if (right instanceof Promise) return right.then((right) => handlePipeResult(right, def.in, ctx));
2139
+ return handlePipeResult(right, def.in, ctx);
2140
+ }
2141
+ const left = def.in._zod.run(payload, ctx);
2142
+ if (left instanceof Promise) return left.then((left) => handlePipeResult(left, def.out, ctx));
2143
+ return handlePipeResult(left, def.out, ctx);
2144
+ };
2145
+ });
2146
+ function handlePipeResult(left, next, ctx) {
2147
+ if (left.issues.length) {
2148
+ left.aborted = true;
2149
+ return left;
2150
+ }
2151
+ return next._zod.run({
2152
+ value: left.value,
2153
+ issues: left.issues,
2154
+ fallback: left.fallback
2155
+ }, ctx);
2156
+ }
2157
+ const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
2158
+ $ZodType.init(inst, def);
2159
+ defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
2160
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2161
+ defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
2162
+ defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
2163
+ inst._zod.parse = (payload, ctx) => {
2164
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
2165
+ const result = def.innerType._zod.run(payload, ctx);
2166
+ if (result instanceof Promise) return result.then(handleReadonlyResult);
2167
+ return handleReadonlyResult(result);
2168
+ };
2169
+ });
2170
+ function handleReadonlyResult(payload) {
2171
+ payload.value = Object.freeze(payload.value);
2172
+ return payload;
2173
+ }
2174
+ const $ZodCustom = /*@__PURE__*/ $constructor("$ZodCustom", (inst, def) => {
2175
+ $ZodCheck.init(inst, def);
2176
+ $ZodType.init(inst, def);
2177
+ inst._zod.parse = (payload, _) => {
2178
+ return payload;
2179
+ };
2180
+ inst._zod.check = (payload) => {
2181
+ const input = payload.value;
2182
+ const r = def.fn(input);
2183
+ if (r instanceof Promise) return r.then((r) => handleRefineResult(r, payload, input, inst));
2184
+ handleRefineResult(r, payload, input, inst);
2185
+ };
2186
+ });
2187
+ function handleRefineResult(result, payload, input, inst) {
2188
+ if (!result) {
2189
+ const _iss = {
2190
+ code: "custom",
2191
+ input,
2192
+ inst,
2193
+ path: [...inst._zod.def.path ?? []],
2194
+ continue: !inst._zod.def.abort
2195
+ };
2196
+ if (inst._zod.def.params) _iss.params = inst._zod.def.params;
2197
+ payload.issues.push(issue(_iss));
2198
+ }
2199
+ }
2200
+ //#endregion
2201
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/registries.js
2202
+ var _a;
2203
+ var $ZodRegistry = class {
2204
+ constructor() {
2205
+ this._map = /* @__PURE__ */ new WeakMap();
2206
+ this._idmap = /* @__PURE__ */ new Map();
2207
+ }
2208
+ add(schema, ..._meta) {
2209
+ const meta = _meta[0];
2210
+ this._map.set(schema, meta);
2211
+ if (meta && typeof meta === "object" && "id" in meta) this._idmap.set(meta.id, schema);
2212
+ return this;
2213
+ }
2214
+ clear() {
2215
+ this._map = /* @__PURE__ */ new WeakMap();
2216
+ this._idmap = /* @__PURE__ */ new Map();
2217
+ return this;
2218
+ }
2219
+ remove(schema) {
2220
+ const meta = this._map.get(schema);
2221
+ if (meta && typeof meta === "object" && "id" in meta) this._idmap.delete(meta.id);
2222
+ this._map.delete(schema);
2223
+ return this;
2224
+ }
2225
+ get(schema) {
2226
+ const p = schema._zod.parent;
2227
+ if (p) {
2228
+ const pm = { ...this.get(p) ?? {} };
2229
+ delete pm.id;
2230
+ const f = {
2231
+ ...pm,
2232
+ ...this._map.get(schema)
2233
+ };
2234
+ return Object.keys(f).length ? f : void 0;
2235
+ }
2236
+ return this._map.get(schema);
2237
+ }
2238
+ has(schema) {
2239
+ return this._map.has(schema);
2240
+ }
2241
+ };
2242
+ function registry() {
2243
+ return new $ZodRegistry();
2244
+ }
2245
+ (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
2246
+ const globalRegistry = globalThis.__zod_globalRegistry;
2247
+ //#endregion
2248
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/api.js
2249
+ // @__NO_SIDE_EFFECTS__
2250
+ function _string(Class, params) {
2251
+ return new Class({
2252
+ type: "string",
2253
+ ...normalizeParams(params)
2254
+ });
2255
+ }
2256
+ // @__NO_SIDE_EFFECTS__
2257
+ function _email(Class, params) {
2258
+ return new Class({
2259
+ type: "string",
2260
+ format: "email",
2261
+ check: "string_format",
2262
+ abort: false,
2263
+ ...normalizeParams(params)
2264
+ });
2265
+ }
2266
+ // @__NO_SIDE_EFFECTS__
2267
+ function _guid(Class, params) {
2268
+ return new Class({
2269
+ type: "string",
2270
+ format: "guid",
2271
+ check: "string_format",
2272
+ abort: false,
2273
+ ...normalizeParams(params)
2274
+ });
2275
+ }
2276
+ // @__NO_SIDE_EFFECTS__
2277
+ function _uuid(Class, params) {
2278
+ return new Class({
2279
+ type: "string",
2280
+ format: "uuid",
2281
+ check: "string_format",
2282
+ abort: false,
2283
+ ...normalizeParams(params)
2284
+ });
2285
+ }
2286
+ // @__NO_SIDE_EFFECTS__
2287
+ function _uuidv4(Class, params) {
2288
+ return new Class({
2289
+ type: "string",
2290
+ format: "uuid",
2291
+ check: "string_format",
2292
+ abort: false,
2293
+ version: "v4",
2294
+ ...normalizeParams(params)
2295
+ });
2296
+ }
2297
+ // @__NO_SIDE_EFFECTS__
2298
+ function _uuidv6(Class, params) {
2299
+ return new Class({
2300
+ type: "string",
2301
+ format: "uuid",
2302
+ check: "string_format",
2303
+ abort: false,
2304
+ version: "v6",
2305
+ ...normalizeParams(params)
2306
+ });
2307
+ }
2308
+ // @__NO_SIDE_EFFECTS__
2309
+ function _uuidv7(Class, params) {
2310
+ return new Class({
2311
+ type: "string",
2312
+ format: "uuid",
2313
+ check: "string_format",
2314
+ abort: false,
2315
+ version: "v7",
2316
+ ...normalizeParams(params)
2317
+ });
2318
+ }
2319
+ // @__NO_SIDE_EFFECTS__
2320
+ function _url(Class, params) {
2321
+ return new Class({
2322
+ type: "string",
2323
+ format: "url",
2324
+ check: "string_format",
2325
+ abort: false,
2326
+ ...normalizeParams(params)
2327
+ });
2328
+ }
2329
+ // @__NO_SIDE_EFFECTS__
2330
+ function _emoji(Class, params) {
2331
+ return new Class({
2332
+ type: "string",
2333
+ format: "emoji",
2334
+ check: "string_format",
2335
+ abort: false,
2336
+ ...normalizeParams(params)
2337
+ });
2338
+ }
2339
+ // @__NO_SIDE_EFFECTS__
2340
+ function _nanoid(Class, params) {
2341
+ return new Class({
2342
+ type: "string",
2343
+ format: "nanoid",
2344
+ check: "string_format",
2345
+ abort: false,
2346
+ ...normalizeParams(params)
2347
+ });
2348
+ }
2349
+ /**
2350
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
2351
+ * (timestamps embedded in the id). Use {@link _cuid2} instead.
2352
+ * See https://github.com/paralleldrive/cuid.
2353
+ */
2354
+ // @__NO_SIDE_EFFECTS__
2355
+ function _cuid(Class, params) {
2356
+ return new Class({
2357
+ type: "string",
2358
+ format: "cuid",
2359
+ check: "string_format",
2360
+ abort: false,
2361
+ ...normalizeParams(params)
2362
+ });
2363
+ }
2364
+ // @__NO_SIDE_EFFECTS__
2365
+ function _cuid2(Class, params) {
2366
+ return new Class({
2367
+ type: "string",
2368
+ format: "cuid2",
2369
+ check: "string_format",
2370
+ abort: false,
2371
+ ...normalizeParams(params)
2372
+ });
2373
+ }
2374
+ // @__NO_SIDE_EFFECTS__
2375
+ function _ulid(Class, params) {
2376
+ return new Class({
2377
+ type: "string",
2378
+ format: "ulid",
2379
+ check: "string_format",
2380
+ abort: false,
2381
+ ...normalizeParams(params)
2382
+ });
2383
+ }
2384
+ // @__NO_SIDE_EFFECTS__
2385
+ function _xid(Class, params) {
2386
+ return new Class({
2387
+ type: "string",
2388
+ format: "xid",
2389
+ check: "string_format",
2390
+ abort: false,
2391
+ ...normalizeParams(params)
2392
+ });
2393
+ }
2394
+ // @__NO_SIDE_EFFECTS__
2395
+ function _ksuid(Class, params) {
2396
+ return new Class({
2397
+ type: "string",
2398
+ format: "ksuid",
2399
+ check: "string_format",
2400
+ abort: false,
2401
+ ...normalizeParams(params)
2402
+ });
2403
+ }
2404
+ // @__NO_SIDE_EFFECTS__
2405
+ function _ipv4(Class, params) {
2406
+ return new Class({
2407
+ type: "string",
2408
+ format: "ipv4",
2409
+ check: "string_format",
2410
+ abort: false,
2411
+ ...normalizeParams(params)
2412
+ });
2413
+ }
2414
+ // @__NO_SIDE_EFFECTS__
2415
+ function _ipv6(Class, params) {
2416
+ return new Class({
2417
+ type: "string",
2418
+ format: "ipv6",
2419
+ check: "string_format",
2420
+ abort: false,
2421
+ ...normalizeParams(params)
2422
+ });
2423
+ }
2424
+ // @__NO_SIDE_EFFECTS__
2425
+ function _cidrv4(Class, params) {
2426
+ return new Class({
2427
+ type: "string",
2428
+ format: "cidrv4",
2429
+ check: "string_format",
2430
+ abort: false,
2431
+ ...normalizeParams(params)
2432
+ });
2433
+ }
2434
+ // @__NO_SIDE_EFFECTS__
2435
+ function _cidrv6(Class, params) {
2436
+ return new Class({
2437
+ type: "string",
2438
+ format: "cidrv6",
2439
+ check: "string_format",
2440
+ abort: false,
2441
+ ...normalizeParams(params)
2442
+ });
2443
+ }
2444
+ // @__NO_SIDE_EFFECTS__
2445
+ function _base64(Class, params) {
2446
+ return new Class({
2447
+ type: "string",
2448
+ format: "base64",
2449
+ check: "string_format",
2450
+ abort: false,
2451
+ ...normalizeParams(params)
2452
+ });
2453
+ }
2454
+ // @__NO_SIDE_EFFECTS__
2455
+ function _base64url(Class, params) {
2456
+ return new Class({
2457
+ type: "string",
2458
+ format: "base64url",
2459
+ check: "string_format",
2460
+ abort: false,
2461
+ ...normalizeParams(params)
2462
+ });
2463
+ }
2464
+ // @__NO_SIDE_EFFECTS__
2465
+ function _e164(Class, params) {
2466
+ return new Class({
2467
+ type: "string",
2468
+ format: "e164",
2469
+ check: "string_format",
2470
+ abort: false,
2471
+ ...normalizeParams(params)
2472
+ });
2473
+ }
2474
+ // @__NO_SIDE_EFFECTS__
2475
+ function _jwt(Class, params) {
2476
+ return new Class({
2477
+ type: "string",
2478
+ format: "jwt",
2479
+ check: "string_format",
2480
+ abort: false,
2481
+ ...normalizeParams(params)
2482
+ });
2483
+ }
2484
+ // @__NO_SIDE_EFFECTS__
2485
+ function _isoDateTime(Class, params) {
2486
+ return new Class({
2487
+ type: "string",
2488
+ format: "datetime",
2489
+ check: "string_format",
2490
+ offset: false,
2491
+ local: false,
2492
+ precision: null,
2493
+ ...normalizeParams(params)
2494
+ });
2495
+ }
2496
+ // @__NO_SIDE_EFFECTS__
2497
+ function _isoDate(Class, params) {
2498
+ return new Class({
2499
+ type: "string",
2500
+ format: "date",
2501
+ check: "string_format",
2502
+ ...normalizeParams(params)
2503
+ });
2504
+ }
2505
+ // @__NO_SIDE_EFFECTS__
2506
+ function _isoTime(Class, params) {
2507
+ return new Class({
2508
+ type: "string",
2509
+ format: "time",
2510
+ check: "string_format",
2511
+ precision: null,
2512
+ ...normalizeParams(params)
2513
+ });
2514
+ }
2515
+ // @__NO_SIDE_EFFECTS__
2516
+ function _isoDuration(Class, params) {
2517
+ return new Class({
2518
+ type: "string",
2519
+ format: "duration",
2520
+ check: "string_format",
2521
+ ...normalizeParams(params)
2522
+ });
2523
+ }
2524
+ // @__NO_SIDE_EFFECTS__
2525
+ function _number(Class, params) {
2526
+ return new Class({
2527
+ type: "number",
2528
+ checks: [],
2529
+ ...normalizeParams(params)
2530
+ });
2531
+ }
2532
+ // @__NO_SIDE_EFFECTS__
2533
+ function _int(Class, params) {
2534
+ return new Class({
2535
+ type: "number",
2536
+ check: "number_format",
2537
+ abort: false,
2538
+ format: "safeint",
2539
+ ...normalizeParams(params)
2540
+ });
2541
+ }
2542
+ // @__NO_SIDE_EFFECTS__
2543
+ function _boolean(Class, params) {
2544
+ return new Class({
2545
+ type: "boolean",
2546
+ ...normalizeParams(params)
2547
+ });
2548
+ }
2549
+ // @__NO_SIDE_EFFECTS__
2550
+ function _unknown(Class) {
2551
+ return new Class({ type: "unknown" });
2552
+ }
2553
+ // @__NO_SIDE_EFFECTS__
2554
+ function _never(Class, params) {
2555
+ return new Class({
2556
+ type: "never",
2557
+ ...normalizeParams(params)
2558
+ });
2559
+ }
2560
+ // @__NO_SIDE_EFFECTS__
2561
+ function _lt(value, params) {
2562
+ return new $ZodCheckLessThan({
2563
+ check: "less_than",
2564
+ ...normalizeParams(params),
2565
+ value,
2566
+ inclusive: false
2567
+ });
2568
+ }
2569
+ // @__NO_SIDE_EFFECTS__
2570
+ function _lte(value, params) {
2571
+ return new $ZodCheckLessThan({
2572
+ check: "less_than",
2573
+ ...normalizeParams(params),
2574
+ value,
2575
+ inclusive: true
2576
+ });
2577
+ }
2578
+ // @__NO_SIDE_EFFECTS__
2579
+ function _gt(value, params) {
2580
+ return new $ZodCheckGreaterThan({
2581
+ check: "greater_than",
2582
+ ...normalizeParams(params),
2583
+ value,
2584
+ inclusive: false
2585
+ });
2586
+ }
2587
+ // @__NO_SIDE_EFFECTS__
2588
+ function _gte(value, params) {
2589
+ return new $ZodCheckGreaterThan({
2590
+ check: "greater_than",
2591
+ ...normalizeParams(params),
2592
+ value,
2593
+ inclusive: true
2594
+ });
2595
+ }
2596
+ // @__NO_SIDE_EFFECTS__
2597
+ function _multipleOf(value, params) {
2598
+ return new $ZodCheckMultipleOf({
2599
+ check: "multiple_of",
2600
+ ...normalizeParams(params),
2601
+ value
2602
+ });
2603
+ }
2604
+ // @__NO_SIDE_EFFECTS__
2605
+ function _maxLength(maximum, params) {
2606
+ return new $ZodCheckMaxLength({
2607
+ check: "max_length",
2608
+ ...normalizeParams(params),
2609
+ maximum
2610
+ });
2611
+ }
2612
+ // @__NO_SIDE_EFFECTS__
2613
+ function _minLength(minimum, params) {
2614
+ return new $ZodCheckMinLength({
2615
+ check: "min_length",
2616
+ ...normalizeParams(params),
2617
+ minimum
2618
+ });
2619
+ }
2620
+ // @__NO_SIDE_EFFECTS__
2621
+ function _length(length, params) {
2622
+ return new $ZodCheckLengthEquals({
2623
+ check: "length_equals",
2624
+ ...normalizeParams(params),
2625
+ length
2626
+ });
2627
+ }
2628
+ // @__NO_SIDE_EFFECTS__
2629
+ function _regex(pattern, params) {
2630
+ return new $ZodCheckRegex({
2631
+ check: "string_format",
2632
+ format: "regex",
2633
+ ...normalizeParams(params),
2634
+ pattern
2635
+ });
2636
+ }
2637
+ // @__NO_SIDE_EFFECTS__
2638
+ function _lowercase(params) {
2639
+ return new $ZodCheckLowerCase({
2640
+ check: "string_format",
2641
+ format: "lowercase",
2642
+ ...normalizeParams(params)
2643
+ });
2644
+ }
2645
+ // @__NO_SIDE_EFFECTS__
2646
+ function _uppercase(params) {
2647
+ return new $ZodCheckUpperCase({
2648
+ check: "string_format",
2649
+ format: "uppercase",
2650
+ ...normalizeParams(params)
2651
+ });
2652
+ }
2653
+ // @__NO_SIDE_EFFECTS__
2654
+ function _includes(includes, params) {
2655
+ return new $ZodCheckIncludes({
2656
+ check: "string_format",
2657
+ format: "includes",
2658
+ ...normalizeParams(params),
2659
+ includes
2660
+ });
2661
+ }
2662
+ // @__NO_SIDE_EFFECTS__
2663
+ function _startsWith(prefix, params) {
2664
+ return new $ZodCheckStartsWith({
2665
+ check: "string_format",
2666
+ format: "starts_with",
2667
+ ...normalizeParams(params),
2668
+ prefix
2669
+ });
2670
+ }
2671
+ // @__NO_SIDE_EFFECTS__
2672
+ function _endsWith(suffix, params) {
2673
+ return new $ZodCheckEndsWith({
2674
+ check: "string_format",
2675
+ format: "ends_with",
2676
+ ...normalizeParams(params),
2677
+ suffix
2678
+ });
2679
+ }
2680
+ // @__NO_SIDE_EFFECTS__
2681
+ function _overwrite(tx) {
2682
+ return new $ZodCheckOverwrite({
2683
+ check: "overwrite",
2684
+ tx
2685
+ });
2686
+ }
2687
+ // @__NO_SIDE_EFFECTS__
2688
+ function _normalize(form) {
2689
+ return /* @__PURE__ */ _overwrite((input) => input.normalize(form));
2690
+ }
2691
+ // @__NO_SIDE_EFFECTS__
2692
+ function _trim() {
2693
+ return /* @__PURE__ */ _overwrite((input) => input.trim());
2694
+ }
2695
+ // @__NO_SIDE_EFFECTS__
2696
+ function _toLowerCase() {
2697
+ return /* @__PURE__ */ _overwrite((input) => input.toLowerCase());
2698
+ }
2699
+ // @__NO_SIDE_EFFECTS__
2700
+ function _toUpperCase() {
2701
+ return /* @__PURE__ */ _overwrite((input) => input.toUpperCase());
2702
+ }
2703
+ // @__NO_SIDE_EFFECTS__
2704
+ function _slugify() {
2705
+ return /* @__PURE__ */ _overwrite((input) => slugify(input));
2706
+ }
2707
+ // @__NO_SIDE_EFFECTS__
2708
+ function _array(Class, element, params) {
2709
+ return new Class({
2710
+ type: "array",
2711
+ element,
2712
+ ...normalizeParams(params)
2713
+ });
2714
+ }
2715
+ // @__NO_SIDE_EFFECTS__
2716
+ function _refine(Class, fn, _params) {
2717
+ return new Class({
2718
+ type: "custom",
2719
+ check: "custom",
2720
+ fn,
2721
+ ...normalizeParams(_params)
2722
+ });
2723
+ }
2724
+ // @__NO_SIDE_EFFECTS__
2725
+ function _superRefine(fn, params) {
2726
+ const ch = /* @__PURE__ */ _check((payload) => {
2727
+ payload.addIssue = (issue$2) => {
2728
+ if (typeof issue$2 === "string") payload.issues.push(issue(issue$2, payload.value, ch._zod.def));
2729
+ else {
2730
+ const _issue = issue$2;
2731
+ if (_issue.fatal) _issue.continue = false;
2732
+ _issue.code ?? (_issue.code = "custom");
2733
+ _issue.input ?? (_issue.input = payload.value);
2734
+ _issue.inst ?? (_issue.inst = ch);
2735
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
2736
+ payload.issues.push(issue(_issue));
2737
+ }
2738
+ };
2739
+ return fn(payload.value, payload);
2740
+ }, params);
2741
+ return ch;
2742
+ }
2743
+ // @__NO_SIDE_EFFECTS__
2744
+ function _check(fn, params) {
2745
+ const ch = new $ZodCheck({
2746
+ check: "custom",
2747
+ ...normalizeParams(params)
2748
+ });
2749
+ ch._zod.check = fn;
2750
+ return ch;
2751
+ }
2752
+ //#endregion
2753
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/to-json-schema.js
2754
+ function initializeContext(params) {
2755
+ let target = params?.target ?? "draft-2020-12";
2756
+ if (target === "draft-4") target = "draft-04";
2757
+ if (target === "draft-7") target = "draft-07";
2758
+ return {
2759
+ processors: params.processors ?? {},
2760
+ metadataRegistry: params?.metadata ?? globalRegistry,
2761
+ target,
2762
+ unrepresentable: params?.unrepresentable ?? "throw",
2763
+ override: params?.override ?? (() => {}),
2764
+ io: params?.io ?? "output",
2765
+ counter: 0,
2766
+ seen: /* @__PURE__ */ new Map(),
2767
+ cycles: params?.cycles ?? "ref",
2768
+ reused: params?.reused ?? "inline",
2769
+ external: params?.external ?? void 0
2770
+ };
2771
+ }
2772
+ function process$1(schema, ctx, _params = {
2773
+ path: [],
2774
+ schemaPath: []
2775
+ }) {
2776
+ var _a;
2777
+ const def = schema._zod.def;
2778
+ const seen = ctx.seen.get(schema);
2779
+ if (seen) {
2780
+ seen.count++;
2781
+ if (_params.schemaPath.includes(schema)) seen.cycle = _params.path;
2782
+ return seen.schema;
2783
+ }
2784
+ const result = {
2785
+ schema: {},
2786
+ count: 1,
2787
+ cycle: void 0,
2788
+ path: _params.path
2789
+ };
2790
+ ctx.seen.set(schema, result);
2791
+ const overrideSchema = schema._zod.toJSONSchema?.();
2792
+ if (overrideSchema) result.schema = overrideSchema;
2793
+ else {
2794
+ const params = {
2795
+ ..._params,
2796
+ schemaPath: [..._params.schemaPath, schema],
2797
+ path: _params.path
2798
+ };
2799
+ if (schema._zod.processJSONSchema) schema._zod.processJSONSchema(ctx, result.schema, params);
2800
+ else {
2801
+ const _json = result.schema;
2802
+ const processor = ctx.processors[def.type];
2803
+ if (!processor) throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
2804
+ processor(schema, ctx, _json, params);
2805
+ }
2806
+ const parent = schema._zod.parent;
2807
+ if (parent) {
2808
+ if (!result.ref) result.ref = parent;
2809
+ process$1(parent, ctx, params);
2810
+ ctx.seen.get(parent).isParent = true;
2811
+ }
2812
+ }
2813
+ const meta = ctx.metadataRegistry.get(schema);
2814
+ if (meta) Object.assign(result.schema, meta);
2815
+ if (ctx.io === "input" && isTransforming(schema)) {
2816
+ delete result.schema.examples;
2817
+ delete result.schema.default;
2818
+ }
2819
+ if (ctx.io === "input" && "_prefault" in result.schema) (_a = result.schema).default ?? (_a.default = result.schema._prefault);
2820
+ delete result.schema._prefault;
2821
+ return ctx.seen.get(schema).schema;
2822
+ }
2823
+ function extractDefs(ctx, schema) {
2824
+ const root = ctx.seen.get(schema);
2825
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
2826
+ const idToSchema = /* @__PURE__ */ new Map();
2827
+ for (const entry of ctx.seen.entries()) {
2828
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
2829
+ if (id) {
2830
+ const existing = idToSchema.get(id);
2831
+ if (existing && existing !== entry[0]) throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
2832
+ idToSchema.set(id, entry[0]);
2833
+ }
2834
+ }
2835
+ const makeURI = (entry) => {
2836
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
2837
+ if (ctx.external) {
2838
+ const externalId = ctx.external.registry.get(entry[0])?.id;
2839
+ const uriGenerator = ctx.external.uri ?? ((id) => id);
2840
+ if (externalId) return { ref: uriGenerator(externalId) };
2841
+ const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
2842
+ entry[1].defId = id;
2843
+ return {
2844
+ defId: id,
2845
+ ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}`
2846
+ };
2847
+ }
2848
+ if (entry[1] === root) return { ref: "#" };
2849
+ const defUriPrefix = `#/${defsSegment}/`;
2850
+ const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
2851
+ return {
2852
+ defId,
2853
+ ref: defUriPrefix + defId
2854
+ };
2855
+ };
2856
+ const extractToDef = (entry) => {
2857
+ if (entry[1].schema.$ref) return;
2858
+ const seen = entry[1];
2859
+ const { ref, defId } = makeURI(entry);
2860
+ seen.def = { ...seen.schema };
2861
+ if (defId) seen.defId = defId;
2862
+ const schema = seen.schema;
2863
+ for (const key in schema) delete schema[key];
2864
+ schema.$ref = ref;
2865
+ };
2866
+ if (ctx.cycles === "throw") for (const entry of ctx.seen.entries()) {
2867
+ const seen = entry[1];
2868
+ if (seen.cycle) throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
2869
+
2870
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
2871
+ }
2872
+ for (const entry of ctx.seen.entries()) {
2873
+ const seen = entry[1];
2874
+ if (schema === entry[0]) {
2875
+ extractToDef(entry);
2876
+ continue;
2877
+ }
2878
+ if (ctx.external) {
2879
+ const ext = ctx.external.registry.get(entry[0])?.id;
2880
+ if (schema !== entry[0] && ext) {
2881
+ extractToDef(entry);
2882
+ continue;
2883
+ }
2884
+ }
2885
+ if (ctx.metadataRegistry.get(entry[0])?.id) {
2886
+ extractToDef(entry);
2887
+ continue;
2888
+ }
2889
+ if (seen.cycle) {
2890
+ extractToDef(entry);
2891
+ continue;
2892
+ }
2893
+ if (seen.count > 1) {
2894
+ if (ctx.reused === "ref") {
2895
+ extractToDef(entry);
2896
+ continue;
2897
+ }
2898
+ }
2899
+ }
2900
+ }
2901
+ function finalize(ctx, schema) {
2902
+ const root = ctx.seen.get(schema);
2903
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
2904
+ const flattenRef = (zodSchema) => {
2905
+ const seen = ctx.seen.get(zodSchema);
2906
+ if (seen.ref === null) return;
2907
+ const schema = seen.def ?? seen.schema;
2908
+ const _cached = { ...schema };
2909
+ const ref = seen.ref;
2910
+ seen.ref = null;
2911
+ if (ref) {
2912
+ flattenRef(ref);
2913
+ const refSeen = ctx.seen.get(ref);
2914
+ const refSchema = refSeen.schema;
2915
+ if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
2916
+ schema.allOf = schema.allOf ?? [];
2917
+ schema.allOf.push(refSchema);
2918
+ } else Object.assign(schema, refSchema);
2919
+ Object.assign(schema, _cached);
2920
+ if (zodSchema._zod.parent === ref) for (const key in schema) {
2921
+ if (key === "$ref" || key === "allOf") continue;
2922
+ if (!(key in _cached)) delete schema[key];
2923
+ }
2924
+ if (refSchema.$ref && refSeen.def) for (const key in schema) {
2925
+ if (key === "$ref" || key === "allOf") continue;
2926
+ if (key in refSeen.def && JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])) delete schema[key];
2927
+ }
2928
+ }
2929
+ const parent = zodSchema._zod.parent;
2930
+ if (parent && parent !== ref) {
2931
+ flattenRef(parent);
2932
+ const parentSeen = ctx.seen.get(parent);
2933
+ if (parentSeen?.schema.$ref) {
2934
+ schema.$ref = parentSeen.schema.$ref;
2935
+ if (parentSeen.def) for (const key in schema) {
2936
+ if (key === "$ref" || key === "allOf") continue;
2937
+ if (key in parentSeen.def && JSON.stringify(schema[key]) === JSON.stringify(parentSeen.def[key])) delete schema[key];
2938
+ }
2939
+ }
2940
+ }
2941
+ ctx.override({
2942
+ zodSchema,
2943
+ jsonSchema: schema,
2944
+ path: seen.path ?? []
2945
+ });
2946
+ };
2947
+ for (const entry of [...ctx.seen.entries()].reverse()) flattenRef(entry[0]);
2948
+ const result = {};
2949
+ if (ctx.target === "draft-2020-12") result.$schema = "https://json-schema.org/draft/2020-12/schema";
2950
+ else if (ctx.target === "draft-07") result.$schema = "http://json-schema.org/draft-07/schema#";
2951
+ else if (ctx.target === "draft-04") result.$schema = "http://json-schema.org/draft-04/schema#";
2952
+ else if (ctx.target === "openapi-3.0") {}
2953
+ if (ctx.external?.uri) {
2954
+ const id = ctx.external.registry.get(schema)?.id;
2955
+ if (!id) throw new Error("Schema is missing an `id` property");
2956
+ result.$id = ctx.external.uri(id);
2957
+ }
2958
+ Object.assign(result, root.def ?? root.schema);
2959
+ const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
2960
+ if (rootMetaId !== void 0 && result.id === rootMetaId) delete result.id;
2961
+ const defs = ctx.external?.defs ?? {};
2962
+ for (const entry of ctx.seen.entries()) {
2963
+ const seen = entry[1];
2964
+ if (seen.def && seen.defId) {
2965
+ if (seen.def.id === seen.defId) delete seen.def.id;
2966
+ defs[seen.defId] = seen.def;
2967
+ }
2968
+ }
2969
+ if (ctx.external) {} else if (Object.keys(defs).length > 0) {
2970
+ if (ctx.target === "draft-2020-12") result.$defs = defs;
2971
+ else result.definitions = defs;
2972
+ }
2973
+ try {
2974
+ const finalized = JSON.parse(JSON.stringify(result));
2975
+ Object.defineProperty(finalized, "~standard", {
2976
+ value: {
2977
+ ...schema["~standard"],
2978
+ jsonSchema: {
2979
+ input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
2980
+ output: createStandardJSONSchemaMethod(schema, "output", ctx.processors)
2981
+ }
2982
+ },
2983
+ enumerable: false,
2984
+ writable: false
2985
+ });
2986
+ return finalized;
2987
+ } catch (_err) {
2988
+ throw new Error("Error converting schema to JSON.");
2989
+ }
2990
+ }
2991
+ function isTransforming(_schema, _ctx) {
2992
+ const ctx = _ctx ?? { seen: /* @__PURE__ */ new Set() };
2993
+ if (ctx.seen.has(_schema)) return false;
2994
+ ctx.seen.add(_schema);
2995
+ const def = _schema._zod.def;
2996
+ if (def.type === "transform") return true;
2997
+ if (def.type === "array") return isTransforming(def.element, ctx);
2998
+ if (def.type === "set") return isTransforming(def.valueType, ctx);
2999
+ if (def.type === "lazy") return isTransforming(def.getter(), ctx);
3000
+ if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault") return isTransforming(def.innerType, ctx);
3001
+ if (def.type === "intersection") return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
3002
+ if (def.type === "record" || def.type === "map") return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
3003
+ if (def.type === "pipe") {
3004
+ if (_schema._zod.traits.has("$ZodCodec")) return true;
3005
+ return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
3006
+ }
3007
+ if (def.type === "object") {
3008
+ for (const key in def.shape) if (isTransforming(def.shape[key], ctx)) return true;
3009
+ return false;
3010
+ }
3011
+ if (def.type === "union") {
3012
+ for (const option of def.options) if (isTransforming(option, ctx)) return true;
3013
+ return false;
3014
+ }
3015
+ if (def.type === "tuple") {
3016
+ for (const item of def.items) if (isTransforming(item, ctx)) return true;
3017
+ if (def.rest && isTransforming(def.rest, ctx)) return true;
3018
+ return false;
3019
+ }
3020
+ return false;
3021
+ }
3022
+ /**
3023
+ * Creates a toJSONSchema method for a schema instance.
3024
+ * This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
3025
+ */
3026
+ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
3027
+ const ctx = initializeContext({
3028
+ ...params,
3029
+ processors
3030
+ });
3031
+ process$1(schema, ctx);
3032
+ extractDefs(ctx, schema);
3033
+ return finalize(ctx, schema);
3034
+ };
3035
+ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
3036
+ const { libraryOptions, target } = params ?? {};
3037
+ const ctx = initializeContext({
3038
+ ...libraryOptions ?? {},
3039
+ target,
3040
+ io,
3041
+ processors
3042
+ });
3043
+ process$1(schema, ctx);
3044
+ extractDefs(ctx, schema);
3045
+ return finalize(ctx, schema);
3046
+ };
3047
+ //#endregion
3048
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/json-schema-processors.js
3049
+ const formatMap = {
3050
+ guid: "uuid",
3051
+ url: "uri",
3052
+ datetime: "date-time",
3053
+ json_string: "json-string",
3054
+ regex: ""
3055
+ };
3056
+ const stringProcessor = (schema, ctx, _json, _params) => {
3057
+ const json = _json;
3058
+ json.type = "string";
3059
+ const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
3060
+ if (typeof minimum === "number") json.minLength = minimum;
3061
+ if (typeof maximum === "number") json.maxLength = maximum;
3062
+ if (format) {
3063
+ json.format = formatMap[format] ?? format;
3064
+ if (json.format === "") delete json.format;
3065
+ if (format === "time") delete json.format;
3066
+ }
3067
+ if (contentEncoding) json.contentEncoding = contentEncoding;
3068
+ if (patterns && patterns.size > 0) {
3069
+ const regexes = [...patterns];
3070
+ if (regexes.length === 1) json.pattern = regexes[0].source;
3071
+ else if (regexes.length > 1) json.allOf = [...regexes.map((regex) => ({
3072
+ ...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
3073
+ pattern: regex.source
3074
+ }))];
3075
+ }
3076
+ };
3077
+ const numberProcessor = (schema, ctx, _json, _params) => {
3078
+ const json = _json;
3079
+ const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
3080
+ if (typeof format === "string" && format.includes("int")) json.type = "integer";
3081
+ else json.type = "number";
3082
+ const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
3083
+ const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
3084
+ const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
3085
+ if (exMin) {
3086
+ if (legacy) {
3087
+ json.minimum = exclusiveMinimum;
3088
+ json.exclusiveMinimum = true;
3089
+ } else json.exclusiveMinimum = exclusiveMinimum;
3090
+ } else if (typeof minimum === "number") json.minimum = minimum;
3091
+ if (exMax) {
3092
+ if (legacy) {
3093
+ json.maximum = exclusiveMaximum;
3094
+ json.exclusiveMaximum = true;
3095
+ } else json.exclusiveMaximum = exclusiveMaximum;
3096
+ } else if (typeof maximum === "number") json.maximum = maximum;
3097
+ if (typeof multipleOf === "number") json.multipleOf = multipleOf;
3098
+ };
3099
+ const booleanProcessor = (_schema, _ctx, json, _params) => {
3100
+ json.type = "boolean";
3101
+ };
3102
+ const neverProcessor = (_schema, _ctx, json, _params) => {
3103
+ json.not = {};
3104
+ };
3105
+ const enumProcessor = (schema, _ctx, json, _params) => {
3106
+ const def = schema._zod.def;
3107
+ const values = getEnumValues(def.entries);
3108
+ if (values.every((v) => typeof v === "number")) json.type = "number";
3109
+ if (values.every((v) => typeof v === "string")) json.type = "string";
3110
+ json.enum = values;
3111
+ };
3112
+ const literalProcessor = (schema, ctx, json, _params) => {
3113
+ const def = schema._zod.def;
3114
+ const vals = [];
3115
+ for (const val of def.values) if (val === void 0) {
3116
+ if (ctx.unrepresentable === "throw") throw new Error("Literal `undefined` cannot be represented in JSON Schema");
3117
+ } else if (typeof val === "bigint") {
3118
+ if (ctx.unrepresentable === "throw") throw new Error("BigInt literals cannot be represented in JSON Schema");
3119
+ else vals.push(Number(val));
3120
+ } else vals.push(val);
3121
+ if (vals.length === 0) {} else if (vals.length === 1) {
3122
+ const val = vals[0];
3123
+ json.type = val === null ? "null" : typeof val;
3124
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") json.enum = [val];
3125
+ else json.const = val;
3126
+ } else {
3127
+ if (vals.every((v) => typeof v === "number")) json.type = "number";
3128
+ if (vals.every((v) => typeof v === "string")) json.type = "string";
3129
+ if (vals.every((v) => typeof v === "boolean")) json.type = "boolean";
3130
+ if (vals.every((v) => v === null)) json.type = "null";
3131
+ json.enum = vals;
3132
+ }
3133
+ };
3134
+ const customProcessor = (_schema, ctx, _json, _params) => {
3135
+ if (ctx.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
3136
+ };
3137
+ const transformProcessor = (_schema, ctx, _json, _params) => {
3138
+ if (ctx.unrepresentable === "throw") throw new Error("Transforms cannot be represented in JSON Schema");
3139
+ };
3140
+ const arrayProcessor = (schema, ctx, _json, params) => {
3141
+ const json = _json;
3142
+ const def = schema._zod.def;
3143
+ const { minimum, maximum } = schema._zod.bag;
3144
+ if (typeof minimum === "number") json.minItems = minimum;
3145
+ if (typeof maximum === "number") json.maxItems = maximum;
3146
+ json.type = "array";
3147
+ json.items = process$1(def.element, ctx, {
3148
+ ...params,
3149
+ path: [...params.path, "items"]
3150
+ });
3151
+ };
3152
+ const objectProcessor = (schema, ctx, _json, params) => {
3153
+ const json = _json;
3154
+ const def = schema._zod.def;
3155
+ json.type = "object";
3156
+ json.properties = {};
3157
+ const shape = def.shape;
3158
+ for (const key in shape) json.properties[key] = process$1(shape[key], ctx, {
3159
+ ...params,
3160
+ path: [
3161
+ ...params.path,
3162
+ "properties",
3163
+ key
3164
+ ]
3165
+ });
3166
+ const allKeys = new Set(Object.keys(shape));
3167
+ const requiredKeys = new Set([...allKeys].filter((key) => {
3168
+ const v = def.shape[key]._zod;
3169
+ if (ctx.io === "input") return v.optin === void 0;
3170
+ else return v.optout === void 0;
3171
+ }));
3172
+ if (requiredKeys.size > 0) json.required = Array.from(requiredKeys);
3173
+ if (def.catchall?._zod.def.type === "never") json.additionalProperties = false;
3174
+ else if (!def.catchall) {
3175
+ if (ctx.io === "output") json.additionalProperties = false;
3176
+ } else if (def.catchall) json.additionalProperties = process$1(def.catchall, ctx, {
3177
+ ...params,
3178
+ path: [...params.path, "additionalProperties"]
3179
+ });
3180
+ };
3181
+ const unionProcessor = (schema, ctx, json, params) => {
3182
+ const def = schema._zod.def;
3183
+ const isExclusive = def.inclusive === false;
3184
+ const options = def.options.map((x, i) => process$1(x, ctx, {
3185
+ ...params,
3186
+ path: [
3187
+ ...params.path,
3188
+ isExclusive ? "oneOf" : "anyOf",
3189
+ i
3190
+ ]
3191
+ }));
3192
+ if (isExclusive) json.oneOf = options;
3193
+ else json.anyOf = options;
3194
+ };
3195
+ const intersectionProcessor = (schema, ctx, json, params) => {
3196
+ const def = schema._zod.def;
3197
+ const a = process$1(def.left, ctx, {
3198
+ ...params,
3199
+ path: [
3200
+ ...params.path,
3201
+ "allOf",
3202
+ 0
3203
+ ]
3204
+ });
3205
+ const b = process$1(def.right, ctx, {
3206
+ ...params,
3207
+ path: [
3208
+ ...params.path,
3209
+ "allOf",
3210
+ 1
3211
+ ]
3212
+ });
3213
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
3214
+ json.allOf = [...isSimpleIntersection(a) ? a.allOf : [a], ...isSimpleIntersection(b) ? b.allOf : [b]];
3215
+ };
3216
+ const nullableProcessor = (schema, ctx, json, params) => {
3217
+ const def = schema._zod.def;
3218
+ const inner = process$1(def.innerType, ctx, params);
3219
+ const seen = ctx.seen.get(schema);
3220
+ if (ctx.target === "openapi-3.0") {
3221
+ seen.ref = def.innerType;
3222
+ json.nullable = true;
3223
+ } else json.anyOf = [inner, { type: "null" }];
3224
+ };
3225
+ const nonoptionalProcessor = (schema, ctx, _json, params) => {
3226
+ const def = schema._zod.def;
3227
+ process$1(def.innerType, ctx, params);
3228
+ const seen = ctx.seen.get(schema);
3229
+ seen.ref = def.innerType;
3230
+ };
3231
+ const defaultProcessor = (schema, ctx, json, params) => {
3232
+ const def = schema._zod.def;
3233
+ process$1(def.innerType, ctx, params);
3234
+ const seen = ctx.seen.get(schema);
3235
+ seen.ref = def.innerType;
3236
+ json.default = JSON.parse(JSON.stringify(def.defaultValue));
3237
+ };
3238
+ const prefaultProcessor = (schema, ctx, json, params) => {
3239
+ const def = schema._zod.def;
3240
+ process$1(def.innerType, ctx, params);
3241
+ const seen = ctx.seen.get(schema);
3242
+ seen.ref = def.innerType;
3243
+ if (ctx.io === "input") json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
3244
+ };
3245
+ const catchProcessor = (schema, ctx, json, params) => {
3246
+ const def = schema._zod.def;
3247
+ process$1(def.innerType, ctx, params);
3248
+ const seen = ctx.seen.get(schema);
3249
+ seen.ref = def.innerType;
3250
+ let catchValue;
3251
+ try {
3252
+ catchValue = def.catchValue(void 0);
3253
+ } catch {
3254
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
3255
+ }
3256
+ json.default = catchValue;
3257
+ };
3258
+ const pipeProcessor = (schema, ctx, _json, params) => {
3259
+ const def = schema._zod.def;
3260
+ const inIsTransform = def.in._zod.traits.has("$ZodTransform");
3261
+ const innerType = ctx.io === "input" ? inIsTransform ? def.out : def.in : def.out;
3262
+ process$1(innerType, ctx, params);
3263
+ const seen = ctx.seen.get(schema);
3264
+ seen.ref = innerType;
3265
+ };
3266
+ const readonlyProcessor = (schema, ctx, json, params) => {
3267
+ const def = schema._zod.def;
3268
+ process$1(def.innerType, ctx, params);
3269
+ const seen = ctx.seen.get(schema);
3270
+ seen.ref = def.innerType;
3271
+ json.readOnly = true;
3272
+ };
3273
+ const optionalProcessor = (schema, ctx, _json, params) => {
3274
+ const def = schema._zod.def;
3275
+ process$1(def.innerType, ctx, params);
3276
+ const seen = ctx.seen.get(schema);
3277
+ seen.ref = def.innerType;
3278
+ };
3279
+ //#endregion
3280
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/iso.js
3281
+ const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
3282
+ $ZodISODateTime.init(inst, def);
3283
+ ZodStringFormat.init(inst, def);
3284
+ });
3285
+ function datetime(params) {
3286
+ return /* @__PURE__ */ _isoDateTime(ZodISODateTime, params);
3287
+ }
3288
+ const ZodISODate = /*@__PURE__*/ $constructor("ZodISODate", (inst, def) => {
3289
+ $ZodISODate.init(inst, def);
3290
+ ZodStringFormat.init(inst, def);
3291
+ });
3292
+ function date(params) {
3293
+ return /* @__PURE__ */ _isoDate(ZodISODate, params);
3294
+ }
3295
+ const ZodISOTime = /*@__PURE__*/ $constructor("ZodISOTime", (inst, def) => {
3296
+ $ZodISOTime.init(inst, def);
3297
+ ZodStringFormat.init(inst, def);
3298
+ });
3299
+ function time(params) {
3300
+ return /* @__PURE__ */ _isoTime(ZodISOTime, params);
3301
+ }
3302
+ const ZodISODuration = /*@__PURE__*/ $constructor("ZodISODuration", (inst, def) => {
3303
+ $ZodISODuration.init(inst, def);
3304
+ ZodStringFormat.init(inst, def);
3305
+ });
3306
+ function duration(params) {
3307
+ return /* @__PURE__ */ _isoDuration(ZodISODuration, params);
3308
+ }
3309
+ //#endregion
3310
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/errors.js
3311
+ const initializer = (inst, issues) => {
3312
+ $ZodError.init(inst, issues);
3313
+ inst.name = "ZodError";
3314
+ Object.defineProperties(inst, {
3315
+ format: { value: (mapper) => formatError(inst, mapper) },
3316
+ flatten: { value: (mapper) => flattenError(inst, mapper) },
3317
+ addIssue: { value: (issue) => {
3318
+ inst.issues.push(issue);
3319
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
3320
+ } },
3321
+ addIssues: { value: (issues) => {
3322
+ inst.issues.push(...issues);
3323
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
3324
+ } },
3325
+ isEmpty: { get() {
3326
+ return inst.issues.length === 0;
3327
+ } }
3328
+ });
3329
+ };
3330
+ const ZodRealError = /*@__PURE__*/ $constructor("ZodError", initializer, { Parent: Error });
3331
+ //#endregion
3332
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/parse.js
3333
+ const parse = /* @__PURE__ */ _parse(ZodRealError);
3334
+ const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
3335
+ const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
3336
+ const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
3337
+ const encode = /* @__PURE__ */ _encode(ZodRealError);
3338
+ const decode = /* @__PURE__ */ _decode(ZodRealError);
3339
+ const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
3340
+ const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
3341
+ const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
3342
+ const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
3343
+ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
3344
+ const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
3345
+ //#endregion
3346
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/schemas.js
3347
+ const _installedGroups = /* @__PURE__ */ new WeakMap();
3348
+ function _installLazyMethods(inst, group, methods) {
3349
+ const proto = Object.getPrototypeOf(inst);
3350
+ let installed = _installedGroups.get(proto);
3351
+ if (!installed) {
3352
+ installed = /* @__PURE__ */ new Set();
3353
+ _installedGroups.set(proto, installed);
3354
+ }
3355
+ if (installed.has(group)) return;
3356
+ installed.add(group);
3357
+ for (const key in methods) {
3358
+ const fn = methods[key];
3359
+ Object.defineProperty(proto, key, {
3360
+ configurable: true,
3361
+ enumerable: false,
3362
+ get() {
3363
+ const bound = fn.bind(this);
3364
+ Object.defineProperty(this, key, {
3365
+ configurable: true,
3366
+ writable: true,
3367
+ enumerable: true,
3368
+ value: bound
3369
+ });
3370
+ return bound;
3371
+ },
3372
+ set(v) {
3373
+ Object.defineProperty(this, key, {
3374
+ configurable: true,
3375
+ writable: true,
3376
+ enumerable: true,
3377
+ value: v
3378
+ });
3379
+ }
3380
+ });
3381
+ }
3382
+ }
3383
+ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
3384
+ $ZodType.init(inst, def);
3385
+ Object.assign(inst["~standard"], { jsonSchema: {
3386
+ input: createStandardJSONSchemaMethod(inst, "input"),
3387
+ output: createStandardJSONSchemaMethod(inst, "output")
3388
+ } });
3389
+ inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
3390
+ inst.def = def;
3391
+ inst.type = def.type;
3392
+ Object.defineProperty(inst, "_def", { value: def });
3393
+ inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
3394
+ inst.safeParse = (data, params) => safeParse(inst, data, params);
3395
+ inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
3396
+ inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
3397
+ inst.spa = inst.safeParseAsync;
3398
+ inst.encode = (data, params) => encode(inst, data, params);
3399
+ inst.decode = (data, params) => decode(inst, data, params);
3400
+ inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
3401
+ inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
3402
+ inst.safeEncode = (data, params) => safeEncode(inst, data, params);
3403
+ inst.safeDecode = (data, params) => safeDecode(inst, data, params);
3404
+ inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
3405
+ inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
3406
+ _installLazyMethods(inst, "ZodType", {
3407
+ check(...chks) {
3408
+ const def = this.def;
3409
+ return this.clone(mergeDefs(def, { checks: [...def.checks ?? [], ...chks.map((ch) => typeof ch === "function" ? { _zod: {
3410
+ check: ch,
3411
+ def: { check: "custom" },
3412
+ onattach: []
3413
+ } } : ch)] }), { parent: true });
3414
+ },
3415
+ with(...chks) {
3416
+ return this.check(...chks);
3417
+ },
3418
+ clone(def, params) {
3419
+ return clone(this, def, params);
3420
+ },
3421
+ brand() {
3422
+ return this;
3423
+ },
3424
+ register(reg, meta) {
3425
+ reg.add(this, meta);
3426
+ return this;
3427
+ },
3428
+ refine(check, params) {
3429
+ return this.check(refine(check, params));
3430
+ },
3431
+ superRefine(refinement, params) {
3432
+ return this.check(superRefine(refinement, params));
3433
+ },
3434
+ overwrite(fn) {
3435
+ return this.check(/* @__PURE__ */ _overwrite(fn));
3436
+ },
3437
+ optional() {
3438
+ return optional(this);
3439
+ },
3440
+ exactOptional() {
3441
+ return exactOptional(this);
3442
+ },
3443
+ nullable() {
3444
+ return nullable(this);
3445
+ },
3446
+ nullish() {
3447
+ return optional(nullable(this));
3448
+ },
3449
+ nonoptional(params) {
3450
+ return nonoptional(this, params);
3451
+ },
3452
+ array() {
3453
+ return array(this);
3454
+ },
3455
+ or(arg) {
3456
+ return union([this, arg]);
3457
+ },
3458
+ and(arg) {
3459
+ return intersection(this, arg);
3460
+ },
3461
+ transform(tx) {
3462
+ return pipe(this, transform(tx));
3463
+ },
3464
+ default(d) {
3465
+ return _default(this, d);
3466
+ },
3467
+ prefault(d) {
3468
+ return prefault(this, d);
3469
+ },
3470
+ catch(params) {
3471
+ return _catch(this, params);
3472
+ },
3473
+ pipe(target) {
3474
+ return pipe(this, target);
3475
+ },
3476
+ readonly() {
3477
+ return readonly(this);
3478
+ },
3479
+ describe(description) {
3480
+ const cl = this.clone();
3481
+ globalRegistry.add(cl, { description });
3482
+ return cl;
3483
+ },
3484
+ meta(...args) {
3485
+ if (args.length === 0) return globalRegistry.get(this);
3486
+ const cl = this.clone();
3487
+ globalRegistry.add(cl, args[0]);
3488
+ return cl;
3489
+ },
3490
+ isOptional() {
3491
+ return this.safeParse(void 0).success;
3492
+ },
3493
+ isNullable() {
3494
+ return this.safeParse(null).success;
3495
+ },
3496
+ apply(fn) {
3497
+ return fn(this);
3498
+ }
3499
+ });
3500
+ Object.defineProperty(inst, "description", {
3501
+ get() {
3502
+ return globalRegistry.get(inst)?.description;
3503
+ },
3504
+ configurable: true
3505
+ });
3506
+ return inst;
3507
+ });
3508
+ /** @internal */
3509
+ const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
3510
+ $ZodString.init(inst, def);
3511
+ ZodType.init(inst, def);
3512
+ inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json, params);
3513
+ const bag = inst._zod.bag;
3514
+ inst.format = bag.format ?? null;
3515
+ inst.minLength = bag.minimum ?? null;
3516
+ inst.maxLength = bag.maximum ?? null;
3517
+ _installLazyMethods(inst, "_ZodString", {
3518
+ regex(...args) {
3519
+ return this.check(/* @__PURE__ */ _regex(...args));
3520
+ },
3521
+ includes(...args) {
3522
+ return this.check(/* @__PURE__ */ _includes(...args));
3523
+ },
3524
+ startsWith(...args) {
3525
+ return this.check(/* @__PURE__ */ _startsWith(...args));
3526
+ },
3527
+ endsWith(...args) {
3528
+ return this.check(/* @__PURE__ */ _endsWith(...args));
3529
+ },
3530
+ min(...args) {
3531
+ return this.check(/* @__PURE__ */ _minLength(...args));
3532
+ },
3533
+ max(...args) {
3534
+ return this.check(/* @__PURE__ */ _maxLength(...args));
3535
+ },
3536
+ length(...args) {
3537
+ return this.check(/* @__PURE__ */ _length(...args));
3538
+ },
3539
+ nonempty(...args) {
3540
+ return this.check(/* @__PURE__ */ _minLength(1, ...args));
3541
+ },
3542
+ lowercase(params) {
3543
+ return this.check(/* @__PURE__ */ _lowercase(params));
3544
+ },
3545
+ uppercase(params) {
3546
+ return this.check(/* @__PURE__ */ _uppercase(params));
3547
+ },
3548
+ trim() {
3549
+ return this.check(/* @__PURE__ */ _trim());
3550
+ },
3551
+ normalize(...args) {
3552
+ return this.check(/* @__PURE__ */ _normalize(...args));
3553
+ },
3554
+ toLowerCase() {
3555
+ return this.check(/* @__PURE__ */ _toLowerCase());
3556
+ },
3557
+ toUpperCase() {
3558
+ return this.check(/* @__PURE__ */ _toUpperCase());
3559
+ },
3560
+ slugify() {
3561
+ return this.check(/* @__PURE__ */ _slugify());
3562
+ }
3563
+ });
3564
+ });
3565
+ const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def) => {
3566
+ $ZodString.init(inst, def);
3567
+ _ZodString.init(inst, def);
3568
+ inst.email = (params) => inst.check(/* @__PURE__ */ _email(ZodEmail, params));
3569
+ inst.url = (params) => inst.check(/* @__PURE__ */ _url(ZodURL, params));
3570
+ inst.jwt = (params) => inst.check(/* @__PURE__ */ _jwt(ZodJWT, params));
3571
+ inst.emoji = (params) => inst.check(/* @__PURE__ */ _emoji(ZodEmoji, params));
3572
+ inst.guid = (params) => inst.check(/* @__PURE__ */ _guid(ZodGUID, params));
3573
+ inst.uuid = (params) => inst.check(/* @__PURE__ */ _uuid(ZodUUID, params));
3574
+ inst.uuidv4 = (params) => inst.check(/* @__PURE__ */ _uuidv4(ZodUUID, params));
3575
+ inst.uuidv6 = (params) => inst.check(/* @__PURE__ */ _uuidv6(ZodUUID, params));
3576
+ inst.uuidv7 = (params) => inst.check(/* @__PURE__ */ _uuidv7(ZodUUID, params));
3577
+ inst.nanoid = (params) => inst.check(/* @__PURE__ */ _nanoid(ZodNanoID, params));
3578
+ inst.guid = (params) => inst.check(/* @__PURE__ */ _guid(ZodGUID, params));
3579
+ inst.cuid = (params) => inst.check(/* @__PURE__ */ _cuid(ZodCUID, params));
3580
+ inst.cuid2 = (params) => inst.check(/* @__PURE__ */ _cuid2(ZodCUID2, params));
3581
+ inst.ulid = (params) => inst.check(/* @__PURE__ */ _ulid(ZodULID, params));
3582
+ inst.base64 = (params) => inst.check(/* @__PURE__ */ _base64(ZodBase64, params));
3583
+ inst.base64url = (params) => inst.check(/* @__PURE__ */ _base64url(ZodBase64URL, params));
3584
+ inst.xid = (params) => inst.check(/* @__PURE__ */ _xid(ZodXID, params));
3585
+ inst.ksuid = (params) => inst.check(/* @__PURE__ */ _ksuid(ZodKSUID, params));
3586
+ inst.ipv4 = (params) => inst.check(/* @__PURE__ */ _ipv4(ZodIPv4, params));
3587
+ inst.ipv6 = (params) => inst.check(/* @__PURE__ */ _ipv6(ZodIPv6, params));
3588
+ inst.cidrv4 = (params) => inst.check(/* @__PURE__ */ _cidrv4(ZodCIDRv4, params));
3589
+ inst.cidrv6 = (params) => inst.check(/* @__PURE__ */ _cidrv6(ZodCIDRv6, params));
3590
+ inst.e164 = (params) => inst.check(/* @__PURE__ */ _e164(ZodE164, params));
3591
+ inst.datetime = (params) => inst.check(datetime(params));
3592
+ inst.date = (params) => inst.check(date(params));
3593
+ inst.time = (params) => inst.check(time(params));
3594
+ inst.duration = (params) => inst.check(duration(params));
3595
+ });
3596
+ function string(params) {
3597
+ return /* @__PURE__ */ _string(ZodString, params);
3598
+ }
3599
+ const ZodStringFormat = /*@__PURE__*/ $constructor("ZodStringFormat", (inst, def) => {
3600
+ $ZodStringFormat.init(inst, def);
3601
+ _ZodString.init(inst, def);
3602
+ });
3603
+ const ZodEmail = /*@__PURE__*/ $constructor("ZodEmail", (inst, def) => {
3604
+ $ZodEmail.init(inst, def);
3605
+ ZodStringFormat.init(inst, def);
3606
+ });
3607
+ const ZodGUID = /*@__PURE__*/ $constructor("ZodGUID", (inst, def) => {
3608
+ $ZodGUID.init(inst, def);
3609
+ ZodStringFormat.init(inst, def);
3610
+ });
3611
+ const ZodUUID = /*@__PURE__*/ $constructor("ZodUUID", (inst, def) => {
3612
+ $ZodUUID.init(inst, def);
3613
+ ZodStringFormat.init(inst, def);
3614
+ });
3615
+ const ZodURL = /*@__PURE__*/ $constructor("ZodURL", (inst, def) => {
3616
+ $ZodURL.init(inst, def);
3617
+ ZodStringFormat.init(inst, def);
3618
+ });
3619
+ const ZodEmoji = /*@__PURE__*/ $constructor("ZodEmoji", (inst, def) => {
3620
+ $ZodEmoji.init(inst, def);
3621
+ ZodStringFormat.init(inst, def);
3622
+ });
3623
+ const ZodNanoID = /*@__PURE__*/ $constructor("ZodNanoID", (inst, def) => {
3624
+ $ZodNanoID.init(inst, def);
3625
+ ZodStringFormat.init(inst, def);
3626
+ });
3627
+ /**
3628
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
3629
+ * (timestamps embedded in the id). Use {@link ZodCUID2} instead.
3630
+ * See https://github.com/paralleldrive/cuid.
3631
+ */
3632
+ const ZodCUID = /*@__PURE__*/ $constructor("ZodCUID", (inst, def) => {
3633
+ $ZodCUID.init(inst, def);
3634
+ ZodStringFormat.init(inst, def);
3635
+ });
3636
+ const ZodCUID2 = /*@__PURE__*/ $constructor("ZodCUID2", (inst, def) => {
3637
+ $ZodCUID2.init(inst, def);
3638
+ ZodStringFormat.init(inst, def);
3639
+ });
3640
+ const ZodULID = /*@__PURE__*/ $constructor("ZodULID", (inst, def) => {
3641
+ $ZodULID.init(inst, def);
3642
+ ZodStringFormat.init(inst, def);
3643
+ });
3644
+ const ZodXID = /*@__PURE__*/ $constructor("ZodXID", (inst, def) => {
3645
+ $ZodXID.init(inst, def);
3646
+ ZodStringFormat.init(inst, def);
3647
+ });
3648
+ const ZodKSUID = /*@__PURE__*/ $constructor("ZodKSUID", (inst, def) => {
3649
+ $ZodKSUID.init(inst, def);
3650
+ ZodStringFormat.init(inst, def);
3651
+ });
3652
+ const ZodIPv4 = /*@__PURE__*/ $constructor("ZodIPv4", (inst, def) => {
3653
+ $ZodIPv4.init(inst, def);
3654
+ ZodStringFormat.init(inst, def);
3655
+ });
3656
+ const ZodIPv6 = /*@__PURE__*/ $constructor("ZodIPv6", (inst, def) => {
3657
+ $ZodIPv6.init(inst, def);
3658
+ ZodStringFormat.init(inst, def);
3659
+ });
3660
+ const ZodCIDRv4 = /*@__PURE__*/ $constructor("ZodCIDRv4", (inst, def) => {
3661
+ $ZodCIDRv4.init(inst, def);
3662
+ ZodStringFormat.init(inst, def);
3663
+ });
3664
+ const ZodCIDRv6 = /*@__PURE__*/ $constructor("ZodCIDRv6", (inst, def) => {
3665
+ $ZodCIDRv6.init(inst, def);
3666
+ ZodStringFormat.init(inst, def);
3667
+ });
3668
+ const ZodBase64 = /*@__PURE__*/ $constructor("ZodBase64", (inst, def) => {
3669
+ $ZodBase64.init(inst, def);
3670
+ ZodStringFormat.init(inst, def);
3671
+ });
3672
+ const ZodBase64URL = /*@__PURE__*/ $constructor("ZodBase64URL", (inst, def) => {
3673
+ $ZodBase64URL.init(inst, def);
3674
+ ZodStringFormat.init(inst, def);
3675
+ });
3676
+ const ZodE164 = /*@__PURE__*/ $constructor("ZodE164", (inst, def) => {
3677
+ $ZodE164.init(inst, def);
3678
+ ZodStringFormat.init(inst, def);
3679
+ });
3680
+ const ZodJWT = /*@__PURE__*/ $constructor("ZodJWT", (inst, def) => {
3681
+ $ZodJWT.init(inst, def);
3682
+ ZodStringFormat.init(inst, def);
3683
+ });
3684
+ const ZodNumber = /*@__PURE__*/ $constructor("ZodNumber", (inst, def) => {
3685
+ $ZodNumber.init(inst, def);
3686
+ ZodType.init(inst, def);
3687
+ inst._zod.processJSONSchema = (ctx, json, params) => numberProcessor(inst, ctx, json, params);
3688
+ _installLazyMethods(inst, "ZodNumber", {
3689
+ gt(value, params) {
3690
+ return this.check(/* @__PURE__ */ _gt(value, params));
3691
+ },
3692
+ gte(value, params) {
3693
+ return this.check(/* @__PURE__ */ _gte(value, params));
3694
+ },
3695
+ min(value, params) {
3696
+ return this.check(/* @__PURE__ */ _gte(value, params));
3697
+ },
3698
+ lt(value, params) {
3699
+ return this.check(/* @__PURE__ */ _lt(value, params));
3700
+ },
3701
+ lte(value, params) {
3702
+ return this.check(/* @__PURE__ */ _lte(value, params));
3703
+ },
3704
+ max(value, params) {
3705
+ return this.check(/* @__PURE__ */ _lte(value, params));
3706
+ },
3707
+ int(params) {
3708
+ return this.check(int(params));
3709
+ },
3710
+ safe(params) {
3711
+ return this.check(int(params));
3712
+ },
3713
+ positive(params) {
3714
+ return this.check(/* @__PURE__ */ _gt(0, params));
3715
+ },
3716
+ nonnegative(params) {
3717
+ return this.check(/* @__PURE__ */ _gte(0, params));
3718
+ },
3719
+ negative(params) {
3720
+ return this.check(/* @__PURE__ */ _lt(0, params));
3721
+ },
3722
+ nonpositive(params) {
3723
+ return this.check(/* @__PURE__ */ _lte(0, params));
3724
+ },
3725
+ multipleOf(value, params) {
3726
+ return this.check(/* @__PURE__ */ _multipleOf(value, params));
3727
+ },
3728
+ step(value, params) {
3729
+ return this.check(/* @__PURE__ */ _multipleOf(value, params));
3730
+ },
3731
+ finite() {
3732
+ return this;
3733
+ }
3734
+ });
3735
+ const bag = inst._zod.bag;
3736
+ inst.minValue = Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
3737
+ inst.maxValue = Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
3738
+ inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? .5);
3739
+ inst.isFinite = true;
3740
+ inst.format = bag.format ?? null;
3741
+ });
3742
+ function number(params) {
3743
+ return /* @__PURE__ */ _number(ZodNumber, params);
3744
+ }
3745
+ const ZodNumberFormat = /*@__PURE__*/ $constructor("ZodNumberFormat", (inst, def) => {
3746
+ $ZodNumberFormat.init(inst, def);
3747
+ ZodNumber.init(inst, def);
3748
+ });
3749
+ function int(params) {
3750
+ return /* @__PURE__ */ _int(ZodNumberFormat, params);
3751
+ }
3752
+ const ZodBoolean = /*@__PURE__*/ $constructor("ZodBoolean", (inst, def) => {
3753
+ $ZodBoolean.init(inst, def);
3754
+ ZodType.init(inst, def);
3755
+ inst._zod.processJSONSchema = (ctx, json, params) => booleanProcessor(inst, ctx, json, params);
3756
+ });
3757
+ function boolean(params) {
3758
+ return /* @__PURE__ */ _boolean(ZodBoolean, params);
3759
+ }
3760
+ const ZodUnknown = /*@__PURE__*/ $constructor("ZodUnknown", (inst, def) => {
3761
+ $ZodUnknown.init(inst, def);
3762
+ ZodType.init(inst, def);
3763
+ inst._zod.processJSONSchema = (ctx, json, params) => void 0;
3764
+ });
3765
+ function unknown() {
3766
+ return /* @__PURE__ */ _unknown(ZodUnknown);
3767
+ }
3768
+ const ZodNever = /*@__PURE__*/ $constructor("ZodNever", (inst, def) => {
3769
+ $ZodNever.init(inst, def);
3770
+ ZodType.init(inst, def);
3771
+ inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json, params);
3772
+ });
3773
+ function never(params) {
3774
+ return /* @__PURE__ */ _never(ZodNever, params);
3775
+ }
3776
+ const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def) => {
3777
+ $ZodArray.init(inst, def);
3778
+ ZodType.init(inst, def);
3779
+ inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
3780
+ inst.element = def.element;
3781
+ _installLazyMethods(inst, "ZodArray", {
3782
+ min(n, params) {
3783
+ return this.check(/* @__PURE__ */ _minLength(n, params));
3784
+ },
3785
+ nonempty(params) {
3786
+ return this.check(/* @__PURE__ */ _minLength(1, params));
3787
+ },
3788
+ max(n, params) {
3789
+ return this.check(/* @__PURE__ */ _maxLength(n, params));
3790
+ },
3791
+ length(n, params) {
3792
+ return this.check(/* @__PURE__ */ _length(n, params));
3793
+ },
3794
+ unwrap() {
3795
+ return this.element;
3796
+ }
3797
+ });
3798
+ });
3799
+ function array(element, params) {
3800
+ return /* @__PURE__ */ _array(ZodArray, element, params);
3801
+ }
3802
+ const ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def) => {
3803
+ $ZodObjectJIT.init(inst, def);
3804
+ ZodType.init(inst, def);
3805
+ inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
3806
+ defineLazy(inst, "shape", () => {
3807
+ return def.shape;
3808
+ });
3809
+ _installLazyMethods(inst, "ZodObject", {
3810
+ keyof() {
3811
+ return _enum(Object.keys(this._zod.def.shape));
3812
+ },
3813
+ catchall(catchall) {
3814
+ return this.clone({
3815
+ ...this._zod.def,
3816
+ catchall
3817
+ });
3818
+ },
3819
+ passthrough() {
3820
+ return this.clone({
3821
+ ...this._zod.def,
3822
+ catchall: unknown()
3823
+ });
3824
+ },
3825
+ loose() {
3826
+ return this.clone({
3827
+ ...this._zod.def,
3828
+ catchall: unknown()
3829
+ });
3830
+ },
3831
+ strict() {
3832
+ return this.clone({
3833
+ ...this._zod.def,
3834
+ catchall: never()
3835
+ });
3836
+ },
3837
+ strip() {
3838
+ return this.clone({
3839
+ ...this._zod.def,
3840
+ catchall: void 0
3841
+ });
3842
+ },
3843
+ extend(incoming) {
3844
+ return extend(this, incoming);
3845
+ },
3846
+ safeExtend(incoming) {
3847
+ return safeExtend(this, incoming);
3848
+ },
3849
+ merge(other) {
3850
+ return merge(this, other);
3851
+ },
3852
+ pick(mask) {
3853
+ return pick(this, mask);
3854
+ },
3855
+ omit(mask) {
3856
+ return omit(this, mask);
3857
+ },
3858
+ partial(...args) {
3859
+ return partial(ZodOptional, this, args[0]);
3860
+ },
3861
+ required(...args) {
3862
+ return required(ZodNonOptional, this, args[0]);
3863
+ }
3864
+ });
3865
+ });
3866
+ function object(shape, params) {
3867
+ const def = {
3868
+ type: "object",
3869
+ shape: shape ?? {},
3870
+ ...normalizeParams(params)
3871
+ };
3872
+ return new ZodObject(def);
3873
+ }
3874
+ const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
3875
+ $ZodUnion.init(inst, def);
3876
+ ZodType.init(inst, def);
3877
+ inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
3878
+ inst.options = def.options;
3879
+ });
3880
+ function union(options, params) {
3881
+ return new ZodUnion({
3882
+ type: "union",
3883
+ options,
3884
+ ...normalizeParams(params)
3885
+ });
3886
+ }
3887
+ const ZodDiscriminatedUnion = /*@__PURE__*/ $constructor("ZodDiscriminatedUnion", (inst, def) => {
3888
+ ZodUnion.init(inst, def);
3889
+ $ZodDiscriminatedUnion.init(inst, def);
3890
+ });
3891
+ function discriminatedUnion(discriminator, options, params) {
3892
+ return new ZodDiscriminatedUnion({
3893
+ type: "union",
3894
+ options,
3895
+ discriminator,
3896
+ ...normalizeParams(params)
3897
+ });
3898
+ }
3899
+ const ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
3900
+ $ZodIntersection.init(inst, def);
3901
+ ZodType.init(inst, def);
3902
+ inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
3903
+ });
3904
+ function intersection(left, right) {
3905
+ return new ZodIntersection({
3906
+ type: "intersection",
3907
+ left,
3908
+ right
3909
+ });
3910
+ }
3911
+ const ZodEnum = /*@__PURE__*/ $constructor("ZodEnum", (inst, def) => {
3912
+ $ZodEnum.init(inst, def);
3913
+ ZodType.init(inst, def);
3914
+ inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json, params);
3915
+ inst.enum = def.entries;
3916
+ inst.options = Object.values(def.entries);
3917
+ const keys = new Set(Object.keys(def.entries));
3918
+ inst.extract = (values, params) => {
3919
+ const newEntries = {};
3920
+ for (const value of values) if (keys.has(value)) newEntries[value] = def.entries[value];
3921
+ else throw new Error(`Key ${value} not found in enum`);
3922
+ return new ZodEnum({
3923
+ ...def,
3924
+ checks: [],
3925
+ ...normalizeParams(params),
3926
+ entries: newEntries
3927
+ });
3928
+ };
3929
+ inst.exclude = (values, params) => {
3930
+ const newEntries = { ...def.entries };
3931
+ for (const value of values) if (keys.has(value)) delete newEntries[value];
3932
+ else throw new Error(`Key ${value} not found in enum`);
3933
+ return new ZodEnum({
3934
+ ...def,
3935
+ checks: [],
3936
+ ...normalizeParams(params),
3937
+ entries: newEntries
3938
+ });
3939
+ };
3940
+ });
3941
+ function _enum(values, params) {
3942
+ const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
3943
+ return new ZodEnum({
3944
+ type: "enum",
3945
+ entries,
3946
+ ...normalizeParams(params)
3947
+ });
3948
+ }
3949
+ const ZodLiteral = /*@__PURE__*/ $constructor("ZodLiteral", (inst, def) => {
3950
+ $ZodLiteral.init(inst, def);
3951
+ ZodType.init(inst, def);
3952
+ inst._zod.processJSONSchema = (ctx, json, params) => literalProcessor(inst, ctx, json, params);
3953
+ inst.values = new Set(def.values);
3954
+ Object.defineProperty(inst, "value", { get() {
3955
+ if (def.values.length > 1) throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
3956
+ return def.values[0];
3957
+ } });
3958
+ });
3959
+ function literal(value, params) {
3960
+ return new ZodLiteral({
3961
+ type: "literal",
3962
+ values: Array.isArray(value) ? value : [value],
3963
+ ...normalizeParams(params)
3964
+ });
3965
+ }
3966
+ const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
3967
+ $ZodTransform.init(inst, def);
3968
+ ZodType.init(inst, def);
3969
+ inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx, json, params);
3970
+ inst._zod.parse = (payload, _ctx) => {
3971
+ if (_ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
3972
+ payload.addIssue = (issue$1) => {
3973
+ if (typeof issue$1 === "string") payload.issues.push(issue(issue$1, payload.value, def));
3974
+ else {
3975
+ const _issue = issue$1;
3976
+ if (_issue.fatal) _issue.continue = false;
3977
+ _issue.code ?? (_issue.code = "custom");
3978
+ _issue.input ?? (_issue.input = payload.value);
3979
+ _issue.inst ?? (_issue.inst = inst);
3980
+ payload.issues.push(issue(_issue));
3981
+ }
3982
+ };
3983
+ const output = def.transform(payload.value, payload);
3984
+ if (output instanceof Promise) return output.then((output) => {
3985
+ payload.value = output;
3986
+ payload.fallback = true;
3987
+ return payload;
3988
+ });
3989
+ payload.value = output;
3990
+ payload.fallback = true;
3991
+ return payload;
3992
+ };
3993
+ });
3994
+ function transform(fn) {
3995
+ return new ZodTransform({
3996
+ type: "transform",
3997
+ transform: fn
3998
+ });
3999
+ }
4000
+ const ZodOptional = /*@__PURE__*/ $constructor("ZodOptional", (inst, def) => {
4001
+ $ZodOptional.init(inst, def);
4002
+ ZodType.init(inst, def);
4003
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
4004
+ inst.unwrap = () => inst._zod.def.innerType;
4005
+ });
4006
+ function optional(innerType) {
4007
+ return new ZodOptional({
4008
+ type: "optional",
4009
+ innerType
4010
+ });
4011
+ }
4012
+ const ZodExactOptional = /*@__PURE__*/ $constructor("ZodExactOptional", (inst, def) => {
4013
+ $ZodExactOptional.init(inst, def);
4014
+ ZodType.init(inst, def);
4015
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
4016
+ inst.unwrap = () => inst._zod.def.innerType;
4017
+ });
4018
+ function exactOptional(innerType) {
4019
+ return new ZodExactOptional({
4020
+ type: "optional",
4021
+ innerType
4022
+ });
4023
+ }
4024
+ const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
4025
+ $ZodNullable.init(inst, def);
4026
+ ZodType.init(inst, def);
4027
+ inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
4028
+ inst.unwrap = () => inst._zod.def.innerType;
4029
+ });
4030
+ function nullable(innerType) {
4031
+ return new ZodNullable({
4032
+ type: "nullable",
4033
+ innerType
4034
+ });
4035
+ }
4036
+ const ZodDefault = /*@__PURE__*/ $constructor("ZodDefault", (inst, def) => {
4037
+ $ZodDefault.init(inst, def);
4038
+ ZodType.init(inst, def);
4039
+ inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
4040
+ inst.unwrap = () => inst._zod.def.innerType;
4041
+ inst.removeDefault = inst.unwrap;
4042
+ });
4043
+ function _default(innerType, defaultValue) {
4044
+ return new ZodDefault({
4045
+ type: "default",
4046
+ innerType,
4047
+ get defaultValue() {
4048
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
4049
+ }
4050
+ });
4051
+ }
4052
+ const ZodPrefault = /*@__PURE__*/ $constructor("ZodPrefault", (inst, def) => {
4053
+ $ZodPrefault.init(inst, def);
4054
+ ZodType.init(inst, def);
4055
+ inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
4056
+ inst.unwrap = () => inst._zod.def.innerType;
4057
+ });
4058
+ function prefault(innerType, defaultValue) {
4059
+ return new ZodPrefault({
4060
+ type: "prefault",
4061
+ innerType,
4062
+ get defaultValue() {
4063
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
4064
+ }
4065
+ });
4066
+ }
4067
+ const ZodNonOptional = /*@__PURE__*/ $constructor("ZodNonOptional", (inst, def) => {
4068
+ $ZodNonOptional.init(inst, def);
4069
+ ZodType.init(inst, def);
4070
+ inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
4071
+ inst.unwrap = () => inst._zod.def.innerType;
4072
+ });
4073
+ function nonoptional(innerType, params) {
4074
+ return new ZodNonOptional({
4075
+ type: "nonoptional",
4076
+ innerType,
4077
+ ...normalizeParams(params)
4078
+ });
4079
+ }
4080
+ const ZodCatch = /*@__PURE__*/ $constructor("ZodCatch", (inst, def) => {
4081
+ $ZodCatch.init(inst, def);
4082
+ ZodType.init(inst, def);
4083
+ inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
4084
+ inst.unwrap = () => inst._zod.def.innerType;
4085
+ inst.removeCatch = inst.unwrap;
4086
+ });
4087
+ function _catch(innerType, catchValue) {
4088
+ return new ZodCatch({
4089
+ type: "catch",
4090
+ innerType,
4091
+ catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
4092
+ });
4093
+ }
4094
+ const ZodPipe = /*@__PURE__*/ $constructor("ZodPipe", (inst, def) => {
4095
+ $ZodPipe.init(inst, def);
4096
+ ZodType.init(inst, def);
4097
+ inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
4098
+ inst.in = def.in;
4099
+ inst.out = def.out;
4100
+ });
4101
+ function pipe(in_, out) {
4102
+ return new ZodPipe({
4103
+ type: "pipe",
4104
+ in: in_,
4105
+ out
4106
+ });
4107
+ }
4108
+ const ZodReadonly = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
4109
+ $ZodReadonly.init(inst, def);
4110
+ ZodType.init(inst, def);
4111
+ inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
4112
+ inst.unwrap = () => inst._zod.def.innerType;
4113
+ });
4114
+ function readonly(innerType) {
4115
+ return new ZodReadonly({
4116
+ type: "readonly",
4117
+ innerType
4118
+ });
4119
+ }
4120
+ const ZodCustom = /*@__PURE__*/ $constructor("ZodCustom", (inst, def) => {
4121
+ $ZodCustom.init(inst, def);
4122
+ ZodType.init(inst, def);
4123
+ inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx, json, params);
4124
+ });
4125
+ function refine(fn, _params = {}) {
4126
+ return /* @__PURE__ */ _refine(ZodCustom, fn, _params);
4127
+ }
4128
+ function superRefine(fn, params) {
4129
+ return /* @__PURE__ */ _superRefine(fn, params);
4130
+ }
4131
+ //#endregion
4132
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-subagent@0_333a83db5ad7aba5051480205ed90428/node_modules/@deepseek-ai/dsh-subagent/lib/index.js
4133
+ const DESCRIPTOR_BASE_KEYS = [
4134
+ "version",
4135
+ "mode",
4136
+ "provider",
4137
+ "label"
4138
+ ];
4139
+ const ONE_SHOT_DESCRIPTOR_KEYS = new Set(DESCRIPTOR_BASE_KEYS);
4140
+ const CONTINUABLE_DESCRIPTOR_KEYS = /* @__PURE__ */ new Set([
4141
+ ...DESCRIPTOR_BASE_KEYS,
4142
+ "agentProvider",
4143
+ "agentModel",
4144
+ "persona",
4145
+ "toolFilter"
4146
+ ]);
4147
+ const TOOL_FILTER_KEYS = /* @__PURE__ */ new Set(["allow", "deny"]);
4148
+ /** Whether a persisted JSON value is an object record. */
4149
+ function isRecord(value) {
4150
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4151
+ }
4152
+ /** Reject fields outside one versioned record's declared schema. */
4153
+ function assertKnownKeys(value, keys, path) {
4154
+ const unknown = Object.keys(value).find((key) => !keys.has(key));
4155
+ if (unknown !== void 0) throw new Error(`persisted subagent descriptor ${path} has unknown field "${unknown}"`);
4156
+ }
4157
+ /** Read one optional string field from a persisted descriptor record. */
4158
+ function optionalString(value, key) {
4159
+ if (!Object.hasOwn(value, key)) return void 0;
4160
+ const field = value[key];
4161
+ if (typeof field !== "string") throw new Error(`persisted subagent descriptor ${key} must be a string`);
4162
+ return field;
4163
+ }
4164
+ /** Read one optional string-array field from a persisted tool restriction. */
4165
+ function optionalStringArray(value, key) {
4166
+ if (!Object.hasOwn(value, key)) return void 0;
4167
+ const field = value[key];
4168
+ if (!Array.isArray(field)) throw new Error(`persisted subagent descriptor toolFilter.${key} must be an array of strings`);
4169
+ const items = field;
4170
+ if (items.some((item) => typeof item !== "string")) throw new Error(`persisted subagent descriptor toolFilter.${key} must be an array of strings`);
4171
+ return items;
4172
+ }
4173
+ /** Validate and reconstruct a persisted tool restriction. */
4174
+ function parseToolFilter(value) {
4175
+ if (!isRecord(value)) throw new Error("persisted subagent descriptor toolFilter must be an object");
4176
+ assertKnownKeys(value, TOOL_FILTER_KEYS, "toolFilter");
4177
+ const allow = optionalStringArray(value, "allow");
4178
+ const deny = optionalStringArray(value, "deny");
4179
+ if (allow === void 0 && deny === void 0) throw new Error("persisted subagent descriptor toolFilter must declare allow and/or deny");
4180
+ return {
4181
+ ...allow !== void 0 ? { allow } : {},
4182
+ ...deny !== void 0 ? { deny } : {}
4183
+ };
4184
+ }
4185
+ /** Validate one persisted descriptor payload for the current runtime. */
4186
+ function parseSubagentDescriptor(value) {
4187
+ if (!isRecord(value)) throw new Error("persisted subagent descriptor payload must be an object");
4188
+ const version = value["version"];
4189
+ if (typeof version !== "number") throw new Error("persisted subagent descriptor version must be a number");
4190
+ if (version !== 2) return void 0;
4191
+ const mode = value["mode"];
4192
+ if (mode !== "one-shot" && mode !== "continuable") throw new Error("persisted subagent descriptor mode must be \"one-shot\" or \"continuable\"");
4193
+ assertKnownKeys(value, mode === "one-shot" ? ONE_SHOT_DESCRIPTOR_KEYS : CONTINUABLE_DESCRIPTOR_KEYS, "payload");
4194
+ const provider = value["provider"];
4195
+ if (typeof provider !== "string") throw new Error("persisted subagent descriptor provider must be a string");
4196
+ if (mode === "one-shot") {
4197
+ const label = optionalString(value, "label");
4198
+ return {
4199
+ version: 2,
4200
+ mode,
4201
+ provider,
4202
+ ...label !== void 0 ? { label } : {}
4203
+ };
4204
+ }
4205
+ const label = value["label"];
4206
+ if (typeof label !== "string") throw new Error("persisted subagent descriptor label must be a string");
4207
+ const agentProvider = optionalString(value, "agentProvider");
4208
+ const agentModel = optionalString(value, "agentModel");
4209
+ const persona = optionalString(value, "persona");
4210
+ const toolFilter = Object.hasOwn(value, "toolFilter") ? parseToolFilter(value["toolFilter"]) : void 0;
4211
+ return {
4212
+ version: 2,
4213
+ mode,
4214
+ provider,
4215
+ label,
4216
+ ...agentProvider !== void 0 ? { agentProvider } : {},
4217
+ ...agentModel !== void 0 ? { agentModel } : {},
4218
+ ...persona !== void 0 ? { persona } : {},
4219
+ ...toolFilter !== void 0 ? { toolFilter } : {}
4220
+ };
4221
+ }
4222
+ function snapshotSubagentDescriptor(input) {
4223
+ const snapshot = snapshotJsonValue(input.mode === "one-shot" ? {
4224
+ version: 2,
4225
+ mode: input.mode,
4226
+ provider: input.provider,
4227
+ ...input.label !== void 0 ? { label: input.label } : {}
4228
+ } : {
4229
+ version: 2,
4230
+ mode: input.mode,
4231
+ provider: input.provider,
4232
+ label: input.label,
4233
+ ...input.agentProvider !== void 0 ? { agentProvider: input.agentProvider } : {},
4234
+ ...input.agentModel !== void 0 ? { agentModel: input.agentModel } : {},
4235
+ ...input.persona !== void 0 ? { persona: input.persona } : {},
4236
+ ...input.toolFilter !== void 0 ? { toolFilter: input.toolFilter } : {}
4237
+ });
4238
+ if (snapshot === void 0) throw new Error("subagent descriptor is not losslessly JSON-serializable");
4239
+ return snapshot;
4240
+ }
4241
+ /**
4242
+ * Fold a persisted child log to its supported descriptor. The first
4243
+ * `subagent/descriptor` event is authoritative — the establishing provider
4244
+ * appends exactly one, so a later same-type event cannot rewrite the declared
4245
+ * composition.
4246
+ * @param events - the loaded child session events.
4247
+ * @returns the descriptor, or `undefined` when the log has none or its
4248
+ * version is not {@link SUBAGENT_DESCRIPTOR_VERSION} (the child cannot be
4249
+ * classified by this runtime).
4250
+ * @throws when a current-version persisted payload does not match its complete
4251
+ * declared schema.
4252
+ */
4253
+ function foldSubagentDescriptor(events) {
4254
+ const event = events.find((candidate) => candidate.type === "subagent/descriptor");
4255
+ if (event === void 0) return void 0;
4256
+ return parseSubagentDescriptor(event.data);
4257
+ }
4258
+ /**
4259
+ * Pure session projections for subagent identity (mode/label) and active-turn
4260
+ * duration.
4261
+ *
4262
+ * @module @deepseek-ai/dsh-subagent/projection
4263
+ */
4264
+ const activeIntervalSchema = object({
4265
+ since: number().int().nonnegative(),
4266
+ through: number().int().nonnegative()
4267
+ }).strict();
4268
+ object({
4269
+ settledMs: number().int().nonnegative(),
4270
+ active: activeIntervalSchema.optional()
4271
+ }).strict().transform(({ settledMs, active }) => ({
4272
+ settledMs,
4273
+ ...active === void 0 ? {} : { active }
4274
+ }));
4275
+ object({
4276
+ settledMs: number().int().nonnegative(),
4277
+ active: activeIntervalSchema.optional(),
4278
+ pendingTurnStart: number().int().nonnegative().optional(),
4279
+ descriptorSeen: boolean()
4280
+ }).strict();
4281
+ const identityValueSchema = discriminatedUnion("mode", [object({
4282
+ mode: literal("one-shot"),
4283
+ label: string().optional(),
4284
+ seq: number().int().nonnegative()
4285
+ }).strict(), object({
4286
+ mode: literal("continuable"),
4287
+ label: string(),
4288
+ seq: number().int().nonnegative()
4289
+ }).strict()]);
4290
+ identityValueSchema.nullable();
4291
+ object({ identity: identityValueSchema.optional() }).strict();
4292
+ new TextEncoder();
4293
+ new TextDecoder();
4294
+ Object.freeze({
4295
+ outputSchema: false,
4296
+ depthLimit: false,
4297
+ toolFilter: false,
4298
+ persona: false
4299
+ });
4300
+ //#endregion
11
4301
  //#region ../voice-assistant/src/tool.ts
12
4302
  const VOICE_MESSAGE_SECTION_ORDER = 118;
13
4303
  /**
@@ -127,6 +4417,9 @@ const Config = z.object({
127
4417
  restoreConversation: z.boolean().default(true),
128
4418
  maxRestoredUtterances: z.natural().min(1).default(24),
129
4419
  taskSessionPolicy: z.union(["isolated", "continuous"]).default("isolated"),
4420
+ taskSessionRotationRatio: z.number().min(.5).max(.99).default(.95),
4421
+ taskSessionRotationReserveTokens: z.natural().default(2048),
4422
+ taskSessionHandoffMaxChars: z.natural().min(1024).default(12e3),
130
4423
  completedAnnouncement: z.string().default("任务已完成。"),
131
4424
  failedAnnouncement: z.string().default("任务失败了,请查看屏幕上的错误信息。"),
132
4425
  cancelledAnnouncement: z.string().default("任务已取消。"),
@@ -144,9 +4437,11 @@ const VOICE_SESSION_EVENT_TYPES = [
144
4437
  "voice/utterance-start",
145
4438
  "voice/utterance-end"
146
4439
  ];
4440
+ const SUBAGENT_DESCRIPTOR_EVENT_TYPE = "subagent/descriptor";
147
4441
  function registerVoiceSessionEventTypes(eventTypes) {
148
4442
  const writable = eventTypes;
149
4443
  for (const type of VOICE_SESSION_EVENT_TYPES) writable.add(type);
4444
+ writable.add(SUBAGENT_DESCRIPTOR_EVENT_TYPE);
150
4445
  }
151
4446
  registerVoiceSessionEventTypes(KNOWN_SESSION_EVENT_TYPES);
152
4447
  try {
@@ -587,6 +4882,13 @@ function optionalSessionTitle(ctx) {
587
4882
  return;
588
4883
  }
589
4884
  }
4885
+ function optionalTokenMeter(ctx) {
4886
+ try {
4887
+ return ctx.get("tokenMeter");
4888
+ } catch {
4889
+ return;
4890
+ }
4891
+ }
590
4892
  function recallWithSoftTimeout(operation, timeoutMs) {
591
4893
  const deadline = Math.max(1, timeoutMs);
592
4894
  return new Promise((resolve) => {
@@ -649,19 +4951,37 @@ const REWRITE_EVENT_INSTRUCTIONS = {
649
4951
  warning: "这是警告信息。简洁说明风险、影响以及用户需要知道的事项。",
650
4952
  error: "这是失败信息。明确说明没有完成、主要原因以及可行的下一步。"
651
4953
  };
652
- const VOICE_TITLE_SYSTEM_PROMPT = `你是语音会话标题生成器。根据用户第一条有实际内容的语音请求,生成一个简短、准确、便于在会话列表中识别的中文标题。
4954
+ const VOICE_TITLE_MAX_WIDTH = 30;
4955
+ const VOICE_TITLE_SYSTEM_PROMPT = `你是语音会话标题生成器。根据用户第一条有实际内容的语音请求,生成一个简短、准确、便于在会话列表中识别的标题。
653
4956
 
654
- 只输出标题本身,不要解释,不要引号,不要 Markdown,不要句末标点,不要使用“语音会话”“新会话”等泛化名称,不超过 12 个汉字。不要加入文件大小、行数、路径等执行细节。`;
4957
+ 只输出标题本身,不要解释,不要引号,不要 Markdown,不要句末标点,不要使用“语音会话”“新会话”等泛化名称,不超过 30 个显示宽度单位(汉字、全角字符和 emoji 按 2 个单位,英文字母、数字、半角符号和空格按 1 个单位)。不要加入文件大小、行数、路径等执行细节。`;
4958
+ function voiceTitleGraphemeWidth(grapheme) {
4959
+ if (/[\p{Extended_Pictographic}\p{Emoji_Presentation}\p{Regional_Indicator}]/u.test(grapheme)) return 2;
4960
+ const codePoint = grapheme.codePointAt(0) ?? 0;
4961
+ if (codePoint >= 4352 && codePoint <= 4447 || codePoint >= 9001 && codePoint <= 9002 || codePoint >= 11904 && codePoint <= 12350 || codePoint >= 12352 && codePoint <= 12543 || codePoint >= 12544 && codePoint <= 12591 || codePoint >= 12592 && codePoint <= 12687 || codePoint >= 12688 && codePoint <= 12799 || codePoint >= 13312 && codePoint <= 19903 || codePoint >= 19968 && codePoint <= 40959 || codePoint >= 43360 && codePoint <= 43391 || codePoint >= 44032 && codePoint <= 55295 || codePoint >= 63744 && codePoint <= 64255 || codePoint >= 65040 && codePoint <= 65135 || codePoint >= 65281 && codePoint <= 65376 || codePoint >= 65504 && codePoint <= 65510) return 2;
4962
+ return 1;
4963
+ }
4964
+ function voiceTitleGraphemes(value) {
4965
+ return Array.from(new Intl.Segmenter(void 0, { granularity: "grapheme" }).segment(value), (part) => part.segment);
4966
+ }
655
4967
  function voiceTitleCandidate(value) {
656
4968
  const normalized = value.replace(/```[\s\S]*?```/gu, "").replace(/^\s*(?:标题|title)\s*[::]\s*/iu, "").replace(/["'「」『』]/gu, "").split(/\r?\n/u, 1)[0].replace(/[。!?!?;;,,::]+$/u, "").replace(/\s+/gu, " ").trim();
657
- return Array.from(normalized).slice(0, 12).join("");
4969
+ let width = 0;
4970
+ let result = "";
4971
+ for (const grapheme of voiceTitleGraphemes(normalized)) {
4972
+ const graphemeWidth = voiceTitleGraphemeWidth(grapheme);
4973
+ if (width + graphemeWidth > VOICE_TITLE_MAX_WIDTH) break;
4974
+ result += grapheme;
4975
+ width += graphemeWidth;
4976
+ }
4977
+ return result.trimEnd();
658
4978
  }
659
4979
  function isMeaningfulVoiceTitleInput(value) {
660
4980
  const normalized = value.replace(/\s+/gu, "").trim();
661
4981
  if (Array.from(normalized).length < 4) return false;
662
4982
  return !/^(?:你好|您好|嗨|哈喽|喂|在吗|有人吗|测试|谢谢|好的)[,。!?!?、]*$/u.test(normalized);
663
4983
  }
664
- async function generateVoiceSessionTitle(ctx, session, input, titleService) {
4984
+ async function generateVoiceTitleCandidate(ctx, input) {
665
4985
  let candidate = "";
666
4986
  try {
667
4987
  const llm = ctx.get("llm");
@@ -691,26 +5011,102 @@ async function generateVoiceSessionTitle(ctx, session, input, titleService) {
691
5011
  ctx.logger.warn(error instanceof Error ? error : new Error(String(error)));
692
5012
  }
693
5013
  if (candidate === "") candidate = voiceTitleCandidate(input);
694
- if (candidate === "" || titleService.get(session) !== void 0) return;
5014
+ return candidate;
5015
+ }
5016
+ function pinVoiceSessionTitle(ctx, session, candidate, titleService) {
5017
+ if (candidate === "") return;
695
5018
  try {
5019
+ if (titleService.get(session) !== void 0) return;
696
5020
  titleService.rename(session, candidate);
697
5021
  } catch (error) {
698
5022
  ctx.logger.warn(error instanceof Error ? error : new Error(String(error)));
699
5023
  }
700
5024
  }
5025
+ async function generateVoiceSessionTitle(ctx, session, input, titleService) {
5026
+ pinVoiceSessionTitle(ctx, session, await generateVoiceTitleCandidate(ctx, input), titleService);
5027
+ }
701
5028
  /** Install the driver. @param ctx - composed Agent and voice context. @param config - driver copy and queue bounds. */
702
5029
  function apply(ctx, config = {}) {
703
5030
  const bindings = /* @__PURE__ */ new Map();
704
5031
  const taskBindings = /* @__PURE__ */ new Map();
705
5032
  const handles = /* @__PURE__ */ new Map();
5033
+ const childModelSelections = /* @__PURE__ */ new Map();
5034
+ const childModelSelectionLoads = /* @__PURE__ */ new Map();
706
5035
  const audioResponsesSeen = /* @__PURE__ */ new Set();
707
5036
  const maxPending = config.maxPendingObservations ?? 64;
708
5037
  const maxRestoredUtterances = config.maxRestoredUtterances ?? 24;
709
5038
  const memoryRecallTimeoutMs = config.memoryRecallTimeoutMs ?? 250;
710
5039
  const evidenceSearchTimeoutMs = config.evidenceSearchTimeoutMs ?? 120;
711
5040
  const evidenceCacheTtlMs = config.evidenceCacheTtlMs ?? 6e5;
5041
+ const taskSessionRotationRatio = config.taskSessionRotationRatio ?? .95;
5042
+ const taskSessionRotationReserveTokens = config.taskSessionRotationReserveTokens ?? 2048;
5043
+ const taskSessionHandoffMaxChars = config.taskSessionHandoffMaxChars ?? 12e3;
712
5044
  const evidenceCache = /* @__PURE__ */ new Map();
713
5045
  const detailIndex = /* @__PURE__ */ new Map();
5046
+ const rememberChildModelSelection = (childSessionId, parentSessionId, agent, selection) => {
5047
+ const existing = childModelSelections.get(childSessionId);
5048
+ if (existing !== void 0) {
5049
+ existing.ref.current = selection;
5050
+ return;
5051
+ }
5052
+ const ref = {
5053
+ current: selection,
5054
+ assembled: void 0
5055
+ };
5056
+ const dispose = installModelSelection(agent.ctx, ref);
5057
+ childModelSelections.set(childSessionId, {
5058
+ parentSessionId,
5059
+ ref,
5060
+ dispose
5061
+ });
5062
+ };
5063
+ const childModelSelectionFor = async (sessionId) => {
5064
+ const existing = childModelSelections.get(sessionId);
5065
+ if (existing !== void 0) return existing;
5066
+ const loading = childModelSelectionLoads.get(sessionId);
5067
+ if (loading !== void 0) return loading;
5068
+ const load = (async () => {
5069
+ const session = ctx.sessions.get(sessionId);
5070
+ const persisted = session === void 0 ? await ctx.get("sessionPersistence")?.inspect(sessionId) : void 0;
5071
+ const header = session?.header ?? persisted?.meta;
5072
+ const events = session?.events ?? persisted?.events;
5073
+ if (header?.origin !== "subagent" || header.parentSession === void 0 || events === void 0) return void 0;
5074
+ if (foldSubagentDescriptor(events)?.provider !== "voice-assistant") return void 0;
5075
+ const logged = foldRequestHeader(events)?.config;
5076
+ const defaults = ctx.agentDefaultModel.currentSelection();
5077
+ const selection = {
5078
+ provider: logged?.provider ?? defaults.provider,
5079
+ model: logged?.model ?? defaults.model,
5080
+ ...logged?.reasoningEffort === void 0 ? {} : { reasoningEffort: logged.reasoningEffort }
5081
+ };
5082
+ const agent = ctx.agents.get(sessionId);
5083
+ if (agent !== void 0) {
5084
+ rememberChildModelSelection(sessionId, header.parentSession, agent, selection);
5085
+ return childModelSelections.get(sessionId);
5086
+ }
5087
+ const resource = await resumeTaskAgent(bindingFor(header.parentSession), sessionId, selection);
5088
+ return childModelSelections.get(sessionId) ?? (() => {
5089
+ const ref = {
5090
+ current: selection,
5091
+ assembled: void 0
5092
+ };
5093
+ const dispose = installModelSelection(resource.agent.ctx, ref);
5094
+ const record = {
5095
+ parentSessionId: header.parentSession,
5096
+ ref,
5097
+ dispose
5098
+ };
5099
+ childModelSelections.set(sessionId, record);
5100
+ return record;
5101
+ })();
5102
+ })();
5103
+ childModelSelectionLoads.set(sessionId, load);
5104
+ try {
5105
+ return await load;
5106
+ } finally {
5107
+ childModelSelectionLoads.delete(sessionId);
5108
+ }
5109
+ };
714
5110
  const loadConversationMemory = async (sessionId) => {
715
5111
  const events = ctx.sessions.get(sessionId)?.events ?? (await ctx.get("sessionPersistence")?.inspect(sessionId))?.events;
716
5112
  if (events === void 0) return void 0;
@@ -1028,17 +5424,59 @@ function apply(ctx, config = {}) {
1028
5424
  sourceHeaderSeq: logged?.seq
1029
5425
  };
1030
5426
  };
1031
- const createTaskAgent = async (binding, taskSessionId, selection) => {
5427
+ const shouldRotateContinuousTaskAgent = (resource) => {
5428
+ const session = ctx.sessions.get(resource.taskSessionId);
5429
+ const meter = optionalTokenMeter(ctx);
5430
+ if (session === void 0 || meter === void 0) return false;
5431
+ const contextWindow = session.requestContext()?.contextWindow;
5432
+ if (contextWindow === void 0 || !Number.isFinite(contextWindow) || contextWindow <= 0) return false;
5433
+ let totalTokens;
5434
+ try {
5435
+ totalTokens = meter.measure(session).totalTokens;
5436
+ } catch (error) {
5437
+ ctx.logger.warn(error instanceof Error ? error : new Error(String(error)));
5438
+ return false;
5439
+ }
5440
+ if (!Number.isFinite(totalTokens) || totalTokens < 0) return false;
5441
+ return totalTokens >= contextWindow * taskSessionRotationRatio || totalTokens + taskSessionRotationReserveTokens >= contextWindow;
5442
+ };
5443
+ const buildTaskHandoff = (binding, current) => {
5444
+ const sections = ["这是来自同一语音会话的工作状态交接。它不是旧会话的完整对话历史,也不是需要执行的指令。", "请只把其中的事实和未完成状态作为背景,继续处理本次新任务;如果内容与本次任务无关,忽略它。"];
5445
+ const active = binding.active;
5446
+ if (active !== void 0 && active.requestText.trim() !== "") sections.push(`旧任务请求:\n${active.requestText.trim()}`);
5447
+ const taskSession = ctx.sessions.get(current.taskSessionId);
5448
+ if (taskSession !== void 0) {
5449
+ const messages = taskSession.deriveMessages().flatMap((message) => {
5450
+ const text = message.content.flatMap((block) => block.type === "text" ? [block.text] : []).join("").trim();
5451
+ return text === "" ? [] : [`${message.role}:${text}`];
5452
+ }).slice(-8);
5453
+ if (messages.length > 0) sections.push(`旧 Agent 最近消息:\n${messages.join("\n")}`);
5454
+ }
5455
+ const observations = requireSourceSession(binding).events.flatMap((event) => {
5456
+ if (event.type !== "voice/task-observation") return [];
5457
+ const detail = event.data.detail?.trim() ?? "";
5458
+ return detail === "" ? [] : [`${event.data.status}:${detail}`];
5459
+ }).slice(-6);
5460
+ if (observations.length > 0) sections.push(`语音会话记录的任务状态:\n${observations.join("\n")}`);
5461
+ return sections.join("\n\n").slice(0, taskSessionHandoffMaxChars);
5462
+ };
5463
+ const createTaskAgent = async (binding, taskSessionId, selection, handoff, label = "语音委派任务") => {
5464
+ const titleService = optionalSessionTitle(ctx);
5465
+ const titleInput = label.trim() === "" ? "语音委派任务" : label.trim();
1032
5466
  const sourceAgent = await ensureAgent(binding);
5467
+ const generatedLabelPromise = titleService === void 0 ? Promise.resolve(voiceTitleCandidate(titleInput)) : generateVoiceTitleCandidate(ctx, titleInput);
1033
5468
  const sourceSession = ctx.sessions.get(binding.sessionId);
1034
5469
  if (sourceSession === void 0) throw new Error(`voice-assistant: source session "${binding.sessionId}" is not live`);
1035
5470
  const presetId = resolveSessionPreset(sourceSession);
1036
5471
  const presets = ctx.get("agentPresets");
1037
5472
  let disposeVoiceMessage;
1038
- const handle = await ctx.agents.create({
5473
+ const [handle, generatedLabel] = await Promise.all([ctx.agents.create({
1039
5474
  sessionId: taskSessionId,
1040
5475
  meta: {
1041
5476
  ...sourceSession.header.cwd === void 0 ? {} : { cwd: sourceSession.header.cwd },
5477
+ parentSession: binding.sessionId,
5478
+ origin: "subagent",
5479
+ delegationDepth: (sourceSession.header.delegationDepth ?? 0) + 1,
1042
5480
  ...presetId === void 0 ? {} : { agentPreset: presetId }
1043
5481
  },
1044
5482
  agentOptions: {
@@ -1049,7 +5487,24 @@ function apply(ctx, config = {}) {
1049
5487
  presets?.composeFrom(agentCtx, sourceAgent.ctx);
1050
5488
  disposeVoiceMessage = installVoiceMessageTool(agentCtx, (input) => sendVoiceMessage(binding, input), () => binding.active?.id);
1051
5489
  }
5490
+ }), generatedLabelPromise]);
5491
+ rememberChildModelSelection(taskSessionId, binding.sessionId, handle.agent, selection);
5492
+ const mode = (config.taskSessionPolicy ?? "isolated") === "continuous" ? "continuable" : "one-shot";
5493
+ const normalizedLabel = generatedLabel === "" ? "语音委派任务" : generatedLabel;
5494
+ const descriptor = mode === "continuable" ? snapshotSubagentDescriptor({
5495
+ mode,
5496
+ provider: "voice-assistant",
5497
+ label: normalizedLabel,
5498
+ agentProvider: selection.provider,
5499
+ agentModel: selection.model
5500
+ }) : snapshotSubagentDescriptor({
5501
+ mode,
5502
+ provider: "voice-assistant",
5503
+ label: normalizedLabel
1052
5504
  });
5505
+ const childSession = handle.agent.session;
5506
+ if (titleService !== void 0) pinVoiceSessionTitle(ctx, childSession, normalizedLabel, titleService);
5507
+ childSession.append.call(childSession, SUBAGENT_DESCRIPTOR_EVENT_TYPE, descriptor);
1053
5508
  handles.set(taskSessionId, handle);
1054
5509
  try {
1055
5510
  await (ctx.get("workspaceRegistry")?.list().find((candidate) => candidate.sessionIds.includes(binding.sessionId)))?.attachSession(taskSessionId);
@@ -1063,6 +5518,16 @@ function apply(ctx, config = {}) {
1063
5518
  await handle.dispose();
1064
5519
  throw new Error("voice-assistant: delegated Agent setup did not install send_voice_message");
1065
5520
  }
5521
+ if (handoff !== void 0 && handoff.trim() !== "") handle.agent.inject(createUserMessage({
5522
+ content: [{
5523
+ type: "text",
5524
+ text: `<voice_task_handoff>\n${handoff}\n</voice_task_handoff>`
5525
+ }],
5526
+ source: {
5527
+ kind: "plugin",
5528
+ plugin: "voice-assistant"
5529
+ }
5530
+ }));
1066
5531
  return {
1067
5532
  agent: handle.agent,
1068
5533
  disposeVoiceMessage
@@ -1070,10 +5535,13 @@ function apply(ctx, config = {}) {
1070
5535
  };
1071
5536
  const resumeTaskAgent = async (binding, taskSessionId, selection) => {
1072
5537
  const live = ctx.agents.get(taskSessionId);
1073
- if (live !== void 0) return {
1074
- agent: live,
1075
- disposeVoiceMessage: installVoiceMessageTool(live.ctx, (input) => sendVoiceMessage(binding, input), () => binding.active?.id)
1076
- };
5538
+ if (live !== void 0) {
5539
+ rememberChildModelSelection(taskSessionId, binding.sessionId, live, selection);
5540
+ return {
5541
+ agent: live,
5542
+ disposeVoiceMessage: installVoiceMessageTool(live.ctx, (input) => sendVoiceMessage(binding, input), () => binding.active?.id)
5543
+ };
5544
+ }
1077
5545
  const sourceAgent = await ensureAgent(binding);
1078
5546
  const presets = ctx.get("agentPresets");
1079
5547
  let disposeVoiceMessage;
@@ -1088,6 +5556,7 @@ function apply(ctx, config = {}) {
1088
5556
  disposeVoiceMessage = installVoiceMessageTool(agentCtx, (input) => sendVoiceMessage(binding, input), () => binding.active?.id);
1089
5557
  }
1090
5558
  });
5559
+ rememberChildModelSelection(taskSessionId, binding.sessionId, handle.agent, selection);
1091
5560
  handles.set(taskSessionId, handle);
1092
5561
  if (disposeVoiceMessage === void 0) {
1093
5562
  handles.delete(taskSessionId);
@@ -1099,17 +5568,62 @@ function apply(ctx, config = {}) {
1099
5568
  disposeVoiceMessage
1100
5569
  };
1101
5570
  };
1102
- const ensureContinuousTaskAgent = async (binding) => {
5571
+ const ensureContinuousTaskAgent = async (binding, label) => {
1103
5572
  const { selection, sourceHeaderSeq } = taskModelSelection(binding);
1104
5573
  const current = binding.continuousTaskAgent;
1105
5574
  if (current !== void 0 && sameModelSelection(current.selection, selection)) {
1106
- if (current.sourceHeaderSeq === sourceHeaderSeq) return current;
1107
- const refreshed = {
1108
- ...current,
1109
- sourceHeaderSeq
5575
+ if (!shouldRotateContinuousTaskAgent(current)) {
5576
+ if (current.sourceHeaderSeq === sourceHeaderSeq) return current;
5577
+ const refreshed = {
5578
+ ...current,
5579
+ sourceHeaderSeq
5580
+ };
5581
+ binding.continuousTaskAgent = refreshed;
5582
+ return refreshed;
5583
+ }
5584
+ const handoff = buildTaskHandoff(binding, current);
5585
+ const taskSessionId = SessionId(`session-${randomUUID()}`);
5586
+ try {
5587
+ current.disposeVoiceMessage();
5588
+ } catch (error) {
5589
+ ctx.logger.warn(error instanceof Error ? error : new Error(String(error)));
5590
+ }
5591
+ let created;
5592
+ try {
5593
+ created = await createTaskAgent(binding, taskSessionId, selection, handoff, label);
5594
+ } catch (error) {
5595
+ try {
5596
+ const restored = installVoiceMessageTool(current.agent.ctx, (input) => sendVoiceMessage(binding, input), () => binding.active?.id);
5597
+ binding.continuousTaskAgent = {
5598
+ ...current,
5599
+ sourceHeaderSeq,
5600
+ disposeVoiceMessage: restored
5601
+ };
5602
+ taskBindings.set(current.taskSessionId, binding);
5603
+ } catch (restoreError) {
5604
+ ctx.logger.warn(restoreError instanceof Error ? restoreError : new Error(String(restoreError)));
5605
+ }
5606
+ throw error;
5607
+ }
5608
+ const resource = {
5609
+ taskSessionId,
5610
+ selection,
5611
+ sourceHeaderSeq,
5612
+ ...created
1110
5613
  };
1111
- binding.continuousTaskAgent = refreshed;
1112
- return refreshed;
5614
+ binding.continuousTaskAgent = resource;
5615
+ taskBindings.delete(current.taskSessionId);
5616
+ taskBindings.set(taskSessionId, binding);
5617
+ const sourceSession = requireSourceSession(binding);
5618
+ sourceSession.append("voice/task-session-bound", { taskSessionId });
5619
+ sourceSession.append("voice/agent-binding-state", {
5620
+ voiceConversationId: binding.sessionId,
5621
+ agentSessionId: taskSessionId,
5622
+ ...sourceSession.header.cwd === void 0 ? {} : { workspacePath: sourceSession.header.cwd },
5623
+ lastUsedAt: Date.now(),
5624
+ status: "idle"
5625
+ });
5626
+ return resource;
1113
5627
  }
1114
5628
  if (current !== void 0) {
1115
5629
  binding.continuousTaskAgent = void 0;
@@ -1157,7 +5671,7 @@ function apply(ctx, config = {}) {
1157
5671
  taskSessionId,
1158
5672
  selection,
1159
5673
  sourceHeaderSeq,
1160
- ...await createTaskAgent(binding, taskSessionId, selection)
5674
+ ...await createTaskAgent(binding, taskSessionId, selection, void 0, label)
1161
5675
  };
1162
5676
  binding.continuousTaskAgent = resource;
1163
5677
  taskBindings.set(taskSessionId, binding);
@@ -1463,13 +5977,13 @@ function apply(ctx, config = {}) {
1463
5977
  });
1464
5978
  let created;
1465
5979
  try {
1466
- if (continuous) created = await ensureContinuousTaskAgent(binding);
5980
+ if (continuous) created = await ensureContinuousTaskAgent(binding, requestText);
1467
5981
  else {
1468
5982
  const taskSessionId = SessionId(`session-${randomUUID()}`);
1469
5983
  const { selection } = taskModelSelection(binding);
1470
5984
  created = {
1471
5985
  taskSessionId,
1472
- ...await createTaskAgent(binding, taskSessionId, selection)
5986
+ ...await createTaskAgent(binding, taskSessionId, selection, void 0, requestText)
1473
5987
  };
1474
5988
  }
1475
5989
  debugVoiceLatency("delegation-init-end", {
@@ -1583,6 +6097,21 @@ function apply(ctx, config = {}) {
1583
6097
  task.requestText += `\n补充要求:${call.command.message}`;
1584
6098
  const waitingForReply = task.waitingUser && task.taskTurn === void 0;
1585
6099
  task.waitingUser = false;
6100
+ if (waitingForReply && (config.taskSessionPolicy ?? "isolated") === "continuous") try {
6101
+ const resource = await ensureContinuousTaskAgent(binding, call.command.message);
6102
+ if (resource.taskSessionId !== task.taskSessionId) {
6103
+ taskBindings.delete(task.taskSessionId);
6104
+ task.taskSessionId = resource.taskSessionId;
6105
+ task.agent = resource.agent;
6106
+ taskBindings.set(task.taskSessionId, binding);
6107
+ }
6108
+ } catch (error) {
6109
+ task.messageIds.delete(message.id);
6110
+ task.requestText = previousRequestText;
6111
+ task.waitingUser = waitingForReply;
6112
+ backendUnavailable(error);
6113
+ return;
6114
+ }
1586
6115
  try {
1587
6116
  if (waitingForReply) task.agent.followup(message);
1588
6117
  else task.agent.steer(message);
@@ -1806,6 +6335,97 @@ function apply(ctx, config = {}) {
1806
6335
  }
1807
6336
  });
1808
6337
  });
6338
+ const installApiProxyCompatibility = (apiProxy) => {
6339
+ const originalModels = apiProxy.sessions.models;
6340
+ const originalSelectModel = apiProxy.sessions.selectModel;
6341
+ apiProxy.sessions.models = async (request) => {
6342
+ const payload = request.payload;
6343
+ const sessionId = payload?.sessionId;
6344
+ const child = sessionId === void 0 ? void 0 : await childModelSelectionFor(sessionId);
6345
+ if (child === void 0) return originalModels.call(apiProxy.sessions, request);
6346
+ const parentRequest = {
6347
+ ...request,
6348
+ payload: {
6349
+ ...payload,
6350
+ sessionId: child.parentSessionId
6351
+ }
6352
+ };
6353
+ const response = await originalModels.call(apiProxy.sessions, parentRequest);
6354
+ if (typeof response !== "object" || response === null) return response;
6355
+ const result = response.result;
6356
+ if (typeof result !== "object" || result === null || result.ok !== true) return response;
6357
+ const value = result.value;
6358
+ if (typeof value !== "object" || value === null) return response;
6359
+ return {
6360
+ ...response,
6361
+ result: {
6362
+ ...result,
6363
+ value: {
6364
+ ...value,
6365
+ current: { ...child.ref.current }
6366
+ }
6367
+ }
6368
+ };
6369
+ };
6370
+ apiProxy.sessions.selectModel = async (request) => {
6371
+ const body = request;
6372
+ const sessionId = body.payload?.sessionId;
6373
+ const child = sessionId === void 0 ? void 0 : await childModelSelectionFor(sessionId);
6374
+ if (child === void 0) return originalSelectModel.call(apiProxy.sessions, request);
6375
+ const provider = body.payload?.provider;
6376
+ const model = body.payload?.model;
6377
+ if (provider === void 0 || model === void 0) return originalSelectModel.call(apiProxy.sessions, request);
6378
+ try {
6379
+ const resolved = await ctx.get("llm").resolveCallConfig({
6380
+ provider,
6381
+ model,
6382
+ ...body.payload?.reasoningEffort === void 0 ? {} : { reasoningEffort: ReasoningEffortId(body.payload.reasoningEffort) }
6383
+ });
6384
+ const selected = {
6385
+ provider: resolved.provider,
6386
+ model: resolved.model,
6387
+ ...resolved.reasoningEffort === void 0 ? {} : { reasoningEffort: resolved.reasoningEffort }
6388
+ };
6389
+ child.ref.current = selected;
6390
+ return {
6391
+ rpcId: body.rpcId,
6392
+ result: {
6393
+ ok: true,
6394
+ value: { selected }
6395
+ }
6396
+ };
6397
+ } catch (error) {
6398
+ return {
6399
+ rpcId: body.rpcId,
6400
+ result: {
6401
+ ok: false,
6402
+ error: {
6403
+ code: "model-unavailable",
6404
+ message: error instanceof Error ? error.message : String(error),
6405
+ details: {
6406
+ provider,
6407
+ model
6408
+ }
6409
+ }
6410
+ }
6411
+ };
6412
+ }
6413
+ };
6414
+ ctx.effect(() => () => {
6415
+ apiProxy.sessions.models = originalModels;
6416
+ apiProxy.sessions.selectModel = originalSelectModel;
6417
+ for (const child of childModelSelections.values()) child.dispose();
6418
+ childModelSelections.clear();
6419
+ }, "voice-assistant child model selection API");
6420
+ };
6421
+ const contextWithInject = ctx;
6422
+ if (typeof contextWithInject.inject === "function") contextWithInject.inject(["apiProxy"], (apiContext) => {
6423
+ installApiProxyCompatibility(apiContext.apiProxy);
6424
+ });
6425
+ else try {
6426
+ const apiProxy = ctx.get("apiProxy");
6427
+ if (apiProxy !== void 0) installApiProxyCompatibility(apiProxy);
6428
+ } catch {}
1809
6429
  ctx.effect(() => async () => {
1810
6430
  await Promise.all([...bindings.values()].map((binding) => binding.chain));
1811
6431
  const failures = [];