@tokmizer/plugin 0.5.11 → 0.5.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __tkrCreateRequire } from "node:module"; const require = __tkrCreateRequire(import.meta.url);
3
- var Er=Object.defineProperty;var wr=(t,e)=>{for(var r in e)Er(t,r,{get:e[r],enumerable:!0})};import{spawn as Ri}from"node:child_process";import{readdir as Mn,readFile as Ln}from"node:fs/promises";import{join as kt,dirname as jn}from"node:path";import{fileURLToPath as Fn}from"node:url";var h={};wr(h,{BRAND:()=>Yr,DIRTY:()=>ee,EMPTY_PATH:()=>Rr,INVALID:()=>g,NEVER:()=>$n,OK:()=>A,ParseStatus:()=>T,Schema:()=>x,ZodAny:()=>J,ZodArray:()=>G,ZodBigInt:()=>re,ZodBoolean:()=>ne,ZodBranded:()=>Ce,ZodCatch:()=>me,ZodDate:()=>se,ZodDefault:()=>pe,ZodDiscriminatedUnion:()=>Fe,ZodEffects:()=>M,ZodEnum:()=>de,ZodError:()=>I,ZodFirstPartyTypeKind:()=>y,ZodFunction:()=>Ze,ZodIntersection:()=>ce,ZodIssueCode:()=>u,ZodLazy:()=>le,ZodLiteral:()=>ue,ZodMap:()=>we,ZodNaN:()=>Te,ZodNativeEnum:()=>fe,ZodNever:()=>j,ZodNull:()=>ae,ZodNullable:()=>Z,ZodNumber:()=>te,ZodObject:()=>O,ZodOptional:()=>P,ZodParsedType:()=>f,ZodPipeline:()=>Ie,ZodPromise:()=>X,ZodReadonly:()=>he,ZodRecord:()=>ze,ZodSchema:()=>x,ZodSet:()=>Se,ZodString:()=>Y,ZodSymbol:()=>ke,ZodTransformer:()=>M,ZodTuple:()=>z,ZodType:()=>x,ZodUndefined:()=>ie,ZodUnion:()=>oe,ZodUnknown:()=>W,ZodVoid:()=>Ee,addIssueToContext:()=>d,any:()=>an,array:()=>un,bigint:()=>en,boolean:()=>vt,coerce:()=>Pn,custom:()=>gt,date:()=>tn,datetimeRegex:()=>mt,defaultErrorMap:()=>H,discriminatedUnion:()=>mn,effect:()=>Tn,enum:()=>En,function:()=>xn,getErrorMap:()=>ve,getParsedType:()=>F,instanceof:()=>Xr,intersection:()=>hn,isAborted:()=>Le,isAsync:()=>xe,isDirty:()=>je,isValid:()=>q,late:()=>Jr,lazy:()=>bn,literal:()=>kn,makeIssue:()=>Re,map:()=>_n,nan:()=>Qr,nativeEnum:()=>wn,never:()=>cn,null:()=>sn,nullable:()=>Rn,number:()=>_t,object:()=>dn,objectUtil:()=>qe,oboolean:()=>Nn,onumber:()=>Dn,optional:()=>An,ostring:()=>On,pipeline:()=>In,preprocess:()=>Cn,promise:()=>Sn,quotelessJson:()=>Sr,record:()=>yn,set:()=>vn,setErrorMap:()=>Ar,strictObject:()=>fn,string:()=>yt,symbol:()=>rn,transformer:()=>Tn,tuple:()=>gn,undefined:()=>nn,union:()=>pn,unknown:()=>on,util:()=>b,void:()=>ln});var b;(function(t){t.assertEqual=s=>{};function e(s){}t.assertIs=e;function r(s){throw new Error}t.assertNever=r,t.arrayToEnum=s=>{let i={};for(let a of s)i[a]=a;return i},t.getValidEnumValues=s=>{let i=t.objectKeys(s).filter(o=>typeof s[s[o]]!="number"),a={};for(let o of i)a[o]=s[o];return t.objectValues(a)},t.objectValues=s=>t.objectKeys(s).map(function(i){return s[i]}),t.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{let i=[];for(let a in s)Object.prototype.hasOwnProperty.call(s,a)&&i.push(a);return i},t.find=(s,i)=>{for(let a of s)if(i(a))return a},t.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function n(s,i=" | "){return s.map(a=>typeof a=="string"?`'${a}'`:a).join(i)}t.joinValues=n,t.jsonStringifyReplacer=(s,i)=>typeof i=="bigint"?i.toString():i})(b||(b={}));var qe;(function(t){t.mergeShapes=(e,r)=>({...e,...r})})(qe||(qe={}));var f=b.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),F=t=>{switch(typeof t){case"undefined":return f.undefined;case"string":return f.string;case"number":return Number.isNaN(t)?f.nan:f.number;case"boolean":return f.boolean;case"function":return f.function;case"bigint":return f.bigint;case"symbol":return f.symbol;case"object":return Array.isArray(t)?f.array:t===null?f.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?f.promise:typeof Map<"u"&&t instanceof Map?f.map:typeof Set<"u"&&t instanceof Set?f.set:typeof Date<"u"&&t instanceof Date?f.date:f.object;default:return f.unknown}};var u=b.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Sr=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:"),I=class t extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=n=>{this.issues=[...this.issues,n]},this.addIssues=(n=[])=>{this.issues=[...this.issues,...n]};let r=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,r):this.__proto__=r,this.name="ZodError",this.issues=e}format(e){let r=e||function(i){return i.message},n={_errors:[]},s=i=>{for(let a of i.issues)if(a.code==="invalid_union")a.unionErrors.map(s);else if(a.code==="invalid_return_type")s(a.returnTypeError);else if(a.code==="invalid_arguments")s(a.argumentsError);else if(a.path.length===0)n._errors.push(r(a));else{let o=n,l=0;for(;l<a.path.length;){let c=a.path[l];l===a.path.length-1?(o[c]=o[c]||{_errors:[]},o[c]._errors.push(r(a))):o[c]=o[c]||{_errors:[]},o=o[c],l++}}};return s(this),n}static assert(e){if(!(e instanceof t))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,b.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=r=>r.message){let r={},n=[];for(let s of this.issues)if(s.path.length>0){let i=s.path[0];r[i]=r[i]||[],r[i].push(e(s))}else n.push(e(s));return{formErrors:n,fieldErrors:r}}get formErrors(){return this.flatten()}};I.create=t=>new I(t);var Tr=(t,e)=>{let r;switch(t.code){case u.invalid_type:t.received===f.undefined?r="Required":r=`Expected ${t.expected}, received ${t.received}`;break;case u.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(t.expected,b.jsonStringifyReplacer)}`;break;case u.unrecognized_keys:r=`Unrecognized key(s) in object: ${b.joinValues(t.keys,", ")}`;break;case u.invalid_union:r="Invalid input";break;case u.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${b.joinValues(t.options)}`;break;case u.invalid_enum_value:r=`Invalid enum value. Expected ${b.joinValues(t.options)}, received '${t.received}'`;break;case u.invalid_arguments:r="Invalid function arguments";break;case u.invalid_return_type:r="Invalid function return type";break;case u.invalid_date:r="Invalid date";break;case u.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(r=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(r=`${r} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?r=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?r=`Invalid input: must end with "${t.validation.endsWith}"`:b.assertNever(t.validation):t.validation!=="regex"?r=`Invalid ${t.validation}`:r="Invalid";break;case u.too_small:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?r=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:r="Invalid input";break;case u.too_big:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?r=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:r="Invalid input";break;case u.custom:r="Invalid input";break;case u.invalid_intersection_types:r="Intersection results could not be merged";break;case u.not_multiple_of:r=`Number must be a multiple of ${t.multipleOf}`;break;case u.not_finite:r="Number must be finite";break;default:r=e.defaultError,b.assertNever(t)}return{message:r}},H=Tr;var lt=H;function Ar(t){lt=t}function ve(){return lt}var Re=t=>{let{data:e,path:r,errorMaps:n,issueData:s}=t,i=[...r,...s.path||[]],a={...s,path:i};if(s.message!==void 0)return{...s,path:i,message:s.message};let o="",l=n.filter(c=>!!c).slice().reverse();for(let c of l)o=c(a,{data:e,defaultError:o}).message;return{...s,path:i,message:o}},Rr=[];function d(t,e){let r=ve(),n=Re({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,r,r===H?void 0:H].filter(s=>!!s)});t.common.issues.push(n)}var T=class t{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,r){let n=[];for(let s of r){if(s.status==="aborted")return g;s.status==="dirty"&&e.dirty(),n.push(s.value)}return{status:e.value,value:n}}static async mergeObjectAsync(e,r){let n=[];for(let s of r){let i=await s.key,a=await s.value;n.push({key:i,value:a})}return t.mergeObjectSync(e,n)}static mergeObjectSync(e,r){let n={};for(let s of r){let{key:i,value:a}=s;if(i.status==="aborted"||a.status==="aborted")return g;i.status==="dirty"&&e.dirty(),a.status==="dirty"&&e.dirty(),i.value!=="__proto__"&&(typeof a.value<"u"||s.alwaysSet)&&(n[i.value]=a.value)}return{status:e.value,value:n}}},g=Object.freeze({status:"aborted"}),ee=t=>({status:"dirty",value:t}),A=t=>({status:"valid",value:t}),Le=t=>t.status==="aborted",je=t=>t.status==="dirty",q=t=>t.status==="valid",xe=t=>typeof Promise<"u"&&t instanceof Promise;var m;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(m||(m={}));var $=class{constructor(e,r,n,s){this._cachedPath=[],this.parent=e,this.data=r,this._path=n,this._key=s}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}},ut=(t,e)=>{if(q(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let r=new I(t.common.issues);return this._error=r,this._error}}};function v(t){if(!t)return{};let{errorMap:e,invalid_type_error:r,required_error:n,description:s}=t;if(e&&(r||n))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(a,o)=>{let{message:l}=t;return a.code==="invalid_enum_value"?{message:l??o.defaultError}:typeof o.data>"u"?{message:l??n??o.defaultError}:a.code!=="invalid_type"?{message:o.defaultError}:{message:l??r??o.defaultError}},description:s}}var x=class{get description(){return this._def.description}_getType(e){return F(e.data)}_getOrReturnCtx(e,r){return r||{common:e.parent.common,data:e.data,parsedType:F(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new T,ctx:{common:e.parent.common,data:e.data,parsedType:F(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let r=this._parse(e);if(xe(r))throw new Error("Synchronous parse encountered promise.");return r}_parseAsync(e){let r=this._parse(e);return Promise.resolve(r)}parse(e,r){let n=this.safeParse(e,r);if(n.success)return n.data;throw n.error}safeParse(e,r){let n={common:{issues:[],async:r?.async??!1,contextualErrorMap:r?.errorMap},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:F(e)},s=this._parseSync({data:e,path:n.path,parent:n});return ut(n,s)}"~validate"(e){let r={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:F(e)};if(!this["~standard"].async)try{let n=this._parseSync({data:e,path:[],parent:r});return q(n)?{value:n.value}:{issues:r.common.issues}}catch(n){n?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),r.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:r}).then(n=>q(n)?{value:n.value}:{issues:r.common.issues})}async parseAsync(e,r){let n=await this.safeParseAsync(e,r);if(n.success)return n.data;throw n.error}async safeParseAsync(e,r){let n={common:{issues:[],contextualErrorMap:r?.errorMap,async:!0},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:F(e)},s=this._parse({data:e,path:n.path,parent:n}),i=await(xe(s)?s:Promise.resolve(s));return ut(n,i)}refine(e,r){let n=s=>typeof r=="string"||typeof r>"u"?{message:r}:typeof r=="function"?r(s):r;return this._refinement((s,i)=>{let a=e(s),o=()=>i.addIssue({code:u.custom,...n(s)});return typeof Promise<"u"&&a instanceof Promise?a.then(l=>l?!0:(o(),!1)):a?!0:(o(),!1)})}refinement(e,r){return this._refinement((n,s)=>e(n)?!0:(s.addIssue(typeof r=="function"?r(n,s):r),!1))}_refinement(e){return new M({schema:this,typeName:y.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:r=>this["~validate"](r)}}optional(){return P.create(this,this._def)}nullable(){return Z.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return G.create(this)}promise(){return X.create(this,this._def)}or(e){return oe.create([this,e],this._def)}and(e){return ce.create(this,e,this._def)}transform(e){return new M({...v(this._def),schema:this,typeName:y.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let r=typeof e=="function"?e:()=>e;return new pe({...v(this._def),innerType:this,defaultValue:r,typeName:y.ZodDefault})}brand(){return new Ce({typeName:y.ZodBranded,type:this,...v(this._def)})}catch(e){let r=typeof e=="function"?e:()=>e;return new me({...v(this._def),innerType:this,catchValue:r,typeName:y.ZodCatch})}describe(e){let r=this.constructor;return new r({...this._def,description:e})}pipe(e){return Ie.create(this,e)}readonly(){return he.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},Cr=/^c[^\s-]{8,}$/i,Ir=/^[0-9a-z]+$/,Or=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Dr=/^[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,Nr=/^[a-z0-9_-]{21}$/i,Pr=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,$r=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Mr=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Lr="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",Ye,jr=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Fr=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,zr=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,Zr=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Br=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Ur=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,ft="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",Vr=new RegExp(`^${ft}$`);function pt(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);let r=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${r}`}function Hr(t){return new RegExp(`^${pt(t)}$`)}function mt(t){let e=`${ft}T${pt(t)}`,r=[];return r.push(t.local?"Z?":"Z"),t.offset&&r.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${r.join("|")})`,new RegExp(`^${e}$`)}function Kr(t,e){return!!((e==="v4"||!e)&&jr.test(t)||(e==="v6"||!e)&&zr.test(t))}function Wr(t,e){if(!Pr.test(t))return!1;try{let[r]=t.split(".");if(!r)return!1;let n=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(r.length+(4-r.length%4)%4,"="),s=JSON.parse(atob(n));return!(typeof s!="object"||s===null||"typ"in s&&s?.typ!=="JWT"||!s.alg||e&&s.alg!==e)}catch{return!1}}function Gr(t,e){return!!((e==="v4"||!e)&&Fr.test(t)||(e==="v6"||!e)&&Zr.test(t))}var Y=class t extends x{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==f.string){let i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_type,expected:f.string,received:i.parsedType}),g}let n=new T,s;for(let i of this._def.checks)if(i.kind==="min")e.data.length<i.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:u.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),n.dirty());else if(i.kind==="max")e.data.length>i.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:u.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),n.dirty());else if(i.kind==="length"){let a=e.data.length>i.value,o=e.data.length<i.value;(a||o)&&(s=this._getOrReturnCtx(e,s),a?d(s,{code:u.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):o&&d(s,{code:u.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),n.dirty())}else if(i.kind==="email")Mr.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"email",code:u.invalid_string,message:i.message}),n.dirty());else if(i.kind==="emoji")Ye||(Ye=new RegExp(Lr,"u")),Ye.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"emoji",code:u.invalid_string,message:i.message}),n.dirty());else if(i.kind==="uuid")Dr.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"uuid",code:u.invalid_string,message:i.message}),n.dirty());else if(i.kind==="nanoid")Nr.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"nanoid",code:u.invalid_string,message:i.message}),n.dirty());else if(i.kind==="cuid")Cr.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"cuid",code:u.invalid_string,message:i.message}),n.dirty());else if(i.kind==="cuid2")Ir.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"cuid2",code:u.invalid_string,message:i.message}),n.dirty());else if(i.kind==="ulid")Or.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"ulid",code:u.invalid_string,message:i.message}),n.dirty());else if(i.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),d(s,{validation:"url",code:u.invalid_string,message:i.message}),n.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"regex",code:u.invalid_string,message:i.message}),n.dirty())):i.kind==="trim"?e.data=e.data.trim():i.kind==="includes"?e.data.includes(i.value,i.position)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),n.dirty()):i.kind==="toLowerCase"?e.data=e.data.toLowerCase():i.kind==="toUpperCase"?e.data=e.data.toUpperCase():i.kind==="startsWith"?e.data.startsWith(i.value)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:{startsWith:i.value},message:i.message}),n.dirty()):i.kind==="endsWith"?e.data.endsWith(i.value)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:{endsWith:i.value},message:i.message}),n.dirty()):i.kind==="datetime"?mt(i).test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:"datetime",message:i.message}),n.dirty()):i.kind==="date"?Vr.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:"date",message:i.message}),n.dirty()):i.kind==="time"?Hr(i).test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:"time",message:i.message}),n.dirty()):i.kind==="duration"?$r.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"duration",code:u.invalid_string,message:i.message}),n.dirty()):i.kind==="ip"?Kr(e.data,i.version)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"ip",code:u.invalid_string,message:i.message}),n.dirty()):i.kind==="jwt"?Wr(e.data,i.alg)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"jwt",code:u.invalid_string,message:i.message}),n.dirty()):i.kind==="cidr"?Gr(e.data,i.version)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"cidr",code:u.invalid_string,message:i.message}),n.dirty()):i.kind==="base64"?Br.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"base64",code:u.invalid_string,message:i.message}),n.dirty()):i.kind==="base64url"?Ur.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"base64url",code:u.invalid_string,message:i.message}),n.dirty()):b.assertNever(i);return{status:n.value,value:e.data}}_regex(e,r,n){return this.refinement(s=>e.test(s),{validation:r,code:u.invalid_string,...m.errToObj(n)})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...m.errToObj(e)})}url(e){return this._addCheck({kind:"url",...m.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...m.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...m.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...m.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...m.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...m.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...m.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...m.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...m.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...m.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...m.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...m.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...m.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...m.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...m.errToObj(e)})}regex(e,r){return this._addCheck({kind:"regex",regex:e,...m.errToObj(r)})}includes(e,r){return this._addCheck({kind:"includes",value:e,position:r?.position,...m.errToObj(r?.message)})}startsWith(e,r){return this._addCheck({kind:"startsWith",value:e,...m.errToObj(r)})}endsWith(e,r){return this._addCheck({kind:"endsWith",value:e,...m.errToObj(r)})}min(e,r){return this._addCheck({kind:"min",value:e,...m.errToObj(r)})}max(e,r){return this._addCheck({kind:"max",value:e,...m.errToObj(r)})}length(e,r){return this._addCheck({kind:"length",value:e,...m.errToObj(r)})}nonempty(e){return this.min(1,m.errToObj(e))}trim(){return new t({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxLength(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}};Y.create=t=>new Y({checks:[],typeName:y.ZodString,coerce:t?.coerce??!1,...v(t)});function qr(t,e){let r=(t.toString().split(".")[1]||"").length,n=(e.toString().split(".")[1]||"").length,s=r>n?r:n,i=Number.parseInt(t.toFixed(s).replace(".","")),a=Number.parseInt(e.toFixed(s).replace(".",""));return i%a/10**s}var te=class t extends x{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==f.number){let i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_type,expected:f.number,received:i.parsedType}),g}let n,s=new T;for(let i of this._def.checks)i.kind==="int"?b.isInteger(e.data)||(n=this._getOrReturnCtx(e,n),d(n,{code:u.invalid_type,expected:"integer",received:"float",message:i.message}),s.dirty()):i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:u.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:u.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="multipleOf"?qr(e.data,i.value)!==0&&(n=this._getOrReturnCtx(e,n),d(n,{code:u.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):i.kind==="finite"?Number.isFinite(e.data)||(n=this._getOrReturnCtx(e,n),d(n,{code:u.not_finite,message:i.message}),s.dirty()):b.assertNever(i);return{status:s.value,value:e.data}}gte(e,r){return this.setLimit("min",e,!0,m.toString(r))}gt(e,r){return this.setLimit("min",e,!1,m.toString(r))}lte(e,r){return this.setLimit("max",e,!0,m.toString(r))}lt(e,r){return this.setLimit("max",e,!1,m.toString(r))}setLimit(e,r,n,s){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:r,inclusive:n,message:m.toString(s)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:m.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:m.toString(e)})}multipleOf(e,r){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(r)})}finite(e){return this._addCheck({kind:"finite",message:m.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:m.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:m.toString(e)})}get minValue(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxValue(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&b.isInteger(e.value))}get isFinite(){let e=null,r=null;for(let n of this._def.checks){if(n.kind==="finite"||n.kind==="int"||n.kind==="multipleOf")return!0;n.kind==="min"?(r===null||n.value>r)&&(r=n.value):n.kind==="max"&&(e===null||n.value<e)&&(e=n.value)}return Number.isFinite(r)&&Number.isFinite(e)}};te.create=t=>new te({checks:[],typeName:y.ZodNumber,coerce:t?.coerce||!1,...v(t)});var re=class t extends x{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==f.bigint)return this._getInvalidInput(e);let n,s=new T;for(let i of this._def.checks)i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:u.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:u.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="multipleOf"?e.data%i.value!==BigInt(0)&&(n=this._getOrReturnCtx(e,n),d(n,{code:u.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):b.assertNever(i);return{status:s.value,value:e.data}}_getInvalidInput(e){let r=this._getOrReturnCtx(e);return d(r,{code:u.invalid_type,expected:f.bigint,received:r.parsedType}),g}gte(e,r){return this.setLimit("min",e,!0,m.toString(r))}gt(e,r){return this.setLimit("min",e,!1,m.toString(r))}lte(e,r){return this.setLimit("max",e,!0,m.toString(r))}lt(e,r){return this.setLimit("max",e,!1,m.toString(r))}setLimit(e,r,n,s){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:r,inclusive:n,message:m.toString(s)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:m.toString(e)})}multipleOf(e,r){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(r)})}get minValue(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxValue(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}};re.create=t=>new re({checks:[],typeName:y.ZodBigInt,coerce:t?.coerce??!1,...v(t)});var ne=class extends x{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==f.boolean){let n=this._getOrReturnCtx(e);return d(n,{code:u.invalid_type,expected:f.boolean,received:n.parsedType}),g}return A(e.data)}};ne.create=t=>new ne({typeName:y.ZodBoolean,coerce:t?.coerce||!1,...v(t)});var se=class t extends x{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==f.date){let i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_type,expected:f.date,received:i.parsedType}),g}if(Number.isNaN(e.data.getTime())){let i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_date}),g}let n=new T,s;for(let i of this._def.checks)i.kind==="min"?e.data.getTime()<i.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:u.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),n.dirty()):i.kind==="max"?e.data.getTime()>i.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:u.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),n.dirty()):b.assertNever(i);return{status:n.value,value:new Date(e.data.getTime())}}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}min(e,r){return this._addCheck({kind:"min",value:e.getTime(),message:m.toString(r)})}max(e,r){return this._addCheck({kind:"max",value:e.getTime(),message:m.toString(r)})}get minDate(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e!=null?new Date(e):null}};se.create=t=>new se({checks:[],coerce:t?.coerce||!1,typeName:y.ZodDate,...v(t)});var ke=class extends x{_parse(e){if(this._getType(e)!==f.symbol){let n=this._getOrReturnCtx(e);return d(n,{code:u.invalid_type,expected:f.symbol,received:n.parsedType}),g}return A(e.data)}};ke.create=t=>new ke({typeName:y.ZodSymbol,...v(t)});var ie=class extends x{_parse(e){if(this._getType(e)!==f.undefined){let n=this._getOrReturnCtx(e);return d(n,{code:u.invalid_type,expected:f.undefined,received:n.parsedType}),g}return A(e.data)}};ie.create=t=>new ie({typeName:y.ZodUndefined,...v(t)});var ae=class extends x{_parse(e){if(this._getType(e)!==f.null){let n=this._getOrReturnCtx(e);return d(n,{code:u.invalid_type,expected:f.null,received:n.parsedType}),g}return A(e.data)}};ae.create=t=>new ae({typeName:y.ZodNull,...v(t)});var J=class extends x{constructor(){super(...arguments),this._any=!0}_parse(e){return A(e.data)}};J.create=t=>new J({typeName:y.ZodAny,...v(t)});var W=class extends x{constructor(){super(...arguments),this._unknown=!0}_parse(e){return A(e.data)}};W.create=t=>new W({typeName:y.ZodUnknown,...v(t)});var j=class extends x{_parse(e){let r=this._getOrReturnCtx(e);return d(r,{code:u.invalid_type,expected:f.never,received:r.parsedType}),g}};j.create=t=>new j({typeName:y.ZodNever,...v(t)});var Ee=class extends x{_parse(e){if(this._getType(e)!==f.undefined){let n=this._getOrReturnCtx(e);return d(n,{code:u.invalid_type,expected:f.void,received:n.parsedType}),g}return A(e.data)}};Ee.create=t=>new Ee({typeName:y.ZodVoid,...v(t)});var G=class t extends x{_parse(e){let{ctx:r,status:n}=this._processInputParams(e),s=this._def;if(r.parsedType!==f.array)return d(r,{code:u.invalid_type,expected:f.array,received:r.parsedType}),g;if(s.exactLength!==null){let a=r.data.length>s.exactLength.value,o=r.data.length<s.exactLength.value;(a||o)&&(d(r,{code:a?u.too_big:u.too_small,minimum:o?s.exactLength.value:void 0,maximum:a?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),n.dirty())}if(s.minLength!==null&&r.data.length<s.minLength.value&&(d(r,{code:u.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),n.dirty()),s.maxLength!==null&&r.data.length>s.maxLength.value&&(d(r,{code:u.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),n.dirty()),r.common.async)return Promise.all([...r.data].map((a,o)=>s.type._parseAsync(new $(r,a,r.path,o)))).then(a=>T.mergeArray(n,a));let i=[...r.data].map((a,o)=>s.type._parseSync(new $(r,a,r.path,o)));return T.mergeArray(n,i)}get element(){return this._def.type}min(e,r){return new t({...this._def,minLength:{value:e,message:m.toString(r)}})}max(e,r){return new t({...this._def,maxLength:{value:e,message:m.toString(r)}})}length(e,r){return new t({...this._def,exactLength:{value:e,message:m.toString(r)}})}nonempty(e){return this.min(1,e)}};G.create=(t,e)=>new G({type:t,minLength:null,maxLength:null,exactLength:null,typeName:y.ZodArray,...v(e)});function be(t){if(t instanceof O){let e={};for(let r in t.shape){let n=t.shape[r];e[r]=P.create(be(n))}return new O({...t._def,shape:()=>e})}else return t instanceof G?new G({...t._def,type:be(t.element)}):t instanceof P?P.create(be(t.unwrap())):t instanceof Z?Z.create(be(t.unwrap())):t instanceof z?z.create(t.items.map(e=>be(e))):t}var O=class t extends x{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape(),r=b.objectKeys(e);return this._cached={shape:e,keys:r},this._cached}_parse(e){if(this._getType(e)!==f.object){let c=this._getOrReturnCtx(e);return d(c,{code:u.invalid_type,expected:f.object,received:c.parsedType}),g}let{status:n,ctx:s}=this._processInputParams(e),{shape:i,keys:a}=this._getCached(),o=[];if(!(this._def.catchall instanceof j&&this._def.unknownKeys==="strip"))for(let c in s.data)a.includes(c)||o.push(c);let l=[];for(let c of a){let p=i[c],_=s.data[c];l.push({key:{status:"valid",value:c},value:p._parse(new $(s,_,s.path,c)),alwaysSet:c in s.data})}if(this._def.catchall instanceof j){let c=this._def.unknownKeys;if(c==="passthrough")for(let p of o)l.push({key:{status:"valid",value:p},value:{status:"valid",value:s.data[p]}});else if(c==="strict")o.length>0&&(d(s,{code:u.unrecognized_keys,keys:o}),n.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{let c=this._def.catchall;for(let p of o){let _=s.data[p];l.push({key:{status:"valid",value:p},value:c._parse(new $(s,_,s.path,p)),alwaysSet:p in s.data})}}return s.common.async?Promise.resolve().then(async()=>{let c=[];for(let p of l){let _=await p.key,E=await p.value;c.push({key:_,value:E,alwaysSet:p.alwaysSet})}return c}).then(c=>T.mergeObjectSync(n,c)):T.mergeObjectSync(n,l)}get shape(){return this._def.shape()}strict(e){return m.errToObj,new t({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(r,n)=>{let s=this._def.errorMap?.(r,n).message??n.defaultError;return r.code==="unrecognized_keys"?{message:m.errToObj(e).message??s}:{message:s}}}:{}})}strip(){return new t({...this._def,unknownKeys:"strip"})}passthrough(){return new t({...this._def,unknownKeys:"passthrough"})}extend(e){return new t({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new t({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:y.ZodObject})}setKey(e,r){return this.augment({[e]:r})}catchall(e){return new t({...this._def,catchall:e})}pick(e){let r={};for(let n of b.objectKeys(e))e[n]&&this.shape[n]&&(r[n]=this.shape[n]);return new t({...this._def,shape:()=>r})}omit(e){let r={};for(let n of b.objectKeys(this.shape))e[n]||(r[n]=this.shape[n]);return new t({...this._def,shape:()=>r})}deepPartial(){return be(this)}partial(e){let r={};for(let n of b.objectKeys(this.shape)){let s=this.shape[n];e&&!e[n]?r[n]=s:r[n]=s.optional()}return new t({...this._def,shape:()=>r})}required(e){let r={};for(let n of b.objectKeys(this.shape))if(e&&!e[n])r[n]=this.shape[n];else{let i=this.shape[n];for(;i instanceof P;)i=i._def.innerType;r[n]=i}return new t({...this._def,shape:()=>r})}keyof(){return ht(b.objectKeys(this.shape))}};O.create=(t,e)=>new O({shape:()=>t,unknownKeys:"strip",catchall:j.create(),typeName:y.ZodObject,...v(e)});O.strictCreate=(t,e)=>new O({shape:()=>t,unknownKeys:"strict",catchall:j.create(),typeName:y.ZodObject,...v(e)});O.lazycreate=(t,e)=>new O({shape:t,unknownKeys:"strip",catchall:j.create(),typeName:y.ZodObject,...v(e)});var oe=class extends x{_parse(e){let{ctx:r}=this._processInputParams(e),n=this._def.options;function s(i){for(let o of i)if(o.result.status==="valid")return o.result;for(let o of i)if(o.result.status==="dirty")return r.common.issues.push(...o.ctx.common.issues),o.result;let a=i.map(o=>new I(o.ctx.common.issues));return d(r,{code:u.invalid_union,unionErrors:a}),g}if(r.common.async)return Promise.all(n.map(async i=>{let a={...r,common:{...r.common,issues:[]},parent:null};return{result:await i._parseAsync({data:r.data,path:r.path,parent:a}),ctx:a}})).then(s);{let i,a=[];for(let l of n){let c={...r,common:{...r.common,issues:[]},parent:null},p=l._parseSync({data:r.data,path:r.path,parent:c});if(p.status==="valid")return p;p.status==="dirty"&&!i&&(i={result:p,ctx:c}),c.common.issues.length&&a.push(c.common.issues)}if(i)return r.common.issues.push(...i.ctx.common.issues),i.result;let o=a.map(l=>new I(l));return d(r,{code:u.invalid_union,unionErrors:o}),g}}get options(){return this._def.options}};oe.create=(t,e)=>new oe({options:t,typeName:y.ZodUnion,...v(e)});var K=t=>t instanceof le?K(t.schema):t instanceof M?K(t.innerType()):t instanceof ue?[t.value]:t instanceof de?t.options:t instanceof fe?b.objectValues(t.enum):t instanceof pe?K(t._def.innerType):t instanceof ie?[void 0]:t instanceof ae?[null]:t instanceof P?[void 0,...K(t.unwrap())]:t instanceof Z?[null,...K(t.unwrap())]:t instanceof Ce||t instanceof he?K(t.unwrap()):t instanceof me?K(t._def.innerType):[],Fe=class t extends x{_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==f.object)return d(r,{code:u.invalid_type,expected:f.object,received:r.parsedType}),g;let n=this.discriminator,s=r.data[n],i=this.optionsMap.get(s);return i?r.common.async?i._parseAsync({data:r.data,path:r.path,parent:r}):i._parseSync({data:r.data,path:r.path,parent:r}):(d(r,{code:u.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[n]}),g)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,r,n){let s=new Map;for(let i of r){let a=K(i.shape[e]);if(!a.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let o of a){if(s.has(o))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);s.set(o,i)}}return new t({typeName:y.ZodDiscriminatedUnion,discriminator:e,options:r,optionsMap:s,...v(n)})}};function Je(t,e){let r=F(t),n=F(e);if(t===e)return{valid:!0,data:t};if(r===f.object&&n===f.object){let s=b.objectKeys(e),i=b.objectKeys(t).filter(o=>s.indexOf(o)!==-1),a={...t,...e};for(let o of i){let l=Je(t[o],e[o]);if(!l.valid)return{valid:!1};a[o]=l.data}return{valid:!0,data:a}}else if(r===f.array&&n===f.array){if(t.length!==e.length)return{valid:!1};let s=[];for(let i=0;i<t.length;i++){let a=t[i],o=e[i],l=Je(a,o);if(!l.valid)return{valid:!1};s.push(l.data)}return{valid:!0,data:s}}else return r===f.date&&n===f.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}var ce=class extends x{_parse(e){let{status:r,ctx:n}=this._processInputParams(e),s=(i,a)=>{if(Le(i)||Le(a))return g;let o=Je(i.value,a.value);return o.valid?((je(i)||je(a))&&r.dirty(),{status:r.value,value:o.data}):(d(n,{code:u.invalid_intersection_types}),g)};return n.common.async?Promise.all([this._def.left._parseAsync({data:n.data,path:n.path,parent:n}),this._def.right._parseAsync({data:n.data,path:n.path,parent:n})]).then(([i,a])=>s(i,a)):s(this._def.left._parseSync({data:n.data,path:n.path,parent:n}),this._def.right._parseSync({data:n.data,path:n.path,parent:n}))}};ce.create=(t,e,r)=>new ce({left:t,right:e,typeName:y.ZodIntersection,...v(r)});var z=class t extends x{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==f.array)return d(n,{code:u.invalid_type,expected:f.array,received:n.parsedType}),g;if(n.data.length<this._def.items.length)return d(n,{code:u.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),g;!this._def.rest&&n.data.length>this._def.items.length&&(d(n,{code:u.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),r.dirty());let i=[...n.data].map((a,o)=>{let l=this._def.items[o]||this._def.rest;return l?l._parse(new $(n,a,n.path,o)):null}).filter(a=>!!a);return n.common.async?Promise.all(i).then(a=>T.mergeArray(r,a)):T.mergeArray(r,i)}get items(){return this._def.items}rest(e){return new t({...this._def,rest:e})}};z.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new z({items:t,typeName:y.ZodTuple,rest:null,...v(e)})};var ze=class t extends x{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==f.object)return d(n,{code:u.invalid_type,expected:f.object,received:n.parsedType}),g;let s=[],i=this._def.keyType,a=this._def.valueType;for(let o in n.data)s.push({key:i._parse(new $(n,o,n.path,o)),value:a._parse(new $(n,n.data[o],n.path,o)),alwaysSet:o in n.data});return n.common.async?T.mergeObjectAsync(r,s):T.mergeObjectSync(r,s)}get element(){return this._def.valueType}static create(e,r,n){return r instanceof x?new t({keyType:e,valueType:r,typeName:y.ZodRecord,...v(n)}):new t({keyType:Y.create(),valueType:e,typeName:y.ZodRecord,...v(r)})}},we=class extends x{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==f.map)return d(n,{code:u.invalid_type,expected:f.map,received:n.parsedType}),g;let s=this._def.keyType,i=this._def.valueType,a=[...n.data.entries()].map(([o,l],c)=>({key:s._parse(new $(n,o,n.path,[c,"key"])),value:i._parse(new $(n,l,n.path,[c,"value"]))}));if(n.common.async){let o=new Map;return Promise.resolve().then(async()=>{for(let l of a){let c=await l.key,p=await l.value;if(c.status==="aborted"||p.status==="aborted")return g;(c.status==="dirty"||p.status==="dirty")&&r.dirty(),o.set(c.value,p.value)}return{status:r.value,value:o}})}else{let o=new Map;for(let l of a){let c=l.key,p=l.value;if(c.status==="aborted"||p.status==="aborted")return g;(c.status==="dirty"||p.status==="dirty")&&r.dirty(),o.set(c.value,p.value)}return{status:r.value,value:o}}}};we.create=(t,e,r)=>new we({valueType:e,keyType:t,typeName:y.ZodMap,...v(r)});var Se=class t extends x{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==f.set)return d(n,{code:u.invalid_type,expected:f.set,received:n.parsedType}),g;let s=this._def;s.minSize!==null&&n.data.size<s.minSize.value&&(d(n,{code:u.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),r.dirty()),s.maxSize!==null&&n.data.size>s.maxSize.value&&(d(n,{code:u.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),r.dirty());let i=this._def.valueType;function a(l){let c=new Set;for(let p of l){if(p.status==="aborted")return g;p.status==="dirty"&&r.dirty(),c.add(p.value)}return{status:r.value,value:c}}let o=[...n.data.values()].map((l,c)=>i._parse(new $(n,l,n.path,c)));return n.common.async?Promise.all(o).then(l=>a(l)):a(o)}min(e,r){return new t({...this._def,minSize:{value:e,message:m.toString(r)}})}max(e,r){return new t({...this._def,maxSize:{value:e,message:m.toString(r)}})}size(e,r){return this.min(e,r).max(e,r)}nonempty(e){return this.min(1,e)}};Se.create=(t,e)=>new Se({valueType:t,minSize:null,maxSize:null,typeName:y.ZodSet,...v(e)});var Ze=class t extends x{constructor(){super(...arguments),this.validate=this.implement}_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==f.function)return d(r,{code:u.invalid_type,expected:f.function,received:r.parsedType}),g;function n(o,l){return Re({data:o,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,ve(),H].filter(c=>!!c),issueData:{code:u.invalid_arguments,argumentsError:l}})}function s(o,l){return Re({data:o,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,ve(),H].filter(c=>!!c),issueData:{code:u.invalid_return_type,returnTypeError:l}})}let i={errorMap:r.common.contextualErrorMap},a=r.data;if(this._def.returns instanceof X){let o=this;return A(async function(...l){let c=new I([]),p=await o._def.args.parseAsync(l,i).catch(w=>{throw c.addIssue(n(l,w)),c}),_=await Reflect.apply(a,this,p);return await o._def.returns._def.type.parseAsync(_,i).catch(w=>{throw c.addIssue(s(_,w)),c})})}else{let o=this;return A(function(...l){let c=o._def.args.safeParse(l,i);if(!c.success)throw new I([n(l,c.error)]);let p=Reflect.apply(a,this,c.data),_=o._def.returns.safeParse(p,i);if(!_.success)throw new I([s(p,_.error)]);return _.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new t({...this._def,args:z.create(e).rest(W.create())})}returns(e){return new t({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,r,n){return new t({args:e||z.create([]).rest(W.create()),returns:r||W.create(),typeName:y.ZodFunction,...v(n)})}},le=class extends x{get schema(){return this._def.getter()}_parse(e){let{ctx:r}=this._processInputParams(e);return this._def.getter()._parse({data:r.data,path:r.path,parent:r})}};le.create=(t,e)=>new le({getter:t,typeName:y.ZodLazy,...v(e)});var ue=class extends x{_parse(e){if(e.data!==this._def.value){let r=this._getOrReturnCtx(e);return d(r,{received:r.data,code:u.invalid_literal,expected:this._def.value}),g}return{status:"valid",value:e.data}}get value(){return this._def.value}};ue.create=(t,e)=>new ue({value:t,typeName:y.ZodLiteral,...v(e)});function ht(t,e){return new de({values:t,typeName:y.ZodEnum,...v(e)})}var de=class t extends x{_parse(e){if(typeof e.data!="string"){let r=this._getOrReturnCtx(e),n=this._def.values;return d(r,{expected:b.joinValues(n),received:r.parsedType,code:u.invalid_type}),g}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let r=this._getOrReturnCtx(e),n=this._def.values;return d(r,{received:r.data,code:u.invalid_enum_value,options:n}),g}return A(e.data)}get options(){return this._def.values}get enum(){let e={};for(let r of this._def.values)e[r]=r;return e}get Values(){let e={};for(let r of this._def.values)e[r]=r;return e}get Enum(){let e={};for(let r of this._def.values)e[r]=r;return e}extract(e,r=this._def){return t.create(e,{...this._def,...r})}exclude(e,r=this._def){return t.create(this.options.filter(n=>!e.includes(n)),{...this._def,...r})}};de.create=ht;var fe=class extends x{_parse(e){let r=b.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(e);if(n.parsedType!==f.string&&n.parsedType!==f.number){let s=b.objectValues(r);return d(n,{expected:b.joinValues(s),received:n.parsedType,code:u.invalid_type}),g}if(this._cache||(this._cache=new Set(b.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let s=b.objectValues(r);return d(n,{received:n.data,code:u.invalid_enum_value,options:s}),g}return A(e.data)}get enum(){return this._def.values}};fe.create=(t,e)=>new fe({values:t,typeName:y.ZodNativeEnum,...v(e)});var X=class extends x{unwrap(){return this._def.type}_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==f.promise&&r.common.async===!1)return d(r,{code:u.invalid_type,expected:f.promise,received:r.parsedType}),g;let n=r.parsedType===f.promise?r.data:Promise.resolve(r.data);return A(n.then(s=>this._def.type.parseAsync(s,{path:r.path,errorMap:r.common.contextualErrorMap})))}};X.create=(t,e)=>new X({type:t,typeName:y.ZodPromise,...v(e)});var M=class extends x{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===y.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:r,ctx:n}=this._processInputParams(e),s=this._def.effect||null,i={addIssue:a=>{d(n,a),a.fatal?r.abort():r.dirty()},get path(){return n.path}};if(i.addIssue=i.addIssue.bind(i),s.type==="preprocess"){let a=s.transform(n.data,i);if(n.common.async)return Promise.resolve(a).then(async o=>{if(r.value==="aborted")return g;let l=await this._def.schema._parseAsync({data:o,path:n.path,parent:n});return l.status==="aborted"?g:l.status==="dirty"?ee(l.value):r.value==="dirty"?ee(l.value):l});{if(r.value==="aborted")return g;let o=this._def.schema._parseSync({data:a,path:n.path,parent:n});return o.status==="aborted"?g:o.status==="dirty"?ee(o.value):r.value==="dirty"?ee(o.value):o}}if(s.type==="refinement"){let a=o=>{let l=s.refinement(o,i);if(n.common.async)return Promise.resolve(l);if(l instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(n.common.async===!1){let o=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return o.status==="aborted"?g:(o.status==="dirty"&&r.dirty(),a(o.value),{status:r.value,value:o.value})}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(o=>o.status==="aborted"?g:(o.status==="dirty"&&r.dirty(),a(o.value).then(()=>({status:r.value,value:o.value}))))}if(s.type==="transform")if(n.common.async===!1){let a=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!q(a))return g;let o=s.transform(a.value,i);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:o}}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(a=>q(a)?Promise.resolve(s.transform(a.value,i)).then(o=>({status:r.value,value:o})):g);b.assertNever(s)}};M.create=(t,e,r)=>new M({schema:t,typeName:y.ZodEffects,effect:e,...v(r)});M.createWithPreprocess=(t,e,r)=>new M({schema:e,effect:{type:"preprocess",transform:t},typeName:y.ZodEffects,...v(r)});var P=class extends x{_parse(e){return this._getType(e)===f.undefined?A(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};P.create=(t,e)=>new P({innerType:t,typeName:y.ZodOptional,...v(e)});var Z=class extends x{_parse(e){return this._getType(e)===f.null?A(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};Z.create=(t,e)=>new Z({innerType:t,typeName:y.ZodNullable,...v(e)});var pe=class extends x{_parse(e){let{ctx:r}=this._processInputParams(e),n=r.data;return r.parsedType===f.undefined&&(n=this._def.defaultValue()),this._def.innerType._parse({data:n,path:r.path,parent:r})}removeDefault(){return this._def.innerType}};pe.create=(t,e)=>new pe({innerType:t,typeName:y.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...v(e)});var me=class extends x{_parse(e){let{ctx:r}=this._processInputParams(e),n={...r,common:{...r.common,issues:[]}},s=this._def.innerType._parse({data:n.data,path:n.path,parent:{...n}});return xe(s)?s.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new I(n.common.issues)},input:n.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new I(n.common.issues)},input:n.data})}}removeCatch(){return this._def.innerType}};me.create=(t,e)=>new me({innerType:t,typeName:y.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...v(e)});var Te=class extends x{_parse(e){if(this._getType(e)!==f.nan){let n=this._getOrReturnCtx(e);return d(n,{code:u.invalid_type,expected:f.nan,received:n.parsedType}),g}return{status:"valid",value:e.data}}};Te.create=t=>new Te({typeName:y.ZodNaN,...v(t)});var Yr=Symbol("zod_brand"),Ce=class extends x{_parse(e){let{ctx:r}=this._processInputParams(e),n=r.data;return this._def.type._parse({data:n,path:r.path,parent:r})}unwrap(){return this._def.type}},Ie=class t extends x{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.common.async)return(async()=>{let i=await this._def.in._parseAsync({data:n.data,path:n.path,parent:n});return i.status==="aborted"?g:i.status==="dirty"?(r.dirty(),ee(i.value)):this._def.out._parseAsync({data:i.value,path:n.path,parent:n})})();{let s=this._def.in._parseSync({data:n.data,path:n.path,parent:n});return s.status==="aborted"?g:s.status==="dirty"?(r.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:n.path,parent:n})}}static create(e,r){return new t({in:e,out:r,typeName:y.ZodPipeline})}},he=class extends x{_parse(e){let r=this._def.innerType._parse(e),n=s=>(q(s)&&(s.value=Object.freeze(s.value)),s);return xe(r)?r.then(s=>n(s)):n(r)}unwrap(){return this._def.innerType}};he.create=(t,e)=>new he({innerType:t,typeName:y.ZodReadonly,...v(e)});function dt(t,e){let r=typeof t=="function"?t(e):typeof t=="string"?{message:t}:t;return typeof r=="string"?{message:r}:r}function gt(t,e={},r){return t?J.create().superRefine((n,s)=>{let i=t(n);if(i instanceof Promise)return i.then(a=>{if(!a){let o=dt(e,n),l=o.fatal??r??!0;s.addIssue({code:"custom",...o,fatal:l})}});if(!i){let a=dt(e,n),o=a.fatal??r??!0;s.addIssue({code:"custom",...a,fatal:o})}}):J.create()}var Jr={object:O.lazycreate},y;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(y||(y={}));var Xr=(t,e={message:`Input not instance of ${t.name}`})=>gt(r=>r instanceof t,e),yt=Y.create,_t=te.create,Qr=Te.create,en=re.create,vt=ne.create,tn=se.create,rn=ke.create,nn=ie.create,sn=ae.create,an=J.create,on=W.create,cn=j.create,ln=Ee.create,un=G.create,dn=O.create,fn=O.strictCreate,pn=oe.create,mn=Fe.create,hn=ce.create,gn=z.create,yn=ze.create,_n=we.create,vn=Se.create,xn=Ze.create,bn=le.create,kn=ue.create,En=de.create,wn=fe.create,Sn=X.create,Tn=M.create,An=P.create,Rn=Z.create,Cn=M.createWithPreprocess,In=Ie.create,On=()=>yt().optional(),Dn=()=>_t().optional(),Nn=()=>vt().optional(),Pn={string:(t=>Y.create({...t,coerce:!0})),number:(t=>te.create({...t,coerce:!0})),boolean:(t=>ne.create({...t,coerce:!0})),bigint:(t=>re.create({...t,coerce:!0})),date:(t=>se.create({...t,coerce:!0}))};var $n=g;var Be=h.object({slug:h.string().min(1).max(64),description:h.string().max(255).optional(),match_command:h.string().min(1),priority:h.number().int().default(50),strip_ansi:h.boolean().default(!1),strip_lines_matching:h.array(h.string()).default([]),truncate_lines_at:h.number().int().positive().max(1e4).optional(),max_lines:h.number().int().positive().max(1e5).optional(),transform:h.string().max(64).optional(),on_empty:h.string().max(255).optional()});var zn=jn(Fn(import.meta.url)),xt=kt(zn,"..","..","filters"),Q=null,bt=!1;function Zn(){return process.env.TOKMIZER_DEV==="1"||process.env.TOKMIZER_DEV==="true"}async function Et(){if(Q)return Q;if(!Zn())return!bt&&process.env.TOKMIZER_DEBUG==="1"&&(process.stderr.write(`tokmizer: disk loader disabled (set TOKMIZER_DEV=1 to re-enable for local dev).
4
- `),bt=!0),Q=new Map,Q;let t=new Map,e,r;try{e=(await import("smol-toml")).parse,r=(await Mn(xt)).filter(n=>n.endsWith(".toml"))}catch{return Q=t,Q}for(let n of r){let s=await Ln(kt(xt,n),"utf8"),a=e(s).filters;if(a)for(let[o,l]of Object.entries(a)){let c=Be.parse({slug:o,...l});t.set(o,{...c,matchRegex:new RegExp(c.match_command)})}}return Q=t,Q}import{createHash as Bn}from"node:crypto";var Un=h.enum(["normal","compact","minimal"]),Vn=h.enum(["off","light","balanced","max"]),Xe=h.object({enabled:h.boolean().default(!0),telemetryOptIn:h.boolean().default(!0),outputVerbosity:Un.default("compact"),reducer:Vn.default("off"),filters:h.object({enableAll:h.boolean().default(!0),disabled:h.array(h.string().max(64)).max(100).default([])}).default({enableAll:!0,disabled:[]})}),Hn=["git","grep","find","ls","ps","cat","head","tail","df","du","tree","wc","read-tool","grep-tool","glob-tool","npm","docker","kubectl","curl","cargo","go-test","gh","aws","dotnet","prisma","tsc","next","jest","vitest","pytest","pip","rspec"],Kn=/^[0-9a-f]{16}$/,wt=new Map;function B(t){let e=wt.get(t);return e||(e=Bn("sha256").update(`tkr:${t}`).digest("hex").slice(0,16),wt.set(t,e)),e}var St=null;function Ue(t,e=!1){return e||!t||t.length===0?(St??=new Set(Hn.map(B)),new Set(St)):new Set(t.map(r=>Kn.test(r)?r:B(r)))}var Oe=new Map,Wn=256,Tt=new WeakMap;function Gn(t){if(!t)return"*";let e=Tt.get(t);return e===void 0&&(e=[...t].join(","),Tt.set(t,e)),e}function At(t,e,r){let n=`${t}::${Gn(r)}`,s=Oe.get(n);if(s!==void 0)return s;let i=null;for(let a of e)r&&!r.has(B(a.slug))||a.matchRegex.test(t)&&(!i||a.priority>i.priority)&&(i=a);if(Oe.size>=Wn){let a=Oe.keys().next().value;a&&Oe.delete(a)}return Oe.set(n,i),i}var qn=/\x1b\[[0-9;?]*[ -/]*[@-~]/g,Yn=/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g;function Rt(t){return t.replace(qn,"").replace(Yn,"")}function Ct(t,e){return e.length===0?t:t.filter(r=>!e.some(n=>n.test(r)))}function It(t,e){return t.map(r=>r.length<=e?r:`${r.slice(0,e)}\u2026`)}function Ot(t,e){if(t.length<=e)return t;let r=t.length-e;return[...t.slice(0,e),`\u2026 (${r} more lines omitted)`]}var Jn=/^(\s*)(?:export\s+)?(?:async\s+)?(?:function|interface|type|const|let|var|def|fn|impl|trait|struct|enum)\s+[\w$]+/,Xn=/\{\s*$/;var Qn=/^\s*(?:(?:public|private|protected|static|async|get|set|readonly|override)\s+)*([\w$]+)\s*\(([^)]*)\)\s*(?::\s*[^{]+)?\{\s*$/,es=new Set(["if","for","while","switch","catch","do","with","return","else","function","await","yield"]);function ts(t){let e=Qn.exec(t);return!e||es.has(e[1])?!1:!/=>|\bfunction\b/.test(e[2])}var rs=/^\s*(?:if|for|while|switch|try|do)\b[^{}]*\{\s*$/;function Ve(t){let e=[],r=0;for(;r<t.length;){let n=t[r];if(Jn.test(n)&&Xn.test(n)||ts(n)||rs.test(n)){let s=0,i=r,a=!1;for(;i<t.length&&i-r<200;){for(let o of t[i])o==="{"||o==="("||o==="["?s+=1:(o==="}"||o===")"||o==="]")&&(s-=1);if(i+=1,s<=0){a=!0;break}}if(a){e.push(`${n.replace(/\{\s*$/,"")}{ \u2026 }`),r=i;continue}}e.push(n),r+=1}return e}var ns=/\b(?:function|class|interface|import\s+|export\s+|def\s+|fn\s+|impl\s+|package\s+|namespace\s+|using\s+|#include|=>\s*\{|=\s*function)/;function Dt(t){let e=t.slice(0,4096);return!(!ns.test(e)||e.split(`
5
- `).length<6)}var ss=/\b(?:DEBUG|TRACE|INFO|VERBOSE)\b/;function Nt(t){return t.filter(e=>!ss.test(e))}function Pt(t){if(t.length===0)return t;let e=[],r=1,n=t[0];for(let s=1;s<t.length;s++){if(t[s]===n){r+=1;continue}e.push(r>1?`${n} \xD7${r}`:n),n=t[s],r=1}return e.push(r>1?`${n} \xD7${r}`:n),e}function $t(t){let e=[],r=0;for(let n of t){if(n.trim()===""){r+=1;continue}r>0&&e.push(""),r=0,e.push(n)}return e}var Mt=new Map;function U(t,e){Mt.set(t,e)}function Lt(t){return Mt.get(t)}var is=/^[dbclps\-][rwxsStT\-]{9}[@.+]?(?:\s|$)/;function as(t){if(t<1024)return String(t);let e=["K","M","G","T"],r=t/1024,n=0;for(;r>=1024&&n<e.length-1;)r/=1024,n+=1;return`${r.toFixed(1)}${e[n]}`}function os(t){if(!is.test(t))return null;let e=t.split(/\s+/);if(e.length<9)return null;let r=Number(e[4]);if(!Number.isFinite(r))return null;let n=e.slice(8).join(" ").trim();if(n===""||n==="."||n==="..")return null;let s=e[0].charCodeAt(0)===100;return{name:n,size:r,isDir:s}}var cs=16;function ls(t){if(t.length<3)return null;let e=new Map;for(let s of t){let i=s.name.lastIndexOf(".");if(i<=0)continue;let a=s.name.slice(i);e.set(a,(e.get(a)??0)+1)}let r=null,n=0;for(let[s,i]of e)i>n&&(n=i,r=s);return r&&n>=Math.ceil(t.length/2)?`${n} ${r}`:null}function us(t){let e=[],r=[],n=!1;for(let k of t){if(/^total\s+\d+/.test(k))continue;let S=os(k);S&&(n=!0,(S.isDir?e:r).push(S))}if(!n)return t;let s=(k,S)=>k.name.localeCompare(S.name);e.sort(s),r.sort((k,S)=>S.size-k.size||s(k,S));let a=e.slice(0,3),o=r.slice(0,Math.max(0,cs-a.length)),l=[...a,...o],c=e.length-a.length+(r.length-o.length),p=Math.min(40,Math.max(0,...l.map(k=>k.isDir?k.name.length+1:k.name.length))),_=[];for(let k of l){let S=k.isDir?`${k.name}/`:k.name,V=k.isDir?"":as(k.size);_.push(V?`${S.padEnd(p)} ${V}`:S)}c>0&&_.push(`\u2026 ${c} more`);let E=r.length===1?"file":"files",w=e.length===1?"dir":"dirs",D=ls(r),L=`${r.length} ${E}, ${e.length} ${w}`+(D?` (${D})`:"");return _.push(L),_}U("smart-ls",us);U("smart-read",t=>Ve(t));var ds=12;function fs(t){let e=t.filter(c=>c.trim()!=="");if(e.length===0||e.filter(c=>!/\s/.test(c.trim())).length<e.length*.6)return t;let n=new Map,s=0;for(let c of e){let p=c.trim();if(/\s/.test(p))continue;let _=p.replace(/^\.\//,"").replace(/\/+$/,""),E=_.lastIndexOf("/"),w=E>=0?_.slice(0,E):"",D=E>=0?_.slice(E+1):_;if(!D)continue;let L=n.get(w)??[];L.push(D),n.set(w,L),s+=1}if(s===0)return t;let i=new Set([""]);for(let c of n.keys()){if(c==="")continue;let p=c.split("/");for(let _=1;_<=p.length;_+=1)i.add(p.slice(0,_).join("/"))}let a=[...i].sort(),o=a.filter(c=>c!=="").length,l=[`${s}F ${o}D:`,""];for(let c of a){let p=c===""?0:c.split("/").length,_=c===""?".":c.slice(c.lastIndexOf("/")+1),E=n.get(c)??[],w=E.slice(0,ds),D=E.length-w.length,L=w.length?` ${w.join(" ")}${D>0?` +${D}`:""}`:"";l.push(`${" ".repeat(p)}${_}/${L}`)}return l}U("smart-find",fs);var ps=/^[\s=]+$/,ms=/^\s*=+\s+(.*?)\s+=+\s*$/;U("strip-banners",t=>{let e=[];for(let r of t){if(ps.test(r))continue;let n=ms.exec(r);e.push(n?n[1]:r)}return e});function hs(t){let e=[],r=0,n=0;for(;n<t.length;){let s=t[n].replace(/\s+$/,"");if(s===""){r+=1,n+=1,r<=1&&e.push("");continue}r=0;let i=1;for(;n+i<t.length&&t[n+i].replace(/\s+$/,"")===s;)i+=1;if(i>=3)e.push(s),e.push(` \u2026 (repeated ${i}x)`);else for(let a=0;a<i;a++)e.push(s);n+=i}for(;e.length>0&&e[e.length-1]==="";)e.pop();return e}U("squeeze-output",hs);var jt=new WeakMap;function gs(t){let e=jt.get(t);if(e)return e;let r=t.strip_lines_matching.map(s=>new RegExp(s)),n={def:t,stripRegexes:r};return jt.set(t,n),n}function Ft(t,e,r={}){let n=gs(e),s=t;e.strip_ansi&&(s=Rt(s));let i=s.split(`
6
- `);n.stripRegexes.length&&(i=Ct(i,n.stripRegexes));let a=r.verbosity??"normal";if(a!=="normal"&&(i=Pt(i),i=$t(i)),a==="minimal"&&(i=Nt(i)),(r.smartCode||r.smartCode===void 0&&a!=="normal"&&Dt(s))&&(i=Ve(i)),e.transform){let l=Lt(e.transform);l&&(i=l(i))}e.truncate_lines_at&&(i=It(i,e.truncate_lines_at)),e.max_lines&&(i=Ot(i,e.max_lines));let o=i.join(`
7
- `);return o.trim().length===0&&e.on_empty&&(o=e.on_empty),o}var ys=[/\bERROR\b/,/\bFAIL\b/,/\bFAILED\b/,/\bFATAL\b/,/^Traceback /m,/^Error: /m,/^\s+at .*\(.*:\d+:\d+\)/m,/panic:/,/SyntaxError:/,/TypeError:/,/ReferenceError:/,/thread '.*' panicked/];function zt(t){if(!t)return!1;let e=t.length<=262144*2?[t]:[t.slice(0,262144),t.slice(-262144)];for(let r of ys)for(let n of e)if(r.test(n))return!0;return!1}var Zt=null;function Qe(t){Zt=t}async function _s(t,e){let r=await Et();return At(t,r.values(),e)}async function Bt(t,e,r,n={}){let s=Buffer.byteLength(e,"utf8"),{exitCode:i,...a}=n;if(i!=null?i!==0:zt(e))return{output:e,filterId:null,rawBytes:s,filteredBytes:s,debugBypass:!0};let c=await(Zt??_s)(t,r);if(!c)return{output:e,filterId:null,rawBytes:s,filteredBytes:s,debugBypass:!1};let p=Ft(e,c,a);return{output:p,filterId:c.slug,rawBytes:s,filteredBytes:Buffer.byteLength(p,"utf8"),debugBypass:!1}}import{join as xs}from"node:path";import{mkdir as to,readFile as bs,writeFile as ro,unlink as no,rename as so}from"node:fs/promises";import vs from"node:os";import{join as Ut}from"node:path";function R(){return process.env.TOKMIZER_HOME||Ut(vs.homedir(),".tokmizer")}function et(){return Ut(R(),"install-id")}var ks="state.json",ao={lastSettingsRevision:0,timeZone:Vt(),bonusActive:!1};function Vt(){try{let t=Intl.DateTimeFormat().resolvedOptions().timeZone;return t&&t.length>0?t:"Etc/UTC"}catch{return"Etc/UTC"}}function Es(t){return t?.dir??R()}async function tt(t){let e=Es(t);try{let r=await bs(xs(e,ks),"utf8"),n=JSON.parse(r);return{...n,lastSettingsRevision:n.lastSettingsRevision??0,timeZone:n.timeZone??Vt(),bonusActive:n.bonusActive??!1,...n.bonusResetAt!==void 0?{bonusResetAt:n.bonusResetAt}:{}}}catch{return null}}function ws(){let t=Number(process.env.TOKMIZER_OFFLINE_GRACE_MS);return Number.isFinite(t)&&t>0?t:6048e5}function rt(t,e=Date.now()){let r=t.lastHeartbeatOkAt;if(typeof r=="number"&&e-r>ws())return!0;if(t.subEndsAt){let n=Date.parse(t.subEndsAt);if(Number.isFinite(n)&&e>n)return!0}return!1}function Ht(t,e=Date.now()){return rt(t,e)?"free":t.plan}import{readFile as Ss,writeFile as uo,mkdir as fo,chmod as po}from"node:fs/promises";import{join as Ts}from"node:path";var As="settings-cache.json",Kt=Xe.parse({});async function Wt(){try{let t=await Ss(Ts(R(),As),"utf8"),e=JSON.parse(t);return Xe.parse({...Kt,...e})}catch{return Kt}}var Rs=[[/(authorization\s*:\s*)([A-Za-z][A-Za-z0-9._-]*)\s+[^\s'"]+/gi,"$1$2 [REDACTED]"],[/(authorization\s*:\s*)[A-Za-z0-9._\-+/=]{8,}/gi,"$1[REDACTED]"],[/(bearer\s+)[A-Za-z0-9._\-+/=]{8,}/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-b|--cookie)[=\s]+['"]?)[^\s'";=]+=[^\s'";]+(?:\s*;\s*[^\s'";=]+=[^\s'";]+)*/gi,"$1[REDACTED]"],[/((?:^|[\s'"])(?:Set-)?Cookie\s*:\s*)[^\s'";=]+=[^\s'";]+(?:\s*;\s*[^\s'";=]+=[^\s'";]+)*/gi,"$1[REDACTED]"],[/(--?(?:password|passwd|passphrase|apipass|pass|pwd|token|api[-_]?key|secret|bearer|cookie|jwt)(?:-[a-z0-9]+)*[=\s]+)\S+/gi,"$1[REDACTED]"],[/((?:^|\s)-b[=\s]?['"]?)[^\s'"=]+=[^\s'"]+/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-u[=\s]?|(?:--user|-a)[=\s])['"]?[^\s:/'"]*:)(\/[^/\s'"][^\s'"]*|[^\s/'"0-9][^\s'"]*|[0-9][^\s'"]*[^\s'"0-9][^\s'"]*)/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-u[=\s]?|(?:--user|-a)[=\s])['"]?[^\s:/'"]*[^\s:/'"0-9][^\s:/'"]*:)(?:\/[^/\s'"]|[^\s/'"])[^\s'"]*/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-u[=\s]?|(?:--user|-a)[=\s])['"]?:)(?:\/[^/\s'"]|[^\s/'"])[^\s'"]*/gi,"$1[REDACTED]"],[/((?:[A-Za-z0-9]+-)*(?:X-Api-Key|Private-Token|[A-Za-z0-9]+-(?:Token|Key|Auth|Secret))\s*:\s*)[^\s'"]+/gi,"$1[REDACTED]"],[/((?:^|[\s'"])(?:Set-)?Cookie\s*:\s*)[^\s'"]+/gi,"$1[REDACTED]"],[/(-i\s+)(\/[^\s]+|~\/[^\s]+|[A-Z]:\\[^\s]+)/g,"$1[REDACTED]"],[/([a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^:/\s@]*:)[^\s]+(@[^@/\s]+)/g,"$1[REDACTED]$2"],[/(AWS_(?:ACCESS_KEY_ID|SECRET_ACCESS_KEY|SESSION_TOKEN)\s*=\s*)\S+/g,"$1[REDACTED]"],[/(GOOGLE_APPLICATION_CREDENTIALS\s*=\s*)\S+/g,"$1[REDACTED]"],[/(AZURE_(?:CLIENT_SECRET|TENANT_ID|CLIENT_ID)\s*=\s*)\S+/g,"$1[REDACTED]"],[/(sk-(?:proj-)?[A-Za-z0-9_-]{20,})/g,"sk-[REDACTED]"],[/\b(OPENAI_API_KEY\s*=\s*)\S+/g,"$1[REDACTED]"],[/\b(ANTHROPIC_API_KEY\s*=\s*)\S+/g,"$1[REDACTED]"],[/(sk-ant-[A-Za-z0-9_-]{20,})/g,"sk-ant-[REDACTED]"],[/\b(GH(?:_|ITHUB_)?TOKEN\s*=\s*)\S+/g,"$1[REDACTED]"],[/\b(GITLAB_TOKEN\s*=\s*)\S+/g,"$1[REDACTED]"],[/\b(SLACK_(?:BOT_)?TOKEN\s*=\s*)\S+/g,"$1[REDACTED]"],[/(xox[bpsoa]-[A-Za-z0-9-]{10,})/g,"xox[REDACTED]"],[/(xapp-[A-Za-z0-9-]{10,})/g,"[REDACTED]"],[/(sk_(?:test|live)_[A-Za-z0-9]{16,})/g,"sk_[REDACTED]"],[/(gh[a-z])_[A-Za-z0-9]{20,}/g,"$1_[REDACTED]"],[/(github_pat)_[A-Za-z0-9_]{20,}/g,"$1_[REDACTED]"],[/(gl(?:pat|rt|soat|imt|dt|ft|agent|oas|cbt|ptt))-[A-Za-z0-9_-]{16,}/g,"$1-[REDACTED]"],[/(npm_[A-Za-z0-9_-]{20,})/g,"npm_[REDACTED]"],[/(?:AKIA|ASIA|AGPA|AIDA|AROA|ANPA)[0-9A-Z]{16,}/g,"[REDACTED_AWS_KEY]"],[/AIza[A-Za-z0-9_-]{35}/g,"[REDACTED_GOOGLE_KEY]"],[/hv[sb]\.[A-Za-z0-9_-]{20,}/g,"[REDACTED_VAULT_TOKEN]"],[/dop_v1_[A-Za-z0-9]{40,}/g,"[REDACTED]"],[/dckr_pat_[A-Za-z0-9_-]{20,}/g,"[REDACTED]"],[/pypi-[A-Za-z0-9_-]{16,}/g,"[REDACTED]"],[/rk_(?:live|test)_[A-Za-z0-9]{16,}/g,"[REDACTED]"],[/whsec_[A-Za-z0-9]{16,}/g,"[REDACTED]"],[/SG\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}/g,"[REDACTED]"],[/(eyJ[A-Za-z0-9_-]{6,}(?:\.[A-Za-z0-9_-]{4,}){1,2})/g,"[REDACTED_JWT]"],[/-----BEGIN [A-Z ]*PRIVATE KEY-----(?:[\s\S]*?-----END[^\n]*-----|\r?\n[A-Za-z0-9+/=][A-Za-z0-9+/=\r\n]*)?/g,"[REDACTED_PEM]"],[/\b((?:--?)?[A-Za-z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|PASS|APIKEY|KEY|CRED|CREDS|CREDENTIAL|CREDENTIALS|AUTH|_PWD)[A-Za-z0-9_]*['"]?\s*=\s*)(?:"[^"]*"|'[^']*'|[^"'\s]\S*)/gi,"$1[REDACTED]"],[/\b([A-Za-z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|PASS|APIKEY|KEY|CRED|CREDS|CREDENTIAL|CREDENTIALS|_PWD)[A-Za-z0-9_]*['"]?\s*:\s*)(?:"[^"]*"|'[^']*'|[^\s'",}]+)/gi,"$1[REDACTED]"],[/((?:^|[\s'"{,])['"]?(?:[A-Za-z0-9_]+_)?auth['"]?\s*:\s*)(?:"[^"]*"|'[^']*'|[^\s'",}]+)/gi,"$1[REDACTED]"],[/(\bpwd\s*[=:]\s*)(?:"[^"]*"|'[^']*'|[^/~\s][^\s;'"]*)/gi,"$1[REDACTED]"],[/([=:]\s*["']?)[A-Za-z0-9_\-+/=]{40,}/g,"$1[REDACTED]"]];function De(t){let e=t;for(let[r,n]of Rs)e=e.replace(r,n);return e}import{join as qt}from"node:path";import{appendFileSync as Ls,existsSync as js,mkdirSync as Fs,readFileSync as Mo,renameSync as Lo,statSync as zs,unlinkSync as jo,writeFileSync as Fo}from"node:fs";import{createHash as xo,randomUUID as Cs}from"node:crypto";import{readFile as Is,writeFile as Os,mkdir as Ds}from"node:fs/promises";async function Gt(){try{let r=(await Is(et(),"utf8")).trim();if(/^[0-9a-f-]{36}$/i.test(r))return r}catch{}await Ds(R(),{recursive:!0});let t=Cs();return await Os(et(),t,{mode:384}),t}import{createRequire as Ns}from"node:module";var Ps=Ns(import.meta.url);function $s(){for(let t of["../package.json","../../package.json"])try{let e=Ps(t).version;if(typeof e=="string"&&e)return e}catch{}return"0.0.0"}var Ms=$s();var Io=300*1e3;var Zs=512*1024;function Yt(){return qt(R(),"spool")}function Bs(t){return qt(Yt(),`${t}.jsonl`)}function He(t,e){try{Fs(Yt(),{recursive:!0,mode:448});let r=Bs(t);if(js(r)&&zs(r).size>=Zs)return;Ls(r,JSON.stringify(e)+`
8
- `,{mode:384})}catch{return}}var Vs=/^[a-z0-9][a-z0-9._-]*$/i,Hs=/^[a-z][a-z-]+$/,Ks=/^[A-Za-z_][A-Za-z0-9_]*=/,Ws=new Set(["gh","glab","gup","hub","gist"]),Gs=/^(gh[a-z]_|github_pat_|gl(?:pat|rt|soat|imt|dt|ft|agent|oas)-|npm_|xox|sk-|sk_|eyj|a(?:kia|sia|gpa|ida|roa|npa)|aiza|hv[sb]\.)/i,qs=24,Ys=new Set(["docker","podman","npm","pnpm","yarn","npx","bun","deno","cargo","rustup","go","pip","pip3","uv","poetry","brew","apt","apt-get","dnf","yum","pacman","kubectl","helm","terraform","aws","gcloud","az","systemctl","composer","bundle","gem","dotnet","prisma","tkr","rtk","token"]);function Jt(t){let e=t.toLowerCase();return e.startsWith("git")||Ws.has(e)}function nt(t){let e=t.trim().split(/\s+/).filter(o=>o.length>0),r=0;for(;r<e.length&&Ks.test(e[r]??"");)r+=1;let n=e[r];if(!n||!Vs.test(n)||n.length>qs||Jt(n)||Gs.test(n)||De(n)!==n)return"";let s=e[r+1];return s&&Jt(s)?"":(s&&Ys.has(n.toLowerCase())&&Hs.test(s)?`${n} ${s}`:n).slice(0,64)}async function Xt(t){if(!t.telemetryOptIn)return;let e=nt(t.cmd),r=e&&De(e)===e?e:"other";He("telemetry",{cmd:r,tokensSaved:Math.max(0,Math.round(t.tokensSaved)),optimized:t.optimized})}async function Qt(t){if(t.plan!=="pro")return;let e=nt(t.cmd);!e||De(e)!==e||He("learn",{cmd:e,filterId:t.filterId==null?null:B(t.filterId),rawBytes:t.rawBytes,filteredBytes:t.filteredBytes})}import{appendFileSync as Js,chmodSync as Xs,mkdirSync as Qs}from"node:fs";import{join as ei}from"node:path";var ti="stats.jsonl";function ri(){return ei(R(),ti)}function st(t,e,r=ri()){if(t<=0||e<0||e>t)return;let n=`{"t":${Math.floor(Date.now()/1e3)},"r":${t},"f":${e}}
9
- `;try{Qs(R(),{recursive:!0,mode:448}),Js(r,n,{mode:384}),Xs(r,384)}catch{return}}function er(t,e,r){let n=r!=null?Math.min(t,r):t,s=Math.min(e,n);return{raw:n,filtered:s}}import{delimiter as tr,join as ni}from"node:path";function si(){return ni(R(),"shims")}function rr(){let t=si(),e={...process.env},r=process.platform==="win32"?"Path":"PATH",s=(e[r]??e.PATH??"").split(tr).filter(i=>i&&i!==t);return e[r]=s.join(tr),r==="Path"&&(e.PATH=e[r]),e}var ii=[{host:"claude-code",vars:["CLAUDE_CODE","CLAUDE_CODE_VERSION","ANTHROPIC_CLAUDE_CODE"]},{host:"codex",vars:["CODEX_VERSION","CODEX_CLI","OPENAI_CODEX"]},{host:"cursor",vars:["CURSOR_VERSION","CURSOR_TRACE_ID"]},{host:"cline",vars:["CLINE_VERSION","CLINE_API_KEY"]},{host:"aider",vars:["AIDER_VERSION","AIDER_MODEL"]},{host:"gemini-cli",vars:["GEMINI_CLI_VERSION","GEMINI_API_KEY"]},{host:"windsurf",vars:["WINDSURF_VERSION","WINDSURF_USER"]},{host:"copilot",vars:["GITHUB_COPILOT_VERSION","COPILOT_INTEGRATION_ID"]}],nr=new Set(["claude-code","codex"]),ai=3e4;function sr(t){return nr.has(t)?ai:null}function it(t=process.env){let e=process.platform,r=e==="darwin"||e==="linux"||e==="win32"?e:"other",n=process.arch;for(let s of ii)if(s.vars.some(i=>t[i]))return{host:s.host,source:"env",os:r,arch:n,shimRecommended:!nr.has(s.host)};return{host:"shell",source:"fallback",os:r,arch:n,shimRecommended:!0}}import{createConnection as hi}from"node:net";import{spawn as gi}from"node:child_process";import{existsSync as hr,openSync as ur,closeSync as yi,unlinkSync as dr,writeFileSync as fr}from"node:fs";import{dirname as _i,join as vi}from"node:path";import{fileURLToPath as xi}from"node:url";var oi=h.object({id:h.string().min(1).max(64),op:h.literal("filter"),cmd:h.string().min(1).max(2048),plan:h.enum(["trial","smart","pro"]),installId:h.string().min(1).max(64).optional()}),ci=h.object({id:h.string().min(1).max(64),op:h.literal("ping")}),li=h.object({id:h.string().min(1).max(64),op:h.literal("shutdown"),installId:h.string().min(1).max(64)}),ui=h.object({id:h.string().min(1).max(64),op:h.literal("reload"),installId:h.string().min(1).max(64).optional()}),lc=h.discriminatedUnion("op",[oi,ci,li,ui]),uc=h.object({id:h.string(),ok:h.literal(!0),data:h.unknown()}),dc=h.object({id:h.string(),ok:h.literal(!1),err:h.string(),retryAfterMs:h.number().int().nonnegative().optional()}),ir=h.object({filter:Be.nullable(),cacheHit:h.boolean().optional()}),Ke=`
10
- `,fc=64*1024;function ar(t){return JSON.stringify(t)+Ke}function*or(t){let e=0;for(;;){let r=t.indexOf(Ke,e);if(r<0)return;yield t.slice(e,r),e=r+1}}function We(){return`${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}import{join as at}from"node:path";import{existsSync as cr,statSync as di,unlinkSync as fi,mkdirSync as pi,chmodSync as mi}from"node:fs";function Ge(){if(process.platform==="win32")return{path:`\\\\.\\pipe\\tokmizer-${process.env.USERNAME??"tokmizer"}`,isPipe:!0};let t=typeof process.getuid=="function"?process.getuid():0,e=process.env.XDG_RUNTIME_DIR;if(e&&cr(e))return{path:at(e,`tokmizer-${t}.sock`),isPipe:!1};let r=at(R(),"run");try{pi(r,{recursive:!0,mode:448}),mi(r,448)}catch{}return{path:at(r,"daemon.sock"),isPipe:!1}}async function lr(){let{path:t,isPipe:e}=Ge();if(e||!cr(t))return;try{if(!di(t).isSocket())return}catch{return}let r=await import("node:net");if(!await new Promise(s=>{let i=r.createConnection(t),a=o=>{i.removeAllListeners();try{i.destroy()}catch{}s(o)};i.once("connect",()=>a(!0)),i.once("error",o=>{let l=o.code;a(l!=="ECONNREFUSED"&&l!=="ENOENT")}),setTimeout(()=>a(!0),250)}))try{fi(t)}catch{}}var yc=5*6e4;var bi=500,ki=3e3,pr=1;async function Ei(t,e){return new Promise((r,n)=>{let s=hi(t),i=o=>{if(s.removeAllListeners("connect"),s.removeAllListeners("error"),clearTimeout(a),o){try{s.destroy()}catch{}n(o)}else r(s)},a=setTimeout(()=>i(new Error("connect timeout")),e);s.once("connect",()=>i(null)),s.once("error",o=>i(o))})}function wi(){return process.env.TOKMIZER_DAEMON_BIN?process.env.TOKMIZER_DAEMON_BIN:xi(new URL("../bin/tkr-daemon.js",import.meta.url))}async function mr(t,e=3e3){let r=Math.ceil(e/75);for(let n=0;n<r;n++){if(hr(t))return!0;await new Promise(s=>setTimeout(s,75))}return!1}async function Si(t){let e=wi();if(!hr(e))throw new Error(`tkr-daemon binary not found at ${e}`);let{path:r}=Ge(),n=vi(_i(r),"daemon.spawn.lock"),s=null;try{s=ur(n,"wx"),fr(s,String(process.pid))}catch(i){if(i.code==="EEXIST"){if(await mr(r,5e3))return;try{dr(n)}catch{}s=ur(n,"wx"),fr(s,String(process.pid))}else throw i}try{if(gi(process.execPath,[e],{detached:!0,stdio:["ignore","ignore","ignore"],env:{...process.env,TOKMIZER_DAEMON_INSTALL_ID:t}}).unref(),!await mr(r,3e3))throw new Error("tkr-daemon failed to bind socket within 3s")}finally{if(s!==null){try{yi(s)}catch{}try{dr(n)}catch{}}}}async function gr(t={}){let{path:e}=t.socketPath?{path:t.socketPath}:Ge(),r=await Gt(),n=null,s=0;for(;s<=pr;)try{n=await Ei(e,bi);break}catch{if(s+=1,s>pr)throw new Error(`tkr-daemon unreachable at ${e}`);await lr(),await Si(r)}if(!n)throw new Error("tkr-daemon: socket setup failed");let i=new Map,a="";n.setEncoding("utf8"),n.on("data",l=>{a+=l;let c=-1;for(let _=0;_<a.length;_++)a[_]===Ke&&(c=_);if(c<0)return;let p=[];for(let _ of or(a.slice(0,c+1)))p.push(_);a=a.slice(c+1);for(let _ of p)if(_)try{let E=JSON.parse(_),w=i.get(E.id);if(!w)continue;clearTimeout(w.timer),i.delete(E.id),w.resolve(E)}catch{}}),n.on("close",()=>{for(let l of i.values())clearTimeout(l.timer),l.reject(new Error("daemon socket closed"));i.clear()}),n.on("error",()=>{});function o(l){return new Promise((c,p)=>{let _=setTimeout(()=>{i.delete(l.id),p(new Error(`daemon request timeout (${l.op})`))},ki);i.set(l.id,{resolve:c,reject:p,timer:_}),n.write(ar(l))})}return{filter:async(l,c)=>{let p=await o({id:We(),op:"filter",cmd:l.slice(0,2048),plan:c,installId:r});if(!p.ok)return null;let _=ir.safeParse(p.data);return _.success?_.data.filter:null},ping:async()=>{let l=await o({id:We(),op:"ping"});if(!l.ok)throw new Error(l.err);return l.data},reload:async()=>{let l=await o({id:We(),op:"reload",installId:r});if(!l.ok)throw new Error(l.err);return l.data},close:()=>{try{n.end()}catch{}}}}var Ae=null,Ne=null;async function Ti(){return Ae||Ne||(Ne=gr().then(t=>(Ae=t,t)).catch(()=>null),Ne)}function Ai(t){return t?{...t,matchRegex:new RegExp(t.match_command)}:null}function yr(t){Qe(async(e,r)=>{let n=await Ti();if(!n)return null;try{let s=t==="free"?"trial":t,i=await n.filter(e,s);return!i||!(r??Ue(void 0)).has(B(i.slug))?null:Ai(i)}catch{return null}})}function _r(){if(Qe(null),Ae){try{Ae.close()}catch{}Ae=null,Ne=null}}var vr=16*1024*1024,xr=Number(process.env.TOKMIZER_SHIM_TIMEOUT_MS??"600000");function br(t){return t[0]==="--as"&&typeof t[1]=="string"?{cmdName:t[1],args:t.slice(2)}:t.length>0?{cmdName:t[0],args:t.slice(1)}:{cmdName:"",args:[]}}async function kr(t){let{cmdName:e,args:r}=t;if(!e)return process.stderr.write(`tkr-shim: missing command name
11
- `),{exitCode:2,filteredOut:"",filteredErr:"",filterId:null,rawBytes:0,filteredBytes:0};let n=[e,...r].join(" "),s=await Wt(),i=await tt(),a=i?Ht(i):null,o=i?Ue(i.allowedFilters,rt(i)):new Set,l=new Set(s.filters.disabled.map(B)),c=l.size>0?new Set([...o].filter(E=>!l.has(E))):o,p=!process.stdout.isTTY&&it().host==="shell",_=!s.enabled||!i;i&&!_&&!p&&yr(a);try{return await new Promise(E=>{let w=Ri(e,r,{stdio:["inherit","pipe","pipe"],shell:!1,windowsHide:!0,env:rr(),timeout:xr>0?xr:void 0}),D=[],L=[],k=0,S=0,V=!1,ot=C=>{try{w.kill(C)}catch{}};process.on("SIGINT",()=>ot("SIGINT")),process.on("SIGTERM",()=>ot("SIGTERM")),w.stdout.on("data",C=>{if(k+=C.length,k>vr){if(!V){for(let ge of D)process.stdout.write(ge);D.length=0,V=!0}process.stdout.write(C);return}D.push(C)}),w.stderr.on("data",C=>{if(S+=C.length,S>vr){if(!V){for(let ge of L)process.stderr.write(ge);L.length=0,V=!0}process.stderr.write(C);return}L.push(C)}),w.on("error",C=>{process.stderr.write(`tkr-shim: ${C.message}
12
- `),E({exitCode:127,filteredOut:"",filteredErr:"",filterId:null,rawBytes:0,filteredBytes:0})}),w.on("close",async(C,ge)=>{let Pe=typeof C=="number"?C:ge==="SIGTERM"?143:ge==="SIGINT"?130:1,ye=Buffer.concat(D),_e=Buffer.concat(L);if(V||_||p){ye.length&&process.stdout.write(ye),_e.length&&process.stderr.write(_e),p&&!_&&!V&&st(k+S,k+S),E({exitCode:Pe,filteredOut:ye.toString("utf8"),filteredErr:_e.toString("utf8"),filterId:null,rawBytes:k+S,filteredBytes:k+S});return}let ct=ye.toString("utf8"),$e=_e.toString("utf8");try{let N=await Bt(n,ct,c,{verbosity:s.outputVerbosity,exitCode:Pe}),Me=er(N.rawBytes,N.filteredBytes,sr(it().host));st(Me.raw,Me.filtered);try{await Qt({cmd:n,filterId:N.filterId,rawBytes:N.rawBytes,filteredBytes:N.filteredBytes,plan:a}),await Xt({cmd:n,tokensSaved:Math.round((Me.raw-Me.filtered)/4),optimized:N.filterId!=null,telemetryOptIn:s.telemetryOptIn})}catch{}if(N.filteredBytes<N.rawBytes){process.stdout.write(N.output),$e&&process.stderr.write($e),E({exitCode:Pe,filteredOut:N.output,filteredErr:$e,filterId:N.filterId,rawBytes:N.rawBytes,filteredBytes:N.filteredBytes});return}}catch{}ye.length&&process.stdout.write(ye),_e.length&&process.stderr.write(_e),E({exitCode:Pe,filteredOut:ct,filteredErr:$e,filterId:null,rawBytes:k+S,filteredBytes:k+S})})})}finally{_r()}}var Ci=br(process.argv.slice(2));kr(Ci).then(t=>{process.exitCode=t.exitCode}).catch(t=>{process.stderr.write(`tkr-shim: ${t.message}
3
+ var Ar=Object.defineProperty;var Rr=(t,e)=>{for(var r in e)Ar(t,r,{get:e[r],enumerable:!0})};import{spawn as Oi}from"node:child_process";import{readdir as zn,readFile as Zn}from"node:fs/promises";import{join as wt,dirname as Bn}from"node:path";import{fileURLToPath as Un}from"node:url";var h={};Rr(h,{BRAND:()=>en,DIRTY:()=>Q,EMPTY_PATH:()=>Dr,INVALID:()=>g,NEVER:()=>Fn,OK:()=>S,ParseStatus:()=>w,Schema:()=>b,ZodAny:()=>Y,ZodArray:()=>K,ZodBigInt:()=>te,ZodBoolean:()=>re,ZodBranded:()=>Ce,ZodCatch:()=>pe,ZodDate:()=>ne,ZodDefault:()=>fe,ZodDiscriminatedUnion:()=>ze,ZodEffects:()=>P,ZodEnum:()=>ue,ZodError:()=>R,ZodFirstPartyTypeKind:()=>y,ZodFunction:()=>Be,ZodIntersection:()=>oe,ZodIssueCode:()=>l,ZodLazy:()=>ce,ZodLiteral:()=>le,ZodMap:()=>we,ZodNaN:()=>Te,ZodNativeEnum:()=>de,ZodNever:()=>M,ZodNull:()=>ie,ZodNullable:()=>F,ZodNumber:()=>ee,ZodObject:()=>C,ZodOptional:()=>D,ZodParsedType:()=>p,ZodPipeline:()=>Ie,ZodPromise:()=>J,ZodReadonly:()=>me,ZodRecord:()=>Ze,ZodSchema:()=>b,ZodSet:()=>Se,ZodString:()=>q,ZodSymbol:()=>ke,ZodTransformer:()=>P,ZodTuple:()=>j,ZodType:()=>b,ZodUndefined:()=>se,ZodUnion:()=>ae,ZodUnknown:()=>H,ZodVoid:()=>Ee,addIssueToContext:()=>d,any:()=>un,array:()=>mn,bigint:()=>sn,boolean:()=>bt,coerce:()=>jn,custom:()=>_t,date:()=>an,datetimeRegex:()=>gt,defaultErrorMap:()=>U,discriminatedUnion:()=>_n,effect:()=>In,enum:()=>An,function:()=>wn,getErrorMap:()=>ve,getParsedType:()=>L,instanceof:()=>rn,intersection:()=>vn,isAborted:()=>je,isAsync:()=>xe,isDirty:()=>Fe,isValid:()=>G,late:()=>tn,lazy:()=>Sn,literal:()=>Tn,makeIssue:()=>Re,map:()=>kn,nan:()=>nn,nativeEnum:()=>Rn,never:()=>fn,null:()=>ln,nullable:()=>Dn,number:()=>xt,object:()=>hn,objectUtil:()=>Ye,oboolean:()=>Ln,onumber:()=>Mn,optional:()=>On,ostring:()=>$n,pipeline:()=>Pn,preprocess:()=>Nn,promise:()=>Cn,quotelessJson:()=>Cr,record:()=>bn,set:()=>En,setErrorMap:()=>Or,strictObject:()=>gn,string:()=>vt,symbol:()=>on,transformer:()=>In,tuple:()=>xn,undefined:()=>cn,union:()=>yn,unknown:()=>dn,util:()=>k,void:()=>pn});var k;(function(t){t.assertEqual=s=>{};function e(s){}t.assertIs=e;function r(s){throw new Error}t.assertNever=r,t.arrayToEnum=s=>{let i={};for(let a of s)i[a]=a;return i},t.getValidEnumValues=s=>{let i=t.objectKeys(s).filter(o=>typeof s[s[o]]!="number"),a={};for(let o of i)a[o]=s[o];return t.objectValues(a)},t.objectValues=s=>t.objectKeys(s).map(function(i){return s[i]}),t.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{let i=[];for(let a in s)Object.prototype.hasOwnProperty.call(s,a)&&i.push(a);return i},t.find=(s,i)=>{for(let a of s)if(i(a))return a},t.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function n(s,i=" | "){return s.map(a=>typeof a=="string"?`'${a}'`:a).join(i)}t.joinValues=n,t.jsonStringifyReplacer=(s,i)=>typeof i=="bigint"?i.toString():i})(k||(k={}));var Ye;(function(t){t.mergeShapes=(e,r)=>({...e,...r})})(Ye||(Ye={}));var p=k.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),L=t=>{switch(typeof t){case"undefined":return p.undefined;case"string":return p.string;case"number":return Number.isNaN(t)?p.nan:p.number;case"boolean":return p.boolean;case"function":return p.function;case"bigint":return p.bigint;case"symbol":return p.symbol;case"object":return Array.isArray(t)?p.array:t===null?p.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?p.promise:typeof Map<"u"&&t instanceof Map?p.map:typeof Set<"u"&&t instanceof Set?p.set:typeof Date<"u"&&t instanceof Date?p.date:p.object;default:return p.unknown}};var l=k.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Cr=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:"),R=class t extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=n=>{this.issues=[...this.issues,n]},this.addIssues=(n=[])=>{this.issues=[...this.issues,...n]};let r=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,r):this.__proto__=r,this.name="ZodError",this.issues=e}format(e){let r=e||function(i){return i.message},n={_errors:[]},s=i=>{for(let a of i.issues)if(a.code==="invalid_union")a.unionErrors.map(s);else if(a.code==="invalid_return_type")s(a.returnTypeError);else if(a.code==="invalid_arguments")s(a.argumentsError);else if(a.path.length===0)n._errors.push(r(a));else{let o=n,c=0;for(;c<a.path.length;){let u=a.path[c];c===a.path.length-1?(o[u]=o[u]||{_errors:[]},o[u]._errors.push(r(a))):o[u]=o[u]||{_errors:[]},o=o[u],c++}}};return s(this),n}static assert(e){if(!(e instanceof t))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,k.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=r=>r.message){let r={},n=[];for(let s of this.issues)if(s.path.length>0){let i=s.path[0];r[i]=r[i]||[],r[i].push(e(s))}else n.push(e(s));return{formErrors:n,fieldErrors:r}}get formErrors(){return this.flatten()}};R.create=t=>new R(t);var Ir=(t,e)=>{let r;switch(t.code){case l.invalid_type:t.received===p.undefined?r="Required":r=`Expected ${t.expected}, received ${t.received}`;break;case l.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(t.expected,k.jsonStringifyReplacer)}`;break;case l.unrecognized_keys:r=`Unrecognized key(s) in object: ${k.joinValues(t.keys,", ")}`;break;case l.invalid_union:r="Invalid input";break;case l.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${k.joinValues(t.options)}`;break;case l.invalid_enum_value:r=`Invalid enum value. Expected ${k.joinValues(t.options)}, received '${t.received}'`;break;case l.invalid_arguments:r="Invalid function arguments";break;case l.invalid_return_type:r="Invalid function return type";break;case l.invalid_date:r="Invalid date";break;case l.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(r=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(r=`${r} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?r=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?r=`Invalid input: must end with "${t.validation.endsWith}"`:k.assertNever(t.validation):t.validation!=="regex"?r=`Invalid ${t.validation}`:r="Invalid";break;case l.too_small:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?r=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:r="Invalid input";break;case l.too_big:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?r=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:r="Invalid input";break;case l.custom:r="Invalid input";break;case l.invalid_intersection_types:r="Intersection results could not be merged";break;case l.not_multiple_of:r=`Number must be a multiple of ${t.multipleOf}`;break;case l.not_finite:r="Number must be finite";break;default:r=e.defaultError,k.assertNever(t)}return{message:r}},U=Ir;var dt=U;function Or(t){dt=t}function ve(){return dt}var Re=t=>{let{data:e,path:r,errorMaps:n,issueData:s}=t,i=[...r,...s.path||[]],a={...s,path:i};if(s.message!==void 0)return{...s,path:i,message:s.message};let o="",c=n.filter(u=>!!u).slice().reverse();for(let u of c)o=u(a,{data:e,defaultError:o}).message;return{...s,path:i,message:o}},Dr=[];function d(t,e){let r=ve(),n=Re({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,r,r===U?void 0:U].filter(s=>!!s)});t.common.issues.push(n)}var w=class t{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,r){let n=[];for(let s of r){if(s.status==="aborted")return g;s.status==="dirty"&&e.dirty(),n.push(s.value)}return{status:e.value,value:n}}static async mergeObjectAsync(e,r){let n=[];for(let s of r){let i=await s.key,a=await s.value;n.push({key:i,value:a})}return t.mergeObjectSync(e,n)}static mergeObjectSync(e,r){let n={};for(let s of r){let{key:i,value:a}=s;if(i.status==="aborted"||a.status==="aborted")return g;i.status==="dirty"&&e.dirty(),a.status==="dirty"&&e.dirty(),i.value!=="__proto__"&&(typeof a.value<"u"||s.alwaysSet)&&(n[i.value]=a.value)}return{status:e.value,value:n}}},g=Object.freeze({status:"aborted"}),Q=t=>({status:"dirty",value:t}),S=t=>({status:"valid",value:t}),je=t=>t.status==="aborted",Fe=t=>t.status==="dirty",G=t=>t.status==="valid",xe=t=>typeof Promise<"u"&&t instanceof Promise;var m;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(m||(m={}));var N=class{constructor(e,r,n,s){this._cachedPath=[],this.parent=e,this.data=r,this._path=n,this._key=s}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}},ft=(t,e)=>{if(G(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let r=new R(t.common.issues);return this._error=r,this._error}}};function x(t){if(!t)return{};let{errorMap:e,invalid_type_error:r,required_error:n,description:s}=t;if(e&&(r||n))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(a,o)=>{let{message:c}=t;return a.code==="invalid_enum_value"?{message:c??o.defaultError}:typeof o.data>"u"?{message:c??n??o.defaultError}:a.code!=="invalid_type"?{message:o.defaultError}:{message:c??r??o.defaultError}},description:s}}var b=class{get description(){return this._def.description}_getType(e){return L(e.data)}_getOrReturnCtx(e,r){return r||{common:e.parent.common,data:e.data,parsedType:L(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new w,ctx:{common:e.parent.common,data:e.data,parsedType:L(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let r=this._parse(e);if(xe(r))throw new Error("Synchronous parse encountered promise.");return r}_parseAsync(e){let r=this._parse(e);return Promise.resolve(r)}parse(e,r){let n=this.safeParse(e,r);if(n.success)return n.data;throw n.error}safeParse(e,r){let n={common:{issues:[],async:r?.async??!1,contextualErrorMap:r?.errorMap},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:L(e)},s=this._parseSync({data:e,path:n.path,parent:n});return ft(n,s)}"~validate"(e){let r={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:L(e)};if(!this["~standard"].async)try{let n=this._parseSync({data:e,path:[],parent:r});return G(n)?{value:n.value}:{issues:r.common.issues}}catch(n){n?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),r.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:r}).then(n=>G(n)?{value:n.value}:{issues:r.common.issues})}async parseAsync(e,r){let n=await this.safeParseAsync(e,r);if(n.success)return n.data;throw n.error}async safeParseAsync(e,r){let n={common:{issues:[],contextualErrorMap:r?.errorMap,async:!0},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:L(e)},s=this._parse({data:e,path:n.path,parent:n}),i=await(xe(s)?s:Promise.resolve(s));return ft(n,i)}refine(e,r){let n=s=>typeof r=="string"||typeof r>"u"?{message:r}:typeof r=="function"?r(s):r;return this._refinement((s,i)=>{let a=e(s),o=()=>i.addIssue({code:l.custom,...n(s)});return typeof Promise<"u"&&a instanceof Promise?a.then(c=>c?!0:(o(),!1)):a?!0:(o(),!1)})}refinement(e,r){return this._refinement((n,s)=>e(n)?!0:(s.addIssue(typeof r=="function"?r(n,s):r),!1))}_refinement(e){return new P({schema:this,typeName:y.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:r=>this["~validate"](r)}}optional(){return D.create(this,this._def)}nullable(){return F.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return K.create(this)}promise(){return J.create(this,this._def)}or(e){return ae.create([this,e],this._def)}and(e){return oe.create(this,e,this._def)}transform(e){return new P({...x(this._def),schema:this,typeName:y.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let r=typeof e=="function"?e:()=>e;return new fe({...x(this._def),innerType:this,defaultValue:r,typeName:y.ZodDefault})}brand(){return new Ce({typeName:y.ZodBranded,type:this,...x(this._def)})}catch(e){let r=typeof e=="function"?e:()=>e;return new pe({...x(this._def),innerType:this,catchValue:r,typeName:y.ZodCatch})}describe(e){let r=this.constructor;return new r({...this._def,description:e})}pipe(e){return Ie.create(this,e)}readonly(){return me.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},Nr=/^c[^\s-]{8,}$/i,Pr=/^[0-9a-z]+$/,$r=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Mr=/^[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,Lr=/^[a-z0-9_-]{21}$/i,jr=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Fr=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,zr=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Zr="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",Je,Br=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Ur=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,Vr=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,Hr=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Kr=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Wr=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,mt="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",Gr=new RegExp(`^${mt}$`);function ht(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);let r=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${r}`}function qr(t){return new RegExp(`^${ht(t)}$`)}function gt(t){let e=`${mt}T${ht(t)}`,r=[];return r.push(t.local?"Z?":"Z"),t.offset&&r.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${r.join("|")})`,new RegExp(`^${e}$`)}function Yr(t,e){return!!((e==="v4"||!e)&&Br.test(t)||(e==="v6"||!e)&&Vr.test(t))}function Jr(t,e){if(!jr.test(t))return!1;try{let[r]=t.split(".");if(!r)return!1;let n=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(r.length+(4-r.length%4)%4,"="),s=JSON.parse(atob(n));return!(typeof s!="object"||s===null||"typ"in s&&s?.typ!=="JWT"||!s.alg||e&&s.alg!==e)}catch{return!1}}function Xr(t,e){return!!((e==="v4"||!e)&&Ur.test(t)||(e==="v6"||!e)&&Hr.test(t))}var q=class t extends b{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==p.string){let i=this._getOrReturnCtx(e);return d(i,{code:l.invalid_type,expected:p.string,received:i.parsedType}),g}let n=new w,s;for(let i of this._def.checks)if(i.kind==="min")e.data.length<i.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:l.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),n.dirty());else if(i.kind==="max")e.data.length>i.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:l.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),n.dirty());else if(i.kind==="length"){let a=e.data.length>i.value,o=e.data.length<i.value;(a||o)&&(s=this._getOrReturnCtx(e,s),a?d(s,{code:l.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):o&&d(s,{code:l.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),n.dirty())}else if(i.kind==="email")zr.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"email",code:l.invalid_string,message:i.message}),n.dirty());else if(i.kind==="emoji")Je||(Je=new RegExp(Zr,"u")),Je.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"emoji",code:l.invalid_string,message:i.message}),n.dirty());else if(i.kind==="uuid")Mr.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"uuid",code:l.invalid_string,message:i.message}),n.dirty());else if(i.kind==="nanoid")Lr.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"nanoid",code:l.invalid_string,message:i.message}),n.dirty());else if(i.kind==="cuid")Nr.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"cuid",code:l.invalid_string,message:i.message}),n.dirty());else if(i.kind==="cuid2")Pr.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"cuid2",code:l.invalid_string,message:i.message}),n.dirty());else if(i.kind==="ulid")$r.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"ulid",code:l.invalid_string,message:i.message}),n.dirty());else if(i.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),d(s,{validation:"url",code:l.invalid_string,message:i.message}),n.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"regex",code:l.invalid_string,message:i.message}),n.dirty())):i.kind==="trim"?e.data=e.data.trim():i.kind==="includes"?e.data.includes(i.value,i.position)||(s=this._getOrReturnCtx(e,s),d(s,{code:l.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),n.dirty()):i.kind==="toLowerCase"?e.data=e.data.toLowerCase():i.kind==="toUpperCase"?e.data=e.data.toUpperCase():i.kind==="startsWith"?e.data.startsWith(i.value)||(s=this._getOrReturnCtx(e,s),d(s,{code:l.invalid_string,validation:{startsWith:i.value},message:i.message}),n.dirty()):i.kind==="endsWith"?e.data.endsWith(i.value)||(s=this._getOrReturnCtx(e,s),d(s,{code:l.invalid_string,validation:{endsWith:i.value},message:i.message}),n.dirty()):i.kind==="datetime"?gt(i).test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{code:l.invalid_string,validation:"datetime",message:i.message}),n.dirty()):i.kind==="date"?Gr.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{code:l.invalid_string,validation:"date",message:i.message}),n.dirty()):i.kind==="time"?qr(i).test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{code:l.invalid_string,validation:"time",message:i.message}),n.dirty()):i.kind==="duration"?Fr.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"duration",code:l.invalid_string,message:i.message}),n.dirty()):i.kind==="ip"?Yr(e.data,i.version)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"ip",code:l.invalid_string,message:i.message}),n.dirty()):i.kind==="jwt"?Jr(e.data,i.alg)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"jwt",code:l.invalid_string,message:i.message}),n.dirty()):i.kind==="cidr"?Xr(e.data,i.version)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"cidr",code:l.invalid_string,message:i.message}),n.dirty()):i.kind==="base64"?Kr.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"base64",code:l.invalid_string,message:i.message}),n.dirty()):i.kind==="base64url"?Wr.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"base64url",code:l.invalid_string,message:i.message}),n.dirty()):k.assertNever(i);return{status:n.value,value:e.data}}_regex(e,r,n){return this.refinement(s=>e.test(s),{validation:r,code:l.invalid_string,...m.errToObj(n)})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...m.errToObj(e)})}url(e){return this._addCheck({kind:"url",...m.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...m.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...m.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...m.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...m.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...m.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...m.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...m.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...m.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...m.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...m.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...m.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...m.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...m.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...m.errToObj(e)})}regex(e,r){return this._addCheck({kind:"regex",regex:e,...m.errToObj(r)})}includes(e,r){return this._addCheck({kind:"includes",value:e,position:r?.position,...m.errToObj(r?.message)})}startsWith(e,r){return this._addCheck({kind:"startsWith",value:e,...m.errToObj(r)})}endsWith(e,r){return this._addCheck({kind:"endsWith",value:e,...m.errToObj(r)})}min(e,r){return this._addCheck({kind:"min",value:e,...m.errToObj(r)})}max(e,r){return this._addCheck({kind:"max",value:e,...m.errToObj(r)})}length(e,r){return this._addCheck({kind:"length",value:e,...m.errToObj(r)})}nonempty(e){return this.min(1,m.errToObj(e))}trim(){return new t({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxLength(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}};q.create=t=>new q({checks:[],typeName:y.ZodString,coerce:t?.coerce??!1,...x(t)});function Qr(t,e){let r=(t.toString().split(".")[1]||"").length,n=(e.toString().split(".")[1]||"").length,s=r>n?r:n,i=Number.parseInt(t.toFixed(s).replace(".","")),a=Number.parseInt(e.toFixed(s).replace(".",""));return i%a/10**s}var ee=class t extends b{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==p.number){let i=this._getOrReturnCtx(e);return d(i,{code:l.invalid_type,expected:p.number,received:i.parsedType}),g}let n,s=new w;for(let i of this._def.checks)i.kind==="int"?k.isInteger(e.data)||(n=this._getOrReturnCtx(e,n),d(n,{code:l.invalid_type,expected:"integer",received:"float",message:i.message}),s.dirty()):i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:l.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:l.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="multipleOf"?Qr(e.data,i.value)!==0&&(n=this._getOrReturnCtx(e,n),d(n,{code:l.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):i.kind==="finite"?Number.isFinite(e.data)||(n=this._getOrReturnCtx(e,n),d(n,{code:l.not_finite,message:i.message}),s.dirty()):k.assertNever(i);return{status:s.value,value:e.data}}gte(e,r){return this.setLimit("min",e,!0,m.toString(r))}gt(e,r){return this.setLimit("min",e,!1,m.toString(r))}lte(e,r){return this.setLimit("max",e,!0,m.toString(r))}lt(e,r){return this.setLimit("max",e,!1,m.toString(r))}setLimit(e,r,n,s){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:r,inclusive:n,message:m.toString(s)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:m.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:m.toString(e)})}multipleOf(e,r){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(r)})}finite(e){return this._addCheck({kind:"finite",message:m.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:m.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:m.toString(e)})}get minValue(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxValue(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&k.isInteger(e.value))}get isFinite(){let e=null,r=null;for(let n of this._def.checks){if(n.kind==="finite"||n.kind==="int"||n.kind==="multipleOf")return!0;n.kind==="min"?(r===null||n.value>r)&&(r=n.value):n.kind==="max"&&(e===null||n.value<e)&&(e=n.value)}return Number.isFinite(r)&&Number.isFinite(e)}};ee.create=t=>new ee({checks:[],typeName:y.ZodNumber,coerce:t?.coerce||!1,...x(t)});var te=class t extends b{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==p.bigint)return this._getInvalidInput(e);let n,s=new w;for(let i of this._def.checks)i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:l.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:l.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="multipleOf"?e.data%i.value!==BigInt(0)&&(n=this._getOrReturnCtx(e,n),d(n,{code:l.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):k.assertNever(i);return{status:s.value,value:e.data}}_getInvalidInput(e){let r=this._getOrReturnCtx(e);return d(r,{code:l.invalid_type,expected:p.bigint,received:r.parsedType}),g}gte(e,r){return this.setLimit("min",e,!0,m.toString(r))}gt(e,r){return this.setLimit("min",e,!1,m.toString(r))}lte(e,r){return this.setLimit("max",e,!0,m.toString(r))}lt(e,r){return this.setLimit("max",e,!1,m.toString(r))}setLimit(e,r,n,s){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:r,inclusive:n,message:m.toString(s)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:m.toString(e)})}multipleOf(e,r){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(r)})}get minValue(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxValue(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}};te.create=t=>new te({checks:[],typeName:y.ZodBigInt,coerce:t?.coerce??!1,...x(t)});var re=class extends b{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==p.boolean){let n=this._getOrReturnCtx(e);return d(n,{code:l.invalid_type,expected:p.boolean,received:n.parsedType}),g}return S(e.data)}};re.create=t=>new re({typeName:y.ZodBoolean,coerce:t?.coerce||!1,...x(t)});var ne=class t extends b{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==p.date){let i=this._getOrReturnCtx(e);return d(i,{code:l.invalid_type,expected:p.date,received:i.parsedType}),g}if(Number.isNaN(e.data.getTime())){let i=this._getOrReturnCtx(e);return d(i,{code:l.invalid_date}),g}let n=new w,s;for(let i of this._def.checks)i.kind==="min"?e.data.getTime()<i.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:l.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),n.dirty()):i.kind==="max"?e.data.getTime()>i.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:l.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),n.dirty()):k.assertNever(i);return{status:n.value,value:new Date(e.data.getTime())}}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}min(e,r){return this._addCheck({kind:"min",value:e.getTime(),message:m.toString(r)})}max(e,r){return this._addCheck({kind:"max",value:e.getTime(),message:m.toString(r)})}get minDate(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e!=null?new Date(e):null}};ne.create=t=>new ne({checks:[],coerce:t?.coerce||!1,typeName:y.ZodDate,...x(t)});var ke=class extends b{_parse(e){if(this._getType(e)!==p.symbol){let n=this._getOrReturnCtx(e);return d(n,{code:l.invalid_type,expected:p.symbol,received:n.parsedType}),g}return S(e.data)}};ke.create=t=>new ke({typeName:y.ZodSymbol,...x(t)});var se=class extends b{_parse(e){if(this._getType(e)!==p.undefined){let n=this._getOrReturnCtx(e);return d(n,{code:l.invalid_type,expected:p.undefined,received:n.parsedType}),g}return S(e.data)}};se.create=t=>new se({typeName:y.ZodUndefined,...x(t)});var ie=class extends b{_parse(e){if(this._getType(e)!==p.null){let n=this._getOrReturnCtx(e);return d(n,{code:l.invalid_type,expected:p.null,received:n.parsedType}),g}return S(e.data)}};ie.create=t=>new ie({typeName:y.ZodNull,...x(t)});var Y=class extends b{constructor(){super(...arguments),this._any=!0}_parse(e){return S(e.data)}};Y.create=t=>new Y({typeName:y.ZodAny,...x(t)});var H=class extends b{constructor(){super(...arguments),this._unknown=!0}_parse(e){return S(e.data)}};H.create=t=>new H({typeName:y.ZodUnknown,...x(t)});var M=class extends b{_parse(e){let r=this._getOrReturnCtx(e);return d(r,{code:l.invalid_type,expected:p.never,received:r.parsedType}),g}};M.create=t=>new M({typeName:y.ZodNever,...x(t)});var Ee=class extends b{_parse(e){if(this._getType(e)!==p.undefined){let n=this._getOrReturnCtx(e);return d(n,{code:l.invalid_type,expected:p.void,received:n.parsedType}),g}return S(e.data)}};Ee.create=t=>new Ee({typeName:y.ZodVoid,...x(t)});var K=class t extends b{_parse(e){let{ctx:r,status:n}=this._processInputParams(e),s=this._def;if(r.parsedType!==p.array)return d(r,{code:l.invalid_type,expected:p.array,received:r.parsedType}),g;if(s.exactLength!==null){let a=r.data.length>s.exactLength.value,o=r.data.length<s.exactLength.value;(a||o)&&(d(r,{code:a?l.too_big:l.too_small,minimum:o?s.exactLength.value:void 0,maximum:a?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),n.dirty())}if(s.minLength!==null&&r.data.length<s.minLength.value&&(d(r,{code:l.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),n.dirty()),s.maxLength!==null&&r.data.length>s.maxLength.value&&(d(r,{code:l.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),n.dirty()),r.common.async)return Promise.all([...r.data].map((a,o)=>s.type._parseAsync(new N(r,a,r.path,o)))).then(a=>w.mergeArray(n,a));let i=[...r.data].map((a,o)=>s.type._parseSync(new N(r,a,r.path,o)));return w.mergeArray(n,i)}get element(){return this._def.type}min(e,r){return new t({...this._def,minLength:{value:e,message:m.toString(r)}})}max(e,r){return new t({...this._def,maxLength:{value:e,message:m.toString(r)}})}length(e,r){return new t({...this._def,exactLength:{value:e,message:m.toString(r)}})}nonempty(e){return this.min(1,e)}};K.create=(t,e)=>new K({type:t,minLength:null,maxLength:null,exactLength:null,typeName:y.ZodArray,...x(e)});function be(t){if(t instanceof C){let e={};for(let r in t.shape){let n=t.shape[r];e[r]=D.create(be(n))}return new C({...t._def,shape:()=>e})}else return t instanceof K?new K({...t._def,type:be(t.element)}):t instanceof D?D.create(be(t.unwrap())):t instanceof F?F.create(be(t.unwrap())):t instanceof j?j.create(t.items.map(e=>be(e))):t}var C=class t extends b{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape(),r=k.objectKeys(e);return this._cached={shape:e,keys:r},this._cached}_parse(e){if(this._getType(e)!==p.object){let u=this._getOrReturnCtx(e);return d(u,{code:l.invalid_type,expected:p.object,received:u.parsedType}),g}let{status:n,ctx:s}=this._processInputParams(e),{shape:i,keys:a}=this._getCached(),o=[];if(!(this._def.catchall instanceof M&&this._def.unknownKeys==="strip"))for(let u in s.data)a.includes(u)||o.push(u);let c=[];for(let u of a){let f=i[u],v=s.data[u];c.push({key:{status:"valid",value:u},value:f._parse(new N(s,v,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof M){let u=this._def.unknownKeys;if(u==="passthrough")for(let f of o)c.push({key:{status:"valid",value:f},value:{status:"valid",value:s.data[f]}});else if(u==="strict")o.length>0&&(d(s,{code:l.unrecognized_keys,keys:o}),n.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{let u=this._def.catchall;for(let f of o){let v=s.data[f];c.push({key:{status:"valid",value:f},value:u._parse(new N(s,v,s.path,f)),alwaysSet:f in s.data})}}return s.common.async?Promise.resolve().then(async()=>{let u=[];for(let f of c){let v=await f.key,_=await f.value;u.push({key:v,value:_,alwaysSet:f.alwaysSet})}return u}).then(u=>w.mergeObjectSync(n,u)):w.mergeObjectSync(n,c)}get shape(){return this._def.shape()}strict(e){return m.errToObj,new t({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(r,n)=>{let s=this._def.errorMap?.(r,n).message??n.defaultError;return r.code==="unrecognized_keys"?{message:m.errToObj(e).message??s}:{message:s}}}:{}})}strip(){return new t({...this._def,unknownKeys:"strip"})}passthrough(){return new t({...this._def,unknownKeys:"passthrough"})}extend(e){return new t({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new t({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:y.ZodObject})}setKey(e,r){return this.augment({[e]:r})}catchall(e){return new t({...this._def,catchall:e})}pick(e){let r={};for(let n of k.objectKeys(e))e[n]&&this.shape[n]&&(r[n]=this.shape[n]);return new t({...this._def,shape:()=>r})}omit(e){let r={};for(let n of k.objectKeys(this.shape))e[n]||(r[n]=this.shape[n]);return new t({...this._def,shape:()=>r})}deepPartial(){return be(this)}partial(e){let r={};for(let n of k.objectKeys(this.shape)){let s=this.shape[n];e&&!e[n]?r[n]=s:r[n]=s.optional()}return new t({...this._def,shape:()=>r})}required(e){let r={};for(let n of k.objectKeys(this.shape))if(e&&!e[n])r[n]=this.shape[n];else{let i=this.shape[n];for(;i instanceof D;)i=i._def.innerType;r[n]=i}return new t({...this._def,shape:()=>r})}keyof(){return yt(k.objectKeys(this.shape))}};C.create=(t,e)=>new C({shape:()=>t,unknownKeys:"strip",catchall:M.create(),typeName:y.ZodObject,...x(e)});C.strictCreate=(t,e)=>new C({shape:()=>t,unknownKeys:"strict",catchall:M.create(),typeName:y.ZodObject,...x(e)});C.lazycreate=(t,e)=>new C({shape:t,unknownKeys:"strip",catchall:M.create(),typeName:y.ZodObject,...x(e)});var ae=class extends b{_parse(e){let{ctx:r}=this._processInputParams(e),n=this._def.options;function s(i){for(let o of i)if(o.result.status==="valid")return o.result;for(let o of i)if(o.result.status==="dirty")return r.common.issues.push(...o.ctx.common.issues),o.result;let a=i.map(o=>new R(o.ctx.common.issues));return d(r,{code:l.invalid_union,unionErrors:a}),g}if(r.common.async)return Promise.all(n.map(async i=>{let a={...r,common:{...r.common,issues:[]},parent:null};return{result:await i._parseAsync({data:r.data,path:r.path,parent:a}),ctx:a}})).then(s);{let i,a=[];for(let c of n){let u={...r,common:{...r.common,issues:[]},parent:null},f=c._parseSync({data:r.data,path:r.path,parent:u});if(f.status==="valid")return f;f.status==="dirty"&&!i&&(i={result:f,ctx:u}),u.common.issues.length&&a.push(u.common.issues)}if(i)return r.common.issues.push(...i.ctx.common.issues),i.result;let o=a.map(c=>new R(c));return d(r,{code:l.invalid_union,unionErrors:o}),g}}get options(){return this._def.options}};ae.create=(t,e)=>new ae({options:t,typeName:y.ZodUnion,...x(e)});var V=t=>t instanceof ce?V(t.schema):t instanceof P?V(t.innerType()):t instanceof le?[t.value]:t instanceof ue?t.options:t instanceof de?k.objectValues(t.enum):t instanceof fe?V(t._def.innerType):t instanceof se?[void 0]:t instanceof ie?[null]:t instanceof D?[void 0,...V(t.unwrap())]:t instanceof F?[null,...V(t.unwrap())]:t instanceof Ce||t instanceof me?V(t.unwrap()):t instanceof pe?V(t._def.innerType):[],ze=class t extends b{_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==p.object)return d(r,{code:l.invalid_type,expected:p.object,received:r.parsedType}),g;let n=this.discriminator,s=r.data[n],i=this.optionsMap.get(s);return i?r.common.async?i._parseAsync({data:r.data,path:r.path,parent:r}):i._parseSync({data:r.data,path:r.path,parent:r}):(d(r,{code:l.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[n]}),g)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,r,n){let s=new Map;for(let i of r){let a=V(i.shape[e]);if(!a.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let o of a){if(s.has(o))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);s.set(o,i)}}return new t({typeName:y.ZodDiscriminatedUnion,discriminator:e,options:r,optionsMap:s,...x(n)})}};function Xe(t,e){let r=L(t),n=L(e);if(t===e)return{valid:!0,data:t};if(r===p.object&&n===p.object){let s=k.objectKeys(e),i=k.objectKeys(t).filter(o=>s.indexOf(o)!==-1),a={...t,...e};for(let o of i){let c=Xe(t[o],e[o]);if(!c.valid)return{valid:!1};a[o]=c.data}return{valid:!0,data:a}}else if(r===p.array&&n===p.array){if(t.length!==e.length)return{valid:!1};let s=[];for(let i=0;i<t.length;i++){let a=t[i],o=e[i],c=Xe(a,o);if(!c.valid)return{valid:!1};s.push(c.data)}return{valid:!0,data:s}}else return r===p.date&&n===p.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}var oe=class extends b{_parse(e){let{status:r,ctx:n}=this._processInputParams(e),s=(i,a)=>{if(je(i)||je(a))return g;let o=Xe(i.value,a.value);return o.valid?((Fe(i)||Fe(a))&&r.dirty(),{status:r.value,value:o.data}):(d(n,{code:l.invalid_intersection_types}),g)};return n.common.async?Promise.all([this._def.left._parseAsync({data:n.data,path:n.path,parent:n}),this._def.right._parseAsync({data:n.data,path:n.path,parent:n})]).then(([i,a])=>s(i,a)):s(this._def.left._parseSync({data:n.data,path:n.path,parent:n}),this._def.right._parseSync({data:n.data,path:n.path,parent:n}))}};oe.create=(t,e,r)=>new oe({left:t,right:e,typeName:y.ZodIntersection,...x(r)});var j=class t extends b{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.array)return d(n,{code:l.invalid_type,expected:p.array,received:n.parsedType}),g;if(n.data.length<this._def.items.length)return d(n,{code:l.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),g;!this._def.rest&&n.data.length>this._def.items.length&&(d(n,{code:l.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),r.dirty());let i=[...n.data].map((a,o)=>{let c=this._def.items[o]||this._def.rest;return c?c._parse(new N(n,a,n.path,o)):null}).filter(a=>!!a);return n.common.async?Promise.all(i).then(a=>w.mergeArray(r,a)):w.mergeArray(r,i)}get items(){return this._def.items}rest(e){return new t({...this._def,rest:e})}};j.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new j({items:t,typeName:y.ZodTuple,rest:null,...x(e)})};var Ze=class t extends b{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.object)return d(n,{code:l.invalid_type,expected:p.object,received:n.parsedType}),g;let s=[],i=this._def.keyType,a=this._def.valueType;for(let o in n.data)s.push({key:i._parse(new N(n,o,n.path,o)),value:a._parse(new N(n,n.data[o],n.path,o)),alwaysSet:o in n.data});return n.common.async?w.mergeObjectAsync(r,s):w.mergeObjectSync(r,s)}get element(){return this._def.valueType}static create(e,r,n){return r instanceof b?new t({keyType:e,valueType:r,typeName:y.ZodRecord,...x(n)}):new t({keyType:q.create(),valueType:e,typeName:y.ZodRecord,...x(r)})}},we=class extends b{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.map)return d(n,{code:l.invalid_type,expected:p.map,received:n.parsedType}),g;let s=this._def.keyType,i=this._def.valueType,a=[...n.data.entries()].map(([o,c],u)=>({key:s._parse(new N(n,o,n.path,[u,"key"])),value:i._parse(new N(n,c,n.path,[u,"value"]))}));if(n.common.async){let o=new Map;return Promise.resolve().then(async()=>{for(let c of a){let u=await c.key,f=await c.value;if(u.status==="aborted"||f.status==="aborted")return g;(u.status==="dirty"||f.status==="dirty")&&r.dirty(),o.set(u.value,f.value)}return{status:r.value,value:o}})}else{let o=new Map;for(let c of a){let u=c.key,f=c.value;if(u.status==="aborted"||f.status==="aborted")return g;(u.status==="dirty"||f.status==="dirty")&&r.dirty(),o.set(u.value,f.value)}return{status:r.value,value:o}}}};we.create=(t,e,r)=>new we({valueType:e,keyType:t,typeName:y.ZodMap,...x(r)});var Se=class t extends b{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.set)return d(n,{code:l.invalid_type,expected:p.set,received:n.parsedType}),g;let s=this._def;s.minSize!==null&&n.data.size<s.minSize.value&&(d(n,{code:l.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),r.dirty()),s.maxSize!==null&&n.data.size>s.maxSize.value&&(d(n,{code:l.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),r.dirty());let i=this._def.valueType;function a(c){let u=new Set;for(let f of c){if(f.status==="aborted")return g;f.status==="dirty"&&r.dirty(),u.add(f.value)}return{status:r.value,value:u}}let o=[...n.data.values()].map((c,u)=>i._parse(new N(n,c,n.path,u)));return n.common.async?Promise.all(o).then(c=>a(c)):a(o)}min(e,r){return new t({...this._def,minSize:{value:e,message:m.toString(r)}})}max(e,r){return new t({...this._def,maxSize:{value:e,message:m.toString(r)}})}size(e,r){return this.min(e,r).max(e,r)}nonempty(e){return this.min(1,e)}};Se.create=(t,e)=>new Se({valueType:t,minSize:null,maxSize:null,typeName:y.ZodSet,...x(e)});var Be=class t extends b{constructor(){super(...arguments),this.validate=this.implement}_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==p.function)return d(r,{code:l.invalid_type,expected:p.function,received:r.parsedType}),g;function n(o,c){return Re({data:o,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,ve(),U].filter(u=>!!u),issueData:{code:l.invalid_arguments,argumentsError:c}})}function s(o,c){return Re({data:o,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,ve(),U].filter(u=>!!u),issueData:{code:l.invalid_return_type,returnTypeError:c}})}let i={errorMap:r.common.contextualErrorMap},a=r.data;if(this._def.returns instanceof J){let o=this;return S(async function(...c){let u=new R([]),f=await o._def.args.parseAsync(c,i).catch(E=>{throw u.addIssue(n(c,E)),u}),v=await Reflect.apply(a,this,f);return await o._def.returns._def.type.parseAsync(v,i).catch(E=>{throw u.addIssue(s(v,E)),u})})}else{let o=this;return S(function(...c){let u=o._def.args.safeParse(c,i);if(!u.success)throw new R([n(c,u.error)]);let f=Reflect.apply(a,this,u.data),v=o._def.returns.safeParse(f,i);if(!v.success)throw new R([s(f,v.error)]);return v.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new t({...this._def,args:j.create(e).rest(H.create())})}returns(e){return new t({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,r,n){return new t({args:e||j.create([]).rest(H.create()),returns:r||H.create(),typeName:y.ZodFunction,...x(n)})}},ce=class extends b{get schema(){return this._def.getter()}_parse(e){let{ctx:r}=this._processInputParams(e);return this._def.getter()._parse({data:r.data,path:r.path,parent:r})}};ce.create=(t,e)=>new ce({getter:t,typeName:y.ZodLazy,...x(e)});var le=class extends b{_parse(e){if(e.data!==this._def.value){let r=this._getOrReturnCtx(e);return d(r,{received:r.data,code:l.invalid_literal,expected:this._def.value}),g}return{status:"valid",value:e.data}}get value(){return this._def.value}};le.create=(t,e)=>new le({value:t,typeName:y.ZodLiteral,...x(e)});function yt(t,e){return new ue({values:t,typeName:y.ZodEnum,...x(e)})}var ue=class t extends b{_parse(e){if(typeof e.data!="string"){let r=this._getOrReturnCtx(e),n=this._def.values;return d(r,{expected:k.joinValues(n),received:r.parsedType,code:l.invalid_type}),g}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let r=this._getOrReturnCtx(e),n=this._def.values;return d(r,{received:r.data,code:l.invalid_enum_value,options:n}),g}return S(e.data)}get options(){return this._def.values}get enum(){let e={};for(let r of this._def.values)e[r]=r;return e}get Values(){let e={};for(let r of this._def.values)e[r]=r;return e}get Enum(){let e={};for(let r of this._def.values)e[r]=r;return e}extract(e,r=this._def){return t.create(e,{...this._def,...r})}exclude(e,r=this._def){return t.create(this.options.filter(n=>!e.includes(n)),{...this._def,...r})}};ue.create=yt;var de=class extends b{_parse(e){let r=k.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(e);if(n.parsedType!==p.string&&n.parsedType!==p.number){let s=k.objectValues(r);return d(n,{expected:k.joinValues(s),received:n.parsedType,code:l.invalid_type}),g}if(this._cache||(this._cache=new Set(k.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let s=k.objectValues(r);return d(n,{received:n.data,code:l.invalid_enum_value,options:s}),g}return S(e.data)}get enum(){return this._def.values}};de.create=(t,e)=>new de({values:t,typeName:y.ZodNativeEnum,...x(e)});var J=class extends b{unwrap(){return this._def.type}_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==p.promise&&r.common.async===!1)return d(r,{code:l.invalid_type,expected:p.promise,received:r.parsedType}),g;let n=r.parsedType===p.promise?r.data:Promise.resolve(r.data);return S(n.then(s=>this._def.type.parseAsync(s,{path:r.path,errorMap:r.common.contextualErrorMap})))}};J.create=(t,e)=>new J({type:t,typeName:y.ZodPromise,...x(e)});var P=class extends b{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===y.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:r,ctx:n}=this._processInputParams(e),s=this._def.effect||null,i={addIssue:a=>{d(n,a),a.fatal?r.abort():r.dirty()},get path(){return n.path}};if(i.addIssue=i.addIssue.bind(i),s.type==="preprocess"){let a=s.transform(n.data,i);if(n.common.async)return Promise.resolve(a).then(async o=>{if(r.value==="aborted")return g;let c=await this._def.schema._parseAsync({data:o,path:n.path,parent:n});return c.status==="aborted"?g:c.status==="dirty"?Q(c.value):r.value==="dirty"?Q(c.value):c});{if(r.value==="aborted")return g;let o=this._def.schema._parseSync({data:a,path:n.path,parent:n});return o.status==="aborted"?g:o.status==="dirty"?Q(o.value):r.value==="dirty"?Q(o.value):o}}if(s.type==="refinement"){let a=o=>{let c=s.refinement(o,i);if(n.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(n.common.async===!1){let o=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return o.status==="aborted"?g:(o.status==="dirty"&&r.dirty(),a(o.value),{status:r.value,value:o.value})}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(o=>o.status==="aborted"?g:(o.status==="dirty"&&r.dirty(),a(o.value).then(()=>({status:r.value,value:o.value}))))}if(s.type==="transform")if(n.common.async===!1){let a=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!G(a))return g;let o=s.transform(a.value,i);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:o}}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(a=>G(a)?Promise.resolve(s.transform(a.value,i)).then(o=>({status:r.value,value:o})):g);k.assertNever(s)}};P.create=(t,e,r)=>new P({schema:t,typeName:y.ZodEffects,effect:e,...x(r)});P.createWithPreprocess=(t,e,r)=>new P({schema:e,effect:{type:"preprocess",transform:t},typeName:y.ZodEffects,...x(r)});var D=class extends b{_parse(e){return this._getType(e)===p.undefined?S(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};D.create=(t,e)=>new D({innerType:t,typeName:y.ZodOptional,...x(e)});var F=class extends b{_parse(e){return this._getType(e)===p.null?S(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};F.create=(t,e)=>new F({innerType:t,typeName:y.ZodNullable,...x(e)});var fe=class extends b{_parse(e){let{ctx:r}=this._processInputParams(e),n=r.data;return r.parsedType===p.undefined&&(n=this._def.defaultValue()),this._def.innerType._parse({data:n,path:r.path,parent:r})}removeDefault(){return this._def.innerType}};fe.create=(t,e)=>new fe({innerType:t,typeName:y.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...x(e)});var pe=class extends b{_parse(e){let{ctx:r}=this._processInputParams(e),n={...r,common:{...r.common,issues:[]}},s=this._def.innerType._parse({data:n.data,path:n.path,parent:{...n}});return xe(s)?s.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new R(n.common.issues)},input:n.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new R(n.common.issues)},input:n.data})}}removeCatch(){return this._def.innerType}};pe.create=(t,e)=>new pe({innerType:t,typeName:y.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...x(e)});var Te=class extends b{_parse(e){if(this._getType(e)!==p.nan){let n=this._getOrReturnCtx(e);return d(n,{code:l.invalid_type,expected:p.nan,received:n.parsedType}),g}return{status:"valid",value:e.data}}};Te.create=t=>new Te({typeName:y.ZodNaN,...x(t)});var en=Symbol("zod_brand"),Ce=class extends b{_parse(e){let{ctx:r}=this._processInputParams(e),n=r.data;return this._def.type._parse({data:n,path:r.path,parent:r})}unwrap(){return this._def.type}},Ie=class t extends b{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.common.async)return(async()=>{let i=await this._def.in._parseAsync({data:n.data,path:n.path,parent:n});return i.status==="aborted"?g:i.status==="dirty"?(r.dirty(),Q(i.value)):this._def.out._parseAsync({data:i.value,path:n.path,parent:n})})();{let s=this._def.in._parseSync({data:n.data,path:n.path,parent:n});return s.status==="aborted"?g:s.status==="dirty"?(r.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:n.path,parent:n})}}static create(e,r){return new t({in:e,out:r,typeName:y.ZodPipeline})}},me=class extends b{_parse(e){let r=this._def.innerType._parse(e),n=s=>(G(s)&&(s.value=Object.freeze(s.value)),s);return xe(r)?r.then(s=>n(s)):n(r)}unwrap(){return this._def.innerType}};me.create=(t,e)=>new me({innerType:t,typeName:y.ZodReadonly,...x(e)});function pt(t,e){let r=typeof t=="function"?t(e):typeof t=="string"?{message:t}:t;return typeof r=="string"?{message:r}:r}function _t(t,e={},r){return t?Y.create().superRefine((n,s)=>{let i=t(n);if(i instanceof Promise)return i.then(a=>{if(!a){let o=pt(e,n),c=o.fatal??r??!0;s.addIssue({code:"custom",...o,fatal:c})}});if(!i){let a=pt(e,n),o=a.fatal??r??!0;s.addIssue({code:"custom",...a,fatal:o})}}):Y.create()}var tn={object:C.lazycreate},y;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(y||(y={}));var rn=(t,e={message:`Input not instance of ${t.name}`})=>_t(r=>r instanceof t,e),vt=q.create,xt=ee.create,nn=Te.create,sn=te.create,bt=re.create,an=ne.create,on=ke.create,cn=se.create,ln=ie.create,un=Y.create,dn=H.create,fn=M.create,pn=Ee.create,mn=K.create,hn=C.create,gn=C.strictCreate,yn=ae.create,_n=ze.create,vn=oe.create,xn=j.create,bn=Ze.create,kn=we.create,En=Se.create,wn=Be.create,Sn=ce.create,Tn=le.create,An=ue.create,Rn=de.create,Cn=J.create,In=P.create,On=D.create,Dn=F.create,Nn=P.createWithPreprocess,Pn=Ie.create,$n=()=>vt().optional(),Mn=()=>xt().optional(),Ln=()=>bt().optional(),jn={string:(t=>q.create({...t,coerce:!0})),number:(t=>ee.create({...t,coerce:!0})),boolean:(t=>re.create({...t,coerce:!0})),bigint:(t=>te.create({...t,coerce:!0})),date:(t=>ne.create({...t,coerce:!0}))};var Fn=g;var Ue=h.object({slug:h.string().min(1).max(64),description:h.string().max(255).optional(),match_command:h.string().min(1),priority:h.number().int().default(50),strip_ansi:h.boolean().default(!1),strip_lines_matching:h.array(h.string()).default([]),truncate_lines_at:h.number().int().positive().max(1e4).optional(),max_lines:h.number().int().positive().max(1e5).optional(),transform:h.string().max(64).optional(),on_empty:h.string().max(255).optional()});var Vn=Bn(Un(import.meta.url)),kt=wt(Vn,"..","..","filters"),X=null,Et=!1;function Hn(){return process.env.TOKMIZER_DEV==="1"||process.env.TOKMIZER_DEV==="true"}async function St(){if(X)return X;if(!Hn())return!Et&&process.env.TOKMIZER_DEBUG==="1"&&(process.stderr.write(`tokmizer: disk loader disabled (set TOKMIZER_DEV=1 to re-enable for local dev).
4
+ `),Et=!0),X=new Map,X;let t=new Map,e,r;try{e=(await import("smol-toml")).parse,r=(await zn(kt)).filter(n=>n.endsWith(".toml"))}catch{return X=t,X}for(let n of r){let s=await Zn(wt(kt,n),"utf8"),a=e(s).filters;if(a)for(let[o,c]of Object.entries(a)){let u=Ue.parse({slug:o,...c});t.set(o,{...u,matchRegex:new RegExp(u.match_command)})}}return X=t,X}import{createHash as Kn}from"node:crypto";var Wn=h.enum(["normal","compact","minimal"]),Gn=h.enum(["off","light","balanced","max"]),Qe=h.object({enabled:h.boolean().default(!0),telemetryOptIn:h.boolean().default(!0),outputVerbosity:Wn.default("compact"),reducer:Gn.default("off"),filters:h.object({enableAll:h.boolean().default(!0),disabled:h.array(h.string().max(64)).max(100).default([])}).default({enableAll:!0,disabled:[]})}),qn=["git","grep","find","ls","ps","cat","head","tail","df","du","tree","wc","read-tool","grep-tool","glob-tool","npm","docker","kubectl","curl","cargo","go-test","gh","aws","dotnet","prisma","tsc","next","jest","vitest","pytest","pip","rspec"],Yn=/^[0-9a-f]{16}$/,Tt=new Map;function z(t){let e=Tt.get(t);return e||(e=Kn("sha256").update(`tkr:${t}`).digest("hex").slice(0,16),Tt.set(t,e)),e}var At=null;function Ve(t,e=!1){return e||!t||t.length===0?(At??=new Set(qn.map(z)),new Set(At)):new Set(t.map(r=>Yn.test(r)?r:z(r)))}var Oe=new Map,Jn=256,Rt=new WeakMap;function Xn(t){if(!t)return"*";let e=Rt.get(t);return e===void 0&&(e=[...t].join(","),Rt.set(t,e)),e}function Ct(t,e,r){let n=`${t}::${Xn(r)}`,s=Oe.get(n);if(s!==void 0)return s;let i=null;for(let a of e)r&&!r.has(z(a.slug))||a.matchRegex.test(t)&&(!i||a.priority>i.priority)&&(i=a);if(Oe.size>=Jn){let a=Oe.keys().next().value;a&&Oe.delete(a)}return Oe.set(n,i),i}var Qn=/\x1b\[[0-9;?]*[ -/]*[@-~]/g,es=/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g;function It(t){return t.replace(Qn,"").replace(es,"")}function Ot(t,e){return e.length===0?t:t.filter(r=>!e.some(n=>n.test(r)))}function Dt(t,e){return t.map(r=>r.length<=e?r:`${r.slice(0,e)}\u2026`)}function Nt(t,e){if(t.length<=e)return t;let r=t.length-e;return[...t.slice(0,e),`\u2026 (${r} more lines omitted)`]}var ts=/^(\s*)(?:export\s+)?(?:async\s+)?(?:function|interface|type|const|let|var|def|fn|impl|trait|struct|enum)\s+[\w$]+/,rs=/\{\s*$/;var ns=/^\s*(?:(?:public|private|protected|static|async|get|set|readonly|override)\s+)*([\w$]+)\s*\(([^)]*)\)\s*(?::\s*[^{]+)?\{\s*$/,ss=new Set(["if","for","while","switch","catch","do","with","return","else","function","await","yield"]);function is(t){let e=ns.exec(t);return!e||ss.has(e[1])?!1:!/=>|\bfunction\b/.test(e[2])}var as=/^\s*(?:if|for|while|switch|try|do)\b[^{}]*\{\s*$/;function os(t,e){let r=0,n=null,s=0;for(;s<t.length;){let i=t[s];if(e.inBlockComment){if(i==="*"&&t[s+1]==="/"){e.inBlockComment=!1,s+=2;continue}s+=1;continue}if(e.inTemplate){if(i==="\\"){s+=2;continue}i==="`"&&(e.inTemplate=!1),s+=1;continue}if(n){if(i==="\\"){s+=2;continue}i===n&&(n=null),s+=1;continue}if(i==="/"&&t[s+1]==="/")break;if(i==="/"&&t[s+1]==="*"){e.inBlockComment=!0,s+=2;continue}if(i==="`"){e.inTemplate=!0,s+=1;continue}if(i==="'"||i==='"'){n=i,s+=1;continue}i==="{"||i==="("||i==="["?r+=1:(i==="}"||i===")"||i==="]")&&(r-=1),s+=1}return r}function He(t){let e=[],r=0;for(;r<t.length;){let n=t[r];if(ts.test(n)&&rs.test(n)||is(n)||as.test(n)){let s={inBlockComment:!1,inTemplate:!1},i=0,a=r,o=!1;for(;a<t.length&&a-r<200;)if(i+=os(t[a],s),a+=1,i<=0&&!s.inTemplate&&!s.inBlockComment){o=!0;break}if(o){e.push(`${n.replace(/\{\s*$/,"")}{ \u2026 }`),r=a;continue}}e.push(n),r+=1}return e}var cs=/\b(?:function|class|interface|import\s+|export\s+|def\s+|fn\s+|impl\s+|package\s+|namespace\s+|using\s+|#include|=>\s*\{|=\s*function)/;function Pt(t){let e=t.slice(0,4096);return!(!cs.test(e)||e.split(`
5
+ `).length<6)}var ls=/\b(?:DEBUG|TRACE|INFO|VERBOSE)\b/;function $t(t){return t.filter(e=>!ls.test(e))}function Mt(t){if(t.length===0)return t;let e=[],r=1,n=t[0];for(let s=1;s<t.length;s++){if(t[s]===n){r+=1;continue}e.push(r>1?`${n} \xD7${r}`:n),n=t[s],r=1}return e.push(r>1?`${n} \xD7${r}`:n),e}function Lt(t){let e=[],r=0;for(let n of t){if(n.trim()===""){r+=1;continue}r>0&&e.push(""),r=0,e.push(n)}return e}var jt=new Map;function Z(t,e){jt.set(t,e)}function Ft(t){return jt.get(t)}var us=/^[dbclps\-][rwxsStT\-]{9}[@.+]?(?:\s|$)/,ds=/^[./~][^\s]*:$/,et=1e3;function fs(t){if(t<1024)return String(t);let e=["K","M","G","T"],r=t/1024,n=0;for(;r>=1024&&n<e.length-1;)r/=1024,n+=1;return`${r.toFixed(1)}${e[n]}`}function ps(t){if(!us.test(t))return null;let e=t.split(/\s+/);if(e.length<9)return null;let r=Number(e[4]);if(!Number.isFinite(r))return null;let n=e.slice(8).join(" ").trim();if(n===""||n==="."||n==="..")return null;let s=e[0].charCodeAt(0)===100;return{name:n,size:r,isDir:s}}function ms(t){if(t.length<3)return null;let e=new Map;for(let s of t){let i=s.name.lastIndexOf(".");if(i<=0)continue;let a=s.name.slice(i);e.set(a,(e.get(a)??0)+1)}let r=null,n=0;for(let[s,i]of e)i>n&&(n=i,r=s);return r&&n>=Math.ceil(t.length/2)?`${n} ${r}`:null}function hs(t){let e=[],r=[],n=!1;for(let _ of t){if(/^total\s+\d+/.test(_))continue;if(ds.test(_.trim()))return t;let E=ps(_);E&&(n=!0,(E.isDir?e:r).push(E))}if(!n)return t;let s=(_,E)=>_.name.localeCompare(E.name);e.sort(s),r.sort((_,E)=>E.size-_.size||s(_,E));let i=[...e,...r],a=Math.min(40,Math.max(0,...i.map(_=>_.isDir?_.name.length+1:_.name.length))),o=[];for(let _ of i){let E=_.isDir?`${_.name}/`:_.name,O=_.isDir?"":fs(_.size);o.push(O?`${E.padEnd(a)} ${O}`:E)}if(o.length>et){let _=o.length-et;o=[...o.slice(0,et),`\u2026 ${_} more lines omitted`]}let c=r.length===1?"file":"files",u=e.length===1?"dir":"dirs",f=ms(r),v=`${r.length} ${c}, ${e.length} ${u}`+(f?` (${f})`:"");return o.push(v),o}Z("smart-ls",hs);Z("smart-read",t=>He(t));var tt=1e3;function gs(t){let e=t.filter(f=>f.trim()!=="");if(e.length===0||e.filter(f=>!/\s/.test(f.trim())).length<e.length*.6)return t;let n=new Map,s=[],i=0;for(let f of e){let v=f.trim();if(v.startsWith("find:")){s.push(v);continue}let _=v.replace(/^\.\//,"").replace(/\/+$/,""),E=_.lastIndexOf("/"),O=E>=0?_.slice(0,E):"",B=E>=0?_.slice(E+1):_;if(!B)continue;let $=n.get(O)??[];$.push(/\s/.test(B)?`"${B}"`:B),n.set(O,$),i+=1}if(i===0)return t;let a=new Set([""]);for(let f of n.keys()){if(f==="")continue;let v=f.split("/");for(let _=1;_<=v.length;_+=1)a.add(v.slice(0,_).join("/"))}let o=[...a].sort(),c=o.filter(f=>f!=="").length,u=[`${i}F ${c}D:`,""];for(let f of o){let v=f===""?0:f.split("/").length,_=f===""?".":f.slice(f.lastIndexOf("/")+1),E=n.get(f)??[],O=E.length?` ${E.join(" ")}`:"";u.push(`${" ".repeat(v)}${_}/${O}`)}if(u.push(...s),u.length>tt){let f=u.length-tt;return[...u.slice(0,tt),`\u2026 ${f} more lines omitted`]}return u}Z("smart-find",gs);var ys=/^[\s=]+$/,_s=/^\s*=+\s+(.*?)\s+=+\s*$/;Z("strip-banners",t=>{let e=[];for(let r of t){if(ys.test(r))continue;let n=_s.exec(r);e.push(n?n[1]:r)}return e});function vs(t){let e=[],r=0,n=0;for(;n<t.length;){let s=t[n].replace(/\s+$/,"");if(s===""){r+=1,n+=1,r<=1&&e.push("");continue}r=0;let i=1;for(;n+i<t.length&&t[n+i].replace(/\s+$/,"")===s;)i+=1;if(i>=3)e.push(s),e.push(` \u2026 (repeated ${i}x)`);else for(let a=0;a<i;a++)e.push(s);n+=i}for(;e.length>0&&e[e.length-1]==="";)e.pop();return e}Z("squeeze-output",vs);var zt=new WeakMap;function xs(t){let e=zt.get(t);if(e)return e;let r=t.strip_lines_matching.map(s=>new RegExp(s)),n={def:t,stripRegexes:r};return zt.set(t,n),n}function Zt(t,e,r={}){let n=xs(e),s=t;e.strip_ansi&&(s=It(s));let i=s.split(`
6
+ `);n.stripRegexes.length&&(i=Ot(i,n.stripRegexes));let a=r.verbosity??"normal";if(a!=="normal"&&(i=Mt(i),i=Lt(i)),a==="minimal"&&(i=$t(i)),(r.smartCode||r.smartCode===void 0&&a!=="normal"&&Pt(s))&&(i=He(i)),e.transform){let c=Ft(e.transform);c&&(i=c(i))}e.truncate_lines_at&&(i=Dt(i,e.truncate_lines_at)),e.max_lines&&(i=Nt(i,e.max_lines));let o=i.join(`
7
+ `);return o.trim().length===0&&e.on_empty&&(o=e.on_empty),o}var bs=[/\bERROR\b/,/\bFAIL\b/,/\bFAILED\b/,/\bFATAL\b/,/^Traceback /m,/^Error: /m,/^\s+at .*\(.*:\d+:\d+\)/m,/panic:/,/SyntaxError:/,/TypeError:/,/ReferenceError:/,/thread '.*' panicked/];function Bt(t){if(!t)return!1;let e=t.length<=262144*2?[t]:[t.slice(0,262144),t.slice(-262144)];for(let r of bs)for(let n of e)if(r.test(n))return!0;return!1}var Ut=null;function rt(t){Ut=t}async function ks(t,e){let r=await St();return Ct(t,r.values(),e)}async function Vt(t,e,r,n={}){let s=Buffer.byteLength(e,"utf8"),{exitCode:i,...a}=n;if(i!=null?i!==0:Bt(e))return{output:e,filterId:null,rawBytes:s,filteredBytes:s,debugBypass:!0};let u=await(Ut??ks)(t,r);if(!u)return{output:e,filterId:null,rawBytes:s,filteredBytes:s,debugBypass:!1};let f=Zt(e,u,a);return{output:f,filterId:u.slug,rawBytes:s,filteredBytes:Buffer.byteLength(f,"utf8"),debugBypass:!1}}import{join as ws}from"node:path";import{mkdir as so,readFile as Ss,writeFile as io,unlink as ao,rename as oo}from"node:fs/promises";import Es from"node:os";import{join as Ht}from"node:path";function T(){return process.env.TOKMIZER_HOME||Ht(Es.homedir(),".tokmizer")}function De(){return Ht(T(),"install-id")}var Ts="state.json",lo={lastSettingsRevision:0,timeZone:Kt(),bonusActive:!1};function Kt(){try{let t=Intl.DateTimeFormat().resolvedOptions().timeZone;return t&&t.length>0?t:"Etc/UTC"}catch{return"Etc/UTC"}}function As(t){return t?.dir??T()}async function nt(t){let e=As(t);try{let r=await Ss(ws(e,Ts),"utf8"),n=JSON.parse(r);return{...n,lastSettingsRevision:n.lastSettingsRevision??0,timeZone:n.timeZone??Kt(),bonusActive:n.bonusActive??!1,...n.bonusResetAt!==void 0?{bonusResetAt:n.bonusResetAt}:{}}}catch{return null}}function Rs(){let t=Number(process.env.TOKMIZER_OFFLINE_GRACE_MS);return Number.isFinite(t)&&t>0?t:6048e5}function st(t,e=Date.now()){let r=t.lastHeartbeatOkAt;if(typeof r=="number"&&e-r>Rs())return!0;if(t.subEndsAt){let n=Date.parse(t.subEndsAt);if(Number.isFinite(n)&&e>n)return!0}return!1}function Wt(t,e=Date.now()){return st(t,e)?"free":t.plan}import{readFile as Cs,writeFile as mo,mkdir as ho,chmod as go}from"node:fs/promises";import{join as Is}from"node:path";var Os="settings-cache.json",Gt=Qe.parse({});async function qt(){try{let t=await Cs(Is(T(),Os),"utf8"),e=JSON.parse(t);return Qe.parse({...Gt,...e})}catch{return Gt}}var Ds=[[/(authorization\s*:\s*)([A-Za-z][A-Za-z0-9._-]*)\s+[^\s'"]+/gi,"$1$2 [REDACTED]"],[/(authorization\s*:\s*)[A-Za-z0-9._\-+/=]{8,}/gi,"$1[REDACTED]"],[/(bearer\s+)[A-Za-z0-9._\-+/=]{8,}/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-b|--cookie)[=\s]+['"]?)[^\s'";=]+=[^\s'";]+(?:\s*;\s*[^\s'";=]+=[^\s'";]+)*/gi,"$1[REDACTED]"],[/((?:^|[\s'"])(?:Set-)?Cookie\s*:\s*)[^\s'";=]+=[^\s'";]+(?:\s*;\s*[^\s'";=]+=[^\s'";]+)*/gi,"$1[REDACTED]"],[/(--?(?:password|passwd|passphrase|apipass|pass|pwd|token|api[-_]?key|secret|bearer|cookie|jwt)(?:-[a-z0-9]+)*[=\s]+)\S+/gi,"$1[REDACTED]"],[/((?:^|\s)-b[=\s]?['"]?)[^\s'"=]+=[^\s'"]+/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-u[=\s]?|(?:--user|-a)[=\s])['"]?[^\s:/'"]*:)(\/[^/\s'"][^\s'"]*|[^\s/'"0-9][^\s'"]*|[0-9][^\s'"]*[^\s'"0-9][^\s'"]*)/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-u[=\s]?|(?:--user|-a)[=\s])['"]?[^\s:/'"]*[^\s:/'"0-9][^\s:/'"]*:)(?:\/[^/\s'"]|[^\s/'"])[^\s'"]*/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-u[=\s]?|(?:--user|-a)[=\s])['"]?:)(?:\/[^/\s'"]|[^\s/'"])[^\s'"]*/gi,"$1[REDACTED]"],[/((?:[A-Za-z0-9]+-)*(?:X-Api-Key|Private-Token|[A-Za-z0-9]+-(?:Token|Key|Auth|Secret))\s*:\s*)[^\s'"]+/gi,"$1[REDACTED]"],[/((?:^|[\s'"])(?:Set-)?Cookie\s*:\s*)[^\s'"]+/gi,"$1[REDACTED]"],[/(-i\s+)(\/[^\s]+|~\/[^\s]+|[A-Z]:\\[^\s]+)/g,"$1[REDACTED]"],[/([a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^:/\s@]*:)[^\s]+(@[^@/\s]+)/g,"$1[REDACTED]$2"],[/(AWS_(?:ACCESS_KEY_ID|SECRET_ACCESS_KEY|SESSION_TOKEN)\s*=\s*)\S+/g,"$1[REDACTED]"],[/(GOOGLE_APPLICATION_CREDENTIALS\s*=\s*)\S+/g,"$1[REDACTED]"],[/(AZURE_(?:CLIENT_SECRET|TENANT_ID|CLIENT_ID)\s*=\s*)\S+/g,"$1[REDACTED]"],[/(sk-(?:proj-)?[A-Za-z0-9_-]{20,})/g,"sk-[REDACTED]"],[/\b(OPENAI_API_KEY\s*=\s*)\S+/g,"$1[REDACTED]"],[/\b(ANTHROPIC_API_KEY\s*=\s*)\S+/g,"$1[REDACTED]"],[/(sk-ant-[A-Za-z0-9_-]{20,})/g,"sk-ant-[REDACTED]"],[/\b(GH(?:_|ITHUB_)?TOKEN\s*=\s*)\S+/g,"$1[REDACTED]"],[/\b(GITLAB_TOKEN\s*=\s*)\S+/g,"$1[REDACTED]"],[/\b(SLACK_(?:BOT_)?TOKEN\s*=\s*)\S+/g,"$1[REDACTED]"],[/(xox[bpsoa]-[A-Za-z0-9-]{10,})/g,"xox[REDACTED]"],[/(xapp-[A-Za-z0-9-]{10,})/g,"[REDACTED]"],[/(sk_(?:test|live)_[A-Za-z0-9]{16,})/g,"sk_[REDACTED]"],[/(gh[a-z])_[A-Za-z0-9]{20,}/g,"$1_[REDACTED]"],[/(github_pat)_[A-Za-z0-9_]{20,}/g,"$1_[REDACTED]"],[/(gl(?:pat|rt|soat|imt|dt|ft|agent|oas|cbt|ptt))-[A-Za-z0-9_-]{16,}/g,"$1-[REDACTED]"],[/(npm_[A-Za-z0-9_-]{20,})/g,"npm_[REDACTED]"],[/(?:AKIA|ASIA|AGPA|AIDA|AROA|ANPA)[0-9A-Z]{16,}/g,"[REDACTED_AWS_KEY]"],[/AIza[A-Za-z0-9_-]{35}/g,"[REDACTED_GOOGLE_KEY]"],[/hv[sb]\.[A-Za-z0-9_-]{20,}/g,"[REDACTED_VAULT_TOKEN]"],[/dop_v1_[A-Za-z0-9]{40,}/g,"[REDACTED]"],[/dckr_pat_[A-Za-z0-9_-]{20,}/g,"[REDACTED]"],[/pypi-[A-Za-z0-9_-]{16,}/g,"[REDACTED]"],[/rk_(?:live|test)_[A-Za-z0-9]{16,}/g,"[REDACTED]"],[/whsec_[A-Za-z0-9]{16,}/g,"[REDACTED]"],[/SG\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}/g,"[REDACTED]"],[/(eyJ[A-Za-z0-9_-]{6,}(?:\.[A-Za-z0-9_-]{4,}){1,2})/g,"[REDACTED_JWT]"],[/-----BEGIN [A-Z ]*PRIVATE KEY-----(?:[\s\S]*?-----END[^\n]*-----|\r?\n[A-Za-z0-9+/=][A-Za-z0-9+/=\r\n]*)?/g,"[REDACTED_PEM]"],[/\b((?:--?)?[A-Za-z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|PASS|APIKEY|KEY|CRED|CREDS|CREDENTIAL|CREDENTIALS|AUTH|_PWD)[A-Za-z0-9_]*['"]?\s*=\s*)(?:"[^"]*"|'[^']*'|[^"'\s]\S*)/gi,"$1[REDACTED]"],[/\b([A-Za-z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|PASS|APIKEY|KEY|CRED|CREDS|CREDENTIAL|CREDENTIALS|_PWD)[A-Za-z0-9_]*['"]?\s*:\s*)(?:"[^"]*"|'[^']*'|[^\s'",}]+)/gi,"$1[REDACTED]"],[/((?:^|[\s'"{,])['"]?(?:[A-Za-z0-9_]+_)?auth['"]?\s*:\s*)(?:"[^"]*"|'[^']*'|[^\s'",}]+)/gi,"$1[REDACTED]"],[/(\bpwd\s*[=:]\s*)(?:"[^"]*"|'[^']*'|[^/~\s][^\s;'"]*)/gi,"$1[REDACTED]"],[/([=:]\s*["']?)[A-Za-z0-9_\-+/=]{40,}/g,"$1[REDACTED]"]];function Ne(t){let e=t;for(let[r,n]of Ds)e=e.replace(r,n);return e}import{join as Qt}from"node:path";import{appendFileSync as Fs,chmodSync as zs,existsSync as Zs,mkdirSync as Bs,readFileSync as Fo,renameSync as zo,rmdirSync as Zo,statSync as Us,unlinkSync as Bo,writeFileSync as Uo}from"node:fs";import{createHash as Eo,randomUUID as Ns}from"node:crypto";import{readFile as Yt,writeFile as Jt,mkdir as Ps}from"node:fs/promises";async function Xt(){try{let r=(await Yt(De(),"utf8")).trim();if(/^[0-9a-f-]{36}$/i.test(r))return r}catch{}await Ps(T(),{recursive:!0});let t=Ns();try{return await Jt(De(),t,{mode:384,flag:"wx"}),t}catch{try{let e=(await Yt(De(),"utf8")).trim();if(/^[0-9a-f-]{36}$/i.test(e))return e}catch{}return await Jt(De(),t,{mode:384}),t}}import{createRequire as $s}from"node:module";var Ms=$s(import.meta.url);function Ls(){for(let t of["../package.json","../../package.json"])try{let e=Ms(t).version;if(typeof e=="string"&&e)return e}catch{}return"0.0.0"}var js=Ls();var No=300*1e3;var Vs=512*1024;function er(){return Qt(T(),"spool")}function Hs(t){return Qt(er(),`${t}.jsonl`)}function Ke(t,e){try{Bs(er(),{recursive:!0,mode:448});let r=Hs(t);if(Zs(r)&&Us(r).size>=Vs)return;Fs(r,JSON.stringify(e)+`
8
+ `,{mode:384}),zs(r,384)}catch{return}}var Ws=/^[a-z0-9][a-z0-9._-]*$/i,Gs=/^[a-z][a-z-]+$/,qs=/^[A-Za-z_][A-Za-z0-9_]*=/,Ys=new Set(["gh","glab","gup","hub","gist"]),Js=/^(gh[a-z]_|github_pat_|gl(?:pat|rt|soat|imt|dt|ft|agent|oas)-|npm_|xox|sk-|sk_|eyj|a(?:kia|sia|gpa|ida|roa|npa)|aiza|hv[sb]\.)/i,Xs=24,Qs=new Set(["docker","podman","npm","pnpm","yarn","npx","bun","deno","cargo","rustup","go","pip","pip3","uv","poetry","brew","apt","apt-get","dnf","yum","pacman","kubectl","helm","terraform","aws","gcloud","az","systemctl","composer","bundle","gem","dotnet","prisma","tkr","rtk","token"]);function tr(t){let e=t.toLowerCase();return e.startsWith("git")||Ys.has(e)}function it(t){let e=t.trim().split(/\s+/).filter(o=>o.length>0),r=0;for(;r<e.length&&qs.test(e[r]??"");)r+=1;let n=e[r];if(!n||!Ws.test(n)||n.length>Xs||tr(n)||Js.test(n)||Ne(n)!==n)return"";let s=e[r+1];return s&&tr(s)?"":(s&&Qs.has(n.toLowerCase())&&Gs.test(s)?`${n} ${s}`:n).slice(0,64)}async function rr(t){if(!t.telemetryOptIn)return;let e=it(t.cmd),r=e&&Ne(e)===e?e:"other";Ke("telemetry",{cmd:r,tokensSaved:Math.max(0,Math.round(t.tokensSaved)),optimized:t.optimized})}async function nr(t){if(t.plan!=="pro")return;let e=it(t.cmd);!e||Ne(e)!==e||Ke("learn",{cmd:e,filterId:t.filterId==null?null:z(t.filterId),rawBytes:t.rawBytes,filteredBytes:t.filteredBytes})}import{appendFileSync as ei,chmodSync as ti,mkdirSync as ri}from"node:fs";import{join as ni}from"node:path";var si="stats.jsonl";function ii(){return ni(T(),si)}function at(t,e,r=ii()){if(t<=0||e<0||e>t)return;let n=`{"t":${Math.floor(Date.now()/1e3)},"r":${t},"f":${e}}
9
+ `;try{ri(T(),{recursive:!0,mode:448}),ei(r,n,{mode:384}),ti(r,384)}catch{return}}function sr(t,e,r){let n=r!=null?Math.min(t,r):t,s=Math.min(e,n);return{raw:n,filtered:s}}import{delimiter as ir,join as ai}from"node:path";function oi(){return ai(T(),"shims")}function ar(){let t=oi(),e={...process.env},r=process.platform==="win32"?"Path":"PATH",s=(e[r]??e.PATH??"").split(ir).filter(i=>i&&i!==t);return e[r]=s.join(ir),r==="Path"&&(e.PATH=e[r]),e}var ci=[{host:"claude-code",vars:["CLAUDE_CODE","CLAUDE_CODE_VERSION","ANTHROPIC_CLAUDE_CODE"]},{host:"codex",vars:["CODEX_VERSION","CODEX_CLI","OPENAI_CODEX"]},{host:"cursor",vars:["CURSOR_VERSION","CURSOR_TRACE_ID"]},{host:"cline",vars:["CLINE_VERSION","CLINE_API_KEY"]},{host:"aider",vars:["AIDER_VERSION","AIDER_MODEL"]},{host:"gemini-cli",vars:["GEMINI_CLI_VERSION","GEMINI_API_KEY"]},{host:"windsurf",vars:["WINDSURF_VERSION","WINDSURF_USER"]},{host:"copilot",vars:["GITHUB_COPILOT_VERSION","COPILOT_INTEGRATION_ID"]}],or=new Set(["claude-code","codex"]),li=3e4;function cr(t){return or.has(t)?li:null}function ot(t=process.env){let e=process.platform,r=e==="darwin"||e==="linux"||e==="win32"?e:"other",n=process.arch;for(let s of ci)if(s.vars.some(i=>t[i]))return{host:s.host,source:"env",os:r,arch:n,shimRecommended:!or.has(s.host)};return{host:"shell",source:"fallback",os:r,arch:n,shimRecommended:!0}}import{createConnection as _i}from"node:net";import{spawn as vi}from"node:child_process";import{existsSync as vr,openSync as mr,closeSync as xi,unlinkSync as hr,writeFileSync as gr}from"node:fs";import{dirname as bi,join as ki}from"node:path";import{fileURLToPath as Ei}from"node:url";var ui=h.object({id:h.string().min(1).max(64),op:h.literal("filter"),cmd:h.string().min(1).max(2048),plan:h.enum(["trial","smart","pro"]),installId:h.string().min(1).max(64).optional()}),di=h.object({id:h.string().min(1).max(64),op:h.literal("ping")}),fi=h.object({id:h.string().min(1).max(64),op:h.literal("shutdown"),installId:h.string().min(1).max(64)}),pi=h.object({id:h.string().min(1).max(64),op:h.literal("reload"),installId:h.string().min(1).max(64).optional()}),pc=h.discriminatedUnion("op",[ui,di,fi,pi]),mc=h.object({id:h.string(),ok:h.literal(!0),data:h.unknown()}),hc=h.object({id:h.string(),ok:h.literal(!1),err:h.string(),retryAfterMs:h.number().int().nonnegative().optional()}),lr=h.object({filter:Ue.nullable(),cacheHit:h.boolean().optional()}),We=`
10
+ `,gc=64*1024;function ur(t){return JSON.stringify(t)+We}function*dr(t){let e=0;for(;;){let r=t.indexOf(We,e);if(r<0)return;yield t.slice(e,r),e=r+1}}function Ge(){return`${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}import{join as ct}from"node:path";import{existsSync as fr,statSync as mi,unlinkSync as hi,mkdirSync as gi,chmodSync as yi}from"node:fs";function qe(){if(process.platform==="win32")return{path:`\\\\.\\pipe\\tokmizer-${process.env.USERNAME??"tokmizer"}`,isPipe:!0};let t=typeof process.getuid=="function"?process.getuid():0,e=process.env.XDG_RUNTIME_DIR;if(e&&fr(e))return{path:ct(e,`tokmizer-${t}.sock`),isPipe:!1};let r=ct(T(),"run");try{gi(r,{recursive:!0,mode:448}),yi(r,448)}catch{}return{path:ct(r,"daemon.sock"),isPipe:!1}}async function pr(){let{path:t,isPipe:e}=qe();if(e||!fr(t))return;try{if(!mi(t).isSocket())return}catch{return}let r=await import("node:net");if(!await new Promise(s=>{let i=r.createConnection(t),a=o=>{i.removeAllListeners();try{i.destroy()}catch{}s(o)};i.once("connect",()=>a(!0)),i.once("error",o=>{let c=o.code;a(c!=="ECONNREFUSED"&&c!=="ENOENT")}),setTimeout(()=>a(!0),250)}))try{hi(t)}catch{}}var bc=5*6e4;var wi=500,Si=3e3,yr=1;async function Ti(t,e){return new Promise((r,n)=>{let s=_i(t),i=o=>{if(s.removeAllListeners("connect"),s.removeAllListeners("error"),clearTimeout(a),o){try{s.destroy()}catch{}n(o)}else r(s)},a=setTimeout(()=>i(new Error("connect timeout")),e);s.once("connect",()=>i(null)),s.once("error",o=>i(o))})}function Ai(){return process.env.TOKMIZER_DAEMON_BIN?process.env.TOKMIZER_DAEMON_BIN:Ei(new URL("../bin/tkr-daemon.js",import.meta.url))}async function _r(t,e=3e3){let r=Math.ceil(e/75);for(let n=0;n<r;n++){if(vr(t))return!0;await new Promise(s=>setTimeout(s,75))}return!1}async function Ri(t){let e=Ai();if(!vr(e))throw new Error(`tkr-daemon binary not found at ${e}`);let{path:r}=qe(),n=ki(bi(r),"daemon.spawn.lock"),s=null;try{s=mr(n,"wx"),gr(s,String(process.pid))}catch(i){if(i.code==="EEXIST"){if(await _r(r,5e3))return;try{hr(n)}catch{}s=mr(n,"wx"),gr(s,String(process.pid))}else throw i}try{if(vi(process.execPath,[e],{detached:!0,stdio:["ignore","ignore","ignore"],env:{...process.env,TOKMIZER_DAEMON_INSTALL_ID:t}}).unref(),!await _r(r,3e3))throw new Error("tkr-daemon failed to bind socket within 3s")}finally{if(s!==null){try{xi(s)}catch{}try{hr(n)}catch{}}}}async function xr(t={}){let{path:e}=t.socketPath?{path:t.socketPath}:qe(),r=await Xt(),n=null,s=0;for(;s<=yr;)try{n=await Ti(e,wi);break}catch{if(s+=1,s>yr)throw new Error(`tkr-daemon unreachable at ${e}`);await pr(),await Ri(r)}if(!n)throw new Error("tkr-daemon: socket setup failed");let i=new Map,a="";n.setEncoding("utf8"),n.on("data",c=>{a+=c;let u=-1;for(let v=0;v<a.length;v++)a[v]===We&&(u=v);if(u<0)return;let f=[];for(let v of dr(a.slice(0,u+1)))f.push(v);a=a.slice(u+1);for(let v of f)if(v)try{let _=JSON.parse(v),E=i.get(_.id);if(!E)continue;clearTimeout(E.timer),i.delete(_.id),E.resolve(_)}catch{}}),n.on("close",()=>{for(let c of i.values())clearTimeout(c.timer),c.reject(new Error("daemon socket closed"));i.clear()}),n.on("error",()=>{});function o(c){return new Promise((u,f)=>{let v=setTimeout(()=>{i.delete(c.id),f(new Error(`daemon request timeout (${c.op})`))},Si);i.set(c.id,{resolve:u,reject:f,timer:v}),n.write(ur(c))})}return{filter:async(c,u)=>{let f=await o({id:Ge(),op:"filter",cmd:c.slice(0,2048),plan:u,installId:r});if(!f.ok)return null;let v=lr.safeParse(f.data);return v.success?v.data.filter:null},ping:async()=>{let c=await o({id:Ge(),op:"ping"});if(!c.ok)throw new Error(c.err);return c.data},reload:async()=>{let c=await o({id:Ge(),op:"reload",installId:r});if(!c.ok)throw new Error(c.err);return c.data},close:()=>{try{n.end()}catch{}}}}var Ae=null,Pe=null;async function Ci(){if(Ae)return Ae;if(Pe)return Pe;let t=xr().then(e=>{if(Pe===t)return Ae=e,e;try{e.close()}catch{}return null}).catch(()=>null);return Pe=t,t}function Ii(t){return t?{...t,matchRegex:new RegExp(t.match_command)}:null}function br(t){rt(async(e,r)=>{let n=await Ci();if(!n)return null;try{let s=t==="free"?"trial":t,i=await n.filter(e,s);return!i||!(r??Ve(void 0)).has(z(i.slug))?null:Ii(i)}catch{return null}})}function kr(){if(rt(null),Ae)try{Ae.close()}catch{}Ae=null,Pe=null}var Er=16*1024*1024,wr=Number(process.env.TOKMIZER_SHIM_TIMEOUT_MS??"600000");function Sr(t){return t[0]==="--as"&&typeof t[1]=="string"?{cmdName:t[1],args:t.slice(2)}:t.length>0?{cmdName:t[0],args:t.slice(1)}:{cmdName:"",args:[]}}async function Tr(t){let{cmdName:e,args:r}=t;if(!e)return process.stderr.write(`tkr-shim: missing command name
11
+ `),{exitCode:2,filteredOut:"",filteredErr:"",filterId:null,rawBytes:0,filteredBytes:0};let n=[e,...r].join(" "),s=await qt(),i=await nt(),a=i?Wt(i):null,o=i?Ve(i.allowedFilters,st(i)):new Set,c=new Set(s.filters.disabled.map(z)),u=c.size>0?new Set([...o].filter(_=>!c.has(_))):o,f=!process.stdout.isTTY&&ot().host==="shell",v=!s.enabled||!i;i&&!v&&!f&&br(a);try{return await new Promise(_=>{let E=Oi(e,r,{stdio:["inherit","pipe","pipe"],shell:!1,windowsHide:!0,env:ar(),timeout:wr>0?wr:void 0}),O=[],B=[],$=0,W=0,he=!1,lt=A=>{try{E.kill(A)}catch{}};process.on("SIGINT",()=>lt("SIGINT")),process.on("SIGTERM",()=>lt("SIGTERM")),E.stdout.on("data",A=>{if($+=A.length,$>Er){if(!he){for(let ge of O)process.stdout.write(ge);O.length=0,he=!0}process.stdout.write(A);return}O.push(A)}),E.stderr.on("data",A=>{if(W+=A.length,W>Er){if(!he){for(let ge of B)process.stderr.write(ge);B.length=0,he=!0}process.stderr.write(A);return}B.push(A)}),E.on("error",A=>{process.stderr.write(`tkr-shim: ${A.message}
12
+ `),_({exitCode:127,filteredOut:"",filteredErr:"",filterId:null,rawBytes:0,filteredBytes:0})}),E.on("close",async(A,ge)=>{let $e=typeof A=="number"?A:ge==="SIGTERM"?143:ge==="SIGINT"?130:1,ye=Buffer.concat(O),_e=Buffer.concat(B);if(he||v||f){ye.length&&process.stdout.write(ye),_e.length&&process.stderr.write(_e),f&&!v&&!he&&at($+W,$+W),_({exitCode:$e,filteredOut:ye.toString("utf8"),filteredErr:_e.toString("utf8"),filterId:null,rawBytes:$+W,filteredBytes:$+W});return}let ut=ye.toString("utf8"),Me=_e.toString("utf8");try{let I=await Vt(n,ut,u,{verbosity:s.outputVerbosity,exitCode:$e}),Le=sr(I.rawBytes,I.filteredBytes,cr(ot().host));at(Le.raw,Le.filtered);try{await nr({cmd:n,filterId:I.filterId,rawBytes:I.rawBytes,filteredBytes:I.filteredBytes,plan:a}),await rr({cmd:n,tokensSaved:Math.round((Le.raw-Le.filtered)/4),optimized:I.filterId!=null,telemetryOptIn:s.telemetryOptIn})}catch{}if(I.filteredBytes<I.rawBytes){process.stdout.write(I.output),Me&&process.stderr.write(Me),_({exitCode:$e,filteredOut:I.output,filteredErr:Me,filterId:I.filterId,rawBytes:I.rawBytes,filteredBytes:I.filteredBytes});return}}catch{}ye.length&&process.stdout.write(ye),_e.length&&process.stderr.write(_e),_({exitCode:$e,filteredOut:ut,filteredErr:Me,filterId:null,rawBytes:$+W,filteredBytes:$+W})})})}finally{kr()}}var Di=Sr(process.argv.slice(2));Tr(Di).then(t=>{process.exitCode=t.exitCode}).catch(t=>{process.stderr.write(`tkr-shim: ${t.message}
13
13
  `),process.exitCode=1});