@t-req/core 0.2.1 → 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.
Files changed (47) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +37 -2
  3. package/dist/config/index.js +6 -6
  4. package/dist/config/index.js.map +5 -5
  5. package/dist/engine/compile-request.d.ts +19 -0
  6. package/dist/engine/compile-request.d.ts.map +1 -0
  7. package/dist/engine/engine-utils.d.ts +13 -0
  8. package/dist/engine/engine-utils.d.ts.map +1 -0
  9. package/dist/engine/engine.d.ts +11 -1
  10. package/dist/engine/engine.d.ts.map +1 -1
  11. package/dist/engine/index.js +6 -4
  12. package/dist/engine/index.js.map +12 -6
  13. package/dist/engine/request-pipeline.d.ts +22 -0
  14. package/dist/engine/request-pipeline.d.ts.map +1 -0
  15. package/dist/index.d.ts +5 -3
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +9 -7
  18. package/dist/index.js.map +16 -10
  19. package/dist/parser.d.ts +17 -1
  20. package/dist/parser.d.ts.map +1 -1
  21. package/dist/plugin/define.d.ts +3 -1
  22. package/dist/plugin/define.d.ts.map +1 -1
  23. package/dist/plugin/index.d.ts +1 -1
  24. package/dist/plugin/index.d.ts.map +1 -1
  25. package/dist/plugin/index.js +4 -4
  26. package/dist/plugin/index.js.map +5 -5
  27. package/dist/plugin/loader.d.ts.map +1 -1
  28. package/dist/plugin/manager.d.ts +29 -1
  29. package/dist/plugin/manager.d.ts.map +1 -1
  30. package/dist/plugin/types.d.ts +84 -0
  31. package/dist/plugin/types.d.ts.map +1 -1
  32. package/dist/protocols/http.d.ts +7 -0
  33. package/dist/protocols/http.d.ts.map +1 -0
  34. package/dist/protocols/index.d.ts +6 -0
  35. package/dist/protocols/index.d.ts.map +1 -0
  36. package/dist/protocols/registry.d.ts +24 -0
  37. package/dist/protocols/registry.d.ts.map +1 -0
  38. package/dist/protocols/sse.d.ts +26 -0
  39. package/dist/protocols/sse.d.ts.map +1 -0
  40. package/dist/protocols/types.d.ts +33 -0
  41. package/dist/protocols/types.d.ts.map +1 -0
  42. package/dist/runtime/types.d.ts +1 -0
  43. package/dist/runtime/types.d.ts.map +1 -1
  44. package/dist/server-client.d.ts.map +1 -1
  45. package/dist/types.d.ts +92 -1
  46. package/dist/types.d.ts.map +1 -1
  47. package/package.json +1 -1
package/dist/parser.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { IO } from './runtime/types';
2
- import type { ParsedRequest } from './types';
2
+ import type { ParsedDocument, ParsedRequest } from './types';
3
3
  /**
4
4
  * Parse .http file content into structured request objects
5
5
  */
@@ -13,4 +13,20 @@ export declare function parseFile(path: string): Promise<ParsedRequest[]>;
13
13
  * If `io` is omitted, Bun runtime fallback is used when available.
14
14
  */
15
15
  export declare function parseFileWithIO(path: string, io?: IO): Promise<ParsedRequest[]>;
16
+ /**
17
+ * Parse .http file content into a full document with file-level variables.
18
+ *
19
+ * File variables use `@var = value` syntax and are extracted before
20
+ * request block parsing. They are available to all requests in the document.
21
+ */
22
+ export declare function parseDocument(content: string): ParsedDocument;
23
+ /**
24
+ * Parse .http file from filesystem into a full document with file-level variables.
25
+ */
26
+ export declare function parseDocumentFile(path: string): Promise<ParsedDocument>;
27
+ /**
28
+ * Parse .http file from filesystem into a full document using an IO adapter.
29
+ * If `io` is omitted, Bun runtime fallback is used when available.
30
+ */
31
+ export declare function parseDocumentFileWithIO(path: string, io?: IO): Promise<ParsedDocument>;
16
32
  //# sourceMappingURL=parser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,KAAK,EAA4B,aAAa,EAAE,MAAM,SAAS,CAAC;AA6FvE;;GAEG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,EAAE,CA4CtD;AAoJD;;GAEG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAEtE;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAiBrF"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,KAAK,EAIV,cAAc,EACd,aAAa,EAId,MAAM,SAAS,CAAC;AAuIjB;;GAEG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,EAAE,CA4CtD;AAyKD;;GAEG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAEtE;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAiBrF;AA6BD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,CAI7D;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAE7E;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAiB5F"}
@@ -17,7 +17,9 @@ import type { ToolContext, ToolDefinition, TreqPlugin } from './types';
17
17
  * });
18
18
  * ```
19
19
  */
20
- export declare function definePlugin(plugin: TreqPlugin): TreqPlugin;
20
+ export declare function definePlugin<T extends TreqPlugin>(plugin: T): T & {
21
+ instanceId: string;
22
+ };
21
23
  /**
22
24
  * Re-export Zod's z object for schema building.
23
25
  *
@@ -1 +1 @@
1
- {"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../src/plugin/define.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAMvE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CA8I3D;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,CAAC,EAAE,CAAC,IAAI,MAAM,EAAE,CAAC;AAM1B;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,WAAW,EAAE,UAAU,EAAE;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CACxF,GAAG,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAW1C"}
1
+ {"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../src/plugin/define.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAMvE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,CA+IxF;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,CAAC,EAAE,CAAC,IAAI,MAAM,EAAE,CAAC;AAM1B;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,WAAW,EAAE,UAAU,EAAE;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CACxF,GAAG,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAW1C"}
@@ -3,5 +3,5 @@ export { getPluginId, isFilePlugin, isInlinePlugin, isNpmPlugin, isSubprocessPlu
3
3
  export { createPluginManager, PluginManager, type PluginManagerOptions } from './manager';
4
4
  export { assertPermission, type CreateRestrictedContextOptions, createRestrictedContext, hasPermission, PermissionDeniedError, validatePermissions } from './permissions';
5
5
  export { createSubprocessPluginWrapper, loadSubprocessPlugin, SubprocessPlugin } from './subprocess';
6
- export type { Collection, CombinedEvent, CombinedEventSink, CommandContext, CommandHandler, CompiledInput, CompiledOutput, CompiledRequest, EnterpriseContext, ErrorInput, ErrorOutput, ExecuteRequestInput, HookContext, LoadedPlugin, MiddlewareFunction, MiddlewareRequest, MiddlewareResponse, ParsedHttpFile, ParseInput, ParseOutput, PluginConfigRef, PluginContext, PluginEvent, PluginFactory, PluginHooks, PluginPermission, PluginPermissionsConfig, PluginResolver, RequestAfterInput, RequestDefinition, RequestInput, RequestOutput, ResolvedPluginConfig, ResolverWithContext, ResponseInput, ResponseOutput, RetrySignal, SessionState, SubprocessErrorResponse, SubprocessEventNotification, SubprocessHookRequest, SubprocessHookResponse, SubprocessInitRequest, SubprocessInitResponse, SubprocessPluginConfig, SubprocessRequest, SubprocessResolverRequest, SubprocessResolverResponse, SubprocessResponse, SubprocessShutdownRequest, TimingInfo, ToolContext, ToolDefinition, ToolSchema, TreqPlugin } from './types';
6
+ export type { Collection, CombinedEvent, CombinedEventSink, CommandContext, CommandHandler, CompiledInput, CompiledOutput, CompiledRequest, EnterpriseContext, ErrorInput, ErrorOutput, ExecuteRequestInput, HookContext, LoadedPlugin, MiddlewareFunction, MiddlewareRequest, MiddlewareResponse, ParsedHttpFile, ParseInput, ParseOutput, PluginConfigRef, PluginContext, PluginDiagnostic, PluginEvent, PluginFactory, PluginHooks, PluginPermission, PluginPermissionsConfig, PluginReport, PluginResolver, RequestAfterInput, RequestDefinition, RequestInput, RequestOutput, ResolvedPluginConfig, ResolverWithContext, ResponseInput, ResponseOutput, RetrySignal, SessionState, SubprocessErrorResponse, SubprocessEventNotification, SubprocessHookRequest, SubprocessHookResponse, SubprocessInitRequest, SubprocessInitResponse, SubprocessPluginConfig, SubprocessRequest, SubprocessResolverRequest, SubprocessResolverResponse, SubprocessResponse, SubprocessShutdownRequest, TimingInfo, ToolContext, ToolDefinition, ToolSchema, TreqPlugin, ValidateInput, ValidateOutput } from './types';
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,UAAU,CAAC;AAEzD,OAAO,EACL,WAAW,EACX,YAAY,EACZ,cAAc,EACd,WAAW,EACX,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,WAAW,EACX,eAAe,EACf,aAAa,EACb,eAAe,EACf,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAE1F,OAAO,EACL,gBAAgB,EAChB,KAAK,8BAA8B,EACnC,uBAAuB,EACvB,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,cAAc,EAEd,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,EAEf,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,WAAW,EAEX,YAAY,EAEZ,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EAEd,UAAU,EACV,WAAW,EAEX,eAAe,EAEf,aAAa,EAEb,WAAW,EACX,aAAa,EAEb,WAAW,EAEX,gBAAgB,EAChB,uBAAuB,EAEvB,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EAEtB,iBAAiB,EACjB,yBAAyB,EACzB,0BAA0B,EAC1B,kBAAkB,EAClB,yBAAyB,EACzB,UAAU,EACV,WAAW,EAEX,cAAc,EACd,UAAU,EAEV,UAAU,EACX,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,UAAU,CAAC;AAEzD,OAAO,EACL,WAAW,EACX,YAAY,EACZ,cAAc,EACd,WAAW,EACX,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,WAAW,EACX,eAAe,EACf,aAAa,EACb,eAAe,EACf,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAE1F,OAAO,EACL,gBAAgB,EAChB,KAAK,8BAA8B,EACnC,uBAAuB,EACvB,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,cAAc,EAEd,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,EAEf,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,WAAW,EAEX,YAAY,EAEZ,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EAEd,UAAU,EACV,WAAW,EAEX,eAAe,EAEf,aAAa,EAEb,gBAAgB,EAEhB,WAAW,EACX,aAAa,EAEb,WAAW,EAEX,gBAAgB,EAChB,uBAAuB,EAEvB,YAAY,EAEZ,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EAEtB,iBAAiB,EACjB,yBAAyB,EACzB,0BAA0B,EAC1B,kBAAkB,EAClB,yBAAyB,EACzB,UAAU,EACV,WAAW,EAEX,cAAc,EACd,UAAU,EAEV,UAAU,EAEV,aAAa,EACb,cAAc,EACf,MAAM,SAAS,CAAC"}
@@ -1,8 +1,8 @@
1
- import{createRequire as Wq}from"node:module";var Qq=Object.defineProperty;var Hq=($,q)=>{for(var J in q)Qq($,J,{get:q[J],enumerable:!0,configurable:!0,set:(G)=>q[J]=()=>G})};var i=Wq(import.meta.url);var _$={};Hq(_$,{void:()=>uq,util:()=>j,unknown:()=>cq,union:()=>rq,undefined:()=>Zq,tuple:()=>sq,transformer:()=>X3,symbol:()=>yq,string:()=>i$,strictObject:()=>iq,setErrorMap:()=>_q,set:()=>$3,record:()=>tq,quotelessJson:()=>Xq,promise:()=>W3,preprocess:()=>B3,pipeline:()=>z3,ostring:()=>M3,optional:()=>Y3,onumber:()=>w3,oboolean:()=>S3,objectUtil:()=>v$,object:()=>dq,number:()=>r$,nullable:()=>_3,null:()=>mq,never:()=>nq,nativeEnum:()=>H3,nan:()=>hq,map:()=>eq,makeIssue:()=>B$,literal:()=>G3,lazy:()=>J3,late:()=>Pq,isValid:()=>g,isDirty:()=>b$,isAsync:()=>o,isAborted:()=>L$,intersection:()=>aq,instanceof:()=>Tq,getParsedType:()=>f,getErrorMap:()=>r,function:()=>q3,enum:()=>Q3,effect:()=>X3,discriminatedUnion:()=>oq,defaultErrorMap:()=>T,datetimeRegex:()=>u$,date:()=>gq,custom:()=>d$,coerce:()=>V3,boolean:()=>o$,bigint:()=>xq,array:()=>pq,any:()=>lq,addIssueToContext:()=>M,ZodVoid:()=>M$,ZodUnknown:()=>y,ZodUnion:()=>q$,ZodUndefined:()=>e,ZodType:()=>R,ZodTuple:()=>I,ZodTransformer:()=>C,ZodSymbol:()=>z$,ZodString:()=>K,ZodSet:()=>p,ZodSchema:()=>R,ZodRecord:()=>w$,ZodReadonly:()=>Y$,ZodPromise:()=>d,ZodPipeline:()=>E$,ZodParsedType:()=>z,ZodOptional:()=>F,ZodObject:()=>b,ZodNumber:()=>Z,ZodNullable:()=>x,ZodNull:()=>$$,ZodNever:()=>k,ZodNativeEnum:()=>H$,ZodNaN:()=>V$,ZodMap:()=>S$,ZodLiteral:()=>Q$,ZodLazy:()=>G$,ZodIssueCode:()=>_,ZodIntersection:()=>J$,ZodFunction:()=>s,ZodFirstPartyTypeKind:()=>V,ZodError:()=>O,ZodEnum:()=>l,ZodEffects:()=>C,ZodDiscriminatedUnion:()=>A$,ZodDefault:()=>W$,ZodDate:()=>n,ZodCatch:()=>X$,ZodBranded:()=>U$,ZodBoolean:()=>t,ZodBigInt:()=>m,ZodArray:()=>N,ZodAny:()=>u,Schema:()=>R,ParseStatus:()=>A,OK:()=>U,NEVER:()=>E3,INVALID:()=>S,EMPTY_PATH:()=>Bq,DIRTY:()=>c,BRAND:()=>Iq});var j;(function($){$.assertEqual=(Q)=>{};function q(Q){}$.assertIs=q;function J(Q){throw Error()}$.assertNever=J,$.arrayToEnum=(Q)=>{let W={};for(let H of Q)W[H]=H;return W},$.getValidEnumValues=(Q)=>{let W=$.objectKeys(Q).filter((X)=>typeof Q[Q[X]]!=="number"),H={};for(let X of W)H[X]=Q[X];return $.objectValues(H)},$.objectValues=(Q)=>{return $.objectKeys(Q).map(function(W){return Q[W]})},$.objectKeys=typeof Object.keys==="function"?(Q)=>Object.keys(Q):(Q)=>{let W=[];for(let H in Q)if(Object.prototype.hasOwnProperty.call(Q,H))W.push(H);return W},$.find=(Q,W)=>{for(let H of Q)if(W(H))return H;return},$.isInteger=typeof Number.isInteger==="function"?(Q)=>Number.isInteger(Q):(Q)=>typeof Q==="number"&&Number.isFinite(Q)&&Math.floor(Q)===Q;function G(Q,W=" | "){return Q.map((H)=>typeof H==="string"?`'${H}'`:H).join(W)}$.joinValues=G,$.jsonStringifyReplacer=(Q,W)=>{if(typeof W==="bigint")return W.toString();return W}})(j||(j={}));var v$;(function($){$.mergeShapes=(q,J)=>{return{...q,...J}}})(v$||(v$={}));var z=j.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),f=($)=>{switch(typeof $){case"undefined":return z.undefined;case"string":return z.string;case"number":return Number.isNaN($)?z.nan:z.number;case"boolean":return z.boolean;case"function":return z.function;case"bigint":return z.bigint;case"symbol":return z.symbol;case"object":if(Array.isArray($))return z.array;if($===null)return z.null;if($.then&&typeof $.then==="function"&&$.catch&&typeof $.catch==="function")return z.promise;if(typeof Map<"u"&&$ instanceof Map)return z.map;if(typeof Set<"u"&&$ instanceof Set)return z.set;if(typeof Date<"u"&&$ instanceof Date)return z.date;return z.object;default:return z.unknown}};var _=j.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"]),Xq=($)=>{return JSON.stringify($,null,2).replace(/"([^"]+)":/g,"$1:")};class O extends Error{get errors(){return this.issues}constructor($){super();this.issues=[],this.addIssue=(J)=>{this.issues=[...this.issues,J]},this.addIssues=(J=[])=>{this.issues=[...this.issues,...J]};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(Q){return Q.message},J={_errors:[]},G=(Q)=>{for(let W of Q.issues)if(W.code==="invalid_union")W.unionErrors.map(G);else if(W.code==="invalid_return_type")G(W.returnTypeError);else if(W.code==="invalid_arguments")G(W.argumentsError);else if(W.path.length===0)J._errors.push(q(W));else{let H=J,X=0;while(X<W.path.length){let Y=W.path[X];if(X!==W.path.length-1)H[Y]=H[Y]||{_errors:[]};else H[Y]=H[Y]||{_errors:[]},H[Y]._errors.push(q(W));H=H[Y],X++}}};return G(this),J}static assert($){if(!($ instanceof O))throw Error(`Not a ZodError: ${$}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,j.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten($=(q)=>q.message){let q={},J=[];for(let G of this.issues)if(G.path.length>0){let Q=G.path[0];q[Q]=q[Q]||[],q[Q].push($(G))}else J.push($(G));return{formErrors:J,fieldErrors:q}}get formErrors(){return this.flatten()}}O.create=($)=>{return new O($)};var Yq=($,q)=>{let J;switch($.code){case _.invalid_type:if($.received===z.undefined)J="Required";else J=`Expected ${$.expected}, received ${$.received}`;break;case _.invalid_literal:J=`Invalid literal value, expected ${JSON.stringify($.expected,j.jsonStringifyReplacer)}`;break;case _.unrecognized_keys:J=`Unrecognized key(s) in object: ${j.joinValues($.keys,", ")}`;break;case _.invalid_union:J="Invalid input";break;case _.invalid_union_discriminator:J=`Invalid discriminator value. Expected ${j.joinValues($.options)}`;break;case _.invalid_enum_value:J=`Invalid enum value. Expected ${j.joinValues($.options)}, received '${$.received}'`;break;case _.invalid_arguments:J="Invalid function arguments";break;case _.invalid_return_type:J="Invalid function return type";break;case _.invalid_date:J="Invalid date";break;case _.invalid_string:if(typeof $.validation==="object")if("includes"in $.validation){if(J=`Invalid input: must include "${$.validation.includes}"`,typeof $.validation.position==="number")J=`${J} at one or more positions greater than or equal to ${$.validation.position}`}else if("startsWith"in $.validation)J=`Invalid input: must start with "${$.validation.startsWith}"`;else if("endsWith"in $.validation)J=`Invalid input: must end with "${$.validation.endsWith}"`;else j.assertNever($.validation);else if($.validation!=="regex")J=`Invalid ${$.validation}`;else J="Invalid";break;case _.too_small:if($.type==="array")J=`Array must contain ${$.exact?"exactly":$.inclusive?"at least":"more than"} ${$.minimum} element(s)`;else if($.type==="string")J=`String must contain ${$.exact?"exactly":$.inclusive?"at least":"over"} ${$.minimum} character(s)`;else if($.type==="number")J=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="bigint")J=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="date")J=`Date must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${new Date(Number($.minimum))}`;else J="Invalid input";break;case _.too_big:if($.type==="array")J=`Array must contain ${$.exact?"exactly":$.inclusive?"at most":"less than"} ${$.maximum} element(s)`;else if($.type==="string")J=`String must contain ${$.exact?"exactly":$.inclusive?"at most":"under"} ${$.maximum} character(s)`;else if($.type==="number")J=`Number must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="bigint")J=`BigInt must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="date")J=`Date must be ${$.exact?"exactly":$.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number($.maximum))}`;else J="Invalid input";break;case _.custom:J="Invalid input";break;case _.invalid_intersection_types:J="Intersection results could not be merged";break;case _.not_multiple_of:J=`Number must be a multiple of ${$.multipleOf}`;break;case _.not_finite:J="Number must be finite";break;default:J=q.defaultError,j.assertNever($)}return{message:J}},T=Yq;var Z$=T;function _q($){Z$=$}function r(){return Z$}var B$=($)=>{let{data:q,path:J,errorMaps:G,issueData:Q}=$,W=[...J,...Q.path||[]],H={...Q,path:W};if(Q.message!==void 0)return{...Q,path:W,message:Q.message};let X="",Y=G.filter((B)=>!!B).slice().reverse();for(let B of Y)X=B(H,{data:q,defaultError:X}).message;return{...Q,path:W,message:X}},Bq=[];function M($,q){let J=r(),G=B$({issueData:q,data:$.data,path:$.path,errorMaps:[$.common.contextualErrorMap,$.schemaErrorMap,J,J===T?void 0:T].filter((Q)=>!!Q)});$.common.issues.push(G)}class A{constructor(){this.value="valid"}dirty(){if(this.value==="valid")this.value="dirty"}abort(){if(this.value!=="aborted")this.value="aborted"}static mergeArray($,q){let J=[];for(let G of q){if(G.status==="aborted")return S;if(G.status==="dirty")$.dirty();J.push(G.value)}return{status:$.value,value:J}}static async mergeObjectAsync($,q){let J=[];for(let G of q){let Q=await G.key,W=await G.value;J.push({key:Q,value:W})}return A.mergeObjectSync($,J)}static mergeObjectSync($,q){let J={};for(let G of q){let{key:Q,value:W}=G;if(Q.status==="aborted")return S;if(W.status==="aborted")return S;if(Q.status==="dirty")$.dirty();if(W.status==="dirty")$.dirty();if(Q.value!=="__proto__"&&(typeof W.value<"u"||G.alwaysSet))J[Q.value]=W.value}return{status:$.value,value:J}}}var S=Object.freeze({status:"aborted"}),c=($)=>({status:"dirty",value:$}),U=($)=>({status:"valid",value:$}),L$=($)=>$.status==="aborted",b$=($)=>$.status==="dirty",g=($)=>$.status==="valid",o=($)=>typeof Promise<"u"&&$ instanceof Promise;var w;(function($){$.errToObj=(q)=>typeof q==="string"?{message:q}:q||{},$.toString=(q)=>typeof q==="string"?q:q?.message})(w||(w={}));class v{constructor($,q,J,G){this._cachedPath=[],this.parent=$,this.data=q,this._path=J,this._key=G}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 m$=($,q)=>{if(g(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 J=new O($.common.issues);return this._error=J,this._error}}}};function E($){if(!$)return{};let{errorMap:q,invalid_type_error:J,required_error:G,description:Q}=$;if(q&&(J||G))throw Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);if(q)return{errorMap:q,description:Q};return{errorMap:(H,X)=>{let{message:Y}=$;if(H.code==="invalid_enum_value")return{message:Y??X.defaultError};if(typeof X.data>"u")return{message:Y??G??X.defaultError};if(H.code!=="invalid_type")return{message:X.defaultError};return{message:Y??J??X.defaultError}},description:Q}}class R{get description(){return this._def.description}_getType($){return f($.data)}_getOrReturnCtx($,q){return q||{common:$.parent.common,data:$.data,parsedType:f($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}_processInputParams($){return{status:new A,ctx:{common:$.parent.common,data:$.data,parsedType:f($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}}_parseSync($){let q=this._parse($);if(o(q))throw Error("Synchronous parse encountered promise.");return q}_parseAsync($){let q=this._parse($);return Promise.resolve(q)}parse($,q){let J=this.safeParse($,q);if(J.success)return J.data;throw J.error}safeParse($,q){let J={common:{issues:[],async:q?.async??!1,contextualErrorMap:q?.errorMap},path:q?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:f($)},G=this._parseSync({data:$,path:J.path,parent:J});return m$(J,G)}"~validate"($){let q={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:f($)};if(!this["~standard"].async)try{let J=this._parseSync({data:$,path:[],parent:q});return g(J)?{value:J.value}:{issues:q.common.issues}}catch(J){if(J?.message?.toLowerCase()?.includes("encountered"))this["~standard"].async=!0;q.common={issues:[],async:!0}}return this._parseAsync({data:$,path:[],parent:q}).then((J)=>g(J)?{value:J.value}:{issues:q.common.issues})}async parseAsync($,q){let J=await this.safeParseAsync($,q);if(J.success)return J.data;throw J.error}async safeParseAsync($,q){let J={common:{issues:[],contextualErrorMap:q?.errorMap,async:!0},path:q?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:f($)},G=this._parse({data:$,path:J.path,parent:J}),Q=await(o(G)?G:Promise.resolve(G));return m$(J,Q)}refine($,q){let J=(G)=>{if(typeof q==="string"||typeof q>"u")return{message:q};else if(typeof q==="function")return q(G);else return q};return this._refinement((G,Q)=>{let W=$(G),H=()=>Q.addIssue({code:_.custom,...J(G)});if(typeof Promise<"u"&&W instanceof Promise)return W.then((X)=>{if(!X)return H(),!1;else return!0});if(!W)return H(),!1;else return!0})}refinement($,q){return this._refinement((J,G)=>{if(!$(J))return G.addIssue(typeof q==="function"?q(J,G):q),!1;else return!0})}_refinement($){return new C({schema:this,typeName:V.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 F.create(this,this._def)}nullable(){return x.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return N.create(this)}promise(){return d.create(this,this._def)}or($){return q$.create([this,$],this._def)}and($){return J$.create(this,$,this._def)}transform($){return new C({...E(this._def),schema:this,typeName:V.ZodEffects,effect:{type:"transform",transform:$}})}default($){let q=typeof $==="function"?$:()=>$;return new W$({...E(this._def),innerType:this,defaultValue:q,typeName:V.ZodDefault})}brand(){return new U$({typeName:V.ZodBranded,type:this,...E(this._def)})}catch($){let q=typeof $==="function"?$:()=>$;return new X$({...E(this._def),innerType:this,catchValue:q,typeName:V.ZodCatch})}describe($){return new this.constructor({...this._def,description:$})}pipe($){return E$.create(this,$)}readonly(){return Y$.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}var zq=/^c[^\s-]{8,}$/i,Mq=/^[0-9a-z]+$/,wq=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Sq=/^[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,Vq=/^[a-z0-9_-]{21}$/i,Eq=/^[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)?)??$/,jq=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Lq="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",C$,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])$/,Aq=/^(?:(?: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])$/,Uq=/^(([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]))$/,Dq=/^(([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])$/,Oq=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Kq=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,c$="((\\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])))",Nq=new RegExp(`^${c$}$`);function n$($){let q="[0-5]\\d";if($.precision)q=`${q}\\.\\d{${$.precision}}`;else if($.precision==null)q=`${q}(\\.\\d+)?`;let J=$.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${q})${J}`}function Fq($){return new RegExp(`^${n$($)}$`)}function u$($){let q=`${c$}T${n$($)}`,J=[];if(J.push($.local?"Z?":"Z"),$.offset)J.push("([+-]\\d{2}:?\\d{2})");return q=`${q}(${J.join("|")})`,new RegExp(`^${q}$`)}function vq($,q){if((q==="v4"||!q)&&bq.test($))return!0;if((q==="v6"||!q)&&Uq.test($))return!0;return!1}function Cq($,q){if(!Eq.test($))return!1;try{let[J]=$.split(".");if(!J)return!1;let G=J.replace(/-/g,"+").replace(/_/g,"/").padEnd(J.length+(4-J.length%4)%4,"="),Q=JSON.parse(atob(G));if(typeof Q!=="object"||Q===null)return!1;if("typ"in Q&&Q?.typ!=="JWT")return!1;if(!Q.alg)return!1;if(q&&Q.alg!==q)return!1;return!0}catch{return!1}}function fq($,q){if((q==="v4"||!q)&&Aq.test($))return!0;if((q==="v6"||!q)&&Dq.test($))return!0;return!1}class K extends R{_parse($){if(this._def.coerce)$.data=String($.data);if(this._getType($)!==z.string){let Q=this._getOrReturnCtx($);return M(Q,{code:_.invalid_type,expected:z.string,received:Q.parsedType}),S}let J=new A,G=void 0;for(let Q of this._def.checks)if(Q.kind==="min"){if($.data.length<Q.value)G=this._getOrReturnCtx($,G),M(G,{code:_.too_small,minimum:Q.value,type:"string",inclusive:!0,exact:!1,message:Q.message}),J.dirty()}else if(Q.kind==="max"){if($.data.length>Q.value)G=this._getOrReturnCtx($,G),M(G,{code:_.too_big,maximum:Q.value,type:"string",inclusive:!0,exact:!1,message:Q.message}),J.dirty()}else if(Q.kind==="length"){let W=$.data.length>Q.value,H=$.data.length<Q.value;if(W||H){if(G=this._getOrReturnCtx($,G),W)M(G,{code:_.too_big,maximum:Q.value,type:"string",inclusive:!0,exact:!0,message:Q.message});else if(H)M(G,{code:_.too_small,minimum:Q.value,type:"string",inclusive:!0,exact:!0,message:Q.message});J.dirty()}}else if(Q.kind==="email"){if(!jq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"email",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="emoji"){if(!C$)C$=new RegExp(Lq,"u");if(!C$.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"emoji",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="uuid"){if(!Sq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"uuid",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="nanoid"){if(!Vq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"nanoid",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="cuid"){if(!zq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"cuid",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="cuid2"){if(!Mq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"cuid2",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="ulid"){if(!wq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"ulid",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="url")try{new URL($.data)}catch{G=this._getOrReturnCtx($,G),M(G,{validation:"url",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="regex"){if(Q.regex.lastIndex=0,!Q.regex.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"regex",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="trim")$.data=$.data.trim();else if(Q.kind==="includes"){if(!$.data.includes(Q.value,Q.position))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:{includes:Q.value,position:Q.position},message:Q.message}),J.dirty()}else if(Q.kind==="toLowerCase")$.data=$.data.toLowerCase();else if(Q.kind==="toUpperCase")$.data=$.data.toUpperCase();else if(Q.kind==="startsWith"){if(!$.data.startsWith(Q.value))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:{startsWith:Q.value},message:Q.message}),J.dirty()}else if(Q.kind==="endsWith"){if(!$.data.endsWith(Q.value))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:{endsWith:Q.value},message:Q.message}),J.dirty()}else if(Q.kind==="datetime"){if(!u$(Q).test($.data))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:"datetime",message:Q.message}),J.dirty()}else if(Q.kind==="date"){if(!Nq.test($.data))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:"date",message:Q.message}),J.dirty()}else if(Q.kind==="time"){if(!Fq(Q).test($.data))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:"time",message:Q.message}),J.dirty()}else if(Q.kind==="duration"){if(!Rq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"duration",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="ip"){if(!vq($.data,Q.version))G=this._getOrReturnCtx($,G),M(G,{validation:"ip",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="jwt"){if(!Cq($.data,Q.alg))G=this._getOrReturnCtx($,G),M(G,{validation:"jwt",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="cidr"){if(!fq($.data,Q.version))G=this._getOrReturnCtx($,G),M(G,{validation:"cidr",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="base64"){if(!Oq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"base64",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="base64url"){if(!Kq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"base64url",code:_.invalid_string,message:Q.message}),J.dirty()}else j.assertNever(Q);return{status:J.value,value:$.data}}_regex($,q,J){return this.refinement((G)=>$.test(G),{validation:q,code:_.invalid_string,...w.errToObj(J)})}_addCheck($){return new K({...this._def,checks:[...this._def.checks,$]})}email($){return this._addCheck({kind:"email",...w.errToObj($)})}url($){return this._addCheck({kind:"url",...w.errToObj($)})}emoji($){return this._addCheck({kind:"emoji",...w.errToObj($)})}uuid($){return this._addCheck({kind:"uuid",...w.errToObj($)})}nanoid($){return this._addCheck({kind:"nanoid",...w.errToObj($)})}cuid($){return this._addCheck({kind:"cuid",...w.errToObj($)})}cuid2($){return this._addCheck({kind:"cuid2",...w.errToObj($)})}ulid($){return this._addCheck({kind:"ulid",...w.errToObj($)})}base64($){return this._addCheck({kind:"base64",...w.errToObj($)})}base64url($){return this._addCheck({kind:"base64url",...w.errToObj($)})}jwt($){return this._addCheck({kind:"jwt",...w.errToObj($)})}ip($){return this._addCheck({kind:"ip",...w.errToObj($)})}cidr($){return this._addCheck({kind:"cidr",...w.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,...w.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,...w.errToObj($?.message)})}duration($){return this._addCheck({kind:"duration",...w.errToObj($)})}regex($,q){return this._addCheck({kind:"regex",regex:$,...w.errToObj(q)})}includes($,q){return this._addCheck({kind:"includes",value:$,position:q?.position,...w.errToObj(q?.message)})}startsWith($,q){return this._addCheck({kind:"startsWith",value:$,...w.errToObj(q)})}endsWith($,q){return this._addCheck({kind:"endsWith",value:$,...w.errToObj(q)})}min($,q){return this._addCheck({kind:"min",value:$,...w.errToObj(q)})}max($,q){return this._addCheck({kind:"max",value:$,...w.errToObj(q)})}length($,q){return this._addCheck({kind:"length",value:$,...w.errToObj(q)})}nonempty($){return this.min(1,w.errToObj($))}trim(){return new K({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new K({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new K({...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 $}}K.create=($)=>{return new K({checks:[],typeName:V.ZodString,coerce:$?.coerce??!1,...E($)})};function kq($,q){let J=($.toString().split(".")[1]||"").length,G=(q.toString().split(".")[1]||"").length,Q=J>G?J:G,W=Number.parseInt($.toFixed(Q).replace(".","")),H=Number.parseInt(q.toFixed(Q).replace(".",""));return W%H/10**Q}class Z extends R{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($)!==z.number){let Q=this._getOrReturnCtx($);return M(Q,{code:_.invalid_type,expected:z.number,received:Q.parsedType}),S}let J=void 0,G=new A;for(let Q of this._def.checks)if(Q.kind==="int"){if(!j.isInteger($.data))J=this._getOrReturnCtx($,J),M(J,{code:_.invalid_type,expected:"integer",received:"float",message:Q.message}),G.dirty()}else if(Q.kind==="min"){if(Q.inclusive?$.data<Q.value:$.data<=Q.value)J=this._getOrReturnCtx($,J),M(J,{code:_.too_small,minimum:Q.value,type:"number",inclusive:Q.inclusive,exact:!1,message:Q.message}),G.dirty()}else if(Q.kind==="max"){if(Q.inclusive?$.data>Q.value:$.data>=Q.value)J=this._getOrReturnCtx($,J),M(J,{code:_.too_big,maximum:Q.value,type:"number",inclusive:Q.inclusive,exact:!1,message:Q.message}),G.dirty()}else if(Q.kind==="multipleOf"){if(kq($.data,Q.value)!==0)J=this._getOrReturnCtx($,J),M(J,{code:_.not_multiple_of,multipleOf:Q.value,message:Q.message}),G.dirty()}else if(Q.kind==="finite"){if(!Number.isFinite($.data))J=this._getOrReturnCtx($,J),M(J,{code:_.not_finite,message:Q.message}),G.dirty()}else j.assertNever(Q);return{status:G.value,value:$.data}}gte($,q){return this.setLimit("min",$,!0,w.toString(q))}gt($,q){return this.setLimit("min",$,!1,w.toString(q))}lte($,q){return this.setLimit("max",$,!0,w.toString(q))}lt($,q){return this.setLimit("max",$,!1,w.toString(q))}setLimit($,q,J,G){return new Z({...this._def,checks:[...this._def.checks,{kind:$,value:q,inclusive:J,message:w.toString(G)}]})}_addCheck($){return new Z({...this._def,checks:[...this._def.checks,$]})}int($){return this._addCheck({kind:"int",message:w.toString($)})}positive($){return this._addCheck({kind:"min",value:0,inclusive:!1,message:w.toString($)})}negative($){return this._addCheck({kind:"max",value:0,inclusive:!1,message:w.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:0,inclusive:!0,message:w.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:0,inclusive:!0,message:w.toString($)})}multipleOf($,q){return this._addCheck({kind:"multipleOf",value:$,message:w.toString(q)})}finite($){return this._addCheck({kind:"finite",message:w.toString($)})}safe($){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:w.toString($)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:w.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"&&j.isInteger($.value))}get isFinite(){let $=null,q=null;for(let J of this._def.checks)if(J.kind==="finite"||J.kind==="int"||J.kind==="multipleOf")return!0;else if(J.kind==="min"){if(q===null||J.value>q)q=J.value}else if(J.kind==="max"){if($===null||J.value<$)$=J.value}return Number.isFinite(q)&&Number.isFinite($)}}Z.create=($)=>{return new Z({checks:[],typeName:V.ZodNumber,coerce:$?.coerce||!1,...E($)})};class m extends R{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($)!==z.bigint)return this._getInvalidInput($);let J=void 0,G=new A;for(let Q of this._def.checks)if(Q.kind==="min"){if(Q.inclusive?$.data<Q.value:$.data<=Q.value)J=this._getOrReturnCtx($,J),M(J,{code:_.too_small,type:"bigint",minimum:Q.value,inclusive:Q.inclusive,message:Q.message}),G.dirty()}else if(Q.kind==="max"){if(Q.inclusive?$.data>Q.value:$.data>=Q.value)J=this._getOrReturnCtx($,J),M(J,{code:_.too_big,type:"bigint",maximum:Q.value,inclusive:Q.inclusive,message:Q.message}),G.dirty()}else if(Q.kind==="multipleOf"){if($.data%Q.value!==BigInt(0))J=this._getOrReturnCtx($,J),M(J,{code:_.not_multiple_of,multipleOf:Q.value,message:Q.message}),G.dirty()}else j.assertNever(Q);return{status:G.value,value:$.data}}_getInvalidInput($){let q=this._getOrReturnCtx($);return M(q,{code:_.invalid_type,expected:z.bigint,received:q.parsedType}),S}gte($,q){return this.setLimit("min",$,!0,w.toString(q))}gt($,q){return this.setLimit("min",$,!1,w.toString(q))}lte($,q){return this.setLimit("max",$,!0,w.toString(q))}lt($,q){return this.setLimit("max",$,!1,w.toString(q))}setLimit($,q,J,G){return new m({...this._def,checks:[...this._def.checks,{kind:$,value:q,inclusive:J,message:w.toString(G)}]})}_addCheck($){return new m({...this._def,checks:[...this._def.checks,$]})}positive($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:w.toString($)})}negative($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:w.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:w.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:w.toString($)})}multipleOf($,q){return this._addCheck({kind:"multipleOf",value:$,message:w.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 $}}m.create=($)=>{return new m({checks:[],typeName:V.ZodBigInt,coerce:$?.coerce??!1,...E($)})};class t extends R{_parse($){if(this._def.coerce)$.data=Boolean($.data);if(this._getType($)!==z.boolean){let J=this._getOrReturnCtx($);return M(J,{code:_.invalid_type,expected:z.boolean,received:J.parsedType}),S}return U($.data)}}t.create=($)=>{return new t({typeName:V.ZodBoolean,coerce:$?.coerce||!1,...E($)})};class n extends R{_parse($){if(this._def.coerce)$.data=new Date($.data);if(this._getType($)!==z.date){let Q=this._getOrReturnCtx($);return M(Q,{code:_.invalid_type,expected:z.date,received:Q.parsedType}),S}if(Number.isNaN($.data.getTime())){let Q=this._getOrReturnCtx($);return M(Q,{code:_.invalid_date}),S}let J=new A,G=void 0;for(let Q of this._def.checks)if(Q.kind==="min"){if($.data.getTime()<Q.value)G=this._getOrReturnCtx($,G),M(G,{code:_.too_small,message:Q.message,inclusive:!0,exact:!1,minimum:Q.value,type:"date"}),J.dirty()}else if(Q.kind==="max"){if($.data.getTime()>Q.value)G=this._getOrReturnCtx($,G),M(G,{code:_.too_big,message:Q.message,inclusive:!0,exact:!1,maximum:Q.value,type:"date"}),J.dirty()}else j.assertNever(Q);return{status:J.value,value:new Date($.data.getTime())}}_addCheck($){return new n({...this._def,checks:[...this._def.checks,$]})}min($,q){return this._addCheck({kind:"min",value:$.getTime(),message:w.toString(q)})}max($,q){return this._addCheck({kind:"max",value:$.getTime(),message:w.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}}n.create=($)=>{return new n({checks:[],coerce:$?.coerce||!1,typeName:V.ZodDate,...E($)})};class z$ extends R{_parse($){if(this._getType($)!==z.symbol){let J=this._getOrReturnCtx($);return M(J,{code:_.invalid_type,expected:z.symbol,received:J.parsedType}),S}return U($.data)}}z$.create=($)=>{return new z$({typeName:V.ZodSymbol,...E($)})};class e extends R{_parse($){if(this._getType($)!==z.undefined){let J=this._getOrReturnCtx($);return M(J,{code:_.invalid_type,expected:z.undefined,received:J.parsedType}),S}return U($.data)}}e.create=($)=>{return new e({typeName:V.ZodUndefined,...E($)})};class $$ extends R{_parse($){if(this._getType($)!==z.null){let J=this._getOrReturnCtx($);return M(J,{code:_.invalid_type,expected:z.null,received:J.parsedType}),S}return U($.data)}}$$.create=($)=>{return new $$({typeName:V.ZodNull,...E($)})};class u extends R{constructor(){super(...arguments);this._any=!0}_parse($){return U($.data)}}u.create=($)=>{return new u({typeName:V.ZodAny,...E($)})};class y extends R{constructor(){super(...arguments);this._unknown=!0}_parse($){return U($.data)}}y.create=($)=>{return new y({typeName:V.ZodUnknown,...E($)})};class k extends R{_parse($){let q=this._getOrReturnCtx($);return M(q,{code:_.invalid_type,expected:z.never,received:q.parsedType}),S}}k.create=($)=>{return new k({typeName:V.ZodNever,...E($)})};class M$ extends R{_parse($){if(this._getType($)!==z.undefined){let J=this._getOrReturnCtx($);return M(J,{code:_.invalid_type,expected:z.void,received:J.parsedType}),S}return U($.data)}}M$.create=($)=>{return new M$({typeName:V.ZodVoid,...E($)})};class N extends R{_parse($){let{ctx:q,status:J}=this._processInputParams($),G=this._def;if(q.parsedType!==z.array)return M(q,{code:_.invalid_type,expected:z.array,received:q.parsedType}),S;if(G.exactLength!==null){let W=q.data.length>G.exactLength.value,H=q.data.length<G.exactLength.value;if(W||H)M(q,{code:W?_.too_big:_.too_small,minimum:H?G.exactLength.value:void 0,maximum:W?G.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:G.exactLength.message}),J.dirty()}if(G.minLength!==null){if(q.data.length<G.minLength.value)M(q,{code:_.too_small,minimum:G.minLength.value,type:"array",inclusive:!0,exact:!1,message:G.minLength.message}),J.dirty()}if(G.maxLength!==null){if(q.data.length>G.maxLength.value)M(q,{code:_.too_big,maximum:G.maxLength.value,type:"array",inclusive:!0,exact:!1,message:G.maxLength.message}),J.dirty()}if(q.common.async)return Promise.all([...q.data].map((W,H)=>{return G.type._parseAsync(new v(q,W,q.path,H))})).then((W)=>{return A.mergeArray(J,W)});let Q=[...q.data].map((W,H)=>{return G.type._parseSync(new v(q,W,q.path,H))});return A.mergeArray(J,Q)}get element(){return this._def.type}min($,q){return new N({...this._def,minLength:{value:$,message:w.toString(q)}})}max($,q){return new N({...this._def,maxLength:{value:$,message:w.toString(q)}})}length($,q){return new N({...this._def,exactLength:{value:$,message:w.toString(q)}})}nonempty($){return this.min(1,$)}}N.create=($,q)=>{return new N({type:$,minLength:null,maxLength:null,exactLength:null,typeName:V.ZodArray,...E(q)})};function a($){if($ instanceof b){let q={};for(let J in $.shape){let G=$.shape[J];q[J]=F.create(a(G))}return new b({...$._def,shape:()=>q})}else if($ instanceof N)return new N({...$._def,type:a($.element)});else if($ instanceof F)return F.create(a($.unwrap()));else if($ instanceof x)return x.create(a($.unwrap()));else if($ instanceof I)return I.create($.items.map((q)=>a(q)));else return $}class b extends R{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=j.objectKeys($);return this._cached={shape:$,keys:q},this._cached}_parse($){if(this._getType($)!==z.object){let Y=this._getOrReturnCtx($);return M(Y,{code:_.invalid_type,expected:z.object,received:Y.parsedType}),S}let{status:J,ctx:G}=this._processInputParams($),{shape:Q,keys:W}=this._getCached(),H=[];if(!(this._def.catchall instanceof k&&this._def.unknownKeys==="strip")){for(let Y in G.data)if(!W.includes(Y))H.push(Y)}let X=[];for(let Y of W){let B=Q[Y],L=G.data[Y];X.push({key:{status:"valid",value:Y},value:B._parse(new v(G,L,G.path,Y)),alwaysSet:Y in G.data})}if(this._def.catchall instanceof k){let Y=this._def.unknownKeys;if(Y==="passthrough")for(let B of H)X.push({key:{status:"valid",value:B},value:{status:"valid",value:G.data[B]}});else if(Y==="strict"){if(H.length>0)M(G,{code:_.unrecognized_keys,keys:H}),J.dirty()}else if(Y==="strip");else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let Y=this._def.catchall;for(let B of H){let L=G.data[B];X.push({key:{status:"valid",value:B},value:Y._parse(new v(G,L,G.path,B)),alwaysSet:B in G.data})}}if(G.common.async)return Promise.resolve().then(async()=>{let Y=[];for(let B of X){let L=await B.key,D=await B.value;Y.push({key:L,value:D,alwaysSet:B.alwaysSet})}return Y}).then((Y)=>{return A.mergeObjectSync(J,Y)});else return A.mergeObjectSync(J,X)}get shape(){return this._def.shape()}strict($){return w.errToObj,new b({...this._def,unknownKeys:"strict",...$!==void 0?{errorMap:(q,J)=>{let G=this._def.errorMap?.(q,J).message??J.defaultError;if(q.code==="unrecognized_keys")return{message:w.errToObj($).message??G};return{message:G}}}:{}})}strip(){return new b({...this._def,unknownKeys:"strip"})}passthrough(){return new b({...this._def,unknownKeys:"passthrough"})}extend($){return new b({...this._def,shape:()=>({...this._def.shape(),...$})})}merge($){return new b({unknownKeys:$._def.unknownKeys,catchall:$._def.catchall,shape:()=>({...this._def.shape(),...$._def.shape()}),typeName:V.ZodObject})}setKey($,q){return this.augment({[$]:q})}catchall($){return new b({...this._def,catchall:$})}pick($){let q={};for(let J of j.objectKeys($))if($[J]&&this.shape[J])q[J]=this.shape[J];return new b({...this._def,shape:()=>q})}omit($){let q={};for(let J of j.objectKeys(this.shape))if(!$[J])q[J]=this.shape[J];return new b({...this._def,shape:()=>q})}deepPartial(){return a(this)}partial($){let q={};for(let J of j.objectKeys(this.shape)){let G=this.shape[J];if($&&!$[J])q[J]=G;else q[J]=G.optional()}return new b({...this._def,shape:()=>q})}required($){let q={};for(let J of j.objectKeys(this.shape))if($&&!$[J])q[J]=this.shape[J];else{let Q=this.shape[J];while(Q instanceof F)Q=Q._def.innerType;q[J]=Q}return new b({...this._def,shape:()=>q})}keyof(){return p$(j.objectKeys(this.shape))}}b.create=($,q)=>{return new b({shape:()=>$,unknownKeys:"strip",catchall:k.create(),typeName:V.ZodObject,...E(q)})};b.strictCreate=($,q)=>{return new b({shape:()=>$,unknownKeys:"strict",catchall:k.create(),typeName:V.ZodObject,...E(q)})};b.lazycreate=($,q)=>{return new b({shape:$,unknownKeys:"strip",catchall:k.create(),typeName:V.ZodObject,...E(q)})};class q$ extends R{_parse($){let{ctx:q}=this._processInputParams($),J=this._def.options;function G(Q){for(let H of Q)if(H.result.status==="valid")return H.result;for(let H of Q)if(H.result.status==="dirty")return q.common.issues.push(...H.ctx.common.issues),H.result;let W=Q.map((H)=>new O(H.ctx.common.issues));return M(q,{code:_.invalid_union,unionErrors:W}),S}if(q.common.async)return Promise.all(J.map(async(Q)=>{let W={...q,common:{...q.common,issues:[]},parent:null};return{result:await Q._parseAsync({data:q.data,path:q.path,parent:W}),ctx:W}})).then(G);else{let Q=void 0,W=[];for(let X of J){let Y={...q,common:{...q.common,issues:[]},parent:null},B=X._parseSync({data:q.data,path:q.path,parent:Y});if(B.status==="valid")return B;else if(B.status==="dirty"&&!Q)Q={result:B,ctx:Y};if(Y.common.issues.length)W.push(Y.common.issues)}if(Q)return q.common.issues.push(...Q.ctx.common.issues),Q.result;let H=W.map((X)=>new O(X));return M(q,{code:_.invalid_union,unionErrors:H}),S}}get options(){return this._def.options}}q$.create=($,q)=>{return new q$({options:$,typeName:V.ZodUnion,...E(q)})};var h=($)=>{if($ instanceof G$)return h($.schema);else if($ instanceof C)return h($.innerType());else if($ instanceof Q$)return[$.value];else if($ instanceof l)return $.options;else if($ instanceof H$)return j.objectValues($.enum);else if($ instanceof W$)return h($._def.innerType);else if($ instanceof e)return[void 0];else if($ instanceof $$)return[null];else if($ instanceof F)return[void 0,...h($.unwrap())];else if($ instanceof x)return[null,...h($.unwrap())];else if($ instanceof U$)return h($.unwrap());else if($ instanceof Y$)return h($.unwrap());else if($ instanceof X$)return h($._def.innerType);else return[]};class A$ extends R{_parse($){let{ctx:q}=this._processInputParams($);if(q.parsedType!==z.object)return M(q,{code:_.invalid_type,expected:z.object,received:q.parsedType}),S;let J=this.discriminator,G=q.data[J],Q=this.optionsMap.get(G);if(!Q)return M(q,{code:_.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[J]}),S;if(q.common.async)return Q._parseAsync({data:q.data,path:q.path,parent:q});else return Q._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,J){let G=new Map;for(let Q of q){let W=h(Q.shape[$]);if(!W.length)throw Error(`A discriminator value for key \`${$}\` could not be extracted from all schema options`);for(let H of W){if(G.has(H))throw Error(`Discriminator property ${String($)} has duplicate value ${String(H)}`);G.set(H,Q)}}return new A$({typeName:V.ZodDiscriminatedUnion,discriminator:$,options:q,optionsMap:G,...E(J)})}}function f$($,q){let J=f($),G=f(q);if($===q)return{valid:!0,data:$};else if(J===z.object&&G===z.object){let Q=j.objectKeys(q),W=j.objectKeys($).filter((X)=>Q.indexOf(X)!==-1),H={...$,...q};for(let X of W){let Y=f$($[X],q[X]);if(!Y.valid)return{valid:!1};H[X]=Y.data}return{valid:!0,data:H}}else if(J===z.array&&G===z.array){if($.length!==q.length)return{valid:!1};let Q=[];for(let W=0;W<$.length;W++){let H=$[W],X=q[W],Y=f$(H,X);if(!Y.valid)return{valid:!1};Q.push(Y.data)}return{valid:!0,data:Q}}else if(J===z.date&&G===z.date&&+$===+q)return{valid:!0,data:$};else return{valid:!1}}class J$ extends R{_parse($){let{status:q,ctx:J}=this._processInputParams($),G=(Q,W)=>{if(L$(Q)||L$(W))return S;let H=f$(Q.value,W.value);if(!H.valid)return M(J,{code:_.invalid_intersection_types}),S;if(b$(Q)||b$(W))q.dirty();return{status:q.value,value:H.data}};if(J.common.async)return Promise.all([this._def.left._parseAsync({data:J.data,path:J.path,parent:J}),this._def.right._parseAsync({data:J.data,path:J.path,parent:J})]).then(([Q,W])=>G(Q,W));else return G(this._def.left._parseSync({data:J.data,path:J.path,parent:J}),this._def.right._parseSync({data:J.data,path:J.path,parent:J}))}}J$.create=($,q,J)=>{return new J$({left:$,right:q,typeName:V.ZodIntersection,...E(J)})};class I extends R{_parse($){let{status:q,ctx:J}=this._processInputParams($);if(J.parsedType!==z.array)return M(J,{code:_.invalid_type,expected:z.array,received:J.parsedType}),S;if(J.data.length<this._def.items.length)return M(J,{code:_.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),S;if(!this._def.rest&&J.data.length>this._def.items.length)M(J,{code:_.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),q.dirty();let Q=[...J.data].map((W,H)=>{let X=this._def.items[H]||this._def.rest;if(!X)return null;return X._parse(new v(J,W,J.path,H))}).filter((W)=>!!W);if(J.common.async)return Promise.all(Q).then((W)=>{return A.mergeArray(q,W)});else return A.mergeArray(q,Q)}get items(){return this._def.items}rest($){return new I({...this._def,rest:$})}}I.create=($,q)=>{if(!Array.isArray($))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new I({items:$,typeName:V.ZodTuple,rest:null,...E(q)})};class w$ extends R{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:q,ctx:J}=this._processInputParams($);if(J.parsedType!==z.object)return M(J,{code:_.invalid_type,expected:z.object,received:J.parsedType}),S;let G=[],Q=this._def.keyType,W=this._def.valueType;for(let H in J.data)G.push({key:Q._parse(new v(J,H,J.path,H)),value:W._parse(new v(J,J.data[H],J.path,H)),alwaysSet:H in J.data});if(J.common.async)return A.mergeObjectAsync(q,G);else return A.mergeObjectSync(q,G)}get element(){return this._def.valueType}static create($,q,J){if(q instanceof R)return new w$({keyType:$,valueType:q,typeName:V.ZodRecord,...E(J)});return new w$({keyType:K.create(),valueType:$,typeName:V.ZodRecord,...E(q)})}}class S$ extends R{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:q,ctx:J}=this._processInputParams($);if(J.parsedType!==z.map)return M(J,{code:_.invalid_type,expected:z.map,received:J.parsedType}),S;let G=this._def.keyType,Q=this._def.valueType,W=[...J.data.entries()].map(([H,X],Y)=>{return{key:G._parse(new v(J,H,J.path,[Y,"key"])),value:Q._parse(new v(J,X,J.path,[Y,"value"]))}});if(J.common.async){let H=new Map;return Promise.resolve().then(async()=>{for(let X of W){let Y=await X.key,B=await X.value;if(Y.status==="aborted"||B.status==="aborted")return S;if(Y.status==="dirty"||B.status==="dirty")q.dirty();H.set(Y.value,B.value)}return{status:q.value,value:H}})}else{let H=new Map;for(let X of W){let{key:Y,value:B}=X;if(Y.status==="aborted"||B.status==="aborted")return S;if(Y.status==="dirty"||B.status==="dirty")q.dirty();H.set(Y.value,B.value)}return{status:q.value,value:H}}}}S$.create=($,q,J)=>{return new S$({valueType:q,keyType:$,typeName:V.ZodMap,...E(J)})};class p extends R{_parse($){let{status:q,ctx:J}=this._processInputParams($);if(J.parsedType!==z.set)return M(J,{code:_.invalid_type,expected:z.set,received:J.parsedType}),S;let G=this._def;if(G.minSize!==null){if(J.data.size<G.minSize.value)M(J,{code:_.too_small,minimum:G.minSize.value,type:"set",inclusive:!0,exact:!1,message:G.minSize.message}),q.dirty()}if(G.maxSize!==null){if(J.data.size>G.maxSize.value)M(J,{code:_.too_big,maximum:G.maxSize.value,type:"set",inclusive:!0,exact:!1,message:G.maxSize.message}),q.dirty()}let Q=this._def.valueType;function W(X){let Y=new Set;for(let B of X){if(B.status==="aborted")return S;if(B.status==="dirty")q.dirty();Y.add(B.value)}return{status:q.value,value:Y}}let H=[...J.data.values()].map((X,Y)=>Q._parse(new v(J,X,J.path,Y)));if(J.common.async)return Promise.all(H).then((X)=>W(X));else return W(H)}min($,q){return new p({...this._def,minSize:{value:$,message:w.toString(q)}})}max($,q){return new p({...this._def,maxSize:{value:$,message:w.toString(q)}})}size($,q){return this.min($,q).max($,q)}nonempty($){return this.min(1,$)}}p.create=($,q)=>{return new p({valueType:$,minSize:null,maxSize:null,typeName:V.ZodSet,...E(q)})};class s extends R{constructor(){super(...arguments);this.validate=this.implement}_parse($){let{ctx:q}=this._processInputParams($);if(q.parsedType!==z.function)return M(q,{code:_.invalid_type,expected:z.function,received:q.parsedType}),S;function J(H,X){return B$({data:H,path:q.path,errorMaps:[q.common.contextualErrorMap,q.schemaErrorMap,r(),T].filter((Y)=>!!Y),issueData:{code:_.invalid_arguments,argumentsError:X}})}function G(H,X){return B$({data:H,path:q.path,errorMaps:[q.common.contextualErrorMap,q.schemaErrorMap,r(),T].filter((Y)=>!!Y),issueData:{code:_.invalid_return_type,returnTypeError:X}})}let Q={errorMap:q.common.contextualErrorMap},W=q.data;if(this._def.returns instanceof d){let H=this;return U(async function(...X){let Y=new O([]),B=await H._def.args.parseAsync(X,Q).catch((P)=>{throw Y.addIssue(J(X,P)),Y}),L=await Reflect.apply(W,this,B);return await H._def.returns._def.type.parseAsync(L,Q).catch((P)=>{throw Y.addIssue(G(L,P)),Y})})}else{let H=this;return U(function(...X){let Y=H._def.args.safeParse(X,Q);if(!Y.success)throw new O([J(X,Y.error)]);let B=Reflect.apply(W,this,Y.data),L=H._def.returns.safeParse(B,Q);if(!L.success)throw new O([G(B,L.error)]);return L.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...$){return new s({...this._def,args:I.create($).rest(y.create())})}returns($){return new s({...this._def,returns:$})}implement($){return this.parse($)}strictImplement($){return this.parse($)}static create($,q,J){return new s({args:$?$:I.create([]).rest(y.create()),returns:q||y.create(),typeName:V.ZodFunction,...E(J)})}}class G$ extends R{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})}}G$.create=($,q)=>{return new G$({getter:$,typeName:V.ZodLazy,...E(q)})};class Q$ extends R{_parse($){if($.data!==this._def.value){let q=this._getOrReturnCtx($);return M(q,{received:q.data,code:_.invalid_literal,expected:this._def.value}),S}return{status:"valid",value:$.data}}get value(){return this._def.value}}Q$.create=($,q)=>{return new Q$({value:$,typeName:V.ZodLiteral,...E(q)})};function p$($,q){return new l({values:$,typeName:V.ZodEnum,...E(q)})}class l extends R{_parse($){if(typeof $.data!=="string"){let q=this._getOrReturnCtx($),J=this._def.values;return M(q,{expected:j.joinValues(J),received:q.parsedType,code:_.invalid_type}),S}if(!this._cache)this._cache=new Set(this._def.values);if(!this._cache.has($.data)){let q=this._getOrReturnCtx($),J=this._def.values;return M(q,{received:q.data,code:_.invalid_enum_value,options:J}),S}return U($.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 l.create($,{...this._def,...q})}exclude($,q=this._def){return l.create(this.options.filter((J)=>!$.includes(J)),{...this._def,...q})}}l.create=p$;class H$ extends R{_parse($){let q=j.getValidEnumValues(this._def.values),J=this._getOrReturnCtx($);if(J.parsedType!==z.string&&J.parsedType!==z.number){let G=j.objectValues(q);return M(J,{expected:j.joinValues(G),received:J.parsedType,code:_.invalid_type}),S}if(!this._cache)this._cache=new Set(j.getValidEnumValues(this._def.values));if(!this._cache.has($.data)){let G=j.objectValues(q);return M(J,{received:J.data,code:_.invalid_enum_value,options:G}),S}return U($.data)}get enum(){return this._def.values}}H$.create=($,q)=>{return new H$({values:$,typeName:V.ZodNativeEnum,...E(q)})};class d extends R{unwrap(){return this._def.type}_parse($){let{ctx:q}=this._processInputParams($);if(q.parsedType!==z.promise&&q.common.async===!1)return M(q,{code:_.invalid_type,expected:z.promise,received:q.parsedType}),S;let J=q.parsedType===z.promise?q.data:Promise.resolve(q.data);return U(J.then((G)=>{return this._def.type.parseAsync(G,{path:q.path,errorMap:q.common.contextualErrorMap})}))}}d.create=($,q)=>{return new d({type:$,typeName:V.ZodPromise,...E(q)})};class C extends R{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===V.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse($){let{status:q,ctx:J}=this._processInputParams($),G=this._def.effect||null,Q={addIssue:(W)=>{if(M(J,W),W.fatal)q.abort();else q.dirty()},get path(){return J.path}};if(Q.addIssue=Q.addIssue.bind(Q),G.type==="preprocess"){let W=G.transform(J.data,Q);if(J.common.async)return Promise.resolve(W).then(async(H)=>{if(q.value==="aborted")return S;let X=await this._def.schema._parseAsync({data:H,path:J.path,parent:J});if(X.status==="aborted")return S;if(X.status==="dirty")return c(X.value);if(q.value==="dirty")return c(X.value);return X});else{if(q.value==="aborted")return S;let H=this._def.schema._parseSync({data:W,path:J.path,parent:J});if(H.status==="aborted")return S;if(H.status==="dirty")return c(H.value);if(q.value==="dirty")return c(H.value);return H}}if(G.type==="refinement"){let W=(H)=>{let X=G.refinement(H,Q);if(J.common.async)return Promise.resolve(X);if(X instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return H};if(J.common.async===!1){let H=this._def.schema._parseSync({data:J.data,path:J.path,parent:J});if(H.status==="aborted")return S;if(H.status==="dirty")q.dirty();return W(H.value),{status:q.value,value:H.value}}else return this._def.schema._parseAsync({data:J.data,path:J.path,parent:J}).then((H)=>{if(H.status==="aborted")return S;if(H.status==="dirty")q.dirty();return W(H.value).then(()=>{return{status:q.value,value:H.value}})})}if(G.type==="transform")if(J.common.async===!1){let W=this._def.schema._parseSync({data:J.data,path:J.path,parent:J});if(!g(W))return S;let H=G.transform(W.value,Q);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:J.data,path:J.path,parent:J}).then((W)=>{if(!g(W))return S;return Promise.resolve(G.transform(W.value,Q)).then((H)=>({status:q.value,value:H}))});j.assertNever(G)}}C.create=($,q,J)=>{return new C({schema:$,typeName:V.ZodEffects,effect:q,...E(J)})};C.createWithPreprocess=($,q,J)=>{return new C({schema:q,effect:{type:"preprocess",transform:$},typeName:V.ZodEffects,...E(J)})};class F extends R{_parse($){if(this._getType($)===z.undefined)return U(void 0);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}F.create=($,q)=>{return new F({innerType:$,typeName:V.ZodOptional,...E(q)})};class x extends R{_parse($){if(this._getType($)===z.null)return U(null);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}x.create=($,q)=>{return new x({innerType:$,typeName:V.ZodNullable,...E(q)})};class W$ extends R{_parse($){let{ctx:q}=this._processInputParams($),J=q.data;if(q.parsedType===z.undefined)J=this._def.defaultValue();return this._def.innerType._parse({data:J,path:q.path,parent:q})}removeDefault(){return this._def.innerType}}W$.create=($,q)=>{return new W$({innerType:$,typeName:V.ZodDefault,defaultValue:typeof q.default==="function"?q.default:()=>q.default,...E(q)})};class X$ extends R{_parse($){let{ctx:q}=this._processInputParams($),J={...q,common:{...q.common,issues:[]}},G=this._def.innerType._parse({data:J.data,path:J.path,parent:{...J}});if(o(G))return G.then((Q)=>{return{status:"valid",value:Q.status==="valid"?Q.value:this._def.catchValue({get error(){return new O(J.common.issues)},input:J.data})}});else return{status:"valid",value:G.status==="valid"?G.value:this._def.catchValue({get error(){return new O(J.common.issues)},input:J.data})}}removeCatch(){return this._def.innerType}}X$.create=($,q)=>{return new X$({innerType:$,typeName:V.ZodCatch,catchValue:typeof q.catch==="function"?q.catch:()=>q.catch,...E(q)})};class V$ extends R{_parse($){if(this._getType($)!==z.nan){let J=this._getOrReturnCtx($);return M(J,{code:_.invalid_type,expected:z.nan,received:J.parsedType}),S}return{status:"valid",value:$.data}}}V$.create=($)=>{return new V$({typeName:V.ZodNaN,...E($)})};var Iq=Symbol("zod_brand");class U$ extends R{_parse($){let{ctx:q}=this._processInputParams($),J=q.data;return this._def.type._parse({data:J,path:q.path,parent:q})}unwrap(){return this._def.type}}class E$ extends R{_parse($){let{status:q,ctx:J}=this._processInputParams($);if(J.common.async)return(async()=>{let Q=await this._def.in._parseAsync({data:J.data,path:J.path,parent:J});if(Q.status==="aborted")return S;if(Q.status==="dirty")return q.dirty(),c(Q.value);else return this._def.out._parseAsync({data:Q.value,path:J.path,parent:J})})();else{let G=this._def.in._parseSync({data:J.data,path:J.path,parent:J});if(G.status==="aborted")return S;if(G.status==="dirty")return q.dirty(),{status:"dirty",value:G.value};else return this._def.out._parseSync({data:G.value,path:J.path,parent:J})}}static create($,q){return new E$({in:$,out:q,typeName:V.ZodPipeline})}}class Y$ extends R{_parse($){let q=this._def.innerType._parse($),J=(G)=>{if(g(G))G.value=Object.freeze(G.value);return G};return o(q)?q.then((G)=>J(G)):J(q)}unwrap(){return this._def.innerType}}Y$.create=($,q)=>{return new Y$({innerType:$,typeName:V.ZodReadonly,...E(q)})};function l$($,q){let J=typeof $==="function"?$(q):typeof $==="string"?{message:$}:$;return typeof J==="string"?{message:J}:J}function d$($,q={},J){if($)return u.create().superRefine((G,Q)=>{let W=$(G);if(W instanceof Promise)return W.then((H)=>{if(!H){let X=l$(q,G),Y=X.fatal??J??!0;Q.addIssue({code:"custom",...X,fatal:Y})}});if(!W){let H=l$(q,G),X=H.fatal??J??!0;Q.addIssue({code:"custom",...H,fatal:X})}return});return u.create()}var Pq={object:b.lazycreate},V;(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"})(V||(V={}));var Tq=($,q={message:`Input not instance of ${$.name}`})=>d$((J)=>J instanceof $,q),i$=K.create,r$=Z.create,hq=V$.create,xq=m.create,o$=t.create,gq=n.create,yq=z$.create,Zq=e.create,mq=$$.create,lq=u.create,cq=y.create,nq=k.create,uq=M$.create,pq=N.create,dq=b.create,iq=b.strictCreate,rq=q$.create,oq=A$.create,aq=J$.create,sq=I.create,tq=w$.create,eq=S$.create,$3=p.create,q3=s.create,J3=G$.create,G3=Q$.create,Q3=l.create,H3=H$.create,W3=d.create,X3=C.create,Y3=F.create,_3=x.create,B3=C.createWithPreprocess,z3=E$.create,M3=()=>i$().optional(),w3=()=>r$().optional(),S3=()=>o$().optional(),V3={string:($)=>K.create({...$,coerce:!0}),number:($)=>Z.create({...$,coerce:!0}),boolean:($)=>t.create({...$,coerce:!0}),bigint:($)=>m.create({...$,coerce:!0}),date:($)=>n.create({...$,coerce:!0})};var E3=S;function R3($){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 J of $.permissions)if(!q.includes(J))throw Error(`Invalid permission: ${J}. 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,J]of Object.entries($.resolvers)){if(!q.startsWith("$"))throw Error(`Resolver name "${q}" must start with $ (e.g., "$${q}")`);if(typeof J!=="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[J,G]of Object.entries($.hooks)){if(!q.includes(J))throw Error(`Invalid hook: "${J}". Valid hooks are: ${q.join(", ")}`);if(typeof G!=="function")throw Error(`Hook "${J}" 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,J]of Object.entries($.commands))if(typeof J!=="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,J]of Object.entries($.tools)){if(typeof J.description!=="string")throw Error(`Tool "${q}" must have a description`);if(typeof J.args!=="object"||J.args===null)throw Error(`Tool "${q}" must have args schema`);if(typeof J.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 j3($){let q=_$.object($.args);return{description:$.description,args:q,execute:async(J,G)=>{let Q=q.parse(J);return await $.execute(Q,G)}}}function R$($){return`${$.name}#${$.instanceId??"default"}`}function L3($){let q=$.indexOf("#");if(q===-1)return{name:$,instanceId:"default"};return{name:$.slice(0,q),instanceId:$.slice(q+1)}}function k$($){return typeof $==="object"&&$!==null&&!Array.isArray($)&&"command"in $&&Array.isArray($.command)}function a$($){return typeof $==="object"&&$!==null&&!Array.isArray($)&&"name"in $&&typeof $.name==="string"&&!("command"in $)}function b3($){if(typeof $==="string")return $.startsWith("file://");if(Array.isArray($)&&typeof $[0]==="string")return $[0].startsWith("file://");return!1}function A3($){if(typeof $==="string")return!$.startsWith("file://")&&!k$($);if(Array.isArray($)&&typeof $[0]==="string")return!$[0].startsWith("file://");return!1}function s$($,q){let J=i("node:path"),G=J.relative(q,$);return!G.startsWith("..")&&!J.isAbsolute(G)}function t$($,q,J){if(!$.startsWith("file://"))throw Error(`Invalid file URL: ${$}`);let G=i("node:path"),Q=$.slice(7),W;if(Q.startsWith("/"))W=G.normalize(Q);else if(Q.startsWith("./")||Q.startsWith("../"))W=G.resolve(q,Q);else throw Error(`Invalid file plugin path: ${$}. Use file://./relative/path.ts or file:///absolute/path.ts`);if(!J&&!s$(W,q))throw Error(`Plugin path "${$}" resolves outside project root. Set security.allowPluginsOutsideProject: true to allow.`);return W}async function U3($,q,J){let G=i("node:fs/promises");if(J)return $;try{let Q=await G.realpath($);if(!s$(Q,q))throw Error(`Plugin path "${$}" resolves to "${Q}" which is outside project root. Symlinks pointing outside the project are not allowed. Set security.allowPluginsOutsideProject: true to allow.`);return Q}catch(Q){if(Q.code==="ENOENT")return $;throw Q}}function D$($,q,J){let G=$.permissions??[],Q=q?.[$.name];if(Q!==void 0){for(let H of G)if(!Q.includes(H))J.push(`Plugin '${$.name}' requires '${H}' permission but it was denied. Some features may not work. Add to security.pluginPermissions to enable.`);return Q}let W=q?.default;if(W!==void 0){let H=G.filter((X)=>W.includes(X));for(let X of G)if(!W.includes(X))J.push(`Plugin '${$.name}' requires '${X}' permission but it was denied by default. Some features may not work. Add to security.pluginPermissions to enable.`);return H}return G}async function I$($){let{projectRoot:q,plugins:J,security:G,pluginPermissions:Q}=$,W=$.warnings??[],H=[],X=new Map;for(let Y of J)try{let B=await D3(Y,{projectRoot:q,allowOutsideProject:G?.allowPluginsOutsideProject??!1,warnings:W,...Q!==void 0?{pluginPermissions:Q}:{}});if(!B)continue;let L=R$(B.plugin),D=X.get(L);if(D!==void 0)H[D]=B;else X.set(L,H.length),H.push(B)}catch(B){let L=B instanceof Error?B.message:String(B);W.push(`Failed to load plugin: ${L}`)}return{plugins:H,warnings:W}}async function D3($,q){let{projectRoot:J,allowOutsideProject:G,pluginPermissions:Q,warnings:W}=q;if(a$($)){let Y=D$($,Q,W);return{plugin:{...$,instanceId:$.instanceId??"default"},id:R$($),source:"inline",permissions:Y,initialized:!1}}if(k$($))return{plugin:{name:`subprocess:${$.command.join(" ")}`,instanceId:"default"},id:`subprocess:${$.command.join(" ")}#default`,source:"subprocess",permissions:[],initialized:!1,_subprocessConfig:$};let H,X;if(Array.isArray($))H=$[0],X=$[1];else H=$;if(H.startsWith("file://")){let Y=t$(H,J,G);return await O3(Y,X,Q,W,J,G)}return await K3(H,X,Q,W)}async function O3($,q,J,G,Q,W){try{let H=$;if(Q!==void 0)H=await U3($,Q,W??!1);let X=await import(H),Y=X.default??X,B;if(typeof Y==="function")B=q?Y(q):Y();else if(typeof Y==="object"&&Y!==null)B=Y;else throw Error(`File "${$}" does not export a valid plugin`);if(B={...B,instanceId:B.instanceId??"default"},q&&typeof q.instanceId==="string")B={...B,instanceId:q.instanceId};let L=D$(B,J,G);return{plugin:B,id:R$(B),source:"file",permissions:L,initialized:!1}}catch(H){throw Error(`Failed to load plugin from "${$}": ${H instanceof Error?H.message:String(H)}`)}}async function K3($,q,J,G){try{let Q=$,W=$.lastIndexOf("@");if(W>0)Q=$.slice(0,W);let H=await import(Q),X=H.default??H,Y;if(typeof X==="function")Y=q?X(q):X();else if(typeof X==="object"&&X!==null)Y=X;else throw Error(`Package "${Q}" does not export a valid plugin`);if(Y={...Y,instanceId:Y.instanceId??"default"},q&&typeof q.instanceId==="string")Y={...Y,instanceId:q.instanceId};let B=D$(Y,J,G);return{plugin:Y,id:R$(Y),source:"npm",permissions:B,initialized:!1}}catch(Q){throw Error(`Failed to load plugin "${$}": ${Q instanceof Error?Q.message:String(Q)}`)}}function N3($,q){return[...$,...q]}class P$ extends Error{permission;pluginName;constructor($,q){super(`Plugin "${q}" does not have "${$}" permission`);this.permission=$;this.pluginName=q;this.name="PermissionDeniedError"}}class e${secrets=new Map;constructor($){if($)for(let[q,J]of Object.entries($))this.secrets.set(q,J)}async get($){return this.secrets.get($)}set($,q){this.secrets.set($,q)}}function O$($,q,J){let G=J.relative(q,$);return!G.startsWith("..")&&!J.isAbsolute(G)}function F3($,q){let J=i("node:fs/promises"),G=i("node:path"),Q=async(H)=>{let X=G.resolve($,H);if(!q&&!O$(X,$,G))throw Error(`Path "${H}" is outside project root. Plugins need "filesystem" permission to access files outside project.`);if(!q)try{let Y=await J.realpath(X);if(!O$(Y,$,G))throw Error(`Path "${H}" resolves to "${Y}" which is outside project root. Symlinks pointing outside the project are not allowed.`);return Y}catch(Y){if(Y.code==="ENOENT")return X;throw Y}return X},W=async(H)=>{let X=G.resolve($,H);if(!q&&!O$(X,$,G))throw Error(`Path "${H}" is outside project root. Plugins need "filesystem" permission to access files outside project.`);if(!q){let Y=G.dirname(X);try{let B=await J.realpath(Y);if(!O$(B,$,G))throw Error(`Path "${H}" parent directory resolves to "${B}" which is outside project root. Symlinks pointing outside the project are not allowed.`)}catch(B){if(B.code!=="ENOENT")throw B}}return X};return{async readFile(H){let X=await Q(H);return await J.readFile(X,"utf-8")},async writeFile(H,X){let Y=await W(H);await J.writeFile(Y,X,"utf-8")}}}function v3($){let q=i("node:child_process");return async(J,G)=>{return new Promise((Q,W)=>{let H=q.spawn(J,G,{cwd:$,stdio:["pipe","pipe","pipe"]}),X="",Y="";H.stdout?.on("data",(B)=>{X+=B.toString("utf-8")}),H.stderr?.on("data",(B)=>{Y+=B.toString("utf-8")}),H.on("close",(B)=>{if(B===0)Q({stdout:X,stderr:Y});else W(Error(`Command failed with code ${B}: ${Y}`))}),H.on("error",(B)=>{W(B)})})}}function C3($){let q=`[plugin:${$}]`;return{debug:(J)=>{if(process.env.DEBUG)console.debug(`${q} ${J}`)},info:(J)=>{console.info(`${q} ${J}`)},warn:(J)=>{console.warn(`${q} ${J}`)},error:(J)=>{console.error(`${q} ${J}`)}}}function T$($){let{plugin:q,permissions:J,config:G,enterprise:Q,secrets:W}=$,H=q.name,X={projectRoot:G.projectRoot,config:G,log:C3(H)};if(J.includes("secrets"))X.secrets=new e$(W);if(J.includes("network"))X.fetch=globalThis.fetch;if(J.includes("filesystem"))X.fs=F3(G.projectRoot,G.security.allowPluginsOutsideProject);if(J.includes("env"))X.env=process.env;if(J.includes("subprocess"))X.spawn=v3(G.projectRoot);if(J.includes("enterprise")&&Q)X.enterprise=Q;return X}function f3($,q,J){let G=[];for(let Q of J)if(!q.includes(Q))G.push(`Plugin "${$.name}" requires "${Q}" permission but it was denied.`);return G}function $q($,q){return $.includes(q)}function k3($,q,J){if(!$q($,q))throw new P$(q,J)}import{spawn as I3}from"node:child_process";function K$($){let q={...$},J={when(G,Q){if(G)q={...q,...Q};return J},ifDefined(G,Q){if(Q!==void 0)q={...q,[G]:Q};return J},build(){return q}};return J}var h$=1,P3=5000,T3=1e4,qq=3,h3=500,x3=10485760;class x${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",(J)=>{this.handleStdout(J)}),this.process.stderr?.on("data",(J)=>{let G=J.toString("utf-8").trim();if(G)console.error(`[subprocess:${this.pluginInfo.name}] ${G}`)}),this.process.on("close",(J,G)=>{this.handleClose(J,G)}),this.process.on("error",(J)=>{this.handleError(J)})}async initialize(){let $=this.config.startupTimeoutMs??T3,q=await this.sendRequest({id:this.nextId(),type:"init",protocolVersion:h$,config:this.config.config??{},projectRoot:this.projectRoot},$);if(q.type==="error")throw Error(`Plugin init failed: ${q.error.message}`);let G=q.result;if(G.protocolVersion>h$)throw Error(`Plugin requires protocol version ${G.protocolVersion}, but t-req supports version ${h$}`);this.pluginInfo=K$({name:G.name}).ifDefined("version",G.version).ifDefined("permissions",G.permissions).build(),this.capabilities={hooks:G.hooks??[],resolvers:G.resolvers??[],commands:G.commands??[]},this.initialized=!0}handleStdout($){if(this.buffer.length+$.length>x3){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 J of q){let G=J.trim();if(!G)continue;try{let Q=JSON.parse(G);this.handleResponse(Q)}catch{console.error(`[subprocess:${this.pluginInfo.name}] Invalid JSON: ${G.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[J,G]of this.pendingRequests)clearTimeout(G.timeout),G.reject(Error(`Plugin process exited with code ${$}, signal ${q}`));if(this.pendingRequests.clear(),this.initialized&&this.restartCount<(this.config.maxRestarts??qq))this.restartCount++,console.warn(`[subprocess:${this.pluginInfo.name}] Process crashed, restarting (${this.restartCount}/${this.config.maxRestarts??qq})`),this.spawn().then(()=>this.initialize()).catch((J)=>{console.error(`[subprocess:${this.pluginInfo.name}] Restart failed: ${J.message}`)})}handleError($){console.error(`[subprocess:${this.pluginInfo.name}] Process error: ${$.message}`);for(let[q,J]of this.pendingRequests)clearTimeout(J.timeout),J.reject($);this.pendingRequests.clear()}nextId(){return String(++this.requestId)}async sendRequest($,q=this.config.timeoutMs??P3){if(!this.process?.stdin)throw Error("Plugin process not running");return new Promise((J,G)=>{let Q=setTimeout(()=>{this.pendingRequests.delete($.id),G(Error(`Request timed out after ${q}ms`))},q);this.pendingRequests.set($.id,{resolve:J,reject:G,timeout:Q});let W=`${JSON.stringify($)}
1
+ import{createRequire as Xq}from"node:module";var Hq=Object.defineProperty;var Wq=($,q)=>{for(var J in q)Hq($,J,{get:q[J],enumerable:!0,configurable:!0,set:(G)=>q[J]=()=>G})};var y=Xq(import.meta.url);var B$={};Wq(B$,{void:()=>pq,util:()=>b,unknown:()=>uq,union:()=>oq,undefined:()=>mq,tuple:()=>tq,transformer:()=>Y3,symbol:()=>Zq,string:()=>r$,strictObject:()=>rq,setErrorMap:()=>Bq,set:()=>q3,record:()=>eq,quotelessJson:()=>Yq,promise:()=>X3,preprocess:()=>z3,pipeline:()=>M3,ostring:()=>w3,optional:()=>_3,onumber:()=>S3,oboolean:()=>V3,objectUtil:()=>C$,object:()=>iq,number:()=>o$,nullable:()=>B3,null:()=>lq,never:()=>nq,nativeEnum:()=>W3,nan:()=>gq,map:()=>$3,makeIssue:()=>z$,literal:()=>Q3,lazy:()=>G3,late:()=>Tq,isValid:()=>Z,isDirty:()=>U$,isAsync:()=>a,isAborted:()=>A$,intersection:()=>sq,instanceof:()=>hq,getParsedType:()=>I,getErrorMap:()=>o,function:()=>J3,enum:()=>H3,effect:()=>Y3,discriminatedUnion:()=>aq,defaultErrorMap:()=>h,datetimeRegex:()=>p$,date:()=>yq,custom:()=>i$,coerce:()=>E3,boolean:()=>a$,bigint:()=>xq,array:()=>dq,any:()=>cq,addIssueToContext:()=>M,ZodVoid:()=>w$,ZodUnknown:()=>m,ZodUnion:()=>J$,ZodUndefined:()=>$$,ZodType:()=>L,ZodTuple:()=>T,ZodTransformer:()=>k,ZodSymbol:()=>M$,ZodString:()=>F,ZodSet:()=>i,ZodSchema:()=>L,ZodRecord:()=>S$,ZodReadonly:()=>_$,ZodPromise:()=>r,ZodPipeline:()=>L$,ZodParsedType:()=>z,ZodOptional:()=>C,ZodObject:()=>A,ZodNumber:()=>l,ZodNullable:()=>x,ZodNull:()=>q$,ZodNever:()=>P,ZodNativeEnum:()=>W$,ZodNaN:()=>E$,ZodMap:()=>V$,ZodLiteral:()=>H$,ZodLazy:()=>Q$,ZodIssueCode:()=>_,ZodIntersection:()=>G$,ZodFunction:()=>t,ZodFirstPartyTypeKind:()=>V,ZodError:()=>N,ZodEnum:()=>u,ZodEffects:()=>k,ZodDiscriminatedUnion:()=>R$,ZodDefault:()=>X$,ZodDate:()=>p,ZodCatch:()=>Y$,ZodBranded:()=>D$,ZodBoolean:()=>e,ZodBigInt:()=>c,ZodArray:()=>v,ZodAny:()=>d,Schema:()=>L,ParseStatus:()=>O,OK:()=>K,NEVER:()=>L3,INVALID:()=>S,EMPTY_PATH:()=>zq,DIRTY:()=>n,BRAND:()=>Pq});var b;(function($){$.assertEqual=(Q)=>{};function q(Q){}$.assertIs=q;function J(Q){throw Error()}$.assertNever=J,$.arrayToEnum=(Q)=>{let W={};for(let H of Q)W[H]=H;return W},$.getValidEnumValues=(Q)=>{let W=$.objectKeys(Q).filter((X)=>typeof Q[Q[X]]!=="number"),H={};for(let X of W)H[X]=Q[X];return $.objectValues(H)},$.objectValues=(Q)=>{return $.objectKeys(Q).map(function(W){return Q[W]})},$.objectKeys=typeof Object.keys==="function"?(Q)=>Object.keys(Q):(Q)=>{let W=[];for(let H in Q)if(Object.prototype.hasOwnProperty.call(Q,H))W.push(H);return W},$.find=(Q,W)=>{for(let H of Q)if(W(H))return H;return},$.isInteger=typeof Number.isInteger==="function"?(Q)=>Number.isInteger(Q):(Q)=>typeof Q==="number"&&Number.isFinite(Q)&&Math.floor(Q)===Q;function G(Q,W=" | "){return Q.map((H)=>typeof H==="string"?`'${H}'`:H).join(W)}$.joinValues=G,$.jsonStringifyReplacer=(Q,W)=>{if(typeof W==="bigint")return W.toString();return W}})(b||(b={}));var C$;(function($){$.mergeShapes=(q,J)=>{return{...q,...J}}})(C$||(C$={}));var z=b.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),I=($)=>{switch(typeof $){case"undefined":return z.undefined;case"string":return z.string;case"number":return Number.isNaN($)?z.nan:z.number;case"boolean":return z.boolean;case"function":return z.function;case"bigint":return z.bigint;case"symbol":return z.symbol;case"object":if(Array.isArray($))return z.array;if($===null)return z.null;if($.then&&typeof $.then==="function"&&$.catch&&typeof $.catch==="function")return z.promise;if(typeof Map<"u"&&$ instanceof Map)return z.map;if(typeof Set<"u"&&$ instanceof Set)return z.set;if(typeof Date<"u"&&$ instanceof Date)return z.date;return z.object;default:return z.unknown}};var _=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"]),Yq=($)=>{return JSON.stringify($,null,2).replace(/"([^"]+)":/g,"$1:")};class N extends Error{get errors(){return this.issues}constructor($){super();this.issues=[],this.addIssue=(J)=>{this.issues=[...this.issues,J]},this.addIssues=(J=[])=>{this.issues=[...this.issues,...J]};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(Q){return Q.message},J={_errors:[]},G=(Q)=>{for(let W of Q.issues)if(W.code==="invalid_union")W.unionErrors.map(G);else if(W.code==="invalid_return_type")G(W.returnTypeError);else if(W.code==="invalid_arguments")G(W.argumentsError);else if(W.path.length===0)J._errors.push(q(W));else{let H=J,X=0;while(X<W.path.length){let Y=W.path[X];if(X!==W.path.length-1)H[Y]=H[Y]||{_errors:[]};else H[Y]=H[Y]||{_errors:[]},H[Y]._errors.push(q(W));H=H[Y],X++}}};return G(this),J}static assert($){if(!($ instanceof N))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={},J=[];for(let G of this.issues)if(G.path.length>0){let Q=G.path[0];q[Q]=q[Q]||[],q[Q].push($(G))}else J.push($(G));return{formErrors:J,fieldErrors:q}}get formErrors(){return this.flatten()}}N.create=($)=>{return new N($)};var _q=($,q)=>{let J;switch($.code){case _.invalid_type:if($.received===z.undefined)J="Required";else J=`Expected ${$.expected}, received ${$.received}`;break;case _.invalid_literal:J=`Invalid literal value, expected ${JSON.stringify($.expected,b.jsonStringifyReplacer)}`;break;case _.unrecognized_keys:J=`Unrecognized key(s) in object: ${b.joinValues($.keys,", ")}`;break;case _.invalid_union:J="Invalid input";break;case _.invalid_union_discriminator:J=`Invalid discriminator value. Expected ${b.joinValues($.options)}`;break;case _.invalid_enum_value:J=`Invalid enum value. Expected ${b.joinValues($.options)}, received '${$.received}'`;break;case _.invalid_arguments:J="Invalid function arguments";break;case _.invalid_return_type:J="Invalid function return type";break;case _.invalid_date:J="Invalid date";break;case _.invalid_string:if(typeof $.validation==="object")if("includes"in $.validation){if(J=`Invalid input: must include "${$.validation.includes}"`,typeof $.validation.position==="number")J=`${J} at one or more positions greater than or equal to ${$.validation.position}`}else if("startsWith"in $.validation)J=`Invalid input: must start with "${$.validation.startsWith}"`;else if("endsWith"in $.validation)J=`Invalid input: must end with "${$.validation.endsWith}"`;else b.assertNever($.validation);else if($.validation!=="regex")J=`Invalid ${$.validation}`;else J="Invalid";break;case _.too_small:if($.type==="array")J=`Array must contain ${$.exact?"exactly":$.inclusive?"at least":"more than"} ${$.minimum} element(s)`;else if($.type==="string")J=`String must contain ${$.exact?"exactly":$.inclusive?"at least":"over"} ${$.minimum} character(s)`;else if($.type==="number")J=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="bigint")J=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="date")J=`Date must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${new Date(Number($.minimum))}`;else J="Invalid input";break;case _.too_big:if($.type==="array")J=`Array must contain ${$.exact?"exactly":$.inclusive?"at most":"less than"} ${$.maximum} element(s)`;else if($.type==="string")J=`String must contain ${$.exact?"exactly":$.inclusive?"at most":"under"} ${$.maximum} character(s)`;else if($.type==="number")J=`Number must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="bigint")J=`BigInt must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="date")J=`Date must be ${$.exact?"exactly":$.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number($.maximum))}`;else J="Invalid input";break;case _.custom:J="Invalid input";break;case _.invalid_intersection_types:J="Intersection results could not be merged";break;case _.not_multiple_of:J=`Number must be a multiple of ${$.multipleOf}`;break;case _.not_finite:J="Number must be finite";break;default:J=q.defaultError,b.assertNever($)}return{message:J}},h=_q;var m$=h;function Bq($){m$=$}function o(){return m$}var z$=($)=>{let{data:q,path:J,errorMaps:G,issueData:Q}=$,W=[...J,...Q.path||[]],H={...Q,path:W};if(Q.message!==void 0)return{...Q,path:W,message:Q.message};let X="",Y=G.filter((B)=>!!B).slice().reverse();for(let B of Y)X=B(H,{data:q,defaultError:X}).message;return{...Q,path:W,message:X}},zq=[];function M($,q){let J=o(),G=z$({issueData:q,data:$.data,path:$.path,errorMaps:[$.common.contextualErrorMap,$.schemaErrorMap,J,J===h?void 0:h].filter((Q)=>!!Q)});$.common.issues.push(G)}class O{constructor(){this.value="valid"}dirty(){if(this.value==="valid")this.value="dirty"}abort(){if(this.value!=="aborted")this.value="aborted"}static mergeArray($,q){let J=[];for(let G of q){if(G.status==="aborted")return S;if(G.status==="dirty")$.dirty();J.push(G.value)}return{status:$.value,value:J}}static async mergeObjectAsync($,q){let J=[];for(let G of q){let Q=await G.key,W=await G.value;J.push({key:Q,value:W})}return O.mergeObjectSync($,J)}static mergeObjectSync($,q){let J={};for(let G of q){let{key:Q,value:W}=G;if(Q.status==="aborted")return S;if(W.status==="aborted")return S;if(Q.status==="dirty")$.dirty();if(W.status==="dirty")$.dirty();if(Q.value!=="__proto__"&&(typeof W.value<"u"||G.alwaysSet))J[Q.value]=W.value}return{status:$.value,value:J}}}var S=Object.freeze({status:"aborted"}),n=($)=>({status:"dirty",value:$}),K=($)=>({status:"valid",value:$}),A$=($)=>$.status==="aborted",U$=($)=>$.status==="dirty",Z=($)=>$.status==="valid",a=($)=>typeof Promise<"u"&&$ instanceof Promise;var w;(function($){$.errToObj=(q)=>typeof q==="string"?{message:q}:q||{},$.toString=(q)=>typeof q==="string"?q:q?.message})(w||(w={}));class f{constructor($,q,J,G){this._cachedPath=[],this.parent=$,this.data=q,this._path=J,this._key=G}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 l$=($,q)=>{if(Z(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 J=new N($.common.issues);return this._error=J,this._error}}}};function E($){if(!$)return{};let{errorMap:q,invalid_type_error:J,required_error:G,description:Q}=$;if(q&&(J||G))throw Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);if(q)return{errorMap:q,description:Q};return{errorMap:(H,X)=>{let{message:Y}=$;if(H.code==="invalid_enum_value")return{message:Y??X.defaultError};if(typeof X.data>"u")return{message:Y??G??X.defaultError};if(H.code!=="invalid_type")return{message:X.defaultError};return{message:Y??J??X.defaultError}},description:Q}}class L{get description(){return this._def.description}_getType($){return I($.data)}_getOrReturnCtx($,q){return q||{common:$.parent.common,data:$.data,parsedType:I($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}_processInputParams($){return{status:new O,ctx:{common:$.parent.common,data:$.data,parsedType:I($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}}_parseSync($){let q=this._parse($);if(a(q))throw Error("Synchronous parse encountered promise.");return q}_parseAsync($){let q=this._parse($);return Promise.resolve(q)}parse($,q){let J=this.safeParse($,q);if(J.success)return J.data;throw J.error}safeParse($,q){let J={common:{issues:[],async:q?.async??!1,contextualErrorMap:q?.errorMap},path:q?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:I($)},G=this._parseSync({data:$,path:J.path,parent:J});return l$(J,G)}"~validate"($){let q={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:I($)};if(!this["~standard"].async)try{let J=this._parseSync({data:$,path:[],parent:q});return Z(J)?{value:J.value}:{issues:q.common.issues}}catch(J){if(J?.message?.toLowerCase()?.includes("encountered"))this["~standard"].async=!0;q.common={issues:[],async:!0}}return this._parseAsync({data:$,path:[],parent:q}).then((J)=>Z(J)?{value:J.value}:{issues:q.common.issues})}async parseAsync($,q){let J=await this.safeParseAsync($,q);if(J.success)return J.data;throw J.error}async safeParseAsync($,q){let J={common:{issues:[],contextualErrorMap:q?.errorMap,async:!0},path:q?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:I($)},G=this._parse({data:$,path:J.path,parent:J}),Q=await(a(G)?G:Promise.resolve(G));return l$(J,Q)}refine($,q){let J=(G)=>{if(typeof q==="string"||typeof q>"u")return{message:q};else if(typeof q==="function")return q(G);else return q};return this._refinement((G,Q)=>{let W=$(G),H=()=>Q.addIssue({code:_.custom,...J(G)});if(typeof Promise<"u"&&W instanceof Promise)return W.then((X)=>{if(!X)return H(),!1;else return!0});if(!W)return H(),!1;else return!0})}refinement($,q){return this._refinement((J,G)=>{if(!$(J))return G.addIssue(typeof q==="function"?q(J,G):q),!1;else return!0})}_refinement($){return new k({schema:this,typeName:V.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 C.create(this,this._def)}nullable(){return x.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return v.create(this)}promise(){return r.create(this,this._def)}or($){return J$.create([this,$],this._def)}and($){return G$.create(this,$,this._def)}transform($){return new k({...E(this._def),schema:this,typeName:V.ZodEffects,effect:{type:"transform",transform:$}})}default($){let q=typeof $==="function"?$:()=>$;return new X$({...E(this._def),innerType:this,defaultValue:q,typeName:V.ZodDefault})}brand(){return new D$({typeName:V.ZodBranded,type:this,...E(this._def)})}catch($){let q=typeof $==="function"?$:()=>$;return new Y$({...E(this._def),innerType:this,catchValue:q,typeName:V.ZodCatch})}describe($){return new this.constructor({...this._def,description:$})}pipe($){return L$.create(this,$)}readonly(){return _$.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}var Mq=/^c[^\s-]{8,}$/i,wq=/^[0-9a-z]+$/,Sq=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Vq=/^[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,Eq=/^[a-z0-9_-]{21}$/i,Lq=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,bq=/^[-+]?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)?)??$/,jq=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Aq="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",f$,Uq=/^(?:(?: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])$/,Rq=/^(?:(?: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])$/,Dq=/^(([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]))$/,Oq=/^(([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])$/,Kq=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Nq=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,u$="((\\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])))",Fq=new RegExp(`^${u$}$`);function n$($){let q="[0-5]\\d";if($.precision)q=`${q}\\.\\d{${$.precision}}`;else if($.precision==null)q=`${q}(\\.\\d+)?`;let J=$.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${q})${J}`}function vq($){return new RegExp(`^${n$($)}$`)}function p$($){let q=`${u$}T${n$($)}`,J=[];if(J.push($.local?"Z?":"Z"),$.offset)J.push("([+-]\\d{2}:?\\d{2})");return q=`${q}(${J.join("|")})`,new RegExp(`^${q}$`)}function Cq($,q){if((q==="v4"||!q)&&Uq.test($))return!0;if((q==="v6"||!q)&&Dq.test($))return!0;return!1}function fq($,q){if(!Lq.test($))return!1;try{let[J]=$.split(".");if(!J)return!1;let G=J.replace(/-/g,"+").replace(/_/g,"/").padEnd(J.length+(4-J.length%4)%4,"="),Q=JSON.parse(atob(G));if(typeof Q!=="object"||Q===null)return!1;if("typ"in Q&&Q?.typ!=="JWT")return!1;if(!Q.alg)return!1;if(q&&Q.alg!==q)return!1;return!0}catch{return!1}}function kq($,q){if((q==="v4"||!q)&&Rq.test($))return!0;if((q==="v6"||!q)&&Oq.test($))return!0;return!1}class F extends L{_parse($){if(this._def.coerce)$.data=String($.data);if(this._getType($)!==z.string){let Q=this._getOrReturnCtx($);return M(Q,{code:_.invalid_type,expected:z.string,received:Q.parsedType}),S}let J=new O,G=void 0;for(let Q of this._def.checks)if(Q.kind==="min"){if($.data.length<Q.value)G=this._getOrReturnCtx($,G),M(G,{code:_.too_small,minimum:Q.value,type:"string",inclusive:!0,exact:!1,message:Q.message}),J.dirty()}else if(Q.kind==="max"){if($.data.length>Q.value)G=this._getOrReturnCtx($,G),M(G,{code:_.too_big,maximum:Q.value,type:"string",inclusive:!0,exact:!1,message:Q.message}),J.dirty()}else if(Q.kind==="length"){let W=$.data.length>Q.value,H=$.data.length<Q.value;if(W||H){if(G=this._getOrReturnCtx($,G),W)M(G,{code:_.too_big,maximum:Q.value,type:"string",inclusive:!0,exact:!0,message:Q.message});else if(H)M(G,{code:_.too_small,minimum:Q.value,type:"string",inclusive:!0,exact:!0,message:Q.message});J.dirty()}}else if(Q.kind==="email"){if(!jq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"email",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="emoji"){if(!f$)f$=new RegExp(Aq,"u");if(!f$.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"emoji",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="uuid"){if(!Vq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"uuid",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="nanoid"){if(!Eq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"nanoid",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="cuid"){if(!Mq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"cuid",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="cuid2"){if(!wq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"cuid2",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="ulid"){if(!Sq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"ulid",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="url")try{new URL($.data)}catch{G=this._getOrReturnCtx($,G),M(G,{validation:"url",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="regex"){if(Q.regex.lastIndex=0,!Q.regex.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"regex",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="trim")$.data=$.data.trim();else if(Q.kind==="includes"){if(!$.data.includes(Q.value,Q.position))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:{includes:Q.value,position:Q.position},message:Q.message}),J.dirty()}else if(Q.kind==="toLowerCase")$.data=$.data.toLowerCase();else if(Q.kind==="toUpperCase")$.data=$.data.toUpperCase();else if(Q.kind==="startsWith"){if(!$.data.startsWith(Q.value))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:{startsWith:Q.value},message:Q.message}),J.dirty()}else if(Q.kind==="endsWith"){if(!$.data.endsWith(Q.value))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:{endsWith:Q.value},message:Q.message}),J.dirty()}else if(Q.kind==="datetime"){if(!p$(Q).test($.data))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:"datetime",message:Q.message}),J.dirty()}else if(Q.kind==="date"){if(!Fq.test($.data))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:"date",message:Q.message}),J.dirty()}else if(Q.kind==="time"){if(!vq(Q).test($.data))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:"time",message:Q.message}),J.dirty()}else if(Q.kind==="duration"){if(!bq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"duration",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="ip"){if(!Cq($.data,Q.version))G=this._getOrReturnCtx($,G),M(G,{validation:"ip",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="jwt"){if(!fq($.data,Q.alg))G=this._getOrReturnCtx($,G),M(G,{validation:"jwt",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="cidr"){if(!kq($.data,Q.version))G=this._getOrReturnCtx($,G),M(G,{validation:"cidr",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="base64"){if(!Kq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"base64",code:_.invalid_string,message:Q.message}),J.dirty()}else if(Q.kind==="base64url"){if(!Nq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"base64url",code:_.invalid_string,message:Q.message}),J.dirty()}else b.assertNever(Q);return{status:J.value,value:$.data}}_regex($,q,J){return this.refinement((G)=>$.test(G),{validation:q,code:_.invalid_string,...w.errToObj(J)})}_addCheck($){return new F({...this._def,checks:[...this._def.checks,$]})}email($){return this._addCheck({kind:"email",...w.errToObj($)})}url($){return this._addCheck({kind:"url",...w.errToObj($)})}emoji($){return this._addCheck({kind:"emoji",...w.errToObj($)})}uuid($){return this._addCheck({kind:"uuid",...w.errToObj($)})}nanoid($){return this._addCheck({kind:"nanoid",...w.errToObj($)})}cuid($){return this._addCheck({kind:"cuid",...w.errToObj($)})}cuid2($){return this._addCheck({kind:"cuid2",...w.errToObj($)})}ulid($){return this._addCheck({kind:"ulid",...w.errToObj($)})}base64($){return this._addCheck({kind:"base64",...w.errToObj($)})}base64url($){return this._addCheck({kind:"base64url",...w.errToObj($)})}jwt($){return this._addCheck({kind:"jwt",...w.errToObj($)})}ip($){return this._addCheck({kind:"ip",...w.errToObj($)})}cidr($){return this._addCheck({kind:"cidr",...w.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,...w.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,...w.errToObj($?.message)})}duration($){return this._addCheck({kind:"duration",...w.errToObj($)})}regex($,q){return this._addCheck({kind:"regex",regex:$,...w.errToObj(q)})}includes($,q){return this._addCheck({kind:"includes",value:$,position:q?.position,...w.errToObj(q?.message)})}startsWith($,q){return this._addCheck({kind:"startsWith",value:$,...w.errToObj(q)})}endsWith($,q){return this._addCheck({kind:"endsWith",value:$,...w.errToObj(q)})}min($,q){return this._addCheck({kind:"min",value:$,...w.errToObj(q)})}max($,q){return this._addCheck({kind:"max",value:$,...w.errToObj(q)})}length($,q){return this._addCheck({kind:"length",value:$,...w.errToObj(q)})}nonempty($){return this.min(1,w.errToObj($))}trim(){return new F({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new F({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new F({...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 $}}F.create=($)=>{return new F({checks:[],typeName:V.ZodString,coerce:$?.coerce??!1,...E($)})};function Iq($,q){let J=($.toString().split(".")[1]||"").length,G=(q.toString().split(".")[1]||"").length,Q=J>G?J:G,W=Number.parseInt($.toFixed(Q).replace(".","")),H=Number.parseInt(q.toFixed(Q).replace(".",""));return W%H/10**Q}class l extends L{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($)!==z.number){let Q=this._getOrReturnCtx($);return M(Q,{code:_.invalid_type,expected:z.number,received:Q.parsedType}),S}let J=void 0,G=new O;for(let Q of this._def.checks)if(Q.kind==="int"){if(!b.isInteger($.data))J=this._getOrReturnCtx($,J),M(J,{code:_.invalid_type,expected:"integer",received:"float",message:Q.message}),G.dirty()}else if(Q.kind==="min"){if(Q.inclusive?$.data<Q.value:$.data<=Q.value)J=this._getOrReturnCtx($,J),M(J,{code:_.too_small,minimum:Q.value,type:"number",inclusive:Q.inclusive,exact:!1,message:Q.message}),G.dirty()}else if(Q.kind==="max"){if(Q.inclusive?$.data>Q.value:$.data>=Q.value)J=this._getOrReturnCtx($,J),M(J,{code:_.too_big,maximum:Q.value,type:"number",inclusive:Q.inclusive,exact:!1,message:Q.message}),G.dirty()}else if(Q.kind==="multipleOf"){if(Iq($.data,Q.value)!==0)J=this._getOrReturnCtx($,J),M(J,{code:_.not_multiple_of,multipleOf:Q.value,message:Q.message}),G.dirty()}else if(Q.kind==="finite"){if(!Number.isFinite($.data))J=this._getOrReturnCtx($,J),M(J,{code:_.not_finite,message:Q.message}),G.dirty()}else b.assertNever(Q);return{status:G.value,value:$.data}}gte($,q){return this.setLimit("min",$,!0,w.toString(q))}gt($,q){return this.setLimit("min",$,!1,w.toString(q))}lte($,q){return this.setLimit("max",$,!0,w.toString(q))}lt($,q){return this.setLimit("max",$,!1,w.toString(q))}setLimit($,q,J,G){return new l({...this._def,checks:[...this._def.checks,{kind:$,value:q,inclusive:J,message:w.toString(G)}]})}_addCheck($){return new l({...this._def,checks:[...this._def.checks,$]})}int($){return this._addCheck({kind:"int",message:w.toString($)})}positive($){return this._addCheck({kind:"min",value:0,inclusive:!1,message:w.toString($)})}negative($){return this._addCheck({kind:"max",value:0,inclusive:!1,message:w.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:0,inclusive:!0,message:w.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:0,inclusive:!0,message:w.toString($)})}multipleOf($,q){return this._addCheck({kind:"multipleOf",value:$,message:w.toString(q)})}finite($){return this._addCheck({kind:"finite",message:w.toString($)})}safe($){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:w.toString($)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:w.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 J of this._def.checks)if(J.kind==="finite"||J.kind==="int"||J.kind==="multipleOf")return!0;else if(J.kind==="min"){if(q===null||J.value>q)q=J.value}else if(J.kind==="max"){if($===null||J.value<$)$=J.value}return Number.isFinite(q)&&Number.isFinite($)}}l.create=($)=>{return new l({checks:[],typeName:V.ZodNumber,coerce:$?.coerce||!1,...E($)})};class c extends L{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($)!==z.bigint)return this._getInvalidInput($);let J=void 0,G=new O;for(let Q of this._def.checks)if(Q.kind==="min"){if(Q.inclusive?$.data<Q.value:$.data<=Q.value)J=this._getOrReturnCtx($,J),M(J,{code:_.too_small,type:"bigint",minimum:Q.value,inclusive:Q.inclusive,message:Q.message}),G.dirty()}else if(Q.kind==="max"){if(Q.inclusive?$.data>Q.value:$.data>=Q.value)J=this._getOrReturnCtx($,J),M(J,{code:_.too_big,type:"bigint",maximum:Q.value,inclusive:Q.inclusive,message:Q.message}),G.dirty()}else if(Q.kind==="multipleOf"){if($.data%Q.value!==BigInt(0))J=this._getOrReturnCtx($,J),M(J,{code:_.not_multiple_of,multipleOf:Q.value,message:Q.message}),G.dirty()}else b.assertNever(Q);return{status:G.value,value:$.data}}_getInvalidInput($){let q=this._getOrReturnCtx($);return M(q,{code:_.invalid_type,expected:z.bigint,received:q.parsedType}),S}gte($,q){return this.setLimit("min",$,!0,w.toString(q))}gt($,q){return this.setLimit("min",$,!1,w.toString(q))}lte($,q){return this.setLimit("max",$,!0,w.toString(q))}lt($,q){return this.setLimit("max",$,!1,w.toString(q))}setLimit($,q,J,G){return new c({...this._def,checks:[...this._def.checks,{kind:$,value:q,inclusive:J,message:w.toString(G)}]})}_addCheck($){return new c({...this._def,checks:[...this._def.checks,$]})}positive($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:w.toString($)})}negative($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:w.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:w.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:w.toString($)})}multipleOf($,q){return this._addCheck({kind:"multipleOf",value:$,message:w.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 $}}c.create=($)=>{return new c({checks:[],typeName:V.ZodBigInt,coerce:$?.coerce??!1,...E($)})};class e extends L{_parse($){if(this._def.coerce)$.data=Boolean($.data);if(this._getType($)!==z.boolean){let J=this._getOrReturnCtx($);return M(J,{code:_.invalid_type,expected:z.boolean,received:J.parsedType}),S}return K($.data)}}e.create=($)=>{return new e({typeName:V.ZodBoolean,coerce:$?.coerce||!1,...E($)})};class p extends L{_parse($){if(this._def.coerce)$.data=new Date($.data);if(this._getType($)!==z.date){let Q=this._getOrReturnCtx($);return M(Q,{code:_.invalid_type,expected:z.date,received:Q.parsedType}),S}if(Number.isNaN($.data.getTime())){let Q=this._getOrReturnCtx($);return M(Q,{code:_.invalid_date}),S}let J=new O,G=void 0;for(let Q of this._def.checks)if(Q.kind==="min"){if($.data.getTime()<Q.value)G=this._getOrReturnCtx($,G),M(G,{code:_.too_small,message:Q.message,inclusive:!0,exact:!1,minimum:Q.value,type:"date"}),J.dirty()}else if(Q.kind==="max"){if($.data.getTime()>Q.value)G=this._getOrReturnCtx($,G),M(G,{code:_.too_big,message:Q.message,inclusive:!0,exact:!1,maximum:Q.value,type:"date"}),J.dirty()}else b.assertNever(Q);return{status:J.value,value:new Date($.data.getTime())}}_addCheck($){return new p({...this._def,checks:[...this._def.checks,$]})}min($,q){return this._addCheck({kind:"min",value:$.getTime(),message:w.toString(q)})}max($,q){return this._addCheck({kind:"max",value:$.getTime(),message:w.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}}p.create=($)=>{return new p({checks:[],coerce:$?.coerce||!1,typeName:V.ZodDate,...E($)})};class M$ extends L{_parse($){if(this._getType($)!==z.symbol){let J=this._getOrReturnCtx($);return M(J,{code:_.invalid_type,expected:z.symbol,received:J.parsedType}),S}return K($.data)}}M$.create=($)=>{return new M$({typeName:V.ZodSymbol,...E($)})};class $$ extends L{_parse($){if(this._getType($)!==z.undefined){let J=this._getOrReturnCtx($);return M(J,{code:_.invalid_type,expected:z.undefined,received:J.parsedType}),S}return K($.data)}}$$.create=($)=>{return new $$({typeName:V.ZodUndefined,...E($)})};class q$ extends L{_parse($){if(this._getType($)!==z.null){let J=this._getOrReturnCtx($);return M(J,{code:_.invalid_type,expected:z.null,received:J.parsedType}),S}return K($.data)}}q$.create=($)=>{return new q$({typeName:V.ZodNull,...E($)})};class d extends L{constructor(){super(...arguments);this._any=!0}_parse($){return K($.data)}}d.create=($)=>{return new d({typeName:V.ZodAny,...E($)})};class m extends L{constructor(){super(...arguments);this._unknown=!0}_parse($){return K($.data)}}m.create=($)=>{return new m({typeName:V.ZodUnknown,...E($)})};class P extends L{_parse($){let q=this._getOrReturnCtx($);return M(q,{code:_.invalid_type,expected:z.never,received:q.parsedType}),S}}P.create=($)=>{return new P({typeName:V.ZodNever,...E($)})};class w$ extends L{_parse($){if(this._getType($)!==z.undefined){let J=this._getOrReturnCtx($);return M(J,{code:_.invalid_type,expected:z.void,received:J.parsedType}),S}return K($.data)}}w$.create=($)=>{return new w$({typeName:V.ZodVoid,...E($)})};class v extends L{_parse($){let{ctx:q,status:J}=this._processInputParams($),G=this._def;if(q.parsedType!==z.array)return M(q,{code:_.invalid_type,expected:z.array,received:q.parsedType}),S;if(G.exactLength!==null){let W=q.data.length>G.exactLength.value,H=q.data.length<G.exactLength.value;if(W||H)M(q,{code:W?_.too_big:_.too_small,minimum:H?G.exactLength.value:void 0,maximum:W?G.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:G.exactLength.message}),J.dirty()}if(G.minLength!==null){if(q.data.length<G.minLength.value)M(q,{code:_.too_small,minimum:G.minLength.value,type:"array",inclusive:!0,exact:!1,message:G.minLength.message}),J.dirty()}if(G.maxLength!==null){if(q.data.length>G.maxLength.value)M(q,{code:_.too_big,maximum:G.maxLength.value,type:"array",inclusive:!0,exact:!1,message:G.maxLength.message}),J.dirty()}if(q.common.async)return Promise.all([...q.data].map((W,H)=>{return G.type._parseAsync(new f(q,W,q.path,H))})).then((W)=>{return O.mergeArray(J,W)});let Q=[...q.data].map((W,H)=>{return G.type._parseSync(new f(q,W,q.path,H))});return O.mergeArray(J,Q)}get element(){return this._def.type}min($,q){return new v({...this._def,minLength:{value:$,message:w.toString(q)}})}max($,q){return new v({...this._def,maxLength:{value:$,message:w.toString(q)}})}length($,q){return new v({...this._def,exactLength:{value:$,message:w.toString(q)}})}nonempty($){return this.min(1,$)}}v.create=($,q)=>{return new v({type:$,minLength:null,maxLength:null,exactLength:null,typeName:V.ZodArray,...E(q)})};function s($){if($ instanceof A){let q={};for(let J in $.shape){let G=$.shape[J];q[J]=C.create(s(G))}return new A({...$._def,shape:()=>q})}else if($ instanceof v)return new v({...$._def,type:s($.element)});else if($ instanceof C)return C.create(s($.unwrap()));else if($ instanceof x)return x.create(s($.unwrap()));else if($ instanceof T)return T.create($.items.map((q)=>s(q)));else return $}class A extends L{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($)!==z.object){let Y=this._getOrReturnCtx($);return M(Y,{code:_.invalid_type,expected:z.object,received:Y.parsedType}),S}let{status:J,ctx:G}=this._processInputParams($),{shape:Q,keys:W}=this._getCached(),H=[];if(!(this._def.catchall instanceof P&&this._def.unknownKeys==="strip")){for(let Y in G.data)if(!W.includes(Y))H.push(Y)}let X=[];for(let Y of W){let B=Q[Y],j=G.data[Y];X.push({key:{status:"valid",value:Y},value:B._parse(new f(G,j,G.path,Y)),alwaysSet:Y in G.data})}if(this._def.catchall instanceof P){let Y=this._def.unknownKeys;if(Y==="passthrough")for(let B of H)X.push({key:{status:"valid",value:B},value:{status:"valid",value:G.data[B]}});else if(Y==="strict"){if(H.length>0)M(G,{code:_.unrecognized_keys,keys:H}),J.dirty()}else if(Y==="strip");else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let Y=this._def.catchall;for(let B of H){let j=G.data[B];X.push({key:{status:"valid",value:B},value:Y._parse(new f(G,j,G.path,B)),alwaysSet:B in G.data})}}if(G.common.async)return Promise.resolve().then(async()=>{let Y=[];for(let B of X){let j=await B.key,U=await B.value;Y.push({key:j,value:U,alwaysSet:B.alwaysSet})}return Y}).then((Y)=>{return O.mergeObjectSync(J,Y)});else return O.mergeObjectSync(J,X)}get shape(){return this._def.shape()}strict($){return w.errToObj,new A({...this._def,unknownKeys:"strict",...$!==void 0?{errorMap:(q,J)=>{let G=this._def.errorMap?.(q,J).message??J.defaultError;if(q.code==="unrecognized_keys")return{message:w.errToObj($).message??G};return{message:G}}}:{}})}strip(){return new A({...this._def,unknownKeys:"strip"})}passthrough(){return new A({...this._def,unknownKeys:"passthrough"})}extend($){return new A({...this._def,shape:()=>({...this._def.shape(),...$})})}merge($){return new A({unknownKeys:$._def.unknownKeys,catchall:$._def.catchall,shape:()=>({...this._def.shape(),...$._def.shape()}),typeName:V.ZodObject})}setKey($,q){return this.augment({[$]:q})}catchall($){return new A({...this._def,catchall:$})}pick($){let q={};for(let J of b.objectKeys($))if($[J]&&this.shape[J])q[J]=this.shape[J];return new A({...this._def,shape:()=>q})}omit($){let q={};for(let J of b.objectKeys(this.shape))if(!$[J])q[J]=this.shape[J];return new A({...this._def,shape:()=>q})}deepPartial(){return s(this)}partial($){let q={};for(let J of b.objectKeys(this.shape)){let G=this.shape[J];if($&&!$[J])q[J]=G;else q[J]=G.optional()}return new A({...this._def,shape:()=>q})}required($){let q={};for(let J of b.objectKeys(this.shape))if($&&!$[J])q[J]=this.shape[J];else{let Q=this.shape[J];while(Q instanceof C)Q=Q._def.innerType;q[J]=Q}return new A({...this._def,shape:()=>q})}keyof(){return d$(b.objectKeys(this.shape))}}A.create=($,q)=>{return new A({shape:()=>$,unknownKeys:"strip",catchall:P.create(),typeName:V.ZodObject,...E(q)})};A.strictCreate=($,q)=>{return new A({shape:()=>$,unknownKeys:"strict",catchall:P.create(),typeName:V.ZodObject,...E(q)})};A.lazycreate=($,q)=>{return new A({shape:$,unknownKeys:"strip",catchall:P.create(),typeName:V.ZodObject,...E(q)})};class J$ extends L{_parse($){let{ctx:q}=this._processInputParams($),J=this._def.options;function G(Q){for(let H of Q)if(H.result.status==="valid")return H.result;for(let H of Q)if(H.result.status==="dirty")return q.common.issues.push(...H.ctx.common.issues),H.result;let W=Q.map((H)=>new N(H.ctx.common.issues));return M(q,{code:_.invalid_union,unionErrors:W}),S}if(q.common.async)return Promise.all(J.map(async(Q)=>{let W={...q,common:{...q.common,issues:[]},parent:null};return{result:await Q._parseAsync({data:q.data,path:q.path,parent:W}),ctx:W}})).then(G);else{let Q=void 0,W=[];for(let X of J){let Y={...q,common:{...q.common,issues:[]},parent:null},B=X._parseSync({data:q.data,path:q.path,parent:Y});if(B.status==="valid")return B;else if(B.status==="dirty"&&!Q)Q={result:B,ctx:Y};if(Y.common.issues.length)W.push(Y.common.issues)}if(Q)return q.common.issues.push(...Q.ctx.common.issues),Q.result;let H=W.map((X)=>new N(X));return M(q,{code:_.invalid_union,unionErrors:H}),S}}get options(){return this._def.options}}J$.create=($,q)=>{return new J$({options:$,typeName:V.ZodUnion,...E(q)})};var g=($)=>{if($ instanceof Q$)return g($.schema);else if($ instanceof k)return g($.innerType());else if($ instanceof H$)return[$.value];else if($ instanceof u)return $.options;else if($ instanceof W$)return b.objectValues($.enum);else if($ instanceof X$)return g($._def.innerType);else if($ instanceof $$)return[void 0];else if($ instanceof q$)return[null];else if($ instanceof C)return[void 0,...g($.unwrap())];else if($ instanceof x)return[null,...g($.unwrap())];else if($ instanceof D$)return g($.unwrap());else if($ instanceof _$)return g($.unwrap());else if($ instanceof Y$)return g($._def.innerType);else return[]};class R$ extends L{_parse($){let{ctx:q}=this._processInputParams($);if(q.parsedType!==z.object)return M(q,{code:_.invalid_type,expected:z.object,received:q.parsedType}),S;let J=this.discriminator,G=q.data[J],Q=this.optionsMap.get(G);if(!Q)return M(q,{code:_.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[J]}),S;if(q.common.async)return Q._parseAsync({data:q.data,path:q.path,parent:q});else return Q._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,J){let G=new Map;for(let Q of q){let W=g(Q.shape[$]);if(!W.length)throw Error(`A discriminator value for key \`${$}\` could not be extracted from all schema options`);for(let H of W){if(G.has(H))throw Error(`Discriminator property ${String($)} has duplicate value ${String(H)}`);G.set(H,Q)}}return new R$({typeName:V.ZodDiscriminatedUnion,discriminator:$,options:q,optionsMap:G,...E(J)})}}function k$($,q){let J=I($),G=I(q);if($===q)return{valid:!0,data:$};else if(J===z.object&&G===z.object){let Q=b.objectKeys(q),W=b.objectKeys($).filter((X)=>Q.indexOf(X)!==-1),H={...$,...q};for(let X of W){let Y=k$($[X],q[X]);if(!Y.valid)return{valid:!1};H[X]=Y.data}return{valid:!0,data:H}}else if(J===z.array&&G===z.array){if($.length!==q.length)return{valid:!1};let Q=[];for(let W=0;W<$.length;W++){let H=$[W],X=q[W],Y=k$(H,X);if(!Y.valid)return{valid:!1};Q.push(Y.data)}return{valid:!0,data:Q}}else if(J===z.date&&G===z.date&&+$===+q)return{valid:!0,data:$};else return{valid:!1}}class G$ extends L{_parse($){let{status:q,ctx:J}=this._processInputParams($),G=(Q,W)=>{if(A$(Q)||A$(W))return S;let H=k$(Q.value,W.value);if(!H.valid)return M(J,{code:_.invalid_intersection_types}),S;if(U$(Q)||U$(W))q.dirty();return{status:q.value,value:H.data}};if(J.common.async)return Promise.all([this._def.left._parseAsync({data:J.data,path:J.path,parent:J}),this._def.right._parseAsync({data:J.data,path:J.path,parent:J})]).then(([Q,W])=>G(Q,W));else return G(this._def.left._parseSync({data:J.data,path:J.path,parent:J}),this._def.right._parseSync({data:J.data,path:J.path,parent:J}))}}G$.create=($,q,J)=>{return new G$({left:$,right:q,typeName:V.ZodIntersection,...E(J)})};class T extends L{_parse($){let{status:q,ctx:J}=this._processInputParams($);if(J.parsedType!==z.array)return M(J,{code:_.invalid_type,expected:z.array,received:J.parsedType}),S;if(J.data.length<this._def.items.length)return M(J,{code:_.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),S;if(!this._def.rest&&J.data.length>this._def.items.length)M(J,{code:_.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),q.dirty();let Q=[...J.data].map((W,H)=>{let X=this._def.items[H]||this._def.rest;if(!X)return null;return X._parse(new f(J,W,J.path,H))}).filter((W)=>!!W);if(J.common.async)return Promise.all(Q).then((W)=>{return O.mergeArray(q,W)});else return O.mergeArray(q,Q)}get items(){return this._def.items}rest($){return new T({...this._def,rest:$})}}T.create=($,q)=>{if(!Array.isArray($))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new T({items:$,typeName:V.ZodTuple,rest:null,...E(q)})};class S$ extends L{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:q,ctx:J}=this._processInputParams($);if(J.parsedType!==z.object)return M(J,{code:_.invalid_type,expected:z.object,received:J.parsedType}),S;let G=[],Q=this._def.keyType,W=this._def.valueType;for(let H in J.data)G.push({key:Q._parse(new f(J,H,J.path,H)),value:W._parse(new f(J,J.data[H],J.path,H)),alwaysSet:H in J.data});if(J.common.async)return O.mergeObjectAsync(q,G);else return O.mergeObjectSync(q,G)}get element(){return this._def.valueType}static create($,q,J){if(q instanceof L)return new S$({keyType:$,valueType:q,typeName:V.ZodRecord,...E(J)});return new S$({keyType:F.create(),valueType:$,typeName:V.ZodRecord,...E(q)})}}class V$ extends L{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:q,ctx:J}=this._processInputParams($);if(J.parsedType!==z.map)return M(J,{code:_.invalid_type,expected:z.map,received:J.parsedType}),S;let G=this._def.keyType,Q=this._def.valueType,W=[...J.data.entries()].map(([H,X],Y)=>{return{key:G._parse(new f(J,H,J.path,[Y,"key"])),value:Q._parse(new f(J,X,J.path,[Y,"value"]))}});if(J.common.async){let H=new Map;return Promise.resolve().then(async()=>{for(let X of W){let Y=await X.key,B=await X.value;if(Y.status==="aborted"||B.status==="aborted")return S;if(Y.status==="dirty"||B.status==="dirty")q.dirty();H.set(Y.value,B.value)}return{status:q.value,value:H}})}else{let H=new Map;for(let X of W){let{key:Y,value:B}=X;if(Y.status==="aborted"||B.status==="aborted")return S;if(Y.status==="dirty"||B.status==="dirty")q.dirty();H.set(Y.value,B.value)}return{status:q.value,value:H}}}}V$.create=($,q,J)=>{return new V$({valueType:q,keyType:$,typeName:V.ZodMap,...E(J)})};class i extends L{_parse($){let{status:q,ctx:J}=this._processInputParams($);if(J.parsedType!==z.set)return M(J,{code:_.invalid_type,expected:z.set,received:J.parsedType}),S;let G=this._def;if(G.minSize!==null){if(J.data.size<G.minSize.value)M(J,{code:_.too_small,minimum:G.minSize.value,type:"set",inclusive:!0,exact:!1,message:G.minSize.message}),q.dirty()}if(G.maxSize!==null){if(J.data.size>G.maxSize.value)M(J,{code:_.too_big,maximum:G.maxSize.value,type:"set",inclusive:!0,exact:!1,message:G.maxSize.message}),q.dirty()}let Q=this._def.valueType;function W(X){let Y=new Set;for(let B of X){if(B.status==="aborted")return S;if(B.status==="dirty")q.dirty();Y.add(B.value)}return{status:q.value,value:Y}}let H=[...J.data.values()].map((X,Y)=>Q._parse(new f(J,X,J.path,Y)));if(J.common.async)return Promise.all(H).then((X)=>W(X));else return W(H)}min($,q){return new i({...this._def,minSize:{value:$,message:w.toString(q)}})}max($,q){return new i({...this._def,maxSize:{value:$,message:w.toString(q)}})}size($,q){return this.min($,q).max($,q)}nonempty($){return this.min(1,$)}}i.create=($,q)=>{return new i({valueType:$,minSize:null,maxSize:null,typeName:V.ZodSet,...E(q)})};class t extends L{constructor(){super(...arguments);this.validate=this.implement}_parse($){let{ctx:q}=this._processInputParams($);if(q.parsedType!==z.function)return M(q,{code:_.invalid_type,expected:z.function,received:q.parsedType}),S;function J(H,X){return z$({data:H,path:q.path,errorMaps:[q.common.contextualErrorMap,q.schemaErrorMap,o(),h].filter((Y)=>!!Y),issueData:{code:_.invalid_arguments,argumentsError:X}})}function G(H,X){return z$({data:H,path:q.path,errorMaps:[q.common.contextualErrorMap,q.schemaErrorMap,o(),h].filter((Y)=>!!Y),issueData:{code:_.invalid_return_type,returnTypeError:X}})}let Q={errorMap:q.common.contextualErrorMap},W=q.data;if(this._def.returns instanceof r){let H=this;return K(async function(...X){let Y=new N([]),B=await H._def.args.parseAsync(X,Q).catch((R)=>{throw Y.addIssue(J(X,R)),Y}),j=await Reflect.apply(W,this,B);return await H._def.returns._def.type.parseAsync(j,Q).catch((R)=>{throw Y.addIssue(G(j,R)),Y})})}else{let H=this;return K(function(...X){let Y=H._def.args.safeParse(X,Q);if(!Y.success)throw new N([J(X,Y.error)]);let B=Reflect.apply(W,this,Y.data),j=H._def.returns.safeParse(B,Q);if(!j.success)throw new N([G(B,j.error)]);return j.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...$){return new t({...this._def,args:T.create($).rest(m.create())})}returns($){return new t({...this._def,returns:$})}implement($){return this.parse($)}strictImplement($){return this.parse($)}static create($,q,J){return new t({args:$?$:T.create([]).rest(m.create()),returns:q||m.create(),typeName:V.ZodFunction,...E(J)})}}class Q$ extends L{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})}}Q$.create=($,q)=>{return new Q$({getter:$,typeName:V.ZodLazy,...E(q)})};class H$ extends L{_parse($){if($.data!==this._def.value){let q=this._getOrReturnCtx($);return M(q,{received:q.data,code:_.invalid_literal,expected:this._def.value}),S}return{status:"valid",value:$.data}}get value(){return this._def.value}}H$.create=($,q)=>{return new H$({value:$,typeName:V.ZodLiteral,...E(q)})};function d$($,q){return new u({values:$,typeName:V.ZodEnum,...E(q)})}class u extends L{_parse($){if(typeof $.data!=="string"){let q=this._getOrReturnCtx($),J=this._def.values;return M(q,{expected:b.joinValues(J),received:q.parsedType,code:_.invalid_type}),S}if(!this._cache)this._cache=new Set(this._def.values);if(!this._cache.has($.data)){let q=this._getOrReturnCtx($),J=this._def.values;return M(q,{received:q.data,code:_.invalid_enum_value,options:J}),S}return K($.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 u.create($,{...this._def,...q})}exclude($,q=this._def){return u.create(this.options.filter((J)=>!$.includes(J)),{...this._def,...q})}}u.create=d$;class W$ extends L{_parse($){let q=b.getValidEnumValues(this._def.values),J=this._getOrReturnCtx($);if(J.parsedType!==z.string&&J.parsedType!==z.number){let G=b.objectValues(q);return M(J,{expected:b.joinValues(G),received:J.parsedType,code:_.invalid_type}),S}if(!this._cache)this._cache=new Set(b.getValidEnumValues(this._def.values));if(!this._cache.has($.data)){let G=b.objectValues(q);return M(J,{received:J.data,code:_.invalid_enum_value,options:G}),S}return K($.data)}get enum(){return this._def.values}}W$.create=($,q)=>{return new W$({values:$,typeName:V.ZodNativeEnum,...E(q)})};class r extends L{unwrap(){return this._def.type}_parse($){let{ctx:q}=this._processInputParams($);if(q.parsedType!==z.promise&&q.common.async===!1)return M(q,{code:_.invalid_type,expected:z.promise,received:q.parsedType}),S;let J=q.parsedType===z.promise?q.data:Promise.resolve(q.data);return K(J.then((G)=>{return this._def.type.parseAsync(G,{path:q.path,errorMap:q.common.contextualErrorMap})}))}}r.create=($,q)=>{return new r({type:$,typeName:V.ZodPromise,...E(q)})};class k extends L{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===V.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse($){let{status:q,ctx:J}=this._processInputParams($),G=this._def.effect||null,Q={addIssue:(W)=>{if(M(J,W),W.fatal)q.abort();else q.dirty()},get path(){return J.path}};if(Q.addIssue=Q.addIssue.bind(Q),G.type==="preprocess"){let W=G.transform(J.data,Q);if(J.common.async)return Promise.resolve(W).then(async(H)=>{if(q.value==="aborted")return S;let X=await this._def.schema._parseAsync({data:H,path:J.path,parent:J});if(X.status==="aborted")return S;if(X.status==="dirty")return n(X.value);if(q.value==="dirty")return n(X.value);return X});else{if(q.value==="aborted")return S;let H=this._def.schema._parseSync({data:W,path:J.path,parent:J});if(H.status==="aborted")return S;if(H.status==="dirty")return n(H.value);if(q.value==="dirty")return n(H.value);return H}}if(G.type==="refinement"){let W=(H)=>{let X=G.refinement(H,Q);if(J.common.async)return Promise.resolve(X);if(X instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return H};if(J.common.async===!1){let H=this._def.schema._parseSync({data:J.data,path:J.path,parent:J});if(H.status==="aborted")return S;if(H.status==="dirty")q.dirty();return W(H.value),{status:q.value,value:H.value}}else return this._def.schema._parseAsync({data:J.data,path:J.path,parent:J}).then((H)=>{if(H.status==="aborted")return S;if(H.status==="dirty")q.dirty();return W(H.value).then(()=>{return{status:q.value,value:H.value}})})}if(G.type==="transform")if(J.common.async===!1){let W=this._def.schema._parseSync({data:J.data,path:J.path,parent:J});if(!Z(W))return S;let H=G.transform(W.value,Q);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:J.data,path:J.path,parent:J}).then((W)=>{if(!Z(W))return S;return Promise.resolve(G.transform(W.value,Q)).then((H)=>({status:q.value,value:H}))});b.assertNever(G)}}k.create=($,q,J)=>{return new k({schema:$,typeName:V.ZodEffects,effect:q,...E(J)})};k.createWithPreprocess=($,q,J)=>{return new k({schema:q,effect:{type:"preprocess",transform:$},typeName:V.ZodEffects,...E(J)})};class C extends L{_parse($){if(this._getType($)===z.undefined)return K(void 0);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}C.create=($,q)=>{return new C({innerType:$,typeName:V.ZodOptional,...E(q)})};class x extends L{_parse($){if(this._getType($)===z.null)return K(null);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}x.create=($,q)=>{return new x({innerType:$,typeName:V.ZodNullable,...E(q)})};class X$ extends L{_parse($){let{ctx:q}=this._processInputParams($),J=q.data;if(q.parsedType===z.undefined)J=this._def.defaultValue();return this._def.innerType._parse({data:J,path:q.path,parent:q})}removeDefault(){return this._def.innerType}}X$.create=($,q)=>{return new X$({innerType:$,typeName:V.ZodDefault,defaultValue:typeof q.default==="function"?q.default:()=>q.default,...E(q)})};class Y$ extends L{_parse($){let{ctx:q}=this._processInputParams($),J={...q,common:{...q.common,issues:[]}},G=this._def.innerType._parse({data:J.data,path:J.path,parent:{...J}});if(a(G))return G.then((Q)=>{return{status:"valid",value:Q.status==="valid"?Q.value:this._def.catchValue({get error(){return new N(J.common.issues)},input:J.data})}});else return{status:"valid",value:G.status==="valid"?G.value:this._def.catchValue({get error(){return new N(J.common.issues)},input:J.data})}}removeCatch(){return this._def.innerType}}Y$.create=($,q)=>{return new Y$({innerType:$,typeName:V.ZodCatch,catchValue:typeof q.catch==="function"?q.catch:()=>q.catch,...E(q)})};class E$ extends L{_parse($){if(this._getType($)!==z.nan){let J=this._getOrReturnCtx($);return M(J,{code:_.invalid_type,expected:z.nan,received:J.parsedType}),S}return{status:"valid",value:$.data}}}E$.create=($)=>{return new E$({typeName:V.ZodNaN,...E($)})};var Pq=Symbol("zod_brand");class D$ extends L{_parse($){let{ctx:q}=this._processInputParams($),J=q.data;return this._def.type._parse({data:J,path:q.path,parent:q})}unwrap(){return this._def.type}}class L$ extends L{_parse($){let{status:q,ctx:J}=this._processInputParams($);if(J.common.async)return(async()=>{let Q=await this._def.in._parseAsync({data:J.data,path:J.path,parent:J});if(Q.status==="aborted")return S;if(Q.status==="dirty")return q.dirty(),n(Q.value);else return this._def.out._parseAsync({data:Q.value,path:J.path,parent:J})})();else{let G=this._def.in._parseSync({data:J.data,path:J.path,parent:J});if(G.status==="aborted")return S;if(G.status==="dirty")return q.dirty(),{status:"dirty",value:G.value};else return this._def.out._parseSync({data:G.value,path:J.path,parent:J})}}static create($,q){return new L$({in:$,out:q,typeName:V.ZodPipeline})}}class _$ extends L{_parse($){let q=this._def.innerType._parse($),J=(G)=>{if(Z(G))G.value=Object.freeze(G.value);return G};return a(q)?q.then((G)=>J(G)):J(q)}unwrap(){return this._def.innerType}}_$.create=($,q)=>{return new _$({innerType:$,typeName:V.ZodReadonly,...E(q)})};function c$($,q){let J=typeof $==="function"?$(q):typeof $==="string"?{message:$}:$;return typeof J==="string"?{message:J}:J}function i$($,q={},J){if($)return d.create().superRefine((G,Q)=>{let W=$(G);if(W instanceof Promise)return W.then((H)=>{if(!H){let X=c$(q,G),Y=X.fatal??J??!0;Q.addIssue({code:"custom",...X,fatal:Y})}});if(!W){let H=c$(q,G),X=H.fatal??J??!0;Q.addIssue({code:"custom",...H,fatal:X})}return});return d.create()}var Tq={object:A.lazycreate},V;(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"})(V||(V={}));var hq=($,q={message:`Input not instance of ${$.name}`})=>i$((J)=>J instanceof $,q),r$=F.create,o$=l.create,gq=E$.create,xq=c.create,a$=e.create,yq=p.create,Zq=M$.create,mq=$$.create,lq=q$.create,cq=d.create,uq=m.create,nq=P.create,pq=w$.create,dq=v.create,iq=A.create,rq=A.strictCreate,oq=J$.create,aq=R$.create,sq=G$.create,tq=T.create,eq=S$.create,$3=V$.create,q3=i.create,J3=t.create,G3=Q$.create,Q3=H$.create,H3=u.create,W3=W$.create,X3=r.create,Y3=k.create,_3=C.create,B3=x.create,z3=k.createWithPreprocess,M3=L$.create,w3=()=>r$().optional(),S3=()=>o$().optional(),V3=()=>a$().optional(),E3={string:($)=>F.create({...$,coerce:!0}),number:($)=>l.create({...$,coerce:!0}),boolean:($)=>e.create({...$,coerce:!0}),bigint:($)=>c.create({...$,coerce:!0}),date:($)=>p.create({...$,coerce:!0})};var L3=S;function b3($){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 J of $.permissions)if(!q.includes(J))throw Error(`Invalid permission: ${J}. 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,J]of Object.entries($.resolvers)){if(!q.startsWith("$"))throw Error(`Resolver name "${q}" must start with $ (e.g., "$${q}")`);if(typeof J!=="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[J,G]of Object.entries($.hooks)){if(!q.includes(J))throw Error(`Invalid hook: "${J}". Valid hooks are: ${q.join(", ")}`);if(typeof G!=="function")throw Error(`Hook "${J}" 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,J]of Object.entries($.commands))if(typeof J!=="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,J]of Object.entries($.tools)){if(typeof J.description!=="string")throw Error(`Tool "${q}" must have a description`);if(typeof J.args!=="object"||J.args===null)throw Error(`Tool "${q}" must have args schema`);if(typeof J.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 j3($){let q=B$.object($.args);return{description:$.description,args:q,execute:async(J,G)=>{let Q=q.parse(J);return await $.execute(Q,G)}}}function b$($){return`${$.name}#${$.instanceId??"default"}`}function A3($){let q=$.indexOf("#");if(q===-1)return{name:$,instanceId:"default"};return{name:$.slice(0,q),instanceId:$.slice(q+1)}}function I$($){return typeof $==="object"&&$!==null&&!Array.isArray($)&&"command"in $&&Array.isArray($.command)}function s$($){return typeof $==="object"&&$!==null&&!Array.isArray($)&&"name"in $&&typeof $.name==="string"&&!("command"in $)}function U3($){if(typeof $==="string")return $.startsWith("file://");if(Array.isArray($)&&typeof $[0]==="string")return $[0].startsWith("file://");return!1}function R3($){if(typeof $==="string")return!$.startsWith("file://")&&!I$($);if(Array.isArray($)&&typeof $[0]==="string")return!$[0].startsWith("file://");return!1}function t$($,q){let J=y("node:path"),G=J.relative(q,$);return!G.startsWith("..")&&!J.isAbsolute(G)}function e$($,q,J){if(!$.startsWith("file://"))throw Error(`Invalid file URL: ${$}`);let G=y("node:path"),Q=$.slice(7),W;if(Q.startsWith("/"))W=G.normalize(Q);else if(Q.startsWith("./")||Q.startsWith("../"))W=G.resolve(q,Q);else throw Error(`Invalid file plugin path: ${$}. Use file://./relative/path.ts or file:///absolute/path.ts`);if(!J&&!t$(W,q))throw Error(`Plugin path "${$}" resolves outside project root. Set security.allowPluginsOutsideProject: true to allow.`);return W}async function D3($,q,J){let G=y("node:fs/promises");if(J)return $;try{let Q=await G.realpath($);if(!t$(Q,q))throw Error(`Plugin path "${$}" resolves to "${Q}" which is outside project root. Symlinks pointing outside the project are not allowed. Set security.allowPluginsOutsideProject: true to allow.`);return Q}catch(Q){if(Q.code==="ENOENT")return $;throw Q}}function O$($,q,J){let G=$.permissions??[],Q=q?.[$.name];if(Q!==void 0){for(let H of G)if(!Q.includes(H))J.push(`Plugin '${$.name}' requires '${H}' permission but it was denied. Some features may not work. Add to security.pluginPermissions to enable.`);return Q}let W=q?.default;if(W!==void 0){let H=G.filter((X)=>W.includes(X));for(let X of G)if(!W.includes(X))J.push(`Plugin '${$.name}' requires '${X}' permission but it was denied by default. Some features may not work. Add to security.pluginPermissions to enable.`);return H}return G}async function P$($){let{projectRoot:q,plugins:J,security:G,pluginPermissions:Q}=$,W=$.warnings??[],H=[],X=new Map;for(let Y of J)try{let B=await O3(Y,{projectRoot:q,allowOutsideProject:G?.allowPluginsOutsideProject??!1,warnings:W,...Q!==void 0?{pluginPermissions:Q}:{}});if(!B)continue;let j=b$(B.plugin),U=X.get(j);if(U!==void 0)H[U]=B;else X.set(j,H.length),H.push(B)}catch(B){let j=B instanceof Error?B.message:String(B);W.push(`Failed to load plugin: ${j}`)}return{plugins:H,warnings:W}}async function O3($,q){let{projectRoot:J,allowOutsideProject:G,pluginPermissions:Q,warnings:W}=q;if(s$($)){let Y=O$($,Q,W);return{plugin:{...$,instanceId:$.instanceId??"default"},id:b$($),source:"inline",permissions:Y,initialized:!1}}if(I$($))return{plugin:{name:`subprocess:${$.command.join(" ")}`,instanceId:"default"},id:`subprocess:${$.command.join(" ")}#default`,source:"subprocess",permissions:[],initialized:!1,_subprocessConfig:$};let H,X;if(Array.isArray($))H=$[0],X=$[1];else H=$;if(H.startsWith("file://")){let Y=e$(H,J,G);return await K3(Y,X,Q,W,J,G)}return await N3(H,J,X,Q,W)}async function K3($,q,J,G,Q,W){try{let H=$;if(Q!==void 0)H=await D3($,Q,W??!1);let X=await import(H),Y=X.default??X,B;if(typeof Y==="function")B=q?Y(q):Y();else if(typeof Y==="object"&&Y!==null)B=Y;else throw Error(`File "${$}" does not export a valid plugin`);if(B={...B,instanceId:B.instanceId??"default"},q&&typeof q.instanceId==="string")B={...B,instanceId:q.instanceId};let j=O$(B,J,G);return{plugin:B,id:b$(B),source:"file",permissions:j,initialized:!1}}catch(H){throw Error(`Failed to load plugin from "${$}": ${H instanceof Error?H.message:String(H)}`)}}async function N3($,q,J,G,Q){try{let W=$,H=$.lastIndexOf("@");if(H>0)W=$.slice(0,H);let X=y("node:path"),{createRequire:Y}=y("node:module"),U=await import(Y(X.join(q,"package.json")).resolve(W)),R=U.default??U,D;if(typeof R==="function")D=J?R(J):R();else if(typeof R==="object"&&R!==null)D=R;else throw Error(`Package "${W}" does not export a valid plugin`);if(D={...D,instanceId:D.instanceId??"default"},J&&typeof J.instanceId==="string")D={...D,instanceId:J.instanceId};let v$=O$(D,G,Q);return{plugin:D,id:b$(D),source:"npm",permissions:v$,initialized:!1}}catch(W){throw Error(`Failed to load plugin "${$}" from project "${q}": ${W instanceof Error?W.message:String(W)}`)}}function F3($,q){return[...$,...q]}class T$ extends Error{permission;pluginName;constructor($,q){super(`Plugin "${q}" does not have "${$}" permission`);this.permission=$;this.pluginName=q;this.name="PermissionDeniedError"}}class $q{secrets=new Map;constructor($){if($)for(let[q,J]of Object.entries($))this.secrets.set(q,J)}async get($){return this.secrets.get($)}set($,q){this.secrets.set($,q)}}function K$($,q,J){let G=J.relative(q,$);return!G.startsWith("..")&&!J.isAbsolute(G)}function v3($,q){let J=y("node:fs/promises"),G=y("node:path"),Q=async(H)=>{let X=G.resolve($,H);if(!q&&!K$(X,$,G))throw Error(`Path "${H}" is outside project root. Plugins need "filesystem" permission to access files outside project.`);if(!q)try{let Y=await J.realpath(X);if(!K$(Y,$,G))throw Error(`Path "${H}" resolves to "${Y}" which is outside project root. Symlinks pointing outside the project are not allowed.`);return Y}catch(Y){if(Y.code==="ENOENT")return X;throw Y}return X},W=async(H)=>{let X=G.resolve($,H);if(!q&&!K$(X,$,G))throw Error(`Path "${H}" is outside project root. Plugins need "filesystem" permission to access files outside project.`);if(!q){let Y=G.dirname(X);try{let B=await J.realpath(Y);if(!K$(B,$,G))throw Error(`Path "${H}" parent directory resolves to "${B}" which is outside project root. Symlinks pointing outside the project are not allowed.`)}catch(B){if(B.code!=="ENOENT")throw B}}return X};return{async readFile(H){let X=await Q(H);return await J.readFile(X,"utf-8")},async writeFile(H,X){let Y=await W(H);await J.writeFile(Y,X,"utf-8")}}}function C3($){let q=y("node:child_process");return async(J,G)=>{return new Promise((Q,W)=>{let H=q.spawn(J,G,{cwd:$,stdio:["pipe","pipe","pipe"]}),X="",Y="";H.stdout?.on("data",(B)=>{X+=B.toString("utf-8")}),H.stderr?.on("data",(B)=>{Y+=B.toString("utf-8")}),H.on("close",(B)=>{if(B===0)Q({stdout:X,stderr:Y});else W(Error(`Command failed with code ${B}: ${Y}`))}),H.on("error",(B)=>{W(B)})})}}function f3($){let q=`[plugin:${$}]`;return{debug:(J)=>{if(process.env.DEBUG)console.debug(`${q} ${J}`)},info:(J)=>{console.info(`${q} ${J}`)},warn:(J)=>{console.warn(`${q} ${J}`)},error:(J)=>{console.error(`${q} ${J}`)}}}function h$($){let{plugin:q,permissions:J,config:G,enterprise:Q,secrets:W}=$,H=q.name,X={projectRoot:G.projectRoot,config:G,log:f3(H)};if(J.includes("secrets"))X.secrets=new $q(W);if(J.includes("network"))X.fetch=globalThis.fetch;if(J.includes("filesystem"))X.fs=v3(G.projectRoot,G.security.allowPluginsOutsideProject);if(J.includes("env"))X.env=process.env;if(J.includes("subprocess"))X.spawn=C3(G.projectRoot);if(J.includes("enterprise")&&Q)X.enterprise=Q;return X}function k3($,q,J){let G=[];for(let Q of J)if(!q.includes(Q))G.push(`Plugin "${$.name}" requires "${Q}" permission but it was denied.`);return G}function qq($,q){return $.includes(q)}function I3($,q,J){if(!qq($,q))throw new T$(q,J)}import{spawn as P3}from"node:child_process";function N$($){let q={...$},J={when(G,Q){if(G)q={...q,...Q};return J},ifDefined(G,Q){if(Q!==void 0)q={...q,[G]:Q};return J},build(){return q}};return J}var g$=1,T3=5000,h3=1e4,Jq=3,g3=500,x3=10485760;class x${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=P3($,q,{cwd:this.projectRoot,stdio:["pipe","pipe","pipe"],env:this.config.env??{}}),this.process.stdout?.on("data",(J)=>{this.handleStdout(J)}),this.process.stderr?.on("data",(J)=>{let G=J.toString("utf-8").trim();if(G)console.error(`[subprocess:${this.pluginInfo.name}] ${G}`)}),this.process.on("close",(J,G)=>{this.handleClose(J,G)}),this.process.on("error",(J)=>{this.handleError(J)})}async initialize(){let $=this.config.startupTimeoutMs??h3,q=await this.sendRequest({id:this.nextId(),type:"init",protocolVersion:g$,config:this.config.config??{},projectRoot:this.projectRoot},$);if(q.type==="error")throw Error(`Plugin init failed: ${q.error.message}`);let G=q.result;if(G.protocolVersion>g$)throw Error(`Plugin requires protocol version ${G.protocolVersion}, but t-req supports version ${g$}`);this.pluginInfo=N$({name:G.name}).ifDefined("version",G.version).ifDefined("permissions",G.permissions).build(),this.capabilities={hooks:G.hooks??[],resolvers:G.resolvers??[],commands:G.commands??[]},this.initialized=!0}handleStdout($){if(this.buffer.length+$.length>x3){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 J of q){let G=J.trim();if(!G)continue;try{let Q=JSON.parse(G);this.handleResponse(Q)}catch{console.error(`[subprocess:${this.pluginInfo.name}] Invalid JSON: ${G.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[J,G]of this.pendingRequests)clearTimeout(G.timeout),G.reject(Error(`Plugin process exited with code ${$}, signal ${q}`));if(this.pendingRequests.clear(),this.initialized&&this.restartCount<(this.config.maxRestarts??Jq))this.restartCount++,console.warn(`[subprocess:${this.pluginInfo.name}] Process crashed, restarting (${this.restartCount}/${this.config.maxRestarts??Jq})`),this.spawn().then(()=>this.initialize()).catch((J)=>{console.error(`[subprocess:${this.pluginInfo.name}] Restart failed: ${J.message}`)})}handleError($){console.error(`[subprocess:${this.pluginInfo.name}] Process error: ${$.message}`);for(let[q,J]of this.pendingRequests)clearTimeout(J.timeout),J.reject($);this.pendingRequests.clear()}nextId(){return String(++this.requestId)}async sendRequest($,q=this.config.timeoutMs??T3){if(!this.process?.stdin)throw Error("Plugin process not running");return new Promise((J,G)=>{let Q=setTimeout(()=>{this.pendingRequests.delete($.id),G(Error(`Request timed out after ${q}ms`))},q);this.pendingRequests.set($.id,{resolve:J,reject:G,timeout:Q});let W=`${JSON.stringify($)}
3
3
  `;this.process?.stdin?.write(W)})}sendEvent($){if(!this.process?.stdin)return;let q=JSON.stringify({type:"event",event:$});this.process.stdin.write(`${q}
4
4
  `)}async callResolver($,q){if(!this.capabilities.resolvers.includes($))throw Error(`Resolver "${$}" not supported by plugin`);let J={id:this.nextId(),type:"resolver",name:$,args:q},G=await this.sendRequest(J);if(G.type==="error")throw Error(G.error.message);return G.result.value}async callHook($,q,J){if(!this.capabilities.hooks.includes($))return J;let G={id:this.nextId(),type:"hook",name:$,input:q,output:J},Q=await this.sendRequest(G);if(Q.type==="error")throw Error(Q.error.message);return Q.result.output}async shutdown(){if(!this.process)return;try{this.process.stdin?.write(`${JSON.stringify({type:"shutdown"})}
5
- `)}catch{}let $=this.config.gracePeriodMs??h3;await new Promise((q)=>{let J=setTimeout(()=>{if(this.process)this.process.kill("SIGKILL");q()},$);this.process?.on("close",()=>{clearTimeout(J),q()})}),this.process=null}getPluginInfo(){return this.pluginInfo}getCapabilities(){return this.capabilities}isInitialized(){return this.initialized}}function Jq($){let q=$.getPluginInfo(),J=$.getCapabilities(),G={};for(let H of J.resolvers)G[H]=async(...X)=>{return await $.callResolver(H,X)};let Q={};if(J.hooks.includes("parse.after"))Q["parse.after"]=async(H,X)=>{let Y=await $.callHook("parse.after",{file:H.file,path:H.path},{file:X.file});if(Y.file)X.file=Y.file};if(J.hooks.includes("request.before"))Q["request.before"]=async(H,X)=>{let Y=await $.callHook("request.before",{request:H.request,variables:H.variables,ctx:j$(H.ctx)},{request:X.request});if(Y.request)X.request=Y.request;let B=Y.skip;if(typeof B==="boolean")X.skip=B};if(J.hooks.includes("request.compiled"))Q["request.compiled"]=async(H,X)=>{let Y=await $.callHook("request.compiled",{request:H.request,variables:H.variables,ctx:j$(H.ctx)},{request:X.request});if(Y.request)X.request=Y.request};if(J.hooks.includes("request.after"))Q["request.after"]=async(H)=>{await $.callHook("request.after",{request:H.request,ctx:j$(H.ctx)},{})};if(J.hooks.includes("response.after"))Q["response.after"]=async(H,X)=>{let Y={status:H.response.status,statusText:H.response.statusText,headers:Object.fromEntries(H.response.headers.entries())},B=await $.callHook("response.after",{request:H.request,response:Y,timing:H.timing,ctx:j$(H.ctx)},{}),L=B.status,D=B.statusText,P=B.headers,F$=B.retry;if(typeof L==="number")X.status=L;if(typeof D==="string")X.statusText=D;if(P&&typeof P==="object")X.headers=P;if(F$&&typeof F$==="object")X.retry=F$};if(J.hooks.includes("error"))Q.error=async(H,X)=>{let Y=await $.callHook("error",{request:H.request,error:{message:H.error.message,code:H.error.code},ctx:j$(H.ctx)},{}),B=Y.error,L=Y.retry,D=Y.suppress;if(B&&typeof B==="object"&&"message"in B)X.error=Error(B.message);if(L&&typeof L==="object")X.retry=L;if(typeof D==="boolean")X.suppress=D};let W=J.hooks.length>0?async({event:H})=>{$.sendEvent(H)}:void 0;return K$({name:q.name,instanceId:"default",teardown:async()=>{await $.shutdown()}}).ifDefined("version",q.version).ifDefined("permissions",q.permissions).ifDefined("resolvers",Object.keys(G).length>0?G:void 0).ifDefined("hooks",Object.keys(Q).length>0?Q:void 0).ifDefined("event",W).build()}function j$($){return K$({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 g$($,q){let J=new x$($,q);await J.start();let G=J.getPluginInfo();return{plugin:Jq(J),id:`${G.name}#default`,source:"subprocess",permissions:G.permissions??[],initialized:!0}}var N$=30000;async function Gq($,q,J){let G,Q=new Promise((W,H)=>{G=setTimeout(()=>H(Error(J)),q)});try{return await Promise.race([$,Q])}finally{if(G!==void 0)clearTimeout(G)}}class y${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 I$({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 J of q.plugins)await this.initializePlugin(J);this.initialized=!0}async initializePlugin($){let q=Date.now();try{if($.source==="subprocess"&&"_subprocessConfig"in $){let Q=$._subprocessConfig,W=await g$(Q,this.options.projectRoot);$.plugin=W.plugin,$.permissions=W.permissions,$.id=W.id}this.emitPluginEvent({type:"pluginLoaded",name:$.plugin.name,source:$.source,...$.plugin.version!==void 0?{version:$.plugin.version}:{}});let J=T$({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(J);$.initialized=!0,this.registerPluginContributions($);let G=Date.now()-q;this.emitPluginEvent({type:"pluginInitialized",name:$.plugin.name,durationMs:G}),this.plugins.push($)}catch(J){let G=J instanceof Error?J.message:String(J);this.warnings.push(`Plugin "${$.plugin.name}" setup failed: ${G}`),this.emitPluginEvent({type:"pluginError",name:$.plugin.name,stage:"setup",message:G,recoverable:!0})}}registerPluginContributions($){let q=$.plugin;if(q.resolvers)for(let[J,G]of Object.entries(q.resolvers)){if(this.resolvers[J])this.warnings.push(`Resolver "${J}" from "${q.name}" shadows existing resolver`);this.resolvers[J]=G}if(q.commands)for(let[J,G]of Object.entries(q.commands)){if(this.commands[J]){this.warnings.push(`Command "${J}" from "${q.name}" shadows same command from "${this.commands[J].pluginName}" (loaded first, takes precedence)`);continue}this.commands[J]={handler:G,pluginName:q.name}}if(q.middleware)for(let J of q.middleware)this.middleware.push({fn:J,pluginName:q.name});if(q.tools)for(let[J,G]of Object.entries(q.tools)){if(this.tools[J])this.warnings.push(`Tool "${J}" from "${q.name}" shadows existing tool`);this.tools[J]={definition:G,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(J){let G=J instanceof Error?J.message:String(J);this.warnings.push(`Plugin "${q.plugin.name}" teardown failed: ${G}`),this.emitPluginEvent({type:"pluginError",name:q.plugin.name,stage:"teardown",message:G,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 J=await this.executeHook("request.before",$,q);return{...J,...J.output.skip!==void 0?{skip:J.output.skip}:{}}}async triggerRequestCompiled($,q){return await this.executeHook("request.compiled",$,q)}async triggerRequestAfter($){await this.executeReadOnlyHook("request.after",$)}async triggerResponseAfter($,q){let J=await this.executeHook("response.after",$,q);return{...J,...J.output.retry!==void 0?{retry:J.output.retry}:{}}}async triggerError($,q){let J=await this.executeHook("error",$,q);return{...J,...J.output.retry!==void 0?{retry:J.output.retry}:{}}}async executeHook($,q,J){let G=!1,Q="ctx"in q?q.ctx:this.createHookContext({});for(let W of this.plugins){let H=W.plugin.hooks?.[$];if(!H)continue;let X=Date.now(),Y=JSON.stringify(J);this.emitPluginEvent({type:"pluginHookStarted",name:W.plugin.name,hook:$,ctx:Q});try{let B=Promise.resolve(H(q,J));await Gq(B,N$,`Hook "${$}" in "${W.plugin.name}" timed out after ${N$}ms`);let L=JSON.stringify(J),D=Y!==L;if(D)G=!0;let P=Date.now()-X;this.emitPluginEvent({type:"pluginHookFinished",name:W.plugin.name,hook:$,durationMs:P,modified:D,ctx:Q})}catch(B){let L=B instanceof Error?B.message:String(B);this.warnings.push(`Hook "${$}" in "${W.plugin.name}" failed: ${L}`),this.emitPluginEvent({type:"pluginError",name:W.plugin.name,stage:"hook",hook:$,message:L,recoverable:!0})}}return{output:J,modified:G}}async executeReadOnlyHook($,q){let J="ctx"in q?q.ctx:this.createHookContext({});for(let G of this.plugins){let Q=G.plugin.hooks?.[$];if(!Q)continue;let W=Date.now();this.emitPluginEvent({type:"pluginHookStarted",name:G.plugin.name,hook:$,ctx:J});try{let H=Promise.resolve(Q(q));await Gq(H,N$,`Hook "${$}" in "${G.plugin.name}" timed out after ${N$}ms`);let X=Date.now()-W;this.emitPluginEvent({type:"pluginHookFinished",name:G.plugin.name,hook:$,durationMs:X,modified:!1,ctx:J})}catch(H){let X=H instanceof Error?H.message:String(H);this.warnings.push(`Hook "${$}" in "${G.plugin.name}" failed: ${X}`),this.emitPluginEvent({type:"pluginError",name:G.plugin.name,stage:"hook",hook:$,message:X,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 J=this.resolvers[$];if(!J)return`{{${$}:ERROR}}`;let G=Date.now();try{let Q=await J(...q),W=Date.now()-G;return this.emitPluginEvent({type:"pluginResolverCalled",name:$,resolver:$,durationMs:W}),Q}catch(Q){let W=Q instanceof Error?Q.message:String(Q);return this.warnings.push(`Resolver "${$}" failed: ${W}`),this.emitPluginEvent({type:"pluginError",name:"resolver",stage:"resolver",message:W,recoverable:!0}),`{{${$}:ERROR}}`}}getCommands(){let $={};for(let[q,{handler:J}]of Object.entries(this.commands))$[q]=J;return $}getCommand($){return this.commands[$]?.handler}getMiddleware(){return this.middleware.map(($)=>$.fn)}getTools(){let $={};for(let[q,{definition:J}]of Object.entries(this.tools))$[q]=J;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 g3($){return new y$($)}export{_$ as z,f3 as validatePermissions,j3 as tool,_$ as schema,D$ as resolvePermissions,t$ as resolveFilePath,L3 as parsePluginId,N3 as mergePluginRefs,g$ as loadSubprocessPlugin,I$ as loadPlugins,k$ as isSubprocessPluginConfig,A3 as isNpmPlugin,a$ as isInlinePlugin,b3 as isFilePlugin,$q as hasPermission,R$ as getPluginId,R3 as definePlugin,Jq as createSubprocessPluginWrapper,T$ as createRestrictedContext,g3 as createPluginManager,k3 as assertPermission,x$ as SubprocessPlugin,y$ as PluginManager,P$ as PermissionDeniedError};
5
+ `)}catch{}let $=this.config.gracePeriodMs??g3;await new Promise((q)=>{let J=setTimeout(()=>{if(this.process)this.process.kill("SIGKILL");q()},$);this.process?.on("close",()=>{clearTimeout(J),q()})}),this.process=null}getPluginInfo(){return this.pluginInfo}getCapabilities(){return this.capabilities}isInitialized(){return this.initialized}}function Gq($){let q=$.getPluginInfo(),J=$.getCapabilities(),G={};for(let H of J.resolvers)G[H]=async(...X)=>{return await $.callResolver(H,X)};let Q={};if(J.hooks.includes("parse.after"))Q["parse.after"]=async(H,X)=>{let Y=await $.callHook("parse.after",{file:H.file,path:H.path},{file:X.file});if(Y.file)X.file=Y.file};if(J.hooks.includes("request.before"))Q["request.before"]=async(H,X)=>{let Y=await $.callHook("request.before",{request:H.request,variables:H.variables,ctx:j$(H.ctx)},{request:X.request});if(Y.request)X.request=Y.request;let B=Y.skip;if(typeof B==="boolean")X.skip=B};if(J.hooks.includes("request.compiled"))Q["request.compiled"]=async(H,X)=>{let Y=await $.callHook("request.compiled",{request:H.request,variables:H.variables,ctx:j$(H.ctx)},{request:X.request});if(Y.request)X.request=Y.request};if(J.hooks.includes("request.after"))Q["request.after"]=async(H)=>{await $.callHook("request.after",{request:H.request,ctx:j$(H.ctx)},{})};if(J.hooks.includes("response.after"))Q["response.after"]=async(H,X)=>{let Y={status:H.response.status,statusText:H.response.statusText,headers:Object.fromEntries(H.response.headers.entries())},B=await $.callHook("response.after",{request:H.request,response:Y,timing:H.timing,ctx:j$(H.ctx)},{}),j=B.status,U=B.statusText,R=B.headers,D=B.retry;if(typeof j==="number")X.status=j;if(typeof U==="string")X.statusText=U;if(R&&typeof R==="object")X.headers=R;if(D&&typeof D==="object")X.retry=D};if(J.hooks.includes("error"))Q.error=async(H,X)=>{let Y=await $.callHook("error",{request:H.request,error:{message:H.error.message,code:H.error.code},ctx:j$(H.ctx)},{}),B=Y.error,j=Y.retry,U=Y.suppress;if(B&&typeof B==="object"&&"message"in B)X.error=Error(B.message);if(j&&typeof j==="object")X.retry=j;if(typeof U==="boolean")X.suppress=U};let W=J.hooks.length>0?async({event:H})=>{$.sendEvent(H)}:void 0;return N$({name:q.name,instanceId:"default",teardown:async()=>{await $.shutdown()}}).ifDefined("version",q.version).ifDefined("permissions",q.permissions).ifDefined("resolvers",Object.keys(G).length>0?G:void 0).ifDefined("hooks",Object.keys(Q).length>0?Q:void 0).ifDefined("event",W).build()}function j$($){return N$({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 y$($,q){let J=new x$($,q);await J.start();let G=J.getPluginInfo();return{plugin:Gq(J),id:`${G.name}#default`,source:"subprocess",permissions:G.permissions??[],initialized:!0}}var F$=30000;async function Qq($,q,J){let G,Q=new Promise((W,H)=>{G=setTimeout(()=>H(Error(J)),q)});try{return await Promise.race([$,Q])}finally{if(G!==void 0)clearTimeout(G)}}class Z${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(),J=$.flowId?`flow:${$.flowId}`:`run:${q}`;if(J!==this.reportScopeKey)this.reportScopeKey=J,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 P$({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 J of q.plugins)await this.initializePlugin(J);this.initialized=!0}async initializePlugin($){let q=Date.now();try{if($.source==="subprocess"&&"_subprocessConfig"in $){let Q=$._subprocessConfig,W=await y$(Q,this.options.projectRoot);$.plugin=W.plugin,$.permissions=W.permissions,$.id=W.id}this.emitPluginEvent({type:"pluginLoaded",name:$.plugin.name,source:$.source,...$.plugin.version!==void 0?{version:$.plugin.version}:{}});let J=h$({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(J);$.initialized=!0,this.registerPluginContributions($);let G=Date.now()-q;this.emitPluginEvent({type:"pluginInitialized",name:$.plugin.name,durationMs:G}),this.plugins.push($)}catch(J){let G=J instanceof Error?J.message:String(J);this.warnings.push(`Plugin "${$.plugin.name}" setup failed: ${G}`),this.emitPluginEvent({type:"pluginError",name:$.plugin.name,stage:"setup",message:G,recoverable:!0})}}registerPluginContributions($){let q=$.plugin;if(q.resolvers)for(let[J,G]of Object.entries(q.resolvers)){if(this.resolvers[J])this.warnings.push(`Resolver "${J}" from "${q.name}" shadows existing resolver`);this.resolvers[J]=G}if(q.commands)for(let[J,G]of Object.entries(q.commands)){if(this.commands[J]){this.warnings.push(`Command "${J}" from "${q.name}" shadows same command from "${this.commands[J].pluginName}" (loaded first, takes precedence)`);continue}this.commands[J]={handler:G,pluginName:q.name}}if(q.middleware)for(let J of q.middleware)this.middleware.push({fn:J,pluginName:q.name});if(q.tools)for(let[J,G]of Object.entries(q.tools)){if(this.tools[J])this.warnings.push(`Tool "${J}" from "${q.name}" shadows existing tool`);this.tools[J]={definition:G,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(J){let G=J instanceof Error?J.message:String(J);this.warnings.push(`Plugin "${q.plugin.name}" teardown failed: ${G}`),this.emitPluginEvent({type:"pluginError",name:q.plugin.name,stage:"teardown",message:G,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:(J)=>{this.emitReport({pluginName:$.pluginName??"unknown",...$.requestName!==void 0?{requestName:$.requestName}:{},data:J})}}}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 J=await this.executeHook("request.before",$,q);return{...J,...J.output.skip!==void 0?{skip:J.output.skip}:{}}}async triggerRequestCompiled($,q){return await this.executeHook("request.compiled",$,q)}async triggerRequestAfter($){await this.executeReadOnlyHook("request.after",$)}async triggerResponseAfter($,q){let J=await this.executeHook("response.after",$,q);return{...J,...J.output.retry!==void 0?{retry:J.output.retry}:{}}}async triggerError($,q){let J=await this.executeHook("error",$,q);return{...J,...J.output.retry!==void 0?{retry:J.output.retry}:{}}}async executeHook($,q,J){let G=!1,Q="ctx"in q?q.ctx:this.createHookContext({}),W=q,H=W.request&&typeof W.request==="object"&&W.request!==null&&"name"in W.request?W.request.name??void 0:void 0;for(let X of this.plugins){let Y=X.plugin.hooks?.[$];if(!Y)continue;Q.report=(U)=>{this.emitReport({pluginName:X.plugin.name,...H!==void 0?{requestName:H}:{},data:U})};let B=Date.now(),j=JSON.stringify(J);this.emitPluginEvent({type:"pluginHookStarted",name:X.plugin.name,hook:$,ctx:Q});try{let U=Promise.resolve(Y(q,J));await Qq(U,F$,`Hook "${$}" in "${X.plugin.name}" timed out after ${F$}ms`);let R=JSON.stringify(J),D=j!==R;if(D)G=!0;let v$=Date.now()-B;this.emitPluginEvent({type:"pluginHookFinished",name:X.plugin.name,hook:$,durationMs:v$,modified:D,ctx:Q})}catch(U){let R=U instanceof Error?U.message:String(U);this.warnings.push(`Hook "${$}" in "${X.plugin.name}" failed: ${R}`),this.emitPluginEvent({type:"pluginError",name:X.plugin.name,stage:"hook",hook:$,message:R,recoverable:!0})}}return{output:J,modified:G}}async executeReadOnlyHook($,q){let J="ctx"in q?q.ctx:this.createHookContext({}),G=q,Q=G.request&&typeof G.request==="object"&&G.request!==null&&"name"in G.request?G.request.name??void 0:void 0;for(let W of this.plugins){let H=W.plugin.hooks?.[$];if(!H)continue;J.report=(Y)=>{this.emitReport({pluginName:W.plugin.name,...Q!==void 0?{requestName:Q}:{},data:Y})};let X=Date.now();this.emitPluginEvent({type:"pluginHookStarted",name:W.plugin.name,hook:$,ctx:J});try{let Y=Promise.resolve(H(q));await Qq(Y,F$,`Hook "${$}" in "${W.plugin.name}" timed out after ${F$}ms`);let B=Date.now()-X;this.emitPluginEvent({type:"pluginHookFinished",name:W.plugin.name,hook:$,durationMs:B,modified:!1,ctx:J})}catch(Y){let B=Y instanceof Error?Y.message:String(Y);this.warnings.push(`Hook "${$}" in "${W.plugin.name}" failed: ${B}`),this.emitPluginEvent({type:"pluginError",name:W.plugin.name,stage:"hook",hook:$,message:B,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 J=this.resolvers[$];if(!J)return`{{${$}:ERROR}}`;let G=Date.now();try{let Q=await J(...q),W=Date.now()-G;return this.emitPluginEvent({type:"pluginResolverCalled",name:$,resolver:$,durationMs:W}),Q}catch(Q){let W=Q instanceof Error?Q.message:String(Q);return this.warnings.push(`Resolver "${$}" failed: ${W}`),this.emitPluginEvent({type:"pluginError",name:"resolver",stage:"resolver",message:W,recoverable:!0}),`{{${$}:ERROR}}`}}getCommands(){let $={};for(let[q,{handler:J}]of Object.entries(this.commands))$[q]=J;return $}getCommand($){return this.commands[$]?.handler}getMiddleware(){return this.middleware.map(($)=>$.fn)}getTools(){let $={};for(let[q,{definition:J}]of Object.entries(this.tools))$[q]=J;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 y3($){return new Z$($)}export{B$ as z,k3 as validatePermissions,j3 as tool,B$ as schema,O$ as resolvePermissions,e$ as resolveFilePath,A3 as parsePluginId,F3 as mergePluginRefs,y$ as loadSubprocessPlugin,P$ as loadPlugins,I$ as isSubprocessPluginConfig,R3 as isNpmPlugin,s$ as isInlinePlugin,U3 as isFilePlugin,qq as hasPermission,b$ as getPluginId,b3 as definePlugin,Gq as createSubprocessPluginWrapper,h$ as createRestrictedContext,y3 as createPluginManager,I3 as assertPermission,x$ as SubprocessPlugin,Z$ as PluginManager,T$ as PermissionDeniedError};
6
6
 
7
- //# debugId=80F9820A7D8053D564756E2164756E21
7
+ //# debugId=C46ACD083FE9A1E464756E2164756E21
8
8
  //# sourceMappingURL=index.js.map