@volley/recognition-client-sdk 0.1.297 → 0.1.382

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,35 +1,35 @@
1
- // ../../node_modules/.pnpm/zod@3.22.5/node_modules/zod/lib/index.mjs
1
+ // ../../node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs
2
2
  var util;
3
- (function(util2) {
4
- util2.assertEqual = (val) => val;
3
+ (function(util3) {
4
+ util3.assertEqual = (val) => val;
5
5
  function assertIs(_arg) {
6
6
  }
7
- util2.assertIs = assertIs;
7
+ util3.assertIs = assertIs;
8
8
  function assertNever(_x) {
9
9
  throw new Error();
10
10
  }
11
- util2.assertNever = assertNever;
12
- util2.arrayToEnum = (items) => {
11
+ util3.assertNever = assertNever;
12
+ util3.arrayToEnum = (items) => {
13
13
  const obj = {};
14
14
  for (const item of items) {
15
15
  obj[item] = item;
16
16
  }
17
17
  return obj;
18
18
  };
19
- util2.getValidEnumValues = (obj) => {
20
- const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
19
+ util3.getValidEnumValues = (obj) => {
20
+ const validKeys = util3.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
21
21
  const filtered = {};
22
22
  for (const k of validKeys) {
23
23
  filtered[k] = obj[k];
24
24
  }
25
- return util2.objectValues(filtered);
25
+ return util3.objectValues(filtered);
26
26
  };
27
- util2.objectValues = (obj) => {
28
- return util2.objectKeys(obj).map(function(e) {
27
+ util3.objectValues = (obj) => {
28
+ return util3.objectKeys(obj).map(function(e) {
29
29
  return obj[e];
30
30
  });
31
31
  };
32
- util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
32
+ util3.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
33
33
  const keys = [];
34
34
  for (const key in object) {
35
35
  if (Object.prototype.hasOwnProperty.call(object, key)) {
@@ -38,19 +38,19 @@ var util;
38
38
  }
39
39
  return keys;
40
40
  };
41
- util2.find = (arr, checker) => {
41
+ util3.find = (arr, checker) => {
42
42
  for (const item of arr) {
43
43
  if (checker(item))
44
44
  return item;
45
45
  }
46
46
  return void 0;
47
47
  };
48
- util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
48
+ util3.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
49
49
  function joinValues(array, separator = " | ") {
50
50
  return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
51
51
  }
52
- util2.joinValues = joinValues;
53
- util2.jsonStringifyReplacer = (_, value) => {
52
+ util3.joinValues = joinValues;
53
+ util3.jsonStringifyReplacer = (_, value) => {
54
54
  if (typeof value === "bigint") {
55
55
  return value.toString();
56
56
  }
@@ -58,8 +58,8 @@ var util;
58
58
  };
59
59
  })(util || (util = {}));
60
60
  var objectUtil;
61
- (function(objectUtil2) {
62
- objectUtil2.mergeShapes = (first, second) => {
61
+ (function(objectUtil3) {
62
+ objectUtil3.mergeShapes = (first, second) => {
63
63
  return {
64
64
  ...first,
65
65
  ...second
@@ -441,9 +441,9 @@ var isDirty = (x) => x.status === "dirty";
441
441
  var isValid = (x) => x.status === "valid";
442
442
  var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
443
443
  var errorUtil;
444
- (function(errorUtil2) {
445
- errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
446
- errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
444
+ (function(errorUtil3) {
445
+ errorUtil3.errToObj = (message) => typeof message === "string" ? { message } : message || {};
446
+ errorUtil3.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
447
447
  })(errorUtil || (errorUtil = {}));
448
448
  var ParseInputLazyPath = class {
449
449
  constructor(parent, value, path, key) {
@@ -486,12 +486,12 @@ var handleResult = (ctx, result) => {
486
486
  function processCreateParams(params) {
487
487
  if (!params)
488
488
  return {};
489
- const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
490
- if (errorMap2 && (invalid_type_error || required_error)) {
489
+ const { errorMap: errorMap3, invalid_type_error, required_error, description } = params;
490
+ if (errorMap3 && (invalid_type_error || required_error)) {
491
491
  throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
492
492
  }
493
- if (errorMap2)
494
- return { errorMap: errorMap2, description };
493
+ if (errorMap3)
494
+ return { errorMap: errorMap3, description };
495
495
  const customMap = (iss, ctx) => {
496
496
  if (iss.code !== "invalid_type")
497
497
  return { message: ctx.defaultError };
@@ -3525,43 +3525,43 @@ var late = {
3525
3525
  object: ZodObject.lazycreate
3526
3526
  };
3527
3527
  var ZodFirstPartyTypeKind;
3528
- (function(ZodFirstPartyTypeKind2) {
3529
- ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
3530
- ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
3531
- ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
3532
- ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
3533
- ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
3534
- ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
3535
- ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
3536
- ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
3537
- ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
3538
- ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
3539
- ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
3540
- ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
3541
- ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
3542
- ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
3543
- ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
3544
- ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
3545
- ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
3546
- ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
3547
- ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
3548
- ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
3549
- ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
3550
- ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
3551
- ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
3552
- ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
3553
- ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
3554
- ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
3555
- ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
3556
- ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
3557
- ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
3558
- ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
3559
- ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
3560
- ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
3561
- ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
3562
- ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
3563
- ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
3564
- ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
3528
+ (function(ZodFirstPartyTypeKind3) {
3529
+ ZodFirstPartyTypeKind3["ZodString"] = "ZodString";
3530
+ ZodFirstPartyTypeKind3["ZodNumber"] = "ZodNumber";
3531
+ ZodFirstPartyTypeKind3["ZodNaN"] = "ZodNaN";
3532
+ ZodFirstPartyTypeKind3["ZodBigInt"] = "ZodBigInt";
3533
+ ZodFirstPartyTypeKind3["ZodBoolean"] = "ZodBoolean";
3534
+ ZodFirstPartyTypeKind3["ZodDate"] = "ZodDate";
3535
+ ZodFirstPartyTypeKind3["ZodSymbol"] = "ZodSymbol";
3536
+ ZodFirstPartyTypeKind3["ZodUndefined"] = "ZodUndefined";
3537
+ ZodFirstPartyTypeKind3["ZodNull"] = "ZodNull";
3538
+ ZodFirstPartyTypeKind3["ZodAny"] = "ZodAny";
3539
+ ZodFirstPartyTypeKind3["ZodUnknown"] = "ZodUnknown";
3540
+ ZodFirstPartyTypeKind3["ZodNever"] = "ZodNever";
3541
+ ZodFirstPartyTypeKind3["ZodVoid"] = "ZodVoid";
3542
+ ZodFirstPartyTypeKind3["ZodArray"] = "ZodArray";
3543
+ ZodFirstPartyTypeKind3["ZodObject"] = "ZodObject";
3544
+ ZodFirstPartyTypeKind3["ZodUnion"] = "ZodUnion";
3545
+ ZodFirstPartyTypeKind3["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
3546
+ ZodFirstPartyTypeKind3["ZodIntersection"] = "ZodIntersection";
3547
+ ZodFirstPartyTypeKind3["ZodTuple"] = "ZodTuple";
3548
+ ZodFirstPartyTypeKind3["ZodRecord"] = "ZodRecord";
3549
+ ZodFirstPartyTypeKind3["ZodMap"] = "ZodMap";
3550
+ ZodFirstPartyTypeKind3["ZodSet"] = "ZodSet";
3551
+ ZodFirstPartyTypeKind3["ZodFunction"] = "ZodFunction";
3552
+ ZodFirstPartyTypeKind3["ZodLazy"] = "ZodLazy";
3553
+ ZodFirstPartyTypeKind3["ZodLiteral"] = "ZodLiteral";
3554
+ ZodFirstPartyTypeKind3["ZodEnum"] = "ZodEnum";
3555
+ ZodFirstPartyTypeKind3["ZodEffects"] = "ZodEffects";
3556
+ ZodFirstPartyTypeKind3["ZodNativeEnum"] = "ZodNativeEnum";
3557
+ ZodFirstPartyTypeKind3["ZodOptional"] = "ZodOptional";
3558
+ ZodFirstPartyTypeKind3["ZodNullable"] = "ZodNullable";
3559
+ ZodFirstPartyTypeKind3["ZodDefault"] = "ZodDefault";
3560
+ ZodFirstPartyTypeKind3["ZodCatch"] = "ZodCatch";
3561
+ ZodFirstPartyTypeKind3["ZodPromise"] = "ZodPromise";
3562
+ ZodFirstPartyTypeKind3["ZodBranded"] = "ZodBranded";
3563
+ ZodFirstPartyTypeKind3["ZodPipeline"] = "ZodPipeline";
3564
+ ZodFirstPartyTypeKind3["ZodReadonly"] = "ZodReadonly";
3565
3565
  })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
3566
3566
  var instanceOfType = (cls, params = {
3567
3567
  message: `Input not instance of ${cls.name}`
@@ -3604,14 +3604,14 @@ var ostring = () => stringType().optional();
3604
3604
  var onumber = () => numberType().optional();
3605
3605
  var oboolean = () => booleanType().optional();
3606
3606
  var coerce = {
3607
- string: ((arg) => ZodString.create({ ...arg, coerce: true })),
3608
- number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
3609
- boolean: ((arg) => ZodBoolean.create({
3607
+ string: (arg) => ZodString.create({ ...arg, coerce: true }),
3608
+ number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
3609
+ boolean: (arg) => ZodBoolean.create({
3610
3610
  ...arg,
3611
3611
  coerce: true
3612
- })),
3613
- bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
3614
- date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
3612
+ }),
3613
+ bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
3614
+ date: (arg) => ZodDate.create({ ...arg, coerce: true })
3615
3615
  };
3616
3616
  var NEVER = INVALID;
3617
3617
  var z = /* @__PURE__ */ Object.freeze({
@@ -3735,9 +3735,12 @@ var RecognitionProvider;
3735
3735
  (function(RecognitionProvider2) {
3736
3736
  RecognitionProvider2["ASSEMBLYAI"] = "assemblyai";
3737
3737
  RecognitionProvider2["DEEPGRAM"] = "deepgram";
3738
+ RecognitionProvider2["ELEVENLABS"] = "elevenlabs";
3739
+ RecognitionProvider2["FIREWORKS"] = "fireworks";
3738
3740
  RecognitionProvider2["GOOGLE"] = "google";
3739
3741
  RecognitionProvider2["GEMINI_BATCH"] = "gemini-batch";
3740
3742
  RecognitionProvider2["OPENAI_BATCH"] = "openai-batch";
3743
+ RecognitionProvider2["OPENAI_REALTIME"] = "openai-realtime";
3741
3744
  })(RecognitionProvider || (RecognitionProvider = {}));
3742
3745
  var RecognitionMode;
3743
3746
  (function(RecognitionMode2) {
@@ -3757,17 +3760,34 @@ var DeepgramModel;
3757
3760
  })(DeepgramModel || (DeepgramModel = {}));
3758
3761
  var GoogleModel;
3759
3762
  (function(GoogleModel2) {
3763
+ GoogleModel2["CHIRP_3"] = "chirp_3";
3764
+ GoogleModel2["CHIRP_2"] = "chirp_2";
3765
+ GoogleModel2["CHIRP"] = "chirp";
3760
3766
  GoogleModel2["LATEST_LONG"] = "latest_long";
3761
3767
  GoogleModel2["LATEST_SHORT"] = "latest_short";
3762
3768
  GoogleModel2["TELEPHONY"] = "telephony";
3763
3769
  GoogleModel2["TELEPHONY_SHORT"] = "telephony_short";
3764
- GoogleModel2["MEDICAL_DICTATION"] = "medical_dictation";
3765
- GoogleModel2["MEDICAL_CONVERSATION"] = "medical_conversation";
3766
3770
  GoogleModel2["DEFAULT"] = "default";
3767
3771
  GoogleModel2["COMMAND_AND_SEARCH"] = "command_and_search";
3768
3772
  GoogleModel2["PHONE_CALL"] = "phone_call";
3769
3773
  GoogleModel2["VIDEO"] = "video";
3770
3774
  })(GoogleModel || (GoogleModel = {}));
3775
+ var FireworksModel;
3776
+ (function(FireworksModel2) {
3777
+ FireworksModel2["ASR_V1"] = "fireworks-asr-large";
3778
+ FireworksModel2["ASR_V2"] = "fireworks-asr-v2";
3779
+ FireworksModel2["WHISPER_V3"] = "whisper-v3";
3780
+ FireworksModel2["WHISPER_V3_TURBO"] = "whisper-v3-turbo";
3781
+ })(FireworksModel || (FireworksModel = {}));
3782
+ var ElevenLabsModel;
3783
+ (function(ElevenLabsModel2) {
3784
+ ElevenLabsModel2["SCRIBE_V2_REALTIME"] = "scribe_v2_realtime";
3785
+ ElevenLabsModel2["SCRIBE_V1"] = "scribe_v1";
3786
+ })(ElevenLabsModel || (ElevenLabsModel = {}));
3787
+ var OpenAIRealtimeModel;
3788
+ (function(OpenAIRealtimeModel2) {
3789
+ OpenAIRealtimeModel2["GPT_4O_MINI_TRANSCRIBE"] = "gpt-4o-mini-transcribe";
3790
+ })(OpenAIRealtimeModel || (OpenAIRealtimeModel = {}));
3771
3791
 
3772
3792
  // ../../libs/types/dist/recognition-result-v1.types.js
3773
3793
  var RecognitionResultTypeV1;
@@ -3781,68 +3801,44 @@ var RecognitionResultTypeV1;
3781
3801
  var TranscriptionResultSchemaV1 = z.object({
3782
3802
  type: z.literal(RecognitionResultTypeV1.TRANSCRIPTION),
3783
3803
  audioUtteranceId: z.string(),
3784
- // audio utterance id for this transcription session
3785
3804
  finalTranscript: z.string(),
3786
- // transcript that is final and won't be overwritten by ASR. default empty string.
3787
3805
  finalTranscriptConfidence: z.number().min(0).max(1).optional(),
3788
- // confidence score for the final transcript (0-1). Optional.
3789
3806
  pendingTranscript: z.string().optional(),
3790
- // transcript that may be overwritten by ASR. Optional.
3791
3807
  pendingTranscriptConfidence: z.number().min(0).max(1).optional(),
3792
- // confidence score for the pending transcript (0-1). Optional.
3793
3808
  is_finished: z.boolean(),
3794
- // entire transcription finished. This will be the last message in the transcription.
3795
3809
  voiceStart: z.number().optional(),
3796
- // voice start time identified by ASR (in milliseconds from stream start). Optional.
3797
3810
  voiceDuration: z.number().optional(),
3798
- // voice duration identified by ASR (in milliseconds, calculated as maxVoiceEnd - voiceStart). Optional.
3799
3811
  voiceEnd: z.number().optional(),
3800
- // voice end time identified by ASR (in milliseconds from stream start). Optional.
3801
3812
  startTimestamp: z.number().optional(),
3802
- // start timestamp of the transcription in milliseconds. Optional.
3803
3813
  endTimestamp: z.number().optional(),
3804
- // end timestamp of the transcription in milliseconds. Optional.
3805
3814
  receivedAtMs: z.number().optional(),
3806
- // server timestamp when this transcript was received (ms since epoch). Optional.
3807
3815
  accumulatedAudioTimeMs: z.number().optional()
3808
3816
  // accumulated audio time watermark in milliseconds. Total duration of all audio chunks sent. Optional.
3809
3817
  });
3810
3818
  var FunctionCallResultSchemaV1 = z.object({
3811
3819
  type: z.literal(RecognitionResultTypeV1.FUNCTION_CALL),
3812
3820
  audioUtteranceId: z.string(),
3813
- // audio utterance id for this function call
3814
3821
  functionName: z.string(),
3815
3822
  functionArgJson: z.string()
3816
3823
  });
3817
3824
  var MetadataResultSchemaV1 = z.object({
3818
3825
  type: z.literal(RecognitionResultTypeV1.METADATA),
3819
3826
  audioUtteranceId: z.string(),
3820
- // audio utterance id for this metadata
3821
3827
  // Timing information
3822
3828
  recordingStartMs: z.number().optional(),
3823
- // When recording started
3824
3829
  recordingEndMs: z.number().optional(),
3825
- // When recording ended
3826
3830
  transcriptEndMs: z.number().optional(),
3827
- // When final transcript was received
3828
3831
  socketCloseAtMs: z.number().optional(),
3829
- // When socket/connection closed
3830
3832
  // Audio Quality Metrics
3831
3833
  duration: z.number().optional(),
3832
- // Duration of the audio in milliseconds
3833
3834
  volume: z.number().optional(),
3834
- // Volume of the audio in decibels
3835
3835
  accumulatedAudioTimeMs: z.number().optional(),
3836
- // Accumulated audio time watermark in milliseconds. Total duration of all audio chunks sent. Optional.
3837
3836
  // Cost Information
3838
3837
  costInUSD: z.number().default(0).optional(),
3839
- // Estimated cost in USD for this recognition session. Default: 0
3840
3838
  // ASR API Type
3841
3839
  apiType: z.nativeEnum(ASRApiType).optional(),
3842
- // ASR API type from job (streaming vs file-based)
3843
3840
  // ASR configuration as JSON string (no type validation)
3844
3841
  asrConfig: z.string().optional(),
3845
- // Stringified JSON of the ASR provider config
3846
3842
  // Raw ASR metadata payload as provided by the provider (stringified if needed)
3847
3843
  rawAsrMetadata: z.string().optional()
3848
3844
  });
@@ -3859,13 +3855,9 @@ var ErrorTypeV1;
3859
3855
  var ErrorResultSchemaV1 = z.object({
3860
3856
  type: z.literal(RecognitionResultTypeV1.ERROR),
3861
3857
  audioUtteranceId: z.string(),
3862
- // audio utterance id for this error
3863
3858
  errorType: z.nativeEnum(ErrorTypeV1).optional(),
3864
- // error type category
3865
3859
  message: z.string().optional(),
3866
- // Error message
3867
3860
  code: z.union([z.string(), z.number()]).optional(),
3868
- // Error code
3869
3861
  description: z.string().optional()
3870
3862
  // Detailed description
3871
3863
  });
@@ -3877,9 +3869,7 @@ var ClientControlActionV1;
3877
3869
  var ClientControlActionsV1 = z.nativeEnum(ClientControlActionV1);
3878
3870
  var ClientControlMessageSchemaV1 = z.object({
3879
3871
  type: z.literal(RecognitionResultTypeV1.CLIENT_CONTROL_MESSAGE),
3880
- // Message type discriminator
3881
3872
  audioUtteranceId: z.string(),
3882
- // audio utterance id for this control message
3883
3873
  action: ClientControlActionsV1
3884
3874
  // The control action to perform
3885
3875
  });
@@ -4017,7 +4007,6 @@ var MetadataMessageSchema = z.object({
4017
4007
  type: z.literal(ProviderMessageType.METADATA),
4018
4008
  provider: z.nativeEnum(RecognitionProvider),
4019
4009
  asrConfig: z.string().optional(),
4020
- // ASR config we sent to provider
4021
4010
  data: z.string().optional()
4022
4011
  // Raw metadata from provider (Deepgram only)
4023
4012
  });
@@ -4141,7 +4130,6 @@ var BaseRecognitionExceptionSchema = z.object({
4141
4130
  var AuthenticationExceptionSchema = BaseRecognitionExceptionSchema.extend({
4142
4131
  errorType: z.literal(ErrorTypeV1.AUTHENTICATION_ERROR),
4143
4132
  isImmediatelyAvailable: z.literal(false),
4144
- // System issue, not user-facing
4145
4133
  /** Which service failed authentication (e.g., 'deepgram', 'google') */
4146
4134
  service: z.string().optional(),
4147
4135
  /** Authentication method that failed (e.g., 'api_key', 'oauth') */
@@ -4150,7 +4138,6 @@ var AuthenticationExceptionSchema = BaseRecognitionExceptionSchema.extend({
4150
4138
  var ValidationExceptionSchema = BaseRecognitionExceptionSchema.extend({
4151
4139
  errorType: z.literal(ErrorTypeV1.VALIDATION_ERROR),
4152
4140
  isImmediatelyAvailable: z.literal(true),
4153
- // Can show to user
4154
4141
  /** Field name that failed validation */
4155
4142
  field: z.string().optional(),
4156
4143
  /** Expected value format/type */
@@ -4161,7 +4148,6 @@ var ValidationExceptionSchema = BaseRecognitionExceptionSchema.extend({
4161
4148
  var ProviderExceptionSchema = BaseRecognitionExceptionSchema.extend({
4162
4149
  errorType: z.literal(ErrorTypeV1.PROVIDER_ERROR),
4163
4150
  isImmediatelyAvailable: z.literal(false),
4164
- // Provider issue, not user-facing
4165
4151
  /** Provider name (e.g., 'deepgram', 'assemblyai', 'google') */
4166
4152
  provider: z.string().optional(),
4167
4153
  /** Provider-specific error code */
@@ -4172,7 +4158,6 @@ var ProviderExceptionSchema = BaseRecognitionExceptionSchema.extend({
4172
4158
  var TimeoutExceptionSchema = BaseRecognitionExceptionSchema.extend({
4173
4159
  errorType: z.literal(ErrorTypeV1.TIMEOUT_ERROR),
4174
4160
  isImmediatelyAvailable: z.literal(true),
4175
- // Can tell user to try again
4176
4161
  /** Timeout duration in milliseconds */
4177
4162
  timeoutMs: z.number().optional(),
4178
4163
  /** What operation timed out (e.g., 'connection', 'transcription', 'response') */
@@ -4181,7 +4166,6 @@ var TimeoutExceptionSchema = BaseRecognitionExceptionSchema.extend({
4181
4166
  var QuotaExceededExceptionSchema = BaseRecognitionExceptionSchema.extend({
4182
4167
  errorType: z.literal(ErrorTypeV1.QUOTA_EXCEEDED),
4183
4168
  isImmediatelyAvailable: z.literal(true),
4184
- // Can tell user to wait
4185
4169
  /** Quota type that was exceeded (e.g., 'rate_limit', 'daily_quota', 'concurrent_requests') */
4186
4170
  quotaType: z.string().optional(),
4187
4171
  /** When quota resets (Unix timestamp in ms) */
@@ -4192,7 +4176,6 @@ var QuotaExceededExceptionSchema = BaseRecognitionExceptionSchema.extend({
4192
4176
  var ConnectionExceptionSchema = BaseRecognitionExceptionSchema.extend({
4193
4177
  errorType: z.literal(ErrorTypeV1.CONNECTION_ERROR),
4194
4178
  isImmediatelyAvailable: z.literal(true),
4195
- // Can tell user about network issues
4196
4179
  /** Number of connection attempts made */
4197
4180
  attempts: z.number().optional(),
4198
4181
  /** URL that failed to connect */
@@ -4203,7 +4186,6 @@ var ConnectionExceptionSchema = BaseRecognitionExceptionSchema.extend({
4203
4186
  var UnknownExceptionSchema = BaseRecognitionExceptionSchema.extend({
4204
4187
  errorType: z.literal(ErrorTypeV1.UNKNOWN_ERROR),
4205
4188
  isImmediatelyAvailable: z.literal(false),
4206
- // Unknown cause, not user-facing
4207
4189
  /** Stack trace for debugging (sanitized) */
4208
4190
  stack: z.string().optional(),
4209
4191
  /** Additional context for debugging */
@@ -4256,16 +4238,11 @@ var SlotMapSchema = z.record(z.string(), z.array(z.string()));
4256
4238
  var GameContextSchemaV1 = z.object({
4257
4239
  type: z.literal(RecognitionContextTypeV1.GAME_CONTEXT),
4258
4240
  gameId: z.string(),
4259
- // Unique identifier for the game
4260
4241
  gamePhase: z.string(),
4261
- // Current phase of the game
4262
4242
  // Prompt fields for different processing stages
4263
4243
  promptSTT: z.string().optional(),
4264
- // Speech-to-Text: Keywords/phrases to optimize ASR (e.g., for Deepgram keywords)
4265
4244
  promptSTF: z.string().optional(),
4266
- // Speech-to-Function: Direct speech to function mapping instructions
4267
4245
  promptTTF: z.string().optional(),
4268
- // Text-to-Function: Text to function mapping instructions after transcription
4269
4246
  // Slot map for entity extraction
4270
4247
  slotMap: SlotMapSchema.optional()
4271
4248
  // Map of slot names to possible values to enhance prompting and keyword matching.
@@ -4292,7 +4269,6 @@ var ASRRequestSchemaV1 = z.object({
4292
4269
  type: z.literal(RecognitionContextTypeV1.ASR_REQUEST),
4293
4270
  // Session identification
4294
4271
  audioUtteranceId: z.string().optional(),
4295
- // Optional utterance ID (prefer query param)
4296
4272
  // ASR configuration
4297
4273
  provider: z.string(),
4298
4274
  model: z.string().optional(),
@@ -4301,12 +4277,9 @@ var ASRRequestSchemaV1 = z.object({
4301
4277
  encoding: z.number(),
4302
4278
  // Recognition options
4303
4279
  interimResults: z.boolean().optional().default(false),
4304
- // Enable interim/partial results
4305
4280
  useContext: z.boolean().optional().default(false),
4306
- // If true, requires GameContext before session creation
4307
4281
  // Final transcript stability mode (timeout for fallback final transcript)
4308
4282
  finalTranscriptStability: z.string().optional(),
4309
- // Stability mode: 'aggressive' | 'balanced' | 'conservative'
4310
4283
  // Debug options (FOR DEBUG/TESTING ONLY - not for production use)
4311
4284
  debugCommand: RequestDebugCommandSchema
4312
4285
  });
@@ -4319,31 +4292,22 @@ var RecognitionContextSchemaV1 = z.discriminatedUnion("type", [
4319
4292
  // ../../libs/types/dist/recognition-query.types.js
4320
4293
  var RecognitionGameInfoSchema = z.object({
4321
4294
  userId: z.string().optional(),
4322
- // User identifier
4323
4295
  gameSessionId: z.string().optional(),
4324
- // Volly session identifier . Called "sessionId" in Platform and most games.
4325
4296
  deviceId: z.string().optional(),
4326
- // Device identifier
4327
4297
  accountId: z.string().optional(),
4328
- // Account identifier
4329
4298
  gameId: z.string().optional(),
4330
- // Game identifier
4331
4299
  gamePhase: z.string().optional(),
4332
- // Game phase or scene. A string that describes the current state of the game for client team to optimize specific turn.
4333
4300
  questionAnswerId: z.string().optional(),
4334
- // Question answer identifier for tracking Q&A sessions
4335
4301
  platform: z.string().optional()
4336
4302
  // Platform for audio recording device (use the definition of platform teams)
4337
4303
  });
4338
4304
  var RecognitionQueryMetadataSchema = z.object({
4339
4305
  audioUtteranceId: z.string(),
4340
- // Audio utterance ID to query
4341
4306
  recognitionGameInfo: RecognitionGameInfoSchema.optional()
4342
4307
  // Optional game info for security
4343
4308
  });
4344
4309
  var UtteranceResourceResponseSchema = z.object({
4345
4310
  audioUtteranceId: z.string(),
4346
- // Audio utterance ID
4347
4311
  results: z.array(z.any())
4348
4312
  // Array of RecognitionResult (version-specific)
4349
4313
  });
@@ -4609,10 +4573,7 @@ var GeminiModel;
4609
4573
  GeminiModel2["GEMINI_2_5_FLASH"] = "gemini-2.5-flash";
4610
4574
  GeminiModel2["GEMINI_2_5_FLASH_LITE"] = "gemini-2.5-flash-lite";
4611
4575
  GeminiModel2["GEMINI_2_0_FLASH_LATEST"] = "gemini-2.0-flash-latest";
4612
- GeminiModel2["GEMINI_2_0_FLASH"] = "gemini-2.0-flash-002";
4613
4576
  GeminiModel2["GEMINI_2_0_FLASH_EXP"] = "gemini-2.0-flash-exp";
4614
- GeminiModel2["GEMINI_1_5_FLASH"] = "gemini-1.5-flash";
4615
- GeminiModel2["GEMINI_1_5_PRO"] = "gemini-1.5-pro";
4616
4577
  })(GeminiModel || (GeminiModel = {}));
4617
4578
  var GeminiApiVersion;
4618
4579
  (function(GeminiApiVersion2) {
@@ -5638,16 +5599,65 @@ var RealTimeTwoWayWebSocketRecognitionClient = class _RealTimeTwoWayWebSocketRec
5638
5599
  this.config.onConnected();
5639
5600
  }
5640
5601
  onDisconnected(code, reason) {
5641
- this.log("debug", "WebSocket disconnected", { code, reason, previousState: this.state });
5602
+ const closeCodeDescription = this.getCloseCodeDescription(code);
5603
+ const is1006 = code === 1006;
5604
+ this.log("debug", "[DIAGNOSTIC] WebSocket disconnected", {
5605
+ code,
5606
+ codeDescription: closeCodeDescription,
5607
+ reason: reason || "(empty)",
5608
+ previousState: this.state,
5609
+ is1006Abnormal: is1006,
5610
+ audioChunksSent: this.audioChunksSent,
5611
+ audioBytesSent: this.audioBytesSent,
5612
+ bufferStats: this.audioBuffer.getStats()
5613
+ });
5642
5614
  if (this.state === "stopping" /* STOPPING */) {
5643
5615
  this.state = "stopped" /* STOPPED */;
5644
5616
  } else if (this.state === "connected" /* CONNECTED */ || this.state === "ready" /* READY */ || this.state === "connecting" /* CONNECTING */) {
5645
- this.log("error", "Unexpected disconnection", { code, reason });
5617
+ this.log("error", "[DIAGNOSTIC] Unexpected disconnection", {
5618
+ code,
5619
+ codeDescription: closeCodeDescription,
5620
+ reason: reason || "(empty)",
5621
+ is1006,
5622
+ possibleCauses: is1006 ? [
5623
+ "Network connection lost",
5624
+ "Server process crashed",
5625
+ "Provider (Deepgram/AssemblyAI) WebSocket closed abnormally",
5626
+ "Firewall/proxy terminated connection",
5627
+ "Browser/tab suspended (mobile)"
5628
+ ] : []
5629
+ });
5646
5630
  this.state = "failed" /* FAILED */;
5647
5631
  }
5648
5632
  this.cleanup();
5649
5633
  this.config.onDisconnected(code, reason);
5650
5634
  }
5635
+ /**
5636
+ * Get human-readable description for WebSocket close code
5637
+ */
5638
+ getCloseCodeDescription(code) {
5639
+ const descriptions = {
5640
+ 1e3: "Normal Closure",
5641
+ 1001: "Going Away",
5642
+ 1002: "Protocol Error",
5643
+ 1003: "Unsupported Data",
5644
+ 1005: "No Status Received",
5645
+ 1006: "Abnormal Closure (no close frame received)",
5646
+ 1007: "Invalid Frame Payload",
5647
+ 1008: "Policy Violation",
5648
+ 1009: "Message Too Big",
5649
+ 1010: "Mandatory Extension",
5650
+ 1011: "Internal Server Error",
5651
+ 1012: "Service Restart",
5652
+ 1013: "Try Again Later",
5653
+ 4e3: "Auth Required",
5654
+ 4001: "Auth Failed",
5655
+ 4002: "Rate Limit Exceeded",
5656
+ 4003: "Invalid Session",
5657
+ 4004: "Session Expired"
5658
+ };
5659
+ return descriptions[code] || `Unknown (${code})`;
5660
+ }
5651
5661
  onError(error) {
5652
5662
  this.state = "failed" /* FAILED */;
5653
5663
  const errorResult = {
@@ -5891,218 +5901,4000 @@ function createClientWithBuilder(configure) {
5891
5901
  return new RealTimeTwoWayWebSocketRecognitionClient(config);
5892
5902
  }
5893
5903
 
5894
- // src/vgf-recognition-state.ts
5895
- var RecognitionVGFStateSchema = z.object({
5896
- // Core STT state
5897
- audioUtteranceId: z.string(),
5898
- startRecordingStatus: z.string().optional(),
5899
- // "NOT_READY", "READY", "RECORDING", "FINISHED". States follow this order.
5900
- // Streaming should only start when "READY". Other states control mic UI and recording.
5901
- transcriptionStatus: z.string().optional(),
5902
- // "NOT_STARTED", "IN_PROGRESS", "FINALIZED", "ABORTED", "ERROR"
5903
- finalTranscript: z.string().optional(),
5904
- // Full finalized transcript for the utterance. Will not change.
5905
- finalConfidence: z.number().optional(),
5906
- // Tracking-only metadata
5907
- asrConfig: z.string().optional(),
5908
- // Json format of the ASR config
5909
- startRecordingTimestamp: z.string().optional(),
5910
- // Start of recording. Immutable after set.
5911
- finalRecordingTimestamp: z.string().optional(),
5912
- // End of recording. Immutable after set. Transcription may still be in progress.
5913
- finalTranscriptionTimestamp: z.string().optional(),
5914
- // When the final transcript was produced. Immutable after set.
5915
- // STEP 2: Support for mic auto-stop upon correct answer
5916
- pendingTranscript: z.string().optional().default(""),
5917
- // Non-final transcript that may change (matches existing naming)
5918
- pendingConfidence: z.number().optional(),
5919
- // STEP 3: Support for semantic/function-call outcomes
5920
- functionCallMetadata: z.string().optional(),
5921
- // Function call metadata in JSON, e.g. "{artist: true, title: true}"
5922
- functionCallConfidence: z.number().optional(),
5923
- // Confidence score for the function call.
5924
- finalFunctionCallTimestamp: z.string().optional(),
5925
- // When the final action after interpreting the transcript was taken. Immutable.
5926
- // Support for prompt slot mapping - passed to recognition context when present
5927
- promptSlotMap: z.record(z.string(), z.array(z.string())).optional()
5928
- // Optional map of slot names to prompt values for recognition context
5929
- });
5930
- var RecordingStatus = {
5931
- NOT_READY: "NOT_READY",
5932
- READY: "READY",
5933
- RECORDING: "RECORDING",
5934
- FINISHED: "FINISHED"
5935
- };
5936
- var TranscriptionStatus = {
5937
- NOT_STARTED: "NOT_STARTED",
5938
- IN_PROGRESS: "IN_PROGRESS",
5939
- FINALIZED: "FINALIZED",
5940
- ABORTED: "ABORTED",
5941
- // Session was cancelled/abandoned by user
5942
- ERROR: "ERROR"
5943
- };
5944
- function createInitialRecognitionState(audioUtteranceId) {
5945
- return {
5946
- audioUtteranceId,
5947
- startRecordingStatus: RecordingStatus.NOT_READY,
5948
- transcriptionStatus: TranscriptionStatus.NOT_STARTED,
5949
- pendingTranscript: ""
5950
- };
5951
- }
5952
- function isValidRecordingStatusTransition(from, to) {
5953
- const statusOrder = [
5954
- RecordingStatus.NOT_READY,
5955
- RecordingStatus.READY,
5956
- RecordingStatus.RECORDING,
5957
- RecordingStatus.FINISHED
5958
- ];
5959
- const fromIndex = from ? statusOrder.indexOf(from) : -1;
5960
- const toIndex = statusOrder.indexOf(to);
5961
- return toIndex > fromIndex && toIndex !== -1;
5962
- }
5963
-
5964
- // src/vgf-recognition-mapper.ts
5965
- function mapTranscriptionResultToState(currentState, result, isRecording) {
5966
- const newState = { ...currentState };
5967
- if (isRecording && currentState.startRecordingStatus !== RecordingStatus.FINISHED) {
5968
- newState.startRecordingStatus = RecordingStatus.RECORDING;
5969
- if (!newState.startRecordingTimestamp) {
5970
- newState.startRecordingTimestamp = (/* @__PURE__ */ new Date()).toISOString();
5971
- }
5904
+ // ../../node_modules/.pnpm/zod@3.22.5/node_modules/zod/lib/index.mjs
5905
+ var util2;
5906
+ (function(util3) {
5907
+ util3.assertEqual = (val) => val;
5908
+ function assertIs(_arg) {
5972
5909
  }
5973
- if (!result.is_finished) {
5974
- newState.transcriptionStatus = TranscriptionStatus.IN_PROGRESS;
5975
- newState.pendingTranscript = result.pendingTranscript || "";
5976
- if (result.pendingTranscriptConfidence !== void 0) {
5977
- newState.pendingConfidence = result.pendingTranscriptConfidence;
5910
+ util3.assertIs = assertIs;
5911
+ function assertNever(_x) {
5912
+ throw new Error();
5913
+ }
5914
+ util3.assertNever = assertNever;
5915
+ util3.arrayToEnum = (items) => {
5916
+ const obj = {};
5917
+ for (const item of items) {
5918
+ obj[item] = item;
5978
5919
  }
5979
- if (result.finalTranscript) {
5980
- newState.finalTranscript = result.finalTranscript;
5981
- if (result.finalTranscriptConfidence !== void 0) {
5982
- newState.finalConfidence = result.finalTranscriptConfidence;
5920
+ return obj;
5921
+ };
5922
+ util3.getValidEnumValues = (obj) => {
5923
+ const validKeys = util3.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
5924
+ const filtered = {};
5925
+ for (const k of validKeys) {
5926
+ filtered[k] = obj[k];
5927
+ }
5928
+ return util3.objectValues(filtered);
5929
+ };
5930
+ util3.objectValues = (obj) => {
5931
+ return util3.objectKeys(obj).map(function(e) {
5932
+ return obj[e];
5933
+ });
5934
+ };
5935
+ util3.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
5936
+ const keys = [];
5937
+ for (const key in object) {
5938
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
5939
+ keys.push(key);
5983
5940
  }
5984
5941
  }
5985
- } else {
5986
- newState.transcriptionStatus = TranscriptionStatus.FINALIZED;
5987
- newState.finalTranscript = result.finalTranscript || "";
5988
- if (result.finalTranscriptConfidence !== void 0) {
5989
- newState.finalConfidence = result.finalTranscriptConfidence;
5942
+ return keys;
5943
+ };
5944
+ util3.find = (arr, checker) => {
5945
+ for (const item of arr) {
5946
+ if (checker(item))
5947
+ return item;
5990
5948
  }
5991
- newState.finalTranscriptionTimestamp = (/* @__PURE__ */ new Date()).toISOString();
5992
- newState.pendingTranscript = "";
5993
- newState.pendingConfidence = void 0;
5994
- }
5995
- return newState;
5996
- }
5997
- function mapMetadataToState(currentState, metadata) {
5998
- const newState = { ...currentState };
5999
- if (!newState.finalRecordingTimestamp) {
6000
- newState.finalRecordingTimestamp = (/* @__PURE__ */ new Date()).toISOString();
6001
- }
6002
- newState.startRecordingStatus = RecordingStatus.FINISHED;
6003
- return newState;
6004
- }
6005
- function mapErrorToState(currentState, error) {
6006
- return {
6007
- ...currentState,
6008
- transcriptionStatus: TranscriptionStatus.ERROR,
6009
- startRecordingStatus: RecordingStatus.FINISHED,
6010
- finalRecordingTimestamp: (/* @__PURE__ */ new Date()).toISOString()
5949
+ return void 0;
6011
5950
  };
6012
- }
6013
- function createVGFStateFromConfig(config) {
6014
- const audioUtteranceId = config.audioUtteranceId || generateUUID();
6015
- const state = createInitialRecognitionState(audioUtteranceId);
6016
- if (config.asrRequestConfig) {
6017
- state.asrConfig = JSON.stringify(config.asrRequestConfig);
5951
+ util3.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
5952
+ function joinValues(array, separator = " | ") {
5953
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
6018
5954
  }
6019
- return state;
6020
- }
6021
- function updateStateOnStop(currentState) {
6022
- return {
6023
- ...currentState,
6024
- startRecordingStatus: RecordingStatus.FINISHED,
6025
- finalRecordingTimestamp: (/* @__PURE__ */ new Date()).toISOString()
5955
+ util3.joinValues = joinValues;
5956
+ util3.jsonStringifyReplacer = (_, value) => {
5957
+ if (typeof value === "bigint") {
5958
+ return value.toString();
5959
+ }
5960
+ return value;
6026
5961
  };
6027
- }
6028
- function generateUUID() {
6029
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
6030
- const r = Math.random() * 16 | 0;
6031
- const v = c === "x" ? r : r & 3 | 8;
6032
- return v.toString(16);
6033
- });
6034
- }
6035
-
6036
- // src/simplified-vgf-recognition-client.ts
6037
- var SimplifiedVGFRecognitionClient = class {
6038
- constructor(config) {
6039
- this.isRecordingAudio = false;
6040
- const { onStateChange, initialState, ...clientConfig } = config;
6041
- this.stateChangeCallback = onStateChange;
6042
- if (initialState) {
6043
- if (initialState.transcriptionStatus === TranscriptionStatus.ABORTED || initialState.transcriptionStatus === TranscriptionStatus.FINALIZED) {
6044
- const newUUID = crypto.randomUUID();
6045
- if (clientConfig.logger) {
6046
- clientConfig.logger("info", `Terminal session detected (${initialState.transcriptionStatus}), generating new UUID: ${newUUID}`);
6047
- }
6048
- this.state = {
6049
- ...initialState,
6050
- audioUtteranceId: newUUID,
6051
- // Reset status fields for fresh session
6052
- transcriptionStatus: TranscriptionStatus.NOT_STARTED,
6053
- startRecordingStatus: RecordingStatus.READY,
6054
- // Clear previous session's transcript
6055
- finalTranscript: void 0
6056
- };
6057
- clientConfig.audioUtteranceId = newUUID;
6058
- if (onStateChange) {
6059
- onStateChange(this.state);
6060
- }
6061
- } else {
6062
- this.state = initialState;
6063
- if (initialState.audioUtteranceId && !clientConfig.audioUtteranceId) {
6064
- clientConfig.audioUtteranceId = initialState.audioUtteranceId;
6065
- }
5962
+ })(util2 || (util2 = {}));
5963
+ var objectUtil2;
5964
+ (function(objectUtil3) {
5965
+ objectUtil3.mergeShapes = (first, second) => {
5966
+ return {
5967
+ ...first,
5968
+ ...second
5969
+ // second overwrites first
5970
+ };
5971
+ };
5972
+ })(objectUtil2 || (objectUtil2 = {}));
5973
+ var ZodParsedType2 = util2.arrayToEnum([
5974
+ "string",
5975
+ "nan",
5976
+ "number",
5977
+ "integer",
5978
+ "float",
5979
+ "boolean",
5980
+ "date",
5981
+ "bigint",
5982
+ "symbol",
5983
+ "function",
5984
+ "undefined",
5985
+ "null",
5986
+ "array",
5987
+ "object",
5988
+ "unknown",
5989
+ "promise",
5990
+ "void",
5991
+ "never",
5992
+ "map",
5993
+ "set"
5994
+ ]);
5995
+ var getParsedType2 = (data) => {
5996
+ const t = typeof data;
5997
+ switch (t) {
5998
+ case "undefined":
5999
+ return ZodParsedType2.undefined;
6000
+ case "string":
6001
+ return ZodParsedType2.string;
6002
+ case "number":
6003
+ return isNaN(data) ? ZodParsedType2.nan : ZodParsedType2.number;
6004
+ case "boolean":
6005
+ return ZodParsedType2.boolean;
6006
+ case "function":
6007
+ return ZodParsedType2.function;
6008
+ case "bigint":
6009
+ return ZodParsedType2.bigint;
6010
+ case "symbol":
6011
+ return ZodParsedType2.symbol;
6012
+ case "object":
6013
+ if (Array.isArray(data)) {
6014
+ return ZodParsedType2.array;
6066
6015
  }
6067
- } else {
6068
- this.state = createVGFStateFromConfig(clientConfig);
6069
- }
6070
- this.state = { ...this.state, startRecordingStatus: "READY" };
6071
- if (this.state.promptSlotMap) {
6072
- if (clientConfig.asrRequestConfig) {
6073
- clientConfig.asrRequestConfig.useContext = true;
6016
+ if (data === null) {
6017
+ return ZodParsedType2.null;
6074
6018
  }
6075
- if (!clientConfig.gameContext) {
6076
- if (clientConfig.logger) {
6077
- clientConfig.logger("warn", "[VGF] promptSlotMap found but no gameContext provided. SlotMap will not be sent.");
6078
- }
6079
- } else {
6080
- clientConfig.gameContext.slotMap = this.state.promptSlotMap;
6019
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
6020
+ return ZodParsedType2.promise;
6081
6021
  }
6082
- }
6083
- this.client = new RealTimeTwoWayWebSocketRecognitionClient({
6084
- ...clientConfig,
6085
- // These callbacks ONLY update the VGF state sink
6086
- onTranscript: (result) => {
6087
- this.state = mapTranscriptionResultToState(this.state, result, this.isRecordingAudio);
6088
- this.notifyStateChange();
6089
- if (clientConfig.onTranscript) {
6090
- clientConfig.onTranscript(result);
6091
- }
6092
- },
6093
- onMetadata: (metadata) => {
6094
- this.state = mapMetadataToState(this.state, metadata);
6095
- this.notifyStateChange();
6096
- if (clientConfig.onMetadata) {
6097
- clientConfig.onMetadata(metadata);
6098
- }
6099
- },
6022
+ if (typeof Map !== "undefined" && data instanceof Map) {
6023
+ return ZodParsedType2.map;
6024
+ }
6025
+ if (typeof Set !== "undefined" && data instanceof Set) {
6026
+ return ZodParsedType2.set;
6027
+ }
6028
+ if (typeof Date !== "undefined" && data instanceof Date) {
6029
+ return ZodParsedType2.date;
6030
+ }
6031
+ return ZodParsedType2.object;
6032
+ default:
6033
+ return ZodParsedType2.unknown;
6034
+ }
6035
+ };
6036
+ var ZodIssueCode2 = util2.arrayToEnum([
6037
+ "invalid_type",
6038
+ "invalid_literal",
6039
+ "custom",
6040
+ "invalid_union",
6041
+ "invalid_union_discriminator",
6042
+ "invalid_enum_value",
6043
+ "unrecognized_keys",
6044
+ "invalid_arguments",
6045
+ "invalid_return_type",
6046
+ "invalid_date",
6047
+ "invalid_string",
6048
+ "too_small",
6049
+ "too_big",
6050
+ "invalid_intersection_types",
6051
+ "not_multiple_of",
6052
+ "not_finite"
6053
+ ]);
6054
+ var quotelessJson2 = (obj) => {
6055
+ const json = JSON.stringify(obj, null, 2);
6056
+ return json.replace(/"([^"]+)":/g, "$1:");
6057
+ };
6058
+ var ZodError2 = class extends Error {
6059
+ constructor(issues) {
6060
+ super();
6061
+ this.issues = [];
6062
+ this.addIssue = (sub) => {
6063
+ this.issues = [...this.issues, sub];
6064
+ };
6065
+ this.addIssues = (subs = []) => {
6066
+ this.issues = [...this.issues, ...subs];
6067
+ };
6068
+ const actualProto = new.target.prototype;
6069
+ if (Object.setPrototypeOf) {
6070
+ Object.setPrototypeOf(this, actualProto);
6071
+ } else {
6072
+ this.__proto__ = actualProto;
6073
+ }
6074
+ this.name = "ZodError";
6075
+ this.issues = issues;
6076
+ }
6077
+ get errors() {
6078
+ return this.issues;
6079
+ }
6080
+ format(_mapper) {
6081
+ const mapper = _mapper || function(issue) {
6082
+ return issue.message;
6083
+ };
6084
+ const fieldErrors = { _errors: [] };
6085
+ const processError = (error) => {
6086
+ for (const issue of error.issues) {
6087
+ if (issue.code === "invalid_union") {
6088
+ issue.unionErrors.map(processError);
6089
+ } else if (issue.code === "invalid_return_type") {
6090
+ processError(issue.returnTypeError);
6091
+ } else if (issue.code === "invalid_arguments") {
6092
+ processError(issue.argumentsError);
6093
+ } else if (issue.path.length === 0) {
6094
+ fieldErrors._errors.push(mapper(issue));
6095
+ } else {
6096
+ let curr = fieldErrors;
6097
+ let i = 0;
6098
+ while (i < issue.path.length) {
6099
+ const el = issue.path[i];
6100
+ const terminal = i === issue.path.length - 1;
6101
+ if (!terminal) {
6102
+ curr[el] = curr[el] || { _errors: [] };
6103
+ } else {
6104
+ curr[el] = curr[el] || { _errors: [] };
6105
+ curr[el]._errors.push(mapper(issue));
6106
+ }
6107
+ curr = curr[el];
6108
+ i++;
6109
+ }
6110
+ }
6111
+ }
6112
+ };
6113
+ processError(this);
6114
+ return fieldErrors;
6115
+ }
6116
+ toString() {
6117
+ return this.message;
6118
+ }
6119
+ get message() {
6120
+ return JSON.stringify(this.issues, util2.jsonStringifyReplacer, 2);
6121
+ }
6122
+ get isEmpty() {
6123
+ return this.issues.length === 0;
6124
+ }
6125
+ flatten(mapper = (issue) => issue.message) {
6126
+ const fieldErrors = {};
6127
+ const formErrors = [];
6128
+ for (const sub of this.issues) {
6129
+ if (sub.path.length > 0) {
6130
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
6131
+ fieldErrors[sub.path[0]].push(mapper(sub));
6132
+ } else {
6133
+ formErrors.push(mapper(sub));
6134
+ }
6135
+ }
6136
+ return { formErrors, fieldErrors };
6137
+ }
6138
+ get formErrors() {
6139
+ return this.flatten();
6140
+ }
6141
+ };
6142
+ ZodError2.create = (issues) => {
6143
+ const error = new ZodError2(issues);
6144
+ return error;
6145
+ };
6146
+ var errorMap2 = (issue, _ctx) => {
6147
+ let message;
6148
+ switch (issue.code) {
6149
+ case ZodIssueCode2.invalid_type:
6150
+ if (issue.received === ZodParsedType2.undefined) {
6151
+ message = "Required";
6152
+ } else {
6153
+ message = `Expected ${issue.expected}, received ${issue.received}`;
6154
+ }
6155
+ break;
6156
+ case ZodIssueCode2.invalid_literal:
6157
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util2.jsonStringifyReplacer)}`;
6158
+ break;
6159
+ case ZodIssueCode2.unrecognized_keys:
6160
+ message = `Unrecognized key(s) in object: ${util2.joinValues(issue.keys, ", ")}`;
6161
+ break;
6162
+ case ZodIssueCode2.invalid_union:
6163
+ message = `Invalid input`;
6164
+ break;
6165
+ case ZodIssueCode2.invalid_union_discriminator:
6166
+ message = `Invalid discriminator value. Expected ${util2.joinValues(issue.options)}`;
6167
+ break;
6168
+ case ZodIssueCode2.invalid_enum_value:
6169
+ message = `Invalid enum value. Expected ${util2.joinValues(issue.options)}, received '${issue.received}'`;
6170
+ break;
6171
+ case ZodIssueCode2.invalid_arguments:
6172
+ message = `Invalid function arguments`;
6173
+ break;
6174
+ case ZodIssueCode2.invalid_return_type:
6175
+ message = `Invalid function return type`;
6176
+ break;
6177
+ case ZodIssueCode2.invalid_date:
6178
+ message = `Invalid date`;
6179
+ break;
6180
+ case ZodIssueCode2.invalid_string:
6181
+ if (typeof issue.validation === "object") {
6182
+ if ("includes" in issue.validation) {
6183
+ message = `Invalid input: must include "${issue.validation.includes}"`;
6184
+ if (typeof issue.validation.position === "number") {
6185
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
6186
+ }
6187
+ } else if ("startsWith" in issue.validation) {
6188
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
6189
+ } else if ("endsWith" in issue.validation) {
6190
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
6191
+ } else {
6192
+ util2.assertNever(issue.validation);
6193
+ }
6194
+ } else if (issue.validation !== "regex") {
6195
+ message = `Invalid ${issue.validation}`;
6196
+ } else {
6197
+ message = "Invalid";
6198
+ }
6199
+ break;
6200
+ case ZodIssueCode2.too_small:
6201
+ if (issue.type === "array")
6202
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
6203
+ else if (issue.type === "string")
6204
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
6205
+ else if (issue.type === "number")
6206
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
6207
+ else if (issue.type === "date")
6208
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
6209
+ else
6210
+ message = "Invalid input";
6211
+ break;
6212
+ case ZodIssueCode2.too_big:
6213
+ if (issue.type === "array")
6214
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
6215
+ else if (issue.type === "string")
6216
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
6217
+ else if (issue.type === "number")
6218
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
6219
+ else if (issue.type === "bigint")
6220
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
6221
+ else if (issue.type === "date")
6222
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
6223
+ else
6224
+ message = "Invalid input";
6225
+ break;
6226
+ case ZodIssueCode2.custom:
6227
+ message = `Invalid input`;
6228
+ break;
6229
+ case ZodIssueCode2.invalid_intersection_types:
6230
+ message = `Intersection results could not be merged`;
6231
+ break;
6232
+ case ZodIssueCode2.not_multiple_of:
6233
+ message = `Number must be a multiple of ${issue.multipleOf}`;
6234
+ break;
6235
+ case ZodIssueCode2.not_finite:
6236
+ message = "Number must be finite";
6237
+ break;
6238
+ default:
6239
+ message = _ctx.defaultError;
6240
+ util2.assertNever(issue);
6241
+ }
6242
+ return { message };
6243
+ };
6244
+ var overrideErrorMap2 = errorMap2;
6245
+ function setErrorMap2(map) {
6246
+ overrideErrorMap2 = map;
6247
+ }
6248
+ function getErrorMap2() {
6249
+ return overrideErrorMap2;
6250
+ }
6251
+ var makeIssue2 = (params) => {
6252
+ const { data, path, errorMaps, issueData } = params;
6253
+ const fullPath = [...path, ...issueData.path || []];
6254
+ const fullIssue = {
6255
+ ...issueData,
6256
+ path: fullPath
6257
+ };
6258
+ let errorMessage = "";
6259
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
6260
+ for (const map of maps) {
6261
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
6262
+ }
6263
+ return {
6264
+ ...issueData,
6265
+ path: fullPath,
6266
+ message: issueData.message || errorMessage
6267
+ };
6268
+ };
6269
+ var EMPTY_PATH2 = [];
6270
+ function addIssueToContext2(ctx, issueData) {
6271
+ const issue = makeIssue2({
6272
+ issueData,
6273
+ data: ctx.data,
6274
+ path: ctx.path,
6275
+ errorMaps: [
6276
+ ctx.common.contextualErrorMap,
6277
+ ctx.schemaErrorMap,
6278
+ getErrorMap2(),
6279
+ errorMap2
6280
+ // then global default map
6281
+ ].filter((x) => !!x)
6282
+ });
6283
+ ctx.common.issues.push(issue);
6284
+ }
6285
+ var ParseStatus2 = class _ParseStatus {
6286
+ constructor() {
6287
+ this.value = "valid";
6288
+ }
6289
+ dirty() {
6290
+ if (this.value === "valid")
6291
+ this.value = "dirty";
6292
+ }
6293
+ abort() {
6294
+ if (this.value !== "aborted")
6295
+ this.value = "aborted";
6296
+ }
6297
+ static mergeArray(status, results) {
6298
+ const arrayValue = [];
6299
+ for (const s of results) {
6300
+ if (s.status === "aborted")
6301
+ return INVALID2;
6302
+ if (s.status === "dirty")
6303
+ status.dirty();
6304
+ arrayValue.push(s.value);
6305
+ }
6306
+ return { status: status.value, value: arrayValue };
6307
+ }
6308
+ static async mergeObjectAsync(status, pairs) {
6309
+ const syncPairs = [];
6310
+ for (const pair of pairs) {
6311
+ syncPairs.push({
6312
+ key: await pair.key,
6313
+ value: await pair.value
6314
+ });
6315
+ }
6316
+ return _ParseStatus.mergeObjectSync(status, syncPairs);
6317
+ }
6318
+ static mergeObjectSync(status, pairs) {
6319
+ const finalObject = {};
6320
+ for (const pair of pairs) {
6321
+ const { key, value } = pair;
6322
+ if (key.status === "aborted")
6323
+ return INVALID2;
6324
+ if (value.status === "aborted")
6325
+ return INVALID2;
6326
+ if (key.status === "dirty")
6327
+ status.dirty();
6328
+ if (value.status === "dirty")
6329
+ status.dirty();
6330
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
6331
+ finalObject[key.value] = value.value;
6332
+ }
6333
+ }
6334
+ return { status: status.value, value: finalObject };
6335
+ }
6336
+ };
6337
+ var INVALID2 = Object.freeze({
6338
+ status: "aborted"
6339
+ });
6340
+ var DIRTY2 = (value) => ({ status: "dirty", value });
6341
+ var OK2 = (value) => ({ status: "valid", value });
6342
+ var isAborted2 = (x) => x.status === "aborted";
6343
+ var isDirty2 = (x) => x.status === "dirty";
6344
+ var isValid2 = (x) => x.status === "valid";
6345
+ var isAsync2 = (x) => typeof Promise !== "undefined" && x instanceof Promise;
6346
+ var errorUtil2;
6347
+ (function(errorUtil3) {
6348
+ errorUtil3.errToObj = (message) => typeof message === "string" ? { message } : message || {};
6349
+ errorUtil3.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
6350
+ })(errorUtil2 || (errorUtil2 = {}));
6351
+ var ParseInputLazyPath2 = class {
6352
+ constructor(parent, value, path, key) {
6353
+ this._cachedPath = [];
6354
+ this.parent = parent;
6355
+ this.data = value;
6356
+ this._path = path;
6357
+ this._key = key;
6358
+ }
6359
+ get path() {
6360
+ if (!this._cachedPath.length) {
6361
+ if (this._key instanceof Array) {
6362
+ this._cachedPath.push(...this._path, ...this._key);
6363
+ } else {
6364
+ this._cachedPath.push(...this._path, this._key);
6365
+ }
6366
+ }
6367
+ return this._cachedPath;
6368
+ }
6369
+ };
6370
+ var handleResult2 = (ctx, result) => {
6371
+ if (isValid2(result)) {
6372
+ return { success: true, data: result.value };
6373
+ } else {
6374
+ if (!ctx.common.issues.length) {
6375
+ throw new Error("Validation failed but no issues detected.");
6376
+ }
6377
+ return {
6378
+ success: false,
6379
+ get error() {
6380
+ if (this._error)
6381
+ return this._error;
6382
+ const error = new ZodError2(ctx.common.issues);
6383
+ this._error = error;
6384
+ return this._error;
6385
+ }
6386
+ };
6387
+ }
6388
+ };
6389
+ function processCreateParams2(params) {
6390
+ if (!params)
6391
+ return {};
6392
+ const { errorMap: errorMap3, invalid_type_error, required_error, description } = params;
6393
+ if (errorMap3 && (invalid_type_error || required_error)) {
6394
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
6395
+ }
6396
+ if (errorMap3)
6397
+ return { errorMap: errorMap3, description };
6398
+ const customMap = (iss, ctx) => {
6399
+ if (iss.code !== "invalid_type")
6400
+ return { message: ctx.defaultError };
6401
+ if (typeof ctx.data === "undefined") {
6402
+ return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
6403
+ }
6404
+ return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
6405
+ };
6406
+ return { errorMap: customMap, description };
6407
+ }
6408
+ var ZodType2 = class {
6409
+ constructor(def) {
6410
+ this.spa = this.safeParseAsync;
6411
+ this._def = def;
6412
+ this.parse = this.parse.bind(this);
6413
+ this.safeParse = this.safeParse.bind(this);
6414
+ this.parseAsync = this.parseAsync.bind(this);
6415
+ this.safeParseAsync = this.safeParseAsync.bind(this);
6416
+ this.spa = this.spa.bind(this);
6417
+ this.refine = this.refine.bind(this);
6418
+ this.refinement = this.refinement.bind(this);
6419
+ this.superRefine = this.superRefine.bind(this);
6420
+ this.optional = this.optional.bind(this);
6421
+ this.nullable = this.nullable.bind(this);
6422
+ this.nullish = this.nullish.bind(this);
6423
+ this.array = this.array.bind(this);
6424
+ this.promise = this.promise.bind(this);
6425
+ this.or = this.or.bind(this);
6426
+ this.and = this.and.bind(this);
6427
+ this.transform = this.transform.bind(this);
6428
+ this.brand = this.brand.bind(this);
6429
+ this.default = this.default.bind(this);
6430
+ this.catch = this.catch.bind(this);
6431
+ this.describe = this.describe.bind(this);
6432
+ this.pipe = this.pipe.bind(this);
6433
+ this.readonly = this.readonly.bind(this);
6434
+ this.isNullable = this.isNullable.bind(this);
6435
+ this.isOptional = this.isOptional.bind(this);
6436
+ }
6437
+ get description() {
6438
+ return this._def.description;
6439
+ }
6440
+ _getType(input) {
6441
+ return getParsedType2(input.data);
6442
+ }
6443
+ _getOrReturnCtx(input, ctx) {
6444
+ return ctx || {
6445
+ common: input.parent.common,
6446
+ data: input.data,
6447
+ parsedType: getParsedType2(input.data),
6448
+ schemaErrorMap: this._def.errorMap,
6449
+ path: input.path,
6450
+ parent: input.parent
6451
+ };
6452
+ }
6453
+ _processInputParams(input) {
6454
+ return {
6455
+ status: new ParseStatus2(),
6456
+ ctx: {
6457
+ common: input.parent.common,
6458
+ data: input.data,
6459
+ parsedType: getParsedType2(input.data),
6460
+ schemaErrorMap: this._def.errorMap,
6461
+ path: input.path,
6462
+ parent: input.parent
6463
+ }
6464
+ };
6465
+ }
6466
+ _parseSync(input) {
6467
+ const result = this._parse(input);
6468
+ if (isAsync2(result)) {
6469
+ throw new Error("Synchronous parse encountered promise.");
6470
+ }
6471
+ return result;
6472
+ }
6473
+ _parseAsync(input) {
6474
+ const result = this._parse(input);
6475
+ return Promise.resolve(result);
6476
+ }
6477
+ parse(data, params) {
6478
+ const result = this.safeParse(data, params);
6479
+ if (result.success)
6480
+ return result.data;
6481
+ throw result.error;
6482
+ }
6483
+ safeParse(data, params) {
6484
+ var _a;
6485
+ const ctx = {
6486
+ common: {
6487
+ issues: [],
6488
+ async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
6489
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
6490
+ },
6491
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
6492
+ schemaErrorMap: this._def.errorMap,
6493
+ parent: null,
6494
+ data,
6495
+ parsedType: getParsedType2(data)
6496
+ };
6497
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
6498
+ return handleResult2(ctx, result);
6499
+ }
6500
+ async parseAsync(data, params) {
6501
+ const result = await this.safeParseAsync(data, params);
6502
+ if (result.success)
6503
+ return result.data;
6504
+ throw result.error;
6505
+ }
6506
+ async safeParseAsync(data, params) {
6507
+ const ctx = {
6508
+ common: {
6509
+ issues: [],
6510
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
6511
+ async: true
6512
+ },
6513
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
6514
+ schemaErrorMap: this._def.errorMap,
6515
+ parent: null,
6516
+ data,
6517
+ parsedType: getParsedType2(data)
6518
+ };
6519
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
6520
+ const result = await (isAsync2(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
6521
+ return handleResult2(ctx, result);
6522
+ }
6523
+ refine(check, message) {
6524
+ const getIssueProperties = (val) => {
6525
+ if (typeof message === "string" || typeof message === "undefined") {
6526
+ return { message };
6527
+ } else if (typeof message === "function") {
6528
+ return message(val);
6529
+ } else {
6530
+ return message;
6531
+ }
6532
+ };
6533
+ return this._refinement((val, ctx) => {
6534
+ const result = check(val);
6535
+ const setError = () => ctx.addIssue({
6536
+ code: ZodIssueCode2.custom,
6537
+ ...getIssueProperties(val)
6538
+ });
6539
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
6540
+ return result.then((data) => {
6541
+ if (!data) {
6542
+ setError();
6543
+ return false;
6544
+ } else {
6545
+ return true;
6546
+ }
6547
+ });
6548
+ }
6549
+ if (!result) {
6550
+ setError();
6551
+ return false;
6552
+ } else {
6553
+ return true;
6554
+ }
6555
+ });
6556
+ }
6557
+ refinement(check, refinementData) {
6558
+ return this._refinement((val, ctx) => {
6559
+ if (!check(val)) {
6560
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
6561
+ return false;
6562
+ } else {
6563
+ return true;
6564
+ }
6565
+ });
6566
+ }
6567
+ _refinement(refinement) {
6568
+ return new ZodEffects2({
6569
+ schema: this,
6570
+ typeName: ZodFirstPartyTypeKind2.ZodEffects,
6571
+ effect: { type: "refinement", refinement }
6572
+ });
6573
+ }
6574
+ superRefine(refinement) {
6575
+ return this._refinement(refinement);
6576
+ }
6577
+ optional() {
6578
+ return ZodOptional2.create(this, this._def);
6579
+ }
6580
+ nullable() {
6581
+ return ZodNullable2.create(this, this._def);
6582
+ }
6583
+ nullish() {
6584
+ return this.nullable().optional();
6585
+ }
6586
+ array() {
6587
+ return ZodArray2.create(this, this._def);
6588
+ }
6589
+ promise() {
6590
+ return ZodPromise2.create(this, this._def);
6591
+ }
6592
+ or(option) {
6593
+ return ZodUnion2.create([this, option], this._def);
6594
+ }
6595
+ and(incoming) {
6596
+ return ZodIntersection2.create(this, incoming, this._def);
6597
+ }
6598
+ transform(transform) {
6599
+ return new ZodEffects2({
6600
+ ...processCreateParams2(this._def),
6601
+ schema: this,
6602
+ typeName: ZodFirstPartyTypeKind2.ZodEffects,
6603
+ effect: { type: "transform", transform }
6604
+ });
6605
+ }
6606
+ default(def) {
6607
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
6608
+ return new ZodDefault2({
6609
+ ...processCreateParams2(this._def),
6610
+ innerType: this,
6611
+ defaultValue: defaultValueFunc,
6612
+ typeName: ZodFirstPartyTypeKind2.ZodDefault
6613
+ });
6614
+ }
6615
+ brand() {
6616
+ return new ZodBranded2({
6617
+ typeName: ZodFirstPartyTypeKind2.ZodBranded,
6618
+ type: this,
6619
+ ...processCreateParams2(this._def)
6620
+ });
6621
+ }
6622
+ catch(def) {
6623
+ const catchValueFunc = typeof def === "function" ? def : () => def;
6624
+ return new ZodCatch2({
6625
+ ...processCreateParams2(this._def),
6626
+ innerType: this,
6627
+ catchValue: catchValueFunc,
6628
+ typeName: ZodFirstPartyTypeKind2.ZodCatch
6629
+ });
6630
+ }
6631
+ describe(description) {
6632
+ const This = this.constructor;
6633
+ return new This({
6634
+ ...this._def,
6635
+ description
6636
+ });
6637
+ }
6638
+ pipe(target) {
6639
+ return ZodPipeline2.create(this, target);
6640
+ }
6641
+ readonly() {
6642
+ return ZodReadonly2.create(this);
6643
+ }
6644
+ isOptional() {
6645
+ return this.safeParse(void 0).success;
6646
+ }
6647
+ isNullable() {
6648
+ return this.safeParse(null).success;
6649
+ }
6650
+ };
6651
+ var cuidRegex2 = /^c[^\s-]{8,}$/i;
6652
+ var cuid2Regex2 = /^[a-z][a-z0-9]*$/;
6653
+ var ulidRegex2 = /^[0-9A-HJKMNP-TV-Z]{26}$/;
6654
+ var uuidRegex2 = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
6655
+ var emailRegex2 = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
6656
+ var _emojiRegex2 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
6657
+ var emojiRegex2;
6658
+ var ipv4Regex2 = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
6659
+ var ipv6Regex2 = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
6660
+ var datetimeRegex2 = (args) => {
6661
+ if (args.precision) {
6662
+ if (args.offset) {
6663
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
6664
+ } else {
6665
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
6666
+ }
6667
+ } else if (args.precision === 0) {
6668
+ if (args.offset) {
6669
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
6670
+ } else {
6671
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
6672
+ }
6673
+ } else {
6674
+ if (args.offset) {
6675
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
6676
+ } else {
6677
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
6678
+ }
6679
+ }
6680
+ };
6681
+ function isValidIP2(ip, version) {
6682
+ if ((version === "v4" || !version) && ipv4Regex2.test(ip)) {
6683
+ return true;
6684
+ }
6685
+ if ((version === "v6" || !version) && ipv6Regex2.test(ip)) {
6686
+ return true;
6687
+ }
6688
+ return false;
6689
+ }
6690
+ var ZodString2 = class _ZodString extends ZodType2 {
6691
+ _parse(input) {
6692
+ if (this._def.coerce) {
6693
+ input.data = String(input.data);
6694
+ }
6695
+ const parsedType = this._getType(input);
6696
+ if (parsedType !== ZodParsedType2.string) {
6697
+ const ctx2 = this._getOrReturnCtx(input);
6698
+ addIssueToContext2(
6699
+ ctx2,
6700
+ {
6701
+ code: ZodIssueCode2.invalid_type,
6702
+ expected: ZodParsedType2.string,
6703
+ received: ctx2.parsedType
6704
+ }
6705
+ //
6706
+ );
6707
+ return INVALID2;
6708
+ }
6709
+ const status = new ParseStatus2();
6710
+ let ctx = void 0;
6711
+ for (const check of this._def.checks) {
6712
+ if (check.kind === "min") {
6713
+ if (input.data.length < check.value) {
6714
+ ctx = this._getOrReturnCtx(input, ctx);
6715
+ addIssueToContext2(ctx, {
6716
+ code: ZodIssueCode2.too_small,
6717
+ minimum: check.value,
6718
+ type: "string",
6719
+ inclusive: true,
6720
+ exact: false,
6721
+ message: check.message
6722
+ });
6723
+ status.dirty();
6724
+ }
6725
+ } else if (check.kind === "max") {
6726
+ if (input.data.length > check.value) {
6727
+ ctx = this._getOrReturnCtx(input, ctx);
6728
+ addIssueToContext2(ctx, {
6729
+ code: ZodIssueCode2.too_big,
6730
+ maximum: check.value,
6731
+ type: "string",
6732
+ inclusive: true,
6733
+ exact: false,
6734
+ message: check.message
6735
+ });
6736
+ status.dirty();
6737
+ }
6738
+ } else if (check.kind === "length") {
6739
+ const tooBig = input.data.length > check.value;
6740
+ const tooSmall = input.data.length < check.value;
6741
+ if (tooBig || tooSmall) {
6742
+ ctx = this._getOrReturnCtx(input, ctx);
6743
+ if (tooBig) {
6744
+ addIssueToContext2(ctx, {
6745
+ code: ZodIssueCode2.too_big,
6746
+ maximum: check.value,
6747
+ type: "string",
6748
+ inclusive: true,
6749
+ exact: true,
6750
+ message: check.message
6751
+ });
6752
+ } else if (tooSmall) {
6753
+ addIssueToContext2(ctx, {
6754
+ code: ZodIssueCode2.too_small,
6755
+ minimum: check.value,
6756
+ type: "string",
6757
+ inclusive: true,
6758
+ exact: true,
6759
+ message: check.message
6760
+ });
6761
+ }
6762
+ status.dirty();
6763
+ }
6764
+ } else if (check.kind === "email") {
6765
+ if (!emailRegex2.test(input.data)) {
6766
+ ctx = this._getOrReturnCtx(input, ctx);
6767
+ addIssueToContext2(ctx, {
6768
+ validation: "email",
6769
+ code: ZodIssueCode2.invalid_string,
6770
+ message: check.message
6771
+ });
6772
+ status.dirty();
6773
+ }
6774
+ } else if (check.kind === "emoji") {
6775
+ if (!emojiRegex2) {
6776
+ emojiRegex2 = new RegExp(_emojiRegex2, "u");
6777
+ }
6778
+ if (!emojiRegex2.test(input.data)) {
6779
+ ctx = this._getOrReturnCtx(input, ctx);
6780
+ addIssueToContext2(ctx, {
6781
+ validation: "emoji",
6782
+ code: ZodIssueCode2.invalid_string,
6783
+ message: check.message
6784
+ });
6785
+ status.dirty();
6786
+ }
6787
+ } else if (check.kind === "uuid") {
6788
+ if (!uuidRegex2.test(input.data)) {
6789
+ ctx = this._getOrReturnCtx(input, ctx);
6790
+ addIssueToContext2(ctx, {
6791
+ validation: "uuid",
6792
+ code: ZodIssueCode2.invalid_string,
6793
+ message: check.message
6794
+ });
6795
+ status.dirty();
6796
+ }
6797
+ } else if (check.kind === "cuid") {
6798
+ if (!cuidRegex2.test(input.data)) {
6799
+ ctx = this._getOrReturnCtx(input, ctx);
6800
+ addIssueToContext2(ctx, {
6801
+ validation: "cuid",
6802
+ code: ZodIssueCode2.invalid_string,
6803
+ message: check.message
6804
+ });
6805
+ status.dirty();
6806
+ }
6807
+ } else if (check.kind === "cuid2") {
6808
+ if (!cuid2Regex2.test(input.data)) {
6809
+ ctx = this._getOrReturnCtx(input, ctx);
6810
+ addIssueToContext2(ctx, {
6811
+ validation: "cuid2",
6812
+ code: ZodIssueCode2.invalid_string,
6813
+ message: check.message
6814
+ });
6815
+ status.dirty();
6816
+ }
6817
+ } else if (check.kind === "ulid") {
6818
+ if (!ulidRegex2.test(input.data)) {
6819
+ ctx = this._getOrReturnCtx(input, ctx);
6820
+ addIssueToContext2(ctx, {
6821
+ validation: "ulid",
6822
+ code: ZodIssueCode2.invalid_string,
6823
+ message: check.message
6824
+ });
6825
+ status.dirty();
6826
+ }
6827
+ } else if (check.kind === "url") {
6828
+ try {
6829
+ new URL(input.data);
6830
+ } catch (_a) {
6831
+ ctx = this._getOrReturnCtx(input, ctx);
6832
+ addIssueToContext2(ctx, {
6833
+ validation: "url",
6834
+ code: ZodIssueCode2.invalid_string,
6835
+ message: check.message
6836
+ });
6837
+ status.dirty();
6838
+ }
6839
+ } else if (check.kind === "regex") {
6840
+ check.regex.lastIndex = 0;
6841
+ const testResult = check.regex.test(input.data);
6842
+ if (!testResult) {
6843
+ ctx = this._getOrReturnCtx(input, ctx);
6844
+ addIssueToContext2(ctx, {
6845
+ validation: "regex",
6846
+ code: ZodIssueCode2.invalid_string,
6847
+ message: check.message
6848
+ });
6849
+ status.dirty();
6850
+ }
6851
+ } else if (check.kind === "trim") {
6852
+ input.data = input.data.trim();
6853
+ } else if (check.kind === "includes") {
6854
+ if (!input.data.includes(check.value, check.position)) {
6855
+ ctx = this._getOrReturnCtx(input, ctx);
6856
+ addIssueToContext2(ctx, {
6857
+ code: ZodIssueCode2.invalid_string,
6858
+ validation: { includes: check.value, position: check.position },
6859
+ message: check.message
6860
+ });
6861
+ status.dirty();
6862
+ }
6863
+ } else if (check.kind === "toLowerCase") {
6864
+ input.data = input.data.toLowerCase();
6865
+ } else if (check.kind === "toUpperCase") {
6866
+ input.data = input.data.toUpperCase();
6867
+ } else if (check.kind === "startsWith") {
6868
+ if (!input.data.startsWith(check.value)) {
6869
+ ctx = this._getOrReturnCtx(input, ctx);
6870
+ addIssueToContext2(ctx, {
6871
+ code: ZodIssueCode2.invalid_string,
6872
+ validation: { startsWith: check.value },
6873
+ message: check.message
6874
+ });
6875
+ status.dirty();
6876
+ }
6877
+ } else if (check.kind === "endsWith") {
6878
+ if (!input.data.endsWith(check.value)) {
6879
+ ctx = this._getOrReturnCtx(input, ctx);
6880
+ addIssueToContext2(ctx, {
6881
+ code: ZodIssueCode2.invalid_string,
6882
+ validation: { endsWith: check.value },
6883
+ message: check.message
6884
+ });
6885
+ status.dirty();
6886
+ }
6887
+ } else if (check.kind === "datetime") {
6888
+ const regex = datetimeRegex2(check);
6889
+ if (!regex.test(input.data)) {
6890
+ ctx = this._getOrReturnCtx(input, ctx);
6891
+ addIssueToContext2(ctx, {
6892
+ code: ZodIssueCode2.invalid_string,
6893
+ validation: "datetime",
6894
+ message: check.message
6895
+ });
6896
+ status.dirty();
6897
+ }
6898
+ } else if (check.kind === "ip") {
6899
+ if (!isValidIP2(input.data, check.version)) {
6900
+ ctx = this._getOrReturnCtx(input, ctx);
6901
+ addIssueToContext2(ctx, {
6902
+ validation: "ip",
6903
+ code: ZodIssueCode2.invalid_string,
6904
+ message: check.message
6905
+ });
6906
+ status.dirty();
6907
+ }
6908
+ } else {
6909
+ util2.assertNever(check);
6910
+ }
6911
+ }
6912
+ return { status: status.value, value: input.data };
6913
+ }
6914
+ _regex(regex, validation, message) {
6915
+ return this.refinement((data) => regex.test(data), {
6916
+ validation,
6917
+ code: ZodIssueCode2.invalid_string,
6918
+ ...errorUtil2.errToObj(message)
6919
+ });
6920
+ }
6921
+ _addCheck(check) {
6922
+ return new _ZodString({
6923
+ ...this._def,
6924
+ checks: [...this._def.checks, check]
6925
+ });
6926
+ }
6927
+ email(message) {
6928
+ return this._addCheck({ kind: "email", ...errorUtil2.errToObj(message) });
6929
+ }
6930
+ url(message) {
6931
+ return this._addCheck({ kind: "url", ...errorUtil2.errToObj(message) });
6932
+ }
6933
+ emoji(message) {
6934
+ return this._addCheck({ kind: "emoji", ...errorUtil2.errToObj(message) });
6935
+ }
6936
+ uuid(message) {
6937
+ return this._addCheck({ kind: "uuid", ...errorUtil2.errToObj(message) });
6938
+ }
6939
+ cuid(message) {
6940
+ return this._addCheck({ kind: "cuid", ...errorUtil2.errToObj(message) });
6941
+ }
6942
+ cuid2(message) {
6943
+ return this._addCheck({ kind: "cuid2", ...errorUtil2.errToObj(message) });
6944
+ }
6945
+ ulid(message) {
6946
+ return this._addCheck({ kind: "ulid", ...errorUtil2.errToObj(message) });
6947
+ }
6948
+ ip(options) {
6949
+ return this._addCheck({ kind: "ip", ...errorUtil2.errToObj(options) });
6950
+ }
6951
+ datetime(options) {
6952
+ var _a;
6953
+ if (typeof options === "string") {
6954
+ return this._addCheck({
6955
+ kind: "datetime",
6956
+ precision: null,
6957
+ offset: false,
6958
+ message: options
6959
+ });
6960
+ }
6961
+ return this._addCheck({
6962
+ kind: "datetime",
6963
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
6964
+ offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
6965
+ ...errorUtil2.errToObj(options === null || options === void 0 ? void 0 : options.message)
6966
+ });
6967
+ }
6968
+ regex(regex, message) {
6969
+ return this._addCheck({
6970
+ kind: "regex",
6971
+ regex,
6972
+ ...errorUtil2.errToObj(message)
6973
+ });
6974
+ }
6975
+ includes(value, options) {
6976
+ return this._addCheck({
6977
+ kind: "includes",
6978
+ value,
6979
+ position: options === null || options === void 0 ? void 0 : options.position,
6980
+ ...errorUtil2.errToObj(options === null || options === void 0 ? void 0 : options.message)
6981
+ });
6982
+ }
6983
+ startsWith(value, message) {
6984
+ return this._addCheck({
6985
+ kind: "startsWith",
6986
+ value,
6987
+ ...errorUtil2.errToObj(message)
6988
+ });
6989
+ }
6990
+ endsWith(value, message) {
6991
+ return this._addCheck({
6992
+ kind: "endsWith",
6993
+ value,
6994
+ ...errorUtil2.errToObj(message)
6995
+ });
6996
+ }
6997
+ min(minLength, message) {
6998
+ return this._addCheck({
6999
+ kind: "min",
7000
+ value: minLength,
7001
+ ...errorUtil2.errToObj(message)
7002
+ });
7003
+ }
7004
+ max(maxLength, message) {
7005
+ return this._addCheck({
7006
+ kind: "max",
7007
+ value: maxLength,
7008
+ ...errorUtil2.errToObj(message)
7009
+ });
7010
+ }
7011
+ length(len, message) {
7012
+ return this._addCheck({
7013
+ kind: "length",
7014
+ value: len,
7015
+ ...errorUtil2.errToObj(message)
7016
+ });
7017
+ }
7018
+ /**
7019
+ * @deprecated Use z.string().min(1) instead.
7020
+ * @see {@link ZodString.min}
7021
+ */
7022
+ nonempty(message) {
7023
+ return this.min(1, errorUtil2.errToObj(message));
7024
+ }
7025
+ trim() {
7026
+ return new _ZodString({
7027
+ ...this._def,
7028
+ checks: [...this._def.checks, { kind: "trim" }]
7029
+ });
7030
+ }
7031
+ toLowerCase() {
7032
+ return new _ZodString({
7033
+ ...this._def,
7034
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
7035
+ });
7036
+ }
7037
+ toUpperCase() {
7038
+ return new _ZodString({
7039
+ ...this._def,
7040
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
7041
+ });
7042
+ }
7043
+ get isDatetime() {
7044
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
7045
+ }
7046
+ get isEmail() {
7047
+ return !!this._def.checks.find((ch) => ch.kind === "email");
7048
+ }
7049
+ get isURL() {
7050
+ return !!this._def.checks.find((ch) => ch.kind === "url");
7051
+ }
7052
+ get isEmoji() {
7053
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
7054
+ }
7055
+ get isUUID() {
7056
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
7057
+ }
7058
+ get isCUID() {
7059
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
7060
+ }
7061
+ get isCUID2() {
7062
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
7063
+ }
7064
+ get isULID() {
7065
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
7066
+ }
7067
+ get isIP() {
7068
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
7069
+ }
7070
+ get minLength() {
7071
+ let min = null;
7072
+ for (const ch of this._def.checks) {
7073
+ if (ch.kind === "min") {
7074
+ if (min === null || ch.value > min)
7075
+ min = ch.value;
7076
+ }
7077
+ }
7078
+ return min;
7079
+ }
7080
+ get maxLength() {
7081
+ let max = null;
7082
+ for (const ch of this._def.checks) {
7083
+ if (ch.kind === "max") {
7084
+ if (max === null || ch.value < max)
7085
+ max = ch.value;
7086
+ }
7087
+ }
7088
+ return max;
7089
+ }
7090
+ };
7091
+ ZodString2.create = (params) => {
7092
+ var _a;
7093
+ return new ZodString2({
7094
+ checks: [],
7095
+ typeName: ZodFirstPartyTypeKind2.ZodString,
7096
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
7097
+ ...processCreateParams2(params)
7098
+ });
7099
+ };
7100
+ function floatSafeRemainder2(val, step) {
7101
+ const valDecCount = (val.toString().split(".")[1] || "").length;
7102
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
7103
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
7104
+ const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
7105
+ const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
7106
+ return valInt % stepInt / Math.pow(10, decCount);
7107
+ }
7108
+ var ZodNumber2 = class _ZodNumber extends ZodType2 {
7109
+ constructor() {
7110
+ super(...arguments);
7111
+ this.min = this.gte;
7112
+ this.max = this.lte;
7113
+ this.step = this.multipleOf;
7114
+ }
7115
+ _parse(input) {
7116
+ if (this._def.coerce) {
7117
+ input.data = Number(input.data);
7118
+ }
7119
+ const parsedType = this._getType(input);
7120
+ if (parsedType !== ZodParsedType2.number) {
7121
+ const ctx2 = this._getOrReturnCtx(input);
7122
+ addIssueToContext2(ctx2, {
7123
+ code: ZodIssueCode2.invalid_type,
7124
+ expected: ZodParsedType2.number,
7125
+ received: ctx2.parsedType
7126
+ });
7127
+ return INVALID2;
7128
+ }
7129
+ let ctx = void 0;
7130
+ const status = new ParseStatus2();
7131
+ for (const check of this._def.checks) {
7132
+ if (check.kind === "int") {
7133
+ if (!util2.isInteger(input.data)) {
7134
+ ctx = this._getOrReturnCtx(input, ctx);
7135
+ addIssueToContext2(ctx, {
7136
+ code: ZodIssueCode2.invalid_type,
7137
+ expected: "integer",
7138
+ received: "float",
7139
+ message: check.message
7140
+ });
7141
+ status.dirty();
7142
+ }
7143
+ } else if (check.kind === "min") {
7144
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
7145
+ if (tooSmall) {
7146
+ ctx = this._getOrReturnCtx(input, ctx);
7147
+ addIssueToContext2(ctx, {
7148
+ code: ZodIssueCode2.too_small,
7149
+ minimum: check.value,
7150
+ type: "number",
7151
+ inclusive: check.inclusive,
7152
+ exact: false,
7153
+ message: check.message
7154
+ });
7155
+ status.dirty();
7156
+ }
7157
+ } else if (check.kind === "max") {
7158
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
7159
+ if (tooBig) {
7160
+ ctx = this._getOrReturnCtx(input, ctx);
7161
+ addIssueToContext2(ctx, {
7162
+ code: ZodIssueCode2.too_big,
7163
+ maximum: check.value,
7164
+ type: "number",
7165
+ inclusive: check.inclusive,
7166
+ exact: false,
7167
+ message: check.message
7168
+ });
7169
+ status.dirty();
7170
+ }
7171
+ } else if (check.kind === "multipleOf") {
7172
+ if (floatSafeRemainder2(input.data, check.value) !== 0) {
7173
+ ctx = this._getOrReturnCtx(input, ctx);
7174
+ addIssueToContext2(ctx, {
7175
+ code: ZodIssueCode2.not_multiple_of,
7176
+ multipleOf: check.value,
7177
+ message: check.message
7178
+ });
7179
+ status.dirty();
7180
+ }
7181
+ } else if (check.kind === "finite") {
7182
+ if (!Number.isFinite(input.data)) {
7183
+ ctx = this._getOrReturnCtx(input, ctx);
7184
+ addIssueToContext2(ctx, {
7185
+ code: ZodIssueCode2.not_finite,
7186
+ message: check.message
7187
+ });
7188
+ status.dirty();
7189
+ }
7190
+ } else {
7191
+ util2.assertNever(check);
7192
+ }
7193
+ }
7194
+ return { status: status.value, value: input.data };
7195
+ }
7196
+ gte(value, message) {
7197
+ return this.setLimit("min", value, true, errorUtil2.toString(message));
7198
+ }
7199
+ gt(value, message) {
7200
+ return this.setLimit("min", value, false, errorUtil2.toString(message));
7201
+ }
7202
+ lte(value, message) {
7203
+ return this.setLimit("max", value, true, errorUtil2.toString(message));
7204
+ }
7205
+ lt(value, message) {
7206
+ return this.setLimit("max", value, false, errorUtil2.toString(message));
7207
+ }
7208
+ setLimit(kind, value, inclusive, message) {
7209
+ return new _ZodNumber({
7210
+ ...this._def,
7211
+ checks: [
7212
+ ...this._def.checks,
7213
+ {
7214
+ kind,
7215
+ value,
7216
+ inclusive,
7217
+ message: errorUtil2.toString(message)
7218
+ }
7219
+ ]
7220
+ });
7221
+ }
7222
+ _addCheck(check) {
7223
+ return new _ZodNumber({
7224
+ ...this._def,
7225
+ checks: [...this._def.checks, check]
7226
+ });
7227
+ }
7228
+ int(message) {
7229
+ return this._addCheck({
7230
+ kind: "int",
7231
+ message: errorUtil2.toString(message)
7232
+ });
7233
+ }
7234
+ positive(message) {
7235
+ return this._addCheck({
7236
+ kind: "min",
7237
+ value: 0,
7238
+ inclusive: false,
7239
+ message: errorUtil2.toString(message)
7240
+ });
7241
+ }
7242
+ negative(message) {
7243
+ return this._addCheck({
7244
+ kind: "max",
7245
+ value: 0,
7246
+ inclusive: false,
7247
+ message: errorUtil2.toString(message)
7248
+ });
7249
+ }
7250
+ nonpositive(message) {
7251
+ return this._addCheck({
7252
+ kind: "max",
7253
+ value: 0,
7254
+ inclusive: true,
7255
+ message: errorUtil2.toString(message)
7256
+ });
7257
+ }
7258
+ nonnegative(message) {
7259
+ return this._addCheck({
7260
+ kind: "min",
7261
+ value: 0,
7262
+ inclusive: true,
7263
+ message: errorUtil2.toString(message)
7264
+ });
7265
+ }
7266
+ multipleOf(value, message) {
7267
+ return this._addCheck({
7268
+ kind: "multipleOf",
7269
+ value,
7270
+ message: errorUtil2.toString(message)
7271
+ });
7272
+ }
7273
+ finite(message) {
7274
+ return this._addCheck({
7275
+ kind: "finite",
7276
+ message: errorUtil2.toString(message)
7277
+ });
7278
+ }
7279
+ safe(message) {
7280
+ return this._addCheck({
7281
+ kind: "min",
7282
+ inclusive: true,
7283
+ value: Number.MIN_SAFE_INTEGER,
7284
+ message: errorUtil2.toString(message)
7285
+ })._addCheck({
7286
+ kind: "max",
7287
+ inclusive: true,
7288
+ value: Number.MAX_SAFE_INTEGER,
7289
+ message: errorUtil2.toString(message)
7290
+ });
7291
+ }
7292
+ get minValue() {
7293
+ let min = null;
7294
+ for (const ch of this._def.checks) {
7295
+ if (ch.kind === "min") {
7296
+ if (min === null || ch.value > min)
7297
+ min = ch.value;
7298
+ }
7299
+ }
7300
+ return min;
7301
+ }
7302
+ get maxValue() {
7303
+ let max = null;
7304
+ for (const ch of this._def.checks) {
7305
+ if (ch.kind === "max") {
7306
+ if (max === null || ch.value < max)
7307
+ max = ch.value;
7308
+ }
7309
+ }
7310
+ return max;
7311
+ }
7312
+ get isInt() {
7313
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util2.isInteger(ch.value));
7314
+ }
7315
+ get isFinite() {
7316
+ let max = null, min = null;
7317
+ for (const ch of this._def.checks) {
7318
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
7319
+ return true;
7320
+ } else if (ch.kind === "min") {
7321
+ if (min === null || ch.value > min)
7322
+ min = ch.value;
7323
+ } else if (ch.kind === "max") {
7324
+ if (max === null || ch.value < max)
7325
+ max = ch.value;
7326
+ }
7327
+ }
7328
+ return Number.isFinite(min) && Number.isFinite(max);
7329
+ }
7330
+ };
7331
+ ZodNumber2.create = (params) => {
7332
+ return new ZodNumber2({
7333
+ checks: [],
7334
+ typeName: ZodFirstPartyTypeKind2.ZodNumber,
7335
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
7336
+ ...processCreateParams2(params)
7337
+ });
7338
+ };
7339
+ var ZodBigInt2 = class _ZodBigInt extends ZodType2 {
7340
+ constructor() {
7341
+ super(...arguments);
7342
+ this.min = this.gte;
7343
+ this.max = this.lte;
7344
+ }
7345
+ _parse(input) {
7346
+ if (this._def.coerce) {
7347
+ input.data = BigInt(input.data);
7348
+ }
7349
+ const parsedType = this._getType(input);
7350
+ if (parsedType !== ZodParsedType2.bigint) {
7351
+ const ctx2 = this._getOrReturnCtx(input);
7352
+ addIssueToContext2(ctx2, {
7353
+ code: ZodIssueCode2.invalid_type,
7354
+ expected: ZodParsedType2.bigint,
7355
+ received: ctx2.parsedType
7356
+ });
7357
+ return INVALID2;
7358
+ }
7359
+ let ctx = void 0;
7360
+ const status = new ParseStatus2();
7361
+ for (const check of this._def.checks) {
7362
+ if (check.kind === "min") {
7363
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
7364
+ if (tooSmall) {
7365
+ ctx = this._getOrReturnCtx(input, ctx);
7366
+ addIssueToContext2(ctx, {
7367
+ code: ZodIssueCode2.too_small,
7368
+ type: "bigint",
7369
+ minimum: check.value,
7370
+ inclusive: check.inclusive,
7371
+ message: check.message
7372
+ });
7373
+ status.dirty();
7374
+ }
7375
+ } else if (check.kind === "max") {
7376
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
7377
+ if (tooBig) {
7378
+ ctx = this._getOrReturnCtx(input, ctx);
7379
+ addIssueToContext2(ctx, {
7380
+ code: ZodIssueCode2.too_big,
7381
+ type: "bigint",
7382
+ maximum: check.value,
7383
+ inclusive: check.inclusive,
7384
+ message: check.message
7385
+ });
7386
+ status.dirty();
7387
+ }
7388
+ } else if (check.kind === "multipleOf") {
7389
+ if (input.data % check.value !== BigInt(0)) {
7390
+ ctx = this._getOrReturnCtx(input, ctx);
7391
+ addIssueToContext2(ctx, {
7392
+ code: ZodIssueCode2.not_multiple_of,
7393
+ multipleOf: check.value,
7394
+ message: check.message
7395
+ });
7396
+ status.dirty();
7397
+ }
7398
+ } else {
7399
+ util2.assertNever(check);
7400
+ }
7401
+ }
7402
+ return { status: status.value, value: input.data };
7403
+ }
7404
+ gte(value, message) {
7405
+ return this.setLimit("min", value, true, errorUtil2.toString(message));
7406
+ }
7407
+ gt(value, message) {
7408
+ return this.setLimit("min", value, false, errorUtil2.toString(message));
7409
+ }
7410
+ lte(value, message) {
7411
+ return this.setLimit("max", value, true, errorUtil2.toString(message));
7412
+ }
7413
+ lt(value, message) {
7414
+ return this.setLimit("max", value, false, errorUtil2.toString(message));
7415
+ }
7416
+ setLimit(kind, value, inclusive, message) {
7417
+ return new _ZodBigInt({
7418
+ ...this._def,
7419
+ checks: [
7420
+ ...this._def.checks,
7421
+ {
7422
+ kind,
7423
+ value,
7424
+ inclusive,
7425
+ message: errorUtil2.toString(message)
7426
+ }
7427
+ ]
7428
+ });
7429
+ }
7430
+ _addCheck(check) {
7431
+ return new _ZodBigInt({
7432
+ ...this._def,
7433
+ checks: [...this._def.checks, check]
7434
+ });
7435
+ }
7436
+ positive(message) {
7437
+ return this._addCheck({
7438
+ kind: "min",
7439
+ value: BigInt(0),
7440
+ inclusive: false,
7441
+ message: errorUtil2.toString(message)
7442
+ });
7443
+ }
7444
+ negative(message) {
7445
+ return this._addCheck({
7446
+ kind: "max",
7447
+ value: BigInt(0),
7448
+ inclusive: false,
7449
+ message: errorUtil2.toString(message)
7450
+ });
7451
+ }
7452
+ nonpositive(message) {
7453
+ return this._addCheck({
7454
+ kind: "max",
7455
+ value: BigInt(0),
7456
+ inclusive: true,
7457
+ message: errorUtil2.toString(message)
7458
+ });
7459
+ }
7460
+ nonnegative(message) {
7461
+ return this._addCheck({
7462
+ kind: "min",
7463
+ value: BigInt(0),
7464
+ inclusive: true,
7465
+ message: errorUtil2.toString(message)
7466
+ });
7467
+ }
7468
+ multipleOf(value, message) {
7469
+ return this._addCheck({
7470
+ kind: "multipleOf",
7471
+ value,
7472
+ message: errorUtil2.toString(message)
7473
+ });
7474
+ }
7475
+ get minValue() {
7476
+ let min = null;
7477
+ for (const ch of this._def.checks) {
7478
+ if (ch.kind === "min") {
7479
+ if (min === null || ch.value > min)
7480
+ min = ch.value;
7481
+ }
7482
+ }
7483
+ return min;
7484
+ }
7485
+ get maxValue() {
7486
+ let max = null;
7487
+ for (const ch of this._def.checks) {
7488
+ if (ch.kind === "max") {
7489
+ if (max === null || ch.value < max)
7490
+ max = ch.value;
7491
+ }
7492
+ }
7493
+ return max;
7494
+ }
7495
+ };
7496
+ ZodBigInt2.create = (params) => {
7497
+ var _a;
7498
+ return new ZodBigInt2({
7499
+ checks: [],
7500
+ typeName: ZodFirstPartyTypeKind2.ZodBigInt,
7501
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
7502
+ ...processCreateParams2(params)
7503
+ });
7504
+ };
7505
+ var ZodBoolean2 = class extends ZodType2 {
7506
+ _parse(input) {
7507
+ if (this._def.coerce) {
7508
+ input.data = Boolean(input.data);
7509
+ }
7510
+ const parsedType = this._getType(input);
7511
+ if (parsedType !== ZodParsedType2.boolean) {
7512
+ const ctx = this._getOrReturnCtx(input);
7513
+ addIssueToContext2(ctx, {
7514
+ code: ZodIssueCode2.invalid_type,
7515
+ expected: ZodParsedType2.boolean,
7516
+ received: ctx.parsedType
7517
+ });
7518
+ return INVALID2;
7519
+ }
7520
+ return OK2(input.data);
7521
+ }
7522
+ };
7523
+ ZodBoolean2.create = (params) => {
7524
+ return new ZodBoolean2({
7525
+ typeName: ZodFirstPartyTypeKind2.ZodBoolean,
7526
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
7527
+ ...processCreateParams2(params)
7528
+ });
7529
+ };
7530
+ var ZodDate2 = class _ZodDate extends ZodType2 {
7531
+ _parse(input) {
7532
+ if (this._def.coerce) {
7533
+ input.data = new Date(input.data);
7534
+ }
7535
+ const parsedType = this._getType(input);
7536
+ if (parsedType !== ZodParsedType2.date) {
7537
+ const ctx2 = this._getOrReturnCtx(input);
7538
+ addIssueToContext2(ctx2, {
7539
+ code: ZodIssueCode2.invalid_type,
7540
+ expected: ZodParsedType2.date,
7541
+ received: ctx2.parsedType
7542
+ });
7543
+ return INVALID2;
7544
+ }
7545
+ if (isNaN(input.data.getTime())) {
7546
+ const ctx2 = this._getOrReturnCtx(input);
7547
+ addIssueToContext2(ctx2, {
7548
+ code: ZodIssueCode2.invalid_date
7549
+ });
7550
+ return INVALID2;
7551
+ }
7552
+ const status = new ParseStatus2();
7553
+ let ctx = void 0;
7554
+ for (const check of this._def.checks) {
7555
+ if (check.kind === "min") {
7556
+ if (input.data.getTime() < check.value) {
7557
+ ctx = this._getOrReturnCtx(input, ctx);
7558
+ addIssueToContext2(ctx, {
7559
+ code: ZodIssueCode2.too_small,
7560
+ message: check.message,
7561
+ inclusive: true,
7562
+ exact: false,
7563
+ minimum: check.value,
7564
+ type: "date"
7565
+ });
7566
+ status.dirty();
7567
+ }
7568
+ } else if (check.kind === "max") {
7569
+ if (input.data.getTime() > check.value) {
7570
+ ctx = this._getOrReturnCtx(input, ctx);
7571
+ addIssueToContext2(ctx, {
7572
+ code: ZodIssueCode2.too_big,
7573
+ message: check.message,
7574
+ inclusive: true,
7575
+ exact: false,
7576
+ maximum: check.value,
7577
+ type: "date"
7578
+ });
7579
+ status.dirty();
7580
+ }
7581
+ } else {
7582
+ util2.assertNever(check);
7583
+ }
7584
+ }
7585
+ return {
7586
+ status: status.value,
7587
+ value: new Date(input.data.getTime())
7588
+ };
7589
+ }
7590
+ _addCheck(check) {
7591
+ return new _ZodDate({
7592
+ ...this._def,
7593
+ checks: [...this._def.checks, check]
7594
+ });
7595
+ }
7596
+ min(minDate, message) {
7597
+ return this._addCheck({
7598
+ kind: "min",
7599
+ value: minDate.getTime(),
7600
+ message: errorUtil2.toString(message)
7601
+ });
7602
+ }
7603
+ max(maxDate, message) {
7604
+ return this._addCheck({
7605
+ kind: "max",
7606
+ value: maxDate.getTime(),
7607
+ message: errorUtil2.toString(message)
7608
+ });
7609
+ }
7610
+ get minDate() {
7611
+ let min = null;
7612
+ for (const ch of this._def.checks) {
7613
+ if (ch.kind === "min") {
7614
+ if (min === null || ch.value > min)
7615
+ min = ch.value;
7616
+ }
7617
+ }
7618
+ return min != null ? new Date(min) : null;
7619
+ }
7620
+ get maxDate() {
7621
+ let max = null;
7622
+ for (const ch of this._def.checks) {
7623
+ if (ch.kind === "max") {
7624
+ if (max === null || ch.value < max)
7625
+ max = ch.value;
7626
+ }
7627
+ }
7628
+ return max != null ? new Date(max) : null;
7629
+ }
7630
+ };
7631
+ ZodDate2.create = (params) => {
7632
+ return new ZodDate2({
7633
+ checks: [],
7634
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
7635
+ typeName: ZodFirstPartyTypeKind2.ZodDate,
7636
+ ...processCreateParams2(params)
7637
+ });
7638
+ };
7639
+ var ZodSymbol2 = class extends ZodType2 {
7640
+ _parse(input) {
7641
+ const parsedType = this._getType(input);
7642
+ if (parsedType !== ZodParsedType2.symbol) {
7643
+ const ctx = this._getOrReturnCtx(input);
7644
+ addIssueToContext2(ctx, {
7645
+ code: ZodIssueCode2.invalid_type,
7646
+ expected: ZodParsedType2.symbol,
7647
+ received: ctx.parsedType
7648
+ });
7649
+ return INVALID2;
7650
+ }
7651
+ return OK2(input.data);
7652
+ }
7653
+ };
7654
+ ZodSymbol2.create = (params) => {
7655
+ return new ZodSymbol2({
7656
+ typeName: ZodFirstPartyTypeKind2.ZodSymbol,
7657
+ ...processCreateParams2(params)
7658
+ });
7659
+ };
7660
+ var ZodUndefined2 = class extends ZodType2 {
7661
+ _parse(input) {
7662
+ const parsedType = this._getType(input);
7663
+ if (parsedType !== ZodParsedType2.undefined) {
7664
+ const ctx = this._getOrReturnCtx(input);
7665
+ addIssueToContext2(ctx, {
7666
+ code: ZodIssueCode2.invalid_type,
7667
+ expected: ZodParsedType2.undefined,
7668
+ received: ctx.parsedType
7669
+ });
7670
+ return INVALID2;
7671
+ }
7672
+ return OK2(input.data);
7673
+ }
7674
+ };
7675
+ ZodUndefined2.create = (params) => {
7676
+ return new ZodUndefined2({
7677
+ typeName: ZodFirstPartyTypeKind2.ZodUndefined,
7678
+ ...processCreateParams2(params)
7679
+ });
7680
+ };
7681
+ var ZodNull2 = class extends ZodType2 {
7682
+ _parse(input) {
7683
+ const parsedType = this._getType(input);
7684
+ if (parsedType !== ZodParsedType2.null) {
7685
+ const ctx = this._getOrReturnCtx(input);
7686
+ addIssueToContext2(ctx, {
7687
+ code: ZodIssueCode2.invalid_type,
7688
+ expected: ZodParsedType2.null,
7689
+ received: ctx.parsedType
7690
+ });
7691
+ return INVALID2;
7692
+ }
7693
+ return OK2(input.data);
7694
+ }
7695
+ };
7696
+ ZodNull2.create = (params) => {
7697
+ return new ZodNull2({
7698
+ typeName: ZodFirstPartyTypeKind2.ZodNull,
7699
+ ...processCreateParams2(params)
7700
+ });
7701
+ };
7702
+ var ZodAny2 = class extends ZodType2 {
7703
+ constructor() {
7704
+ super(...arguments);
7705
+ this._any = true;
7706
+ }
7707
+ _parse(input) {
7708
+ return OK2(input.data);
7709
+ }
7710
+ };
7711
+ ZodAny2.create = (params) => {
7712
+ return new ZodAny2({
7713
+ typeName: ZodFirstPartyTypeKind2.ZodAny,
7714
+ ...processCreateParams2(params)
7715
+ });
7716
+ };
7717
+ var ZodUnknown2 = class extends ZodType2 {
7718
+ constructor() {
7719
+ super(...arguments);
7720
+ this._unknown = true;
7721
+ }
7722
+ _parse(input) {
7723
+ return OK2(input.data);
7724
+ }
7725
+ };
7726
+ ZodUnknown2.create = (params) => {
7727
+ return new ZodUnknown2({
7728
+ typeName: ZodFirstPartyTypeKind2.ZodUnknown,
7729
+ ...processCreateParams2(params)
7730
+ });
7731
+ };
7732
+ var ZodNever2 = class extends ZodType2 {
7733
+ _parse(input) {
7734
+ const ctx = this._getOrReturnCtx(input);
7735
+ addIssueToContext2(ctx, {
7736
+ code: ZodIssueCode2.invalid_type,
7737
+ expected: ZodParsedType2.never,
7738
+ received: ctx.parsedType
7739
+ });
7740
+ return INVALID2;
7741
+ }
7742
+ };
7743
+ ZodNever2.create = (params) => {
7744
+ return new ZodNever2({
7745
+ typeName: ZodFirstPartyTypeKind2.ZodNever,
7746
+ ...processCreateParams2(params)
7747
+ });
7748
+ };
7749
+ var ZodVoid2 = class extends ZodType2 {
7750
+ _parse(input) {
7751
+ const parsedType = this._getType(input);
7752
+ if (parsedType !== ZodParsedType2.undefined) {
7753
+ const ctx = this._getOrReturnCtx(input);
7754
+ addIssueToContext2(ctx, {
7755
+ code: ZodIssueCode2.invalid_type,
7756
+ expected: ZodParsedType2.void,
7757
+ received: ctx.parsedType
7758
+ });
7759
+ return INVALID2;
7760
+ }
7761
+ return OK2(input.data);
7762
+ }
7763
+ };
7764
+ ZodVoid2.create = (params) => {
7765
+ return new ZodVoid2({
7766
+ typeName: ZodFirstPartyTypeKind2.ZodVoid,
7767
+ ...processCreateParams2(params)
7768
+ });
7769
+ };
7770
+ var ZodArray2 = class _ZodArray extends ZodType2 {
7771
+ _parse(input) {
7772
+ const { ctx, status } = this._processInputParams(input);
7773
+ const def = this._def;
7774
+ if (ctx.parsedType !== ZodParsedType2.array) {
7775
+ addIssueToContext2(ctx, {
7776
+ code: ZodIssueCode2.invalid_type,
7777
+ expected: ZodParsedType2.array,
7778
+ received: ctx.parsedType
7779
+ });
7780
+ return INVALID2;
7781
+ }
7782
+ if (def.exactLength !== null) {
7783
+ const tooBig = ctx.data.length > def.exactLength.value;
7784
+ const tooSmall = ctx.data.length < def.exactLength.value;
7785
+ if (tooBig || tooSmall) {
7786
+ addIssueToContext2(ctx, {
7787
+ code: tooBig ? ZodIssueCode2.too_big : ZodIssueCode2.too_small,
7788
+ minimum: tooSmall ? def.exactLength.value : void 0,
7789
+ maximum: tooBig ? def.exactLength.value : void 0,
7790
+ type: "array",
7791
+ inclusive: true,
7792
+ exact: true,
7793
+ message: def.exactLength.message
7794
+ });
7795
+ status.dirty();
7796
+ }
7797
+ }
7798
+ if (def.minLength !== null) {
7799
+ if (ctx.data.length < def.minLength.value) {
7800
+ addIssueToContext2(ctx, {
7801
+ code: ZodIssueCode2.too_small,
7802
+ minimum: def.minLength.value,
7803
+ type: "array",
7804
+ inclusive: true,
7805
+ exact: false,
7806
+ message: def.minLength.message
7807
+ });
7808
+ status.dirty();
7809
+ }
7810
+ }
7811
+ if (def.maxLength !== null) {
7812
+ if (ctx.data.length > def.maxLength.value) {
7813
+ addIssueToContext2(ctx, {
7814
+ code: ZodIssueCode2.too_big,
7815
+ maximum: def.maxLength.value,
7816
+ type: "array",
7817
+ inclusive: true,
7818
+ exact: false,
7819
+ message: def.maxLength.message
7820
+ });
7821
+ status.dirty();
7822
+ }
7823
+ }
7824
+ if (ctx.common.async) {
7825
+ return Promise.all([...ctx.data].map((item, i) => {
7826
+ return def.type._parseAsync(new ParseInputLazyPath2(ctx, item, ctx.path, i));
7827
+ })).then((result2) => {
7828
+ return ParseStatus2.mergeArray(status, result2);
7829
+ });
7830
+ }
7831
+ const result = [...ctx.data].map((item, i) => {
7832
+ return def.type._parseSync(new ParseInputLazyPath2(ctx, item, ctx.path, i));
7833
+ });
7834
+ return ParseStatus2.mergeArray(status, result);
7835
+ }
7836
+ get element() {
7837
+ return this._def.type;
7838
+ }
7839
+ min(minLength, message) {
7840
+ return new _ZodArray({
7841
+ ...this._def,
7842
+ minLength: { value: minLength, message: errorUtil2.toString(message) }
7843
+ });
7844
+ }
7845
+ max(maxLength, message) {
7846
+ return new _ZodArray({
7847
+ ...this._def,
7848
+ maxLength: { value: maxLength, message: errorUtil2.toString(message) }
7849
+ });
7850
+ }
7851
+ length(len, message) {
7852
+ return new _ZodArray({
7853
+ ...this._def,
7854
+ exactLength: { value: len, message: errorUtil2.toString(message) }
7855
+ });
7856
+ }
7857
+ nonempty(message) {
7858
+ return this.min(1, message);
7859
+ }
7860
+ };
7861
+ ZodArray2.create = (schema, params) => {
7862
+ return new ZodArray2({
7863
+ type: schema,
7864
+ minLength: null,
7865
+ maxLength: null,
7866
+ exactLength: null,
7867
+ typeName: ZodFirstPartyTypeKind2.ZodArray,
7868
+ ...processCreateParams2(params)
7869
+ });
7870
+ };
7871
+ function deepPartialify2(schema) {
7872
+ if (schema instanceof ZodObject2) {
7873
+ const newShape = {};
7874
+ for (const key in schema.shape) {
7875
+ const fieldSchema = schema.shape[key];
7876
+ newShape[key] = ZodOptional2.create(deepPartialify2(fieldSchema));
7877
+ }
7878
+ return new ZodObject2({
7879
+ ...schema._def,
7880
+ shape: () => newShape
7881
+ });
7882
+ } else if (schema instanceof ZodArray2) {
7883
+ return new ZodArray2({
7884
+ ...schema._def,
7885
+ type: deepPartialify2(schema.element)
7886
+ });
7887
+ } else if (schema instanceof ZodOptional2) {
7888
+ return ZodOptional2.create(deepPartialify2(schema.unwrap()));
7889
+ } else if (schema instanceof ZodNullable2) {
7890
+ return ZodNullable2.create(deepPartialify2(schema.unwrap()));
7891
+ } else if (schema instanceof ZodTuple2) {
7892
+ return ZodTuple2.create(schema.items.map((item) => deepPartialify2(item)));
7893
+ } else {
7894
+ return schema;
7895
+ }
7896
+ }
7897
+ var ZodObject2 = class _ZodObject extends ZodType2 {
7898
+ constructor() {
7899
+ super(...arguments);
7900
+ this._cached = null;
7901
+ this.nonstrict = this.passthrough;
7902
+ this.augment = this.extend;
7903
+ }
7904
+ _getCached() {
7905
+ if (this._cached !== null)
7906
+ return this._cached;
7907
+ const shape = this._def.shape();
7908
+ const keys = util2.objectKeys(shape);
7909
+ return this._cached = { shape, keys };
7910
+ }
7911
+ _parse(input) {
7912
+ const parsedType = this._getType(input);
7913
+ if (parsedType !== ZodParsedType2.object) {
7914
+ const ctx2 = this._getOrReturnCtx(input);
7915
+ addIssueToContext2(ctx2, {
7916
+ code: ZodIssueCode2.invalid_type,
7917
+ expected: ZodParsedType2.object,
7918
+ received: ctx2.parsedType
7919
+ });
7920
+ return INVALID2;
7921
+ }
7922
+ const { status, ctx } = this._processInputParams(input);
7923
+ const { shape, keys: shapeKeys } = this._getCached();
7924
+ const extraKeys = [];
7925
+ if (!(this._def.catchall instanceof ZodNever2 && this._def.unknownKeys === "strip")) {
7926
+ for (const key in ctx.data) {
7927
+ if (!shapeKeys.includes(key)) {
7928
+ extraKeys.push(key);
7929
+ }
7930
+ }
7931
+ }
7932
+ const pairs = [];
7933
+ for (const key of shapeKeys) {
7934
+ const keyValidator = shape[key];
7935
+ const value = ctx.data[key];
7936
+ pairs.push({
7937
+ key: { status: "valid", value: key },
7938
+ value: keyValidator._parse(new ParseInputLazyPath2(ctx, value, ctx.path, key)),
7939
+ alwaysSet: key in ctx.data
7940
+ });
7941
+ }
7942
+ if (this._def.catchall instanceof ZodNever2) {
7943
+ const unknownKeys = this._def.unknownKeys;
7944
+ if (unknownKeys === "passthrough") {
7945
+ for (const key of extraKeys) {
7946
+ pairs.push({
7947
+ key: { status: "valid", value: key },
7948
+ value: { status: "valid", value: ctx.data[key] }
7949
+ });
7950
+ }
7951
+ } else if (unknownKeys === "strict") {
7952
+ if (extraKeys.length > 0) {
7953
+ addIssueToContext2(ctx, {
7954
+ code: ZodIssueCode2.unrecognized_keys,
7955
+ keys: extraKeys
7956
+ });
7957
+ status.dirty();
7958
+ }
7959
+ } else if (unknownKeys === "strip") ;
7960
+ else {
7961
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
7962
+ }
7963
+ } else {
7964
+ const catchall = this._def.catchall;
7965
+ for (const key of extraKeys) {
7966
+ const value = ctx.data[key];
7967
+ pairs.push({
7968
+ key: { status: "valid", value: key },
7969
+ value: catchall._parse(
7970
+ new ParseInputLazyPath2(ctx, value, ctx.path, key)
7971
+ //, ctx.child(key), value, getParsedType(value)
7972
+ ),
7973
+ alwaysSet: key in ctx.data
7974
+ });
7975
+ }
7976
+ }
7977
+ if (ctx.common.async) {
7978
+ return Promise.resolve().then(async () => {
7979
+ const syncPairs = [];
7980
+ for (const pair of pairs) {
7981
+ const key = await pair.key;
7982
+ syncPairs.push({
7983
+ key,
7984
+ value: await pair.value,
7985
+ alwaysSet: pair.alwaysSet
7986
+ });
7987
+ }
7988
+ return syncPairs;
7989
+ }).then((syncPairs) => {
7990
+ return ParseStatus2.mergeObjectSync(status, syncPairs);
7991
+ });
7992
+ } else {
7993
+ return ParseStatus2.mergeObjectSync(status, pairs);
7994
+ }
7995
+ }
7996
+ get shape() {
7997
+ return this._def.shape();
7998
+ }
7999
+ strict(message) {
8000
+ errorUtil2.errToObj;
8001
+ return new _ZodObject({
8002
+ ...this._def,
8003
+ unknownKeys: "strict",
8004
+ ...message !== void 0 ? {
8005
+ errorMap: (issue, ctx) => {
8006
+ var _a, _b, _c, _d;
8007
+ const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
8008
+ if (issue.code === "unrecognized_keys")
8009
+ return {
8010
+ message: (_d = errorUtil2.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError
8011
+ };
8012
+ return {
8013
+ message: defaultError
8014
+ };
8015
+ }
8016
+ } : {}
8017
+ });
8018
+ }
8019
+ strip() {
8020
+ return new _ZodObject({
8021
+ ...this._def,
8022
+ unknownKeys: "strip"
8023
+ });
8024
+ }
8025
+ passthrough() {
8026
+ return new _ZodObject({
8027
+ ...this._def,
8028
+ unknownKeys: "passthrough"
8029
+ });
8030
+ }
8031
+ // const AugmentFactory =
8032
+ // <Def extends ZodObjectDef>(def: Def) =>
8033
+ // <Augmentation extends ZodRawShape>(
8034
+ // augmentation: Augmentation
8035
+ // ): ZodObject<
8036
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
8037
+ // Def["unknownKeys"],
8038
+ // Def["catchall"]
8039
+ // > => {
8040
+ // return new ZodObject({
8041
+ // ...def,
8042
+ // shape: () => ({
8043
+ // ...def.shape(),
8044
+ // ...augmentation,
8045
+ // }),
8046
+ // }) as any;
8047
+ // };
8048
+ extend(augmentation) {
8049
+ return new _ZodObject({
8050
+ ...this._def,
8051
+ shape: () => ({
8052
+ ...this._def.shape(),
8053
+ ...augmentation
8054
+ })
8055
+ });
8056
+ }
8057
+ /**
8058
+ * Prior to zod@1.0.12 there was a bug in the
8059
+ * inferred type of merged objects. Please
8060
+ * upgrade if you are experiencing issues.
8061
+ */
8062
+ merge(merging) {
8063
+ const merged = new _ZodObject({
8064
+ unknownKeys: merging._def.unknownKeys,
8065
+ catchall: merging._def.catchall,
8066
+ shape: () => ({
8067
+ ...this._def.shape(),
8068
+ ...merging._def.shape()
8069
+ }),
8070
+ typeName: ZodFirstPartyTypeKind2.ZodObject
8071
+ });
8072
+ return merged;
8073
+ }
8074
+ // merge<
8075
+ // Incoming extends AnyZodObject,
8076
+ // Augmentation extends Incoming["shape"],
8077
+ // NewOutput extends {
8078
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
8079
+ // ? Augmentation[k]["_output"]
8080
+ // : k extends keyof Output
8081
+ // ? Output[k]
8082
+ // : never;
8083
+ // },
8084
+ // NewInput extends {
8085
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
8086
+ // ? Augmentation[k]["_input"]
8087
+ // : k extends keyof Input
8088
+ // ? Input[k]
8089
+ // : never;
8090
+ // }
8091
+ // >(
8092
+ // merging: Incoming
8093
+ // ): ZodObject<
8094
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
8095
+ // Incoming["_def"]["unknownKeys"],
8096
+ // Incoming["_def"]["catchall"],
8097
+ // NewOutput,
8098
+ // NewInput
8099
+ // > {
8100
+ // const merged: any = new ZodObject({
8101
+ // unknownKeys: merging._def.unknownKeys,
8102
+ // catchall: merging._def.catchall,
8103
+ // shape: () =>
8104
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
8105
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
8106
+ // }) as any;
8107
+ // return merged;
8108
+ // }
8109
+ setKey(key, schema) {
8110
+ return this.augment({ [key]: schema });
8111
+ }
8112
+ // merge<Incoming extends AnyZodObject>(
8113
+ // merging: Incoming
8114
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
8115
+ // ZodObject<
8116
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
8117
+ // Incoming["_def"]["unknownKeys"],
8118
+ // Incoming["_def"]["catchall"]
8119
+ // > {
8120
+ // // const mergedShape = objectUtil.mergeShapes(
8121
+ // // this._def.shape(),
8122
+ // // merging._def.shape()
8123
+ // // );
8124
+ // const merged: any = new ZodObject({
8125
+ // unknownKeys: merging._def.unknownKeys,
8126
+ // catchall: merging._def.catchall,
8127
+ // shape: () =>
8128
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
8129
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
8130
+ // }) as any;
8131
+ // return merged;
8132
+ // }
8133
+ catchall(index) {
8134
+ return new _ZodObject({
8135
+ ...this._def,
8136
+ catchall: index
8137
+ });
8138
+ }
8139
+ pick(mask) {
8140
+ const shape = {};
8141
+ util2.objectKeys(mask).forEach((key) => {
8142
+ if (mask[key] && this.shape[key]) {
8143
+ shape[key] = this.shape[key];
8144
+ }
8145
+ });
8146
+ return new _ZodObject({
8147
+ ...this._def,
8148
+ shape: () => shape
8149
+ });
8150
+ }
8151
+ omit(mask) {
8152
+ const shape = {};
8153
+ util2.objectKeys(this.shape).forEach((key) => {
8154
+ if (!mask[key]) {
8155
+ shape[key] = this.shape[key];
8156
+ }
8157
+ });
8158
+ return new _ZodObject({
8159
+ ...this._def,
8160
+ shape: () => shape
8161
+ });
8162
+ }
8163
+ /**
8164
+ * @deprecated
8165
+ */
8166
+ deepPartial() {
8167
+ return deepPartialify2(this);
8168
+ }
8169
+ partial(mask) {
8170
+ const newShape = {};
8171
+ util2.objectKeys(this.shape).forEach((key) => {
8172
+ const fieldSchema = this.shape[key];
8173
+ if (mask && !mask[key]) {
8174
+ newShape[key] = fieldSchema;
8175
+ } else {
8176
+ newShape[key] = fieldSchema.optional();
8177
+ }
8178
+ });
8179
+ return new _ZodObject({
8180
+ ...this._def,
8181
+ shape: () => newShape
8182
+ });
8183
+ }
8184
+ required(mask) {
8185
+ const newShape = {};
8186
+ util2.objectKeys(this.shape).forEach((key) => {
8187
+ if (mask && !mask[key]) {
8188
+ newShape[key] = this.shape[key];
8189
+ } else {
8190
+ const fieldSchema = this.shape[key];
8191
+ let newField = fieldSchema;
8192
+ while (newField instanceof ZodOptional2) {
8193
+ newField = newField._def.innerType;
8194
+ }
8195
+ newShape[key] = newField;
8196
+ }
8197
+ });
8198
+ return new _ZodObject({
8199
+ ...this._def,
8200
+ shape: () => newShape
8201
+ });
8202
+ }
8203
+ keyof() {
8204
+ return createZodEnum2(util2.objectKeys(this.shape));
8205
+ }
8206
+ };
8207
+ ZodObject2.create = (shape, params) => {
8208
+ return new ZodObject2({
8209
+ shape: () => shape,
8210
+ unknownKeys: "strip",
8211
+ catchall: ZodNever2.create(),
8212
+ typeName: ZodFirstPartyTypeKind2.ZodObject,
8213
+ ...processCreateParams2(params)
8214
+ });
8215
+ };
8216
+ ZodObject2.strictCreate = (shape, params) => {
8217
+ return new ZodObject2({
8218
+ shape: () => shape,
8219
+ unknownKeys: "strict",
8220
+ catchall: ZodNever2.create(),
8221
+ typeName: ZodFirstPartyTypeKind2.ZodObject,
8222
+ ...processCreateParams2(params)
8223
+ });
8224
+ };
8225
+ ZodObject2.lazycreate = (shape, params) => {
8226
+ return new ZodObject2({
8227
+ shape,
8228
+ unknownKeys: "strip",
8229
+ catchall: ZodNever2.create(),
8230
+ typeName: ZodFirstPartyTypeKind2.ZodObject,
8231
+ ...processCreateParams2(params)
8232
+ });
8233
+ };
8234
+ var ZodUnion2 = class extends ZodType2 {
8235
+ _parse(input) {
8236
+ const { ctx } = this._processInputParams(input);
8237
+ const options = this._def.options;
8238
+ function handleResults(results) {
8239
+ for (const result of results) {
8240
+ if (result.result.status === "valid") {
8241
+ return result.result;
8242
+ }
8243
+ }
8244
+ for (const result of results) {
8245
+ if (result.result.status === "dirty") {
8246
+ ctx.common.issues.push(...result.ctx.common.issues);
8247
+ return result.result;
8248
+ }
8249
+ }
8250
+ const unionErrors = results.map((result) => new ZodError2(result.ctx.common.issues));
8251
+ addIssueToContext2(ctx, {
8252
+ code: ZodIssueCode2.invalid_union,
8253
+ unionErrors
8254
+ });
8255
+ return INVALID2;
8256
+ }
8257
+ if (ctx.common.async) {
8258
+ return Promise.all(options.map(async (option) => {
8259
+ const childCtx = {
8260
+ ...ctx,
8261
+ common: {
8262
+ ...ctx.common,
8263
+ issues: []
8264
+ },
8265
+ parent: null
8266
+ };
8267
+ return {
8268
+ result: await option._parseAsync({
8269
+ data: ctx.data,
8270
+ path: ctx.path,
8271
+ parent: childCtx
8272
+ }),
8273
+ ctx: childCtx
8274
+ };
8275
+ })).then(handleResults);
8276
+ } else {
8277
+ let dirty = void 0;
8278
+ const issues = [];
8279
+ for (const option of options) {
8280
+ const childCtx = {
8281
+ ...ctx,
8282
+ common: {
8283
+ ...ctx.common,
8284
+ issues: []
8285
+ },
8286
+ parent: null
8287
+ };
8288
+ const result = option._parseSync({
8289
+ data: ctx.data,
8290
+ path: ctx.path,
8291
+ parent: childCtx
8292
+ });
8293
+ if (result.status === "valid") {
8294
+ return result;
8295
+ } else if (result.status === "dirty" && !dirty) {
8296
+ dirty = { result, ctx: childCtx };
8297
+ }
8298
+ if (childCtx.common.issues.length) {
8299
+ issues.push(childCtx.common.issues);
8300
+ }
8301
+ }
8302
+ if (dirty) {
8303
+ ctx.common.issues.push(...dirty.ctx.common.issues);
8304
+ return dirty.result;
8305
+ }
8306
+ const unionErrors = issues.map((issues2) => new ZodError2(issues2));
8307
+ addIssueToContext2(ctx, {
8308
+ code: ZodIssueCode2.invalid_union,
8309
+ unionErrors
8310
+ });
8311
+ return INVALID2;
8312
+ }
8313
+ }
8314
+ get options() {
8315
+ return this._def.options;
8316
+ }
8317
+ };
8318
+ ZodUnion2.create = (types, params) => {
8319
+ return new ZodUnion2({
8320
+ options: types,
8321
+ typeName: ZodFirstPartyTypeKind2.ZodUnion,
8322
+ ...processCreateParams2(params)
8323
+ });
8324
+ };
8325
+ var getDiscriminator2 = (type) => {
8326
+ if (type instanceof ZodLazy2) {
8327
+ return getDiscriminator2(type.schema);
8328
+ } else if (type instanceof ZodEffects2) {
8329
+ return getDiscriminator2(type.innerType());
8330
+ } else if (type instanceof ZodLiteral2) {
8331
+ return [type.value];
8332
+ } else if (type instanceof ZodEnum2) {
8333
+ return type.options;
8334
+ } else if (type instanceof ZodNativeEnum2) {
8335
+ return Object.keys(type.enum);
8336
+ } else if (type instanceof ZodDefault2) {
8337
+ return getDiscriminator2(type._def.innerType);
8338
+ } else if (type instanceof ZodUndefined2) {
8339
+ return [void 0];
8340
+ } else if (type instanceof ZodNull2) {
8341
+ return [null];
8342
+ } else {
8343
+ return null;
8344
+ }
8345
+ };
8346
+ var ZodDiscriminatedUnion2 = class _ZodDiscriminatedUnion extends ZodType2 {
8347
+ _parse(input) {
8348
+ const { ctx } = this._processInputParams(input);
8349
+ if (ctx.parsedType !== ZodParsedType2.object) {
8350
+ addIssueToContext2(ctx, {
8351
+ code: ZodIssueCode2.invalid_type,
8352
+ expected: ZodParsedType2.object,
8353
+ received: ctx.parsedType
8354
+ });
8355
+ return INVALID2;
8356
+ }
8357
+ const discriminator = this.discriminator;
8358
+ const discriminatorValue = ctx.data[discriminator];
8359
+ const option = this.optionsMap.get(discriminatorValue);
8360
+ if (!option) {
8361
+ addIssueToContext2(ctx, {
8362
+ code: ZodIssueCode2.invalid_union_discriminator,
8363
+ options: Array.from(this.optionsMap.keys()),
8364
+ path: [discriminator]
8365
+ });
8366
+ return INVALID2;
8367
+ }
8368
+ if (ctx.common.async) {
8369
+ return option._parseAsync({
8370
+ data: ctx.data,
8371
+ path: ctx.path,
8372
+ parent: ctx
8373
+ });
8374
+ } else {
8375
+ return option._parseSync({
8376
+ data: ctx.data,
8377
+ path: ctx.path,
8378
+ parent: ctx
8379
+ });
8380
+ }
8381
+ }
8382
+ get discriminator() {
8383
+ return this._def.discriminator;
8384
+ }
8385
+ get options() {
8386
+ return this._def.options;
8387
+ }
8388
+ get optionsMap() {
8389
+ return this._def.optionsMap;
8390
+ }
8391
+ /**
8392
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
8393
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
8394
+ * have a different value for each object in the union.
8395
+ * @param discriminator the name of the discriminator property
8396
+ * @param types an array of object schemas
8397
+ * @param params
8398
+ */
8399
+ static create(discriminator, options, params) {
8400
+ const optionsMap = /* @__PURE__ */ new Map();
8401
+ for (const type of options) {
8402
+ const discriminatorValues = getDiscriminator2(type.shape[discriminator]);
8403
+ if (!discriminatorValues) {
8404
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
8405
+ }
8406
+ for (const value of discriminatorValues) {
8407
+ if (optionsMap.has(value)) {
8408
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
8409
+ }
8410
+ optionsMap.set(value, type);
8411
+ }
8412
+ }
8413
+ return new _ZodDiscriminatedUnion({
8414
+ typeName: ZodFirstPartyTypeKind2.ZodDiscriminatedUnion,
8415
+ discriminator,
8416
+ options,
8417
+ optionsMap,
8418
+ ...processCreateParams2(params)
8419
+ });
8420
+ }
8421
+ };
8422
+ function mergeValues2(a, b) {
8423
+ const aType = getParsedType2(a);
8424
+ const bType = getParsedType2(b);
8425
+ if (a === b) {
8426
+ return { valid: true, data: a };
8427
+ } else if (aType === ZodParsedType2.object && bType === ZodParsedType2.object) {
8428
+ const bKeys = util2.objectKeys(b);
8429
+ const sharedKeys = util2.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
8430
+ const newObj = { ...a, ...b };
8431
+ for (const key of sharedKeys) {
8432
+ const sharedValue = mergeValues2(a[key], b[key]);
8433
+ if (!sharedValue.valid) {
8434
+ return { valid: false };
8435
+ }
8436
+ newObj[key] = sharedValue.data;
8437
+ }
8438
+ return { valid: true, data: newObj };
8439
+ } else if (aType === ZodParsedType2.array && bType === ZodParsedType2.array) {
8440
+ if (a.length !== b.length) {
8441
+ return { valid: false };
8442
+ }
8443
+ const newArray = [];
8444
+ for (let index = 0; index < a.length; index++) {
8445
+ const itemA = a[index];
8446
+ const itemB = b[index];
8447
+ const sharedValue = mergeValues2(itemA, itemB);
8448
+ if (!sharedValue.valid) {
8449
+ return { valid: false };
8450
+ }
8451
+ newArray.push(sharedValue.data);
8452
+ }
8453
+ return { valid: true, data: newArray };
8454
+ } else if (aType === ZodParsedType2.date && bType === ZodParsedType2.date && +a === +b) {
8455
+ return { valid: true, data: a };
8456
+ } else {
8457
+ return { valid: false };
8458
+ }
8459
+ }
8460
+ var ZodIntersection2 = class extends ZodType2 {
8461
+ _parse(input) {
8462
+ const { status, ctx } = this._processInputParams(input);
8463
+ const handleParsed = (parsedLeft, parsedRight) => {
8464
+ if (isAborted2(parsedLeft) || isAborted2(parsedRight)) {
8465
+ return INVALID2;
8466
+ }
8467
+ const merged = mergeValues2(parsedLeft.value, parsedRight.value);
8468
+ if (!merged.valid) {
8469
+ addIssueToContext2(ctx, {
8470
+ code: ZodIssueCode2.invalid_intersection_types
8471
+ });
8472
+ return INVALID2;
8473
+ }
8474
+ if (isDirty2(parsedLeft) || isDirty2(parsedRight)) {
8475
+ status.dirty();
8476
+ }
8477
+ return { status: status.value, value: merged.data };
8478
+ };
8479
+ if (ctx.common.async) {
8480
+ return Promise.all([
8481
+ this._def.left._parseAsync({
8482
+ data: ctx.data,
8483
+ path: ctx.path,
8484
+ parent: ctx
8485
+ }),
8486
+ this._def.right._parseAsync({
8487
+ data: ctx.data,
8488
+ path: ctx.path,
8489
+ parent: ctx
8490
+ })
8491
+ ]).then(([left, right]) => handleParsed(left, right));
8492
+ } else {
8493
+ return handleParsed(this._def.left._parseSync({
8494
+ data: ctx.data,
8495
+ path: ctx.path,
8496
+ parent: ctx
8497
+ }), this._def.right._parseSync({
8498
+ data: ctx.data,
8499
+ path: ctx.path,
8500
+ parent: ctx
8501
+ }));
8502
+ }
8503
+ }
8504
+ };
8505
+ ZodIntersection2.create = (left, right, params) => {
8506
+ return new ZodIntersection2({
8507
+ left,
8508
+ right,
8509
+ typeName: ZodFirstPartyTypeKind2.ZodIntersection,
8510
+ ...processCreateParams2(params)
8511
+ });
8512
+ };
8513
+ var ZodTuple2 = class _ZodTuple extends ZodType2 {
8514
+ _parse(input) {
8515
+ const { status, ctx } = this._processInputParams(input);
8516
+ if (ctx.parsedType !== ZodParsedType2.array) {
8517
+ addIssueToContext2(ctx, {
8518
+ code: ZodIssueCode2.invalid_type,
8519
+ expected: ZodParsedType2.array,
8520
+ received: ctx.parsedType
8521
+ });
8522
+ return INVALID2;
8523
+ }
8524
+ if (ctx.data.length < this._def.items.length) {
8525
+ addIssueToContext2(ctx, {
8526
+ code: ZodIssueCode2.too_small,
8527
+ minimum: this._def.items.length,
8528
+ inclusive: true,
8529
+ exact: false,
8530
+ type: "array"
8531
+ });
8532
+ return INVALID2;
8533
+ }
8534
+ const rest = this._def.rest;
8535
+ if (!rest && ctx.data.length > this._def.items.length) {
8536
+ addIssueToContext2(ctx, {
8537
+ code: ZodIssueCode2.too_big,
8538
+ maximum: this._def.items.length,
8539
+ inclusive: true,
8540
+ exact: false,
8541
+ type: "array"
8542
+ });
8543
+ status.dirty();
8544
+ }
8545
+ const items = [...ctx.data].map((item, itemIndex) => {
8546
+ const schema = this._def.items[itemIndex] || this._def.rest;
8547
+ if (!schema)
8548
+ return null;
8549
+ return schema._parse(new ParseInputLazyPath2(ctx, item, ctx.path, itemIndex));
8550
+ }).filter((x) => !!x);
8551
+ if (ctx.common.async) {
8552
+ return Promise.all(items).then((results) => {
8553
+ return ParseStatus2.mergeArray(status, results);
8554
+ });
8555
+ } else {
8556
+ return ParseStatus2.mergeArray(status, items);
8557
+ }
8558
+ }
8559
+ get items() {
8560
+ return this._def.items;
8561
+ }
8562
+ rest(rest) {
8563
+ return new _ZodTuple({
8564
+ ...this._def,
8565
+ rest
8566
+ });
8567
+ }
8568
+ };
8569
+ ZodTuple2.create = (schemas, params) => {
8570
+ if (!Array.isArray(schemas)) {
8571
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
8572
+ }
8573
+ return new ZodTuple2({
8574
+ items: schemas,
8575
+ typeName: ZodFirstPartyTypeKind2.ZodTuple,
8576
+ rest: null,
8577
+ ...processCreateParams2(params)
8578
+ });
8579
+ };
8580
+ var ZodRecord2 = class _ZodRecord extends ZodType2 {
8581
+ get keySchema() {
8582
+ return this._def.keyType;
8583
+ }
8584
+ get valueSchema() {
8585
+ return this._def.valueType;
8586
+ }
8587
+ _parse(input) {
8588
+ const { status, ctx } = this._processInputParams(input);
8589
+ if (ctx.parsedType !== ZodParsedType2.object) {
8590
+ addIssueToContext2(ctx, {
8591
+ code: ZodIssueCode2.invalid_type,
8592
+ expected: ZodParsedType2.object,
8593
+ received: ctx.parsedType
8594
+ });
8595
+ return INVALID2;
8596
+ }
8597
+ const pairs = [];
8598
+ const keyType = this._def.keyType;
8599
+ const valueType = this._def.valueType;
8600
+ for (const key in ctx.data) {
8601
+ pairs.push({
8602
+ key: keyType._parse(new ParseInputLazyPath2(ctx, key, ctx.path, key)),
8603
+ value: valueType._parse(new ParseInputLazyPath2(ctx, ctx.data[key], ctx.path, key))
8604
+ });
8605
+ }
8606
+ if (ctx.common.async) {
8607
+ return ParseStatus2.mergeObjectAsync(status, pairs);
8608
+ } else {
8609
+ return ParseStatus2.mergeObjectSync(status, pairs);
8610
+ }
8611
+ }
8612
+ get element() {
8613
+ return this._def.valueType;
8614
+ }
8615
+ static create(first, second, third) {
8616
+ if (second instanceof ZodType2) {
8617
+ return new _ZodRecord({
8618
+ keyType: first,
8619
+ valueType: second,
8620
+ typeName: ZodFirstPartyTypeKind2.ZodRecord,
8621
+ ...processCreateParams2(third)
8622
+ });
8623
+ }
8624
+ return new _ZodRecord({
8625
+ keyType: ZodString2.create(),
8626
+ valueType: first,
8627
+ typeName: ZodFirstPartyTypeKind2.ZodRecord,
8628
+ ...processCreateParams2(second)
8629
+ });
8630
+ }
8631
+ };
8632
+ var ZodMap2 = class extends ZodType2 {
8633
+ get keySchema() {
8634
+ return this._def.keyType;
8635
+ }
8636
+ get valueSchema() {
8637
+ return this._def.valueType;
8638
+ }
8639
+ _parse(input) {
8640
+ const { status, ctx } = this._processInputParams(input);
8641
+ if (ctx.parsedType !== ZodParsedType2.map) {
8642
+ addIssueToContext2(ctx, {
8643
+ code: ZodIssueCode2.invalid_type,
8644
+ expected: ZodParsedType2.map,
8645
+ received: ctx.parsedType
8646
+ });
8647
+ return INVALID2;
8648
+ }
8649
+ const keyType = this._def.keyType;
8650
+ const valueType = this._def.valueType;
8651
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
8652
+ return {
8653
+ key: keyType._parse(new ParseInputLazyPath2(ctx, key, ctx.path, [index, "key"])),
8654
+ value: valueType._parse(new ParseInputLazyPath2(ctx, value, ctx.path, [index, "value"]))
8655
+ };
8656
+ });
8657
+ if (ctx.common.async) {
8658
+ const finalMap = /* @__PURE__ */ new Map();
8659
+ return Promise.resolve().then(async () => {
8660
+ for (const pair of pairs) {
8661
+ const key = await pair.key;
8662
+ const value = await pair.value;
8663
+ if (key.status === "aborted" || value.status === "aborted") {
8664
+ return INVALID2;
8665
+ }
8666
+ if (key.status === "dirty" || value.status === "dirty") {
8667
+ status.dirty();
8668
+ }
8669
+ finalMap.set(key.value, value.value);
8670
+ }
8671
+ return { status: status.value, value: finalMap };
8672
+ });
8673
+ } else {
8674
+ const finalMap = /* @__PURE__ */ new Map();
8675
+ for (const pair of pairs) {
8676
+ const key = pair.key;
8677
+ const value = pair.value;
8678
+ if (key.status === "aborted" || value.status === "aborted") {
8679
+ return INVALID2;
8680
+ }
8681
+ if (key.status === "dirty" || value.status === "dirty") {
8682
+ status.dirty();
8683
+ }
8684
+ finalMap.set(key.value, value.value);
8685
+ }
8686
+ return { status: status.value, value: finalMap };
8687
+ }
8688
+ }
8689
+ };
8690
+ ZodMap2.create = (keyType, valueType, params) => {
8691
+ return new ZodMap2({
8692
+ valueType,
8693
+ keyType,
8694
+ typeName: ZodFirstPartyTypeKind2.ZodMap,
8695
+ ...processCreateParams2(params)
8696
+ });
8697
+ };
8698
+ var ZodSet2 = class _ZodSet extends ZodType2 {
8699
+ _parse(input) {
8700
+ const { status, ctx } = this._processInputParams(input);
8701
+ if (ctx.parsedType !== ZodParsedType2.set) {
8702
+ addIssueToContext2(ctx, {
8703
+ code: ZodIssueCode2.invalid_type,
8704
+ expected: ZodParsedType2.set,
8705
+ received: ctx.parsedType
8706
+ });
8707
+ return INVALID2;
8708
+ }
8709
+ const def = this._def;
8710
+ if (def.minSize !== null) {
8711
+ if (ctx.data.size < def.minSize.value) {
8712
+ addIssueToContext2(ctx, {
8713
+ code: ZodIssueCode2.too_small,
8714
+ minimum: def.minSize.value,
8715
+ type: "set",
8716
+ inclusive: true,
8717
+ exact: false,
8718
+ message: def.minSize.message
8719
+ });
8720
+ status.dirty();
8721
+ }
8722
+ }
8723
+ if (def.maxSize !== null) {
8724
+ if (ctx.data.size > def.maxSize.value) {
8725
+ addIssueToContext2(ctx, {
8726
+ code: ZodIssueCode2.too_big,
8727
+ maximum: def.maxSize.value,
8728
+ type: "set",
8729
+ inclusive: true,
8730
+ exact: false,
8731
+ message: def.maxSize.message
8732
+ });
8733
+ status.dirty();
8734
+ }
8735
+ }
8736
+ const valueType = this._def.valueType;
8737
+ function finalizeSet(elements2) {
8738
+ const parsedSet = /* @__PURE__ */ new Set();
8739
+ for (const element of elements2) {
8740
+ if (element.status === "aborted")
8741
+ return INVALID2;
8742
+ if (element.status === "dirty")
8743
+ status.dirty();
8744
+ parsedSet.add(element.value);
8745
+ }
8746
+ return { status: status.value, value: parsedSet };
8747
+ }
8748
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath2(ctx, item, ctx.path, i)));
8749
+ if (ctx.common.async) {
8750
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
8751
+ } else {
8752
+ return finalizeSet(elements);
8753
+ }
8754
+ }
8755
+ min(minSize, message) {
8756
+ return new _ZodSet({
8757
+ ...this._def,
8758
+ minSize: { value: minSize, message: errorUtil2.toString(message) }
8759
+ });
8760
+ }
8761
+ max(maxSize, message) {
8762
+ return new _ZodSet({
8763
+ ...this._def,
8764
+ maxSize: { value: maxSize, message: errorUtil2.toString(message) }
8765
+ });
8766
+ }
8767
+ size(size, message) {
8768
+ return this.min(size, message).max(size, message);
8769
+ }
8770
+ nonempty(message) {
8771
+ return this.min(1, message);
8772
+ }
8773
+ };
8774
+ ZodSet2.create = (valueType, params) => {
8775
+ return new ZodSet2({
8776
+ valueType,
8777
+ minSize: null,
8778
+ maxSize: null,
8779
+ typeName: ZodFirstPartyTypeKind2.ZodSet,
8780
+ ...processCreateParams2(params)
8781
+ });
8782
+ };
8783
+ var ZodFunction2 = class _ZodFunction extends ZodType2 {
8784
+ constructor() {
8785
+ super(...arguments);
8786
+ this.validate = this.implement;
8787
+ }
8788
+ _parse(input) {
8789
+ const { ctx } = this._processInputParams(input);
8790
+ if (ctx.parsedType !== ZodParsedType2.function) {
8791
+ addIssueToContext2(ctx, {
8792
+ code: ZodIssueCode2.invalid_type,
8793
+ expected: ZodParsedType2.function,
8794
+ received: ctx.parsedType
8795
+ });
8796
+ return INVALID2;
8797
+ }
8798
+ function makeArgsIssue(args, error) {
8799
+ return makeIssue2({
8800
+ data: args,
8801
+ path: ctx.path,
8802
+ errorMaps: [
8803
+ ctx.common.contextualErrorMap,
8804
+ ctx.schemaErrorMap,
8805
+ getErrorMap2(),
8806
+ errorMap2
8807
+ ].filter((x) => !!x),
8808
+ issueData: {
8809
+ code: ZodIssueCode2.invalid_arguments,
8810
+ argumentsError: error
8811
+ }
8812
+ });
8813
+ }
8814
+ function makeReturnsIssue(returns, error) {
8815
+ return makeIssue2({
8816
+ data: returns,
8817
+ path: ctx.path,
8818
+ errorMaps: [
8819
+ ctx.common.contextualErrorMap,
8820
+ ctx.schemaErrorMap,
8821
+ getErrorMap2(),
8822
+ errorMap2
8823
+ ].filter((x) => !!x),
8824
+ issueData: {
8825
+ code: ZodIssueCode2.invalid_return_type,
8826
+ returnTypeError: error
8827
+ }
8828
+ });
8829
+ }
8830
+ const params = { errorMap: ctx.common.contextualErrorMap };
8831
+ const fn = ctx.data;
8832
+ if (this._def.returns instanceof ZodPromise2) {
8833
+ const me = this;
8834
+ return OK2(async function(...args) {
8835
+ const error = new ZodError2([]);
8836
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
8837
+ error.addIssue(makeArgsIssue(args, e));
8838
+ throw error;
8839
+ });
8840
+ const result = await Reflect.apply(fn, this, parsedArgs);
8841
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
8842
+ error.addIssue(makeReturnsIssue(result, e));
8843
+ throw error;
8844
+ });
8845
+ return parsedReturns;
8846
+ });
8847
+ } else {
8848
+ const me = this;
8849
+ return OK2(function(...args) {
8850
+ const parsedArgs = me._def.args.safeParse(args, params);
8851
+ if (!parsedArgs.success) {
8852
+ throw new ZodError2([makeArgsIssue(args, parsedArgs.error)]);
8853
+ }
8854
+ const result = Reflect.apply(fn, this, parsedArgs.data);
8855
+ const parsedReturns = me._def.returns.safeParse(result, params);
8856
+ if (!parsedReturns.success) {
8857
+ throw new ZodError2([makeReturnsIssue(result, parsedReturns.error)]);
8858
+ }
8859
+ return parsedReturns.data;
8860
+ });
8861
+ }
8862
+ }
8863
+ parameters() {
8864
+ return this._def.args;
8865
+ }
8866
+ returnType() {
8867
+ return this._def.returns;
8868
+ }
8869
+ args(...items) {
8870
+ return new _ZodFunction({
8871
+ ...this._def,
8872
+ args: ZodTuple2.create(items).rest(ZodUnknown2.create())
8873
+ });
8874
+ }
8875
+ returns(returnType) {
8876
+ return new _ZodFunction({
8877
+ ...this._def,
8878
+ returns: returnType
8879
+ });
8880
+ }
8881
+ implement(func) {
8882
+ const validatedFunc = this.parse(func);
8883
+ return validatedFunc;
8884
+ }
8885
+ strictImplement(func) {
8886
+ const validatedFunc = this.parse(func);
8887
+ return validatedFunc;
8888
+ }
8889
+ static create(args, returns, params) {
8890
+ return new _ZodFunction({
8891
+ args: args ? args : ZodTuple2.create([]).rest(ZodUnknown2.create()),
8892
+ returns: returns || ZodUnknown2.create(),
8893
+ typeName: ZodFirstPartyTypeKind2.ZodFunction,
8894
+ ...processCreateParams2(params)
8895
+ });
8896
+ }
8897
+ };
8898
+ var ZodLazy2 = class extends ZodType2 {
8899
+ get schema() {
8900
+ return this._def.getter();
8901
+ }
8902
+ _parse(input) {
8903
+ const { ctx } = this._processInputParams(input);
8904
+ const lazySchema = this._def.getter();
8905
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
8906
+ }
8907
+ };
8908
+ ZodLazy2.create = (getter, params) => {
8909
+ return new ZodLazy2({
8910
+ getter,
8911
+ typeName: ZodFirstPartyTypeKind2.ZodLazy,
8912
+ ...processCreateParams2(params)
8913
+ });
8914
+ };
8915
+ var ZodLiteral2 = class extends ZodType2 {
8916
+ _parse(input) {
8917
+ if (input.data !== this._def.value) {
8918
+ const ctx = this._getOrReturnCtx(input);
8919
+ addIssueToContext2(ctx, {
8920
+ received: ctx.data,
8921
+ code: ZodIssueCode2.invalid_literal,
8922
+ expected: this._def.value
8923
+ });
8924
+ return INVALID2;
8925
+ }
8926
+ return { status: "valid", value: input.data };
8927
+ }
8928
+ get value() {
8929
+ return this._def.value;
8930
+ }
8931
+ };
8932
+ ZodLiteral2.create = (value, params) => {
8933
+ return new ZodLiteral2({
8934
+ value,
8935
+ typeName: ZodFirstPartyTypeKind2.ZodLiteral,
8936
+ ...processCreateParams2(params)
8937
+ });
8938
+ };
8939
+ function createZodEnum2(values, params) {
8940
+ return new ZodEnum2({
8941
+ values,
8942
+ typeName: ZodFirstPartyTypeKind2.ZodEnum,
8943
+ ...processCreateParams2(params)
8944
+ });
8945
+ }
8946
+ var ZodEnum2 = class _ZodEnum extends ZodType2 {
8947
+ _parse(input) {
8948
+ if (typeof input.data !== "string") {
8949
+ const ctx = this._getOrReturnCtx(input);
8950
+ const expectedValues = this._def.values;
8951
+ addIssueToContext2(ctx, {
8952
+ expected: util2.joinValues(expectedValues),
8953
+ received: ctx.parsedType,
8954
+ code: ZodIssueCode2.invalid_type
8955
+ });
8956
+ return INVALID2;
8957
+ }
8958
+ if (this._def.values.indexOf(input.data) === -1) {
8959
+ const ctx = this._getOrReturnCtx(input);
8960
+ const expectedValues = this._def.values;
8961
+ addIssueToContext2(ctx, {
8962
+ received: ctx.data,
8963
+ code: ZodIssueCode2.invalid_enum_value,
8964
+ options: expectedValues
8965
+ });
8966
+ return INVALID2;
8967
+ }
8968
+ return OK2(input.data);
8969
+ }
8970
+ get options() {
8971
+ return this._def.values;
8972
+ }
8973
+ get enum() {
8974
+ const enumValues = {};
8975
+ for (const val of this._def.values) {
8976
+ enumValues[val] = val;
8977
+ }
8978
+ return enumValues;
8979
+ }
8980
+ get Values() {
8981
+ const enumValues = {};
8982
+ for (const val of this._def.values) {
8983
+ enumValues[val] = val;
8984
+ }
8985
+ return enumValues;
8986
+ }
8987
+ get Enum() {
8988
+ const enumValues = {};
8989
+ for (const val of this._def.values) {
8990
+ enumValues[val] = val;
8991
+ }
8992
+ return enumValues;
8993
+ }
8994
+ extract(values) {
8995
+ return _ZodEnum.create(values);
8996
+ }
8997
+ exclude(values) {
8998
+ return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
8999
+ }
9000
+ };
9001
+ ZodEnum2.create = createZodEnum2;
9002
+ var ZodNativeEnum2 = class extends ZodType2 {
9003
+ _parse(input) {
9004
+ const nativeEnumValues = util2.getValidEnumValues(this._def.values);
9005
+ const ctx = this._getOrReturnCtx(input);
9006
+ if (ctx.parsedType !== ZodParsedType2.string && ctx.parsedType !== ZodParsedType2.number) {
9007
+ const expectedValues = util2.objectValues(nativeEnumValues);
9008
+ addIssueToContext2(ctx, {
9009
+ expected: util2.joinValues(expectedValues),
9010
+ received: ctx.parsedType,
9011
+ code: ZodIssueCode2.invalid_type
9012
+ });
9013
+ return INVALID2;
9014
+ }
9015
+ if (nativeEnumValues.indexOf(input.data) === -1) {
9016
+ const expectedValues = util2.objectValues(nativeEnumValues);
9017
+ addIssueToContext2(ctx, {
9018
+ received: ctx.data,
9019
+ code: ZodIssueCode2.invalid_enum_value,
9020
+ options: expectedValues
9021
+ });
9022
+ return INVALID2;
9023
+ }
9024
+ return OK2(input.data);
9025
+ }
9026
+ get enum() {
9027
+ return this._def.values;
9028
+ }
9029
+ };
9030
+ ZodNativeEnum2.create = (values, params) => {
9031
+ return new ZodNativeEnum2({
9032
+ values,
9033
+ typeName: ZodFirstPartyTypeKind2.ZodNativeEnum,
9034
+ ...processCreateParams2(params)
9035
+ });
9036
+ };
9037
+ var ZodPromise2 = class extends ZodType2 {
9038
+ unwrap() {
9039
+ return this._def.type;
9040
+ }
9041
+ _parse(input) {
9042
+ const { ctx } = this._processInputParams(input);
9043
+ if (ctx.parsedType !== ZodParsedType2.promise && ctx.common.async === false) {
9044
+ addIssueToContext2(ctx, {
9045
+ code: ZodIssueCode2.invalid_type,
9046
+ expected: ZodParsedType2.promise,
9047
+ received: ctx.parsedType
9048
+ });
9049
+ return INVALID2;
9050
+ }
9051
+ const promisified = ctx.parsedType === ZodParsedType2.promise ? ctx.data : Promise.resolve(ctx.data);
9052
+ return OK2(promisified.then((data) => {
9053
+ return this._def.type.parseAsync(data, {
9054
+ path: ctx.path,
9055
+ errorMap: ctx.common.contextualErrorMap
9056
+ });
9057
+ }));
9058
+ }
9059
+ };
9060
+ ZodPromise2.create = (schema, params) => {
9061
+ return new ZodPromise2({
9062
+ type: schema,
9063
+ typeName: ZodFirstPartyTypeKind2.ZodPromise,
9064
+ ...processCreateParams2(params)
9065
+ });
9066
+ };
9067
+ var ZodEffects2 = class extends ZodType2 {
9068
+ innerType() {
9069
+ return this._def.schema;
9070
+ }
9071
+ sourceType() {
9072
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind2.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
9073
+ }
9074
+ _parse(input) {
9075
+ const { status, ctx } = this._processInputParams(input);
9076
+ const effect = this._def.effect || null;
9077
+ const checkCtx = {
9078
+ addIssue: (arg) => {
9079
+ addIssueToContext2(ctx, arg);
9080
+ if (arg.fatal) {
9081
+ status.abort();
9082
+ } else {
9083
+ status.dirty();
9084
+ }
9085
+ },
9086
+ get path() {
9087
+ return ctx.path;
9088
+ }
9089
+ };
9090
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
9091
+ if (effect.type === "preprocess") {
9092
+ const processed = effect.transform(ctx.data, checkCtx);
9093
+ if (ctx.common.issues.length) {
9094
+ return {
9095
+ status: "dirty",
9096
+ value: ctx.data
9097
+ };
9098
+ }
9099
+ if (ctx.common.async) {
9100
+ return Promise.resolve(processed).then((processed2) => {
9101
+ return this._def.schema._parseAsync({
9102
+ data: processed2,
9103
+ path: ctx.path,
9104
+ parent: ctx
9105
+ });
9106
+ });
9107
+ } else {
9108
+ return this._def.schema._parseSync({
9109
+ data: processed,
9110
+ path: ctx.path,
9111
+ parent: ctx
9112
+ });
9113
+ }
9114
+ }
9115
+ if (effect.type === "refinement") {
9116
+ const executeRefinement = (acc) => {
9117
+ const result = effect.refinement(acc, checkCtx);
9118
+ if (ctx.common.async) {
9119
+ return Promise.resolve(result);
9120
+ }
9121
+ if (result instanceof Promise) {
9122
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
9123
+ }
9124
+ return acc;
9125
+ };
9126
+ if (ctx.common.async === false) {
9127
+ const inner = this._def.schema._parseSync({
9128
+ data: ctx.data,
9129
+ path: ctx.path,
9130
+ parent: ctx
9131
+ });
9132
+ if (inner.status === "aborted")
9133
+ return INVALID2;
9134
+ if (inner.status === "dirty")
9135
+ status.dirty();
9136
+ executeRefinement(inner.value);
9137
+ return { status: status.value, value: inner.value };
9138
+ } else {
9139
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
9140
+ if (inner.status === "aborted")
9141
+ return INVALID2;
9142
+ if (inner.status === "dirty")
9143
+ status.dirty();
9144
+ return executeRefinement(inner.value).then(() => {
9145
+ return { status: status.value, value: inner.value };
9146
+ });
9147
+ });
9148
+ }
9149
+ }
9150
+ if (effect.type === "transform") {
9151
+ if (ctx.common.async === false) {
9152
+ const base = this._def.schema._parseSync({
9153
+ data: ctx.data,
9154
+ path: ctx.path,
9155
+ parent: ctx
9156
+ });
9157
+ if (!isValid2(base))
9158
+ return base;
9159
+ const result = effect.transform(base.value, checkCtx);
9160
+ if (result instanceof Promise) {
9161
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
9162
+ }
9163
+ return { status: status.value, value: result };
9164
+ } else {
9165
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
9166
+ if (!isValid2(base))
9167
+ return base;
9168
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
9169
+ });
9170
+ }
9171
+ }
9172
+ util2.assertNever(effect);
9173
+ }
9174
+ };
9175
+ ZodEffects2.create = (schema, effect, params) => {
9176
+ return new ZodEffects2({
9177
+ schema,
9178
+ typeName: ZodFirstPartyTypeKind2.ZodEffects,
9179
+ effect,
9180
+ ...processCreateParams2(params)
9181
+ });
9182
+ };
9183
+ ZodEffects2.createWithPreprocess = (preprocess, schema, params) => {
9184
+ return new ZodEffects2({
9185
+ schema,
9186
+ effect: { type: "preprocess", transform: preprocess },
9187
+ typeName: ZodFirstPartyTypeKind2.ZodEffects,
9188
+ ...processCreateParams2(params)
9189
+ });
9190
+ };
9191
+ var ZodOptional2 = class extends ZodType2 {
9192
+ _parse(input) {
9193
+ const parsedType = this._getType(input);
9194
+ if (parsedType === ZodParsedType2.undefined) {
9195
+ return OK2(void 0);
9196
+ }
9197
+ return this._def.innerType._parse(input);
9198
+ }
9199
+ unwrap() {
9200
+ return this._def.innerType;
9201
+ }
9202
+ };
9203
+ ZodOptional2.create = (type, params) => {
9204
+ return new ZodOptional2({
9205
+ innerType: type,
9206
+ typeName: ZodFirstPartyTypeKind2.ZodOptional,
9207
+ ...processCreateParams2(params)
9208
+ });
9209
+ };
9210
+ var ZodNullable2 = class extends ZodType2 {
9211
+ _parse(input) {
9212
+ const parsedType = this._getType(input);
9213
+ if (parsedType === ZodParsedType2.null) {
9214
+ return OK2(null);
9215
+ }
9216
+ return this._def.innerType._parse(input);
9217
+ }
9218
+ unwrap() {
9219
+ return this._def.innerType;
9220
+ }
9221
+ };
9222
+ ZodNullable2.create = (type, params) => {
9223
+ return new ZodNullable2({
9224
+ innerType: type,
9225
+ typeName: ZodFirstPartyTypeKind2.ZodNullable,
9226
+ ...processCreateParams2(params)
9227
+ });
9228
+ };
9229
+ var ZodDefault2 = class extends ZodType2 {
9230
+ _parse(input) {
9231
+ const { ctx } = this._processInputParams(input);
9232
+ let data = ctx.data;
9233
+ if (ctx.parsedType === ZodParsedType2.undefined) {
9234
+ data = this._def.defaultValue();
9235
+ }
9236
+ return this._def.innerType._parse({
9237
+ data,
9238
+ path: ctx.path,
9239
+ parent: ctx
9240
+ });
9241
+ }
9242
+ removeDefault() {
9243
+ return this._def.innerType;
9244
+ }
9245
+ };
9246
+ ZodDefault2.create = (type, params) => {
9247
+ return new ZodDefault2({
9248
+ innerType: type,
9249
+ typeName: ZodFirstPartyTypeKind2.ZodDefault,
9250
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
9251
+ ...processCreateParams2(params)
9252
+ });
9253
+ };
9254
+ var ZodCatch2 = class extends ZodType2 {
9255
+ _parse(input) {
9256
+ const { ctx } = this._processInputParams(input);
9257
+ const newCtx = {
9258
+ ...ctx,
9259
+ common: {
9260
+ ...ctx.common,
9261
+ issues: []
9262
+ }
9263
+ };
9264
+ const result = this._def.innerType._parse({
9265
+ data: newCtx.data,
9266
+ path: newCtx.path,
9267
+ parent: {
9268
+ ...newCtx
9269
+ }
9270
+ });
9271
+ if (isAsync2(result)) {
9272
+ return result.then((result2) => {
9273
+ return {
9274
+ status: "valid",
9275
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
9276
+ get error() {
9277
+ return new ZodError2(newCtx.common.issues);
9278
+ },
9279
+ input: newCtx.data
9280
+ })
9281
+ };
9282
+ });
9283
+ } else {
9284
+ return {
9285
+ status: "valid",
9286
+ value: result.status === "valid" ? result.value : this._def.catchValue({
9287
+ get error() {
9288
+ return new ZodError2(newCtx.common.issues);
9289
+ },
9290
+ input: newCtx.data
9291
+ })
9292
+ };
9293
+ }
9294
+ }
9295
+ removeCatch() {
9296
+ return this._def.innerType;
9297
+ }
9298
+ };
9299
+ ZodCatch2.create = (type, params) => {
9300
+ return new ZodCatch2({
9301
+ innerType: type,
9302
+ typeName: ZodFirstPartyTypeKind2.ZodCatch,
9303
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
9304
+ ...processCreateParams2(params)
9305
+ });
9306
+ };
9307
+ var ZodNaN2 = class extends ZodType2 {
9308
+ _parse(input) {
9309
+ const parsedType = this._getType(input);
9310
+ if (parsedType !== ZodParsedType2.nan) {
9311
+ const ctx = this._getOrReturnCtx(input);
9312
+ addIssueToContext2(ctx, {
9313
+ code: ZodIssueCode2.invalid_type,
9314
+ expected: ZodParsedType2.nan,
9315
+ received: ctx.parsedType
9316
+ });
9317
+ return INVALID2;
9318
+ }
9319
+ return { status: "valid", value: input.data };
9320
+ }
9321
+ };
9322
+ ZodNaN2.create = (params) => {
9323
+ return new ZodNaN2({
9324
+ typeName: ZodFirstPartyTypeKind2.ZodNaN,
9325
+ ...processCreateParams2(params)
9326
+ });
9327
+ };
9328
+ var BRAND2 = Symbol("zod_brand");
9329
+ var ZodBranded2 = class extends ZodType2 {
9330
+ _parse(input) {
9331
+ const { ctx } = this._processInputParams(input);
9332
+ const data = ctx.data;
9333
+ return this._def.type._parse({
9334
+ data,
9335
+ path: ctx.path,
9336
+ parent: ctx
9337
+ });
9338
+ }
9339
+ unwrap() {
9340
+ return this._def.type;
9341
+ }
9342
+ };
9343
+ var ZodPipeline2 = class _ZodPipeline extends ZodType2 {
9344
+ _parse(input) {
9345
+ const { status, ctx } = this._processInputParams(input);
9346
+ if (ctx.common.async) {
9347
+ const handleAsync = async () => {
9348
+ const inResult = await this._def.in._parseAsync({
9349
+ data: ctx.data,
9350
+ path: ctx.path,
9351
+ parent: ctx
9352
+ });
9353
+ if (inResult.status === "aborted")
9354
+ return INVALID2;
9355
+ if (inResult.status === "dirty") {
9356
+ status.dirty();
9357
+ return DIRTY2(inResult.value);
9358
+ } else {
9359
+ return this._def.out._parseAsync({
9360
+ data: inResult.value,
9361
+ path: ctx.path,
9362
+ parent: ctx
9363
+ });
9364
+ }
9365
+ };
9366
+ return handleAsync();
9367
+ } else {
9368
+ const inResult = this._def.in._parseSync({
9369
+ data: ctx.data,
9370
+ path: ctx.path,
9371
+ parent: ctx
9372
+ });
9373
+ if (inResult.status === "aborted")
9374
+ return INVALID2;
9375
+ if (inResult.status === "dirty") {
9376
+ status.dirty();
9377
+ return {
9378
+ status: "dirty",
9379
+ value: inResult.value
9380
+ };
9381
+ } else {
9382
+ return this._def.out._parseSync({
9383
+ data: inResult.value,
9384
+ path: ctx.path,
9385
+ parent: ctx
9386
+ });
9387
+ }
9388
+ }
9389
+ }
9390
+ static create(a, b) {
9391
+ return new _ZodPipeline({
9392
+ in: a,
9393
+ out: b,
9394
+ typeName: ZodFirstPartyTypeKind2.ZodPipeline
9395
+ });
9396
+ }
9397
+ };
9398
+ var ZodReadonly2 = class extends ZodType2 {
9399
+ _parse(input) {
9400
+ const result = this._def.innerType._parse(input);
9401
+ if (isValid2(result)) {
9402
+ result.value = Object.freeze(result.value);
9403
+ }
9404
+ return result;
9405
+ }
9406
+ };
9407
+ ZodReadonly2.create = (type, params) => {
9408
+ return new ZodReadonly2({
9409
+ innerType: type,
9410
+ typeName: ZodFirstPartyTypeKind2.ZodReadonly,
9411
+ ...processCreateParams2(params)
9412
+ });
9413
+ };
9414
+ var custom2 = (check, params = {}, fatal) => {
9415
+ if (check)
9416
+ return ZodAny2.create().superRefine((data, ctx) => {
9417
+ var _a, _b;
9418
+ if (!check(data)) {
9419
+ const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
9420
+ const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
9421
+ const p2 = typeof p === "string" ? { message: p } : p;
9422
+ ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
9423
+ }
9424
+ });
9425
+ return ZodAny2.create();
9426
+ };
9427
+ var late2 = {
9428
+ object: ZodObject2.lazycreate
9429
+ };
9430
+ var ZodFirstPartyTypeKind2;
9431
+ (function(ZodFirstPartyTypeKind3) {
9432
+ ZodFirstPartyTypeKind3["ZodString"] = "ZodString";
9433
+ ZodFirstPartyTypeKind3["ZodNumber"] = "ZodNumber";
9434
+ ZodFirstPartyTypeKind3["ZodNaN"] = "ZodNaN";
9435
+ ZodFirstPartyTypeKind3["ZodBigInt"] = "ZodBigInt";
9436
+ ZodFirstPartyTypeKind3["ZodBoolean"] = "ZodBoolean";
9437
+ ZodFirstPartyTypeKind3["ZodDate"] = "ZodDate";
9438
+ ZodFirstPartyTypeKind3["ZodSymbol"] = "ZodSymbol";
9439
+ ZodFirstPartyTypeKind3["ZodUndefined"] = "ZodUndefined";
9440
+ ZodFirstPartyTypeKind3["ZodNull"] = "ZodNull";
9441
+ ZodFirstPartyTypeKind3["ZodAny"] = "ZodAny";
9442
+ ZodFirstPartyTypeKind3["ZodUnknown"] = "ZodUnknown";
9443
+ ZodFirstPartyTypeKind3["ZodNever"] = "ZodNever";
9444
+ ZodFirstPartyTypeKind3["ZodVoid"] = "ZodVoid";
9445
+ ZodFirstPartyTypeKind3["ZodArray"] = "ZodArray";
9446
+ ZodFirstPartyTypeKind3["ZodObject"] = "ZodObject";
9447
+ ZodFirstPartyTypeKind3["ZodUnion"] = "ZodUnion";
9448
+ ZodFirstPartyTypeKind3["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
9449
+ ZodFirstPartyTypeKind3["ZodIntersection"] = "ZodIntersection";
9450
+ ZodFirstPartyTypeKind3["ZodTuple"] = "ZodTuple";
9451
+ ZodFirstPartyTypeKind3["ZodRecord"] = "ZodRecord";
9452
+ ZodFirstPartyTypeKind3["ZodMap"] = "ZodMap";
9453
+ ZodFirstPartyTypeKind3["ZodSet"] = "ZodSet";
9454
+ ZodFirstPartyTypeKind3["ZodFunction"] = "ZodFunction";
9455
+ ZodFirstPartyTypeKind3["ZodLazy"] = "ZodLazy";
9456
+ ZodFirstPartyTypeKind3["ZodLiteral"] = "ZodLiteral";
9457
+ ZodFirstPartyTypeKind3["ZodEnum"] = "ZodEnum";
9458
+ ZodFirstPartyTypeKind3["ZodEffects"] = "ZodEffects";
9459
+ ZodFirstPartyTypeKind3["ZodNativeEnum"] = "ZodNativeEnum";
9460
+ ZodFirstPartyTypeKind3["ZodOptional"] = "ZodOptional";
9461
+ ZodFirstPartyTypeKind3["ZodNullable"] = "ZodNullable";
9462
+ ZodFirstPartyTypeKind3["ZodDefault"] = "ZodDefault";
9463
+ ZodFirstPartyTypeKind3["ZodCatch"] = "ZodCatch";
9464
+ ZodFirstPartyTypeKind3["ZodPromise"] = "ZodPromise";
9465
+ ZodFirstPartyTypeKind3["ZodBranded"] = "ZodBranded";
9466
+ ZodFirstPartyTypeKind3["ZodPipeline"] = "ZodPipeline";
9467
+ ZodFirstPartyTypeKind3["ZodReadonly"] = "ZodReadonly";
9468
+ })(ZodFirstPartyTypeKind2 || (ZodFirstPartyTypeKind2 = {}));
9469
+ var instanceOfType2 = (cls, params = {
9470
+ message: `Input not instance of ${cls.name}`
9471
+ }) => custom2((data) => data instanceof cls, params);
9472
+ var stringType2 = ZodString2.create;
9473
+ var numberType2 = ZodNumber2.create;
9474
+ var nanType2 = ZodNaN2.create;
9475
+ var bigIntType2 = ZodBigInt2.create;
9476
+ var booleanType2 = ZodBoolean2.create;
9477
+ var dateType2 = ZodDate2.create;
9478
+ var symbolType2 = ZodSymbol2.create;
9479
+ var undefinedType2 = ZodUndefined2.create;
9480
+ var nullType2 = ZodNull2.create;
9481
+ var anyType2 = ZodAny2.create;
9482
+ var unknownType2 = ZodUnknown2.create;
9483
+ var neverType2 = ZodNever2.create;
9484
+ var voidType2 = ZodVoid2.create;
9485
+ var arrayType2 = ZodArray2.create;
9486
+ var objectType2 = ZodObject2.create;
9487
+ var strictObjectType2 = ZodObject2.strictCreate;
9488
+ var unionType2 = ZodUnion2.create;
9489
+ var discriminatedUnionType2 = ZodDiscriminatedUnion2.create;
9490
+ var intersectionType2 = ZodIntersection2.create;
9491
+ var tupleType2 = ZodTuple2.create;
9492
+ var recordType2 = ZodRecord2.create;
9493
+ var mapType2 = ZodMap2.create;
9494
+ var setType2 = ZodSet2.create;
9495
+ var functionType2 = ZodFunction2.create;
9496
+ var lazyType2 = ZodLazy2.create;
9497
+ var literalType2 = ZodLiteral2.create;
9498
+ var enumType2 = ZodEnum2.create;
9499
+ var nativeEnumType2 = ZodNativeEnum2.create;
9500
+ var promiseType2 = ZodPromise2.create;
9501
+ var effectsType2 = ZodEffects2.create;
9502
+ var optionalType2 = ZodOptional2.create;
9503
+ var nullableType2 = ZodNullable2.create;
9504
+ var preprocessType2 = ZodEffects2.createWithPreprocess;
9505
+ var pipelineType2 = ZodPipeline2.create;
9506
+ var ostring2 = () => stringType2().optional();
9507
+ var onumber2 = () => numberType2().optional();
9508
+ var oboolean2 = () => booleanType2().optional();
9509
+ var coerce2 = {
9510
+ string: (arg) => ZodString2.create({ ...arg, coerce: true }),
9511
+ number: (arg) => ZodNumber2.create({ ...arg, coerce: true }),
9512
+ boolean: (arg) => ZodBoolean2.create({
9513
+ ...arg,
9514
+ coerce: true
9515
+ }),
9516
+ bigint: (arg) => ZodBigInt2.create({ ...arg, coerce: true }),
9517
+ date: (arg) => ZodDate2.create({ ...arg, coerce: true })
9518
+ };
9519
+ var NEVER2 = INVALID2;
9520
+ var z2 = /* @__PURE__ */ Object.freeze({
9521
+ __proto__: null,
9522
+ defaultErrorMap: errorMap2,
9523
+ setErrorMap: setErrorMap2,
9524
+ getErrorMap: getErrorMap2,
9525
+ makeIssue: makeIssue2,
9526
+ EMPTY_PATH: EMPTY_PATH2,
9527
+ addIssueToContext: addIssueToContext2,
9528
+ ParseStatus: ParseStatus2,
9529
+ INVALID: INVALID2,
9530
+ DIRTY: DIRTY2,
9531
+ OK: OK2,
9532
+ isAborted: isAborted2,
9533
+ isDirty: isDirty2,
9534
+ isValid: isValid2,
9535
+ isAsync: isAsync2,
9536
+ get util() {
9537
+ return util2;
9538
+ },
9539
+ get objectUtil() {
9540
+ return objectUtil2;
9541
+ },
9542
+ ZodParsedType: ZodParsedType2,
9543
+ getParsedType: getParsedType2,
9544
+ ZodType: ZodType2,
9545
+ ZodString: ZodString2,
9546
+ ZodNumber: ZodNumber2,
9547
+ ZodBigInt: ZodBigInt2,
9548
+ ZodBoolean: ZodBoolean2,
9549
+ ZodDate: ZodDate2,
9550
+ ZodSymbol: ZodSymbol2,
9551
+ ZodUndefined: ZodUndefined2,
9552
+ ZodNull: ZodNull2,
9553
+ ZodAny: ZodAny2,
9554
+ ZodUnknown: ZodUnknown2,
9555
+ ZodNever: ZodNever2,
9556
+ ZodVoid: ZodVoid2,
9557
+ ZodArray: ZodArray2,
9558
+ ZodObject: ZodObject2,
9559
+ ZodUnion: ZodUnion2,
9560
+ ZodDiscriminatedUnion: ZodDiscriminatedUnion2,
9561
+ ZodIntersection: ZodIntersection2,
9562
+ ZodTuple: ZodTuple2,
9563
+ ZodRecord: ZodRecord2,
9564
+ ZodMap: ZodMap2,
9565
+ ZodSet: ZodSet2,
9566
+ ZodFunction: ZodFunction2,
9567
+ ZodLazy: ZodLazy2,
9568
+ ZodLiteral: ZodLiteral2,
9569
+ ZodEnum: ZodEnum2,
9570
+ ZodNativeEnum: ZodNativeEnum2,
9571
+ ZodPromise: ZodPromise2,
9572
+ ZodEffects: ZodEffects2,
9573
+ ZodTransformer: ZodEffects2,
9574
+ ZodOptional: ZodOptional2,
9575
+ ZodNullable: ZodNullable2,
9576
+ ZodDefault: ZodDefault2,
9577
+ ZodCatch: ZodCatch2,
9578
+ ZodNaN: ZodNaN2,
9579
+ BRAND: BRAND2,
9580
+ ZodBranded: ZodBranded2,
9581
+ ZodPipeline: ZodPipeline2,
9582
+ ZodReadonly: ZodReadonly2,
9583
+ custom: custom2,
9584
+ Schema: ZodType2,
9585
+ ZodSchema: ZodType2,
9586
+ late: late2,
9587
+ get ZodFirstPartyTypeKind() {
9588
+ return ZodFirstPartyTypeKind2;
9589
+ },
9590
+ coerce: coerce2,
9591
+ any: anyType2,
9592
+ array: arrayType2,
9593
+ bigint: bigIntType2,
9594
+ boolean: booleanType2,
9595
+ date: dateType2,
9596
+ discriminatedUnion: discriminatedUnionType2,
9597
+ effect: effectsType2,
9598
+ "enum": enumType2,
9599
+ "function": functionType2,
9600
+ "instanceof": instanceOfType2,
9601
+ intersection: intersectionType2,
9602
+ lazy: lazyType2,
9603
+ literal: literalType2,
9604
+ map: mapType2,
9605
+ nan: nanType2,
9606
+ nativeEnum: nativeEnumType2,
9607
+ never: neverType2,
9608
+ "null": nullType2,
9609
+ nullable: nullableType2,
9610
+ number: numberType2,
9611
+ object: objectType2,
9612
+ oboolean: oboolean2,
9613
+ onumber: onumber2,
9614
+ optional: optionalType2,
9615
+ ostring: ostring2,
9616
+ pipeline: pipelineType2,
9617
+ preprocess: preprocessType2,
9618
+ promise: promiseType2,
9619
+ record: recordType2,
9620
+ set: setType2,
9621
+ strictObject: strictObjectType2,
9622
+ string: stringType2,
9623
+ symbol: symbolType2,
9624
+ transformer: effectsType2,
9625
+ tuple: tupleType2,
9626
+ "undefined": undefinedType2,
9627
+ union: unionType2,
9628
+ unknown: unknownType2,
9629
+ "void": voidType2,
9630
+ NEVER: NEVER2,
9631
+ ZodIssueCode: ZodIssueCode2,
9632
+ quotelessJson: quotelessJson2,
9633
+ ZodError: ZodError2
9634
+ });
9635
+
9636
+ // src/vgf-recognition-state.ts
9637
+ var RecognitionVGFStateSchema = z2.object({
9638
+ // Core STT state
9639
+ audioUtteranceId: z2.string(),
9640
+ startRecordingStatus: z2.string().optional(),
9641
+ // "NOT_READY", "READY", "RECORDING", "FINISHED". States follow this order.
9642
+ // Streaming should only start when "READY". Other states control mic UI and recording.
9643
+ transcriptionStatus: z2.string().optional(),
9644
+ // "NOT_STARTED", "IN_PROGRESS", "FINALIZED", "ABORTED", "ERROR"
9645
+ finalTranscript: z2.string().optional(),
9646
+ // Full finalized transcript for the utterance. Will not change.
9647
+ finalConfidence: z2.number().optional(),
9648
+ // Tracking-only metadata
9649
+ asrConfig: z2.string().optional(),
9650
+ // Json format of the ASR config
9651
+ startRecordingTimestamp: z2.string().optional(),
9652
+ // Start of recording. Immutable after set.
9653
+ finalRecordingTimestamp: z2.string().optional(),
9654
+ // End of recording. Immutable after set. Transcription may still be in progress.
9655
+ finalTranscriptionTimestamp: z2.string().optional(),
9656
+ // When the final transcript was produced. Immutable after set.
9657
+ // STEP 2: Support for mic auto-stop upon correct answer
9658
+ pendingTranscript: z2.string().optional().default(""),
9659
+ // Non-final transcript that may change (matches existing naming)
9660
+ pendingConfidence: z2.number().optional(),
9661
+ // STEP 3: Support for semantic/function-call outcomes
9662
+ functionCallMetadata: z2.string().optional(),
9663
+ // Function call metadata in JSON, e.g. "{artist: true, title: true}"
9664
+ functionCallConfidence: z2.number().optional(),
9665
+ // Confidence score for the function call.
9666
+ finalFunctionCallTimestamp: z2.string().optional(),
9667
+ // When the final action after interpreting the transcript was taken. Immutable.
9668
+ // Support for prompt slot mapping - passed to recognition context when present
9669
+ promptSlotMap: z2.record(z2.string(), z2.array(z2.string())).optional(),
9670
+ // Optional map of slot names to prompt values for recognition context
9671
+ // Recognition action processing state - managed externally, SDK preserves but never modifies
9672
+ recognitionActionProcessingState: z2.string().optional()
9673
+ // "NOT_STARTED", "IN_PROGRESS", "COMPLETED"
9674
+ });
9675
+ var RecordingStatus = {
9676
+ NOT_READY: "NOT_READY",
9677
+ READY: "READY",
9678
+ RECORDING: "RECORDING",
9679
+ FINISHED: "FINISHED"
9680
+ };
9681
+ var TranscriptionStatus = {
9682
+ NOT_STARTED: "NOT_STARTED",
9683
+ IN_PROGRESS: "IN_PROGRESS",
9684
+ FINALIZED: "FINALIZED",
9685
+ ABORTED: "ABORTED",
9686
+ // Session was cancelled/abandoned by user
9687
+ ERROR: "ERROR"
9688
+ };
9689
+ var RecognitionActionProcessingState = {
9690
+ NOT_STARTED: "NOT_STARTED",
9691
+ IN_PROGRESS: "IN_PROGRESS",
9692
+ COMPLETED: "COMPLETED"
9693
+ };
9694
+ function createInitialRecognitionState(audioUtteranceId) {
9695
+ return {
9696
+ audioUtteranceId,
9697
+ startRecordingStatus: RecordingStatus.NOT_READY,
9698
+ transcriptionStatus: TranscriptionStatus.NOT_STARTED,
9699
+ pendingTranscript: "",
9700
+ recognitionActionProcessingState: RecognitionActionProcessingState.NOT_STARTED
9701
+ };
9702
+ }
9703
+ function isValidRecordingStatusTransition(from, to) {
9704
+ const statusOrder = [
9705
+ RecordingStatus.NOT_READY,
9706
+ RecordingStatus.READY,
9707
+ RecordingStatus.RECORDING,
9708
+ RecordingStatus.FINISHED
9709
+ ];
9710
+ const fromIndex = from ? statusOrder.indexOf(from) : -1;
9711
+ const toIndex = statusOrder.indexOf(to);
9712
+ return toIndex > fromIndex && toIndex !== -1;
9713
+ }
9714
+
9715
+ // src/vgf-recognition-mapper.ts
9716
+ function mapTranscriptionResultToState(currentState, result, isRecording) {
9717
+ const newState = { ...currentState };
9718
+ if (isRecording && currentState.startRecordingStatus !== RecordingStatus.FINISHED) {
9719
+ newState.startRecordingStatus = RecordingStatus.RECORDING;
9720
+ if (!newState.startRecordingTimestamp) {
9721
+ newState.startRecordingTimestamp = (/* @__PURE__ */ new Date()).toISOString();
9722
+ }
9723
+ }
9724
+ if (!result.is_finished) {
9725
+ newState.transcriptionStatus = TranscriptionStatus.IN_PROGRESS;
9726
+ newState.pendingTranscript = result.pendingTranscript || "";
9727
+ if (result.pendingTranscriptConfidence !== void 0) {
9728
+ newState.pendingConfidence = result.pendingTranscriptConfidence;
9729
+ }
9730
+ if (result.finalTranscript) {
9731
+ newState.finalTranscript = result.finalTranscript;
9732
+ if (result.finalTranscriptConfidence !== void 0) {
9733
+ newState.finalConfidence = result.finalTranscriptConfidence;
9734
+ }
9735
+ }
9736
+ } else {
9737
+ newState.transcriptionStatus = TranscriptionStatus.FINALIZED;
9738
+ newState.finalTranscript = result.finalTranscript || "";
9739
+ if (result.finalTranscriptConfidence !== void 0) {
9740
+ newState.finalConfidence = result.finalTranscriptConfidence;
9741
+ }
9742
+ newState.finalTranscriptionTimestamp = (/* @__PURE__ */ new Date()).toISOString();
9743
+ newState.pendingTranscript = "";
9744
+ newState.pendingConfidence = void 0;
9745
+ }
9746
+ return newState;
9747
+ }
9748
+ function mapMetadataToState(currentState, metadata) {
9749
+ const newState = { ...currentState };
9750
+ if (!newState.finalRecordingTimestamp) {
9751
+ newState.finalRecordingTimestamp = (/* @__PURE__ */ new Date()).toISOString();
9752
+ }
9753
+ newState.startRecordingStatus = RecordingStatus.FINISHED;
9754
+ return newState;
9755
+ }
9756
+ function mapErrorToState(currentState, error) {
9757
+ return {
9758
+ ...currentState,
9759
+ transcriptionStatus: TranscriptionStatus.ERROR,
9760
+ startRecordingStatus: RecordingStatus.FINISHED,
9761
+ finalRecordingTimestamp: (/* @__PURE__ */ new Date()).toISOString()
9762
+ };
9763
+ }
9764
+ function createVGFStateFromConfig(config) {
9765
+ const audioUtteranceId = config.audioUtteranceId || generateUUID();
9766
+ const state = createInitialRecognitionState(audioUtteranceId);
9767
+ if (config.asrRequestConfig) {
9768
+ state.asrConfig = JSON.stringify(config.asrRequestConfig);
9769
+ }
9770
+ return state;
9771
+ }
9772
+ function updateStateOnStop(currentState) {
9773
+ return {
9774
+ ...currentState,
9775
+ startRecordingStatus: RecordingStatus.FINISHED,
9776
+ finalRecordingTimestamp: (/* @__PURE__ */ new Date()).toISOString()
9777
+ };
9778
+ }
9779
+ function generateUUID() {
9780
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
9781
+ const r = Math.random() * 16 | 0;
9782
+ const v = c === "x" ? r : r & 3 | 8;
9783
+ return v.toString(16);
9784
+ });
9785
+ }
9786
+
9787
+ // src/simplified-vgf-recognition-client.ts
9788
+ var SimplifiedVGFRecognitionClient = class {
9789
+ constructor(config) {
9790
+ this.isRecordingAudio = false;
9791
+ const { onStateChange, initialState, ...clientConfig } = config;
9792
+ this.stateChangeCallback = onStateChange;
9793
+ this.logger = clientConfig.logger;
9794
+ if (initialState) {
9795
+ const needsNewUuid = !initialState.audioUtteranceId || initialState.audioUtteranceId === "" || initialState.transcriptionStatus === TranscriptionStatus.ABORTED || initialState.transcriptionStatus === TranscriptionStatus.FINALIZED;
9796
+ if (needsNewUuid) {
9797
+ const newUUID = crypto.randomUUID();
9798
+ if (clientConfig.logger) {
9799
+ const reason = !initialState.audioUtteranceId ? "Missing UUID" : initialState.audioUtteranceId === "" ? "Empty UUID" : `Terminal session (${initialState.transcriptionStatus})`;
9800
+ clientConfig.logger("info", `${reason} detected, generating new UUID: ${newUUID}`);
9801
+ }
9802
+ this.state = {
9803
+ ...initialState,
9804
+ audioUtteranceId: newUUID,
9805
+ // Reset status fields for fresh session if terminal state
9806
+ ...initialState.transcriptionStatus === TranscriptionStatus.ABORTED || initialState.transcriptionStatus === TranscriptionStatus.FINALIZED ? {
9807
+ transcriptionStatus: TranscriptionStatus.NOT_STARTED,
9808
+ startRecordingStatus: RecordingStatus.READY,
9809
+ finalTranscript: void 0
9810
+ } : {}
9811
+ };
9812
+ clientConfig.audioUtteranceId = newUUID;
9813
+ if (onStateChange) {
9814
+ onStateChange(this.state);
9815
+ }
9816
+ } else {
9817
+ this.state = initialState;
9818
+ if (initialState.audioUtteranceId && !clientConfig.audioUtteranceId) {
9819
+ clientConfig.audioUtteranceId = initialState.audioUtteranceId;
9820
+ }
9821
+ }
9822
+ } else {
9823
+ this.state = createVGFStateFromConfig(clientConfig);
9824
+ }
9825
+ this.state = { ...this.state, startRecordingStatus: "READY" };
9826
+ this.expectedUuid = this.state.audioUtteranceId;
9827
+ if (this.state.promptSlotMap) {
9828
+ if (clientConfig.asrRequestConfig) {
9829
+ clientConfig.asrRequestConfig.useContext = true;
9830
+ }
9831
+ if (!clientConfig.gameContext) {
9832
+ if (clientConfig.logger) {
9833
+ clientConfig.logger("warn", "[VGF] promptSlotMap found but no gameContext provided. SlotMap will not be sent.");
9834
+ }
9835
+ } else {
9836
+ clientConfig.gameContext.slotMap = this.state.promptSlotMap;
9837
+ }
9838
+ }
9839
+ this.client = new RealTimeTwoWayWebSocketRecognitionClient({
9840
+ ...clientConfig,
9841
+ // These callbacks ONLY update the VGF state sink
9842
+ onTranscript: (result) => {
9843
+ if (result.audioUtteranceId && result.audioUtteranceId !== this.expectedUuid) {
9844
+ if (this.logger) {
9845
+ this.logger(
9846
+ "warn",
9847
+ `[VGF] Skipping transcript update: UUID mismatch (expected: ${this.expectedUuid}, got: ${result.audioUtteranceId})`
9848
+ );
9849
+ }
9850
+ if (clientConfig.onTranscript) {
9851
+ clientConfig.onTranscript(result);
9852
+ }
9853
+ return;
9854
+ }
9855
+ this.state = mapTranscriptionResultToState(this.state, result, this.isRecordingAudio);
9856
+ this.notifyStateChange();
9857
+ if (clientConfig.onTranscript) {
9858
+ clientConfig.onTranscript(result);
9859
+ }
9860
+ },
9861
+ onMetadata: (metadata) => {
9862
+ if (metadata.audioUtteranceId && metadata.audioUtteranceId !== this.expectedUuid) {
9863
+ if (this.logger) {
9864
+ this.logger(
9865
+ "warn",
9866
+ `[VGF] Skipping metadata update: UUID mismatch (expected: ${this.expectedUuid}, got: ${metadata.audioUtteranceId})`
9867
+ );
9868
+ }
9869
+ if (clientConfig.onMetadata) {
9870
+ clientConfig.onMetadata(metadata);
9871
+ }
9872
+ return;
9873
+ }
9874
+ this.state = mapMetadataToState(this.state, metadata);
9875
+ this.notifyStateChange();
9876
+ if (clientConfig.onMetadata) {
9877
+ clientConfig.onMetadata(metadata);
9878
+ }
9879
+ },
6100
9880
  onFunctionCall: (result) => {
6101
9881
  if (clientConfig.onFunctionCall) {
6102
9882
  clientConfig.onFunctionCall(result);
6103
9883
  }
6104
9884
  },
6105
9885
  onError: (error) => {
9886
+ if (error.audioUtteranceId && error.audioUtteranceId !== this.expectedUuid) {
9887
+ if (this.logger) {
9888
+ this.logger(
9889
+ "warn",
9890
+ `[VGF] Skipping error update: UUID mismatch (expected: ${this.expectedUuid}, got: ${error.audioUtteranceId})`
9891
+ );
9892
+ }
9893
+ if (clientConfig.onError) {
9894
+ clientConfig.onError(error);
9895
+ }
9896
+ return;
9897
+ }
6106
9898
  this.isRecordingAudio = false;
6107
9899
  this.state = mapErrorToState(this.state, error);
6108
9900
  this.notifyStateChange();
@@ -6211,8 +10003,10 @@ export {
6211
10003
  ControlSignalTypeV1 as ControlSignal,
6212
10004
  ControlSignalTypeV1,
6213
10005
  DeepgramModel,
10006
+ ElevenLabsModel,
6214
10007
  ErrorTypeV1,
6215
10008
  FinalTranscriptStability,
10009
+ FireworksModel,
6216
10010
  GeminiModel,
6217
10011
  GoogleModel,
6218
10012
  Language,