@t-req/core 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +37 -2
- package/dist/config/index.js +6 -6
- package/dist/config/index.js.map +5 -5
- package/dist/engine/compile-request.d.ts +19 -0
- package/dist/engine/compile-request.d.ts.map +1 -0
- package/dist/engine/engine-utils.d.ts +13 -0
- package/dist/engine/engine-utils.d.ts.map +1 -0
- package/dist/engine/engine.d.ts +11 -1
- package/dist/engine/engine.d.ts.map +1 -1
- package/dist/engine/index.js +6 -4
- package/dist/engine/index.js.map +12 -6
- package/dist/engine/request-pipeline.d.ts +22 -0
- package/dist/engine/request-pipeline.d.ts.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -7
- package/dist/index.js.map +16 -10
- package/dist/parser.d.ts +17 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/plugin/define.d.ts +3 -1
- package/dist/plugin/define.d.ts.map +1 -1
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +4 -4
- package/dist/plugin/index.js.map +5 -5
- package/dist/plugin/loader.d.ts.map +1 -1
- package/dist/plugin/manager.d.ts +29 -1
- package/dist/plugin/manager.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +84 -0
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/protocols/http.d.ts +7 -0
- package/dist/protocols/http.d.ts.map +1 -0
- package/dist/protocols/index.d.ts +6 -0
- package/dist/protocols/index.d.ts.map +1 -0
- package/dist/protocols/registry.d.ts +24 -0
- package/dist/protocols/registry.d.ts.map +1 -0
- package/dist/protocols/sse.d.ts +26 -0
- package/dist/protocols/sse.d.ts.map +1 -0
- package/dist/protocols/types.d.ts +33 -0
- package/dist/protocols/types.d.ts.map +1 -0
- package/dist/server-client.d.ts.map +1 -1
- package/dist/types.d.ts +92 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import{createRequire as qQ}from"node:module";var jQ=Object.defineProperty;var wQ=($,Q)=>{for(var G in Q)jQ($,G,{get:Q[G],enumerable:!0,configurable:!0,set:(X)=>Q[G]=()=>X})};var U$=qQ(import.meta.url);var q$={};wQ(q$,{void:()=>tQ,util:()=>L,unknown:()=>aQ,union:()=>G0,undefined:()=>iQ,tuple:()=>H0,transformer:()=>V0,symbol:()=>nQ,string:()=>g3,strictObject:()=>Q0,setErrorMap:()=>UQ,set:()=>_0,record:()=>J0,quotelessJson:()=>VQ,promise:()=>q0,preprocess:()=>A0,pipeline:()=>D0,ostring:()=>S0,optional:()=>E0,onumber:()=>K0,oboolean:()=>L0,objectUtil:()=>B3,object:()=>$0,number:()=>Z3,nullable:()=>U0,null:()=>rQ,never:()=>sQ,nativeEnum:()=>w0,nan:()=>uQ,map:()=>W0,makeIssue:()=>g$,literal:()=>M0,lazy:()=>B0,late:()=>cQ,isValid:()=>Y$,isDirty:()=>r$,isAsync:()=>D$,isAborted:()=>i$,intersection:()=>Y0,instanceof:()=>lQ,getParsedType:()=>o,getErrorMap:()=>A$,function:()=>z0,enum:()=>j0,effect:()=>V0,discriminatedUnion:()=>X0,defaultErrorMap:()=>e,datetimeRegex:()=>T3,date:()=>pQ,custom:()=>x3,coerce:()=>N0,boolean:()=>h3,bigint:()=>dQ,array:()=>eQ,any:()=>oQ,addIssueToContext:()=>j,ZodVoid:()=>h$,ZodUnknown:()=>H$,ZodUnion:()=>R$,ZodUndefined:()=>N$,ZodType:()=>S,ZodTuple:()=>s,ZodTransformer:()=>n,ZodSymbol:()=>Z$,ZodString:()=>l,ZodSet:()=>j$,ZodSchema:()=>S,ZodRecord:()=>y$,ZodReadonly:()=>f$,ZodPromise:()=>w$,ZodPipeline:()=>l$,ZodParsedType:()=>M,ZodOptional:()=>d,ZodObject:()=>T,ZodNumber:()=>J$,ZodNullable:()=>Q$,ZodNull:()=>O$,ZodNever:()=>a,ZodNativeEnum:()=>I$,ZodNaN:()=>c$,ZodMap:()=>m$,ZodLiteral:()=>b$,ZodLazy:()=>C$,ZodIssueCode:()=>B,ZodIntersection:()=>F$,ZodFunction:()=>K$,ZodFirstPartyTypeKind:()=>U,ZodError:()=>y,ZodEnum:()=>_$,ZodEffects:()=>n,ZodDiscriminatedUnion:()=>o$,ZodDefault:()=>k$,ZodDate:()=>B$,ZodCatch:()=>v$,ZodBranded:()=>a$,ZodBoolean:()=>L$,ZodBigInt:()=>W$,ZodArray:()=>u,ZodAny:()=>M$,Schema:()=>S,ParseStatus:()=>g,OK:()=>Z,NEVER:()=>O0,INVALID:()=>V,EMPTY_PATH:()=>AQ,DIRTY:()=>z$,BRAND:()=>mQ});var L;(function($){$.assertEqual=(Y)=>{};function Q(Y){}$.assertIs=Q;function G(Y){throw Error()}$.assertNever=G,$.arrayToEnum=(Y)=>{let J={};for(let H of Y)J[H]=H;return J},$.getValidEnumValues=(Y)=>{let J=$.objectKeys(Y).filter((W)=>typeof Y[Y[W]]!=="number"),H={};for(let W of J)H[W]=Y[W];return $.objectValues(H)},$.objectValues=(Y)=>{return $.objectKeys(Y).map(function(J){return Y[J]})},$.objectKeys=typeof Object.keys==="function"?(Y)=>Object.keys(Y):(Y)=>{let J=[];for(let H in Y)if(Object.prototype.hasOwnProperty.call(Y,H))J.push(H);return J},$.find=(Y,J)=>{for(let H of Y)if(J(H))return H;return},$.isInteger=typeof Number.isInteger==="function"?(Y)=>Number.isInteger(Y):(Y)=>typeof Y==="number"&&Number.isFinite(Y)&&Math.floor(Y)===Y;function X(Y,J=" | "){return Y.map((H)=>typeof H==="string"?`'${H}'`:H).join(J)}$.joinValues=X,$.jsonStringifyReplacer=(Y,J)=>{if(typeof J==="bigint")return J.toString();return J}})(L||(L={}));var B3;(function($){$.mergeShapes=(Q,G)=>{return{...Q,...G}}})(B3||(B3={}));var M=L.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),o=($)=>{switch(typeof $){case"undefined":return M.undefined;case"string":return M.string;case"number":return Number.isNaN($)?M.nan:M.number;case"boolean":return M.boolean;case"function":return M.function;case"bigint":return M.bigint;case"symbol":return M.symbol;case"object":if(Array.isArray($))return M.array;if($===null)return M.null;if($.then&&typeof $.then==="function"&&$.catch&&typeof $.catch==="function")return M.promise;if(typeof Map<"u"&&$ instanceof Map)return M.map;if(typeof Set<"u"&&$ instanceof Set)return M.set;if(typeof Date<"u"&&$ instanceof Date)return M.date;return M.object;default:return M.unknown}};var B=L.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"]),VQ=($)=>{return JSON.stringify($,null,2).replace(/"([^"]+)":/g,"$1:")};class y extends Error{get errors(){return this.issues}constructor($){super();this.issues=[],this.addIssue=(G)=>{this.issues=[...this.issues,G]},this.addIssues=(G=[])=>{this.issues=[...this.issues,...G]};let Q=new.target.prototype;if(Object.setPrototypeOf)Object.setPrototypeOf(this,Q);else this.__proto__=Q;this.name="ZodError",this.issues=$}format($){let Q=$||function(Y){return Y.message},G={_errors:[]},X=(Y)=>{for(let J of Y.issues)if(J.code==="invalid_union")J.unionErrors.map(X);else if(J.code==="invalid_return_type")X(J.returnTypeError);else if(J.code==="invalid_arguments")X(J.argumentsError);else if(J.path.length===0)G._errors.push(Q(J));else{let H=G,W=0;while(W<J.path.length){let _=J.path[W];if(W!==J.path.length-1)H[_]=H[_]||{_errors:[]};else H[_]=H[_]||{_errors:[]},H[_]._errors.push(Q(J));H=H[_],W++}}};return X(this),G}static assert($){if(!($ instanceof y))throw Error(`Not a ZodError: ${$}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,L.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten($=(Q)=>Q.message){let Q={},G=[];for(let X of this.issues)if(X.path.length>0){let Y=X.path[0];Q[Y]=Q[Y]||[],Q[Y].push($(X))}else G.push($(X));return{formErrors:G,fieldErrors:Q}}get formErrors(){return this.flatten()}}y.create=($)=>{return new y($)};var EQ=($,Q)=>{let G;switch($.code){case B.invalid_type:if($.received===M.undefined)G="Required";else G=`Expected ${$.expected}, received ${$.received}`;break;case B.invalid_literal:G=`Invalid literal value, expected ${JSON.stringify($.expected,L.jsonStringifyReplacer)}`;break;case B.unrecognized_keys:G=`Unrecognized key(s) in object: ${L.joinValues($.keys,", ")}`;break;case B.invalid_union:G="Invalid input";break;case B.invalid_union_discriminator:G=`Invalid discriminator value. Expected ${L.joinValues($.options)}`;break;case B.invalid_enum_value:G=`Invalid enum value. Expected ${L.joinValues($.options)}, received '${$.received}'`;break;case B.invalid_arguments:G="Invalid function arguments";break;case B.invalid_return_type:G="Invalid function return type";break;case B.invalid_date:G="Invalid date";break;case B.invalid_string:if(typeof $.validation==="object")if("includes"in $.validation){if(G=`Invalid input: must include "${$.validation.includes}"`,typeof $.validation.position==="number")G=`${G} at one or more positions greater than or equal to ${$.validation.position}`}else if("startsWith"in $.validation)G=`Invalid input: must start with "${$.validation.startsWith}"`;else if("endsWith"in $.validation)G=`Invalid input: must end with "${$.validation.endsWith}"`;else L.assertNever($.validation);else if($.validation!=="regex")G=`Invalid ${$.validation}`;else G="Invalid";break;case B.too_small:if($.type==="array")G=`Array must contain ${$.exact?"exactly":$.inclusive?"at least":"more than"} ${$.minimum} element(s)`;else if($.type==="string")G=`String must contain ${$.exact?"exactly":$.inclusive?"at least":"over"} ${$.minimum} character(s)`;else if($.type==="number")G=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="bigint")G=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="date")G=`Date must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${new Date(Number($.minimum))}`;else G="Invalid input";break;case B.too_big:if($.type==="array")G=`Array must contain ${$.exact?"exactly":$.inclusive?"at most":"less than"} ${$.maximum} element(s)`;else if($.type==="string")G=`String must contain ${$.exact?"exactly":$.inclusive?"at most":"under"} ${$.maximum} character(s)`;else if($.type==="number")G=`Number must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="bigint")G=`BigInt must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="date")G=`Date must be ${$.exact?"exactly":$.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number($.maximum))}`;else G="Invalid input";break;case B.custom:G="Invalid input";break;case B.invalid_intersection_types:G="Intersection results could not be merged";break;case B.not_multiple_of:G=`Number must be a multiple of ${$.multipleOf}`;break;case B.not_finite:G="Number must be finite";break;default:G=Q.defaultError,L.assertNever($)}return{message:G}},e=EQ;var b3=e;function UQ($){b3=$}function A$(){return b3}var g$=($)=>{let{data:Q,path:G,errorMaps:X,issueData:Y}=$,J=[...G,...Y.path||[]],H={...Y,path:J};if(Y.message!==void 0)return{...Y,path:J,message:Y.message};let W="",_=X.filter((z)=>!!z).slice().reverse();for(let z of _)W=z(H,{data:Q,defaultError:W}).message;return{...Y,path:J,message:W}},AQ=[];function j($,Q){let G=A$(),X=g$({issueData:Q,data:$.data,path:$.path,errorMaps:[$.common.contextualErrorMap,$.schemaErrorMap,G,G===e?void 0:e].filter((Y)=>!!Y)});$.common.issues.push(X)}class g{constructor(){this.value="valid"}dirty(){if(this.value==="valid")this.value="dirty"}abort(){if(this.value!=="aborted")this.value="aborted"}static mergeArray($,Q){let G=[];for(let X of Q){if(X.status==="aborted")return V;if(X.status==="dirty")$.dirty();G.push(X.value)}return{status:$.value,value:G}}static async mergeObjectAsync($,Q){let G=[];for(let X of Q){let Y=await X.key,J=await X.value;G.push({key:Y,value:J})}return g.mergeObjectSync($,G)}static mergeObjectSync($,Q){let G={};for(let X of Q){let{key:Y,value:J}=X;if(Y.status==="aborted")return V;if(J.status==="aborted")return V;if(Y.status==="dirty")$.dirty();if(J.status==="dirty")$.dirty();if(Y.value!=="__proto__"&&(typeof J.value<"u"||X.alwaysSet))G[Y.value]=J.value}return{status:$.value,value:G}}}var V=Object.freeze({status:"aborted"}),z$=($)=>({status:"dirty",value:$}),Z=($)=>({status:"valid",value:$}),i$=($)=>$.status==="aborted",r$=($)=>$.status==="dirty",Y$=($)=>$.status==="valid",D$=($)=>typeof Promise<"u"&&$ instanceof Promise;var q;(function($){$.errToObj=(Q)=>typeof Q==="string"?{message:Q}:Q||{},$.toString=(Q)=>typeof Q==="string"?Q:Q?.message})(q||(q={}));class p{constructor($,Q,G,X){this._cachedPath=[],this.parent=$,this.data=Q,this._path=G,this._key=X}get path(){if(!this._cachedPath.length)if(Array.isArray(this._key))this._cachedPath.push(...this._path,...this._key);else this._cachedPath.push(...this._path,this._key);return this._cachedPath}}var I3=($,Q)=>{if(Y$(Q))return{success:!0,data:Q.value};else{if(!$.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let G=new y($.common.issues);return this._error=G,this._error}}}};function D($){if(!$)return{};let{errorMap:Q,invalid_type_error:G,required_error:X,description:Y}=$;if(Q&&(G||X))throw Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);if(Q)return{errorMap:Q,description:Y};return{errorMap:(H,W)=>{let{message:_}=$;if(H.code==="invalid_enum_value")return{message:_??W.defaultError};if(typeof W.data>"u")return{message:_??X??W.defaultError};if(H.code!=="invalid_type")return{message:W.defaultError};return{message:_??G??W.defaultError}},description:Y}}class S{get description(){return this._def.description}_getType($){return o($.data)}_getOrReturnCtx($,Q){return Q||{common:$.parent.common,data:$.data,parsedType:o($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}_processInputParams($){return{status:new g,ctx:{common:$.parent.common,data:$.data,parsedType:o($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}}_parseSync($){let Q=this._parse($);if(D$(Q))throw Error("Synchronous parse encountered promise.");return Q}_parseAsync($){let Q=this._parse($);return Promise.resolve(Q)}parse($,Q){let G=this.safeParse($,Q);if(G.success)return G.data;throw G.error}safeParse($,Q){let G={common:{issues:[],async:Q?.async??!1,contextualErrorMap:Q?.errorMap},path:Q?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:o($)},X=this._parseSync({data:$,path:G.path,parent:G});return I3(G,X)}"~validate"($){let Q={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:o($)};if(!this["~standard"].async)try{let G=this._parseSync({data:$,path:[],parent:Q});return Y$(G)?{value:G.value}:{issues:Q.common.issues}}catch(G){if(G?.message?.toLowerCase()?.includes("encountered"))this["~standard"].async=!0;Q.common={issues:[],async:!0}}return this._parseAsync({data:$,path:[],parent:Q}).then((G)=>Y$(G)?{value:G.value}:{issues:Q.common.issues})}async parseAsync($,Q){let G=await this.safeParseAsync($,Q);if(G.success)return G.data;throw G.error}async safeParseAsync($,Q){let G={common:{issues:[],contextualErrorMap:Q?.errorMap,async:!0},path:Q?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:o($)},X=this._parse({data:$,path:G.path,parent:G}),Y=await(D$(X)?X:Promise.resolve(X));return I3(G,Y)}refine($,Q){let G=(X)=>{if(typeof Q==="string"||typeof Q>"u")return{message:Q};else if(typeof Q==="function")return Q(X);else return Q};return this._refinement((X,Y)=>{let J=$(X),H=()=>Y.addIssue({code:B.custom,...G(X)});if(typeof Promise<"u"&&J instanceof Promise)return J.then((W)=>{if(!W)return H(),!1;else return!0});if(!J)return H(),!1;else return!0})}refinement($,Q){return this._refinement((G,X)=>{if(!$(G))return X.addIssue(typeof Q==="function"?Q(G,X):Q),!1;else return!0})}_refinement($){return new n({schema:this,typeName:U.ZodEffects,effect:{type:"refinement",refinement:$}})}superRefine($){return this._refinement($)}constructor($){this.spa=this.safeParseAsync,this._def=$,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:(Q)=>this["~validate"](Q)}}optional(){return d.create(this,this._def)}nullable(){return Q$.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return u.create(this)}promise(){return w$.create(this,this._def)}or($){return R$.create([this,$],this._def)}and($){return F$.create(this,$,this._def)}transform($){return new n({...D(this._def),schema:this,typeName:U.ZodEffects,effect:{type:"transform",transform:$}})}default($){let Q=typeof $==="function"?$:()=>$;return new k$({...D(this._def),innerType:this,defaultValue:Q,typeName:U.ZodDefault})}brand(){return new a$({typeName:U.ZodBranded,type:this,...D(this._def)})}catch($){let Q=typeof $==="function"?$:()=>$;return new v$({...D(this._def),innerType:this,catchValue:Q,typeName:U.ZodCatch})}describe($){return new this.constructor({...this._def,description:$})}pipe($){return l$.create(this,$)}readonly(){return f$.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}var DQ=/^c[^\s-]{8,}$/i,SQ=/^[0-9a-z]+$/,KQ=/^[0-9A-HJKMNP-TV-Z]{26}$/i,LQ=/^[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,NQ=/^[a-z0-9_-]{21}$/i,OQ=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,RQ=/^[-+]?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)?)??$/,FQ=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,CQ="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",M3,bQ=/^(?:(?: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])$/,IQ=/^(?:(?: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])$/,kQ=/^(([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]))$/,vQ=/^(([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])$/,fQ=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,TQ=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,v3="((\\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])))",PQ=new RegExp(`^${v3}$`);function f3($){let Q="[0-5]\\d";if($.precision)Q=`${Q}\\.\\d{${$.precision}}`;else if($.precision==null)Q=`${Q}(\\.\\d+)?`;let G=$.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${Q})${G}`}function xQ($){return new RegExp(`^${f3($)}$`)}function T3($){let Q=`${v3}T${f3($)}`,G=[];if(G.push($.local?"Z?":"Z"),$.offset)G.push("([+-]\\d{2}:?\\d{2})");return Q=`${Q}(${G.join("|")})`,new RegExp(`^${Q}$`)}function gQ($,Q){if((Q==="v4"||!Q)&&bQ.test($))return!0;if((Q==="v6"||!Q)&&kQ.test($))return!0;return!1}function ZQ($,Q){if(!OQ.test($))return!1;try{let[G]=$.split(".");if(!G)return!1;let X=G.replace(/-/g,"+").replace(/_/g,"/").padEnd(G.length+(4-G.length%4)%4,"="),Y=JSON.parse(atob(X));if(typeof Y!=="object"||Y===null)return!1;if("typ"in Y&&Y?.typ!=="JWT")return!1;if(!Y.alg)return!1;if(Q&&Y.alg!==Q)return!1;return!0}catch{return!1}}function hQ($,Q){if((Q==="v4"||!Q)&&IQ.test($))return!0;if((Q==="v6"||!Q)&&vQ.test($))return!0;return!1}class l extends S{_parse($){if(this._def.coerce)$.data=String($.data);if(this._getType($)!==M.string){let Y=this._getOrReturnCtx($);return j(Y,{code:B.invalid_type,expected:M.string,received:Y.parsedType}),V}let G=new g,X=void 0;for(let Y of this._def.checks)if(Y.kind==="min"){if($.data.length<Y.value)X=this._getOrReturnCtx($,X),j(X,{code:B.too_small,minimum:Y.value,type:"string",inclusive:!0,exact:!1,message:Y.message}),G.dirty()}else if(Y.kind==="max"){if($.data.length>Y.value)X=this._getOrReturnCtx($,X),j(X,{code:B.too_big,maximum:Y.value,type:"string",inclusive:!0,exact:!1,message:Y.message}),G.dirty()}else if(Y.kind==="length"){let J=$.data.length>Y.value,H=$.data.length<Y.value;if(J||H){if(X=this._getOrReturnCtx($,X),J)j(X,{code:B.too_big,maximum:Y.value,type:"string",inclusive:!0,exact:!0,message:Y.message});else if(H)j(X,{code:B.too_small,minimum:Y.value,type:"string",inclusive:!0,exact:!0,message:Y.message});G.dirty()}}else if(Y.kind==="email"){if(!FQ.test($.data))X=this._getOrReturnCtx($,X),j(X,{validation:"email",code:B.invalid_string,message:Y.message}),G.dirty()}else if(Y.kind==="emoji"){if(!M3)M3=new RegExp(CQ,"u");if(!M3.test($.data))X=this._getOrReturnCtx($,X),j(X,{validation:"emoji",code:B.invalid_string,message:Y.message}),G.dirty()}else if(Y.kind==="uuid"){if(!LQ.test($.data))X=this._getOrReturnCtx($,X),j(X,{validation:"uuid",code:B.invalid_string,message:Y.message}),G.dirty()}else if(Y.kind==="nanoid"){if(!NQ.test($.data))X=this._getOrReturnCtx($,X),j(X,{validation:"nanoid",code:B.invalid_string,message:Y.message}),G.dirty()}else if(Y.kind==="cuid"){if(!DQ.test($.data))X=this._getOrReturnCtx($,X),j(X,{validation:"cuid",code:B.invalid_string,message:Y.message}),G.dirty()}else if(Y.kind==="cuid2"){if(!SQ.test($.data))X=this._getOrReturnCtx($,X),j(X,{validation:"cuid2",code:B.invalid_string,message:Y.message}),G.dirty()}else if(Y.kind==="ulid"){if(!KQ.test($.data))X=this._getOrReturnCtx($,X),j(X,{validation:"ulid",code:B.invalid_string,message:Y.message}),G.dirty()}else if(Y.kind==="url")try{new URL($.data)}catch{X=this._getOrReturnCtx($,X),j(X,{validation:"url",code:B.invalid_string,message:Y.message}),G.dirty()}else if(Y.kind==="regex"){if(Y.regex.lastIndex=0,!Y.regex.test($.data))X=this._getOrReturnCtx($,X),j(X,{validation:"regex",code:B.invalid_string,message:Y.message}),G.dirty()}else if(Y.kind==="trim")$.data=$.data.trim();else if(Y.kind==="includes"){if(!$.data.includes(Y.value,Y.position))X=this._getOrReturnCtx($,X),j(X,{code:B.invalid_string,validation:{includes:Y.value,position:Y.position},message:Y.message}),G.dirty()}else if(Y.kind==="toLowerCase")$.data=$.data.toLowerCase();else if(Y.kind==="toUpperCase")$.data=$.data.toUpperCase();else if(Y.kind==="startsWith"){if(!$.data.startsWith(Y.value))X=this._getOrReturnCtx($,X),j(X,{code:B.invalid_string,validation:{startsWith:Y.value},message:Y.message}),G.dirty()}else if(Y.kind==="endsWith"){if(!$.data.endsWith(Y.value))X=this._getOrReturnCtx($,X),j(X,{code:B.invalid_string,validation:{endsWith:Y.value},message:Y.message}),G.dirty()}else if(Y.kind==="datetime"){if(!T3(Y).test($.data))X=this._getOrReturnCtx($,X),j(X,{code:B.invalid_string,validation:"datetime",message:Y.message}),G.dirty()}else if(Y.kind==="date"){if(!PQ.test($.data))X=this._getOrReturnCtx($,X),j(X,{code:B.invalid_string,validation:"date",message:Y.message}),G.dirty()}else if(Y.kind==="time"){if(!xQ(Y).test($.data))X=this._getOrReturnCtx($,X),j(X,{code:B.invalid_string,validation:"time",message:Y.message}),G.dirty()}else if(Y.kind==="duration"){if(!RQ.test($.data))X=this._getOrReturnCtx($,X),j(X,{validation:"duration",code:B.invalid_string,message:Y.message}),G.dirty()}else if(Y.kind==="ip"){if(!gQ($.data,Y.version))X=this._getOrReturnCtx($,X),j(X,{validation:"ip",code:B.invalid_string,message:Y.message}),G.dirty()}else if(Y.kind==="jwt"){if(!ZQ($.data,Y.alg))X=this._getOrReturnCtx($,X),j(X,{validation:"jwt",code:B.invalid_string,message:Y.message}),G.dirty()}else if(Y.kind==="cidr"){if(!hQ($.data,Y.version))X=this._getOrReturnCtx($,X),j(X,{validation:"cidr",code:B.invalid_string,message:Y.message}),G.dirty()}else if(Y.kind==="base64"){if(!fQ.test($.data))X=this._getOrReturnCtx($,X),j(X,{validation:"base64",code:B.invalid_string,message:Y.message}),G.dirty()}else if(Y.kind==="base64url"){if(!TQ.test($.data))X=this._getOrReturnCtx($,X),j(X,{validation:"base64url",code:B.invalid_string,message:Y.message}),G.dirty()}else L.assertNever(Y);return{status:G.value,value:$.data}}_regex($,Q,G){return this.refinement((X)=>$.test(X),{validation:Q,code:B.invalid_string,...q.errToObj(G)})}_addCheck($){return new l({...this._def,checks:[...this._def.checks,$]})}email($){return this._addCheck({kind:"email",...q.errToObj($)})}url($){return this._addCheck({kind:"url",...q.errToObj($)})}emoji($){return this._addCheck({kind:"emoji",...q.errToObj($)})}uuid($){return this._addCheck({kind:"uuid",...q.errToObj($)})}nanoid($){return this._addCheck({kind:"nanoid",...q.errToObj($)})}cuid($){return this._addCheck({kind:"cuid",...q.errToObj($)})}cuid2($){return this._addCheck({kind:"cuid2",...q.errToObj($)})}ulid($){return this._addCheck({kind:"ulid",...q.errToObj($)})}base64($){return this._addCheck({kind:"base64",...q.errToObj($)})}base64url($){return this._addCheck({kind:"base64url",...q.errToObj($)})}jwt($){return this._addCheck({kind:"jwt",...q.errToObj($)})}ip($){return this._addCheck({kind:"ip",...q.errToObj($)})}cidr($){return this._addCheck({kind:"cidr",...q.errToObj($)})}datetime($){if(typeof $==="string")return this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:$});return this._addCheck({kind:"datetime",precision:typeof $?.precision>"u"?null:$?.precision,offset:$?.offset??!1,local:$?.local??!1,...q.errToObj($?.message)})}date($){return this._addCheck({kind:"date",message:$})}time($){if(typeof $==="string")return this._addCheck({kind:"time",precision:null,message:$});return this._addCheck({kind:"time",precision:typeof $?.precision>"u"?null:$?.precision,...q.errToObj($?.message)})}duration($){return this._addCheck({kind:"duration",...q.errToObj($)})}regex($,Q){return this._addCheck({kind:"regex",regex:$,...q.errToObj(Q)})}includes($,Q){return this._addCheck({kind:"includes",value:$,position:Q?.position,...q.errToObj(Q?.message)})}startsWith($,Q){return this._addCheck({kind:"startsWith",value:$,...q.errToObj(Q)})}endsWith($,Q){return this._addCheck({kind:"endsWith",value:$,...q.errToObj(Q)})}min($,Q){return this._addCheck({kind:"min",value:$,...q.errToObj(Q)})}max($,Q){return this._addCheck({kind:"max",value:$,...q.errToObj(Q)})}length($,Q){return this._addCheck({kind:"length",value:$,...q.errToObj(Q)})}nonempty($){return this.min(1,q.errToObj($))}trim(){return new l({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new l({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new l({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(($)=>$.kind==="datetime")}get isDate(){return!!this._def.checks.find(($)=>$.kind==="date")}get isTime(){return!!this._def.checks.find(($)=>$.kind==="time")}get isDuration(){return!!this._def.checks.find(($)=>$.kind==="duration")}get isEmail(){return!!this._def.checks.find(($)=>$.kind==="email")}get isURL(){return!!this._def.checks.find(($)=>$.kind==="url")}get isEmoji(){return!!this._def.checks.find(($)=>$.kind==="emoji")}get isUUID(){return!!this._def.checks.find(($)=>$.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(($)=>$.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(($)=>$.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(($)=>$.kind==="cuid2")}get isULID(){return!!this._def.checks.find(($)=>$.kind==="ulid")}get isIP(){return!!this._def.checks.find(($)=>$.kind==="ip")}get isCIDR(){return!!this._def.checks.find(($)=>$.kind==="cidr")}get isBase64(){return!!this._def.checks.find(($)=>$.kind==="base64")}get isBase64url(){return!!this._def.checks.find(($)=>$.kind==="base64url")}get minLength(){let $=null;for(let Q of this._def.checks)if(Q.kind==="min"){if($===null||Q.value>$)$=Q.value}return $}get maxLength(){let $=null;for(let Q of this._def.checks)if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return $}}l.create=($)=>{return new l({checks:[],typeName:U.ZodString,coerce:$?.coerce??!1,...D($)})};function yQ($,Q){let G=($.toString().split(".")[1]||"").length,X=(Q.toString().split(".")[1]||"").length,Y=G>X?G:X,J=Number.parseInt($.toFixed(Y).replace(".","")),H=Number.parseInt(Q.toFixed(Y).replace(".",""));return J%H/10**Y}class J$ extends S{constructor(){super(...arguments);this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse($){if(this._def.coerce)$.data=Number($.data);if(this._getType($)!==M.number){let Y=this._getOrReturnCtx($);return j(Y,{code:B.invalid_type,expected:M.number,received:Y.parsedType}),V}let G=void 0,X=new g;for(let Y of this._def.checks)if(Y.kind==="int"){if(!L.isInteger($.data))G=this._getOrReturnCtx($,G),j(G,{code:B.invalid_type,expected:"integer",received:"float",message:Y.message}),X.dirty()}else if(Y.kind==="min"){if(Y.inclusive?$.data<Y.value:$.data<=Y.value)G=this._getOrReturnCtx($,G),j(G,{code:B.too_small,minimum:Y.value,type:"number",inclusive:Y.inclusive,exact:!1,message:Y.message}),X.dirty()}else if(Y.kind==="max"){if(Y.inclusive?$.data>Y.value:$.data>=Y.value)G=this._getOrReturnCtx($,G),j(G,{code:B.too_big,maximum:Y.value,type:"number",inclusive:Y.inclusive,exact:!1,message:Y.message}),X.dirty()}else if(Y.kind==="multipleOf"){if(yQ($.data,Y.value)!==0)G=this._getOrReturnCtx($,G),j(G,{code:B.not_multiple_of,multipleOf:Y.value,message:Y.message}),X.dirty()}else if(Y.kind==="finite"){if(!Number.isFinite($.data))G=this._getOrReturnCtx($,G),j(G,{code:B.not_finite,message:Y.message}),X.dirty()}else L.assertNever(Y);return{status:X.value,value:$.data}}gte($,Q){return this.setLimit("min",$,!0,q.toString(Q))}gt($,Q){return this.setLimit("min",$,!1,q.toString(Q))}lte($,Q){return this.setLimit("max",$,!0,q.toString(Q))}lt($,Q){return this.setLimit("max",$,!1,q.toString(Q))}setLimit($,Q,G,X){return new J$({...this._def,checks:[...this._def.checks,{kind:$,value:Q,inclusive:G,message:q.toString(X)}]})}_addCheck($){return new J$({...this._def,checks:[...this._def.checks,$]})}int($){return this._addCheck({kind:"int",message:q.toString($)})}positive($){return this._addCheck({kind:"min",value:0,inclusive:!1,message:q.toString($)})}negative($){return this._addCheck({kind:"max",value:0,inclusive:!1,message:q.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:0,inclusive:!0,message:q.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:0,inclusive:!0,message:q.toString($)})}multipleOf($,Q){return this._addCheck({kind:"multipleOf",value:$,message:q.toString(Q)})}finite($){return this._addCheck({kind:"finite",message:q.toString($)})}safe($){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:q.toString($)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:q.toString($)})}get minValue(){let $=null;for(let Q of this._def.checks)if(Q.kind==="min"){if($===null||Q.value>$)$=Q.value}return $}get maxValue(){let $=null;for(let Q of this._def.checks)if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return $}get isInt(){return!!this._def.checks.find(($)=>$.kind==="int"||$.kind==="multipleOf"&&L.isInteger($.value))}get isFinite(){let $=null,Q=null;for(let G of this._def.checks)if(G.kind==="finite"||G.kind==="int"||G.kind==="multipleOf")return!0;else if(G.kind==="min"){if(Q===null||G.value>Q)Q=G.value}else if(G.kind==="max"){if($===null||G.value<$)$=G.value}return Number.isFinite(Q)&&Number.isFinite($)}}J$.create=($)=>{return new J$({checks:[],typeName:U.ZodNumber,coerce:$?.coerce||!1,...D($)})};class W$ extends S{constructor(){super(...arguments);this.min=this.gte,this.max=this.lte}_parse($){if(this._def.coerce)try{$.data=BigInt($.data)}catch{return this._getInvalidInput($)}if(this._getType($)!==M.bigint)return this._getInvalidInput($);let G=void 0,X=new g;for(let Y of this._def.checks)if(Y.kind==="min"){if(Y.inclusive?$.data<Y.value:$.data<=Y.value)G=this._getOrReturnCtx($,G),j(G,{code:B.too_small,type:"bigint",minimum:Y.value,inclusive:Y.inclusive,message:Y.message}),X.dirty()}else if(Y.kind==="max"){if(Y.inclusive?$.data>Y.value:$.data>=Y.value)G=this._getOrReturnCtx($,G),j(G,{code:B.too_big,type:"bigint",maximum:Y.value,inclusive:Y.inclusive,message:Y.message}),X.dirty()}else if(Y.kind==="multipleOf"){if($.data%Y.value!==BigInt(0))G=this._getOrReturnCtx($,G),j(G,{code:B.not_multiple_of,multipleOf:Y.value,message:Y.message}),X.dirty()}else L.assertNever(Y);return{status:X.value,value:$.data}}_getInvalidInput($){let Q=this._getOrReturnCtx($);return j(Q,{code:B.invalid_type,expected:M.bigint,received:Q.parsedType}),V}gte($,Q){return this.setLimit("min",$,!0,q.toString(Q))}gt($,Q){return this.setLimit("min",$,!1,q.toString(Q))}lte($,Q){return this.setLimit("max",$,!0,q.toString(Q))}lt($,Q){return this.setLimit("max",$,!1,q.toString(Q))}setLimit($,Q,G,X){return new W$({...this._def,checks:[...this._def.checks,{kind:$,value:Q,inclusive:G,message:q.toString(X)}]})}_addCheck($){return new W$({...this._def,checks:[...this._def.checks,$]})}positive($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:q.toString($)})}negative($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:q.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:q.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:q.toString($)})}multipleOf($,Q){return this._addCheck({kind:"multipleOf",value:$,message:q.toString(Q)})}get minValue(){let $=null;for(let Q of this._def.checks)if(Q.kind==="min"){if($===null||Q.value>$)$=Q.value}return $}get maxValue(){let $=null;for(let Q of this._def.checks)if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return $}}W$.create=($)=>{return new W$({checks:[],typeName:U.ZodBigInt,coerce:$?.coerce??!1,...D($)})};class L$ extends S{_parse($){if(this._def.coerce)$.data=Boolean($.data);if(this._getType($)!==M.boolean){let G=this._getOrReturnCtx($);return j(G,{code:B.invalid_type,expected:M.boolean,received:G.parsedType}),V}return Z($.data)}}L$.create=($)=>{return new L$({typeName:U.ZodBoolean,coerce:$?.coerce||!1,...D($)})};class B$ extends S{_parse($){if(this._def.coerce)$.data=new Date($.data);if(this._getType($)!==M.date){let Y=this._getOrReturnCtx($);return j(Y,{code:B.invalid_type,expected:M.date,received:Y.parsedType}),V}if(Number.isNaN($.data.getTime())){let Y=this._getOrReturnCtx($);return j(Y,{code:B.invalid_date}),V}let G=new g,X=void 0;for(let Y of this._def.checks)if(Y.kind==="min"){if($.data.getTime()<Y.value)X=this._getOrReturnCtx($,X),j(X,{code:B.too_small,message:Y.message,inclusive:!0,exact:!1,minimum:Y.value,type:"date"}),G.dirty()}else if(Y.kind==="max"){if($.data.getTime()>Y.value)X=this._getOrReturnCtx($,X),j(X,{code:B.too_big,message:Y.message,inclusive:!0,exact:!1,maximum:Y.value,type:"date"}),G.dirty()}else L.assertNever(Y);return{status:G.value,value:new Date($.data.getTime())}}_addCheck($){return new B$({...this._def,checks:[...this._def.checks,$]})}min($,Q){return this._addCheck({kind:"min",value:$.getTime(),message:q.toString(Q)})}max($,Q){return this._addCheck({kind:"max",value:$.getTime(),message:q.toString(Q)})}get minDate(){let $=null;for(let Q of this._def.checks)if(Q.kind==="min"){if($===null||Q.value>$)$=Q.value}return $!=null?new Date($):null}get maxDate(){let $=null;for(let Q of this._def.checks)if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return $!=null?new Date($):null}}B$.create=($)=>{return new B$({checks:[],coerce:$?.coerce||!1,typeName:U.ZodDate,...D($)})};class Z$ extends S{_parse($){if(this._getType($)!==M.symbol){let G=this._getOrReturnCtx($);return j(G,{code:B.invalid_type,expected:M.symbol,received:G.parsedType}),V}return Z($.data)}}Z$.create=($)=>{return new Z$({typeName:U.ZodSymbol,...D($)})};class N$ extends S{_parse($){if(this._getType($)!==M.undefined){let G=this._getOrReturnCtx($);return j(G,{code:B.invalid_type,expected:M.undefined,received:G.parsedType}),V}return Z($.data)}}N$.create=($)=>{return new N$({typeName:U.ZodUndefined,...D($)})};class O$ extends S{_parse($){if(this._getType($)!==M.null){let G=this._getOrReturnCtx($);return j(G,{code:B.invalid_type,expected:M.null,received:G.parsedType}),V}return Z($.data)}}O$.create=($)=>{return new O$({typeName:U.ZodNull,...D($)})};class M$ extends S{constructor(){super(...arguments);this._any=!0}_parse($){return Z($.data)}}M$.create=($)=>{return new M$({typeName:U.ZodAny,...D($)})};class H$ extends S{constructor(){super(...arguments);this._unknown=!0}_parse($){return Z($.data)}}H$.create=($)=>{return new H$({typeName:U.ZodUnknown,...D($)})};class a extends S{_parse($){let Q=this._getOrReturnCtx($);return j(Q,{code:B.invalid_type,expected:M.never,received:Q.parsedType}),V}}a.create=($)=>{return new a({typeName:U.ZodNever,...D($)})};class h$ extends S{_parse($){if(this._getType($)!==M.undefined){let G=this._getOrReturnCtx($);return j(G,{code:B.invalid_type,expected:M.void,received:G.parsedType}),V}return Z($.data)}}h$.create=($)=>{return new h$({typeName:U.ZodVoid,...D($)})};class u extends S{_parse($){let{ctx:Q,status:G}=this._processInputParams($),X=this._def;if(Q.parsedType!==M.array)return j(Q,{code:B.invalid_type,expected:M.array,received:Q.parsedType}),V;if(X.exactLength!==null){let J=Q.data.length>X.exactLength.value,H=Q.data.length<X.exactLength.value;if(J||H)j(Q,{code:J?B.too_big:B.too_small,minimum:H?X.exactLength.value:void 0,maximum:J?X.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:X.exactLength.message}),G.dirty()}if(X.minLength!==null){if(Q.data.length<X.minLength.value)j(Q,{code:B.too_small,minimum:X.minLength.value,type:"array",inclusive:!0,exact:!1,message:X.minLength.message}),G.dirty()}if(X.maxLength!==null){if(Q.data.length>X.maxLength.value)j(Q,{code:B.too_big,maximum:X.maxLength.value,type:"array",inclusive:!0,exact:!1,message:X.maxLength.message}),G.dirty()}if(Q.common.async)return Promise.all([...Q.data].map((J,H)=>{return X.type._parseAsync(new p(Q,J,Q.path,H))})).then((J)=>{return g.mergeArray(G,J)});let Y=[...Q.data].map((J,H)=>{return X.type._parseSync(new p(Q,J,Q.path,H))});return g.mergeArray(G,Y)}get element(){return this._def.type}min($,Q){return new u({...this._def,minLength:{value:$,message:q.toString(Q)}})}max($,Q){return new u({...this._def,maxLength:{value:$,message:q.toString(Q)}})}length($,Q){return new u({...this._def,exactLength:{value:$,message:q.toString(Q)}})}nonempty($){return this.min(1,$)}}u.create=($,Q)=>{return new u({type:$,minLength:null,maxLength:null,exactLength:null,typeName:U.ZodArray,...D(Q)})};function S$($){if($ instanceof T){let Q={};for(let G in $.shape){let X=$.shape[G];Q[G]=d.create(S$(X))}return new T({...$._def,shape:()=>Q})}else if($ instanceof u)return new u({...$._def,type:S$($.element)});else if($ instanceof d)return d.create(S$($.unwrap()));else if($ instanceof Q$)return Q$.create(S$($.unwrap()));else if($ instanceof s)return s.create($.items.map((Q)=>S$(Q)));else return $}class T extends S{constructor(){super(...arguments);this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let $=this._def.shape(),Q=L.objectKeys($);return this._cached={shape:$,keys:Q},this._cached}_parse($){if(this._getType($)!==M.object){let _=this._getOrReturnCtx($);return j(_,{code:B.invalid_type,expected:M.object,received:_.parsedType}),V}let{status:G,ctx:X}=this._processInputParams($),{shape:Y,keys:J}=this._getCached(),H=[];if(!(this._def.catchall instanceof a&&this._def.unknownKeys==="strip")){for(let _ in X.data)if(!J.includes(_))H.push(_)}let W=[];for(let _ of J){let z=Y[_],w=X.data[_];W.push({key:{status:"valid",value:_},value:z._parse(new p(X,w,X.path,_)),alwaysSet:_ in X.data})}if(this._def.catchall instanceof a){let _=this._def.unknownKeys;if(_==="passthrough")for(let z of H)W.push({key:{status:"valid",value:z},value:{status:"valid",value:X.data[z]}});else if(_==="strict"){if(H.length>0)j(X,{code:B.unrecognized_keys,keys:H}),G.dirty()}else if(_==="strip");else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let _=this._def.catchall;for(let z of H){let w=X.data[z];W.push({key:{status:"valid",value:z},value:_._parse(new p(X,w,X.path,z)),alwaysSet:z in X.data})}}if(X.common.async)return Promise.resolve().then(async()=>{let _=[];for(let z of W){let w=await z.key,E=await z.value;_.push({key:w,value:E,alwaysSet:z.alwaysSet})}return _}).then((_)=>{return g.mergeObjectSync(G,_)});else return g.mergeObjectSync(G,W)}get shape(){return this._def.shape()}strict($){return q.errToObj,new T({...this._def,unknownKeys:"strict",...$!==void 0?{errorMap:(Q,G)=>{let X=this._def.errorMap?.(Q,G).message??G.defaultError;if(Q.code==="unrecognized_keys")return{message:q.errToObj($).message??X};return{message:X}}}:{}})}strip(){return new T({...this._def,unknownKeys:"strip"})}passthrough(){return new T({...this._def,unknownKeys:"passthrough"})}extend($){return new T({...this._def,shape:()=>({...this._def.shape(),...$})})}merge($){return new T({unknownKeys:$._def.unknownKeys,catchall:$._def.catchall,shape:()=>({...this._def.shape(),...$._def.shape()}),typeName:U.ZodObject})}setKey($,Q){return this.augment({[$]:Q})}catchall($){return new T({...this._def,catchall:$})}pick($){let Q={};for(let G of L.objectKeys($))if($[G]&&this.shape[G])Q[G]=this.shape[G];return new T({...this._def,shape:()=>Q})}omit($){let Q={};for(let G of L.objectKeys(this.shape))if(!$[G])Q[G]=this.shape[G];return new T({...this._def,shape:()=>Q})}deepPartial(){return S$(this)}partial($){let Q={};for(let G of L.objectKeys(this.shape)){let X=this.shape[G];if($&&!$[G])Q[G]=X;else Q[G]=X.optional()}return new T({...this._def,shape:()=>Q})}required($){let Q={};for(let G of L.objectKeys(this.shape))if($&&!$[G])Q[G]=this.shape[G];else{let Y=this.shape[G];while(Y instanceof d)Y=Y._def.innerType;Q[G]=Y}return new T({...this._def,shape:()=>Q})}keyof(){return P3(L.objectKeys(this.shape))}}T.create=($,Q)=>{return new T({shape:()=>$,unknownKeys:"strip",catchall:a.create(),typeName:U.ZodObject,...D(Q)})};T.strictCreate=($,Q)=>{return new T({shape:()=>$,unknownKeys:"strict",catchall:a.create(),typeName:U.ZodObject,...D(Q)})};T.lazycreate=($,Q)=>{return new T({shape:$,unknownKeys:"strip",catchall:a.create(),typeName:U.ZodObject,...D(Q)})};class R$ extends S{_parse($){let{ctx:Q}=this._processInputParams($),G=this._def.options;function X(Y){for(let H of Y)if(H.result.status==="valid")return H.result;for(let H of Y)if(H.result.status==="dirty")return Q.common.issues.push(...H.ctx.common.issues),H.result;let J=Y.map((H)=>new y(H.ctx.common.issues));return j(Q,{code:B.invalid_union,unionErrors:J}),V}if(Q.common.async)return Promise.all(G.map(async(Y)=>{let J={...Q,common:{...Q.common,issues:[]},parent:null};return{result:await Y._parseAsync({data:Q.data,path:Q.path,parent:J}),ctx:J}})).then(X);else{let Y=void 0,J=[];for(let W of G){let _={...Q,common:{...Q.common,issues:[]},parent:null},z=W._parseSync({data:Q.data,path:Q.path,parent:_});if(z.status==="valid")return z;else if(z.status==="dirty"&&!Y)Y={result:z,ctx:_};if(_.common.issues.length)J.push(_.common.issues)}if(Y)return Q.common.issues.push(...Y.ctx.common.issues),Y.result;let H=J.map((W)=>new y(W));return j(Q,{code:B.invalid_union,unionErrors:H}),V}}get options(){return this._def.options}}R$.create=($,Q)=>{return new R$({options:$,typeName:U.ZodUnion,...D(Q)})};var $$=($)=>{if($ instanceof C$)return $$($.schema);else if($ instanceof n)return $$($.innerType());else if($ instanceof b$)return[$.value];else if($ instanceof _$)return $.options;else if($ instanceof I$)return L.objectValues($.enum);else if($ instanceof k$)return $$($._def.innerType);else if($ instanceof N$)return[void 0];else if($ instanceof O$)return[null];else if($ instanceof d)return[void 0,...$$($.unwrap())];else if($ instanceof Q$)return[null,...$$($.unwrap())];else if($ instanceof a$)return $$($.unwrap());else if($ instanceof f$)return $$($.unwrap());else if($ instanceof v$)return $$($._def.innerType);else return[]};class o$ extends S{_parse($){let{ctx:Q}=this._processInputParams($);if(Q.parsedType!==M.object)return j(Q,{code:B.invalid_type,expected:M.object,received:Q.parsedType}),V;let G=this.discriminator,X=Q.data[G],Y=this.optionsMap.get(X);if(!Y)return j(Q,{code:B.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[G]}),V;if(Q.common.async)return Y._parseAsync({data:Q.data,path:Q.path,parent:Q});else return Y._parseSync({data:Q.data,path:Q.path,parent:Q})}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create($,Q,G){let X=new Map;for(let Y of Q){let J=$$(Y.shape[$]);if(!J.length)throw Error(`A discriminator value for key \`${$}\` could not be extracted from all schema options`);for(let H of J){if(X.has(H))throw Error(`Discriminator property ${String($)} has duplicate value ${String(H)}`);X.set(H,Y)}}return new o$({typeName:U.ZodDiscriminatedUnion,discriminator:$,options:Q,optionsMap:X,...D(G)})}}function j3($,Q){let G=o($),X=o(Q);if($===Q)return{valid:!0,data:$};else if(G===M.object&&X===M.object){let Y=L.objectKeys(Q),J=L.objectKeys($).filter((W)=>Y.indexOf(W)!==-1),H={...$,...Q};for(let W of J){let _=j3($[W],Q[W]);if(!_.valid)return{valid:!1};H[W]=_.data}return{valid:!0,data:H}}else if(G===M.array&&X===M.array){if($.length!==Q.length)return{valid:!1};let Y=[];for(let J=0;J<$.length;J++){let H=$[J],W=Q[J],_=j3(H,W);if(!_.valid)return{valid:!1};Y.push(_.data)}return{valid:!0,data:Y}}else if(G===M.date&&X===M.date&&+$===+Q)return{valid:!0,data:$};else return{valid:!1}}class F$ extends S{_parse($){let{status:Q,ctx:G}=this._processInputParams($),X=(Y,J)=>{if(i$(Y)||i$(J))return V;let H=j3(Y.value,J.value);if(!H.valid)return j(G,{code:B.invalid_intersection_types}),V;if(r$(Y)||r$(J))Q.dirty();return{status:Q.value,value:H.data}};if(G.common.async)return Promise.all([this._def.left._parseAsync({data:G.data,path:G.path,parent:G}),this._def.right._parseAsync({data:G.data,path:G.path,parent:G})]).then(([Y,J])=>X(Y,J));else return X(this._def.left._parseSync({data:G.data,path:G.path,parent:G}),this._def.right._parseSync({data:G.data,path:G.path,parent:G}))}}F$.create=($,Q,G)=>{return new F$({left:$,right:Q,typeName:U.ZodIntersection,...D(G)})};class s extends S{_parse($){let{status:Q,ctx:G}=this._processInputParams($);if(G.parsedType!==M.array)return j(G,{code:B.invalid_type,expected:M.array,received:G.parsedType}),V;if(G.data.length<this._def.items.length)return j(G,{code:B.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),V;if(!this._def.rest&&G.data.length>this._def.items.length)j(G,{code:B.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),Q.dirty();let Y=[...G.data].map((J,H)=>{let W=this._def.items[H]||this._def.rest;if(!W)return null;return W._parse(new p(G,J,G.path,H))}).filter((J)=>!!J);if(G.common.async)return Promise.all(Y).then((J)=>{return g.mergeArray(Q,J)});else return g.mergeArray(Q,Y)}get items(){return this._def.items}rest($){return new s({...this._def,rest:$})}}s.create=($,Q)=>{if(!Array.isArray($))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new s({items:$,typeName:U.ZodTuple,rest:null,...D(Q)})};class y$ extends S{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:Q,ctx:G}=this._processInputParams($);if(G.parsedType!==M.object)return j(G,{code:B.invalid_type,expected:M.object,received:G.parsedType}),V;let X=[],Y=this._def.keyType,J=this._def.valueType;for(let H in G.data)X.push({key:Y._parse(new p(G,H,G.path,H)),value:J._parse(new p(G,G.data[H],G.path,H)),alwaysSet:H in G.data});if(G.common.async)return g.mergeObjectAsync(Q,X);else return g.mergeObjectSync(Q,X)}get element(){return this._def.valueType}static create($,Q,G){if(Q instanceof S)return new y$({keyType:$,valueType:Q,typeName:U.ZodRecord,...D(G)});return new y$({keyType:l.create(),valueType:$,typeName:U.ZodRecord,...D(Q)})}}class m$ extends S{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:Q,ctx:G}=this._processInputParams($);if(G.parsedType!==M.map)return j(G,{code:B.invalid_type,expected:M.map,received:G.parsedType}),V;let X=this._def.keyType,Y=this._def.valueType,J=[...G.data.entries()].map(([H,W],_)=>{return{key:X._parse(new p(G,H,G.path,[_,"key"])),value:Y._parse(new p(G,W,G.path,[_,"value"]))}});if(G.common.async){let H=new Map;return Promise.resolve().then(async()=>{for(let W of J){let _=await W.key,z=await W.value;if(_.status==="aborted"||z.status==="aborted")return V;if(_.status==="dirty"||z.status==="dirty")Q.dirty();H.set(_.value,z.value)}return{status:Q.value,value:H}})}else{let H=new Map;for(let W of J){let{key:_,value:z}=W;if(_.status==="aborted"||z.status==="aborted")return V;if(_.status==="dirty"||z.status==="dirty")Q.dirty();H.set(_.value,z.value)}return{status:Q.value,value:H}}}}m$.create=($,Q,G)=>{return new m$({valueType:Q,keyType:$,typeName:U.ZodMap,...D(G)})};class j$ extends S{_parse($){let{status:Q,ctx:G}=this._processInputParams($);if(G.parsedType!==M.set)return j(G,{code:B.invalid_type,expected:M.set,received:G.parsedType}),V;let X=this._def;if(X.minSize!==null){if(G.data.size<X.minSize.value)j(G,{code:B.too_small,minimum:X.minSize.value,type:"set",inclusive:!0,exact:!1,message:X.minSize.message}),Q.dirty()}if(X.maxSize!==null){if(G.data.size>X.maxSize.value)j(G,{code:B.too_big,maximum:X.maxSize.value,type:"set",inclusive:!0,exact:!1,message:X.maxSize.message}),Q.dirty()}let Y=this._def.valueType;function J(W){let _=new Set;for(let z of W){if(z.status==="aborted")return V;if(z.status==="dirty")Q.dirty();_.add(z.value)}return{status:Q.value,value:_}}let H=[...G.data.values()].map((W,_)=>Y._parse(new p(G,W,G.path,_)));if(G.common.async)return Promise.all(H).then((W)=>J(W));else return J(H)}min($,Q){return new j$({...this._def,minSize:{value:$,message:q.toString(Q)}})}max($,Q){return new j$({...this._def,maxSize:{value:$,message:q.toString(Q)}})}size($,Q){return this.min($,Q).max($,Q)}nonempty($){return this.min(1,$)}}j$.create=($,Q)=>{return new j$({valueType:$,minSize:null,maxSize:null,typeName:U.ZodSet,...D(Q)})};class K$ extends S{constructor(){super(...arguments);this.validate=this.implement}_parse($){let{ctx:Q}=this._processInputParams($);if(Q.parsedType!==M.function)return j(Q,{code:B.invalid_type,expected:M.function,received:Q.parsedType}),V;function G(H,W){return g$({data:H,path:Q.path,errorMaps:[Q.common.contextualErrorMap,Q.schemaErrorMap,A$(),e].filter((_)=>!!_),issueData:{code:B.invalid_arguments,argumentsError:W}})}function X(H,W){return g$({data:H,path:Q.path,errorMaps:[Q.common.contextualErrorMap,Q.schemaErrorMap,A$(),e].filter((_)=>!!_),issueData:{code:B.invalid_return_type,returnTypeError:W}})}let Y={errorMap:Q.common.contextualErrorMap},J=Q.data;if(this._def.returns instanceof w$){let H=this;return Z(async function(...W){let _=new y([]),z=await H._def.args.parseAsync(W,Y).catch((N)=>{throw _.addIssue(G(W,N)),_}),w=await Reflect.apply(J,this,z);return await H._def.returns._def.type.parseAsync(w,Y).catch((N)=>{throw _.addIssue(X(w,N)),_})})}else{let H=this;return Z(function(...W){let _=H._def.args.safeParse(W,Y);if(!_.success)throw new y([G(W,_.error)]);let z=Reflect.apply(J,this,_.data),w=H._def.returns.safeParse(z,Y);if(!w.success)throw new y([X(z,w.error)]);return w.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...$){return new K$({...this._def,args:s.create($).rest(H$.create())})}returns($){return new K$({...this._def,returns:$})}implement($){return this.parse($)}strictImplement($){return this.parse($)}static create($,Q,G){return new K$({args:$?$:s.create([]).rest(H$.create()),returns:Q||H$.create(),typeName:U.ZodFunction,...D(G)})}}class C$ extends S{get schema(){return this._def.getter()}_parse($){let{ctx:Q}=this._processInputParams($);return this._def.getter()._parse({data:Q.data,path:Q.path,parent:Q})}}C$.create=($,Q)=>{return new C$({getter:$,typeName:U.ZodLazy,...D(Q)})};class b$ extends S{_parse($){if($.data!==this._def.value){let Q=this._getOrReturnCtx($);return j(Q,{received:Q.data,code:B.invalid_literal,expected:this._def.value}),V}return{status:"valid",value:$.data}}get value(){return this._def.value}}b$.create=($,Q)=>{return new b$({value:$,typeName:U.ZodLiteral,...D(Q)})};function P3($,Q){return new _$({values:$,typeName:U.ZodEnum,...D(Q)})}class _$ extends S{_parse($){if(typeof $.data!=="string"){let Q=this._getOrReturnCtx($),G=this._def.values;return j(Q,{expected:L.joinValues(G),received:Q.parsedType,code:B.invalid_type}),V}if(!this._cache)this._cache=new Set(this._def.values);if(!this._cache.has($.data)){let Q=this._getOrReturnCtx($),G=this._def.values;return j(Q,{received:Q.data,code:B.invalid_enum_value,options:G}),V}return Z($.data)}get options(){return this._def.values}get enum(){let $={};for(let Q of this._def.values)$[Q]=Q;return $}get Values(){let $={};for(let Q of this._def.values)$[Q]=Q;return $}get Enum(){let $={};for(let Q of this._def.values)$[Q]=Q;return $}extract($,Q=this._def){return _$.create($,{...this._def,...Q})}exclude($,Q=this._def){return _$.create(this.options.filter((G)=>!$.includes(G)),{...this._def,...Q})}}_$.create=P3;class I$ extends S{_parse($){let Q=L.getValidEnumValues(this._def.values),G=this._getOrReturnCtx($);if(G.parsedType!==M.string&&G.parsedType!==M.number){let X=L.objectValues(Q);return j(G,{expected:L.joinValues(X),received:G.parsedType,code:B.invalid_type}),V}if(!this._cache)this._cache=new Set(L.getValidEnumValues(this._def.values));if(!this._cache.has($.data)){let X=L.objectValues(Q);return j(G,{received:G.data,code:B.invalid_enum_value,options:X}),V}return Z($.data)}get enum(){return this._def.values}}I$.create=($,Q)=>{return new I$({values:$,typeName:U.ZodNativeEnum,...D(Q)})};class w$ extends S{unwrap(){return this._def.type}_parse($){let{ctx:Q}=this._processInputParams($);if(Q.parsedType!==M.promise&&Q.common.async===!1)return j(Q,{code:B.invalid_type,expected:M.promise,received:Q.parsedType}),V;let G=Q.parsedType===M.promise?Q.data:Promise.resolve(Q.data);return Z(G.then((X)=>{return this._def.type.parseAsync(X,{path:Q.path,errorMap:Q.common.contextualErrorMap})}))}}w$.create=($,Q)=>{return new w$({type:$,typeName:U.ZodPromise,...D(Q)})};class n extends S{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===U.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse($){let{status:Q,ctx:G}=this._processInputParams($),X=this._def.effect||null,Y={addIssue:(J)=>{if(j(G,J),J.fatal)Q.abort();else Q.dirty()},get path(){return G.path}};if(Y.addIssue=Y.addIssue.bind(Y),X.type==="preprocess"){let J=X.transform(G.data,Y);if(G.common.async)return Promise.resolve(J).then(async(H)=>{if(Q.value==="aborted")return V;let W=await this._def.schema._parseAsync({data:H,path:G.path,parent:G});if(W.status==="aborted")return V;if(W.status==="dirty")return z$(W.value);if(Q.value==="dirty")return z$(W.value);return W});else{if(Q.value==="aborted")return V;let H=this._def.schema._parseSync({data:J,path:G.path,parent:G});if(H.status==="aborted")return V;if(H.status==="dirty")return z$(H.value);if(Q.value==="dirty")return z$(H.value);return H}}if(X.type==="refinement"){let J=(H)=>{let W=X.refinement(H,Y);if(G.common.async)return Promise.resolve(W);if(W instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return H};if(G.common.async===!1){let H=this._def.schema._parseSync({data:G.data,path:G.path,parent:G});if(H.status==="aborted")return V;if(H.status==="dirty")Q.dirty();return J(H.value),{status:Q.value,value:H.value}}else return this._def.schema._parseAsync({data:G.data,path:G.path,parent:G}).then((H)=>{if(H.status==="aborted")return V;if(H.status==="dirty")Q.dirty();return J(H.value).then(()=>{return{status:Q.value,value:H.value}})})}if(X.type==="transform")if(G.common.async===!1){let J=this._def.schema._parseSync({data:G.data,path:G.path,parent:G});if(!Y$(J))return V;let H=X.transform(J.value,Y);if(H instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:Q.value,value:H}}else return this._def.schema._parseAsync({data:G.data,path:G.path,parent:G}).then((J)=>{if(!Y$(J))return V;return Promise.resolve(X.transform(J.value,Y)).then((H)=>({status:Q.value,value:H}))});L.assertNever(X)}}n.create=($,Q,G)=>{return new n({schema:$,typeName:U.ZodEffects,effect:Q,...D(G)})};n.createWithPreprocess=($,Q,G)=>{return new n({schema:Q,effect:{type:"preprocess",transform:$},typeName:U.ZodEffects,...D(G)})};class d extends S{_parse($){if(this._getType($)===M.undefined)return Z(void 0);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}d.create=($,Q)=>{return new d({innerType:$,typeName:U.ZodOptional,...D(Q)})};class Q$ extends S{_parse($){if(this._getType($)===M.null)return Z(null);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}Q$.create=($,Q)=>{return new Q$({innerType:$,typeName:U.ZodNullable,...D(Q)})};class k$ extends S{_parse($){let{ctx:Q}=this._processInputParams($),G=Q.data;if(Q.parsedType===M.undefined)G=this._def.defaultValue();return this._def.innerType._parse({data:G,path:Q.path,parent:Q})}removeDefault(){return this._def.innerType}}k$.create=($,Q)=>{return new k$({innerType:$,typeName:U.ZodDefault,defaultValue:typeof Q.default==="function"?Q.default:()=>Q.default,...D(Q)})};class v$ extends S{_parse($){let{ctx:Q}=this._processInputParams($),G={...Q,common:{...Q.common,issues:[]}},X=this._def.innerType._parse({data:G.data,path:G.path,parent:{...G}});if(D$(X))return X.then((Y)=>{return{status:"valid",value:Y.status==="valid"?Y.value:this._def.catchValue({get error(){return new y(G.common.issues)},input:G.data})}});else return{status:"valid",value:X.status==="valid"?X.value:this._def.catchValue({get error(){return new y(G.common.issues)},input:G.data})}}removeCatch(){return this._def.innerType}}v$.create=($,Q)=>{return new v$({innerType:$,typeName:U.ZodCatch,catchValue:typeof Q.catch==="function"?Q.catch:()=>Q.catch,...D(Q)})};class c$ extends S{_parse($){if(this._getType($)!==M.nan){let G=this._getOrReturnCtx($);return j(G,{code:B.invalid_type,expected:M.nan,received:G.parsedType}),V}return{status:"valid",value:$.data}}}c$.create=($)=>{return new c$({typeName:U.ZodNaN,...D($)})};var mQ=Symbol("zod_brand");class a$ extends S{_parse($){let{ctx:Q}=this._processInputParams($),G=Q.data;return this._def.type._parse({data:G,path:Q.path,parent:Q})}unwrap(){return this._def.type}}class l$ extends S{_parse($){let{status:Q,ctx:G}=this._processInputParams($);if(G.common.async)return(async()=>{let Y=await this._def.in._parseAsync({data:G.data,path:G.path,parent:G});if(Y.status==="aborted")return V;if(Y.status==="dirty")return Q.dirty(),z$(Y.value);else return this._def.out._parseAsync({data:Y.value,path:G.path,parent:G})})();else{let X=this._def.in._parseSync({data:G.data,path:G.path,parent:G});if(X.status==="aborted")return V;if(X.status==="dirty")return Q.dirty(),{status:"dirty",value:X.value};else return this._def.out._parseSync({data:X.value,path:G.path,parent:G})}}static create($,Q){return new l$({in:$,out:Q,typeName:U.ZodPipeline})}}class f$ extends S{_parse($){let Q=this._def.innerType._parse($),G=(X)=>{if(Y$(X))X.value=Object.freeze(X.value);return X};return D$(Q)?Q.then((X)=>G(X)):G(Q)}unwrap(){return this._def.innerType}}f$.create=($,Q)=>{return new f$({innerType:$,typeName:U.ZodReadonly,...D(Q)})};function k3($,Q){let G=typeof $==="function"?$(Q):typeof $==="string"?{message:$}:$;return typeof G==="string"?{message:G}:G}function x3($,Q={},G){if($)return M$.create().superRefine((X,Y)=>{let J=$(X);if(J instanceof Promise)return J.then((H)=>{if(!H){let W=k3(Q,X),_=W.fatal??G??!0;Y.addIssue({code:"custom",...W,fatal:_})}});if(!J){let H=k3(Q,X),W=H.fatal??G??!0;Y.addIssue({code:"custom",...H,fatal:W})}return});return M$.create()}var cQ={object:T.lazycreate},U;(function($){$.ZodString="ZodString",$.ZodNumber="ZodNumber",$.ZodNaN="ZodNaN",$.ZodBigInt="ZodBigInt",$.ZodBoolean="ZodBoolean",$.ZodDate="ZodDate",$.ZodSymbol="ZodSymbol",$.ZodUndefined="ZodUndefined",$.ZodNull="ZodNull",$.ZodAny="ZodAny",$.ZodUnknown="ZodUnknown",$.ZodNever="ZodNever",$.ZodVoid="ZodVoid",$.ZodArray="ZodArray",$.ZodObject="ZodObject",$.ZodUnion="ZodUnion",$.ZodDiscriminatedUnion="ZodDiscriminatedUnion",$.ZodIntersection="ZodIntersection",$.ZodTuple="ZodTuple",$.ZodRecord="ZodRecord",$.ZodMap="ZodMap",$.ZodSet="ZodSet",$.ZodFunction="ZodFunction",$.ZodLazy="ZodLazy",$.ZodLiteral="ZodLiteral",$.ZodEnum="ZodEnum",$.ZodEffects="ZodEffects",$.ZodNativeEnum="ZodNativeEnum",$.ZodOptional="ZodOptional",$.ZodNullable="ZodNullable",$.ZodDefault="ZodDefault",$.ZodCatch="ZodCatch",$.ZodPromise="ZodPromise",$.ZodBranded="ZodBranded",$.ZodPipeline="ZodPipeline",$.ZodReadonly="ZodReadonly"})(U||(U={}));var lQ=($,Q={message:`Input not instance of ${$.name}`})=>x3((G)=>G instanceof $,Q),g3=l.create,Z3=J$.create,uQ=c$.create,dQ=W$.create,h3=L$.create,pQ=B$.create,nQ=Z$.create,iQ=N$.create,rQ=O$.create,oQ=M$.create,aQ=H$.create,sQ=a.create,tQ=h$.create,eQ=u.create,$0=T.create,Q0=T.strictCreate,G0=R$.create,X0=o$.create,Y0=F$.create,H0=s.create,J0=y$.create,W0=m$.create,_0=j$.create,z0=K$.create,B0=C$.create,M0=b$.create,j0=_$.create,w0=I$.create,q0=w$.create,V0=n.create,E0=d.create,U0=Q$.create,A0=n.createWithPreprocess,D0=l$.create,S0=()=>g3().optional(),K0=()=>Z3().optional(),L0=()=>h3().optional(),N0={string:($)=>l.create({...$,coerce:!0}),number:($)=>J$.create({...$,coerce:!0}),boolean:($)=>L$.create({...$,coerce:!0}),bigint:($)=>W$.create({...$,coerce:!0}),date:($)=>B$.create({...$,coerce:!0})};var O0=V;function y3($){if(!$.name)throw Error("Plugin must have a name");if(typeof $.name!=="string"||$.name.trim()==="")throw Error("Plugin name must be a non-empty string");if($.instanceId!==void 0&&typeof $.instanceId!=="string")throw Error("Plugin instanceId must be a string");if($.version!==void 0&&typeof $.version!=="string")throw Error("Plugin version must be a string");if($.permissions!==void 0){if(!Array.isArray($.permissions))throw Error("Plugin permissions must be an array");let Q=["secrets","network","filesystem","env","subprocess","enterprise"];for(let G of $.permissions)if(!Q.includes(G))throw Error(`Invalid permission: ${G}. Valid permissions are: ${Q.join(", ")}`)}if($.resolvers!==void 0){if(typeof $.resolvers!=="object"||$.resolvers===null)throw Error("Plugin resolvers must be an object");for(let[Q,G]of Object.entries($.resolvers)){if(!Q.startsWith("$"))throw Error(`Resolver name "${Q}" must start with $ (e.g., "$${Q}")`);if(typeof G!=="function")throw Error(`Resolver "${Q}" must be a function`)}}if($.hooks!==void 0){if(typeof $.hooks!=="object"||$.hooks===null)throw Error("Plugin hooks must be an object");let Q=["parse.after","request.before","request.compiled","request.after","response.after","error"];for(let[G,X]of Object.entries($.hooks)){if(!Q.includes(G))throw Error(`Invalid hook: "${G}". Valid hooks are: ${Q.join(", ")}`);if(typeof X!=="function")throw Error(`Hook "${G}" must be a function`)}}if($.commands!==void 0){if(typeof $.commands!=="object"||$.commands===null)throw Error("Plugin commands must be an object");for(let[Q,G]of Object.entries($.commands))if(typeof G!=="function")throw Error(`Command "${Q}" must be a function`)}if($.middleware!==void 0){if(!Array.isArray($.middleware))throw Error("Plugin middleware must be an array");for(let Q=0;Q<$.middleware.length;Q++)if(typeof $.middleware[Q]!=="function")throw Error(`Middleware at index ${Q} must be a function`)}if($.tools!==void 0){if(typeof $.tools!=="object"||$.tools===null)throw Error("Plugin tools must be an object");for(let[Q,G]of Object.entries($.tools)){if(typeof G.description!=="string")throw Error(`Tool "${Q}" must have a description`);if(typeof G.args!=="object"||G.args===null)throw Error(`Tool "${Q}" must have args schema`);if(typeof G.execute!=="function")throw Error(`Tool "${Q}" must have an execute function`)}}if($.event!==void 0&&typeof $.event!=="function")throw Error("Plugin event handler must be a function");if($.setup!==void 0&&typeof $.setup!=="function")throw Error("Plugin setup must be a function");if($.teardown!==void 0&&typeof $.teardown!=="function")throw Error("Plugin teardown must be a function");return{...$,instanceId:$.instanceId??"default"}}function m3($){let Q=q$.object($.args);return{description:$.description,args:Q,execute:async(G,X)=>{let Y=Q.parse(G);return await $.execute(Y,X)}}}function T$($){return`${$.name}#${$.instanceId??"default"}`}function c3($){let Q=$.indexOf("#");if(Q===-1)return{name:$,instanceId:"default"};return{name:$.slice(0,Q),instanceId:$.slice(Q+1)}}function w3($){return typeof $==="object"&&$!==null&&!Array.isArray($)&&"command"in $&&Array.isArray($.command)}function l3($){return typeof $==="object"&&$!==null&&!Array.isArray($)&&"name"in $&&typeof $.name==="string"&&!("command"in $)}function R0($){if(typeof $==="string")return $.startsWith("file://");if(Array.isArray($)&&typeof $[0]==="string")return $[0].startsWith("file://");return!1}function F0($){if(typeof $==="string")return!$.startsWith("file://")&&!w3($);if(Array.isArray($)&&typeof $[0]==="string")return!$[0].startsWith("file://");return!1}function u3($,Q){let G=U$("node:path"),X=G.relative(Q,$);return!X.startsWith("..")&&!G.isAbsolute(X)}function d3($,Q,G){if(!$.startsWith("file://"))throw Error(`Invalid file URL: ${$}`);let X=U$("node:path"),Y=$.slice(7),J;if(Y.startsWith("/"))J=X.normalize(Y);else if(Y.startsWith("./")||Y.startsWith("../"))J=X.resolve(Q,Y);else throw Error(`Invalid file plugin path: ${$}. Use file://./relative/path.ts or file:///absolute/path.ts`);if(!G&&!u3(J,Q))throw Error(`Plugin path "${$}" resolves outside project root. Set security.allowPluginsOutsideProject: true to allow.`);return J}async function C0($,Q,G){let X=U$("node:fs/promises");if(G)return $;try{let Y=await X.realpath($);if(!u3(Y,Q))throw Error(`Plugin path "${$}" resolves to "${Y}" which is outside project root. Symlinks pointing outside the project are not allowed. Set security.allowPluginsOutsideProject: true to allow.`);return Y}catch(Y){if(Y.code==="ENOENT")return $;throw Y}}function s$($,Q,G){let X=$.permissions??[],Y=Q?.[$.name];if(Y!==void 0){for(let H of X)if(!Y.includes(H))G.push(`Plugin '${$.name}' requires '${H}' permission but it was denied. Some features may not work. Add to security.pluginPermissions to enable.`);return Y}let J=Q?.default;if(J!==void 0){let H=X.filter((W)=>J.includes(W));for(let W of X)if(!J.includes(W))G.push(`Plugin '${$.name}' requires '${W}' permission but it was denied by default. Some features may not work. Add to security.pluginPermissions to enable.`);return H}return X}async function t$($){let{projectRoot:Q,plugins:G,security:X,pluginPermissions:Y}=$,J=$.warnings??[],H=[],W=new Map;for(let _ of G)try{let z=await b0(_,{projectRoot:Q,allowOutsideProject:X?.allowPluginsOutsideProject??!1,warnings:J,...Y!==void 0?{pluginPermissions:Y}:{}});if(!z)continue;let w=T$(z.plugin),E=W.get(w);if(E!==void 0)H[E]=z;else W.set(w,H.length),H.push(z)}catch(z){let w=z instanceof Error?z.message:String(z);J.push(`Failed to load plugin: ${w}`)}return{plugins:H,warnings:J}}async function b0($,Q){let{projectRoot:G,allowOutsideProject:X,pluginPermissions:Y,warnings:J}=Q;if(l3($)){let _=s$($,Y,J);return{plugin:{...$,instanceId:$.instanceId??"default"},id:T$($),source:"inline",permissions:_,initialized:!1}}if(w3($))return{plugin:{name:`subprocess:${$.command.join(" ")}`,instanceId:"default"},id:`subprocess:${$.command.join(" ")}#default`,source:"subprocess",permissions:[],initialized:!1,_subprocessConfig:$};let H,W;if(Array.isArray($))H=$[0],W=$[1];else H=$;if(H.startsWith("file://")){let _=d3(H,G,X);return await I0(_,W,Y,J,G,X)}return await k0(H,W,Y,J)}async function I0($,Q,G,X,Y,J){try{let H=$;if(Y!==void 0)H=await C0($,Y,J??!1);let W=await import(H),_=W.default??W,z;if(typeof _==="function")z=Q?_(Q):_();else if(typeof _==="object"&&_!==null)z=_;else throw Error(`File "${$}" does not export a valid plugin`);if(z={...z,instanceId:z.instanceId??"default"},Q&&typeof Q.instanceId==="string")z={...z,instanceId:Q.instanceId};let w=s$(z,G,X);return{plugin:z,id:T$(z),source:"file",permissions:w,initialized:!1}}catch(H){throw Error(`Failed to load plugin from "${$}": ${H instanceof Error?H.message:String(H)}`)}}async function k0($,Q,G,X){try{let Y=$,J=$.lastIndexOf("@");if(J>0)Y=$.slice(0,J);let H=await import(Y),W=H.default??H,_;if(typeof W==="function")_=Q?W(Q):W();else if(typeof W==="object"&&W!==null)_=W;else throw Error(`Package "${Y}" does not export a valid plugin`);if(_={..._,instanceId:_.instanceId??"default"},Q&&typeof Q.instanceId==="string")_={..._,instanceId:Q.instanceId};let z=s$(_,G,X);return{plugin:_,id:T$(_),source:"npm",permissions:z,initialized:!1}}catch(Y){throw Error(`Failed to load plugin "${$}": ${Y instanceof Error?Y.message:String(Y)}`)}}function v0($,Q){return[...$,...Q]}class $3 extends Error{permission;pluginName;constructor($,Q){super(`Plugin "${Q}" does not have "${$}" permission`);this.permission=$;this.pluginName=Q;this.name="PermissionDeniedError"}}class p3{secrets=new Map;constructor($){if($)for(let[Q,G]of Object.entries($))this.secrets.set(Q,G)}async get($){return this.secrets.get($)}set($,Q){this.secrets.set($,Q)}}function e$($,Q,G){let X=G.relative(Q,$);return!X.startsWith("..")&&!G.isAbsolute(X)}function f0($,Q){let G=U$("node:fs/promises"),X=U$("node:path"),Y=async(H)=>{let W=X.resolve($,H);if(!Q&&!e$(W,$,X))throw Error(`Path "${H}" is outside project root. Plugins need "filesystem" permission to access files outside project.`);if(!Q)try{let _=await G.realpath(W);if(!e$(_,$,X))throw Error(`Path "${H}" resolves to "${_}" which is outside project root. Symlinks pointing outside the project are not allowed.`);return _}catch(_){if(_.code==="ENOENT")return W;throw _}return W},J=async(H)=>{let W=X.resolve($,H);if(!Q&&!e$(W,$,X))throw Error(`Path "${H}" is outside project root. Plugins need "filesystem" permission to access files outside project.`);if(!Q){let _=X.dirname(W);try{let z=await G.realpath(_);if(!e$(z,$,X))throw Error(`Path "${H}" parent directory resolves to "${z}" which is outside project root. Symlinks pointing outside the project are not allowed.`)}catch(z){if(z.code!=="ENOENT")throw z}}return W};return{async readFile(H){let W=await Y(H);return await G.readFile(W,"utf-8")},async writeFile(H,W){let _=await J(H);await G.writeFile(_,W,"utf-8")}}}function T0($){let Q=U$("node:child_process");return async(G,X)=>{return new Promise((Y,J)=>{let H=Q.spawn(G,X,{cwd:$,stdio:["pipe","pipe","pipe"]}),W="",_="";H.stdout?.on("data",(z)=>{W+=z.toString("utf-8")}),H.stderr?.on("data",(z)=>{_+=z.toString("utf-8")}),H.on("close",(z)=>{if(z===0)Y({stdout:W,stderr:_});else J(Error(`Command failed with code ${z}: ${_}`))}),H.on("error",(z)=>{J(z)})})}}function P0($){let Q=`[plugin:${$}]`;return{debug:(G)=>{if(process.env.DEBUG)console.debug(`${Q} ${G}`)},info:(G)=>{console.info(`${Q} ${G}`)},warn:(G)=>{console.warn(`${Q} ${G}`)},error:(G)=>{console.error(`${Q} ${G}`)}}}function Q3($){let{plugin:Q,permissions:G,config:X,enterprise:Y,secrets:J}=$,H=Q.name,W={projectRoot:X.projectRoot,config:X,log:P0(H)};if(G.includes("secrets"))W.secrets=new p3(J);if(G.includes("network"))W.fetch=globalThis.fetch;if(G.includes("filesystem"))W.fs=f0(X.projectRoot,X.security.allowPluginsOutsideProject);if(G.includes("env"))W.env=process.env;if(G.includes("subprocess"))W.spawn=T0(X.projectRoot);if(G.includes("enterprise")&&Y)W.enterprise=Y;return W}function x0($,Q,G){let X=[];for(let Y of G)if(!Q.includes(Y))X.push(`Plugin "${$.name}" requires "${Y}" permission but it was denied.`);return X}function n3($,Q){return $.includes(Q)}function g0($,Q,G){if(!n3($,Q))throw new $3(Q,G)}import{spawn as Z0}from"node:child_process";function P($){let Q={...$},G={when(X,Y){if(X)Q={...Q,...Y};return G},ifDefined(X,Y){if(Y!==void 0)Q={...Q,[X]:Y};return G},build(){return Q}};return G}var q3=1,h0=5000,y0=1e4,i3=3,m0=500,c0=10485760;class G3{config;projectRoot;process=null;requestId=0;pendingRequests=new Map;buffer="";initialized=!1;restartCount=0;capabilities={hooks:[],resolvers:[],commands:[]};pluginInfo={name:"unknown"};constructor($,Q){this.config=$;this.projectRoot=Q}async start(){await this.spawn(),await this.initialize()}async spawn(){let[$,...Q]=this.config.command;if(!$)throw Error("Subprocess plugin has empty command");this.process=Z0($,Q,{cwd:this.projectRoot,stdio:["pipe","pipe","pipe"],env:this.config.env??{}}),this.process.stdout?.on("data",(G)=>{this.handleStdout(G)}),this.process.stderr?.on("data",(G)=>{let X=G.toString("utf-8").trim();if(X)console.error(`[subprocess:${this.pluginInfo.name}] ${X}`)}),this.process.on("close",(G,X)=>{this.handleClose(G,X)}),this.process.on("error",(G)=>{this.handleError(G)})}async initialize(){let $=this.config.startupTimeoutMs??y0,Q=await this.sendRequest({id:this.nextId(),type:"init",protocolVersion:q3,config:this.config.config??{},projectRoot:this.projectRoot},$);if(Q.type==="error")throw Error(`Plugin init failed: ${Q.error.message}`);let X=Q.result;if(X.protocolVersion>q3)throw Error(`Plugin requires protocol version ${X.protocolVersion}, but t-req supports version ${q3}`);this.pluginInfo=P({name:X.name}).ifDefined("version",X.version).ifDefined("permissions",X.permissions).build(),this.capabilities={hooks:X.hooks??[],resolvers:X.resolvers??[],commands:X.commands??[]},this.initialized=!0}handleStdout($){if(this.buffer.length+$.length>c0){this.buffer="",console.error(`[subprocess:${this.pluginInfo.name}] stdout buffer exceeded, clearing`);return}this.buffer+=$.toString("utf-8");let Q=this.buffer.split(`
|
|
2
|
-
`);this.buffer=Q.pop()??"";for(let
|
|
1
|
+
import{createRequire as O1}from"node:module";var q1=Object.defineProperty;var N1=($,Q)=>{for(var W in Q)q1($,W,{get:Q[W],enumerable:!0,configurable:!0,set:(X)=>Q[W]=()=>X})};var Q$=O1(import.meta.url);var M$={};N1(M$,{void:()=>_3,util:()=>b,unknown:()=>J3,union:()=>M3,undefined:()=>X3,tuple:()=>E3,transformer:()=>F3,symbol:()=>W3,string:()=>c0,strictObject:()=>w3,setErrorMap:()=>C1,set:()=>D3,record:()=>V3,quotelessJson:()=>F1,promise:()=>O3,preprocess:()=>b3,pipeline:()=>I3,ostring:()=>k3,optional:()=>R3,onumber:()=>v3,oboolean:()=>f3,objectUtil:()=>w0,object:()=>B3,number:()=>l0,nullable:()=>C3,null:()=>G3,never:()=>H3,nativeEnum:()=>N3,nan:()=>e1,map:()=>A3,makeIssue:()=>P$,literal:()=>L3,lazy:()=>S3,late:()=>s1,isValid:()=>W$,isDirty:()=>o$,isAsync:()=>V$,isAborted:()=>r$,intersection:()=>U3,instanceof:()=>t1,getParsedType:()=>r,getErrorMap:()=>E$,function:()=>K3,enum:()=>q3,effect:()=>F3,discriminatedUnion:()=>j3,defaultErrorMap:()=>t,datetimeRegex:()=>h0,date:()=>Q3,custom:()=>m0,coerce:()=>T3,boolean:()=>u0,bigint:()=>$3,array:()=>z3,any:()=>Y3,addIssueToContext:()=>M,ZodVoid:()=>g$,ZodUnknown:()=>X$,ZodUnion:()=>q$,ZodUndefined:()=>S$,ZodType:()=>C,ZodTuple:()=>a,ZodTransformer:()=>i,ZodSymbol:()=>x$,ZodString:()=>u,ZodSet:()=>B$,ZodSchema:()=>C,ZodRecord:()=>Z$,ZodReadonly:()=>I$,ZodPromise:()=>w$,ZodPipeline:()=>m$,ZodParsedType:()=>w,ZodOptional:()=>n,ZodObject:()=>g,ZodNumber:()=>G$,ZodNullable:()=>$$,ZodNull:()=>L$,ZodNever:()=>o,ZodNativeEnum:()=>R$,ZodNaN:()=>y$,ZodMap:()=>h$,ZodLiteral:()=>F$,ZodLazy:()=>O$,ZodIssueCode:()=>B,ZodIntersection:()=>N$,ZodFunction:()=>D$,ZodFirstPartyTypeKind:()=>K,ZodError:()=>m,ZodEnum:()=>J$,ZodEffects:()=>i,ZodDiscriminatedUnion:()=>a$,ZodDefault:()=>C$,ZodDate:()=>_$,ZodCatch:()=>b$,ZodBranded:()=>s$,ZodBoolean:()=>K$,ZodBigInt:()=>Y$,ZodArray:()=>d,ZodAny:()=>z$,Schema:()=>C,ParseStatus:()=>Z,OK:()=>h,NEVER:()=>P3,INVALID:()=>D,EMPTY_PATH:()=>b1,DIRTY:()=>H$,BRAND:()=>a1});var b;(function($){$.assertEqual=(G)=>{};function Q(G){}$.assertIs=Q;function W(G){throw Error()}$.assertNever=W,$.arrayToEnum=(G)=>{let J={};for(let Y of G)J[Y]=Y;return J},$.getValidEnumValues=(G)=>{let J=$.objectKeys(G).filter((H)=>typeof G[G[H]]!=="number"),Y={};for(let H of J)Y[H]=G[H];return $.objectValues(Y)},$.objectValues=(G)=>{return $.objectKeys(G).map(function(J){return G[J]})},$.objectKeys=typeof Object.keys==="function"?(G)=>Object.keys(G):(G)=>{let J=[];for(let Y in G)if(Object.prototype.hasOwnProperty.call(G,Y))J.push(Y);return J},$.find=(G,J)=>{for(let Y of G)if(J(Y))return Y;return},$.isInteger=typeof Number.isInteger==="function"?(G)=>Number.isInteger(G):(G)=>typeof G==="number"&&Number.isFinite(G)&&Math.floor(G)===G;function X(G,J=" | "){return G.map((Y)=>typeof Y==="string"?`'${Y}'`:Y).join(J)}$.joinValues=X,$.jsonStringifyReplacer=(G,J)=>{if(typeof J==="bigint")return J.toString();return J}})(b||(b={}));var w0;(function($){$.mergeShapes=(Q,W)=>{return{...Q,...W}}})(w0||(w0={}));var w=b.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),r=($)=>{switch(typeof $){case"undefined":return w.undefined;case"string":return w.string;case"number":return Number.isNaN($)?w.nan:w.number;case"boolean":return w.boolean;case"function":return w.function;case"bigint":return w.bigint;case"symbol":return w.symbol;case"object":if(Array.isArray($))return w.array;if($===null)return w.null;if($.then&&typeof $.then==="function"&&$.catch&&typeof $.catch==="function")return w.promise;if(typeof Map<"u"&&$ instanceof Map)return w.map;if(typeof Set<"u"&&$ instanceof Set)return w.set;if(typeof Date<"u"&&$ instanceof Date)return w.date;return w.object;default:return w.unknown}};var B=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"]),F1=($)=>{return JSON.stringify($,null,2).replace(/"([^"]+)":/g,"$1:")};class m extends Error{get errors(){return this.issues}constructor($){super();this.issues=[],this.addIssue=(W)=>{this.issues=[...this.issues,W]},this.addIssues=(W=[])=>{this.issues=[...this.issues,...W]};let Q=new.target.prototype;if(Object.setPrototypeOf)Object.setPrototypeOf(this,Q);else this.__proto__=Q;this.name="ZodError",this.issues=$}format($){let Q=$||function(G){return G.message},W={_errors:[]},X=(G)=>{for(let J of G.issues)if(J.code==="invalid_union")J.unionErrors.map(X);else if(J.code==="invalid_return_type")X(J.returnTypeError);else if(J.code==="invalid_arguments")X(J.argumentsError);else if(J.path.length===0)W._errors.push(Q(J));else{let Y=W,H=0;while(H<J.path.length){let _=J.path[H];if(H!==J.path.length-1)Y[_]=Y[_]||{_errors:[]};else Y[_]=Y[_]||{_errors:[]},Y[_]._errors.push(Q(J));Y=Y[_],H++}}};return X(this),W}static assert($){if(!($ instanceof m))throw Error(`Not a ZodError: ${$}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,b.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten($=(Q)=>Q.message){let Q={},W=[];for(let X of this.issues)if(X.path.length>0){let G=X.path[0];Q[G]=Q[G]||[],Q[G].push($(X))}else W.push($(X));return{formErrors:W,fieldErrors:Q}}get formErrors(){return this.flatten()}}m.create=($)=>{return new m($)};var R1=($,Q)=>{let W;switch($.code){case B.invalid_type:if($.received===w.undefined)W="Required";else W=`Expected ${$.expected}, received ${$.received}`;break;case B.invalid_literal:W=`Invalid literal value, expected ${JSON.stringify($.expected,b.jsonStringifyReplacer)}`;break;case B.unrecognized_keys:W=`Unrecognized key(s) in object: ${b.joinValues($.keys,", ")}`;break;case B.invalid_union:W="Invalid input";break;case B.invalid_union_discriminator:W=`Invalid discriminator value. Expected ${b.joinValues($.options)}`;break;case B.invalid_enum_value:W=`Invalid enum value. Expected ${b.joinValues($.options)}, received '${$.received}'`;break;case B.invalid_arguments:W="Invalid function arguments";break;case B.invalid_return_type:W="Invalid function return type";break;case B.invalid_date:W="Invalid date";break;case B.invalid_string:if(typeof $.validation==="object")if("includes"in $.validation){if(W=`Invalid input: must include "${$.validation.includes}"`,typeof $.validation.position==="number")W=`${W} at one or more positions greater than or equal to ${$.validation.position}`}else if("startsWith"in $.validation)W=`Invalid input: must start with "${$.validation.startsWith}"`;else if("endsWith"in $.validation)W=`Invalid input: must end with "${$.validation.endsWith}"`;else b.assertNever($.validation);else if($.validation!=="regex")W=`Invalid ${$.validation}`;else W="Invalid";break;case B.too_small:if($.type==="array")W=`Array must contain ${$.exact?"exactly":$.inclusive?"at least":"more than"} ${$.minimum} element(s)`;else if($.type==="string")W=`String must contain ${$.exact?"exactly":$.inclusive?"at least":"over"} ${$.minimum} character(s)`;else if($.type==="number")W=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="bigint")W=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="date")W=`Date must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${new Date(Number($.minimum))}`;else W="Invalid input";break;case B.too_big:if($.type==="array")W=`Array must contain ${$.exact?"exactly":$.inclusive?"at most":"less than"} ${$.maximum} element(s)`;else if($.type==="string")W=`String must contain ${$.exact?"exactly":$.inclusive?"at most":"under"} ${$.maximum} character(s)`;else if($.type==="number")W=`Number must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="bigint")W=`BigInt must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="date")W=`Date must be ${$.exact?"exactly":$.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number($.maximum))}`;else W="Invalid input";break;case B.custom:W="Invalid input";break;case B.invalid_intersection_types:W="Intersection results could not be merged";break;case B.not_multiple_of:W=`Number must be a multiple of ${$.multipleOf}`;break;case B.not_finite:W="Number must be finite";break;default:W=Q.defaultError,b.assertNever($)}return{message:W}},t=R1;var T0=t;function C1($){T0=$}function E$(){return T0}var P$=($)=>{let{data:Q,path:W,errorMaps:X,issueData:G}=$,J=[...W,...G.path||[]],Y={...G,path:J};if(G.message!==void 0)return{...G,path:J,message:G.message};let H="",_=X.filter((z)=>!!z).slice().reverse();for(let z of _)H=z(Y,{data:Q,defaultError:H}).message;return{...G,path:J,message:H}},b1=[];function M($,Q){let W=E$(),X=P$({issueData:Q,data:$.data,path:$.path,errorMaps:[$.common.contextualErrorMap,$.schemaErrorMap,W,W===t?void 0:t].filter((G)=>!!G)});$.common.issues.push(X)}class Z{constructor(){this.value="valid"}dirty(){if(this.value==="valid")this.value="dirty"}abort(){if(this.value!=="aborted")this.value="aborted"}static mergeArray($,Q){let W=[];for(let X of Q){if(X.status==="aborted")return D;if(X.status==="dirty")$.dirty();W.push(X.value)}return{status:$.value,value:W}}static async mergeObjectAsync($,Q){let W=[];for(let X of Q){let G=await X.key,J=await X.value;W.push({key:G,value:J})}return Z.mergeObjectSync($,W)}static mergeObjectSync($,Q){let W={};for(let X of Q){let{key:G,value:J}=X;if(G.status==="aborted")return D;if(J.status==="aborted")return D;if(G.status==="dirty")$.dirty();if(J.status==="dirty")$.dirty();if(G.value!=="__proto__"&&(typeof J.value<"u"||X.alwaysSet))W[G.value]=J.value}return{status:$.value,value:W}}}var D=Object.freeze({status:"aborted"}),H$=($)=>({status:"dirty",value:$}),h=($)=>({status:"valid",value:$}),r$=($)=>$.status==="aborted",o$=($)=>$.status==="dirty",W$=($)=>$.status==="valid",V$=($)=>typeof Promise<"u"&&$ instanceof Promise;var A;(function($){$.errToObj=(Q)=>typeof Q==="string"?{message:Q}:Q||{},$.toString=(Q)=>typeof Q==="string"?Q:Q?.message})(A||(A={}));class p{constructor($,Q,W,X){this._cachedPath=[],this.parent=$,this.data=Q,this._path=W,this._key=X}get path(){if(!this._cachedPath.length)if(Array.isArray(this._key))this._cachedPath.push(...this._path,...this._key);else this._cachedPath.push(...this._path,this._key);return this._cachedPath}}var P0=($,Q)=>{if(W$(Q))return{success:!0,data:Q.value};else{if(!$.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let W=new m($.common.issues);return this._error=W,this._error}}}};function q($){if(!$)return{};let{errorMap:Q,invalid_type_error:W,required_error:X,description:G}=$;if(Q&&(W||X))throw Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);if(Q)return{errorMap:Q,description:G};return{errorMap:(Y,H)=>{let{message:_}=$;if(Y.code==="invalid_enum_value")return{message:_??H.defaultError};if(typeof H.data>"u")return{message:_??X??H.defaultError};if(Y.code!=="invalid_type")return{message:H.defaultError};return{message:_??W??H.defaultError}},description:G}}class C{get description(){return this._def.description}_getType($){return r($.data)}_getOrReturnCtx($,Q){return Q||{common:$.parent.common,data:$.data,parsedType:r($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}_processInputParams($){return{status:new Z,ctx:{common:$.parent.common,data:$.data,parsedType:r($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}}_parseSync($){let Q=this._parse($);if(V$(Q))throw Error("Synchronous parse encountered promise.");return Q}_parseAsync($){let Q=this._parse($);return Promise.resolve(Q)}parse($,Q){let W=this.safeParse($,Q);if(W.success)return W.data;throw W.error}safeParse($,Q){let W={common:{issues:[],async:Q?.async??!1,contextualErrorMap:Q?.errorMap},path:Q?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:r($)},X=this._parseSync({data:$,path:W.path,parent:W});return P0(W,X)}"~validate"($){let Q={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:r($)};if(!this["~standard"].async)try{let W=this._parseSync({data:$,path:[],parent:Q});return W$(W)?{value:W.value}:{issues:Q.common.issues}}catch(W){if(W?.message?.toLowerCase()?.includes("encountered"))this["~standard"].async=!0;Q.common={issues:[],async:!0}}return this._parseAsync({data:$,path:[],parent:Q}).then((W)=>W$(W)?{value:W.value}:{issues:Q.common.issues})}async parseAsync($,Q){let W=await this.safeParseAsync($,Q);if(W.success)return W.data;throw W.error}async safeParseAsync($,Q){let W={common:{issues:[],contextualErrorMap:Q?.errorMap,async:!0},path:Q?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:r($)},X=this._parse({data:$,path:W.path,parent:W}),G=await(V$(X)?X:Promise.resolve(X));return P0(W,G)}refine($,Q){let W=(X)=>{if(typeof Q==="string"||typeof Q>"u")return{message:Q};else if(typeof Q==="function")return Q(X);else return Q};return this._refinement((X,G)=>{let J=$(X),Y=()=>G.addIssue({code:B.custom,...W(X)});if(typeof Promise<"u"&&J instanceof Promise)return J.then((H)=>{if(!H)return Y(),!1;else return!0});if(!J)return Y(),!1;else return!0})}refinement($,Q){return this._refinement((W,X)=>{if(!$(W))return X.addIssue(typeof Q==="function"?Q(W,X):Q),!1;else return!0})}_refinement($){return new i({schema:this,typeName:K.ZodEffects,effect:{type:"refinement",refinement:$}})}superRefine($){return this._refinement($)}constructor($){this.spa=this.safeParseAsync,this._def=$,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:(Q)=>this["~validate"](Q)}}optional(){return n.create(this,this._def)}nullable(){return $$.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return d.create(this)}promise(){return w$.create(this,this._def)}or($){return q$.create([this,$],this._def)}and($){return N$.create(this,$,this._def)}transform($){return new i({...q(this._def),schema:this,typeName:K.ZodEffects,effect:{type:"transform",transform:$}})}default($){let Q=typeof $==="function"?$:()=>$;return new C$({...q(this._def),innerType:this,defaultValue:Q,typeName:K.ZodDefault})}brand(){return new s$({typeName:K.ZodBranded,type:this,...q(this._def)})}catch($){let Q=typeof $==="function"?$:()=>$;return new b$({...q(this._def),innerType:this,catchValue:Q,typeName:K.ZodCatch})}describe($){return new this.constructor({...this._def,description:$})}pipe($){return m$.create(this,$)}readonly(){return I$.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}var I1=/^c[^\s-]{8,}$/i,k1=/^[0-9a-z]+$/,v1=/^[0-9A-HJKMNP-TV-Z]{26}$/i,f1=/^[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,T1=/^[a-z0-9_-]{21}$/i,P1=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,x1=/^[-+]?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)?)??$/,g1=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Z1="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",M0,h1=/^(?:(?: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])$/,y1=/^(?:(?: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])$/,m1=/^(([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]))$/,c1=/^(([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])$/,l1=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,u1=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,g0="((\\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])))",d1=new RegExp(`^${g0}$`);function Z0($){let Q="[0-5]\\d";if($.precision)Q=`${Q}\\.\\d{${$.precision}}`;else if($.precision==null)Q=`${Q}(\\.\\d+)?`;let W=$.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${Q})${W}`}function n1($){return new RegExp(`^${Z0($)}$`)}function h0($){let Q=`${g0}T${Z0($)}`,W=[];if(W.push($.local?"Z?":"Z"),$.offset)W.push("([+-]\\d{2}:?\\d{2})");return Q=`${Q}(${W.join("|")})`,new RegExp(`^${Q}$`)}function p1($,Q){if((Q==="v4"||!Q)&&h1.test($))return!0;if((Q==="v6"||!Q)&&m1.test($))return!0;return!1}function i1($,Q){if(!P1.test($))return!1;try{let[W]=$.split(".");if(!W)return!1;let X=W.replace(/-/g,"+").replace(/_/g,"/").padEnd(W.length+(4-W.length%4)%4,"="),G=JSON.parse(atob(X));if(typeof G!=="object"||G===null)return!1;if("typ"in G&&G?.typ!=="JWT")return!1;if(!G.alg)return!1;if(Q&&G.alg!==Q)return!1;return!0}catch{return!1}}function r1($,Q){if((Q==="v4"||!Q)&&y1.test($))return!0;if((Q==="v6"||!Q)&&c1.test($))return!0;return!1}class u extends C{_parse($){if(this._def.coerce)$.data=String($.data);if(this._getType($)!==w.string){let G=this._getOrReturnCtx($);return M(G,{code:B.invalid_type,expected:w.string,received:G.parsedType}),D}let W=new Z,X=void 0;for(let G of this._def.checks)if(G.kind==="min"){if($.data.length<G.value)X=this._getOrReturnCtx($,X),M(X,{code:B.too_small,minimum:G.value,type:"string",inclusive:!0,exact:!1,message:G.message}),W.dirty()}else if(G.kind==="max"){if($.data.length>G.value)X=this._getOrReturnCtx($,X),M(X,{code:B.too_big,maximum:G.value,type:"string",inclusive:!0,exact:!1,message:G.message}),W.dirty()}else if(G.kind==="length"){let J=$.data.length>G.value,Y=$.data.length<G.value;if(J||Y){if(X=this._getOrReturnCtx($,X),J)M(X,{code:B.too_big,maximum:G.value,type:"string",inclusive:!0,exact:!0,message:G.message});else if(Y)M(X,{code:B.too_small,minimum:G.value,type:"string",inclusive:!0,exact:!0,message:G.message});W.dirty()}}else if(G.kind==="email"){if(!g1.test($.data))X=this._getOrReturnCtx($,X),M(X,{validation:"email",code:B.invalid_string,message:G.message}),W.dirty()}else if(G.kind==="emoji"){if(!M0)M0=new RegExp(Z1,"u");if(!M0.test($.data))X=this._getOrReturnCtx($,X),M(X,{validation:"emoji",code:B.invalid_string,message:G.message}),W.dirty()}else if(G.kind==="uuid"){if(!f1.test($.data))X=this._getOrReturnCtx($,X),M(X,{validation:"uuid",code:B.invalid_string,message:G.message}),W.dirty()}else if(G.kind==="nanoid"){if(!T1.test($.data))X=this._getOrReturnCtx($,X),M(X,{validation:"nanoid",code:B.invalid_string,message:G.message}),W.dirty()}else if(G.kind==="cuid"){if(!I1.test($.data))X=this._getOrReturnCtx($,X),M(X,{validation:"cuid",code:B.invalid_string,message:G.message}),W.dirty()}else if(G.kind==="cuid2"){if(!k1.test($.data))X=this._getOrReturnCtx($,X),M(X,{validation:"cuid2",code:B.invalid_string,message:G.message}),W.dirty()}else if(G.kind==="ulid"){if(!v1.test($.data))X=this._getOrReturnCtx($,X),M(X,{validation:"ulid",code:B.invalid_string,message:G.message}),W.dirty()}else if(G.kind==="url")try{new URL($.data)}catch{X=this._getOrReturnCtx($,X),M(X,{validation:"url",code:B.invalid_string,message:G.message}),W.dirty()}else if(G.kind==="regex"){if(G.regex.lastIndex=0,!G.regex.test($.data))X=this._getOrReturnCtx($,X),M(X,{validation:"regex",code:B.invalid_string,message:G.message}),W.dirty()}else if(G.kind==="trim")$.data=$.data.trim();else if(G.kind==="includes"){if(!$.data.includes(G.value,G.position))X=this._getOrReturnCtx($,X),M(X,{code:B.invalid_string,validation:{includes:G.value,position:G.position},message:G.message}),W.dirty()}else if(G.kind==="toLowerCase")$.data=$.data.toLowerCase();else if(G.kind==="toUpperCase")$.data=$.data.toUpperCase();else if(G.kind==="startsWith"){if(!$.data.startsWith(G.value))X=this._getOrReturnCtx($,X),M(X,{code:B.invalid_string,validation:{startsWith:G.value},message:G.message}),W.dirty()}else if(G.kind==="endsWith"){if(!$.data.endsWith(G.value))X=this._getOrReturnCtx($,X),M(X,{code:B.invalid_string,validation:{endsWith:G.value},message:G.message}),W.dirty()}else if(G.kind==="datetime"){if(!h0(G).test($.data))X=this._getOrReturnCtx($,X),M(X,{code:B.invalid_string,validation:"datetime",message:G.message}),W.dirty()}else if(G.kind==="date"){if(!d1.test($.data))X=this._getOrReturnCtx($,X),M(X,{code:B.invalid_string,validation:"date",message:G.message}),W.dirty()}else if(G.kind==="time"){if(!n1(G).test($.data))X=this._getOrReturnCtx($,X),M(X,{code:B.invalid_string,validation:"time",message:G.message}),W.dirty()}else if(G.kind==="duration"){if(!x1.test($.data))X=this._getOrReturnCtx($,X),M(X,{validation:"duration",code:B.invalid_string,message:G.message}),W.dirty()}else if(G.kind==="ip"){if(!p1($.data,G.version))X=this._getOrReturnCtx($,X),M(X,{validation:"ip",code:B.invalid_string,message:G.message}),W.dirty()}else if(G.kind==="jwt"){if(!i1($.data,G.alg))X=this._getOrReturnCtx($,X),M(X,{validation:"jwt",code:B.invalid_string,message:G.message}),W.dirty()}else if(G.kind==="cidr"){if(!r1($.data,G.version))X=this._getOrReturnCtx($,X),M(X,{validation:"cidr",code:B.invalid_string,message:G.message}),W.dirty()}else if(G.kind==="base64"){if(!l1.test($.data))X=this._getOrReturnCtx($,X),M(X,{validation:"base64",code:B.invalid_string,message:G.message}),W.dirty()}else if(G.kind==="base64url"){if(!u1.test($.data))X=this._getOrReturnCtx($,X),M(X,{validation:"base64url",code:B.invalid_string,message:G.message}),W.dirty()}else b.assertNever(G);return{status:W.value,value:$.data}}_regex($,Q,W){return this.refinement((X)=>$.test(X),{validation:Q,code:B.invalid_string,...A.errToObj(W)})}_addCheck($){return new u({...this._def,checks:[...this._def.checks,$]})}email($){return this._addCheck({kind:"email",...A.errToObj($)})}url($){return this._addCheck({kind:"url",...A.errToObj($)})}emoji($){return this._addCheck({kind:"emoji",...A.errToObj($)})}uuid($){return this._addCheck({kind:"uuid",...A.errToObj($)})}nanoid($){return this._addCheck({kind:"nanoid",...A.errToObj($)})}cuid($){return this._addCheck({kind:"cuid",...A.errToObj($)})}cuid2($){return this._addCheck({kind:"cuid2",...A.errToObj($)})}ulid($){return this._addCheck({kind:"ulid",...A.errToObj($)})}base64($){return this._addCheck({kind:"base64",...A.errToObj($)})}base64url($){return this._addCheck({kind:"base64url",...A.errToObj($)})}jwt($){return this._addCheck({kind:"jwt",...A.errToObj($)})}ip($){return this._addCheck({kind:"ip",...A.errToObj($)})}cidr($){return this._addCheck({kind:"cidr",...A.errToObj($)})}datetime($){if(typeof $==="string")return this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:$});return this._addCheck({kind:"datetime",precision:typeof $?.precision>"u"?null:$?.precision,offset:$?.offset??!1,local:$?.local??!1,...A.errToObj($?.message)})}date($){return this._addCheck({kind:"date",message:$})}time($){if(typeof $==="string")return this._addCheck({kind:"time",precision:null,message:$});return this._addCheck({kind:"time",precision:typeof $?.precision>"u"?null:$?.precision,...A.errToObj($?.message)})}duration($){return this._addCheck({kind:"duration",...A.errToObj($)})}regex($,Q){return this._addCheck({kind:"regex",regex:$,...A.errToObj(Q)})}includes($,Q){return this._addCheck({kind:"includes",value:$,position:Q?.position,...A.errToObj(Q?.message)})}startsWith($,Q){return this._addCheck({kind:"startsWith",value:$,...A.errToObj(Q)})}endsWith($,Q){return this._addCheck({kind:"endsWith",value:$,...A.errToObj(Q)})}min($,Q){return this._addCheck({kind:"min",value:$,...A.errToObj(Q)})}max($,Q){return this._addCheck({kind:"max",value:$,...A.errToObj(Q)})}length($,Q){return this._addCheck({kind:"length",value:$,...A.errToObj(Q)})}nonempty($){return this.min(1,A.errToObj($))}trim(){return new u({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new u({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new u({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(($)=>$.kind==="datetime")}get isDate(){return!!this._def.checks.find(($)=>$.kind==="date")}get isTime(){return!!this._def.checks.find(($)=>$.kind==="time")}get isDuration(){return!!this._def.checks.find(($)=>$.kind==="duration")}get isEmail(){return!!this._def.checks.find(($)=>$.kind==="email")}get isURL(){return!!this._def.checks.find(($)=>$.kind==="url")}get isEmoji(){return!!this._def.checks.find(($)=>$.kind==="emoji")}get isUUID(){return!!this._def.checks.find(($)=>$.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(($)=>$.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(($)=>$.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(($)=>$.kind==="cuid2")}get isULID(){return!!this._def.checks.find(($)=>$.kind==="ulid")}get isIP(){return!!this._def.checks.find(($)=>$.kind==="ip")}get isCIDR(){return!!this._def.checks.find(($)=>$.kind==="cidr")}get isBase64(){return!!this._def.checks.find(($)=>$.kind==="base64")}get isBase64url(){return!!this._def.checks.find(($)=>$.kind==="base64url")}get minLength(){let $=null;for(let Q of this._def.checks)if(Q.kind==="min"){if($===null||Q.value>$)$=Q.value}return $}get maxLength(){let $=null;for(let Q of this._def.checks)if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return $}}u.create=($)=>{return new u({checks:[],typeName:K.ZodString,coerce:$?.coerce??!1,...q($)})};function o1($,Q){let W=($.toString().split(".")[1]||"").length,X=(Q.toString().split(".")[1]||"").length,G=W>X?W:X,J=Number.parseInt($.toFixed(G).replace(".","")),Y=Number.parseInt(Q.toFixed(G).replace(".",""));return J%Y/10**G}class G$ extends C{constructor(){super(...arguments);this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse($){if(this._def.coerce)$.data=Number($.data);if(this._getType($)!==w.number){let G=this._getOrReturnCtx($);return M(G,{code:B.invalid_type,expected:w.number,received:G.parsedType}),D}let W=void 0,X=new Z;for(let G of this._def.checks)if(G.kind==="int"){if(!b.isInteger($.data))W=this._getOrReturnCtx($,W),M(W,{code:B.invalid_type,expected:"integer",received:"float",message:G.message}),X.dirty()}else if(G.kind==="min"){if(G.inclusive?$.data<G.value:$.data<=G.value)W=this._getOrReturnCtx($,W),M(W,{code:B.too_small,minimum:G.value,type:"number",inclusive:G.inclusive,exact:!1,message:G.message}),X.dirty()}else if(G.kind==="max"){if(G.inclusive?$.data>G.value:$.data>=G.value)W=this._getOrReturnCtx($,W),M(W,{code:B.too_big,maximum:G.value,type:"number",inclusive:G.inclusive,exact:!1,message:G.message}),X.dirty()}else if(G.kind==="multipleOf"){if(o1($.data,G.value)!==0)W=this._getOrReturnCtx($,W),M(W,{code:B.not_multiple_of,multipleOf:G.value,message:G.message}),X.dirty()}else if(G.kind==="finite"){if(!Number.isFinite($.data))W=this._getOrReturnCtx($,W),M(W,{code:B.not_finite,message:G.message}),X.dirty()}else b.assertNever(G);return{status:X.value,value:$.data}}gte($,Q){return this.setLimit("min",$,!0,A.toString(Q))}gt($,Q){return this.setLimit("min",$,!1,A.toString(Q))}lte($,Q){return this.setLimit("max",$,!0,A.toString(Q))}lt($,Q){return this.setLimit("max",$,!1,A.toString(Q))}setLimit($,Q,W,X){return new G$({...this._def,checks:[...this._def.checks,{kind:$,value:Q,inclusive:W,message:A.toString(X)}]})}_addCheck($){return new G$({...this._def,checks:[...this._def.checks,$]})}int($){return this._addCheck({kind:"int",message:A.toString($)})}positive($){return this._addCheck({kind:"min",value:0,inclusive:!1,message:A.toString($)})}negative($){return this._addCheck({kind:"max",value:0,inclusive:!1,message:A.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:0,inclusive:!0,message:A.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:0,inclusive:!0,message:A.toString($)})}multipleOf($,Q){return this._addCheck({kind:"multipleOf",value:$,message:A.toString(Q)})}finite($){return this._addCheck({kind:"finite",message:A.toString($)})}safe($){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:A.toString($)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:A.toString($)})}get minValue(){let $=null;for(let Q of this._def.checks)if(Q.kind==="min"){if($===null||Q.value>$)$=Q.value}return $}get maxValue(){let $=null;for(let Q of this._def.checks)if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return $}get isInt(){return!!this._def.checks.find(($)=>$.kind==="int"||$.kind==="multipleOf"&&b.isInteger($.value))}get isFinite(){let $=null,Q=null;for(let W of this._def.checks)if(W.kind==="finite"||W.kind==="int"||W.kind==="multipleOf")return!0;else if(W.kind==="min"){if(Q===null||W.value>Q)Q=W.value}else if(W.kind==="max"){if($===null||W.value<$)$=W.value}return Number.isFinite(Q)&&Number.isFinite($)}}G$.create=($)=>{return new G$({checks:[],typeName:K.ZodNumber,coerce:$?.coerce||!1,...q($)})};class Y$ extends C{constructor(){super(...arguments);this.min=this.gte,this.max=this.lte}_parse($){if(this._def.coerce)try{$.data=BigInt($.data)}catch{return this._getInvalidInput($)}if(this._getType($)!==w.bigint)return this._getInvalidInput($);let W=void 0,X=new Z;for(let G of this._def.checks)if(G.kind==="min"){if(G.inclusive?$.data<G.value:$.data<=G.value)W=this._getOrReturnCtx($,W),M(W,{code:B.too_small,type:"bigint",minimum:G.value,inclusive:G.inclusive,message:G.message}),X.dirty()}else if(G.kind==="max"){if(G.inclusive?$.data>G.value:$.data>=G.value)W=this._getOrReturnCtx($,W),M(W,{code:B.too_big,type:"bigint",maximum:G.value,inclusive:G.inclusive,message:G.message}),X.dirty()}else if(G.kind==="multipleOf"){if($.data%G.value!==BigInt(0))W=this._getOrReturnCtx($,W),M(W,{code:B.not_multiple_of,multipleOf:G.value,message:G.message}),X.dirty()}else b.assertNever(G);return{status:X.value,value:$.data}}_getInvalidInput($){let Q=this._getOrReturnCtx($);return M(Q,{code:B.invalid_type,expected:w.bigint,received:Q.parsedType}),D}gte($,Q){return this.setLimit("min",$,!0,A.toString(Q))}gt($,Q){return this.setLimit("min",$,!1,A.toString(Q))}lte($,Q){return this.setLimit("max",$,!0,A.toString(Q))}lt($,Q){return this.setLimit("max",$,!1,A.toString(Q))}setLimit($,Q,W,X){return new Y$({...this._def,checks:[...this._def.checks,{kind:$,value:Q,inclusive:W,message:A.toString(X)}]})}_addCheck($){return new Y$({...this._def,checks:[...this._def.checks,$]})}positive($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:A.toString($)})}negative($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:A.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:A.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:A.toString($)})}multipleOf($,Q){return this._addCheck({kind:"multipleOf",value:$,message:A.toString(Q)})}get minValue(){let $=null;for(let Q of this._def.checks)if(Q.kind==="min"){if($===null||Q.value>$)$=Q.value}return $}get maxValue(){let $=null;for(let Q of this._def.checks)if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return $}}Y$.create=($)=>{return new Y$({checks:[],typeName:K.ZodBigInt,coerce:$?.coerce??!1,...q($)})};class K$ extends C{_parse($){if(this._def.coerce)$.data=Boolean($.data);if(this._getType($)!==w.boolean){let W=this._getOrReturnCtx($);return M(W,{code:B.invalid_type,expected:w.boolean,received:W.parsedType}),D}return h($.data)}}K$.create=($)=>{return new K$({typeName:K.ZodBoolean,coerce:$?.coerce||!1,...q($)})};class _$ extends C{_parse($){if(this._def.coerce)$.data=new Date($.data);if(this._getType($)!==w.date){let G=this._getOrReturnCtx($);return M(G,{code:B.invalid_type,expected:w.date,received:G.parsedType}),D}if(Number.isNaN($.data.getTime())){let G=this._getOrReturnCtx($);return M(G,{code:B.invalid_date}),D}let W=new Z,X=void 0;for(let G of this._def.checks)if(G.kind==="min"){if($.data.getTime()<G.value)X=this._getOrReturnCtx($,X),M(X,{code:B.too_small,message:G.message,inclusive:!0,exact:!1,minimum:G.value,type:"date"}),W.dirty()}else if(G.kind==="max"){if($.data.getTime()>G.value)X=this._getOrReturnCtx($,X),M(X,{code:B.too_big,message:G.message,inclusive:!0,exact:!1,maximum:G.value,type:"date"}),W.dirty()}else b.assertNever(G);return{status:W.value,value:new Date($.data.getTime())}}_addCheck($){return new _$({...this._def,checks:[...this._def.checks,$]})}min($,Q){return this._addCheck({kind:"min",value:$.getTime(),message:A.toString(Q)})}max($,Q){return this._addCheck({kind:"max",value:$.getTime(),message:A.toString(Q)})}get minDate(){let $=null;for(let Q of this._def.checks)if(Q.kind==="min"){if($===null||Q.value>$)$=Q.value}return $!=null?new Date($):null}get maxDate(){let $=null;for(let Q of this._def.checks)if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return $!=null?new Date($):null}}_$.create=($)=>{return new _$({checks:[],coerce:$?.coerce||!1,typeName:K.ZodDate,...q($)})};class x$ extends C{_parse($){if(this._getType($)!==w.symbol){let W=this._getOrReturnCtx($);return M(W,{code:B.invalid_type,expected:w.symbol,received:W.parsedType}),D}return h($.data)}}x$.create=($)=>{return new x$({typeName:K.ZodSymbol,...q($)})};class S$ extends C{_parse($){if(this._getType($)!==w.undefined){let W=this._getOrReturnCtx($);return M(W,{code:B.invalid_type,expected:w.undefined,received:W.parsedType}),D}return h($.data)}}S$.create=($)=>{return new S$({typeName:K.ZodUndefined,...q($)})};class L$ extends C{_parse($){if(this._getType($)!==w.null){let W=this._getOrReturnCtx($);return M(W,{code:B.invalid_type,expected:w.null,received:W.parsedType}),D}return h($.data)}}L$.create=($)=>{return new L$({typeName:K.ZodNull,...q($)})};class z$ extends C{constructor(){super(...arguments);this._any=!0}_parse($){return h($.data)}}z$.create=($)=>{return new z$({typeName:K.ZodAny,...q($)})};class X$ extends C{constructor(){super(...arguments);this._unknown=!0}_parse($){return h($.data)}}X$.create=($)=>{return new X$({typeName:K.ZodUnknown,...q($)})};class o extends C{_parse($){let Q=this._getOrReturnCtx($);return M(Q,{code:B.invalid_type,expected:w.never,received:Q.parsedType}),D}}o.create=($)=>{return new o({typeName:K.ZodNever,...q($)})};class g$ extends C{_parse($){if(this._getType($)!==w.undefined){let W=this._getOrReturnCtx($);return M(W,{code:B.invalid_type,expected:w.void,received:W.parsedType}),D}return h($.data)}}g$.create=($)=>{return new g$({typeName:K.ZodVoid,...q($)})};class d extends C{_parse($){let{ctx:Q,status:W}=this._processInputParams($),X=this._def;if(Q.parsedType!==w.array)return M(Q,{code:B.invalid_type,expected:w.array,received:Q.parsedType}),D;if(X.exactLength!==null){let J=Q.data.length>X.exactLength.value,Y=Q.data.length<X.exactLength.value;if(J||Y)M(Q,{code:J?B.too_big:B.too_small,minimum:Y?X.exactLength.value:void 0,maximum:J?X.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:X.exactLength.message}),W.dirty()}if(X.minLength!==null){if(Q.data.length<X.minLength.value)M(Q,{code:B.too_small,minimum:X.minLength.value,type:"array",inclusive:!0,exact:!1,message:X.minLength.message}),W.dirty()}if(X.maxLength!==null){if(Q.data.length>X.maxLength.value)M(Q,{code:B.too_big,maximum:X.maxLength.value,type:"array",inclusive:!0,exact:!1,message:X.maxLength.message}),W.dirty()}if(Q.common.async)return Promise.all([...Q.data].map((J,Y)=>{return X.type._parseAsync(new p(Q,J,Q.path,Y))})).then((J)=>{return Z.mergeArray(W,J)});let G=[...Q.data].map((J,Y)=>{return X.type._parseSync(new p(Q,J,Q.path,Y))});return Z.mergeArray(W,G)}get element(){return this._def.type}min($,Q){return new d({...this._def,minLength:{value:$,message:A.toString(Q)}})}max($,Q){return new d({...this._def,maxLength:{value:$,message:A.toString(Q)}})}length($,Q){return new d({...this._def,exactLength:{value:$,message:A.toString(Q)}})}nonempty($){return this.min(1,$)}}d.create=($,Q)=>{return new d({type:$,minLength:null,maxLength:null,exactLength:null,typeName:K.ZodArray,...q(Q)})};function A$($){if($ instanceof g){let Q={};for(let W in $.shape){let X=$.shape[W];Q[W]=n.create(A$(X))}return new g({...$._def,shape:()=>Q})}else if($ instanceof d)return new d({...$._def,type:A$($.element)});else if($ instanceof n)return n.create(A$($.unwrap()));else if($ instanceof $$)return $$.create(A$($.unwrap()));else if($ instanceof a)return a.create($.items.map((Q)=>A$(Q)));else return $}class g extends C{constructor(){super(...arguments);this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let $=this._def.shape(),Q=b.objectKeys($);return this._cached={shape:$,keys:Q},this._cached}_parse($){if(this._getType($)!==w.object){let _=this._getOrReturnCtx($);return M(_,{code:B.invalid_type,expected:w.object,received:_.parsedType}),D}let{status:W,ctx:X}=this._processInputParams($),{shape:G,keys:J}=this._getCached(),Y=[];if(!(this._def.catchall instanceof o&&this._def.unknownKeys==="strip")){for(let _ in X.data)if(!J.includes(_))Y.push(_)}let H=[];for(let _ of J){let z=G[_],j=X.data[_];H.push({key:{status:"valid",value:_},value:z._parse(new p(X,j,X.path,_)),alwaysSet:_ in X.data})}if(this._def.catchall instanceof o){let _=this._def.unknownKeys;if(_==="passthrough")for(let z of Y)H.push({key:{status:"valid",value:z},value:{status:"valid",value:X.data[z]}});else if(_==="strict"){if(Y.length>0)M(X,{code:B.unrecognized_keys,keys:Y}),W.dirty()}else if(_==="strip");else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let _=this._def.catchall;for(let z of Y){let j=X.data[z];H.push({key:{status:"valid",value:z},value:_._parse(new p(X,j,X.path,z)),alwaysSet:z in X.data})}}if(X.common.async)return Promise.resolve().then(async()=>{let _=[];for(let z of H){let j=await z.key,U=await z.value;_.push({key:j,value:U,alwaysSet:z.alwaysSet})}return _}).then((_)=>{return Z.mergeObjectSync(W,_)});else return Z.mergeObjectSync(W,H)}get shape(){return this._def.shape()}strict($){return A.errToObj,new g({...this._def,unknownKeys:"strict",...$!==void 0?{errorMap:(Q,W)=>{let X=this._def.errorMap?.(Q,W).message??W.defaultError;if(Q.code==="unrecognized_keys")return{message:A.errToObj($).message??X};return{message:X}}}:{}})}strip(){return new g({...this._def,unknownKeys:"strip"})}passthrough(){return new g({...this._def,unknownKeys:"passthrough"})}extend($){return new g({...this._def,shape:()=>({...this._def.shape(),...$})})}merge($){return new g({unknownKeys:$._def.unknownKeys,catchall:$._def.catchall,shape:()=>({...this._def.shape(),...$._def.shape()}),typeName:K.ZodObject})}setKey($,Q){return this.augment({[$]:Q})}catchall($){return new g({...this._def,catchall:$})}pick($){let Q={};for(let W of b.objectKeys($))if($[W]&&this.shape[W])Q[W]=this.shape[W];return new g({...this._def,shape:()=>Q})}omit($){let Q={};for(let W of b.objectKeys(this.shape))if(!$[W])Q[W]=this.shape[W];return new g({...this._def,shape:()=>Q})}deepPartial(){return A$(this)}partial($){let Q={};for(let W of b.objectKeys(this.shape)){let X=this.shape[W];if($&&!$[W])Q[W]=X;else Q[W]=X.optional()}return new g({...this._def,shape:()=>Q})}required($){let Q={};for(let W of b.objectKeys(this.shape))if($&&!$[W])Q[W]=this.shape[W];else{let G=this.shape[W];while(G instanceof n)G=G._def.innerType;Q[W]=G}return new g({...this._def,shape:()=>Q})}keyof(){return y0(b.objectKeys(this.shape))}}g.create=($,Q)=>{return new g({shape:()=>$,unknownKeys:"strip",catchall:o.create(),typeName:K.ZodObject,...q(Q)})};g.strictCreate=($,Q)=>{return new g({shape:()=>$,unknownKeys:"strict",catchall:o.create(),typeName:K.ZodObject,...q(Q)})};g.lazycreate=($,Q)=>{return new g({shape:$,unknownKeys:"strip",catchall:o.create(),typeName:K.ZodObject,...q(Q)})};class q$ extends C{_parse($){let{ctx:Q}=this._processInputParams($),W=this._def.options;function X(G){for(let Y of G)if(Y.result.status==="valid")return Y.result;for(let Y of G)if(Y.result.status==="dirty")return Q.common.issues.push(...Y.ctx.common.issues),Y.result;let J=G.map((Y)=>new m(Y.ctx.common.issues));return M(Q,{code:B.invalid_union,unionErrors:J}),D}if(Q.common.async)return Promise.all(W.map(async(G)=>{let J={...Q,common:{...Q.common,issues:[]},parent:null};return{result:await G._parseAsync({data:Q.data,path:Q.path,parent:J}),ctx:J}})).then(X);else{let G=void 0,J=[];for(let H of W){let _={...Q,common:{...Q.common,issues:[]},parent:null},z=H._parseSync({data:Q.data,path:Q.path,parent:_});if(z.status==="valid")return z;else if(z.status==="dirty"&&!G)G={result:z,ctx:_};if(_.common.issues.length)J.push(_.common.issues)}if(G)return Q.common.issues.push(...G.ctx.common.issues),G.result;let Y=J.map((H)=>new m(H));return M(Q,{code:B.invalid_union,unionErrors:Y}),D}}get options(){return this._def.options}}q$.create=($,Q)=>{return new q$({options:$,typeName:K.ZodUnion,...q(Q)})};var e=($)=>{if($ instanceof O$)return e($.schema);else if($ instanceof i)return e($.innerType());else if($ instanceof F$)return[$.value];else if($ instanceof J$)return $.options;else if($ instanceof R$)return b.objectValues($.enum);else if($ instanceof C$)return e($._def.innerType);else if($ instanceof S$)return[void 0];else if($ instanceof L$)return[null];else if($ instanceof n)return[void 0,...e($.unwrap())];else if($ instanceof $$)return[null,...e($.unwrap())];else if($ instanceof s$)return e($.unwrap());else if($ instanceof I$)return e($.unwrap());else if($ instanceof b$)return e($._def.innerType);else return[]};class a$ extends C{_parse($){let{ctx:Q}=this._processInputParams($);if(Q.parsedType!==w.object)return M(Q,{code:B.invalid_type,expected:w.object,received:Q.parsedType}),D;let W=this.discriminator,X=Q.data[W],G=this.optionsMap.get(X);if(!G)return M(Q,{code:B.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[W]}),D;if(Q.common.async)return G._parseAsync({data:Q.data,path:Q.path,parent:Q});else return G._parseSync({data:Q.data,path:Q.path,parent:Q})}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create($,Q,W){let X=new Map;for(let G of Q){let J=e(G.shape[$]);if(!J.length)throw Error(`A discriminator value for key \`${$}\` could not be extracted from all schema options`);for(let Y of J){if(X.has(Y))throw Error(`Discriminator property ${String($)} has duplicate value ${String(Y)}`);X.set(Y,G)}}return new a$({typeName:K.ZodDiscriminatedUnion,discriminator:$,options:Q,optionsMap:X,...q(W)})}}function j0($,Q){let W=r($),X=r(Q);if($===Q)return{valid:!0,data:$};else if(W===w.object&&X===w.object){let G=b.objectKeys(Q),J=b.objectKeys($).filter((H)=>G.indexOf(H)!==-1),Y={...$,...Q};for(let H of J){let _=j0($[H],Q[H]);if(!_.valid)return{valid:!1};Y[H]=_.data}return{valid:!0,data:Y}}else if(W===w.array&&X===w.array){if($.length!==Q.length)return{valid:!1};let G=[];for(let J=0;J<$.length;J++){let Y=$[J],H=Q[J],_=j0(Y,H);if(!_.valid)return{valid:!1};G.push(_.data)}return{valid:!0,data:G}}else if(W===w.date&&X===w.date&&+$===+Q)return{valid:!0,data:$};else return{valid:!1}}class N$ extends C{_parse($){let{status:Q,ctx:W}=this._processInputParams($),X=(G,J)=>{if(r$(G)||r$(J))return D;let Y=j0(G.value,J.value);if(!Y.valid)return M(W,{code:B.invalid_intersection_types}),D;if(o$(G)||o$(J))Q.dirty();return{status:Q.value,value:Y.data}};if(W.common.async)return Promise.all([this._def.left._parseAsync({data:W.data,path:W.path,parent:W}),this._def.right._parseAsync({data:W.data,path:W.path,parent:W})]).then(([G,J])=>X(G,J));else return X(this._def.left._parseSync({data:W.data,path:W.path,parent:W}),this._def.right._parseSync({data:W.data,path:W.path,parent:W}))}}N$.create=($,Q,W)=>{return new N$({left:$,right:Q,typeName:K.ZodIntersection,...q(W)})};class a extends C{_parse($){let{status:Q,ctx:W}=this._processInputParams($);if(W.parsedType!==w.array)return M(W,{code:B.invalid_type,expected:w.array,received:W.parsedType}),D;if(W.data.length<this._def.items.length)return M(W,{code:B.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),D;if(!this._def.rest&&W.data.length>this._def.items.length)M(W,{code:B.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),Q.dirty();let G=[...W.data].map((J,Y)=>{let H=this._def.items[Y]||this._def.rest;if(!H)return null;return H._parse(new p(W,J,W.path,Y))}).filter((J)=>!!J);if(W.common.async)return Promise.all(G).then((J)=>{return Z.mergeArray(Q,J)});else return Z.mergeArray(Q,G)}get items(){return this._def.items}rest($){return new a({...this._def,rest:$})}}a.create=($,Q)=>{if(!Array.isArray($))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new a({items:$,typeName:K.ZodTuple,rest:null,...q(Q)})};class Z$ extends C{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:Q,ctx:W}=this._processInputParams($);if(W.parsedType!==w.object)return M(W,{code:B.invalid_type,expected:w.object,received:W.parsedType}),D;let X=[],G=this._def.keyType,J=this._def.valueType;for(let Y in W.data)X.push({key:G._parse(new p(W,Y,W.path,Y)),value:J._parse(new p(W,W.data[Y],W.path,Y)),alwaysSet:Y in W.data});if(W.common.async)return Z.mergeObjectAsync(Q,X);else return Z.mergeObjectSync(Q,X)}get element(){return this._def.valueType}static create($,Q,W){if(Q instanceof C)return new Z$({keyType:$,valueType:Q,typeName:K.ZodRecord,...q(W)});return new Z$({keyType:u.create(),valueType:$,typeName:K.ZodRecord,...q(Q)})}}class h$ extends C{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:Q,ctx:W}=this._processInputParams($);if(W.parsedType!==w.map)return M(W,{code:B.invalid_type,expected:w.map,received:W.parsedType}),D;let X=this._def.keyType,G=this._def.valueType,J=[...W.data.entries()].map(([Y,H],_)=>{return{key:X._parse(new p(W,Y,W.path,[_,"key"])),value:G._parse(new p(W,H,W.path,[_,"value"]))}});if(W.common.async){let Y=new Map;return Promise.resolve().then(async()=>{for(let H of J){let _=await H.key,z=await H.value;if(_.status==="aborted"||z.status==="aborted")return D;if(_.status==="dirty"||z.status==="dirty")Q.dirty();Y.set(_.value,z.value)}return{status:Q.value,value:Y}})}else{let Y=new Map;for(let H of J){let{key:_,value:z}=H;if(_.status==="aborted"||z.status==="aborted")return D;if(_.status==="dirty"||z.status==="dirty")Q.dirty();Y.set(_.value,z.value)}return{status:Q.value,value:Y}}}}h$.create=($,Q,W)=>{return new h$({valueType:Q,keyType:$,typeName:K.ZodMap,...q(W)})};class B$ extends C{_parse($){let{status:Q,ctx:W}=this._processInputParams($);if(W.parsedType!==w.set)return M(W,{code:B.invalid_type,expected:w.set,received:W.parsedType}),D;let X=this._def;if(X.minSize!==null){if(W.data.size<X.minSize.value)M(W,{code:B.too_small,minimum:X.minSize.value,type:"set",inclusive:!0,exact:!1,message:X.minSize.message}),Q.dirty()}if(X.maxSize!==null){if(W.data.size>X.maxSize.value)M(W,{code:B.too_big,maximum:X.maxSize.value,type:"set",inclusive:!0,exact:!1,message:X.maxSize.message}),Q.dirty()}let G=this._def.valueType;function J(H){let _=new Set;for(let z of H){if(z.status==="aborted")return D;if(z.status==="dirty")Q.dirty();_.add(z.value)}return{status:Q.value,value:_}}let Y=[...W.data.values()].map((H,_)=>G._parse(new p(W,H,W.path,_)));if(W.common.async)return Promise.all(Y).then((H)=>J(H));else return J(Y)}min($,Q){return new B$({...this._def,minSize:{value:$,message:A.toString(Q)}})}max($,Q){return new B$({...this._def,maxSize:{value:$,message:A.toString(Q)}})}size($,Q){return this.min($,Q).max($,Q)}nonempty($){return this.min(1,$)}}B$.create=($,Q)=>{return new B$({valueType:$,minSize:null,maxSize:null,typeName:K.ZodSet,...q(Q)})};class D$ extends C{constructor(){super(...arguments);this.validate=this.implement}_parse($){let{ctx:Q}=this._processInputParams($);if(Q.parsedType!==w.function)return M(Q,{code:B.invalid_type,expected:w.function,received:Q.parsedType}),D;function W(Y,H){return P$({data:Y,path:Q.path,errorMaps:[Q.common.contextualErrorMap,Q.schemaErrorMap,E$(),t].filter((_)=>!!_),issueData:{code:B.invalid_arguments,argumentsError:H}})}function X(Y,H){return P$({data:Y,path:Q.path,errorMaps:[Q.common.contextualErrorMap,Q.schemaErrorMap,E$(),t].filter((_)=>!!_),issueData:{code:B.invalid_return_type,returnTypeError:H}})}let G={errorMap:Q.common.contextualErrorMap},J=Q.data;if(this._def.returns instanceof w$){let Y=this;return h(async function(...H){let _=new m([]),z=await Y._def.args.parseAsync(H,G).catch((O)=>{throw _.addIssue(W(H,O)),_}),j=await Reflect.apply(J,this,z);return await Y._def.returns._def.type.parseAsync(j,G).catch((O)=>{throw _.addIssue(X(j,O)),_})})}else{let Y=this;return h(function(...H){let _=Y._def.args.safeParse(H,G);if(!_.success)throw new m([W(H,_.error)]);let z=Reflect.apply(J,this,_.data),j=Y._def.returns.safeParse(z,G);if(!j.success)throw new m([X(z,j.error)]);return j.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...$){return new D$({...this._def,args:a.create($).rest(X$.create())})}returns($){return new D$({...this._def,returns:$})}implement($){return this.parse($)}strictImplement($){return this.parse($)}static create($,Q,W){return new D$({args:$?$:a.create([]).rest(X$.create()),returns:Q||X$.create(),typeName:K.ZodFunction,...q(W)})}}class O$ extends C{get schema(){return this._def.getter()}_parse($){let{ctx:Q}=this._processInputParams($);return this._def.getter()._parse({data:Q.data,path:Q.path,parent:Q})}}O$.create=($,Q)=>{return new O$({getter:$,typeName:K.ZodLazy,...q(Q)})};class F$ extends C{_parse($){if($.data!==this._def.value){let Q=this._getOrReturnCtx($);return M(Q,{received:Q.data,code:B.invalid_literal,expected:this._def.value}),D}return{status:"valid",value:$.data}}get value(){return this._def.value}}F$.create=($,Q)=>{return new F$({value:$,typeName:K.ZodLiteral,...q(Q)})};function y0($,Q){return new J$({values:$,typeName:K.ZodEnum,...q(Q)})}class J$ extends C{_parse($){if(typeof $.data!=="string"){let Q=this._getOrReturnCtx($),W=this._def.values;return M(Q,{expected:b.joinValues(W),received:Q.parsedType,code:B.invalid_type}),D}if(!this._cache)this._cache=new Set(this._def.values);if(!this._cache.has($.data)){let Q=this._getOrReturnCtx($),W=this._def.values;return M(Q,{received:Q.data,code:B.invalid_enum_value,options:W}),D}return h($.data)}get options(){return this._def.values}get enum(){let $={};for(let Q of this._def.values)$[Q]=Q;return $}get Values(){let $={};for(let Q of this._def.values)$[Q]=Q;return $}get Enum(){let $={};for(let Q of this._def.values)$[Q]=Q;return $}extract($,Q=this._def){return J$.create($,{...this._def,...Q})}exclude($,Q=this._def){return J$.create(this.options.filter((W)=>!$.includes(W)),{...this._def,...Q})}}J$.create=y0;class R$ extends C{_parse($){let Q=b.getValidEnumValues(this._def.values),W=this._getOrReturnCtx($);if(W.parsedType!==w.string&&W.parsedType!==w.number){let X=b.objectValues(Q);return M(W,{expected:b.joinValues(X),received:W.parsedType,code:B.invalid_type}),D}if(!this._cache)this._cache=new Set(b.getValidEnumValues(this._def.values));if(!this._cache.has($.data)){let X=b.objectValues(Q);return M(W,{received:W.data,code:B.invalid_enum_value,options:X}),D}return h($.data)}get enum(){return this._def.values}}R$.create=($,Q)=>{return new R$({values:$,typeName:K.ZodNativeEnum,...q(Q)})};class w$ extends C{unwrap(){return this._def.type}_parse($){let{ctx:Q}=this._processInputParams($);if(Q.parsedType!==w.promise&&Q.common.async===!1)return M(Q,{code:B.invalid_type,expected:w.promise,received:Q.parsedType}),D;let W=Q.parsedType===w.promise?Q.data:Promise.resolve(Q.data);return h(W.then((X)=>{return this._def.type.parseAsync(X,{path:Q.path,errorMap:Q.common.contextualErrorMap})}))}}w$.create=($,Q)=>{return new w$({type:$,typeName:K.ZodPromise,...q(Q)})};class i extends C{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===K.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse($){let{status:Q,ctx:W}=this._processInputParams($),X=this._def.effect||null,G={addIssue:(J)=>{if(M(W,J),J.fatal)Q.abort();else Q.dirty()},get path(){return W.path}};if(G.addIssue=G.addIssue.bind(G),X.type==="preprocess"){let J=X.transform(W.data,G);if(W.common.async)return Promise.resolve(J).then(async(Y)=>{if(Q.value==="aborted")return D;let H=await this._def.schema._parseAsync({data:Y,path:W.path,parent:W});if(H.status==="aborted")return D;if(H.status==="dirty")return H$(H.value);if(Q.value==="dirty")return H$(H.value);return H});else{if(Q.value==="aborted")return D;let Y=this._def.schema._parseSync({data:J,path:W.path,parent:W});if(Y.status==="aborted")return D;if(Y.status==="dirty")return H$(Y.value);if(Q.value==="dirty")return H$(Y.value);return Y}}if(X.type==="refinement"){let J=(Y)=>{let H=X.refinement(Y,G);if(W.common.async)return Promise.resolve(H);if(H instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return Y};if(W.common.async===!1){let Y=this._def.schema._parseSync({data:W.data,path:W.path,parent:W});if(Y.status==="aborted")return D;if(Y.status==="dirty")Q.dirty();return J(Y.value),{status:Q.value,value:Y.value}}else return this._def.schema._parseAsync({data:W.data,path:W.path,parent:W}).then((Y)=>{if(Y.status==="aborted")return D;if(Y.status==="dirty")Q.dirty();return J(Y.value).then(()=>{return{status:Q.value,value:Y.value}})})}if(X.type==="transform")if(W.common.async===!1){let J=this._def.schema._parseSync({data:W.data,path:W.path,parent:W});if(!W$(J))return D;let Y=X.transform(J.value,G);if(Y instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:Q.value,value:Y}}else return this._def.schema._parseAsync({data:W.data,path:W.path,parent:W}).then((J)=>{if(!W$(J))return D;return Promise.resolve(X.transform(J.value,G)).then((Y)=>({status:Q.value,value:Y}))});b.assertNever(X)}}i.create=($,Q,W)=>{return new i({schema:$,typeName:K.ZodEffects,effect:Q,...q(W)})};i.createWithPreprocess=($,Q,W)=>{return new i({schema:Q,effect:{type:"preprocess",transform:$},typeName:K.ZodEffects,...q(W)})};class n extends C{_parse($){if(this._getType($)===w.undefined)return h(void 0);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}n.create=($,Q)=>{return new n({innerType:$,typeName:K.ZodOptional,...q(Q)})};class $$ extends C{_parse($){if(this._getType($)===w.null)return h(null);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}$$.create=($,Q)=>{return new $$({innerType:$,typeName:K.ZodNullable,...q(Q)})};class C$ extends C{_parse($){let{ctx:Q}=this._processInputParams($),W=Q.data;if(Q.parsedType===w.undefined)W=this._def.defaultValue();return this._def.innerType._parse({data:W,path:Q.path,parent:Q})}removeDefault(){return this._def.innerType}}C$.create=($,Q)=>{return new C$({innerType:$,typeName:K.ZodDefault,defaultValue:typeof Q.default==="function"?Q.default:()=>Q.default,...q(Q)})};class b$ extends C{_parse($){let{ctx:Q}=this._processInputParams($),W={...Q,common:{...Q.common,issues:[]}},X=this._def.innerType._parse({data:W.data,path:W.path,parent:{...W}});if(V$(X))return X.then((G)=>{return{status:"valid",value:G.status==="valid"?G.value:this._def.catchValue({get error(){return new m(W.common.issues)},input:W.data})}});else return{status:"valid",value:X.status==="valid"?X.value:this._def.catchValue({get error(){return new m(W.common.issues)},input:W.data})}}removeCatch(){return this._def.innerType}}b$.create=($,Q)=>{return new b$({innerType:$,typeName:K.ZodCatch,catchValue:typeof Q.catch==="function"?Q.catch:()=>Q.catch,...q(Q)})};class y$ extends C{_parse($){if(this._getType($)!==w.nan){let W=this._getOrReturnCtx($);return M(W,{code:B.invalid_type,expected:w.nan,received:W.parsedType}),D}return{status:"valid",value:$.data}}}y$.create=($)=>{return new y$({typeName:K.ZodNaN,...q($)})};var a1=Symbol("zod_brand");class s$ extends C{_parse($){let{ctx:Q}=this._processInputParams($),W=Q.data;return this._def.type._parse({data:W,path:Q.path,parent:Q})}unwrap(){return this._def.type}}class m$ extends C{_parse($){let{status:Q,ctx:W}=this._processInputParams($);if(W.common.async)return(async()=>{let G=await this._def.in._parseAsync({data:W.data,path:W.path,parent:W});if(G.status==="aborted")return D;if(G.status==="dirty")return Q.dirty(),H$(G.value);else return this._def.out._parseAsync({data:G.value,path:W.path,parent:W})})();else{let X=this._def.in._parseSync({data:W.data,path:W.path,parent:W});if(X.status==="aborted")return D;if(X.status==="dirty")return Q.dirty(),{status:"dirty",value:X.value};else return this._def.out._parseSync({data:X.value,path:W.path,parent:W})}}static create($,Q){return new m$({in:$,out:Q,typeName:K.ZodPipeline})}}class I$ extends C{_parse($){let Q=this._def.innerType._parse($),W=(X)=>{if(W$(X))X.value=Object.freeze(X.value);return X};return V$(Q)?Q.then((X)=>W(X)):W(Q)}unwrap(){return this._def.innerType}}I$.create=($,Q)=>{return new I$({innerType:$,typeName:K.ZodReadonly,...q(Q)})};function x0($,Q){let W=typeof $==="function"?$(Q):typeof $==="string"?{message:$}:$;return typeof W==="string"?{message:W}:W}function m0($,Q={},W){if($)return z$.create().superRefine((X,G)=>{let J=$(X);if(J instanceof Promise)return J.then((Y)=>{if(!Y){let H=x0(Q,X),_=H.fatal??W??!0;G.addIssue({code:"custom",...H,fatal:_})}});if(!J){let Y=x0(Q,X),H=Y.fatal??W??!0;G.addIssue({code:"custom",...Y,fatal:H})}return});return z$.create()}var s1={object:g.lazycreate},K;(function($){$.ZodString="ZodString",$.ZodNumber="ZodNumber",$.ZodNaN="ZodNaN",$.ZodBigInt="ZodBigInt",$.ZodBoolean="ZodBoolean",$.ZodDate="ZodDate",$.ZodSymbol="ZodSymbol",$.ZodUndefined="ZodUndefined",$.ZodNull="ZodNull",$.ZodAny="ZodAny",$.ZodUnknown="ZodUnknown",$.ZodNever="ZodNever",$.ZodVoid="ZodVoid",$.ZodArray="ZodArray",$.ZodObject="ZodObject",$.ZodUnion="ZodUnion",$.ZodDiscriminatedUnion="ZodDiscriminatedUnion",$.ZodIntersection="ZodIntersection",$.ZodTuple="ZodTuple",$.ZodRecord="ZodRecord",$.ZodMap="ZodMap",$.ZodSet="ZodSet",$.ZodFunction="ZodFunction",$.ZodLazy="ZodLazy",$.ZodLiteral="ZodLiteral",$.ZodEnum="ZodEnum",$.ZodEffects="ZodEffects",$.ZodNativeEnum="ZodNativeEnum",$.ZodOptional="ZodOptional",$.ZodNullable="ZodNullable",$.ZodDefault="ZodDefault",$.ZodCatch="ZodCatch",$.ZodPromise="ZodPromise",$.ZodBranded="ZodBranded",$.ZodPipeline="ZodPipeline",$.ZodReadonly="ZodReadonly"})(K||(K={}));var t1=($,Q={message:`Input not instance of ${$.name}`})=>m0((W)=>W instanceof $,Q),c0=u.create,l0=G$.create,e1=y$.create,$3=Y$.create,u0=K$.create,Q3=_$.create,W3=x$.create,X3=S$.create,G3=L$.create,Y3=z$.create,J3=X$.create,H3=o.create,_3=g$.create,z3=d.create,B3=g.create,w3=g.strictCreate,M3=q$.create,j3=a$.create,U3=N$.create,E3=a.create,V3=Z$.create,A3=h$.create,D3=B$.create,K3=D$.create,S3=O$.create,L3=F$.create,q3=J$.create,N3=R$.create,O3=w$.create,F3=i.create,R3=n.create,C3=$$.create,b3=i.createWithPreprocess,I3=m$.create,k3=()=>c0().optional(),v3=()=>l0().optional(),f3=()=>u0().optional(),T3={string:($)=>u.create({...$,coerce:!0}),number:($)=>G$.create({...$,coerce:!0}),boolean:($)=>K$.create({...$,coerce:!0}),bigint:($)=>Y$.create({...$,coerce:!0}),date:($)=>_$.create({...$,coerce:!0})};var P3=D;function d0($){if(!$.name)throw Error("Plugin must have a name");if(typeof $.name!=="string"||$.name.trim()==="")throw Error("Plugin name must be a non-empty string");if($.instanceId!==void 0&&typeof $.instanceId!=="string")throw Error("Plugin instanceId must be a string");if($.version!==void 0&&typeof $.version!=="string")throw Error("Plugin version must be a string");if($.permissions!==void 0){if(!Array.isArray($.permissions))throw Error("Plugin permissions must be an array");let Q=["secrets","network","filesystem","env","subprocess","enterprise"];for(let W of $.permissions)if(!Q.includes(W))throw Error(`Invalid permission: ${W}. Valid permissions are: ${Q.join(", ")}`)}if($.resolvers!==void 0){if(typeof $.resolvers!=="object"||$.resolvers===null)throw Error("Plugin resolvers must be an object");for(let[Q,W]of Object.entries($.resolvers)){if(!Q.startsWith("$"))throw Error(`Resolver name "${Q}" must start with $ (e.g., "$${Q}")`);if(typeof W!=="function")throw Error(`Resolver "${Q}" must be a function`)}}if($.hooks!==void 0){if(typeof $.hooks!=="object"||$.hooks===null)throw Error("Plugin hooks must be an object");let Q=["parse.after","request.before","request.compiled","request.after","response.after","error","validate"];for(let[W,X]of Object.entries($.hooks)){if(!Q.includes(W))throw Error(`Invalid hook: "${W}". Valid hooks are: ${Q.join(", ")}`);if(typeof X!=="function")throw Error(`Hook "${W}" must be a function`)}}if($.commands!==void 0){if(typeof $.commands!=="object"||$.commands===null)throw Error("Plugin commands must be an object");for(let[Q,W]of Object.entries($.commands))if(typeof W!=="function")throw Error(`Command "${Q}" must be a function`)}if($.middleware!==void 0){if(!Array.isArray($.middleware))throw Error("Plugin middleware must be an array");for(let Q=0;Q<$.middleware.length;Q++)if(typeof $.middleware[Q]!=="function")throw Error(`Middleware at index ${Q} must be a function`)}if($.tools!==void 0){if(typeof $.tools!=="object"||$.tools===null)throw Error("Plugin tools must be an object");for(let[Q,W]of Object.entries($.tools)){if(typeof W.description!=="string")throw Error(`Tool "${Q}" must have a description`);if(typeof W.args!=="object"||W.args===null)throw Error(`Tool "${Q}" must have args schema`);if(typeof W.execute!=="function")throw Error(`Tool "${Q}" must have an execute function`)}}if($.event!==void 0&&typeof $.event!=="function")throw Error("Plugin event handler must be a function");if($.setup!==void 0&&typeof $.setup!=="function")throw Error("Plugin setup must be a function");if($.teardown!==void 0&&typeof $.teardown!=="function")throw Error("Plugin teardown must be a function");return{...$,instanceId:$.instanceId??"default"}}function n0($){let Q=M$.object($.args);return{description:$.description,args:Q,execute:async(W,X)=>{let G=Q.parse(W);return await $.execute(G,X)}}}function k$($){return`${$.name}#${$.instanceId??"default"}`}function p0($){let Q=$.indexOf("#");if(Q===-1)return{name:$,instanceId:"default"};return{name:$.slice(0,Q),instanceId:$.slice(Q+1)}}function U0($){return typeof $==="object"&&$!==null&&!Array.isArray($)&&"command"in $&&Array.isArray($.command)}function i0($){return typeof $==="object"&&$!==null&&!Array.isArray($)&&"name"in $&&typeof $.name==="string"&&!("command"in $)}function x3($){if(typeof $==="string")return $.startsWith("file://");if(Array.isArray($)&&typeof $[0]==="string")return $[0].startsWith("file://");return!1}function g3($){if(typeof $==="string")return!$.startsWith("file://")&&!U0($);if(Array.isArray($)&&typeof $[0]==="string")return!$[0].startsWith("file://");return!1}function r0($,Q){let W=Q$("node:path"),X=W.relative(Q,$);return!X.startsWith("..")&&!W.isAbsolute(X)}function o0($,Q,W){if(!$.startsWith("file://"))throw Error(`Invalid file URL: ${$}`);let X=Q$("node:path"),G=$.slice(7),J;if(G.startsWith("/"))J=X.normalize(G);else if(G.startsWith("./")||G.startsWith("../"))J=X.resolve(Q,G);else throw Error(`Invalid file plugin path: ${$}. Use file://./relative/path.ts or file:///absolute/path.ts`);if(!W&&!r0(J,Q))throw Error(`Plugin path "${$}" resolves outside project root. Set security.allowPluginsOutsideProject: true to allow.`);return J}async function Z3($,Q,W){let X=Q$("node:fs/promises");if(W)return $;try{let G=await X.realpath($);if(!r0(G,Q))throw Error(`Plugin path "${$}" resolves to "${G}" which is outside project root. Symlinks pointing outside the project are not allowed. Set security.allowPluginsOutsideProject: true to allow.`);return G}catch(G){if(G.code==="ENOENT")return $;throw G}}function t$($,Q,W){let X=$.permissions??[],G=Q?.[$.name];if(G!==void 0){for(let Y of X)if(!G.includes(Y))W.push(`Plugin '${$.name}' requires '${Y}' permission but it was denied. Some features may not work. Add to security.pluginPermissions to enable.`);return G}let J=Q?.default;if(J!==void 0){let Y=X.filter((H)=>J.includes(H));for(let H of X)if(!J.includes(H))W.push(`Plugin '${$.name}' requires '${H}' permission but it was denied by default. Some features may not work. Add to security.pluginPermissions to enable.`);return Y}return X}async function e$($){let{projectRoot:Q,plugins:W,security:X,pluginPermissions:G}=$,J=$.warnings??[],Y=[],H=new Map;for(let _ of W)try{let z=await h3(_,{projectRoot:Q,allowOutsideProject:X?.allowPluginsOutsideProject??!1,warnings:J,...G!==void 0?{pluginPermissions:G}:{}});if(!z)continue;let j=k$(z.plugin),U=H.get(j);if(U!==void 0)Y[U]=z;else H.set(j,Y.length),Y.push(z)}catch(z){let j=z instanceof Error?z.message:String(z);J.push(`Failed to load plugin: ${j}`)}return{plugins:Y,warnings:J}}async function h3($,Q){let{projectRoot:W,allowOutsideProject:X,pluginPermissions:G,warnings:J}=Q;if(i0($)){let _=t$($,G,J);return{plugin:{...$,instanceId:$.instanceId??"default"},id:k$($),source:"inline",permissions:_,initialized:!1}}if(U0($))return{plugin:{name:`subprocess:${$.command.join(" ")}`,instanceId:"default"},id:`subprocess:${$.command.join(" ")}#default`,source:"subprocess",permissions:[],initialized:!1,_subprocessConfig:$};let Y,H;if(Array.isArray($))Y=$[0],H=$[1];else Y=$;if(Y.startsWith("file://")){let _=o0(Y,W,X);return await y3(_,H,G,J,W,X)}return await m3(Y,W,H,G,J)}async function y3($,Q,W,X,G,J){try{let Y=$;if(G!==void 0)Y=await Z3($,G,J??!1);let H=await import(Y),_=H.default??H,z;if(typeof _==="function")z=Q?_(Q):_();else if(typeof _==="object"&&_!==null)z=_;else throw Error(`File "${$}" does not export a valid plugin`);if(z={...z,instanceId:z.instanceId??"default"},Q&&typeof Q.instanceId==="string")z={...z,instanceId:Q.instanceId};let j=t$(z,W,X);return{plugin:z,id:k$(z),source:"file",permissions:j,initialized:!1}}catch(Y){throw Error(`Failed to load plugin from "${$}": ${Y instanceof Error?Y.message:String(Y)}`)}}async function m3($,Q,W,X,G){try{let J=$,Y=$.lastIndexOf("@");if(Y>0)J=$.slice(0,Y);let H=Q$("node:path"),{createRequire:_}=Q$("node:module"),U=await import(_(H.join(Q,"package.json")).resolve(J)),O=U.default??U,L;if(typeof O==="function")L=W?O(W):O();else if(typeof O==="object"&&O!==null)L=O;else throw Error(`Package "${J}" does not export a valid plugin`);if(L={...L,instanceId:L.instanceId??"default"},W&&typeof W.instanceId==="string")L={...L,instanceId:W.instanceId};let T=t$(L,X,G);return{plugin:L,id:k$(L),source:"npm",permissions:T,initialized:!1}}catch(J){throw Error(`Failed to load plugin "${$}" from project "${Q}": ${J instanceof Error?J.message:String(J)}`)}}function c3($,Q){return[...$,...Q]}class Q0 extends Error{permission;pluginName;constructor($,Q){super(`Plugin "${Q}" does not have "${$}" permission`);this.permission=$;this.pluginName=Q;this.name="PermissionDeniedError"}}class a0{secrets=new Map;constructor($){if($)for(let[Q,W]of Object.entries($))this.secrets.set(Q,W)}async get($){return this.secrets.get($)}set($,Q){this.secrets.set($,Q)}}function $0($,Q,W){let X=W.relative(Q,$);return!X.startsWith("..")&&!W.isAbsolute(X)}function l3($,Q){let W=Q$("node:fs/promises"),X=Q$("node:path"),G=async(Y)=>{let H=X.resolve($,Y);if(!Q&&!$0(H,$,X))throw Error(`Path "${Y}" is outside project root. Plugins need "filesystem" permission to access files outside project.`);if(!Q)try{let _=await W.realpath(H);if(!$0(_,$,X))throw Error(`Path "${Y}" resolves to "${_}" which is outside project root. Symlinks pointing outside the project are not allowed.`);return _}catch(_){if(_.code==="ENOENT")return H;throw _}return H},J=async(Y)=>{let H=X.resolve($,Y);if(!Q&&!$0(H,$,X))throw Error(`Path "${Y}" is outside project root. Plugins need "filesystem" permission to access files outside project.`);if(!Q){let _=X.dirname(H);try{let z=await W.realpath(_);if(!$0(z,$,X))throw Error(`Path "${Y}" parent directory resolves to "${z}" which is outside project root. Symlinks pointing outside the project are not allowed.`)}catch(z){if(z.code!=="ENOENT")throw z}}return H};return{async readFile(Y){let H=await G(Y);return await W.readFile(H,"utf-8")},async writeFile(Y,H){let _=await J(Y);await W.writeFile(_,H,"utf-8")}}}function u3($){let Q=Q$("node:child_process");return async(W,X)=>{return new Promise((G,J)=>{let Y=Q.spawn(W,X,{cwd:$,stdio:["pipe","pipe","pipe"]}),H="",_="";Y.stdout?.on("data",(z)=>{H+=z.toString("utf-8")}),Y.stderr?.on("data",(z)=>{_+=z.toString("utf-8")}),Y.on("close",(z)=>{if(z===0)G({stdout:H,stderr:_});else J(Error(`Command failed with code ${z}: ${_}`))}),Y.on("error",(z)=>{J(z)})})}}function d3($){let Q=`[plugin:${$}]`;return{debug:(W)=>{if(process.env.DEBUG)console.debug(`${Q} ${W}`)},info:(W)=>{console.info(`${Q} ${W}`)},warn:(W)=>{console.warn(`${Q} ${W}`)},error:(W)=>{console.error(`${Q} ${W}`)}}}function W0($){let{plugin:Q,permissions:W,config:X,enterprise:G,secrets:J}=$,Y=Q.name,H={projectRoot:X.projectRoot,config:X,log:d3(Y)};if(W.includes("secrets"))H.secrets=new a0(J);if(W.includes("network"))H.fetch=globalThis.fetch;if(W.includes("filesystem"))H.fs=l3(X.projectRoot,X.security.allowPluginsOutsideProject);if(W.includes("env"))H.env=process.env;if(W.includes("subprocess"))H.spawn=u3(X.projectRoot);if(W.includes("enterprise")&&G)H.enterprise=G;return H}function n3($,Q,W){let X=[];for(let G of W)if(!Q.includes(G))X.push(`Plugin "${$.name}" requires "${G}" permission but it was denied.`);return X}function s0($,Q){return $.includes(Q)}function p3($,Q,W){if(!s0($,Q))throw new Q0(Q,W)}import{spawn as i3}from"node:child_process";function P($){let Q={...$},W={when(X,G){if(X)Q={...Q,...G};return W},ifDefined(X,G){if(G!==void 0)Q={...Q,[X]:G};return W},build(){return Q}};return W}var E0=1,r3=5000,o3=1e4,t0=3,a3=500,s3=10485760;class X0{config;projectRoot;process=null;requestId=0;pendingRequests=new Map;buffer="";initialized=!1;restartCount=0;capabilities={hooks:[],resolvers:[],commands:[]};pluginInfo={name:"unknown"};constructor($,Q){this.config=$;this.projectRoot=Q}async start(){await this.spawn(),await this.initialize()}async spawn(){let[$,...Q]=this.config.command;if(!$)throw Error("Subprocess plugin has empty command");this.process=i3($,Q,{cwd:this.projectRoot,stdio:["pipe","pipe","pipe"],env:this.config.env??{}}),this.process.stdout?.on("data",(W)=>{this.handleStdout(W)}),this.process.stderr?.on("data",(W)=>{let X=W.toString("utf-8").trim();if(X)console.error(`[subprocess:${this.pluginInfo.name}] ${X}`)}),this.process.on("close",(W,X)=>{this.handleClose(W,X)}),this.process.on("error",(W)=>{this.handleError(W)})}async initialize(){let $=this.config.startupTimeoutMs??o3,Q=await this.sendRequest({id:this.nextId(),type:"init",protocolVersion:E0,config:this.config.config??{},projectRoot:this.projectRoot},$);if(Q.type==="error")throw Error(`Plugin init failed: ${Q.error.message}`);let X=Q.result;if(X.protocolVersion>E0)throw Error(`Plugin requires protocol version ${X.protocolVersion}, but t-req supports version ${E0}`);this.pluginInfo=P({name:X.name}).ifDefined("version",X.version).ifDefined("permissions",X.permissions).build(),this.capabilities={hooks:X.hooks??[],resolvers:X.resolvers??[],commands:X.commands??[]},this.initialized=!0}handleStdout($){if(this.buffer.length+$.length>s3){this.buffer="",console.error(`[subprocess:${this.pluginInfo.name}] stdout buffer exceeded, clearing`);return}this.buffer+=$.toString("utf-8");let Q=this.buffer.split(`
|
|
2
|
+
`);this.buffer=Q.pop()??"";for(let W of Q){let X=W.trim();if(!X)continue;try{let G=JSON.parse(X);this.handleResponse(G)}catch{console.error(`[subprocess:${this.pluginInfo.name}] Invalid JSON: ${X.slice(0,100)}`)}}}handleResponse($){let Q=this.pendingRequests.get($.id);if(!Q){console.error(`[subprocess:${this.pluginInfo.name}] Unknown response ID: ${$.id}`);return}clearTimeout(Q.timeout),this.pendingRequests.delete($.id),Q.resolve($)}handleClose($,Q){this.process=null;for(let[W,X]of this.pendingRequests)clearTimeout(X.timeout),X.reject(Error(`Plugin process exited with code ${$}, signal ${Q}`));if(this.pendingRequests.clear(),this.initialized&&this.restartCount<(this.config.maxRestarts??t0))this.restartCount++,console.warn(`[subprocess:${this.pluginInfo.name}] Process crashed, restarting (${this.restartCount}/${this.config.maxRestarts??t0})`),this.spawn().then(()=>this.initialize()).catch((W)=>{console.error(`[subprocess:${this.pluginInfo.name}] Restart failed: ${W.message}`)})}handleError($){console.error(`[subprocess:${this.pluginInfo.name}] Process error: ${$.message}`);for(let[Q,W]of this.pendingRequests)clearTimeout(W.timeout),W.reject($);this.pendingRequests.clear()}nextId(){return String(++this.requestId)}async sendRequest($,Q=this.config.timeoutMs??r3){if(!this.process?.stdin)throw Error("Plugin process not running");return new Promise((W,X)=>{let G=setTimeout(()=>{this.pendingRequests.delete($.id),X(Error(`Request timed out after ${Q}ms`))},Q);this.pendingRequests.set($.id,{resolve:W,reject:X,timeout:G});let J=`${JSON.stringify($)}
|
|
3
3
|
`;this.process?.stdin?.write(J)})}sendEvent($){if(!this.process?.stdin)return;let Q=JSON.stringify({type:"event",event:$});this.process.stdin.write(`${Q}
|
|
4
|
-
`)}async callResolver($,Q){if(!this.capabilities.resolvers.includes($))throw Error(`Resolver "${$}" not supported by plugin`);let
|
|
5
|
-
`)}catch{}let $=this.config.gracePeriodMs??m0;await new Promise((Q)=>{let G=setTimeout(()=>{if(this.process)this.process.kill("SIGKILL");Q()},$);this.process?.on("close",()=>{clearTimeout(G),Q()})}),this.process=null}getPluginInfo(){return this.pluginInfo}getCapabilities(){return this.capabilities}isInitialized(){return this.initialized}}function r3($){let Q=$.getPluginInfo(),G=$.getCapabilities(),X={};for(let H of G.resolvers)X[H]=async(...W)=>{return await $.callResolver(H,W)};let Y={};if(G.hooks.includes("parse.after"))Y["parse.after"]=async(H,W)=>{let _=await $.callHook("parse.after",{file:H.file,path:H.path},{file:W.file});if(_.file)W.file=_.file};if(G.hooks.includes("request.before"))Y["request.before"]=async(H,W)=>{let _=await $.callHook("request.before",{request:H.request,variables:H.variables,ctx:u$(H.ctx)},{request:W.request});if(_.request)W.request=_.request;let z=_.skip;if(typeof z==="boolean")W.skip=z};if(G.hooks.includes("request.compiled"))Y["request.compiled"]=async(H,W)=>{let _=await $.callHook("request.compiled",{request:H.request,variables:H.variables,ctx:u$(H.ctx)},{request:W.request});if(_.request)W.request=_.request};if(G.hooks.includes("request.after"))Y["request.after"]=async(H)=>{await $.callHook("request.after",{request:H.request,ctx:u$(H.ctx)},{})};if(G.hooks.includes("response.after"))Y["response.after"]=async(H,W)=>{let _={status:H.response.status,statusText:H.response.statusText,headers:Object.fromEntries(H.response.headers.entries())},z=await $.callHook("response.after",{request:H.request,response:_,timing:H.timing,ctx:u$(H.ctx)},{}),w=z.status,E=z.statusText,N=z.headers,x=z.retry;if(typeof w==="number")W.status=w;if(typeof E==="string")W.statusText=E;if(N&&typeof N==="object")W.headers=N;if(x&&typeof x==="object")W.retry=x};if(G.hooks.includes("error"))Y.error=async(H,W)=>{let _=await $.callHook("error",{request:H.request,error:{message:H.error.message,code:H.error.code},ctx:u$(H.ctx)},{}),z=_.error,w=_.retry,E=_.suppress;if(z&&typeof z==="object"&&"message"in z)W.error=Error(z.message);if(w&&typeof w==="object")W.retry=w;if(typeof E==="boolean")W.suppress=E};let J=G.hooks.length>0?async({event:H})=>{$.sendEvent(H)}:void 0;return P({name:Q.name,instanceId:"default",teardown:async()=>{await $.shutdown()}}).ifDefined("version",Q.version).ifDefined("permissions",Q.permissions).ifDefined("resolvers",Object.keys(X).length>0?X:void 0).ifDefined("hooks",Object.keys(Y).length>0?Y:void 0).ifDefined("event",J).build()}function u$($){return P({retries:$.retries,maxRetries:$.maxRetries,session:{id:$.session.id,variables:$.session.variables},variables:$.variables,config:{projectRoot:$.config.projectRoot,variables:$.config.variables,security:$.config.security},projectRoot:$.projectRoot}).ifDefined("enterprise",$.enterprise?{org:$.enterprise.org,user:$.enterprise.user,team:$.enterprise.team,session:{id:$.enterprise.session.id,startedAt:$.enterprise.session.startedAt.toISOString(),source:$.enterprise.session.source,token:$.enterprise.session.token}}:void 0).build()}async function X3($,Q){let G=new G3($,Q);await G.start();let X=G.getPluginInfo();return{plugin:r3(G),id:`${X.name}#default`,source:"subprocess",permissions:X.permissions??[],initialized:!0}}var Y3=30000;async function o3($,Q,G){let X,Y=new Promise((J,H)=>{X=setTimeout(()=>H(Error(G)),Q)});try{return await Promise.race([$,Y])}finally{if(X!==void 0)clearTimeout(X)}}class H3{options;plugins=[];resolvers={};commands={};middleware=[];tools={};warnings=[];initialized=!1;config;onEvent;enterprise;secrets;session;constructor($){this.options=$;if(this.config={projectRoot:$.projectRoot,variables:{},security:{allowExternalFiles:!1,allowPluginsOutsideProject:$.security?.allowPluginsOutsideProject??!1}},$.onEvent!==void 0)this.onEvent=$.onEvent;if($.enterprise!==void 0)this.enterprise=$.enterprise;if($.secrets!==void 0)this.secrets=$.secrets;this.session={id:crypto.randomUUID(),variables:{}}}setEventSink($){this.onEvent=$}async initialize(){if(this.initialized)return;let $=this.options.plugins??[],Q=await t$({projectRoot:this.options.projectRoot,plugins:$,warnings:this.warnings,...this.options.security!==void 0?{security:this.options.security}:{},...this.options.pluginPermissions!==void 0?{pluginPermissions:this.options.pluginPermissions}:{}});for(let G of Q.plugins)await this.initializePlugin(G);this.initialized=!0}async initializePlugin($){let Q=Date.now();try{if($.source==="subprocess"&&"_subprocessConfig"in $){let Y=$._subprocessConfig,J=await X3(Y,this.options.projectRoot);$.plugin=J.plugin,$.permissions=J.permissions,$.id=J.id}this.emitPluginEvent({type:"pluginLoaded",name:$.plugin.name,source:$.source,...$.plugin.version!==void 0?{version:$.plugin.version}:{}});let G=Q3({plugin:$.plugin,permissions:$.permissions,config:this.config,...this.enterprise!==void 0?{enterprise:this.enterprise}:{},...this.secrets!==void 0?{secrets:this.secrets}:{}});if($.plugin.setup)await $.plugin.setup(G);$.initialized=!0,this.registerPluginContributions($);let X=Date.now()-Q;this.emitPluginEvent({type:"pluginInitialized",name:$.plugin.name,durationMs:X}),this.plugins.push($)}catch(G){let X=G instanceof Error?G.message:String(G);this.warnings.push(`Plugin "${$.plugin.name}" setup failed: ${X}`),this.emitPluginEvent({type:"pluginError",name:$.plugin.name,stage:"setup",message:X,recoverable:!0})}}registerPluginContributions($){let Q=$.plugin;if(Q.resolvers)for(let[G,X]of Object.entries(Q.resolvers)){if(this.resolvers[G])this.warnings.push(`Resolver "${G}" from "${Q.name}" shadows existing resolver`);this.resolvers[G]=X}if(Q.commands)for(let[G,X]of Object.entries(Q.commands)){if(this.commands[G]){this.warnings.push(`Command "${G}" from "${Q.name}" shadows same command from "${this.commands[G].pluginName}" (loaded first, takes precedence)`);continue}this.commands[G]={handler:X,pluginName:Q.name}}if(Q.middleware)for(let G of Q.middleware)this.middleware.push({fn:G,pluginName:Q.name});if(Q.tools)for(let[G,X]of Object.entries(Q.tools)){if(this.tools[G])this.warnings.push(`Tool "${G}" from "${Q.name}" shadows existing tool`);this.tools[G]={definition:X,pluginName:Q.name}}}async teardown(){for(let $=this.plugins.length-1;$>=0;$--){let Q=this.plugins[$];if(!Q)continue;try{if(Q.plugin.teardown)await Q.plugin.teardown();this.emitPluginEvent({type:"pluginTeardown",name:Q.plugin.name})}catch(G){let X=G instanceof Error?G.message:String(G);this.warnings.push(`Plugin "${Q.plugin.name}" teardown failed: ${X}`),this.emitPluginEvent({type:"pluginError",name:Q.plugin.name,stage:"teardown",message:X,recoverable:!0})}}this.plugins=[],this.initialized=!1}createHookContext($){return{retries:$.retries??0,maxRetries:$.maxRetries??3,session:this.session,variables:$.variables??{},config:this.config,projectRoot:this.options.projectRoot,...this.enterprise!==void 0?{enterprise:this.enterprise}:{}}}async triggerParseAfter($,Q){return await this.executeHook("parse.after",$,Q)}async triggerRequestBefore($,Q){let G=await this.executeHook("request.before",$,Q);return{...G,...G.output.skip!==void 0?{skip:G.output.skip}:{}}}async triggerRequestCompiled($,Q){return await this.executeHook("request.compiled",$,Q)}async triggerRequestAfter($){await this.executeReadOnlyHook("request.after",$)}async triggerResponseAfter($,Q){let G=await this.executeHook("response.after",$,Q);return{...G,...G.output.retry!==void 0?{retry:G.output.retry}:{}}}async triggerError($,Q){let G=await this.executeHook("error",$,Q);return{...G,...G.output.retry!==void 0?{retry:G.output.retry}:{}}}async executeHook($,Q,G){let X=!1,Y="ctx"in Q?Q.ctx:this.createHookContext({});for(let J of this.plugins){let H=J.plugin.hooks?.[$];if(!H)continue;let W=Date.now(),_=JSON.stringify(G);this.emitPluginEvent({type:"pluginHookStarted",name:J.plugin.name,hook:$,ctx:Y});try{let z=Promise.resolve(H(Q,G));await o3(z,Y3,`Hook "${$}" in "${J.plugin.name}" timed out after ${Y3}ms`);let w=JSON.stringify(G),E=_!==w;if(E)X=!0;let N=Date.now()-W;this.emitPluginEvent({type:"pluginHookFinished",name:J.plugin.name,hook:$,durationMs:N,modified:E,ctx:Y})}catch(z){let w=z instanceof Error?z.message:String(z);this.warnings.push(`Hook "${$}" in "${J.plugin.name}" failed: ${w}`),this.emitPluginEvent({type:"pluginError",name:J.plugin.name,stage:"hook",hook:$,message:w,recoverable:!0})}}return{output:G,modified:X}}async executeReadOnlyHook($,Q){let G="ctx"in Q?Q.ctx:this.createHookContext({});for(let X of this.plugins){let Y=X.plugin.hooks?.[$];if(!Y)continue;let J=Date.now();this.emitPluginEvent({type:"pluginHookStarted",name:X.plugin.name,hook:$,ctx:G});try{let H=Promise.resolve(Y(Q));await o3(H,Y3,`Hook "${$}" in "${X.plugin.name}" timed out after ${Y3}ms`);let W=Date.now()-J;this.emitPluginEvent({type:"pluginHookFinished",name:X.plugin.name,hook:$,durationMs:W,modified:!1,ctx:G})}catch(H){let W=H instanceof Error?H.message:String(H);this.warnings.push(`Hook "${$}" in "${X.plugin.name}" failed: ${W}`),this.emitPluginEvent({type:"pluginError",name:X.plugin.name,stage:"hook",hook:$,message:W,recoverable:!0})}}}emitPluginEvent($){this.onEvent?.($);for(let Q of this.plugins)if(Q.plugin.event&&$.type!=="pluginLoaded");}emitEngineEvent($){this.onEvent?.($);for(let Q of this.plugins)if(Q.plugin.event)try{Q.plugin.event({event:$})}catch{}}getResolvers(){return{...this.resolvers}}getResolver($){return this.resolvers[$]}async callResolver($,Q){let G=this.resolvers[$];if(!G)return`{{${$}:ERROR}}`;let X=Date.now();try{let Y=await G(...Q),J=Date.now()-X;return this.emitPluginEvent({type:"pluginResolverCalled",name:$,resolver:$,durationMs:J}),Y}catch(Y){let J=Y instanceof Error?Y.message:String(Y);return this.warnings.push(`Resolver "${$}" failed: ${J}`),this.emitPluginEvent({type:"pluginError",name:"resolver",stage:"resolver",message:J,recoverable:!0}),`{{${$}:ERROR}}`}}getCommands(){let $={};for(let[Q,{handler:G}]of Object.entries(this.commands))$[Q]=G;return $}getCommand($){return this.commands[$]?.handler}getMiddleware(){return this.middleware.map(($)=>$.fn)}getTools(){let $={};for(let[Q,{definition:G}]of Object.entries(this.tools))$[Q]=G;return $}getPlugins(){return[...this.plugins]}getWarnings(){return[...this.warnings]}hasPlugins(){return this.plugins.length>0}getPlugin($){return this.plugins.find((Q)=>Q.plugin.name===$)}getPluginInfo(){return this.plugins.map(($)=>({name:$.plugin.name,source:$.source,permissions:$.permissions,...$.plugin.version!==void 0?{version:$.plugin.version}:{}}))}setSessionVariable($,Q){this.session.variables[$]=Q}getSessionVariables(){return{...this.session.variables}}}function a3($){return new H3($)}function s3($){throw Error(`${$} is not supported by this transport. Provide a transport that supports it.`)}function J3($=fetch){return{capabilities:{proxy:!1,validateSSL:!1},async fetch(Q,G,X){if(X.proxy)s3("proxy");if(X.validateSSL===!1)s3("validateSSL=false");return await $(Q,G)}}}function l0(){return typeof globalThis.Bun<"u"}function d$(){if(!l0())return J3(fetch);return{capabilities:{proxy:!0,validateSSL:!0},async fetch($,Q,G){let X={...Q??{}};if(G.proxy!==void 0)X.proxy=G.proxy;if(G.validateSSL===!1)X.tls={rejectUnauthorized:!1};return await fetch($,X)}}}import{access as u0,readFile as t3}from"node:fs/promises";import*as c from"node:path";async function d0($){try{return await u0($),!0}catch{return!1}}function p0(){return{cwd:()=>process.cwd(),path:{resolve:(...$)=>c.resolve(...$),dirname:($)=>c.dirname($),basename:($)=>c.basename($),extname:($)=>c.extname($),isAbsolute:($)=>c.isAbsolute($),sep:c.sep},exists:d0,readText:async($)=>await t3($,"utf8"),readBinary:async($)=>{let Q=await t3($);return Q.buffer.slice(Q.byteOffset,Q.byteOffset+Q.byteLength)}}}function n0($,Q){return Q!==void 0&&!["GET","HEAD"].includes($.toUpperCase())}function i0($,Q){let G=n0($.method,$.body)&&$.body!==void 0;return P({method:$.method,redirect:Q.followRedirects?"follow":"manual",signal:Q.signal}).ifDefined("headers",$.headers).ifDefined("body",G?$.body:void 0).build()}function r0($){if($.provided)return{signal:$.provided,isInternalTimeout:!1,cleanup:()=>{}};let Q=new AbortController,G=setTimeout(()=>Q.abort(),$.timeout);return{signal:Q.signal,isInternalTimeout:!0,cleanup:()=>clearTimeout(G)}}function o0($,Q){if($ instanceof Error&&$.name==="AbortError"){if(Q.isInternalTimeout)return Error(`Request timeout after ${Q.timeout}ms`)}return $ instanceof Error?$:Error(String($))}async function e3($,Q,G){let X=Q.timeout??30000,Y=P({timeout:X}).ifDefined("provided",Q.signal).build(),{signal:J,isInternalTimeout:H,cleanup:W}=r0(Y),_=P({followRedirects:Q.followRedirects??!0,signal:J}).build(),z=i0($,_);try{let w=P({}).ifDefined("proxy",Q.proxy).ifDefined("validateSSL",Q.validateSSL).build();return await G.fetch($.url,z,w)}catch(w){throw o0(w,{timeout:X,isInternalTimeout:H})}finally{W()}}var a0={".json":"application/json",".xml":"application/xml",".txt":"text/plain",".html":"text/html",".htm":"text/html",".css":"text/css",".js":"application/javascript",".mjs":"application/javascript",".ts":"application/typescript",".csv":"text/csv",".md":"text/markdown",".yaml":"text/yaml",".yml":"text/yaml",".svg":"image/svg+xml",".jpg":"image/jpeg",".jpeg":"image/jpeg",".png":"image/png",".gif":"image/gif",".webp":"image/webp",".ico":"image/x-icon",".bmp":"image/bmp",".tiff":"image/tiff",".tif":"image/tiff",".pdf":"application/pdf",".doc":"application/msword",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xls":"application/vnd.ms-excel",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".ppt":"application/vnd.ms-powerpoint",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".zip":"application/zip",".gz":"application/gzip",".tar":"application/x-tar",".rar":"application/vnd.rar",".7z":"application/x-7z-compressed",".mp3":"audio/mpeg",".wav":"audio/wav",".ogg":"audio/ogg",".m4a":"audio/mp4",".mp4":"video/mp4",".webm":"video/webm",".avi":"video/x-msvideo",".mov":"video/quicktime",".wasm":"application/wasm",".bin":"application/octet-stream",".exe":"application/octet-stream",".dll":"application/octet-stream",".so":"application/octet-stream",".dylib":"application/octet-stream"},s0=new Set(["application/json","application/xml","application/javascript","application/typescript","text/plain","text/html","text/css","text/csv","text/xml","text/markdown","text/yaml","image/svg+xml"]);function $Q($){let Q=Q1($).toLowerCase();return a0[Q]??"application/octet-stream"}function QQ($){if($.startsWith("text/"))return!1;if(s0.has($))return!1;return!0}function E3($){return $.includes("\\")?"\\":"/"}function V3($){return $.split(/[\\/]+/).filter(Boolean)}function t0($){if($.startsWith("/")||$.startsWith("\\"))return!0;if(/^[A-Za-z]:[\\/]/.test($))return!0;if($.startsWith("\\\\"))return!0;return!1}function p$($,Q){let G=[];for(let X of Q){if(!X||X===".")continue;if(X===".."){G.pop();continue}G.push(X)}return($==="\\"?"\\":"/")+G.join($)}function e0($,Q){let G=E3($),X=/^[A-Za-z]:$/.test($),J=$.match(/^([A-Za-z]:)[\\/]?/)?.[1],H=V3($),W=V3(Q);if(J){let _=p$(G,[...H.slice(1),...W]);return`${J}${_}`}if(X){let _=p$(G,W);return`${$}${_}`}return p$(G,[...H,...W])}function $1($){if($==="")return"/";let Q=E3($),X=$.match(/^([A-Za-z]:)[\\/]?/)?.[1],Y=V3($);if(X){let J=p$(Q,Y.slice(1));return`${X}${J}`}return p$(Q,Y)}function Q1($){let Q=G1($),G=Q.lastIndexOf(".");if(G<=0)return"";return Q.slice(G)}function G1($){let Q=$.split(/[\\/]/);return Q[Q.length-1]??""}function GQ($,Q){if(t0($))throw Error(`Absolute paths not allowed: ${$}`);let G=e0(Q,$),X=$1(Q),Y=E3(X);if(G!==X&&!G.startsWith(X+Y))throw Error(`Path escapes base directory: ${$}`);return G}async function n$($,Q={}){let G=Q.basePath??Q.io?.cwd()??globalThis.process?.cwd?.()??".",X=GQ($,G),Y=$Q($),J=QQ(Y),H;if(Q.io){if(!await Q.io.exists(X))throw Error(`File not found: ${$}`);H=J?await Q.io.readBinary(X):await Q.io.readText(X)}else if(typeof globalThis.Bun<"u"){let _=globalThis.Bun.file(X);if(!await _.exists())throw Error(`File not found: ${$}`);H=J?await _.arrayBuffer():await _.text()}else throw Error("No IO adapter provided. Provide `options.io` (Node/Bun/Tauri) to load file bodies.");return{content:H,isBinary:J,mimeType:Y}}function U3($){return $.some((Q)=>Q.isFile)}async function A3($,Q={}){let G=new FormData,X=Q.basePath??Q.io?.cwd()??globalThis.process?.cwd?.()??".";for(let Y of $)if(Y.isFile&&Y.path){let J=await n$(Y.path,Q.io?{basePath:X,io:Q.io}:{basePath:X}),H=Y.filename??Q.io?.path.basename(Y.path)??X1(Y.path),W=new Blob([J.content],{type:J.mimeType});G.append(Y.name,W,H)}else G.append(Y.name,Y.value);return G}function X1($){let Q=$.split(/[\\/]/);return Q[Q.length-1]??""}function D3($){let Q=new URLSearchParams;for(let G of $){if(G.isFile)continue;Q.append(G.name,G.value)}return Q}function Y1($){return/^[A-Za-z0-9_]+$/.test($)}function L3($){let Q=[],G=0,X=0;while(G<$.length){let Y=$[G],J=$[G+1];if(Y==="{"&&J==="{"){if(G>X)Q.push({type:"text",value:$.slice(X,G)});let H=G;G+=2;let W=1,_="";while(G<$.length){let w=$[G],E=$[G+1];if(w==="{"&&E==="{"){W++,_+="{{",G+=2;continue}if(w==="}"&&E==="}"){if(W--,W===0){G+=2;break}_+="}}",G+=2;continue}_+=w,G++}if(W!==0)throw Error('Unterminated interpolation: missing "}}"');let z=$.slice(H,G);Q.push({type:"expr",expression:_,raw:z}),X=G;continue}G++}if(X<$.length)Q.push({type:"text",value:$.slice(X)});return Q}function N3($,Q){let G=Q.split("."),X=$;for(let Y of G){if(X===null||X===void 0)return;if(typeof X!=="object")return;X=X[Y]}return X}function O3($){let Q=$.trim();if(!Q.startsWith("$"))return null;if(!Q.endsWith(")"))return null;let G=Q.indexOf("(");if(G===-1)return null;let X=Q.slice(1,G).trim();if(!X||!Y1(X))return null;let Y=Q.slice(G+1,-1);return{resolverKey:`$${X}`,argText:Y}}function H1($,Q,G){let X=L3($);if(X.length===1&&X[0]?.type==="text")return $;let Y="";for(let J of X){if(J.type==="text"){Y+=J.value;continue}let H=J.expression.trim();if(O3(H))throw Error(`Resolver calls are not allowed inside resolver args: ${J.raw}`);let W=N3(Q,H);if(W===void 0){if(G==="throw")throw Error(`Undefined variable: ${H}`);Y+=G==="keep"?J.raw:"";continue}Y+=String(W)}return Y}function XQ($,Q,G){let X=H1($,Q,G).trim();if(!X)return[];try{let Y=JSON.parse(X);if(Array.isArray(Y))return Y.map((J)=>String(J))}catch{}return[X]}function J1($,Q,G={}){let{resolvers:X={},undefinedBehavior:Y="throw"}=G,J=L3($);if(J.length===1&&J[0]?.type==="text")return $;let H="";for(let W of J){if(W.type==="text"){H+=W.value;continue}let _=O3(W.expression);if(_){let E=X[_.resolverKey];if(E){let N=XQ(_.argText,Q,Y),x=E(...N);if(x instanceof Promise)throw Error(`Resolver ${_.resolverKey} returned a Promise. Use createInterpolator() for async resolvers.`);H+=String(x);continue}if(Y==="throw")throw Error(`Unknown resolver: ${_.resolverKey}`);H+=Y==="keep"?W.raw:"";continue}let z=W.expression.trim(),w=N3(Q,z);if(w===void 0){if(Y==="throw")throw Error(`Undefined variable: ${z}`);H+=Y==="keep"?W.raw:"";continue}H+=String(w)}return H}async function W1($,Q,G={}){let{resolvers:X={},undefinedBehavior:Y="throw"}=G,J=L3($);if(J.length===1&&J[0]?.type==="text")return $;let H="";for(let W of J){if(W.type==="text"){H+=W.value;continue}let _=O3(W.expression);if(_){let E=X[_.resolverKey];if(E){let N=XQ(_.argText,Q,Y),x=await E(...N);H+=String(x);continue}if(Y==="throw")throw Error(`Unknown resolver: ${_.resolverKey}`);H+=Y==="keep"?W.raw:"";continue}let z=W.expression.trim(),w=N3(Q,z);if(w===void 0){if(Y==="throw")throw Error(`Undefined variable: ${z}`);H+=Y==="keep"?W.raw:"";continue}H+=String(w)}return H}function S3($,Q,G){if(typeof $==="string")return J1($,Q,G);if(Array.isArray($))return $.map((X)=>S3(X,Q,G));if($!==null&&typeof $==="object"){let X={};for(let[Y,J]of Object.entries($))X[Y]=S3(J,Q,G);return X}return $}async function K3($,Q,G){if(typeof $==="string")return await W1($,Q,G);if(Array.isArray($))return await Promise.all($.map((X)=>K3(X,Q,G)));if($!==null&&typeof $==="object"){let X={},Y=Object.entries($),J=await Promise.all(Y.map(async([H,W])=>[H,await K3(W,Q,G)]));for(let[H,W]of J)X[H]=W;return X}return $}function _1($,Q,G={}){return S3($,Q,G)}function R3($={}){return{async interpolate(Q,G){return K3(Q,G,$)}}}var YQ=/^([^=]+?)\s*=\s*(.*)$/;function z1($,Q){if(Q&&!Q.includes("form-data")&&!Q.includes("x-www-form-urlencoded"))return!1;let G=$.split(/\r?\n/).filter((X)=>X.trim());if(G.length===0)return!1;if(G.length===1&&G[0]?.includes("&"))return!1;return G.every((X)=>YQ.test(X))}function B1($){let Q=[],G=$.split(/\r?\n/).filter((X)=>X.trim());for(let X of G){let Y=X.match(YQ);if(!Y)continue;let J=Y[1],H=Y[2];if(!J)continue;let W=J.trim(),_=(H??"").trim();if(_.startsWith("@./")||_.startsWith("@{{")){_=_.slice(1);let w=_,E,N=_.indexOf(" | ");if(N!==-1)w=_.slice(0,N).trim(),E=_.slice(N+3).trim();Q.push(P({name:W,value:"",isFile:!0,path:w}).ifDefined("filename",E).build())}else Q.push({name:W,value:_,isFile:!1})}return Q}function P$($){let Q=[],G=$.split(/\r?\n/),X=[],Y={lines:[]};for(let J of G){let H=J.match(/^###\s*(.*)$/);if(H){if(Y.lines.length>0||X.length===0)X.push(Y);let W=H[1]?.trim();Y=P({lines:[]}).ifDefined("name",W||void 0).build()}else Y.lines.push(J)}X.push(Y);for(let J of X){if(J.lines.length===0&&!J.name)continue;let H=J.lines.join(`
|
|
6
|
-
`),
|
|
7
|
-
`)}let A=W["Content-Type"]||W["content-type"];if(_&&z1(_,A))w=B1(_),_=void 0;return P({method:J,url:H,headers:W,raw:$,meta:X}).ifDefined("name",Y).ifDefined("body",_).ifDefined("bodyFile",z).ifDefined("formData",w).build()}async function j1($){return await W3($)}async function W3($,Q){if(Q){let G=await Q.readText($);return P$(G)}if(typeof globalThis.Bun<"u"){let Y=await globalThis.Bun.file($).text();return P$(Y)}throw Error("No IO adapter provided. Use parseFileWithIO(path, io) in this runtime.")}function w1($,Q){$?.(Q)}function HQ($,Q){let G=$[0];if(!G)throw Error(Q);return G}function q1($){let Q=Math.max($.lastIndexOf("/"),$.lastIndexOf("\\"));if(Q===-1)return".";return Q===0?$.slice(0,1):$.slice(0,Q)}function V1($){if($.startsWith("/")||$.startsWith("\\"))return!0;if(/^[A-Za-z]:[\\/]/.test($))return!0;if($.startsWith("\\\\"))return!0;return!1}function E1($,Q){if(!$)return Q;if(!Q)return $;let G=$.includes("\\")?"\\":"/",X=$.endsWith("/")||$.endsWith("\\")?$.slice(0,-1):$,Y=Q.startsWith("/")||Q.startsWith("\\")?Q.slice(1):Q;return`${X}${G}${Y}`}function U1($,Q){if(Q)return Q.path.dirname(Q.path.resolve($));let G=globalThis.process?.cwd?.()??".",X=V1($)?$:E1(G,$);return q1(X)}function A1($,Q){if(!Q)return $;let G=$.Cookie||$.cookie||"";return{...$,Cookie:G?`${G}; ${Q}`:Q}}function JQ($){return new Promise((Q)=>setTimeout(Q,$))}function F3($={}){let Q=$.transport??d$(),G=$.io,X=$.cookieStore,Y=$.onEvent,J=$.headerDefaults,H=$.pluginManager,W=$.maxRetries??3,_=R3({resolvers:$.resolvers??{}});function z(A){w1(Y,A),H?.emitEngineEvent(A)}async function w(A,I){z({type:"parseStarted",source:"string"});let F=P$(A);z({type:"parseFinished",source:"string",requestCount:F.length});let v=I.basePath??G?.cwd()??globalThis.process?.cwd?.()??".";if(H){let C={path:"string",requests:F},b={file:C};return await H.triggerParseAfter({file:C,path:"string"},b),{requests:b.file.requests,basePath:v}}return{requests:F,basePath:v}}async function E(A,I){z({type:"parseStarted",source:"file"});let F=await W3(A,G);z({type:"parseFinished",source:"file",requestCount:F.length});let v=U1(A,G);if(H){let C={path:A,requests:F},b={file:C};return await H.triggerParseAfter({file:C,path:A},b),{requests:b.file.requests,filePath:A,basePath:v}}return{requests:F,filePath:A,basePath:v}}async function N(A,I,F){let v=I.variables??{},C=0,b=()=>H?.createHookContext({retries:C,maxRetries:W,variables:v})??{retries:C,maxRetries:W,session:{id:"default",variables:{}},variables:v,config:{projectRoot:".",variables:{},security:{allowExternalFiles:!1,allowPluginsOutsideProject:!1}},projectRoot:"."};while(!0)try{let k=await x(A,I,F,b(),C);if(k.retry&&C<W){C++,await JQ(k.retry.delayMs);continue}return k.response}catch(k){if(H){let h={method:A.method,url:A.url,headers:A.headers,...A.body!==void 0?{body:A.body}:{}},t={error:k instanceof Error?k:Error(String(k)),suppress:!1};if(await H.triggerError({request:h,error:k instanceof Error?k:Error(String(k)),ctx:b()},t),t.retry&&C<W){C++,await JQ(t.retry.delayMs);continue}if(t.suppress)return new Response(t.error.message,{status:0,statusText:"Suppressed Error"});throw t.error}throw k}}async function x(A,I,F,v,C){let b={method:A.method,url:A.url,headers:{...A.headers},...A.body!==void 0?{body:A.body}:{}};if(H){let O={request:b,skip:!1};if((await H.triggerRequestBefore({request:b,variables:I.variables??{},ctx:v},O)).skip)return{response:new Response(null,{status:204,statusText:"Skipped by Plugin"})};b=O.request}z({type:"interpolateStarted"});let k={...I.variables??{}},h={method:b.method,url:b.url,headers:b.headers,...b.body!==void 0?{body:b.body}:{},...A.name!==void 0?{name:A.name}:{},raw:A.raw,meta:A.meta,...A.bodyFile!==void 0?{bodyFile:A.bodyFile}:{},...A.formData!==void 0?{formData:A.formData}:{}},t=await _.interpolate(h,k);z({type:"interpolateFinished"}),z({type:"compileStarted"});let{executeRequest:R}=await D1(t,P({basePath:F}).ifDefined("io",G).ifDefined("headerDefaults",J).build());z({type:"compileFinished"});let K={method:R.method,url:R.url,headers:R.headers??{},...R.body!==void 0?{body:R.body}:{}};if(H){let O={request:K};await H.triggerRequestCompiled({request:K,variables:k,ctx:v},O),K=O.request}if(H)await H.triggerRequestAfter({request:K,ctx:v});let{url:f,headers:m}=K,i=X?await X.getCookieHeader(f):void 0,G$=X?A1(m,i):m,V$;if(K.body!==void 0)if(K.body instanceof Buffer){let O=K.body,X$=new ArrayBuffer(O.byteLength);new Uint8Array(X$).set(new Uint8Array(O.buffer,O.byteOffset,O.byteLength)),V$=X$}else V$=K.body;let _3={method:K.method,url:K.url,headers:G$,...V$!==void 0?{body:V$}:{}};z({type:"fetchStarted",method:_3.method,url:f});let _Q=Date.now(),r;try{let O=P({}).ifDefined("timeout",I.timeoutMs).ifDefined("signal",I.signal).ifDefined("followRedirects",I.followRedirects).ifDefined("validateSSL",I.validateSSL).ifDefined("proxy",I.proxy).build(),X$=performance.now();r=await e3(_3,O,Q);let E$=performance.now()-X$;if(z({type:"fetchFinished",method:_3.method,url:f,status:r.status,ttfb:E$}),X)await X.setFromResponse(f,r)}catch(O){throw z({type:"error",stage:"fetch",message:O instanceof Error?O.message:String(O)}),O}let zQ={total:Date.now()-_Q},z3;if(H){let O={};if(await H.triggerResponseAfter({request:K,response:r,timing:zQ,ctx:v},O),z3=O.retry,O.status!==void 0||O.statusText!==void 0||O.headers!==void 0||O.body!==void 0){let X$=new Headers(r.headers);if(O.headers)for(let[BQ,MQ]of Object.entries(O.headers))X$.set(BQ,MQ);let E$=null;if(O.body!==void 0){if(typeof O.body==="string")E$=O.body;else if(O.body instanceof Buffer)E$=new Uint8Array(O.body);else if(O.body instanceof ReadableStream)E$=O.body}r=new Response(E$??r.body,{status:O.status??r.status,statusText:O.statusText??r.statusText,headers:X$})}}return{response:r,...z3!==void 0?{retry:z3}:{}}}return{parseString:P$,async runString(A,I={}){let{requests:F,basePath:v}=await w(A,I),C=HQ(F,"No valid requests found in provided content.");return await N(C,I,v)},async runFile(A,I={}){let{requests:F,basePath:v}=await E(A,I),C=HQ(F,`No valid requests found in file: ${A}`);return await N(C,I,v)}}}async function D1($,Q){let G={...Q.headerDefaults??{},...$.headers??{}},X=$.body;if($.bodyFile){let J=await n$($.bodyFile.path,P({basePath:Q.basePath}).ifDefined("io",Q.io).build());if(X=J.content,!G["Content-Type"]&&!G["content-type"])G["Content-Type"]=J.mimeType}else if($.formData&&$.formData.length>0){if(U3($.formData))X=await A3($.formData,P({basePath:Q.basePath}).ifDefined("io",Q.io).build()),delete G["Content-Type"],delete G["content-type"];else if(X=D3($.formData),!G["Content-Type"]&&!G["content-type"])G["Content-Type"]="application/x-www-form-urlencoded"}return{executeRequest:{method:$.method,url:$.url,headers:G,...X!==void 0?{body:X}:{}}}}var C3=Symbol("serverMetadata");function x$($){if(typeof process<"u"&&process.env)return process.env[$];return}function WQ($){let{serverUrl:Q}=$,G=x$("TREQ_FLOW_ID"),X=x$("TREQ_SESSION_ID"),J=x$("TREQ_TOKEN")??$.token,H=Q.replace(/\/$/,""),W={...$.variables},_=X,z=G,w=!1,E,N=!!G,x=!!X,A=Promise.resolve(),I=$.timeout??30000,F={"Content-Type":"application/json"};if(J)F.Authorization=`Bearer ${J}`;async function v(){if(w)return;if(E)return E;return E=(async()=>{if(x){w=!0;return}let R=await fetch(`${H}/session`,{method:"POST",headers:F,body:JSON.stringify({variables:W})});if(!R.ok){let f=await R.text();throw Error(`Failed to create session: ${f}`)}if(_=(await R.json()).sessionId,!N){let f=await fetch(`${H}/flows`,{method:"POST",headers:F,body:JSON.stringify({sessionId:_})});if(!f.ok){let i=await f.text();throw Error(`Failed to create flow: ${i}`)}z=(await f.json()).flowId}w=!0})(),E}function C(R){let K=async()=>{if(!_)return;try{let f=await fetch(`${H}/session/${_}/variables`,{method:"PUT",headers:F,body:JSON.stringify({variables:R,mode:"merge"})});if(!f.ok)console.error("Failed to sync variables to server:",f.statusText)}catch(f){console.error("Failed to sync variables to server:",f)}};if(_)A=A.catch(()=>{return}).then(K);else if(E)A=A.catch(()=>{return}).then(()=>E).then(K)}async function b(R,K={}){await v(),await A;let f={...R,sessionId:_,flowId:z,profile:$.profile,timeoutMs:K.timeout??I};if(R.path)f.reqLabel=R.path;if(K.variables&&Object.keys(K.variables).length>0)f.variables=K.variables;if(K.basePath)f.basePath=K.basePath;let m={method:"POST",headers:F,body:JSON.stringify(f)};if(K.signal)m.signal=K.signal;let i=await fetch(`${H}/execute`,m);if(!i.ok){let V$=await i.text();throw Error(`Execution failed: ${V$}`)}let G$=await i.json();return k(G$.response)}function k(R){let K;if(R.body!==void 0)if(R.encoding==="base64"){let m=atob(R.body),i=new Uint8Array(m.length);for(let G$=0;G$<m.length;G$++)i[G$]=m.charCodeAt(G$);K=i}else K=R.body;let f=new Headers;for(let m of R.headers)f.append(m.name,m.value);return new Response(K,{status:R.status,statusText:R.statusText,headers:f})}async function h(){if(!z||N)return;try{await fetch(`${H}/flows/${z}/finish`,{method:"POST",headers:F})}catch{}}return{async run(R,K={}){return b({path:R},K)},async runString(R,K={}){return b({content:R},K)},setVariables(R){W={...W,...R},C(R)},setVariable(R,K){W[R]=K,C({[R]:K})},getVariables(){return{...W}},close:h,[Symbol.asyncDispose]:h,[C3]:()=>({serverUrl:H,sessionId:_,flowId:z})}}function S1($={}){let Q=$.server??x$("TREQ_SERVER");if(Q)return WQ({...$,serverUrl:Q,token:$.serverToken??x$("TREQ_TOKEN")});let G={...$.variables},X=$.cookieJar,Y=$.timeout??30000,J=$.defaults||{},H=X?K1(X):void 0,W=F3(P({}).ifDefined("io",$.io).ifDefined("transport",$.transport).ifDefined("cookieStore",H).ifDefined("resolvers",$.resolvers).ifDefined("onEvent",$.onEvent).ifDefined("headerDefaults",J.headers).build());function _(w){return{...G,...w}}async function z(){}return{async run(w,E={}){return await W.runFile(w,P({variables:_(E.variables),timeoutMs:E.timeout??Y}).ifDefined("signal",E.signal).ifDefined("followRedirects",J.followRedirects).ifDefined("validateSSL",J.validateSSL).ifDefined("proxy",J.proxy).build())},async runString(w,E={}){return await W.runString(w,P({variables:_(E.variables),timeoutMs:E.timeout??Y}).ifDefined("signal",E.signal).ifDefined("followRedirects",J.followRedirects).ifDefined("validateSSL",J.validateSSL).ifDefined("proxy",J.proxy).ifDefined("basePath",E.basePath).build())},setVariables(w){G={...G,...w}},setVariable(w,E){G[w]=E},getVariables(){return{...G}},close:z,[Symbol.asyncDispose]:z}}function K1($){return{getCookieHeader(Q){try{return $.getCookieStringSync(Q)||void 0}catch{return}},setFromResponse(Q,G){let X=L1(G);for(let Y of X)$.setCookieSync(Y,Q,{ignoreError:!0})}}}function L1($){let G=$.headers.getSetCookie?.();if(Array.isArray(G)&&G.length>0)return G;let X=$.headers.get("set-cookie");return X?[X]:[]}function N1($){let G=$[C3];if(typeof G==="function")return G();return}export{GQ as validateFilePath,m3 as tool,q$ as schema,c3 as parsePluginId,W3 as parseFileWithIO,j1 as parseFile,P$ as parse,X3 as loadSubprocessPlugin,t$ as loadPlugins,n$ as loadFileBody,QQ as isBinaryMimeType,_1 as interpolate,$Q as inferMimeType,U3 as hasFileFields,N1 as getServerMetadata,T$ as getPluginId,y3 as definePlugin,Q3 as createRestrictedContext,a3 as createPluginManager,R3 as createInterpolator,J3 as createFetchTransport,F3 as createEngine,S1 as createClient,d$ as createAutoTransport,D3 as buildUrlEncoded,A3 as buildFormData,G3 as SubprocessPlugin,H3 as PluginManager,$3 as PermissionDeniedError};
|
|
4
|
+
`)}async callResolver($,Q){if(!this.capabilities.resolvers.includes($))throw Error(`Resolver "${$}" not supported by plugin`);let W={id:this.nextId(),type:"resolver",name:$,args:Q},X=await this.sendRequest(W);if(X.type==="error")throw Error(X.error.message);return X.result.value}async callHook($,Q,W){if(!this.capabilities.hooks.includes($))return W;let X={id:this.nextId(),type:"hook",name:$,input:Q,output:W},G=await this.sendRequest(X);if(G.type==="error")throw Error(G.error.message);return G.result.output}async shutdown(){if(!this.process)return;try{this.process.stdin?.write(`${JSON.stringify({type:"shutdown"})}
|
|
5
|
+
`)}catch{}let $=this.config.gracePeriodMs??a3;await new Promise((Q)=>{let W=setTimeout(()=>{if(this.process)this.process.kill("SIGKILL");Q()},$);this.process?.on("close",()=>{clearTimeout(W),Q()})}),this.process=null}getPluginInfo(){return this.pluginInfo}getCapabilities(){return this.capabilities}isInitialized(){return this.initialized}}function e0($){let Q=$.getPluginInfo(),W=$.getCapabilities(),X={};for(let Y of W.resolvers)X[Y]=async(...H)=>{return await $.callResolver(Y,H)};let G={};if(W.hooks.includes("parse.after"))G["parse.after"]=async(Y,H)=>{let _=await $.callHook("parse.after",{file:Y.file,path:Y.path},{file:H.file});if(_.file)H.file=_.file};if(W.hooks.includes("request.before"))G["request.before"]=async(Y,H)=>{let _=await $.callHook("request.before",{request:Y.request,variables:Y.variables,ctx:c$(Y.ctx)},{request:H.request});if(_.request)H.request=_.request;let z=_.skip;if(typeof z==="boolean")H.skip=z};if(W.hooks.includes("request.compiled"))G["request.compiled"]=async(Y,H)=>{let _=await $.callHook("request.compiled",{request:Y.request,variables:Y.variables,ctx:c$(Y.ctx)},{request:H.request});if(_.request)H.request=_.request};if(W.hooks.includes("request.after"))G["request.after"]=async(Y)=>{await $.callHook("request.after",{request:Y.request,ctx:c$(Y.ctx)},{})};if(W.hooks.includes("response.after"))G["response.after"]=async(Y,H)=>{let _={status:Y.response.status,statusText:Y.response.statusText,headers:Object.fromEntries(Y.response.headers.entries())},z=await $.callHook("response.after",{request:Y.request,response:_,timing:Y.timing,ctx:c$(Y.ctx)},{}),j=z.status,U=z.statusText,O=z.headers,L=z.retry;if(typeof j==="number")H.status=j;if(typeof U==="string")H.statusText=U;if(O&&typeof O==="object")H.headers=O;if(L&&typeof L==="object")H.retry=L};if(W.hooks.includes("error"))G.error=async(Y,H)=>{let _=await $.callHook("error",{request:Y.request,error:{message:Y.error.message,code:Y.error.code},ctx:c$(Y.ctx)},{}),z=_.error,j=_.retry,U=_.suppress;if(z&&typeof z==="object"&&"message"in z)H.error=Error(z.message);if(j&&typeof j==="object")H.retry=j;if(typeof U==="boolean")H.suppress=U};let J=W.hooks.length>0?async({event:Y})=>{$.sendEvent(Y)}:void 0;return P({name:Q.name,instanceId:"default",teardown:async()=>{await $.shutdown()}}).ifDefined("version",Q.version).ifDefined("permissions",Q.permissions).ifDefined("resolvers",Object.keys(X).length>0?X:void 0).ifDefined("hooks",Object.keys(G).length>0?G:void 0).ifDefined("event",J).build()}function c$($){return P({retries:$.retries,maxRetries:$.maxRetries,session:{id:$.session.id,variables:$.session.variables},variables:$.variables,config:{projectRoot:$.config.projectRoot,variables:$.config.variables,security:$.config.security},projectRoot:$.projectRoot}).ifDefined("enterprise",$.enterprise?{org:$.enterprise.org,user:$.enterprise.user,team:$.enterprise.team,session:{id:$.enterprise.session.id,startedAt:$.enterprise.session.startedAt.toISOString(),source:$.enterprise.session.source,token:$.enterprise.session.token}}:void 0).build()}async function G0($,Q){let W=new X0($,Q);await W.start();let X=W.getPluginInfo();return{plugin:e0(W),id:`${X.name}#default`,source:"subprocess",permissions:X.permissions??[],initialized:!0}}var Y0=30000;async function $1($,Q,W){let X,G=new Promise((J,Y)=>{X=setTimeout(()=>Y(Error(W)),Q)});try{return await Promise.race([$,G])}finally{if(X!==void 0)clearTimeout(X)}}class J0{options;plugins=[];resolvers={};commands={};middleware=[];tools={};warnings=[];initialized=!1;config;onEvent;enterprise;secrets;session;executionContext;reportSeq=0;reportScopeKey;constructor($){this.options=$;if(this.config={projectRoot:$.projectRoot,variables:{},security:{allowExternalFiles:!1,allowPluginsOutsideProject:$.security?.allowPluginsOutsideProject??!1}},$.onEvent!==void 0)this.onEvent=$.onEvent;if($.enterprise!==void 0)this.enterprise=$.enterprise;if($.secrets!==void 0)this.secrets=$.secrets;this.session={id:crypto.randomUUID(),variables:{},reports:[]},this.executionContext={runId:this.createRunId()},this.reportScopeKey=`run:${this.executionContext.runId}`}setEventSink($){this.onEvent=$}setExecutionContext($){let Q=$.runId??this.executionContext.runId??this.createRunId(),W=$.flowId?`flow:${$.flowId}`:`run:${Q}`;if(W!==this.reportScopeKey)this.reportScopeKey=W,this.reportSeq=0;this.executionContext={runId:Q,...$.flowId!==void 0?{flowId:$.flowId}:{},...$.reqExecId!==void 0?{reqExecId:$.reqExecId}:{},...$.now!==void 0?{now:$.now}:{},...$.nextSeq!==void 0?{nextSeq:$.nextSeq}:{}}}async initialize(){if(this.initialized)return;let $=this.options.plugins??[],Q=await e$({projectRoot:this.options.projectRoot,plugins:$,warnings:this.warnings,...this.options.security!==void 0?{security:this.options.security}:{},...this.options.pluginPermissions!==void 0?{pluginPermissions:this.options.pluginPermissions}:{}});for(let W of Q.plugins)await this.initializePlugin(W);this.initialized=!0}async initializePlugin($){let Q=Date.now();try{if($.source==="subprocess"&&"_subprocessConfig"in $){let G=$._subprocessConfig,J=await G0(G,this.options.projectRoot);$.plugin=J.plugin,$.permissions=J.permissions,$.id=J.id}this.emitPluginEvent({type:"pluginLoaded",name:$.plugin.name,source:$.source,...$.plugin.version!==void 0?{version:$.plugin.version}:{}});let W=W0({plugin:$.plugin,permissions:$.permissions,config:this.config,...this.enterprise!==void 0?{enterprise:this.enterprise}:{},...this.secrets!==void 0?{secrets:this.secrets}:{}});if($.plugin.setup)await $.plugin.setup(W);$.initialized=!0,this.registerPluginContributions($);let X=Date.now()-Q;this.emitPluginEvent({type:"pluginInitialized",name:$.plugin.name,durationMs:X}),this.plugins.push($)}catch(W){let X=W instanceof Error?W.message:String(W);this.warnings.push(`Plugin "${$.plugin.name}" setup failed: ${X}`),this.emitPluginEvent({type:"pluginError",name:$.plugin.name,stage:"setup",message:X,recoverable:!0})}}registerPluginContributions($){let Q=$.plugin;if(Q.resolvers)for(let[W,X]of Object.entries(Q.resolvers)){if(this.resolvers[W])this.warnings.push(`Resolver "${W}" from "${Q.name}" shadows existing resolver`);this.resolvers[W]=X}if(Q.commands)for(let[W,X]of Object.entries(Q.commands)){if(this.commands[W]){this.warnings.push(`Command "${W}" from "${Q.name}" shadows same command from "${this.commands[W].pluginName}" (loaded first, takes precedence)`);continue}this.commands[W]={handler:X,pluginName:Q.name}}if(Q.middleware)for(let W of Q.middleware)this.middleware.push({fn:W,pluginName:Q.name});if(Q.tools)for(let[W,X]of Object.entries(Q.tools)){if(this.tools[W])this.warnings.push(`Tool "${W}" from "${Q.name}" shadows existing tool`);this.tools[W]={definition:X,pluginName:Q.name}}}async teardown(){for(let $=this.plugins.length-1;$>=0;$--){let Q=this.plugins[$];if(!Q)continue;try{if(Q.plugin.teardown)await Q.plugin.teardown();this.emitPluginEvent({type:"pluginTeardown",name:Q.plugin.name})}catch(W){let X=W instanceof Error?W.message:String(W);this.warnings.push(`Plugin "${Q.plugin.name}" teardown failed: ${X}`),this.emitPluginEvent({type:"pluginError",name:Q.plugin.name,stage:"teardown",message:X,recoverable:!0})}}this.plugins=[],this.initialized=!1}createHookContext($){let Q=this.session;return{retries:$.retries??0,maxRetries:$.maxRetries??3,session:Q,variables:$.variables??{},config:this.config,projectRoot:this.options.projectRoot,...this.enterprise!==void 0?{enterprise:this.enterprise}:{},report:(W)=>{this.emitReport({pluginName:$.pluginName??"unknown",...$.requestName!==void 0?{requestName:$.requestName}:{},data:W})}}}getReports(){return this.session.reports}createRunId(){return`run-${crypto.randomUUID()}`}nextSeq(){if(this.executionContext.nextSeq)return this.executionContext.nextSeq();return this.reportSeq+=1,this.reportSeq}now(){return this.executionContext.now?this.executionContext.now():Date.now()}emitReport($){try{JSON.stringify($.data)}catch{throw Error("Plugin report data must be JSON-serializable")}let Q={pluginName:$.pluginName,runId:this.executionContext.runId??this.createRunId(),...this.executionContext.flowId!==void 0?{flowId:this.executionContext.flowId}:{},...this.executionContext.reqExecId!==void 0?{reqExecId:this.executionContext.reqExecId}:{},...$.requestName!==void 0?{requestName:$.requestName}:{},ts:this.now(),seq:this.nextSeq(),data:$.data};this.session.reports.push(Q),this.emitPluginEvent({type:"pluginReport",report:Q})}async triggerParseAfter($,Q){return await this.executeHook("parse.after",$,Q)}async triggerValidate($,Q){return await this.executeHook("validate",$,Q)}async triggerRequestBefore($,Q){let W=await this.executeHook("request.before",$,Q);return{...W,...W.output.skip!==void 0?{skip:W.output.skip}:{}}}async triggerRequestCompiled($,Q){return await this.executeHook("request.compiled",$,Q)}async triggerRequestAfter($){await this.executeReadOnlyHook("request.after",$)}async triggerResponseAfter($,Q){let W=await this.executeHook("response.after",$,Q);return{...W,...W.output.retry!==void 0?{retry:W.output.retry}:{}}}async triggerError($,Q){let W=await this.executeHook("error",$,Q);return{...W,...W.output.retry!==void 0?{retry:W.output.retry}:{}}}async executeHook($,Q,W){let X=!1,G="ctx"in Q?Q.ctx:this.createHookContext({}),J=Q,Y=J.request&&typeof J.request==="object"&&J.request!==null&&"name"in J.request?J.request.name??void 0:void 0;for(let H of this.plugins){let _=H.plugin.hooks?.[$];if(!_)continue;G.report=(U)=>{this.emitReport({pluginName:H.plugin.name,...Y!==void 0?{requestName:Y}:{},data:U})};let z=Date.now(),j=JSON.stringify(W);this.emitPluginEvent({type:"pluginHookStarted",name:H.plugin.name,hook:$,ctx:G});try{let U=Promise.resolve(_(Q,W));await $1(U,Y0,`Hook "${$}" in "${H.plugin.name}" timed out after ${Y0}ms`);let O=JSON.stringify(W),L=j!==O;if(L)X=!0;let T=Date.now()-z;this.emitPluginEvent({type:"pluginHookFinished",name:H.plugin.name,hook:$,durationMs:T,modified:L,ctx:G})}catch(U){let O=U instanceof Error?U.message:String(U);this.warnings.push(`Hook "${$}" in "${H.plugin.name}" failed: ${O}`),this.emitPluginEvent({type:"pluginError",name:H.plugin.name,stage:"hook",hook:$,message:O,recoverable:!0})}}return{output:W,modified:X}}async executeReadOnlyHook($,Q){let W="ctx"in Q?Q.ctx:this.createHookContext({}),X=Q,G=X.request&&typeof X.request==="object"&&X.request!==null&&"name"in X.request?X.request.name??void 0:void 0;for(let J of this.plugins){let Y=J.plugin.hooks?.[$];if(!Y)continue;W.report=(_)=>{this.emitReport({pluginName:J.plugin.name,...G!==void 0?{requestName:G}:{},data:_})};let H=Date.now();this.emitPluginEvent({type:"pluginHookStarted",name:J.plugin.name,hook:$,ctx:W});try{let _=Promise.resolve(Y(Q));await $1(_,Y0,`Hook "${$}" in "${J.plugin.name}" timed out after ${Y0}ms`);let z=Date.now()-H;this.emitPluginEvent({type:"pluginHookFinished",name:J.plugin.name,hook:$,durationMs:z,modified:!1,ctx:W})}catch(_){let z=_ instanceof Error?_.message:String(_);this.warnings.push(`Hook "${$}" in "${J.plugin.name}" failed: ${z}`),this.emitPluginEvent({type:"pluginError",name:J.plugin.name,stage:"hook",hook:$,message:z,recoverable:!0})}}}emitPluginEvent($){this.onEvent?.($);for(let Q of this.plugins)if(Q.plugin.event&&$.type!=="pluginLoaded");}emitEngineEvent($){this.onEvent?.($);for(let Q of this.plugins)if(Q.plugin.event)try{Q.plugin.event({event:$})}catch{}}getResolvers(){return{...this.resolvers}}getResolver($){return this.resolvers[$]}async callResolver($,Q){let W=this.resolvers[$];if(!W)return`{{${$}:ERROR}}`;let X=Date.now();try{let G=await W(...Q),J=Date.now()-X;return this.emitPluginEvent({type:"pluginResolverCalled",name:$,resolver:$,durationMs:J}),G}catch(G){let J=G instanceof Error?G.message:String(G);return this.warnings.push(`Resolver "${$}" failed: ${J}`),this.emitPluginEvent({type:"pluginError",name:"resolver",stage:"resolver",message:J,recoverable:!0}),`{{${$}:ERROR}}`}}getCommands(){let $={};for(let[Q,{handler:W}]of Object.entries(this.commands))$[Q]=W;return $}getCommand($){return this.commands[$]?.handler}getMiddleware(){return this.middleware.map(($)=>$.fn)}getTools(){let $={};for(let[Q,{definition:W}]of Object.entries(this.tools))$[Q]=W;return $}getPlugins(){return[...this.plugins]}getWarnings(){return[...this.warnings]}hasPlugins(){return this.plugins.length>0}getPlugin($){return this.plugins.find((Q)=>Q.plugin.name===$)}getPluginInfo(){return this.plugins.map(($)=>({name:$.plugin.name,source:$.source,permissions:$.permissions,...$.plugin.version!==void 0?{version:$.plugin.version}:{}}))}setSessionVariable($,Q){this.session.variables[$]=Q}getSessionVariables(){return{...this.session.variables}}}function Q1($){return new J0($)}function W1($){throw Error(`${$} is not supported by this transport. Provide a transport that supports it.`)}function H0($=fetch){return{capabilities:{proxy:!1,validateSSL:!1},async fetch(Q,W,X){if(X.proxy)W1("proxy");if(X.validateSSL===!1)W1("validateSSL=false");return await $(Q,W)}}}function t3(){return typeof globalThis.Bun<"u"}function l$(){if(!t3())return H0(fetch);return{capabilities:{proxy:!0,validateSSL:!0},async fetch($,Q,W){let X={...Q??{}};if(W.proxy!==void 0)X.proxy=W.proxy;if(W.validateSSL===!1)X.tls={rejectUnauthorized:!1};return await fetch($,X)}}}import{access as e3,readFile as X1}from"node:fs/promises";import*as l from"node:path";async function $Q($){try{return await e3($),!0}catch{return!1}}function QQ(){return{cwd:()=>process.cwd(),path:{resolve:(...$)=>l.resolve(...$),dirname:($)=>l.dirname($),basename:($)=>l.basename($),extname:($)=>l.extname($),isAbsolute:($)=>l.isAbsolute($),sep:l.sep},exists:$Q,readText:async($)=>await X1($,"utf8"),readBinary:async($)=>{let Q=await X1($);return Q.buffer.slice(Q.byteOffset,Q.byteOffset+Q.byteLength)}}}function WQ($,Q){return Q!==void 0&&!["GET","HEAD"].includes($.toUpperCase())}function XQ($,Q){let W=WQ($.method,$.body)&&$.body!==void 0;return P({method:$.method,redirect:Q.followRedirects?"follow":"manual",signal:Q.signal}).ifDefined("headers",$.headers).ifDefined("body",W?$.body:void 0).build()}function GQ($){if($.provided)return{signal:$.provided,isInternalTimeout:!1,cleanup:()=>{}};let Q=new AbortController,W=setTimeout(()=>Q.abort(),$.timeout);return{signal:Q.signal,isInternalTimeout:!0,cleanup:()=>clearTimeout(W)}}function YQ($,Q){if($ instanceof Error&&$.name==="AbortError"){if(Q.isInternalTimeout)return Error(`Request timeout after ${Q.timeout}ms`)}return $ instanceof Error?$:Error(String($))}async function _0($,Q,W){let X=Q.timeout??30000,G=P({timeout:X}).ifDefined("provided",Q.signal).build(),{signal:J,isInternalTimeout:Y,cleanup:H}=GQ(G),_=P({followRedirects:Q.followRedirects??!0,signal:J}).build(),z=XQ($,_);try{let j=P({}).ifDefined("proxy",Q.proxy).ifDefined("validateSSL",Q.validateSSL).build();return await W.fetch($.url,z,j)}catch(j){throw YQ(j,{timeout:X,isInternalTimeout:Y})}finally{H()}}function JQ($){return/^[A-Za-z0-9_]+$/.test($)}function D0($){let Q=[],W=0,X=0;while(W<$.length){let G=$[W],J=$[W+1];if(G==="{"&&J==="{"){if(W>X)Q.push({type:"text",value:$.slice(X,W)});let Y=W;W+=2;let H=1,_="";while(W<$.length){let j=$[W],U=$[W+1];if(j==="{"&&U==="{"){H++,_+="{{",W+=2;continue}if(j==="}"&&U==="}"){if(H--,H===0){W+=2;break}_+="}}",W+=2;continue}_+=j,W++}if(H!==0)throw Error('Unterminated interpolation: missing "}}"');let z=$.slice(Y,W);Q.push({type:"expr",expression:_,raw:z}),X=W;continue}W++}if(X<$.length)Q.push({type:"text",value:$.slice(X)});return Q}function K0($,Q){let W=Q.split("."),X=$;for(let G of W){if(X===null||X===void 0)return;if(typeof X!=="object")return;X=X[G]}return X}function S0($){let Q=$.trim();if(!Q.startsWith("$"))return null;if(!Q.endsWith(")"))return null;let W=Q.indexOf("(");if(W===-1)return null;let X=Q.slice(1,W).trim();if(!X||!JQ(X))return null;let G=Q.slice(W+1,-1);return{resolverKey:`$${X}`,argText:G}}function HQ($,Q,W){let X=D0($);if(X.length===1&&X[0]?.type==="text")return $;let G="";for(let J of X){if(J.type==="text"){G+=J.value;continue}let Y=J.expression.trim();if(S0(Y))throw Error(`Resolver calls are not allowed inside resolver args: ${J.raw}`);let H=K0(Q,Y);if(H===void 0){if(W==="throw")throw Error(`Undefined variable: ${Y}`);G+=W==="keep"?J.raw:"";continue}G+=String(H)}return G}function G1($,Q,W){let X=HQ($,Q,W).trim();if(!X)return[];try{let G=JSON.parse(X);if(Array.isArray(G))return G.map((J)=>String(J))}catch{}return[X]}function _Q($,Q,W={}){let{resolvers:X={},undefinedBehavior:G="throw"}=W,J=D0($);if(J.length===1&&J[0]?.type==="text")return $;let Y="";for(let H of J){if(H.type==="text"){Y+=H.value;continue}let _=S0(H.expression);if(_){let U=X[_.resolverKey];if(U){let O=G1(_.argText,Q,G),L=U(...O);if(L instanceof Promise)throw Error(`Resolver ${_.resolverKey} returned a Promise. Use createInterpolator() for async resolvers.`);Y+=String(L);continue}if(G==="throw")throw Error(`Unknown resolver: ${_.resolverKey}`);Y+=G==="keep"?H.raw:"";continue}let z=H.expression.trim(),j=K0(Q,z);if(j===void 0){if(G==="throw")throw Error(`Undefined variable: ${z}`);Y+=G==="keep"?H.raw:"";continue}Y+=String(j)}return Y}async function zQ($,Q,W={}){let{resolvers:X={},undefinedBehavior:G="throw"}=W,J=D0($);if(J.length===1&&J[0]?.type==="text")return $;let Y="";for(let H of J){if(H.type==="text"){Y+=H.value;continue}let _=S0(H.expression);if(_){let U=X[_.resolverKey];if(U){let O=G1(_.argText,Q,G),L=await U(...O);Y+=String(L);continue}if(G==="throw")throw Error(`Unknown resolver: ${_.resolverKey}`);Y+=G==="keep"?H.raw:"";continue}let z=H.expression.trim(),j=K0(Q,z);if(j===void 0){if(G==="throw")throw Error(`Undefined variable: ${z}`);Y+=G==="keep"?H.raw:"";continue}Y+=String(j)}return Y}function V0($,Q,W){if(typeof $==="string")return _Q($,Q,W);if(Array.isArray($))return $.map((X)=>V0(X,Q,W));if($!==null&&typeof $==="object"){let X={};for(let[G,J]of Object.entries($))X[G]=V0(J,Q,W);return X}return $}async function A0($,Q,W){if(typeof $==="string")return await zQ($,Q,W);if(Array.isArray($))return await Promise.all($.map((X)=>A0(X,Q,W)));if($!==null&&typeof $==="object"){let X={},G=Object.entries($),J=await Promise.all(G.map(async([Y,H])=>[Y,await A0(H,Q,W)]));for(let[Y,H]of J)X[Y]=H;return X}return $}function BQ($,Q,W={}){return V0($,Q,W)}function L0($={}){return{async interpolate(Q,W){return A0(Q,W,$)}}}var Y1=/^([^=]+?)\s*=\s*(.*)$/,wQ=/^@([A-Za-z_][\w.]*)\s*=\s*(.+)$/;function MQ($,Q){if(Q&&!Q.includes("form-data")&&!Q.includes("x-www-form-urlencoded"))return!1;let W=$.split(/\r?\n/).filter((X)=>X.trim());if(W.length===0)return!1;if(W.length===1&&W[0]?.includes("&"))return!1;return W.every((X)=>Y1.test(X))}function jQ($){let Q=[],W=$.split(/\r?\n/).filter((X)=>X.trim());for(let X of W){let G=X.match(Y1);if(!G)continue;let J=G[1],Y=G[2];if(!J)continue;let H=J.trim(),_=(Y??"").trim();if(_.startsWith("@./")||_.startsWith("@{{")){_=_.slice(1);let j=_,U,O=_.indexOf(" | ");if(O!==-1)j=_.slice(0,O).trim(),U=_.slice(O+3).trim();Q.push(P({name:H,value:"",isFile:!0,path:j}).ifDefined("filename",U).build())}else Q.push({name:H,value:_,isFile:!1})}return Q}function UQ($,Q){if(Q.sse!==void 0){let X={type:"sse"};if(Q.timeout){let G=parseInt(Q.timeout,10);if(!Number.isNaN(G))X.timeout=G}if(Q.lastEventId)X.lastEventId=Q.lastEventId;return{protocol:"sse",protocolOptions:X}}if(($.Accept||$.accept)?.includes("text/event-stream"))return{protocol:"sse",protocolOptions:{type:"sse"}};return{protocol:"http"}}function v$($){let Q=[],W=$.split(/\r?\n/),X=[],G={lines:[]};for(let J of W){let Y=J.match(/^###\s*(.*)$/);if(Y){if(G.lines.length>0||X.length===0)X.push(G);let H=Y[1]?.trim();G=P({lines:[]}).ifDefined("name",H||void 0).build()}else G.lines.push(J)}X.push(G);for(let J of X){if(J.lines.length===0&&!J.name)continue;let Y=J.lines.join(`
|
|
6
|
+
`),H=EQ(Y,J.name);if(H)Q.push(H)}return Q}function EQ($,Q){let W=$.split(/\r?\n/),X={},G=[],J=Q,Y="",H="",_={},z,j,U,O=!1,L=[],T=!1;for(let I=0;I<W.length;I++){let f=W[I];if(f===void 0)continue;let k=f.trim();if(!T&&k==="")continue;if(!T&&(k.startsWith("#")||k.startsWith("//"))){let R=k.replace(/^(#|\/\/)\s*/,"").match(/^@([\w-]+)\s*(.*)?$/);if(R){let[,V,S]=R;if(V==="name")J=S?.trim()||J;else if(V)X[V]=S?.trim()||"";if(V)G.push({name:V,value:S?.trim()||"",line:I})}continue}if(!T){let F=k.match(/^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS|TRACE|CONNECT)\s+(\S+)(\s+HTTP\/[\d.]+)?$/i);if(F){let[,R,V]=F;if(!R||!V)continue;Y=R.toUpperCase(),H=V,T=!0}if(!T){let R=k.match(/^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS|TRACE|CONNECT)\s+(.+)$/i);if(R){let[,V,S]=R;if(!V||!S)continue;Y=V.toUpperCase(),H=S.trim(),T=!0}}if(T){while(I+1<W.length){let R=W[I+1]?.trim();if(R&&(R.startsWith("?")||R.startsWith("&")))H+=R,I++;else break}continue}continue}if(O)L.push(f);else if(k==="")O=!0;else{let F=f.match(/^([^:]+):\s*(.*)$/);if(F){let R=F[1];if(!R)continue;let V=F[2]??"";_[R.trim()]=V.trim()}}}if(!Y||!H)return null;if(L.length>0){while(L.length>0&&L[L.length-1]?.trim()==="")L.pop();if(L.length===1){let I=L[0]?.trim().match(/^<\s+(.+)$/);if(I){let f=I[1];if(f)j={path:f}}else if(L[0]?.trim())z=L[0]}else if(L.length>0)z=L.join(`
|
|
7
|
+
`)}let c=_["Content-Type"]||_["content-type"];if(z&&MQ(z,c))U=jQ(z),z=void 0;let{protocol:E,protocolOptions:N}=UQ(_,X);return P({method:Y,url:H,headers:_,raw:$,meta:X}).ifDefined("name",J).ifDefined("body",z).ifDefined("bodyFile",j).ifDefined("formData",U).ifDefined("directives",G.length>0?G:void 0).ifDefined("protocol",E!=="http"?E:void 0).ifDefined("protocolOptions",N?.type!==void 0?N:void 0).build()}async function VQ($){return await J1($)}async function J1($,Q){if(Q){let W=await Q.readText($);return v$(W)}if(typeof globalThis.Bun<"u"){let G=await globalThis.Bun.file($).text();return v$(G)}throw Error("No IO adapter provided. Use parseFileWithIO(path, io) in this runtime.")}function AQ($){let Q={},W=$.split(/\r?\n/),X=[];for(let G of W){let J=G.trim().match(wQ);if(J){let[,Y,H]=J;if(Y&&H!==void 0)Q[Y]=H.trim()}else X.push(G)}return{fileVariables:Q,cleanedContent:X.join(`
|
|
8
|
+
`)}}function u$($){let{fileVariables:Q,cleanedContent:W}=AQ($);return{requests:v$(W),fileVariables:Q}}async function DQ($){return await z0($)}async function z0($,Q){if(Q){let W=await Q.readText($);return u$(W)}if(typeof globalThis.Bun<"u"){let G=await globalThis.Bun.file($).text();return u$(G)}throw Error("No IO adapter provided. Use parseDocumentFileWithIO(path, io) in this runtime.")}var d$=new Map;function f$($){d$.set($.protocol,$)}function B0($){return d$.get($)}function H1(){let $=d$.get("http");if(!$)throw Error("HTTP handler not registered. Import the http protocol handler.");return $}function _1($){return d$.has($)}function z1(){return Array.from(d$.keys())}function B1($,Q){$?.(Q)}function n$($,Q){let W=$[0];if(!W)throw Error(Q);return W}function KQ($){let Q=Math.max($.lastIndexOf("/"),$.lastIndexOf("\\"));if(Q===-1)return".";return Q===0?$.slice(0,1):$.slice(0,Q)}function SQ($){if($.startsWith("/")||$.startsWith("\\"))return!0;if(/^[A-Za-z]:[\\/]/.test($))return!0;if($.startsWith("\\\\"))return!0;return!1}function LQ($,Q){if(!$)return Q;if(!Q)return $;let W=$.includes("\\")?"\\":"/",X=$.endsWith("/")||$.endsWith("\\")?$.slice(0,-1):$,G=Q.startsWith("/")||Q.startsWith("\\")?Q.slice(1):Q;return`${X}${W}${G}`}function w1($,Q){if(Q)return Q.path.dirname(Q.path.resolve($));let W=globalThis.process?.cwd?.()??".",X=SQ($)?$:LQ(W,$);return KQ(X)}function M1($,Q){if(!Q)return $;let W=$.Cookie||$.cookie||"";return{...$,Cookie:W?`${W}; ${Q}`:Q}}function q0($){return new Promise((Q)=>setTimeout(Q,$))}var qQ={".json":"application/json",".xml":"application/xml",".txt":"text/plain",".html":"text/html",".htm":"text/html",".css":"text/css",".js":"application/javascript",".mjs":"application/javascript",".ts":"application/typescript",".csv":"text/csv",".md":"text/markdown",".yaml":"text/yaml",".yml":"text/yaml",".svg":"image/svg+xml",".jpg":"image/jpeg",".jpeg":"image/jpeg",".png":"image/png",".gif":"image/gif",".webp":"image/webp",".ico":"image/x-icon",".bmp":"image/bmp",".tiff":"image/tiff",".tif":"image/tiff",".pdf":"application/pdf",".doc":"application/msword",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xls":"application/vnd.ms-excel",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".ppt":"application/vnd.ms-powerpoint",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".zip":"application/zip",".gz":"application/gzip",".tar":"application/x-tar",".rar":"application/vnd.rar",".7z":"application/x-7z-compressed",".mp3":"audio/mpeg",".wav":"audio/wav",".ogg":"audio/ogg",".m4a":"audio/mp4",".mp4":"video/mp4",".webm":"video/webm",".avi":"video/x-msvideo",".mov":"video/quicktime",".wasm":"application/wasm",".bin":"application/octet-stream",".exe":"application/octet-stream",".dll":"application/octet-stream",".so":"application/octet-stream",".dylib":"application/octet-stream"},NQ=new Set(["application/json","application/xml","application/javascript","application/typescript","text/plain","text/html","text/css","text/csv","text/xml","text/markdown","text/yaml","image/svg+xml"]);function j1($){let Q=CQ($).toLowerCase();return qQ[Q]??"application/octet-stream"}function U1($){if($.startsWith("text/"))return!1;if(NQ.has($))return!1;return!0}function O0($){return $.includes("\\")?"\\":"/"}function N0($){return $.split(/[\\/]+/).filter(Boolean)}function OQ($){if($.startsWith("/")||$.startsWith("\\"))return!0;if(/^[A-Za-z]:[\\/]/.test($))return!0;if($.startsWith("\\\\"))return!0;return!1}function p$($,Q){let W=[];for(let X of Q){if(!X||X===".")continue;if(X===".."){W.pop();continue}W.push(X)}return($==="\\"?"\\":"/")+W.join($)}function FQ($,Q){let W=O0($),X=/^[A-Za-z]:$/.test($),J=$.match(/^([A-Za-z]:)[\\/]?/)?.[1],Y=N0($),H=N0(Q);if(J){let _=p$(W,[...Y.slice(1),...H]);return`${J}${_}`}if(X){let _=p$(W,H);return`${$}${_}`}return p$(W,[...Y,...H])}function RQ($){if($==="")return"/";let Q=O0($),X=$.match(/^([A-Za-z]:)[\\/]?/)?.[1],G=N0($);if(X){let J=p$(Q,G.slice(1));return`${X}${J}`}return p$(Q,G)}function CQ($){let Q=bQ($),W=Q.lastIndexOf(".");if(W<=0)return"";return Q.slice(W)}function bQ($){let Q=$.split(/[\\/]/);return Q[Q.length-1]??""}function E1($,Q){if(OQ($))throw Error(`Absolute paths not allowed: ${$}`);let W=FQ(Q,$),X=RQ(Q),G=O0(X);if(W!==X&&!W.startsWith(X+G))throw Error(`Path escapes base directory: ${$}`);return W}async function i$($,Q={}){let W=Q.basePath??Q.io?.cwd()??globalThis.process?.cwd?.()??".",X=E1($,W),G=j1($),J=U1(G),Y;if(Q.io){if(!await Q.io.exists(X))throw Error(`File not found: ${$}`);Y=J?await Q.io.readBinary(X):await Q.io.readText(X)}else if(typeof globalThis.Bun<"u"){let _=globalThis.Bun.file(X);if(!await _.exists())throw Error(`File not found: ${$}`);Y=J?await _.arrayBuffer():await _.text()}else throw Error("No IO adapter provided. Provide `options.io` (Node/Bun/Tauri) to load file bodies.");return{content:Y,isBinary:J,mimeType:G}}function F0($){return $.some((Q)=>Q.isFile)}async function R0($,Q={}){let W=new FormData,X=Q.basePath??Q.io?.cwd()??globalThis.process?.cwd?.()??".";for(let G of $)if(G.isFile&&G.path){let J=await i$(G.path,Q.io?{basePath:X,io:Q.io}:{basePath:X}),Y=G.filename??Q.io?.path.basename(G.path)??IQ(G.path),H=new Blob([J.content],{type:J.mimeType});W.append(G.name,H,Y)}else W.append(G.name,G.value);return W}function IQ($){let Q=$.split(/[\\/]/);return Q[Q.length-1]??""}function C0($){let Q=new URLSearchParams;for(let W of $){if(W.isFile)continue;Q.append(W.name,W.value)}return Q}async function V1($,Q){let W={...Q.headerDefaults??{},...$.headers??{}},X=$.body;if($.bodyFile){let J=await i$($.bodyFile.path,P({basePath:Q.basePath}).ifDefined("io",Q.io).build());if(X=J.content,!W["Content-Type"]&&!W["content-type"])W["Content-Type"]=J.mimeType}else if($.formData&&$.formData.length>0){if(F0($.formData))X=await R0($.formData,P({basePath:Q.basePath}).ifDefined("io",Q.io).build()),delete W["Content-Type"],delete W["content-type"];else if(X=C0($.formData),!W["Content-Type"]&&!W["content-type"])W["Content-Type"]="application/x-www-form-urlencoded"}return{executeRequest:{method:$.method,url:$.url,headers:W,...X!==void 0?{body:X}:{}}}}async function b0($,Q,W,X,G){let{interpolator:J,cookieStore:Y,headerDefaults:H,io:_,pluginManager:z,emitEvent:j}=$,U={method:Q.method,url:Q.url,headers:{...Q.headers},...Q.body!==void 0?{body:Q.body}:{}};if(z){let V={request:U,skip:!1};if((await z.triggerRequestBefore({request:U,variables:W,ctx:G},V)).skip)return{compiledRequest:{method:U.method,url:U.url,headers:U.headers},requestWithCookies:{method:U.method,url:U.url,headers:U.headers},urlForCookies:U.url,mergedVars:{...W},skipped:!0};U=V.request}j({type:"interpolateStarted"});let O={...W},L={method:U.method,url:U.url,headers:U.headers,...U.body!==void 0?{body:U.body}:{},...Q.name!==void 0?{name:Q.name}:{},raw:Q.raw,meta:Q.meta,...Q.bodyFile!==void 0?{bodyFile:Q.bodyFile}:{},...Q.formData!==void 0?{formData:Q.formData}:{},...Q.directives!==void 0?{directives:Q.directives}:{}},T=await J.interpolate(L,O);j({type:"interpolateFinished"}),j({type:"compileStarted"});let{executeRequest:c}=await V1(T,P({basePath:X}).ifDefined("io",_).ifDefined("headerDefaults",H).build());j({type:"compileFinished"});let E={method:c.method,url:c.url,headers:c.headers??{},...c.body!==void 0?{body:c.body}:{},...T.name!==void 0?{name:T.name}:{},...T.meta!==void 0?{meta:T.meta}:{},...T.directives!==void 0?{directives:T.directives}:{}};if(z){let V={request:E};await z.triggerRequestCompiled({request:E,variables:O,ctx:G},V),E=V.request}if(z)await z.triggerRequestAfter({request:E,ctx:G});let{url:N,headers:I}=E,f=Y?await Y.getCookieHeader(N):void 0,k=Y?M1(I,f):I,F;if(E.body!==void 0)if(E.body instanceof Buffer){let V=E.body,S=new ArrayBuffer(V.byteLength);new Uint8Array(S).set(new Uint8Array(V.buffer,V.byteOffset,V.byteLength)),F=S}else F=E.body;let R={method:E.method,url:E.url,headers:k,...F!==void 0?{body:F}:{}};return{compiledRequest:E,requestWithCookies:R,urlForCookies:N,mergedVars:O,skipped:!1}}var I0={protocol:"http",canHandle($){return!$.protocol||$.protocol==="http"},async execute($,Q,W){let X={};if(Q.timeout!==void 0)X.timeout=Q.timeout;if(Q.signal!==void 0)X.signal=Q.signal;if(Q.followRedirects!==void 0)X.followRedirects=Q.followRedirects;if(Q.validateSSL!==void 0)X.validateSSL=Q.validateSSL;if(Q.proxy!==void 0)X.proxy=Q.proxy;return _0($,X,W)}};f$(I0);async function*A1($){let Q=new TextDecoder,W="",X={};while(!0){let{done:G,value:J}=await $.read();if(G)break;W+=Q.decode(J,{stream:!0});let Y=W.split(/\r?\n/);W=Y.pop()??"";for(let H of Y)if(H.startsWith("id:"))X.id=H.slice(3).trim();else if(H.startsWith("event:"))X.event=H.slice(6).trim();else if(H.startsWith("data:")){let _=H.slice(5);X.data=X.data!==void 0?`${X.data}
|
|
9
|
+
${_}`:_}else if(H.startsWith("retry:")){let _=parseInt(H.slice(6).trim(),10);if(!Number.isNaN(_))X.retry=_}else if(H===""){if(X.data!==void 0)yield X;X={}}}if(X.data!==void 0)yield X}function D1($){if(!$.body)throw Error("SSE response has no body");let Q=$.body.getReader(),W=!1,X=A1(Q),G={type:"sse",async*[Symbol.asyncIterator](){if(W)return;for await(let J of X){if(W)return;if(J.id)G.lastEventId=J.id;yield J}},close(){if(W)return;W=!0,Q.cancel().catch(()=>{})},response:$};return G}var k0={protocol:"sse",canHandle($){if($.protocol==="sse")return!0;if(($.headers.Accept||$.headers.accept)?.includes("text/event-stream"))return!0;return!1},async execute($,Q,W){let X={...$.headers,Accept:"text/event-stream","Cache-Control":"no-cache"};if(Q.lastEventId)X["Last-Event-ID"]=Q.lastEventId;let G=P({}).ifDefined("proxy",Q.proxy).ifDefined("validateSSL",Q.validateSSL).build(),J={method:$.method||"GET",headers:X};if(Q.signal)J.signal=Q.signal;let Y=await W.fetch($.url,J,G);if(!(Y.headers.get("content-type")??"").includes("text/event-stream")&&Y.ok);if(!Y.ok)throw Error(`SSE request failed: ${Y.status} ${Y.statusText}`);return D1(Y)}};f$(k0);function v0($={}){let Q=$.transport??l$(),W=$.io,X=$.cookieStore,G=$.onEvent,J=$.headerDefaults,Y=$.pluginManager,H=$.maxRetries??3,_=L0({resolvers:$.resolvers??{}});function z(E){B1(G,E),Y?.emitEngineEvent(E)}let j={interpolator:_,emitEvent:z};if(X)j.cookieStore=X;if(J)j.headerDefaults=J;if(W)j.io=W;if(Y)j.pluginManager=Y;function U(E,N){return Y?.createHookContext({retries:E,maxRetries:H,variables:N})??{retries:E,maxRetries:H,session:{id:"default",variables:{},reports:[]},variables:N,config:{projectRoot:".",variables:{},security:{allowExternalFiles:!1,allowPluginsOutsideProject:!1}},projectRoot:".",report:()=>{}}}async function O(E,N){z({type:"parseStarted",source:"string"});let{requests:I,fileVariables:f}=u$(E);z({type:"parseFinished",source:"string",requestCount:I.length});let k=N.basePath??W?.cwd()??globalThis.process?.cwd?.()??".";if(Y){let F={path:"string",requests:I},R={file:F};return await Y.triggerParseAfter({file:F,path:"string"},R),{requests:R.file.requests,fileVariables:f,basePath:k}}return{requests:I,fileVariables:f,basePath:k}}async function L(E,N){z({type:"parseStarted",source:"file"});let{requests:I,fileVariables:f}=await z0(E,W);z({type:"parseFinished",source:"file",requestCount:I.length});let k=w1(E,W);if(Y){let F={path:E,requests:I},R={file:F};return await Y.triggerParseAfter({file:F,path:E},R),{requests:R.file.requests,fileVariables:f,filePath:E,basePath:k}}return{requests:I,fileVariables:f,filePath:E,basePath:k}}async function T(E,N,I,f={}){let k={...f,...N.variables??{}},F=0;while(!0)try{let R=U(F,k),V=await b0(j,E,k,I,R);if(V.skipped)return new Response(null,{status:204,statusText:"Skipped by Plugin"});z({type:"fetchStarted",method:V.requestWithCookies.method,url:V.urlForCookies});let S=Date.now(),v;try{let x=P({}).ifDefined("timeout",N.timeoutMs).ifDefined("signal",N.signal).ifDefined("followRedirects",N.followRedirects).ifDefined("validateSSL",N.validateSSL).ifDefined("proxy",N.proxy).build(),j$=performance.now();v=await _0(V.requestWithCookies,x,Q);let U$=performance.now()-j$;if(z({type:"fetchFinished",method:V.requestWithCookies.method,url:V.urlForCookies,status:v.status,ttfb:U$}),X)await X.setFromResponse(V.urlForCookies,v)}catch(x){throw z({type:"error",stage:"fetch",message:x instanceof Error?x.message:String(x)}),x}let y={total:Date.now()-S},s;if(Y){let x={};if(await Y.triggerResponseAfter({request:V.compiledRequest,response:v,timing:y,ctx:R},x),s=x.retry,x.status!==void 0||x.statusText!==void 0||x.headers!==void 0||x.body!==void 0){let j$=new Headers(v.headers);if(x.headers)for(let[S1,L1]of Object.entries(x.headers))j$.set(S1,L1);let U$=null;if(x.body!==void 0){if(typeof x.body==="string")U$=x.body;else if(x.body instanceof Buffer)U$=new Uint8Array(x.body);else if(x.body instanceof ReadableStream)U$=x.body}v=new Response(U$??v.body,{status:x.status??v.status,statusText:x.statusText??v.statusText,headers:j$})}}if(s&&F<H){F++,await q0(s.delayMs);continue}return v}catch(R){if(Y){let V={method:E.method,url:E.url,headers:E.headers,...E.body!==void 0?{body:E.body}:{},...E.name!==void 0?{name:E.name}:{},...E.meta!==void 0?{meta:E.meta}:{},...E.directives!==void 0?{directives:E.directives}:{}},S={error:R instanceof Error?R:Error(String(R)),suppress:!1};if(await Y.triggerError({request:V,error:R instanceof Error?R:Error(String(R)),ctx:U(F,k)},S),S.retry&&F<H){F++,await q0(S.retry.delayMs);continue}if(S.suppress)return new Response(S.error.message,{status:0,statusText:"Suppressed Error"});throw S.error}throw R}}async function c(E,N,I,f={}){let k=N.protocol??E.protocol??"http";if(k==="http")throw Error("Request protocol is 'http' but expected a streaming protocol (sse, ws). Use runString() for HTTP requests or add @sse directive.");let F=B0(k);if(!F)throw Error(`No handler registered for protocol: ${k}`);let R={...f,...N.variables??{}},V=U(0,R),S=await b0(j,E,R,I,V);if(S.skipped)throw Error("Request skipped by plugin - cannot stream a skipped request");z({type:"fetchStarted",method:S.requestWithCookies.method,url:S.urlForCookies});let v=P({}).ifDefined("timeout",N.timeoutMs).ifDefined("signal",N.signal).ifDefined("followRedirects",N.followRedirects).ifDefined("validateSSL",N.validateSSL).ifDefined("proxy",N.proxy).ifDefined("lastEventId",N.lastEventId??E.protocolOptions?.lastEventId).build();try{return await F.execute(S.requestWithCookies,v,Q)}catch(y){throw z({type:"error",stage:"fetch",message:y instanceof Error?y.message:String(y)}),y}}return{parseString:v$,async runString(E,N={}){let{requests:I,fileVariables:f,basePath:k}=await O(E,N),F=n$(I,"No valid requests found in provided content.");return await T(F,N,k,f)},async runFile(E,N={}){let{requests:I,fileVariables:f,basePath:k}=await L(E,N),F=n$(I,`No valid requests found in file: ${E}`);return await T(F,N,k,f)},async streamString(E,N={}){let{requests:I,fileVariables:f,basePath:k}=await O(E,N),F=n$(I,"No valid requests found in provided content.");return await c(F,N,k,f)},async streamFile(E,N={}){let{requests:I,fileVariables:f,basePath:k}=await L(E,N),F=n$(I,`No valid requests found in file: ${E}`);return await c(F,N,k,f)}}}var f0=Symbol("serverMetadata");function T$($){if(typeof process<"u"&&process.env)return process.env[$];return}function kQ($){if(typeof Buffer<"u"){let Q=Buffer.from($,"base64");return Q.buffer.slice(Q.byteOffset,Q.byteOffset+Q.byteLength)}if(typeof atob<"u"){let Q=atob($),W=new Uint8Array(Q.length);for(let X=0;X<Q.length;X++)W[X]=Q.charCodeAt(X);return W.buffer}throw Error("No base64 decoder available in this runtime")}function K1($){let{serverUrl:Q}=$,W=T$("TREQ_FLOW_ID"),X=T$("TREQ_SESSION_ID"),J=T$("TREQ_TOKEN")??$.token,Y=Q.replace(/\/$/,""),H={...$.variables},_=X,z=W,j=!1,U,O=!!W,L=!!X,T=Promise.resolve(),c=$.timeout??30000,E={"Content-Type":"application/json"};if(J)E.Authorization=`Bearer ${J}`;async function N(){if(j)return;if(U)return U;return U=(async()=>{if(L){j=!0;return}let V=await fetch(`${Y}/session`,{method:"POST",headers:E,body:JSON.stringify({variables:H})});if(!V.ok){let v=await V.text();throw Error(`Failed to create session: ${v}`)}if(_=(await V.json()).sessionId,!O){let v=await fetch(`${Y}/flows`,{method:"POST",headers:E,body:JSON.stringify({sessionId:_})});if(!v.ok){let s=await v.text();throw Error(`Failed to create flow: ${s}`)}z=(await v.json()).flowId}j=!0})(),U}function I(V){let S=async()=>{if(!_)return;try{let v=await fetch(`${Y}/session/${_}/variables`,{method:"PUT",headers:E,body:JSON.stringify({variables:V,mode:"merge"})});if(!v.ok)console.error("Failed to sync variables to server:",v.statusText)}catch(v){console.error("Failed to sync variables to server:",v)}};if(_)T=T.catch(()=>{return}).then(S);else if(U)T=T.catch(()=>{return}).then(()=>U).then(S)}async function f(V,S={}){await N(),await T;let v={...V,sessionId:_,flowId:z,profile:$.profile,timeoutMs:S.timeout??c};if(V.path)v.reqLabel=V.path;if(S.variables&&Object.keys(S.variables).length>0)v.variables=S.variables;if(S.basePath)v.basePath=S.basePath;let y={method:"POST",headers:E,body:JSON.stringify(v)};if(S.signal)y.signal=S.signal;let s=await fetch(`${Y}/execute`,y);if(!s.ok){let j$=await s.text();throw Error(`Execution failed: ${j$}`)}let x=await s.json();return k(x.response)}function k(V){let S;if(V.body!==void 0)if(V.encoding==="base64")S=kQ(V.body);else S=V.body;let v=new Headers;for(let y of V.headers)v.append(y.name,y.value);return new Response(S,{status:V.status,statusText:V.statusText,headers:v})}async function F(){if(!z||O)return;try{await fetch(`${Y}/flows/${z}/finish`,{method:"POST",headers:E})}catch{}}return{async run(V,S={}){return f({path:V},S)},async runString(V,S={}){return f({content:V},S)},setVariables(V){H={...H,...V},I(V)},setVariable(V,S){H[V]=S,I({[V]:S})},getVariables(){return{...H}},close:F,[Symbol.asyncDispose]:F,[f0]:()=>({serverUrl:Y,sessionId:_,flowId:z})}}function vQ($={}){let Q=$.server??T$("TREQ_SERVER");if(Q)return K1({...$,serverUrl:Q,token:$.serverToken??T$("TREQ_TOKEN")});let W={...$.variables},X=$.cookieJar,G=$.timeout??30000,J=$.defaults||{},Y=X?fQ(X):void 0,H=v0(P({}).ifDefined("io",$.io).ifDefined("transport",$.transport).ifDefined("cookieStore",Y).ifDefined("resolvers",$.resolvers).ifDefined("onEvent",$.onEvent).ifDefined("headerDefaults",J.headers).build());function _(j){return{...W,...j}}async function z(){}return{async run(j,U={}){return await H.runFile(j,P({variables:_(U.variables),timeoutMs:U.timeout??G}).ifDefined("signal",U.signal).ifDefined("followRedirects",J.followRedirects).ifDefined("validateSSL",J.validateSSL).ifDefined("proxy",J.proxy).build())},async runString(j,U={}){return await H.runString(j,P({variables:_(U.variables),timeoutMs:U.timeout??G}).ifDefined("signal",U.signal).ifDefined("followRedirects",J.followRedirects).ifDefined("validateSSL",J.validateSSL).ifDefined("proxy",J.proxy).ifDefined("basePath",U.basePath).build())},setVariables(j){W={...W,...j}},setVariable(j,U){W[j]=U},getVariables(){return{...W}},close:z,[Symbol.asyncDispose]:z}}function fQ($){return{getCookieHeader(Q){try{return $.getCookieStringSync(Q)||void 0}catch{return}},setFromResponse(Q,W){let X=TQ(W);for(let G of X)$.setCookieSync(G,Q,{ignoreError:!0})}}}function TQ($){let W=$.headers.getSetCookie?.();if(Array.isArray(W)&&W.length>0)return W;let X=$.headers.get("set-cookie");return X?[X]:[]}function PQ($){let W=$[f0];if(typeof W==="function")return W();return}export{E1 as validateFilePath,n0 as tool,k0 as sseHandler,M$ as schema,f$ as registerProtocol,p0 as parsePluginId,J1 as parseFileWithIO,VQ as parseFile,z0 as parseDocumentFileWithIO,DQ as parseDocumentFile,u$ as parseDocument,v$ as parse,G0 as loadSubprocessPlugin,e$ as loadPlugins,i$ as loadFileBody,U1 as isBinaryMimeType,BQ as interpolate,j1 as inferMimeType,I0 as httpHandler,_1 as hasHandler,F0 as hasFileFields,PQ as getServerMetadata,z1 as getRegisteredProtocols,k$ as getPluginId,B0 as getHandler,H1 as getDefaultHandler,d0 as definePlugin,W0 as createRestrictedContext,Q1 as createPluginManager,L0 as createInterpolator,H0 as createFetchTransport,v0 as createEngine,vQ as createClient,l$ as createAutoTransport,C0 as buildUrlEncoded,R0 as buildFormData,X0 as SubprocessPlugin,J0 as PluginManager,Q0 as PermissionDeniedError};
|
|
8
10
|
|
|
9
|
-
//# debugId=
|
|
11
|
+
//# debugId=602D900C67D5CCB964756E2164756E21
|
|
10
12
|
//# sourceMappingURL=index.js.map
|