xmcp 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var s in r)("object"==typeof exports?exports:e)[s]=r[s]}}(this,(()=>(()=>{"use strict";const e=require("node:process");var t,r;!function(e){e.assertEqual=e=>e,e.assertIs=function(e){},e.assertNever=function(e){throw new Error},e.arrayToEnum=e=>{const t={};for(const r of e)t[r]=r;return t},e.getValidEnumValues=t=>{const r=e.objectKeys(t).filter((e=>"number"!=typeof t[t[e]])),s={};for(const e of r)s[e]=t[e];return e.objectValues(s)},e.objectValues=t=>e.objectKeys(t).map((function(e){return t[e]})),e.objectKeys="function"==typeof Object.keys?e=>Object.keys(e):e=>{const t=[];for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.push(r);return t},e.find=(e,t)=>{for(const r of e)if(t(r))return r},e.isInteger="function"==typeof Number.isInteger?e=>Number.isInteger(e):e=>"number"==typeof e&&isFinite(e)&&Math.floor(e)===e,e.joinValues=function(e,t=" | "){return e.map((e=>"string"==typeof e?`'${e}'`:e)).join(t)},e.jsonStringifyReplacer=(e,t)=>"bigint"==typeof t?t.toString():t}(t||(t={})),function(e){e.mergeShapes=(e,t)=>({...e,...t})}(r||(r={}));const s=t.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),a=e=>{switch(typeof e){case"undefined":return s.undefined;case"string":return s.string;case"number":return isNaN(e)?s.nan:s.number;case"boolean":return s.boolean;case"function":return s.function;case"bigint":return s.bigint;case"symbol":return s.symbol;case"object":return Array.isArray(e)?s.array:null===e?s.null:e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch?s.promise:"undefined"!=typeof Map&&e instanceof Map?s.map:"undefined"!=typeof Set&&e instanceof Set?s.set:"undefined"!=typeof Date&&e instanceof Date?s.date:s.object;default:return s.unknown}},n=t.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"]);class i extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=e=>{this.issues=[...this.issues,e]},this.addIssues=(e=[])=>{this.issues=[...this.issues,...e]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(e){return e.message},r={_errors:[]},s=e=>{for(const a of e.issues)if("invalid_union"===a.code)a.unionErrors.map(s);else if("invalid_return_type"===a.code)s(a.returnTypeError);else if("invalid_arguments"===a.code)s(a.argumentsError);else if(0===a.path.length)r._errors.push(t(a));else{let e=r,s=0;for(;s<a.path.length;){const r=a.path[s];s===a.path.length-1?(e[r]=e[r]||{_errors:[]},e[r]._errors.push(t(a))):e[r]=e[r]||{_errors:[]},e=e[r],s++}}};return s(this),r}static assert(e){if(!(e instanceof i))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,t.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(e=e=>e.message){const t={},r=[];for(const s of this.issues)s.path.length>0?(t[s.path[0]]=t[s.path[0]]||[],t[s.path[0]].push(e(s))):r.push(e(s));return{formErrors:r,fieldErrors:t}}get formErrors(){return this.flatten()}}i.create=e=>new i(e);const o=(e,r)=>{let a;switch(e.code){case n.invalid_type:a=e.received===s.undefined?"Required":`Expected ${e.expected}, received ${e.received}`;break;case n.invalid_literal:a=`Invalid literal value, expected ${JSON.stringify(e.expected,t.jsonStringifyReplacer)}`;break;case n.unrecognized_keys:a=`Unrecognized key(s) in object: ${t.joinValues(e.keys,", ")}`;break;case n.invalid_union:a="Invalid input";break;case n.invalid_union_discriminator:a=`Invalid discriminator value. Expected ${t.joinValues(e.options)}`;break;case n.invalid_enum_value:a=`Invalid enum value. Expected ${t.joinValues(e.options)}, received '${e.received}'`;break;case n.invalid_arguments:a="Invalid function arguments";break;case n.invalid_return_type:a="Invalid function return type";break;case n.invalid_date:a="Invalid date";break;case n.invalid_string:"object"==typeof e.validation?"includes"in e.validation?(a=`Invalid input: must include "${e.validation.includes}"`,"number"==typeof e.validation.position&&(a=`${a} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?a=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?a=`Invalid input: must end with "${e.validation.endsWith}"`:t.assertNever(e.validation):a="regex"!==e.validation?`Invalid ${e.validation}`:"Invalid";break;case n.too_small:a="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:"date"===e.type?`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:"Invalid input";break;case n.too_big:a="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"bigint"===e.type?`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"date"===e.type?`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:"Invalid input";break;case n.custom:a="Invalid input";break;case n.invalid_intersection_types:a="Intersection results could not be merged";break;case n.not_multiple_of:a=`Number must be a multiple of ${e.multipleOf}`;break;case n.not_finite:a="Number must be finite";break;default:a=r.defaultError,t.assertNever(e)}return{message:a}};let d=o;function c(){return d}const u=e=>{const{data:t,path:r,errorMaps:s,issueData:a}=e,n=[...r,...a.path||[]],i={...a,path:n};if(void 0!==a.message)return{...a,path:n,message:a.message};let o="";const d=s.filter((e=>!!e)).slice().reverse();for(const e of d)o=e(i,{data:t,defaultError:o}).message;return{...a,path:n,message:o}};function l(e,t){const r=c(),s=u({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,r,r===o?void 0:o].filter((e=>!!e))});e.common.issues.push(s)}class p{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(e,t){const r=[];for(const s of t){if("aborted"===s.status)return h;"dirty"===s.status&&e.dirty(),r.push(s.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,t){const r=[];for(const e of t){const t=await e.key,s=await e.value;r.push({key:t,value:s})}return p.mergeObjectSync(e,r)}static mergeObjectSync(e,t){const r={};for(const s of t){const{key:t,value:a}=s;if("aborted"===t.status)return h;if("aborted"===a.status)return h;"dirty"===t.status&&e.dirty(),"dirty"===a.status&&e.dirty(),"__proto__"===t.value||void 0===a.value&&!s.alwaysSet||(r[t.value]=a.value)}return{status:e.value,value:r}}}const h=Object.freeze({status:"aborted"}),m=e=>({status:"dirty",value:e}),f=e=>({status:"valid",value:e}),g=e=>"aborted"===e.status,v=e=>"dirty"===e.status,y=e=>"valid"===e.status,_=e=>"undefined"!=typeof Promise&&e instanceof Promise;function b(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)}function x(e,t,r,s,a){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?a.call(e,r):a?a.value=r:t.set(e,r),r}var k,w,T;"function"==typeof SuppressedError&&SuppressedError,function(e){e.errToObj=e=>"string"==typeof e?{message:e}:e||{},e.toString=e=>"string"==typeof e?e:null==e?void 0:e.message}(k||(k={}));class S{constructor(e,t,r,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=r,this._key=s}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Z=(e,t)=>{if(y(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new i(e.common.issues);return this._error=t,this._error}}};function j(e){if(!e)return{};const{errorMap:t,invalid_type_error:r,required_error:s,description:a}=e;if(t&&(r||s))throw new Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');return t?{errorMap:t,description:a}:{errorMap:(t,a)=>{var n,i;const{message:o}=e;return"invalid_enum_value"===t.code?{message:null!=o?o:a.defaultError}:void 0===a.data?{message:null!==(n=null!=o?o:s)&&void 0!==n?n:a.defaultError}:"invalid_type"!==t.code?{message:a.defaultError}:{message:null!==(i=null!=o?o:r)&&void 0!==i?i:a.defaultError}},description:a}}class P{get description(){return this._def.description}_getType(e){return a(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:a(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new p,ctx:{common:e.parent.common,data:e.data,parsedType:a(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(_(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const r=this.safeParse(e,t);if(r.success)return r.data;throw r.error}safeParse(e,t){var r;const s={common:{issues:[],async:null!==(r=null==t?void 0:t.async)&&void 0!==r&&r,contextualErrorMap:null==t?void 0:t.errorMap},path:(null==t?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:a(e)},n=this._parseSync({data:e,path:s.path,parent:s});return Z(s,n)}"~validate"(e){var t,r;const s={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:a(e)};if(!this["~standard"].async)try{const t=this._parseSync({data:e,path:[],parent:s});return y(t)?{value:t.value}:{issues:s.common.issues}}catch(e){(null===(r=null===(t=null==e?void 0:e.message)||void 0===t?void 0:t.toLowerCase())||void 0===r?void 0:r.includes("encountered"))&&(this["~standard"].async=!0),s.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:s}).then((e=>y(e)?{value:e.value}:{issues:s.common.issues}))}async parseAsync(e,t){const r=await this.safeParseAsync(e,t);if(r.success)return r.data;throw r.error}async safeParseAsync(e,t){const r={common:{issues:[],contextualErrorMap:null==t?void 0:t.errorMap,async:!0},path:(null==t?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:a(e)},s=this._parse({data:e,path:r.path,parent:r}),n=await(_(s)?s:Promise.resolve(s));return Z(r,n)}refine(e,t){const r=e=>"string"==typeof t||void 0===t?{message:t}:"function"==typeof t?t(e):t;return this._refinement(((t,s)=>{const a=e(t),i=()=>s.addIssue({code:n.custom,...r(t)});return"undefined"!=typeof Promise&&a instanceof Promise?a.then((e=>!!e||(i(),!1))):!!a||(i(),!1)}))}refinement(e,t){return this._refinement(((r,s)=>!!e(r)||(s.addIssue("function"==typeof t?t(r,s):t),!1)))}_refinement(e){return new Pe({schema:this,typeName:He.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return Ce.create(this,this._def)}nullable(){return Oe.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ce.create(this)}promise(){return je.create(this,this._def)}or(e){return pe.create([this,e],this._def)}and(e){return ge.create(this,e,this._def)}transform(e){return new Pe({...j(this._def),schema:this,typeName:He.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t="function"==typeof e?e:()=>e;return new Ie({...j(this._def),innerType:this,defaultValue:t,typeName:He.ZodDefault})}brand(){return new Ne({typeName:He.ZodBranded,type:this,...j(this._def)})}catch(e){const t="function"==typeof e?e:()=>e;return new Ae({...j(this._def),innerType:this,catchValue:t,typeName:He.ZodCatch})}describe(e){return new(0,this.constructor)({...this._def,description:e})}pipe(e){return $e.create(this,e)}readonly(){return Me.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const C=/^c[^\s-]{8,}$/i,O=/^[0-9a-z]+$/,I=/^[0-9A-HJKMNP-TV-Z]{26}$/i,A=/^[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,R=/^[a-z0-9_-]{21}$/i,E=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,N=/^[-+]?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)?)??$/,$=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;let M;const q=/^(?:(?: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])$/,L=/^(?:(?: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])$/,z=/^(([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]))$/,H=/^(([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])$/,F=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,D=/^([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])))",V=new RegExp(`^${U}$`);function B(e){let t="[0-5]\\d";return e.precision?t=`${t}\\.\\d{${e.precision}}`:null==e.precision&&(t=`${t}(\\.\\d+)?`),`([01]\\d|2[0-3]):[0-5]\\d(:${t})${e.precision?"+":"?"}`}function K(e){let t=`${U}T${B(e)}`;const r=[];return r.push(e.local?"Z?":"Z"),e.offset&&r.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${r.join("|")})`,new RegExp(`^${t}$`)}function W(e,t){if(!E.test(e))return!1;try{const[r]=e.split("."),s=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(r.length+(4-r.length%4)%4,"="),a=JSON.parse(atob(s));return!("object"!=typeof a||null===a||!a.typ||!a.alg||t&&a.alg!==t)}catch(e){return!1}}function J(e,t){return!("v4"!==t&&t||!L.test(e))||!("v6"!==t&&t||!H.test(e))}class Y extends P{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==s.string){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.string,received:t.parsedType}),h}const r=new p;let a;for(const s of this._def.checks)if("min"===s.kind)e.data.length<s.value&&(a=this._getOrReturnCtx(e,a),l(a,{code:n.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if("max"===s.kind)e.data.length>s.value&&(a=this._getOrReturnCtx(e,a),l(a,{code:n.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if("length"===s.kind){const t=e.data.length>s.value,i=e.data.length<s.value;(t||i)&&(a=this._getOrReturnCtx(e,a),t?l(a,{code:n.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):i&&l(a,{code:n.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),r.dirty())}else if("email"===s.kind)$.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"email",code:n.invalid_string,message:s.message}),r.dirty());else if("emoji"===s.kind)M||(M=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),M.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"emoji",code:n.invalid_string,message:s.message}),r.dirty());else if("uuid"===s.kind)A.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"uuid",code:n.invalid_string,message:s.message}),r.dirty());else if("nanoid"===s.kind)R.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"nanoid",code:n.invalid_string,message:s.message}),r.dirty());else if("cuid"===s.kind)C.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"cuid",code:n.invalid_string,message:s.message}),r.dirty());else if("cuid2"===s.kind)O.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"cuid2",code:n.invalid_string,message:s.message}),r.dirty());else if("ulid"===s.kind)I.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"ulid",code:n.invalid_string,message:s.message}),r.dirty());else if("url"===s.kind)try{new URL(e.data)}catch(t){a=this._getOrReturnCtx(e,a),l(a,{validation:"url",code:n.invalid_string,message:s.message}),r.dirty()}else"regex"===s.kind?(s.regex.lastIndex=0,s.regex.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"regex",code:n.invalid_string,message:s.message}),r.dirty())):"trim"===s.kind?e.data=e.data.trim():"includes"===s.kind?e.data.includes(s.value,s.position)||(a=this._getOrReturnCtx(e,a),l(a,{code:n.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),r.dirty()):"toLowerCase"===s.kind?e.data=e.data.toLowerCase():"toUpperCase"===s.kind?e.data=e.data.toUpperCase():"startsWith"===s.kind?e.data.startsWith(s.value)||(a=this._getOrReturnCtx(e,a),l(a,{code:n.invalid_string,validation:{startsWith:s.value},message:s.message}),r.dirty()):"endsWith"===s.kind?e.data.endsWith(s.value)||(a=this._getOrReturnCtx(e,a),l(a,{code:n.invalid_string,validation:{endsWith:s.value},message:s.message}),r.dirty()):"datetime"===s.kind?K(s).test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{code:n.invalid_string,validation:"datetime",message:s.message}),r.dirty()):"date"===s.kind?V.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{code:n.invalid_string,validation:"date",message:s.message}),r.dirty()):"time"===s.kind?new RegExp(`^${B(s)}$`).test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{code:n.invalid_string,validation:"time",message:s.message}),r.dirty()):"duration"===s.kind?N.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"duration",code:n.invalid_string,message:s.message}),r.dirty()):"ip"===s.kind?(i=e.data,("v4"!==(o=s.version)&&o||!q.test(i))&&("v6"!==o&&o||!z.test(i))&&(a=this._getOrReturnCtx(e,a),l(a,{validation:"ip",code:n.invalid_string,message:s.message}),r.dirty())):"jwt"===s.kind?W(e.data,s.alg)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"jwt",code:n.invalid_string,message:s.message}),r.dirty()):"cidr"===s.kind?J(e.data,s.version)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"cidr",code:n.invalid_string,message:s.message}),r.dirty()):"base64"===s.kind?F.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"base64",code:n.invalid_string,message:s.message}),r.dirty()):"base64url"===s.kind?D.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"base64url",code:n.invalid_string,message:s.message}),r.dirty()):t.assertNever(s);var i,o;return{status:r.value,value:e.data}}_regex(e,t,r){return this.refinement((t=>e.test(t)),{validation:t,code:n.invalid_string,...k.errToObj(r)})}_addCheck(e){return new Y({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...k.errToObj(e)})}url(e){return this._addCheck({kind:"url",...k.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...k.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...k.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...k.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...k.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...k.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...k.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...k.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...k.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...k.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...k.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...k.errToObj(e)})}datetime(e){var t,r;return"string"==typeof e?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:void 0===(null==e?void 0:e.precision)?null:null==e?void 0:e.precision,offset:null!==(t=null==e?void 0:e.offset)&&void 0!==t&&t,local:null!==(r=null==e?void 0:e.local)&&void 0!==r&&r,...k.errToObj(null==e?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return"string"==typeof e?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:void 0===(null==e?void 0:e.precision)?null:null==e?void 0:e.precision,...k.errToObj(null==e?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...k.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...k.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:null==t?void 0:t.position,...k.errToObj(null==t?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...k.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...k.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...k.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...k.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...k.errToObj(t)})}nonempty(e){return this.min(1,k.errToObj(e))}trim(){return new Y({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Y({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Y({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find((e=>"datetime"===e.kind))}get isDate(){return!!this._def.checks.find((e=>"date"===e.kind))}get isTime(){return!!this._def.checks.find((e=>"time"===e.kind))}get isDuration(){return!!this._def.checks.find((e=>"duration"===e.kind))}get isEmail(){return!!this._def.checks.find((e=>"email"===e.kind))}get isURL(){return!!this._def.checks.find((e=>"url"===e.kind))}get isEmoji(){return!!this._def.checks.find((e=>"emoji"===e.kind))}get isUUID(){return!!this._def.checks.find((e=>"uuid"===e.kind))}get isNANOID(){return!!this._def.checks.find((e=>"nanoid"===e.kind))}get isCUID(){return!!this._def.checks.find((e=>"cuid"===e.kind))}get isCUID2(){return!!this._def.checks.find((e=>"cuid2"===e.kind))}get isULID(){return!!this._def.checks.find((e=>"ulid"===e.kind))}get isIP(){return!!this._def.checks.find((e=>"ip"===e.kind))}get isCIDR(){return!!this._def.checks.find((e=>"cidr"===e.kind))}get isBase64(){return!!this._def.checks.find((e=>"base64"===e.kind))}get isBase64url(){return!!this._def.checks.find((e=>"base64url"===e.kind))}get minLength(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}function G(e,t){const r=(e.toString().split(".")[1]||"").length,s=(t.toString().split(".")[1]||"").length,a=r>s?r:s;return parseInt(e.toFixed(a).replace(".",""))%parseInt(t.toFixed(a).replace(".",""))/Math.pow(10,a)}Y.create=e=>{var t;return new Y({checks:[],typeName:He.ZodString,coerce:null!==(t=null==e?void 0:e.coerce)&&void 0!==t&&t,...j(e)})};class X extends P{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==s.number){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.number,received:t.parsedType}),h}let r;const a=new p;for(const s of this._def.checks)"int"===s.kind?t.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{code:n.invalid_type,expected:"integer",received:"float",message:s.message}),a.dirty()):"min"===s.kind?(s.inclusive?e.data<s.value:e.data<=s.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:n.too_small,minimum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),a.dirty()):"max"===s.kind?(s.inclusive?e.data>s.value:e.data>=s.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:n.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),a.dirty()):"multipleOf"===s.kind?0!==G(e.data,s.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:n.not_multiple_of,multipleOf:s.value,message:s.message}),a.dirty()):"finite"===s.kind?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{code:n.not_finite,message:s.message}),a.dirty()):t.assertNever(s);return{status:a.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,k.toString(t))}gt(e,t){return this.setLimit("min",e,!1,k.toString(t))}lte(e,t){return this.setLimit("max",e,!0,k.toString(t))}lt(e,t){return this.setLimit("max",e,!1,k.toString(t))}setLimit(e,t,r,s){return new X({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:k.toString(s)}]})}_addCheck(e){return new X({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:k.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:k.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:k.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:k.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:k.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:k.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:k.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:k.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:k.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find((e=>"int"===e.kind||"multipleOf"===e.kind&&t.isInteger(e.value)))}get isFinite(){let e=null,t=null;for(const r of this._def.checks){if("finite"===r.kind||"int"===r.kind||"multipleOf"===r.kind)return!0;"min"===r.kind?(null===t||r.value>t)&&(t=r.value):"max"===r.kind&&(null===e||r.value<e)&&(e=r.value)}return Number.isFinite(t)&&Number.isFinite(e)}}X.create=e=>new X({checks:[],typeName:He.ZodNumber,coerce:(null==e?void 0:e.coerce)||!1,...j(e)});class Q extends P{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch(t){return this._getInvalidInput(e)}if(this._getType(e)!==s.bigint)return this._getInvalidInput(e);let r;const a=new p;for(const s of this._def.checks)"min"===s.kind?(s.inclusive?e.data<s.value:e.data<=s.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:n.too_small,type:"bigint",minimum:s.value,inclusive:s.inclusive,message:s.message}),a.dirty()):"max"===s.kind?(s.inclusive?e.data>s.value:e.data>=s.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:n.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),a.dirty()):"multipleOf"===s.kind?e.data%s.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),l(r,{code:n.not_multiple_of,multipleOf:s.value,message:s.message}),a.dirty()):t.assertNever(s);return{status:a.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.bigint,received:t.parsedType}),h}gte(e,t){return this.setLimit("min",e,!0,k.toString(t))}gt(e,t){return this.setLimit("min",e,!1,k.toString(t))}lte(e,t){return this.setLimit("max",e,!0,k.toString(t))}lt(e,t){return this.setLimit("max",e,!1,k.toString(t))}setLimit(e,t,r,s){return new Q({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:k.toString(s)}]})}_addCheck(e){return new Q({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:k.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:k.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:k.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:k.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:k.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}Q.create=e=>{var t;return new Q({checks:[],typeName:He.ZodBigInt,coerce:null!==(t=null==e?void 0:e.coerce)&&void 0!==t&&t,...j(e)})};class ee extends P{_parse(e){if(this._def.coerce&&(e.data=Boolean(e.data)),this._getType(e)!==s.boolean){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.boolean,received:t.parsedType}),h}return f(e.data)}}ee.create=e=>new ee({typeName:He.ZodBoolean,coerce:(null==e?void 0:e.coerce)||!1,...j(e)});class te extends P{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==s.date){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.date,received:t.parsedType}),h}if(isNaN(e.data.getTime()))return l(this._getOrReturnCtx(e),{code:n.invalid_date}),h;const r=new p;let a;for(const s of this._def.checks)"min"===s.kind?e.data.getTime()<s.value&&(a=this._getOrReturnCtx(e,a),l(a,{code:n.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),r.dirty()):"max"===s.kind?e.data.getTime()>s.value&&(a=this._getOrReturnCtx(e,a),l(a,{code:n.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),r.dirty()):t.assertNever(s);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new te({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:k.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:k.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return null!=e?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return null!=e?new Date(e):null}}te.create=e=>new te({checks:[],coerce:(null==e?void 0:e.coerce)||!1,typeName:He.ZodDate,...j(e)});class re extends P{_parse(e){if(this._getType(e)!==s.symbol){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.symbol,received:t.parsedType}),h}return f(e.data)}}re.create=e=>new re({typeName:He.ZodSymbol,...j(e)});class se extends P{_parse(e){if(this._getType(e)!==s.undefined){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.undefined,received:t.parsedType}),h}return f(e.data)}}se.create=e=>new se({typeName:He.ZodUndefined,...j(e)});class ae extends P{_parse(e){if(this._getType(e)!==s.null){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.null,received:t.parsedType}),h}return f(e.data)}}ae.create=e=>new ae({typeName:He.ZodNull,...j(e)});class ne extends P{constructor(){super(...arguments),this._any=!0}_parse(e){return f(e.data)}}ne.create=e=>new ne({typeName:He.ZodAny,...j(e)});class ie extends P{constructor(){super(...arguments),this._unknown=!0}_parse(e){return f(e.data)}}ie.create=e=>new ie({typeName:He.ZodUnknown,...j(e)});class oe extends P{_parse(e){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.never,received:t.parsedType}),h}}oe.create=e=>new oe({typeName:He.ZodNever,...j(e)});class de extends P{_parse(e){if(this._getType(e)!==s.undefined){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.void,received:t.parsedType}),h}return f(e.data)}}de.create=e=>new de({typeName:He.ZodVoid,...j(e)});class ce extends P{_parse(e){const{ctx:t,status:r}=this._processInputParams(e),a=this._def;if(t.parsedType!==s.array)return l(t,{code:n.invalid_type,expected:s.array,received:t.parsedType}),h;if(null!==a.exactLength){const e=t.data.length>a.exactLength.value,s=t.data.length<a.exactLength.value;(e||s)&&(l(t,{code:e?n.too_big:n.too_small,minimum:s?a.exactLength.value:void 0,maximum:e?a.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:a.exactLength.message}),r.dirty())}if(null!==a.minLength&&t.data.length<a.minLength.value&&(l(t,{code:n.too_small,minimum:a.minLength.value,type:"array",inclusive:!0,exact:!1,message:a.minLength.message}),r.dirty()),null!==a.maxLength&&t.data.length>a.maxLength.value&&(l(t,{code:n.too_big,maximum:a.maxLength.value,type:"array",inclusive:!0,exact:!1,message:a.maxLength.message}),r.dirty()),t.common.async)return Promise.all([...t.data].map(((e,r)=>a.type._parseAsync(new S(t,e,t.path,r))))).then((e=>p.mergeArray(r,e)));const i=[...t.data].map(((e,r)=>a.type._parseSync(new S(t,e,t.path,r))));return p.mergeArray(r,i)}get element(){return this._def.type}min(e,t){return new ce({...this._def,minLength:{value:e,message:k.toString(t)}})}max(e,t){return new ce({...this._def,maxLength:{value:e,message:k.toString(t)}})}length(e,t){return new ce({...this._def,exactLength:{value:e,message:k.toString(t)}})}nonempty(e){return this.min(1,e)}}function ue(e){if(e instanceof le){const t={};for(const r in e.shape){const s=e.shape[r];t[r]=Ce.create(ue(s))}return new le({...e._def,shape:()=>t})}return e instanceof ce?new ce({...e._def,type:ue(e.element)}):e instanceof Ce?Ce.create(ue(e.unwrap())):e instanceof Oe?Oe.create(ue(e.unwrap())):e instanceof ve?ve.create(e.items.map((e=>ue(e)))):e}ce.create=(e,t)=>new ce({type:e,minLength:null,maxLength:null,exactLength:null,typeName:He.ZodArray,...j(t)});class le extends P{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;const e=this._def.shape(),r=t.objectKeys(e);return this._cached={shape:e,keys:r}}_parse(e){if(this._getType(e)!==s.object){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.object,received:t.parsedType}),h}const{status:t,ctx:r}=this._processInputParams(e),{shape:a,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof oe&&"strip"===this._def.unknownKeys))for(const e in r.data)i.includes(e)||o.push(e);const d=[];for(const e of i){const t=a[e],s=r.data[e];d.push({key:{status:"valid",value:e},value:t._parse(new S(r,s,r.path,e)),alwaysSet:e in r.data})}if(this._def.catchall instanceof oe){const e=this._def.unknownKeys;if("passthrough"===e)for(const e of o)d.push({key:{status:"valid",value:e},value:{status:"valid",value:r.data[e]}});else if("strict"===e)o.length>0&&(l(r,{code:n.unrecognized_keys,keys:o}),t.dirty());else if("strip"!==e)throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const e=this._def.catchall;for(const t of o){const s=r.data[t];d.push({key:{status:"valid",value:t},value:e._parse(new S(r,s,r.path,t)),alwaysSet:t in r.data})}}return r.common.async?Promise.resolve().then((async()=>{const e=[];for(const t of d){const r=await t.key,s=await t.value;e.push({key:r,value:s,alwaysSet:t.alwaysSet})}return e})).then((e=>p.mergeObjectSync(t,e))):p.mergeObjectSync(t,d)}get shape(){return this._def.shape()}strict(e){return k.errToObj,new le({...this._def,unknownKeys:"strict",...void 0!==e?{errorMap:(t,r)=>{var s,a,n,i;const o=null!==(n=null===(a=(s=this._def).errorMap)||void 0===a?void 0:a.call(s,t,r).message)&&void 0!==n?n:r.defaultError;return"unrecognized_keys"===t.code?{message:null!==(i=k.errToObj(e).message)&&void 0!==i?i:o}:{message:o}}}:{}})}strip(){return new le({...this._def,unknownKeys:"strip"})}passthrough(){return new le({...this._def,unknownKeys:"passthrough"})}extend(e){return new le({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new le({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:He.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new le({...this._def,catchall:e})}pick(e){const r={};return t.objectKeys(e).forEach((t=>{e[t]&&this.shape[t]&&(r[t]=this.shape[t])})),new le({...this._def,shape:()=>r})}omit(e){const r={};return t.objectKeys(this.shape).forEach((t=>{e[t]||(r[t]=this.shape[t])})),new le({...this._def,shape:()=>r})}deepPartial(){return ue(this)}partial(e){const r={};return t.objectKeys(this.shape).forEach((t=>{const s=this.shape[t];e&&!e[t]?r[t]=s:r[t]=s.optional()})),new le({...this._def,shape:()=>r})}required(e){const r={};return t.objectKeys(this.shape).forEach((t=>{if(e&&!e[t])r[t]=this.shape[t];else{let e=this.shape[t];for(;e instanceof Ce;)e=e._def.innerType;r[t]=e}})),new le({...this._def,shape:()=>r})}keyof(){return Te(t.objectKeys(this.shape))}}le.create=(e,t)=>new le({shape:()=>e,unknownKeys:"strip",catchall:oe.create(),typeName:He.ZodObject,...j(t)}),le.strictCreate=(e,t)=>new le({shape:()=>e,unknownKeys:"strict",catchall:oe.create(),typeName:He.ZodObject,...j(t)}),le.lazycreate=(e,t)=>new le({shape:e,unknownKeys:"strip",catchall:oe.create(),typeName:He.ZodObject,...j(t)});class pe extends P{_parse(e){const{ctx:t}=this._processInputParams(e),r=this._def.options;if(t.common.async)return Promise.all(r.map((async e=>{const r={...t,common:{...t.common,issues:[]},parent:null};return{result:await e._parseAsync({data:t.data,path:t.path,parent:r}),ctx:r}}))).then((function(e){for(const t of e)if("valid"===t.result.status)return t.result;for(const r of e)if("dirty"===r.result.status)return t.common.issues.push(...r.ctx.common.issues),r.result;const r=e.map((e=>new i(e.ctx.common.issues)));return l(t,{code:n.invalid_union,unionErrors:r}),h}));{let e;const s=[];for(const a of r){const r={...t,common:{...t.common,issues:[]},parent:null},n=a._parseSync({data:t.data,path:t.path,parent:r});if("valid"===n.status)return n;"dirty"!==n.status||e||(e={result:n,ctx:r}),r.common.issues.length&&s.push(r.common.issues)}if(e)return t.common.issues.push(...e.ctx.common.issues),e.result;const a=s.map((e=>new i(e)));return l(t,{code:n.invalid_union,unionErrors:a}),h}}get options(){return this._def.options}}pe.create=(e,t)=>new pe({options:e,typeName:He.ZodUnion,...j(t)});const he=e=>e instanceof ke?he(e.schema):e instanceof Pe?he(e.innerType()):e instanceof we?[e.value]:e instanceof Se?e.options:e instanceof Ze?t.objectValues(e.enum):e instanceof Ie?he(e._def.innerType):e instanceof se?[void 0]:e instanceof ae?[null]:e instanceof Ce?[void 0,...he(e.unwrap())]:e instanceof Oe?[null,...he(e.unwrap())]:e instanceof Ne||e instanceof Me?he(e.unwrap()):e instanceof Ae?he(e._def.innerType):[];class me extends P{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==s.object)return l(t,{code:n.invalid_type,expected:s.object,received:t.parsedType}),h;const r=this.discriminator,a=t.data[r],i=this.optionsMap.get(a);return i?t.common.async?i._parseAsync({data:t.data,path:t.path,parent:t}):i._parseSync({data:t.data,path:t.path,parent:t}):(l(t,{code:n.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),h)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,r){const s=new Map;for(const r of t){const t=he(r.shape[e]);if(!t.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const a of t){if(s.has(a))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(a)}`);s.set(a,r)}}return new me({typeName:He.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:s,...j(r)})}}function fe(e,r){const n=a(e),i=a(r);if(e===r)return{valid:!0,data:e};if(n===s.object&&i===s.object){const s=t.objectKeys(r),a=t.objectKeys(e).filter((e=>-1!==s.indexOf(e))),n={...e,...r};for(const t of a){const s=fe(e[t],r[t]);if(!s.valid)return{valid:!1};n[t]=s.data}return{valid:!0,data:n}}if(n===s.array&&i===s.array){if(e.length!==r.length)return{valid:!1};const t=[];for(let s=0;s<e.length;s++){const a=fe(e[s],r[s]);if(!a.valid)return{valid:!1};t.push(a.data)}return{valid:!0,data:t}}return n===s.date&&i===s.date&&+e===+r?{valid:!0,data:e}:{valid:!1}}class ge extends P{_parse(e){const{status:t,ctx:r}=this._processInputParams(e),s=(e,s)=>{if(g(e)||g(s))return h;const a=fe(e.value,s.value);return a.valid?((v(e)||v(s))&&t.dirty(),{status:t.value,value:a.data}):(l(r,{code:n.invalid_intersection_types}),h)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then((([e,t])=>s(e,t))):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}ge.create=(e,t,r)=>new ge({left:e,right:t,typeName:He.ZodIntersection,...j(r)});class ve extends P{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==s.array)return l(r,{code:n.invalid_type,expected:s.array,received:r.parsedType}),h;if(r.data.length<this._def.items.length)return l(r,{code:n.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),h;!this._def.rest&&r.data.length>this._def.items.length&&(l(r,{code:n.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const a=[...r.data].map(((e,t)=>{const s=this._def.items[t]||this._def.rest;return s?s._parse(new S(r,e,r.path,t)):null})).filter((e=>!!e));return r.common.async?Promise.all(a).then((e=>p.mergeArray(t,e))):p.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new ve({...this._def,rest:e})}}ve.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ve({items:e,typeName:He.ZodTuple,rest:null,...j(t)})};class ye extends P{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==s.object)return l(r,{code:n.invalid_type,expected:s.object,received:r.parsedType}),h;const a=[],i=this._def.keyType,o=this._def.valueType;for(const e in r.data)a.push({key:i._parse(new S(r,e,r.path,e)),value:o._parse(new S(r,r.data[e],r.path,e)),alwaysSet:e in r.data});return r.common.async?p.mergeObjectAsync(t,a):p.mergeObjectSync(t,a)}get element(){return this._def.valueType}static create(e,t,r){return new ye(t instanceof P?{keyType:e,valueType:t,typeName:He.ZodRecord,...j(r)}:{keyType:Y.create(),valueType:e,typeName:He.ZodRecord,...j(t)})}}class _e extends P{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==s.map)return l(r,{code:n.invalid_type,expected:s.map,received:r.parsedType}),h;const a=this._def.keyType,i=this._def.valueType,o=[...r.data.entries()].map((([e,t],s)=>({key:a._parse(new S(r,e,r.path,[s,"key"])),value:i._parse(new S(r,t,r.path,[s,"value"]))})));if(r.common.async){const e=new Map;return Promise.resolve().then((async()=>{for(const r of o){const s=await r.key,a=await r.value;if("aborted"===s.status||"aborted"===a.status)return h;"dirty"!==s.status&&"dirty"!==a.status||t.dirty(),e.set(s.value,a.value)}return{status:t.value,value:e}}))}{const e=new Map;for(const r of o){const s=r.key,a=r.value;if("aborted"===s.status||"aborted"===a.status)return h;"dirty"!==s.status&&"dirty"!==a.status||t.dirty(),e.set(s.value,a.value)}return{status:t.value,value:e}}}}_e.create=(e,t,r)=>new _e({valueType:t,keyType:e,typeName:He.ZodMap,...j(r)});class be extends P{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==s.set)return l(r,{code:n.invalid_type,expected:s.set,received:r.parsedType}),h;const a=this._def;null!==a.minSize&&r.data.size<a.minSize.value&&(l(r,{code:n.too_small,minimum:a.minSize.value,type:"set",inclusive:!0,exact:!1,message:a.minSize.message}),t.dirty()),null!==a.maxSize&&r.data.size>a.maxSize.value&&(l(r,{code:n.too_big,maximum:a.maxSize.value,type:"set",inclusive:!0,exact:!1,message:a.maxSize.message}),t.dirty());const i=this._def.valueType;function o(e){const r=new Set;for(const s of e){if("aborted"===s.status)return h;"dirty"===s.status&&t.dirty(),r.add(s.value)}return{status:t.value,value:r}}const d=[...r.data.values()].map(((e,t)=>i._parse(new S(r,e,r.path,t))));return r.common.async?Promise.all(d).then((e=>o(e))):o(d)}min(e,t){return new be({...this._def,minSize:{value:e,message:k.toString(t)}})}max(e,t){return new be({...this._def,maxSize:{value:e,message:k.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}be.create=(e,t)=>new be({valueType:e,minSize:null,maxSize:null,typeName:He.ZodSet,...j(t)});class xe extends P{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==s.function)return l(t,{code:n.invalid_type,expected:s.function,received:t.parsedType}),h;function r(e,r){return u({data:e,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,c(),o].filter((e=>!!e)),issueData:{code:n.invalid_arguments,argumentsError:r}})}function a(e,r){return u({data:e,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,c(),o].filter((e=>!!e)),issueData:{code:n.invalid_return_type,returnTypeError:r}})}const d={errorMap:t.common.contextualErrorMap},p=t.data;if(this._def.returns instanceof je){const e=this;return f((async function(...t){const s=new i([]),n=await e._def.args.parseAsync(t,d).catch((e=>{throw s.addIssue(r(t,e)),s})),o=await Reflect.apply(p,this,n);return await e._def.returns._def.type.parseAsync(o,d).catch((e=>{throw s.addIssue(a(o,e)),s}))}))}{const e=this;return f((function(...t){const s=e._def.args.safeParse(t,d);if(!s.success)throw new i([r(t,s.error)]);const n=Reflect.apply(p,this,s.data),o=e._def.returns.safeParse(n,d);if(!o.success)throw new i([a(n,o.error)]);return o.data}))}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new xe({...this._def,args:ve.create(e).rest(ie.create())})}returns(e){return new xe({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,r){return new xe({args:e||ve.create([]).rest(ie.create()),returns:t||ie.create(),typeName:He.ZodFunction,...j(r)})}}class ke extends P{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}ke.create=(e,t)=>new ke({getter:e,typeName:He.ZodLazy,...j(t)});class we extends P{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return l(t,{received:t.data,code:n.invalid_literal,expected:this._def.value}),h}return{status:"valid",value:e.data}}get value(){return this._def.value}}function Te(e,t){return new Se({values:e,typeName:He.ZodEnum,...j(t)})}we.create=(e,t)=>new we({value:e,typeName:He.ZodLiteral,...j(t)});class Se extends P{constructor(){super(...arguments),w.set(this,void 0)}_parse(e){if("string"!=typeof e.data){const r=this._getOrReturnCtx(e),s=this._def.values;return l(r,{expected:t.joinValues(s),received:r.parsedType,code:n.invalid_type}),h}if(b(this,w,"f")||x(this,w,new Set(this._def.values),"f"),!b(this,w,"f").has(e.data)){const t=this._getOrReturnCtx(e),r=this._def.values;return l(t,{received:t.data,code:n.invalid_enum_value,options:r}),h}return f(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return Se.create(e,{...this._def,...t})}exclude(e,t=this._def){return Se.create(this.options.filter((t=>!e.includes(t))),{...this._def,...t})}}w=new WeakMap,Se.create=Te;class Ze extends P{constructor(){super(...arguments),T.set(this,void 0)}_parse(e){const r=t.getValidEnumValues(this._def.values),a=this._getOrReturnCtx(e);if(a.parsedType!==s.string&&a.parsedType!==s.number){const e=t.objectValues(r);return l(a,{expected:t.joinValues(e),received:a.parsedType,code:n.invalid_type}),h}if(b(this,T,"f")||x(this,T,new Set(t.getValidEnumValues(this._def.values)),"f"),!b(this,T,"f").has(e.data)){const e=t.objectValues(r);return l(a,{received:a.data,code:n.invalid_enum_value,options:e}),h}return f(e.data)}get enum(){return this._def.values}}T=new WeakMap,Ze.create=(e,t)=>new Ze({values:e,typeName:He.ZodNativeEnum,...j(t)});class je extends P{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==s.promise&&!1===t.common.async)return l(t,{code:n.invalid_type,expected:s.promise,received:t.parsedType}),h;const r=t.parsedType===s.promise?t.data:Promise.resolve(t.data);return f(r.then((e=>this._def.type.parseAsync(e,{path:t.path,errorMap:t.common.contextualErrorMap}))))}}je.create=(e,t)=>new je({type:e,typeName:He.ZodPromise,...j(t)});class Pe extends P{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===He.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:r,ctx:s}=this._processInputParams(e),a=this._def.effect||null,n={addIssue:e=>{l(s,e),e.fatal?r.abort():r.dirty()},get path(){return s.path}};if(n.addIssue=n.addIssue.bind(n),"preprocess"===a.type){const e=a.transform(s.data,n);if(s.common.async)return Promise.resolve(e).then((async e=>{if("aborted"===r.value)return h;const t=await this._def.schema._parseAsync({data:e,path:s.path,parent:s});return"aborted"===t.status?h:"dirty"===t.status||"dirty"===r.value?m(t.value):t}));{if("aborted"===r.value)return h;const t=this._def.schema._parseSync({data:e,path:s.path,parent:s});return"aborted"===t.status?h:"dirty"===t.status||"dirty"===r.value?m(t.value):t}}if("refinement"===a.type){const e=e=>{const t=a.refinement(e,n);if(s.common.async)return Promise.resolve(t);if(t instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return e};if(!1===s.common.async){const t=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});return"aborted"===t.status?h:("dirty"===t.status&&r.dirty(),e(t.value),{status:r.value,value:t.value})}return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then((t=>"aborted"===t.status?h:("dirty"===t.status&&r.dirty(),e(t.value).then((()=>({status:r.value,value:t.value}))))))}if("transform"===a.type){if(!1===s.common.async){const e=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});if(!y(e))return e;const t=a.transform(e.value,n);if(t instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:t}}return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then((e=>y(e)?Promise.resolve(a.transform(e.value,n)).then((e=>({status:r.value,value:e}))):e))}t.assertNever(a)}}Pe.create=(e,t,r)=>new Pe({schema:e,typeName:He.ZodEffects,effect:t,...j(r)}),Pe.createWithPreprocess=(e,t,r)=>new Pe({schema:t,effect:{type:"preprocess",transform:e},typeName:He.ZodEffects,...j(r)});class Ce extends P{_parse(e){return this._getType(e)===s.undefined?f(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Ce.create=(e,t)=>new Ce({innerType:e,typeName:He.ZodOptional,...j(t)});class Oe extends P{_parse(e){return this._getType(e)===s.null?f(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Oe.create=(e,t)=>new Oe({innerType:e,typeName:He.ZodNullable,...j(t)});class Ie extends P{_parse(e){const{ctx:t}=this._processInputParams(e);let r=t.data;return t.parsedType===s.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}Ie.create=(e,t)=>new Ie({innerType:e,typeName:He.ZodDefault,defaultValue:"function"==typeof t.default?t.default:()=>t.default,...j(t)});class Ae extends P{_parse(e){const{ctx:t}=this._processInputParams(e),r={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return _(s)?s.then((e=>({status:"valid",value:"valid"===e.status?e.value:this._def.catchValue({get error(){return new i(r.common.issues)},input:r.data})}))):{status:"valid",value:"valid"===s.status?s.value:this._def.catchValue({get error(){return new i(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Ae.create=(e,t)=>new Ae({innerType:e,typeName:He.ZodCatch,catchValue:"function"==typeof t.catch?t.catch:()=>t.catch,...j(t)});class Re extends P{_parse(e){if(this._getType(e)!==s.nan){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.nan,received:t.parsedType}),h}return{status:"valid",value:e.data}}}Re.create=e=>new Re({typeName:He.ZodNaN,...j(e)});const Ee=Symbol("zod_brand");class Ne extends P{_parse(e){const{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}class $e extends P{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const e=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return"aborted"===e.status?h:"dirty"===e.status?(t.dirty(),m(e.value)):this._def.out._parseAsync({data:e.value,path:r.path,parent:r})})();{const e=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return"aborted"===e.status?h:"dirty"===e.status?(t.dirty(),{status:"dirty",value:e.value}):this._def.out._parseSync({data:e.value,path:r.path,parent:r})}}static create(e,t){return new $e({in:e,out:t,typeName:He.ZodPipeline})}}class Me extends P{_parse(e){const t=this._def.innerType._parse(e),r=e=>(y(e)&&(e.value=Object.freeze(e.value)),e);return _(t)?t.then((e=>r(e))):r(t)}unwrap(){return this._def.innerType}}function qe(e,t){const r="function"==typeof e?e(t):"string"==typeof e?{message:e}:e;return"string"==typeof r?{message:r}:r}function Le(e,t={},r){return e?ne.create().superRefine(((s,a)=>{var n,i;const o=e(s);if(o instanceof Promise)return o.then((e=>{var n,i;if(!e){const e=qe(t,s),o=null===(i=null!==(n=e.fatal)&&void 0!==n?n:r)||void 0===i||i;a.addIssue({code:"custom",...e,fatal:o})}}));if(!o){const e=qe(t,s),o=null===(i=null!==(n=e.fatal)&&void 0!==n?n:r)||void 0===i||i;a.addIssue({code:"custom",...e,fatal:o})}})):ne.create()}Me.create=(e,t)=>new Me({innerType:e,typeName:He.ZodReadonly,...j(t)});const ze={object:le.lazycreate};var He;!function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"}(He||(He={}));const Fe=Y.create,De=X.create,Ue=Re.create,Ve=Q.create,Be=ee.create,Ke=te.create,We=re.create,Je=se.create,Ye=ae.create,Ge=ne.create,Xe=ie.create,Qe=oe.create,et=de.create,tt=ce.create,rt=le.create,st=le.strictCreate,at=pe.create,nt=me.create,it=ge.create,ot=ve.create,dt=ye.create,ct=_e.create,ut=be.create,lt=xe.create,pt=ke.create,ht=we.create,mt=Se.create,ft=Ze.create,gt=je.create,vt=Pe.create,yt=Ce.create,_t=Oe.create,bt=Pe.createWithPreprocess,xt=$e.create,kt={string:e=>Y.create({...e,coerce:!0}),number:e=>X.create({...e,coerce:!0}),boolean:e=>ee.create({...e,coerce:!0}),bigint:e=>Q.create({...e,coerce:!0}),date:e=>te.create({...e,coerce:!0})},wt=h;var Tt=Object.freeze({__proto__:null,defaultErrorMap:o,setErrorMap:function(e){d=e},getErrorMap:c,makeIssue:u,EMPTY_PATH:[],addIssueToContext:l,ParseStatus:p,INVALID:h,DIRTY:m,OK:f,isAborted:g,isDirty:v,isValid:y,isAsync:_,get util(){return t},get objectUtil(){return r},ZodParsedType:s,getParsedType:a,ZodType:P,datetimeRegex:K,ZodString:Y,ZodNumber:X,ZodBigInt:Q,ZodBoolean:ee,ZodDate:te,ZodSymbol:re,ZodUndefined:se,ZodNull:ae,ZodAny:ne,ZodUnknown:ie,ZodNever:oe,ZodVoid:de,ZodArray:ce,ZodObject:le,ZodUnion:pe,ZodDiscriminatedUnion:me,ZodIntersection:ge,ZodTuple:ve,ZodRecord:ye,ZodMap:_e,ZodSet:be,ZodFunction:xe,ZodLazy:ke,ZodLiteral:we,ZodEnum:Se,ZodNativeEnum:Ze,ZodPromise:je,ZodEffects:Pe,ZodTransformer:Pe,ZodOptional:Ce,ZodNullable:Oe,ZodDefault:Ie,ZodCatch:Ae,ZodNaN:Re,BRAND:Ee,ZodBranded:Ne,ZodPipeline:$e,ZodReadonly:Me,custom:Le,Schema:P,ZodSchema:P,late:ze,get ZodFirstPartyTypeKind(){return He},coerce:kt,any:Ge,array:tt,bigint:Ve,boolean:Be,date:Ke,discriminatedUnion:nt,effect:vt,enum:mt,function:lt,instanceof:(e,t={message:`Input not instance of ${e.name}`})=>Le((t=>t instanceof e),t),intersection:it,lazy:pt,literal:ht,map:ct,nan:Ue,nativeEnum:ft,never:Qe,null:Ye,nullable:_t,number:De,object:rt,oboolean:()=>Be().optional(),onumber:()=>De().optional(),optional:yt,ostring:()=>Fe().optional(),pipeline:xt,preprocess:bt,promise:gt,record:dt,set:ut,strictObject:st,string:Fe,symbol:We,transformer:vt,tuple:ot,undefined:Je,union:at,unknown:Xe,void:et,NEVER:wt,ZodIssueCode:n,quotelessJson:e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:"),ZodError:i});const St="2025-03-26",Zt=[St,"2024-11-05","2024-10-07"],jt="2.0",Pt=Tt.union([Tt.string(),Tt.number().int()]),Ct=Tt.string(),Ot=Tt.object({progressToken:Tt.optional(Pt)}).passthrough(),It=Tt.object({_meta:Tt.optional(Ot)}).passthrough(),At=Tt.object({method:Tt.string(),params:Tt.optional(It)}),Rt=Tt.object({_meta:Tt.optional(Tt.object({}).passthrough())}).passthrough(),Et=Tt.object({method:Tt.string(),params:Tt.optional(Rt)}),Nt=Tt.object({_meta:Tt.optional(Tt.object({}).passthrough())}).passthrough(),$t=Tt.union([Tt.string(),Tt.number().int()]),Mt=Tt.object({jsonrpc:Tt.literal(jt),id:$t}).merge(At).strict(),qt=Tt.object({jsonrpc:Tt.literal(jt)}).merge(Et).strict(),Lt=Tt.object({jsonrpc:Tt.literal(jt),id:$t,result:Nt}).strict(),zt=e=>Lt.safeParse(e).success;var Ht;!function(e){e[e.ConnectionClosed=-32e3]="ConnectionClosed",e[e.RequestTimeout=-32001]="RequestTimeout",e[e.ParseError=-32700]="ParseError",e[e.InvalidRequest=-32600]="InvalidRequest",e[e.MethodNotFound=-32601]="MethodNotFound",e[e.InvalidParams=-32602]="InvalidParams",e[e.InternalError=-32603]="InternalError"}(Ht||(Ht={}));const Ft=Tt.object({jsonrpc:Tt.literal(jt),id:$t,error:Tt.object({code:Tt.number().int(),message:Tt.string(),data:Tt.optional(Tt.unknown())})}).strict(),Dt=Tt.union([Mt,qt,Lt,Ft]),Ut=Nt.strict(),Vt=Et.extend({method:Tt.literal("notifications/cancelled"),params:Rt.extend({requestId:$t,reason:Tt.string().optional()})}),Bt=Tt.object({name:Tt.string(),version:Tt.string()}).passthrough(),Kt=Tt.object({experimental:Tt.optional(Tt.object({}).passthrough()),sampling:Tt.optional(Tt.object({}).passthrough()),roots:Tt.optional(Tt.object({listChanged:Tt.optional(Tt.boolean())}).passthrough())}).passthrough(),Wt=At.extend({method:Tt.literal("initialize"),params:It.extend({protocolVersion:Tt.string(),capabilities:Kt,clientInfo:Bt})}),Jt=Tt.object({experimental:Tt.optional(Tt.object({}).passthrough()),logging:Tt.optional(Tt.object({}).passthrough()),completions:Tt.optional(Tt.object({}).passthrough()),prompts:Tt.optional(Tt.object({listChanged:Tt.optional(Tt.boolean())}).passthrough()),resources:Tt.optional(Tt.object({subscribe:Tt.optional(Tt.boolean()),listChanged:Tt.optional(Tt.boolean())}).passthrough()),tools:Tt.optional(Tt.object({listChanged:Tt.optional(Tt.boolean())}).passthrough())}).passthrough(),Yt=Nt.extend({protocolVersion:Tt.string(),capabilities:Jt,serverInfo:Bt,instructions:Tt.optional(Tt.string())}),Gt=Et.extend({method:Tt.literal("notifications/initialized")}),Xt=At.extend({method:Tt.literal("ping")}),Qt=Tt.object({progress:Tt.number(),total:Tt.optional(Tt.number())}).passthrough(),er=Et.extend({method:Tt.literal("notifications/progress"),params:Rt.merge(Qt).extend({progressToken:Pt})}),tr=At.extend({params:It.extend({cursor:Tt.optional(Ct)}).optional()}),rr=Nt.extend({nextCursor:Tt.optional(Ct)}),sr=Tt.object({uri:Tt.string(),mimeType:Tt.optional(Tt.string())}).passthrough(),ar=sr.extend({text:Tt.string()}),nr=sr.extend({blob:Tt.string().base64()}),ir=Tt.object({uri:Tt.string(),name:Tt.string(),description:Tt.optional(Tt.string()),mimeType:Tt.optional(Tt.string())}).passthrough(),or=Tt.object({uriTemplate:Tt.string(),name:Tt.string(),description:Tt.optional(Tt.string()),mimeType:Tt.optional(Tt.string())}).passthrough(),dr=tr.extend({method:Tt.literal("resources/list")}),cr=rr.extend({resources:Tt.array(ir)}),ur=tr.extend({method:Tt.literal("resources/templates/list")}),lr=rr.extend({resourceTemplates:Tt.array(or)}),pr=At.extend({method:Tt.literal("resources/read"),params:It.extend({uri:Tt.string()})}),hr=Nt.extend({contents:Tt.array(Tt.union([ar,nr]))}),mr=Et.extend({method:Tt.literal("notifications/resources/list_changed")}),fr=At.extend({method:Tt.literal("resources/subscribe"),params:It.extend({uri:Tt.string()})}),gr=At.extend({method:Tt.literal("resources/unsubscribe"),params:It.extend({uri:Tt.string()})}),vr=Et.extend({method:Tt.literal("notifications/resources/updated"),params:Rt.extend({uri:Tt.string()})}),yr=Tt.object({name:Tt.string(),description:Tt.optional(Tt.string()),required:Tt.optional(Tt.boolean())}).passthrough(),_r=Tt.object({name:Tt.string(),description:Tt.optional(Tt.string()),arguments:Tt.optional(Tt.array(yr))}).passthrough(),br=tr.extend({method:Tt.literal("prompts/list")}),xr=rr.extend({prompts:Tt.array(_r)}),kr=At.extend({method:Tt.literal("prompts/get"),params:It.extend({name:Tt.string(),arguments:Tt.optional(Tt.record(Tt.string()))})}),wr=Tt.object({type:Tt.literal("text"),text:Tt.string()}).passthrough(),Tr=Tt.object({type:Tt.literal("image"),data:Tt.string().base64(),mimeType:Tt.string()}).passthrough(),Sr=Tt.object({type:Tt.literal("audio"),data:Tt.string().base64(),mimeType:Tt.string()}).passthrough(),Zr=Tt.object({type:Tt.literal("resource"),resource:Tt.union([ar,nr])}).passthrough(),jr=Tt.object({role:Tt.enum(["user","assistant"]),content:Tt.union([wr,Tr,Sr,Zr])}).passthrough(),Pr=Nt.extend({description:Tt.optional(Tt.string()),messages:Tt.array(jr)}),Cr=Et.extend({method:Tt.literal("notifications/prompts/list_changed")}),Or=Tt.object({title:Tt.optional(Tt.string()),readOnlyHint:Tt.optional(Tt.boolean()),destructiveHint:Tt.optional(Tt.boolean()),idempotentHint:Tt.optional(Tt.boolean()),openWorldHint:Tt.optional(Tt.boolean())}).passthrough(),Ir=Tt.object({name:Tt.string(),description:Tt.optional(Tt.string()),inputSchema:Tt.object({type:Tt.literal("object"),properties:Tt.optional(Tt.object({}).passthrough()),required:Tt.optional(Tt.array(Tt.string()))}).passthrough(),outputSchema:Tt.optional(Tt.object({type:Tt.literal("object"),properties:Tt.optional(Tt.object({}).passthrough()),required:Tt.optional(Tt.array(Tt.string()))}).passthrough()),annotations:Tt.optional(Or)}).passthrough(),Ar=tr.extend({method:Tt.literal("tools/list")}),Rr=rr.extend({tools:Tt.array(Ir)}),Er=Tt.array(Tt.union([wr,Tr,Sr,Zr])),Nr=Nt.extend({content:Er,structuredContent:Tt.never().optional(),isError:Tt.optional(Tt.boolean())}),$r=Nt.extend({structuredContent:Tt.object({}).passthrough(),content:Tt.optional(Er),isError:Tt.optional(Tt.boolean())}),Mr=Tt.union([Nr,$r]),qr=(Mr.or(Nt.extend({toolResult:Tt.unknown()})),At.extend({method:Tt.literal("tools/call"),params:It.extend({name:Tt.string(),arguments:Tt.optional(Tt.record(Tt.unknown()))})})),Lr=Et.extend({method:Tt.literal("notifications/tools/list_changed")}),zr=Tt.enum(["debug","info","notice","warning","error","critical","alert","emergency"]),Hr=At.extend({method:Tt.literal("logging/setLevel"),params:It.extend({level:zr})}),Fr=Et.extend({method:Tt.literal("notifications/message"),params:Rt.extend({level:zr,logger:Tt.optional(Tt.string()),data:Tt.unknown()})}),Dr=Tt.object({name:Tt.string().optional()}).passthrough(),Ur=Tt.object({hints:Tt.optional(Tt.array(Dr)),costPriority:Tt.optional(Tt.number().min(0).max(1)),speedPriority:Tt.optional(Tt.number().min(0).max(1)),intelligencePriority:Tt.optional(Tt.number().min(0).max(1))}).passthrough(),Vr=Tt.object({role:Tt.enum(["user","assistant"]),content:Tt.union([wr,Tr,Sr])}).passthrough(),Br=At.extend({method:Tt.literal("sampling/createMessage"),params:It.extend({messages:Tt.array(Vr),systemPrompt:Tt.optional(Tt.string()),includeContext:Tt.optional(Tt.enum(["none","thisServer","allServers"])),temperature:Tt.optional(Tt.number()),maxTokens:Tt.number().int(),stopSequences:Tt.optional(Tt.array(Tt.string())),metadata:Tt.optional(Tt.object({}).passthrough()),modelPreferences:Tt.optional(Ur)})}),Kr=Nt.extend({model:Tt.string(),stopReason:Tt.optional(Tt.enum(["endTurn","stopSequence","maxTokens"]).or(Tt.string())),role:Tt.enum(["user","assistant"]),content:Tt.discriminatedUnion("type",[wr,Tr,Sr])}),Wr=Tt.object({type:Tt.literal("ref/resource"),uri:Tt.string()}).passthrough(),Jr=Tt.object({type:Tt.literal("ref/prompt"),name:Tt.string()}).passthrough(),Yr=At.extend({method:Tt.literal("completion/complete"),params:It.extend({ref:Tt.union([Jr,Wr]),argument:Tt.object({name:Tt.string(),value:Tt.string()}).passthrough()})}),Gr=Nt.extend({completion:Tt.object({values:Tt.array(Tt.string()).max(100),total:Tt.optional(Tt.number().int()),hasMore:Tt.optional(Tt.boolean())}).passthrough()}),Xr=Tt.object({uri:Tt.string().startsWith("file://"),name:Tt.optional(Tt.string())}).passthrough(),Qr=At.extend({method:Tt.literal("roots/list")}),es=Nt.extend({roots:Tt.array(Xr)}),ts=Et.extend({method:Tt.literal("notifications/roots/list_changed")});Tt.union([Xt,Wt,Yr,Hr,kr,br,dr,ur,pr,fr,gr,qr,Ar]),Tt.union([Vt,er,Gt,ts]),Tt.union([Ut,Kr,es]),Tt.union([Xt,Br,Qr]),Tt.union([Vt,er,Fr,vr,mr,Lr,Cr]),Tt.union([Ut,Yt,Gr,Pr,xr,cr,lr,hr,Mr,Rr]);class rs extends Error{constructor(e,t,r){super(`MCP error ${e}: ${t}`),this.code=e,this.data=r,this.name="McpError"}}class ss{append(e){this._buffer=this._buffer?Buffer.concat([this._buffer,e]):e}readMessage(){if(!this._buffer)return null;const e=this._buffer.indexOf("\n");if(-1===e)return null;const t=this._buffer.toString("utf8",0,e).replace(/\r$/,"");return this._buffer=this._buffer.subarray(e+1),function(e){return Dt.parse(JSON.parse(e))}(t)}clear(){this._buffer=void 0}}class as{constructor(t=e.stdin,r=e.stdout){this._stdin=t,this._stdout=r,this._readBuffer=new ss,this._started=!1,this._ondata=e=>{this._readBuffer.append(e),this.processReadBuffer()},this._onerror=e=>{var t;null===(t=this.onerror)||void 0===t||t.call(this,e)}}async start(){if(this._started)throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");this._started=!0,this._stdin.on("data",this._ondata),this._stdin.on("error",this._onerror)}processReadBuffer(){for(var e,t;;)try{const t=this._readBuffer.readMessage();if(null===t)break;null===(e=this.onmessage)||void 0===e||e.call(this,t)}catch(e){null===(t=this.onerror)||void 0===t||t.call(this,e)}}async close(){var e;this._stdin.off("data",this._ondata),this._stdin.off("error",this._onerror),0===this._stdin.listenerCount("data")&&this._stdin.pause(),this._readBuffer.clear(),null===(e=this.onclose)||void 0===e||e.call(this)}send(e){return new Promise((t=>{const r=function(e){return JSON.stringify(e)+"\n"}(e);this._stdout.write(r)?t():this._stdout.once("drain",t)}))}}class ns{constructor(e){this._options=e,this._requestMessageId=0,this._requestHandlers=new Map,this._requestHandlerAbortControllers=new Map,this._notificationHandlers=new Map,this._responseHandlers=new Map,this._progressHandlers=new Map,this._timeoutInfo=new Map,this.setNotificationHandler(Vt,(e=>{const t=this._requestHandlerAbortControllers.get(e.params.requestId);null==t||t.abort(e.params.reason)})),this.setNotificationHandler(er,(e=>{this._onprogress(e)})),this.setRequestHandler(Xt,(e=>({})))}_setupTimeout(e,t,r,s,a=!1){this._timeoutInfo.set(e,{timeoutId:setTimeout(s,t),startTime:Date.now(),timeout:t,maxTotalTimeout:r,resetTimeoutOnProgress:a,onTimeout:s})}_resetTimeout(e){const t=this._timeoutInfo.get(e);if(!t)return!1;const r=Date.now()-t.startTime;if(t.maxTotalTimeout&&r>=t.maxTotalTimeout)throw this._timeoutInfo.delete(e),new rs(Ht.RequestTimeout,"Maximum total timeout exceeded",{maxTotalTimeout:t.maxTotalTimeout,totalElapsed:r});return clearTimeout(t.timeoutId),t.timeoutId=setTimeout(t.onTimeout,t.timeout),!0}_cleanupTimeout(e){const t=this._timeoutInfo.get(e);t&&(clearTimeout(t.timeoutId),this._timeoutInfo.delete(e))}async connect(e){this._transport=e,this._transport.onclose=()=>{this._onclose()},this._transport.onerror=e=>{this._onerror(e)},this._transport.onmessage=(e,t)=>{var r;zt(e)||(r=e,Ft.safeParse(r).success)?this._onresponse(e):(e=>Mt.safeParse(e).success)(e)?this._onrequest(e,t):(e=>qt.safeParse(e).success)(e)?this._onnotification(e):this._onerror(new Error(`Unknown message type: ${JSON.stringify(e)}`))},await this._transport.start()}_onclose(){var e;const t=this._responseHandlers;this._responseHandlers=new Map,this._progressHandlers.clear(),this._transport=void 0,null===(e=this.onclose)||void 0===e||e.call(this);const r=new rs(Ht.ConnectionClosed,"Connection closed");for(const e of t.values())e(r)}_onerror(e){var t;null===(t=this.onerror)||void 0===t||t.call(this,e)}_onnotification(e){var t;const r=null!==(t=this._notificationHandlers.get(e.method))&&void 0!==t?t:this.fallbackNotificationHandler;void 0!==r&&Promise.resolve().then((()=>r(e))).catch((e=>this._onerror(new Error(`Uncaught error in notification handler: ${e}`))))}_onrequest(e,t){var r,s,a,n;const i=null!==(r=this._requestHandlers.get(e.method))&&void 0!==r?r:this.fallbackRequestHandler;if(void 0===i)return void(null===(s=this._transport)||void 0===s||s.send({jsonrpc:"2.0",id:e.id,error:{code:Ht.MethodNotFound,message:"Method not found"}}).catch((e=>this._onerror(new Error(`Failed to send an error response: ${e}`)))));const o=new AbortController;this._requestHandlerAbortControllers.set(e.id,o);const d={signal:o.signal,sessionId:null===(a=this._transport)||void 0===a?void 0:a.sessionId,_meta:null===(n=e.params)||void 0===n?void 0:n._meta,sendNotification:t=>this.notification(t,{relatedRequestId:e.id}),sendRequest:(t,r,s)=>this.request(t,r,{...s,relatedRequestId:e.id}),authInfo:null==t?void 0:t.authInfo,requestId:e.id};Promise.resolve().then((()=>i(e,d))).then((t=>{var r;if(!o.signal.aborted)return null===(r=this._transport)||void 0===r?void 0:r.send({result:t,jsonrpc:"2.0",id:e.id})}),(t=>{var r,s;if(!o.signal.aborted)return null===(r=this._transport)||void 0===r?void 0:r.send({jsonrpc:"2.0",id:e.id,error:{code:Number.isSafeInteger(t.code)?t.code:Ht.InternalError,message:null!==(s=t.message)&&void 0!==s?s:"Internal error"}})})).catch((e=>this._onerror(new Error(`Failed to send response: ${e}`)))).finally((()=>{this._requestHandlerAbortControllers.delete(e.id)}))}_onprogress(e){const{progressToken:t,...r}=e.params,s=Number(t),a=this._progressHandlers.get(s);if(!a)return void this._onerror(new Error(`Received a progress notification for an unknown token: ${JSON.stringify(e)}`));const n=this._responseHandlers.get(s),i=this._timeoutInfo.get(s);if(i&&n&&i.resetTimeoutOnProgress)try{this._resetTimeout(s)}catch(e){return void n(e)}a(r)}_onresponse(e){const t=Number(e.id),r=this._responseHandlers.get(t);void 0!==r?(this._responseHandlers.delete(t),this._progressHandlers.delete(t),this._cleanupTimeout(t),zt(e)?r(e):r(new rs(e.error.code,e.error.message,e.error.data))):this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(e)}`))}get transport(){return this._transport}async close(){var e;await(null===(e=this._transport)||void 0===e?void 0:e.close())}request(e,t,r){const{relatedRequestId:s,resumptionToken:a,onresumptiontoken:n}=null!=r?r:{};return new Promise(((i,o)=>{var d,c,u,l,p;if(!this._transport)return void o(new Error("Not connected"));!0===(null===(d=this._options)||void 0===d?void 0:d.enforceStrictCapabilities)&&this.assertCapabilityForMethod(e.method),null===(c=null==r?void 0:r.signal)||void 0===c||c.throwIfAborted();const h=this._requestMessageId++,m={...e,jsonrpc:"2.0",id:h};(null==r?void 0:r.onprogress)&&(this._progressHandlers.set(h,r.onprogress),m.params={...e.params,_meta:{progressToken:h}});const f=e=>{var t;this._responseHandlers.delete(h),this._progressHandlers.delete(h),this._cleanupTimeout(h),null===(t=this._transport)||void 0===t||t.send({jsonrpc:"2.0",method:"notifications/cancelled",params:{requestId:h,reason:String(e)}},{relatedRequestId:s,resumptionToken:a,onresumptiontoken:n}).catch((e=>this._onerror(new Error(`Failed to send cancellation: ${e}`)))),o(e)};this._responseHandlers.set(h,(e=>{var s;if(!(null===(s=null==r?void 0:r.signal)||void 0===s?void 0:s.aborted)){if(e instanceof Error)return o(e);try{const r=t.parse(e.result);i(r)}catch(e){o(e)}}})),null===(u=null==r?void 0:r.signal)||void 0===u||u.addEventListener("abort",(()=>{var e;f(null===(e=null==r?void 0:r.signal)||void 0===e?void 0:e.reason)}));const g=null!==(l=null==r?void 0:r.timeout)&&void 0!==l?l:6e4;this._setupTimeout(h,g,null==r?void 0:r.maxTotalTimeout,(()=>f(new rs(Ht.RequestTimeout,"Request timed out",{timeout:g}))),null!==(p=null==r?void 0:r.resetTimeoutOnProgress)&&void 0!==p&&p),this._transport.send(m,{relatedRequestId:s,resumptionToken:a,onresumptiontoken:n}).catch((e=>{this._cleanupTimeout(h),o(e)}))}))}async notification(e,t){if(!this._transport)throw new Error("Not connected");this.assertNotificationCapability(e.method);const r={...e,jsonrpc:"2.0"};await this._transport.send(r,t)}setRequestHandler(e,t){const r=e.shape.method.value;this.assertRequestHandlerCapability(r),this._requestHandlers.set(r,((r,s)=>Promise.resolve(t(e.parse(r),s))))}removeRequestHandler(e){this._requestHandlers.delete(e)}assertCanSetRequestHandler(e){if(this._requestHandlers.has(e))throw new Error(`A request handler for ${e} already exists, which would be overridden`)}setNotificationHandler(e,t){this._notificationHandlers.set(e.shape.method.value,(r=>Promise.resolve(t(e.parse(r)))))}removeNotificationHandler(e){this._notificationHandlers.delete(e)}}class is extends ns{constructor(e,t){var r;super(t),this._serverInfo=e,this._capabilities=null!==(r=null==t?void 0:t.capabilities)&&void 0!==r?r:{},this._instructions=null==t?void 0:t.instructions,this.setRequestHandler(Wt,(e=>this._oninitialize(e))),this.setNotificationHandler(Gt,(()=>{var e;return null===(e=this.oninitialized)||void 0===e?void 0:e.call(this)}))}registerCapabilities(e){if(this.transport)throw new Error("Cannot register capabilities after connecting to transport");var t,r;this._capabilities=(t=this._capabilities,r=e,Object.entries(r).reduce(((e,[t,r])=>(e[t]=r&&"object"==typeof r&&e[t]?{...e[t],...r}:r,e)),{...t}))}assertCapabilityForMethod(e){var t,r;switch(e){case"sampling/createMessage":if(!(null===(t=this._clientCapabilities)||void 0===t?void 0:t.sampling))throw new Error(`Client does not support sampling (required for ${e})`);break;case"roots/list":if(!(null===(r=this._clientCapabilities)||void 0===r?void 0:r.roots))throw new Error(`Client does not support listing roots (required for ${e})`)}}assertNotificationCapability(e){switch(e){case"notifications/message":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"notifications/resources/updated":case"notifications/resources/list_changed":if(!this._capabilities.resources)throw new Error(`Server does not support notifying about resources (required for ${e})`);break;case"notifications/tools/list_changed":if(!this._capabilities.tools)throw new Error(`Server does not support notifying of tool list changes (required for ${e})`);break;case"notifications/prompts/list_changed":if(!this._capabilities.prompts)throw new Error(`Server does not support notifying of prompt list changes (required for ${e})`)}}assertRequestHandlerCapability(e){switch(e){case"sampling/createMessage":if(!this._capabilities.sampling)throw new Error(`Server does not support sampling (required for ${e})`);break;case"logging/setLevel":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"prompts/get":case"prompts/list":if(!this._capabilities.prompts)throw new Error(`Server does not support prompts (required for ${e})`);break;case"resources/list":case"resources/templates/list":case"resources/read":if(!this._capabilities.resources)throw new Error(`Server does not support resources (required for ${e})`);break;case"tools/call":case"tools/list":if(!this._capabilities.tools)throw new Error(`Server does not support tools (required for ${e})`)}}async _oninitialize(e){const t=e.params.protocolVersion;return this._clientCapabilities=e.params.capabilities,this._clientVersion=e.params.clientInfo,{protocolVersion:Zt.includes(t)?t:St,capabilities:this.getCapabilities(),serverInfo:this._serverInfo,...this._instructions&&{instructions:this._instructions}}}getClientCapabilities(){return this._clientCapabilities}getClientVersion(){return this._clientVersion}getCapabilities(){return this._capabilities}async ping(){return this.request({method:"ping"},Ut)}async createMessage(e,t){return this.request({method:"sampling/createMessage",params:e},Kr,t)}async listRoots(e,t){return this.request({method:"roots/list",params:e},es,t)}async sendLoggingMessage(e){return this.notification({method:"notifications/message",params:e})}async sendResourceUpdated(e){return this.notification({method:"notifications/resources/updated",params:e})}async sendResourceListChanged(){return this.notification({method:"notifications/resources/list_changed"})}async sendToolListChanged(){return this.notification({method:"notifications/tools/list_changed"})}async sendPromptListChanged(){return this.notification({method:"notifications/prompts/list_changed"})}}const os=Symbol("Let zodToJsonSchema decide on which parser to use"),ds={name:void 0,$refStrategy:"root",basePath:["#"],effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",removeAdditionalStrategy:"passthrough",allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:"definitions",target:"jsonSchema7",strictUnions:!1,definitions:{},errorMessages:!1,markdownDescription:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref"};function cs(e,t,r,s){s?.errorMessages&&r&&(e.errorMessage={...e.errorMessage,[t]:r})}function us(e,t,r,s,a){e[t]=r,cs(e,t,s,a)}function ls(e,t){return $s(e.type._def,t)}function ps(e,t,r){const s=r??t.dateStrategy;if(Array.isArray(s))return{anyOf:s.map(((r,s)=>ps(e,t,r)))};switch(s){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":return hs(e,t)}}const hs=(e,t)=>{const r={type:"integer",format:"unix-time"};if("openApi3"===t.target)return r;for(const s of e.checks)switch(s.kind){case"min":us(r,"minimum",s.value,s.message,t);break;case"max":us(r,"maximum",s.value,s.message,t)}return r};let ms;const fs=/^[cC][^\s-]{8,}$/,gs=/^[0-9a-z]+$/,vs=/^[0-9A-HJKMNP-TV-Z]{26}$/,ys=/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,_s=/^(?:(?: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])$/,bs=/^(([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])$/,xs=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,ks=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,ws=/^[a-zA-Z0-9_-]{21}$/,Ts=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;function Ss(e,t){const r={type:"string"};if(e.checks)for(const s of e.checks)switch(s.kind){case"min":us(r,"minLength","number"==typeof r.minLength?Math.max(r.minLength,s.value):s.value,s.message,t);break;case"max":us(r,"maxLength","number"==typeof r.maxLength?Math.min(r.maxLength,s.value):s.value,s.message,t);break;case"email":switch(t.emailStrategy){case"format:email":Ps(r,"email",s.message,t);break;case"format:idn-email":Ps(r,"idn-email",s.message,t);break;case"pattern:zod":Cs(r,ys,s.message,t)}break;case"url":Ps(r,"uri",s.message,t);break;case"uuid":Ps(r,"uuid",s.message,t);break;case"regex":Cs(r,s.regex,s.message,t);break;case"cuid":Cs(r,fs,s.message,t);break;case"cuid2":Cs(r,gs,s.message,t);break;case"startsWith":Cs(r,RegExp(`^${Zs(s.value,t)}`),s.message,t);break;case"endsWith":Cs(r,RegExp(`${Zs(s.value,t)}$`),s.message,t);break;case"datetime":Ps(r,"date-time",s.message,t);break;case"date":Ps(r,"date",s.message,t);break;case"time":Ps(r,"time",s.message,t);break;case"duration":Ps(r,"duration",s.message,t);break;case"length":us(r,"minLength","number"==typeof r.minLength?Math.max(r.minLength,s.value):s.value,s.message,t),us(r,"maxLength","number"==typeof r.maxLength?Math.min(r.maxLength,s.value):s.value,s.message,t);break;case"includes":Cs(r,RegExp(Zs(s.value,t)),s.message,t);break;case"ip":"v6"!==s.version&&Ps(r,"ipv4",s.message,t),"v4"!==s.version&&Ps(r,"ipv6",s.message,t);break;case"base64url":Cs(r,ks,s.message,t);break;case"jwt":Cs(r,Ts,s.message,t);break;case"cidr":"v6"!==s.version&&Cs(r,_s,s.message,t),"v4"!==s.version&&Cs(r,bs,s.message,t);break;case"emoji":Cs(r,(void 0===ms&&(ms=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),ms),s.message,t);break;case"ulid":Cs(r,vs,s.message,t);break;case"base64":switch(t.base64Strategy){case"format:binary":Ps(r,"binary",s.message,t);break;case"contentEncoding:base64":us(r,"contentEncoding","base64",s.message,t);break;case"pattern:zod":Cs(r,xs,s.message,t)}break;case"nanoid":Cs(r,ws,s.message,t)}return r}function Zs(e,t){return"escape"===t.patternStrategy?function(e){let t="";for(let r=0;r<e.length;r++)js.has(e[r])||(t+="\\"),t+=e[r];return t}(e):e}const js=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function Ps(e,t,r,s){e.format||e.anyOf?.some((e=>e.format))?(e.anyOf||(e.anyOf=[]),e.format&&(e.anyOf.push({format:e.format,...e.errorMessage&&s.errorMessages&&{errorMessage:{format:e.errorMessage.format}}}),delete e.format,e.errorMessage&&(delete e.errorMessage.format,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.anyOf.push({format:t,...r&&s.errorMessages&&{errorMessage:{format:r}}})):us(e,"format",t,r,s)}function Cs(e,t,r,s){e.pattern||e.allOf?.some((e=>e.pattern))?(e.allOf||(e.allOf=[]),e.pattern&&(e.allOf.push({pattern:e.pattern,...e.errorMessage&&s.errorMessages&&{errorMessage:{pattern:e.errorMessage.pattern}}}),delete e.pattern,e.errorMessage&&(delete e.errorMessage.pattern,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.allOf.push({pattern:Os(t,s),...r&&s.errorMessages&&{errorMessage:{pattern:r}}})):us(e,"pattern",Os(t,s),r,s)}function Os(e,t){if(!t.applyRegexFlags||!e.flags)return e.source;const r=e.flags.includes("i"),s=e.flags.includes("m"),a=e.flags.includes("s"),n=r?e.source.toLowerCase():e.source;let i="",o=!1,d=!1,c=!1;for(let e=0;e<n.length;e++)if(o)i+=n[e],o=!1;else{if(r)if(d){if(n[e].match(/[a-z]/)){c?(i+=n[e],i+=`${n[e-2]}-${n[e]}`.toUpperCase(),c=!1):"-"===n[e+1]&&n[e+2]?.match(/[a-z]/)?(i+=n[e],c=!0):i+=`${n[e]}${n[e].toUpperCase()}`;continue}}else if(n[e].match(/[a-z]/)){i+=`[${n[e]}${n[e].toUpperCase()}]`;continue}if(s){if("^"===n[e]){i+="(^|(?<=[\r\n]))";continue}if("$"===n[e]){i+="($|(?=[\r\n]))";continue}}a&&"."===n[e]?i+=d?`${n[e]}\r\n`:`[${n[e]}\r\n]`:(i+=n[e],"\\"===n[e]?o=!0:d&&"]"===n[e]?d=!1:d||"["!==n[e]||(d=!0))}try{new RegExp(i)}catch{return console.warn(`Could not convert regex pattern at ${t.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),e.source}return i}function Is(e,t){if("openAi"===t.target&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),"openApi3"===t.target&&e.keyType?._def.typeName===He.ZodEnum)return{type:"object",required:e.keyType._def.values,properties:e.keyType._def.values.reduce(((r,s)=>({...r,[s]:$s(e.valueType._def,{...t,currentPath:[...t.currentPath,"properties",s]})??{}})),{}),additionalProperties:t.rejectedAdditionalProperties};const r={type:"object",additionalProperties:$s(e.valueType._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??t.allowedAdditionalProperties};if("openApi3"===t.target)return r;if(e.keyType?._def.typeName===He.ZodString&&e.keyType._def.checks?.length){const{type:s,...a}=Ss(e.keyType._def,t);return{...r,propertyNames:a}}if(e.keyType?._def.typeName===He.ZodEnum)return{...r,propertyNames:{enum:e.keyType._def.values}};if(e.keyType?._def.typeName===He.ZodBranded&&e.keyType._def.type._def.typeName===He.ZodString&&e.keyType._def.type._def.checks?.length){const{type:s,...a}=ls(e.keyType._def,t);return{...r,propertyNames:a}}return r}const As={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"},Rs=(e,t)=>{const r=(e.options instanceof Map?Array.from(e.options.values()):e.options).map(((e,r)=>$s(e._def,{...t,currentPath:[...t.currentPath,"anyOf",`${r}`]}))).filter((e=>!!e&&(!t.strictUnions||"object"==typeof e&&Object.keys(e).length>0)));return r.length?{anyOf:r}:void 0};function Es(e){try{return e.isOptional()}catch{return!0}}const Ns=(e,t,r)=>{switch(t){case He.ZodString:return Ss(e,r);case He.ZodNumber:return function(e,t){const r={type:"number"};if(!e.checks)return r;for(const s of e.checks)switch(s.kind){case"int":r.type="integer",cs(r,"type",s.message,t);break;case"min":"jsonSchema7"===t.target?s.inclusive?us(r,"minimum",s.value,s.message,t):us(r,"exclusiveMinimum",s.value,s.message,t):(s.inclusive||(r.exclusiveMinimum=!0),us(r,"minimum",s.value,s.message,t));break;case"max":"jsonSchema7"===t.target?s.inclusive?us(r,"maximum",s.value,s.message,t):us(r,"exclusiveMaximum",s.value,s.message,t):(s.inclusive||(r.exclusiveMaximum=!0),us(r,"maximum",s.value,s.message,t));break;case"multipleOf":us(r,"multipleOf",s.value,s.message,t)}return r}(e,r);case He.ZodObject:return function(e,t){const r="openAi"===t.target,s={type:"object",properties:{}},a=[],n=e.shape();for(const e in n){let i=n[e];if(void 0===i||void 0===i._def)continue;let o=Es(i);o&&r&&(i instanceof Ce&&(i=i._def.innerType),i.isNullable()||(i=i.nullable()),o=!1);const d=$s(i._def,{...t,currentPath:[...t.currentPath,"properties",e],propertyPath:[...t.currentPath,"properties",e]});void 0!==d&&(s.properties[e]=d,o||a.push(e))}a.length&&(s.required=a);const i=function(e,t){if("ZodNever"!==e.catchall._def.typeName)return $s(e.catchall._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]});switch(e.unknownKeys){case"passthrough":return t.allowedAdditionalProperties;case"strict":return t.rejectedAdditionalProperties;case"strip":return"strict"===t.removeAdditionalStrategy?t.allowedAdditionalProperties:t.rejectedAdditionalProperties}}(e,t);return void 0!==i&&(s.additionalProperties=i),s}(e,r);case He.ZodBigInt:return function(e,t){const r={type:"integer",format:"int64"};if(!e.checks)return r;for(const s of e.checks)switch(s.kind){case"min":"jsonSchema7"===t.target?s.inclusive?us(r,"minimum",s.value,s.message,t):us(r,"exclusiveMinimum",s.value,s.message,t):(s.inclusive||(r.exclusiveMinimum=!0),us(r,"minimum",s.value,s.message,t));break;case"max":"jsonSchema7"===t.target?s.inclusive?us(r,"maximum",s.value,s.message,t):us(r,"exclusiveMaximum",s.value,s.message,t):(s.inclusive||(r.exclusiveMaximum=!0),us(r,"maximum",s.value,s.message,t));break;case"multipleOf":us(r,"multipleOf",s.value,s.message,t)}return r}(e,r);case He.ZodBoolean:return{type:"boolean"};case He.ZodDate:return ps(e,r);case He.ZodUndefined:return{not:{}};case He.ZodNull:return function(e){return"openApi3"===e.target?{enum:["null"],nullable:!0}:{type:"null"}}(r);case He.ZodArray:return function(e,t){const r={type:"array"};return e.type?._def&&e.type?._def?.typeName!==He.ZodAny&&(r.items=$s(e.type._def,{...t,currentPath:[...t.currentPath,"items"]})),e.minLength&&us(r,"minItems",e.minLength.value,e.minLength.message,t),e.maxLength&&us(r,"maxItems",e.maxLength.value,e.maxLength.message,t),e.exactLength&&(us(r,"minItems",e.exactLength.value,e.exactLength.message,t),us(r,"maxItems",e.exactLength.value,e.exactLength.message,t)),r}(e,r);case He.ZodUnion:case He.ZodDiscriminatedUnion:return function(e,t){if("openApi3"===t.target)return Rs(e,t);const r=e.options instanceof Map?Array.from(e.options.values()):e.options;if(r.every((e=>e._def.typeName in As&&(!e._def.checks||!e._def.checks.length)))){const e=r.reduce(((e,t)=>{const r=As[t._def.typeName];return r&&!e.includes(r)?[...e,r]:e}),[]);return{type:e.length>1?e:e[0]}}if(r.every((e=>"ZodLiteral"===e._def.typeName&&!e.description))){const e=r.reduce(((e,t)=>{const r=typeof t._def.value;switch(r){case"string":case"number":case"boolean":return[...e,r];case"bigint":return[...e,"integer"];case"object":if(null===t._def.value)return[...e,"null"];default:return e}}),[]);if(e.length===r.length){const t=e.filter(((e,t,r)=>r.indexOf(e)===t));return{type:t.length>1?t:t[0],enum:r.reduce(((e,t)=>e.includes(t._def.value)?e:[...e,t._def.value]),[])}}}else if(r.every((e=>"ZodEnum"===e._def.typeName)))return{type:"string",enum:r.reduce(((e,t)=>[...e,...t._def.values.filter((t=>!e.includes(t)))]),[])};return Rs(e,t)}(e,r);case He.ZodIntersection:return function(e,t){const r=[$s(e.left._def,{...t,currentPath:[...t.currentPath,"allOf","0"]}),$s(e.right._def,{...t,currentPath:[...t.currentPath,"allOf","1"]})].filter((e=>!!e));let s="jsonSchema2019-09"===t.target?{unevaluatedProperties:!1}:void 0;const a=[];return r.forEach((e=>{if("type"in(t=e)&&"string"===t.type||!("allOf"in t)){let t=e;if("additionalProperties"in e&&!1===e.additionalProperties){const{additionalProperties:r,...s}=e;t=s}else s=void 0;a.push(t)}else a.push(...e.allOf),void 0===e.unevaluatedProperties&&(s=void 0);var t})),a.length?{allOf:a,...s}:void 0}(e,r);case He.ZodTuple:return function(e,t){return e.rest?{type:"array",minItems:e.items.length,items:e.items.map(((e,r)=>$s(e._def,{...t,currentPath:[...t.currentPath,"items",`${r}`]}))).reduce(((e,t)=>void 0===t?e:[...e,t]),[]),additionalItems:$s(e.rest._def,{...t,currentPath:[...t.currentPath,"additionalItems"]})}:{type:"array",minItems:e.items.length,maxItems:e.items.length,items:e.items.map(((e,r)=>$s(e._def,{...t,currentPath:[...t.currentPath,"items",`${r}`]}))).reduce(((e,t)=>void 0===t?e:[...e,t]),[])}}(e,r);case He.ZodRecord:return Is(e,r);case He.ZodLiteral:return function(e,t){const r=typeof e.value;return"bigint"!==r&&"number"!==r&&"boolean"!==r&&"string"!==r?{type:Array.isArray(e.value)?"array":"object"}:"openApi3"===t.target?{type:"bigint"===r?"integer":r,enum:[e.value]}:{type:"bigint"===r?"integer":r,const:e.value}}(e,r);case He.ZodEnum:return function(e){return{type:"string",enum:Array.from(e.values)}}(e);case He.ZodNativeEnum:return function(e){const t=e.values,r=Object.keys(e.values).filter((e=>"number"!=typeof t[t[e]])).map((e=>t[e])),s=Array.from(new Set(r.map((e=>typeof e))));return{type:1===s.length?"string"===s[0]?"string":"number":["string","number"],enum:r}}(e);case He.ZodNullable:return function(e,t){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(e.innerType._def.typeName)&&(!e.innerType._def.checks||!e.innerType._def.checks.length))return"openApi3"===t.target?{type:As[e.innerType._def.typeName],nullable:!0}:{type:[As[e.innerType._def.typeName],"null"]};if("openApi3"===t.target){const r=$s(e.innerType._def,{...t,currentPath:[...t.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}const r=$s(e.innerType._def,{...t,currentPath:[...t.currentPath,"anyOf","0"]});return r&&{anyOf:[r,{type:"null"}]}}(e,r);case He.ZodOptional:return((e,t)=>{if(t.currentPath.toString()===t.propertyPath?.toString())return $s(e.innerType._def,t);const r=$s(e.innerType._def,{...t,currentPath:[...t.currentPath,"anyOf","1"]});return r?{anyOf:[{not:{}},r]}:{}})(e,r);case He.ZodMap:return function(e,t){return"record"===t.mapStrategy?Is(e,t):{type:"array",maxItems:125,items:{type:"array",items:[$s(e.keyType._def,{...t,currentPath:[...t.currentPath,"items","items","0"]})||{},$s(e.valueType._def,{...t,currentPath:[...t.currentPath,"items","items","1"]})||{}],minItems:2,maxItems:2}}}(e,r);case He.ZodSet:return function(e,t){const r={type:"array",uniqueItems:!0,items:$s(e.valueType._def,{...t,currentPath:[...t.currentPath,"items"]})};return e.minSize&&us(r,"minItems",e.minSize.value,e.minSize.message,t),e.maxSize&&us(r,"maxItems",e.maxSize.value,e.maxSize.message,t),r}(e,r);case He.ZodLazy:return()=>e.getter()._def;case He.ZodPromise:return function(e,t){return $s(e.type._def,t)}(e,r);case He.ZodNaN:case He.ZodNever:return{not:{}};case He.ZodEffects:return function(e,t){return"input"===t.effectStrategy?$s(e.schema._def,t):{}}(e,r);case He.ZodAny:case He.ZodUnknown:return{};case He.ZodDefault:return function(e,t){return{...$s(e.innerType._def,t),default:e.defaultValue()}}(e,r);case He.ZodBranded:return ls(e,r);case He.ZodReadonly:case He.ZodCatch:return((e,t)=>$s(e.innerType._def,t))(e,r);case He.ZodPipeline:return((e,t)=>{if("input"===t.pipeStrategy)return $s(e.in._def,t);if("output"===t.pipeStrategy)return $s(e.out._def,t);const r=$s(e.in._def,{...t,currentPath:[...t.currentPath,"allOf","0"]});return{allOf:[r,$s(e.out._def,{...t,currentPath:[...t.currentPath,"allOf",r?"1":"0"]})].filter((e=>void 0!==e))}})(e,r);case He.ZodFunction:case He.ZodVoid:case He.ZodSymbol:default:return}};function $s(e,t,r=!1){const s=t.seen.get(e);if(t.override){const a=t.override?.(e,t,s,r);if(a!==os)return a}if(s&&!r){const e=Ms(s,t);if(void 0!==e)return e}const a={def:e,path:t.currentPath,jsonSchema:void 0};t.seen.set(e,a);const n=Ns(e,e.typeName,t),i="function"==typeof n?$s(n(),t):n;if(i&&Ls(e,t,i),t.postProcess){const r=t.postProcess(i,e,t);return a.jsonSchema=i,r}return a.jsonSchema=i,i}const Ms=(e,t)=>{switch(t.$refStrategy){case"root":return{$ref:e.path.join("/")};case"relative":return{$ref:qs(t.currentPath,e.path)};case"none":case"seen":return e.path.length<t.currentPath.length&&e.path.every(((e,r)=>t.currentPath[r]===e))?(console.warn(`Recursive reference detected at ${t.currentPath.join("/")}! Defaulting to any`),{}):"seen"===t.$refStrategy?{}:void 0}},qs=(e,t)=>{let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];r++);return[(e.length-r).toString(),...t.slice(r)].join("/")},Ls=(e,t,r)=>(e.description&&(r.description=e.description,t.markdownDescription&&(r.markdownDescription=e.description)),r),zs=(e,t)=>{const r=(e=>{const t=(e=>"string"==typeof e?{...ds,name:e}:{...ds,...e})(e),r=void 0!==t.name?[...t.basePath,t.definitionPath,t.name]:t.basePath;return{...t,currentPath:r,propertyPath:void 0,seen:new Map(Object.entries(t.definitions).map((([e,r])=>[r._def,{def:r._def,path:[...t.basePath,t.definitionPath,e],jsonSchema:void 0}])))}})(t),s="object"==typeof t&&t.definitions?Object.entries(t.definitions).reduce(((e,[t,s])=>({...e,[t]:$s(s._def,{...r,currentPath:[...r.basePath,r.definitionPath,t]},!0)??{}})),{}):void 0,a="string"==typeof t?t:"title"===t?.nameStrategy?void 0:t?.name,n=$s(e._def,void 0===a?r:{...r,currentPath:[...r.basePath,r.definitionPath,a]},!1)??{},i="object"==typeof t&&void 0!==t.name&&"title"===t.nameStrategy?t.name:void 0;void 0!==i&&(n.title=i);const o=void 0===a?s?{...n,[r.definitionPath]:s}:n:{$ref:[..."relative"===r.$refStrategy?[]:r.basePath,r.definitionPath,a].join("/"),[r.definitionPath]:{...s,[a]:n}};return"jsonSchema7"===r.target?o.$schema="http://json-schema.org/draft-07/schema#":"jsonSchema2019-09"!==r.target&&"openAi"!==r.target||(o.$schema="https://json-schema.org/draft/2019-09/schema#"),"openAi"===r.target&&("anyOf"in o||"oneOf"in o||"allOf"in o||"type"in o&&Array.isArray(o.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),o};var Hs;!function(e){e.Completable="McpCompletable"}(Hs||(Hs={}));class Fs extends P{_parse(e){const{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}function Ds(e){if(!e)return{};const{errorMap:t,invalid_type_error:r,required_error:s,description:a}=e;if(t&&(r||s))throw new Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');return t?{errorMap:t,description:a}:{errorMap:(t,a)=>{var n,i;const{message:o}=e;return"invalid_enum_value"===t.code?{message:null!=o?o:a.defaultError}:void 0===a.data?{message:null!==(n=null!=o?o:s)&&void 0!==n?n:a.defaultError}:"invalid_type"!==t.code?{message:a.defaultError}:{message:null!==(i=null!=o?o:r)&&void 0!==i?i:a.defaultError}},description:a}}Fs.create=(e,t)=>new Fs({type:e,typeName:Hs.Completable,complete:t.complete,...Ds(t)});class Us{constructor(e,t){this._registeredResources={},this._registeredResourceTemplates={},this._registeredTools={},this._registeredPrompts={},this._toolHandlersInitialized=!1,this._completionHandlerInitialized=!1,this._resourceHandlersInitialized=!1,this._promptHandlersInitialized=!1,this.server=new is(e,t)}async connect(e){return await this.server.connect(e)}async close(){await this.server.close()}setToolRequestHandlers(){this._toolHandlersInitialized||(this.server.assertCanSetRequestHandler(Ar.shape.method.value),this.server.assertCanSetRequestHandler(qr.shape.method.value),this.server.registerCapabilities({tools:{listChanged:!0}}),this.server.setRequestHandler(Ar,(()=>({tools:Object.entries(this._registeredTools).filter((([,e])=>e.enabled)).map((([e,t])=>{const r={name:e,description:t.description,inputSchema:t.inputSchema?zs(t.inputSchema,{strictUnions:!0}):Vs,annotations:t.annotations};return t.outputSchema&&(r.outputSchema=zs(t.outputSchema,{strictUnions:!0})),r}))}))),this.server.setRequestHandler(qr,(async(e,t)=>{const r=this._registeredTools[e.params.name];if(!r)throw new rs(Ht.InvalidParams,`Tool ${e.params.name} not found`);if(!r.enabled)throw new rs(Ht.InvalidParams,`Tool ${e.params.name} disabled`);let s;if(r.inputSchema){const a=await r.inputSchema.safeParseAsync(e.params.arguments);if(!a.success)throw new rs(Ht.InvalidParams,`Invalid arguments for tool ${e.params.name}: ${a.error.message}`);const n=a.data,i=r.callback;try{s=await Promise.resolve(i(n,t))}catch(e){s={content:[{type:"text",text:e instanceof Error?e.message:String(e)}],isError:!0}}}else{const e=r.callback;try{s=await Promise.resolve(e(t))}catch(e){s={content:[{type:"text",text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(r.outputSchema){if(!s.structuredContent&&!s.isError)throw new rs(Ht.InternalError,`Tool ${e.params.name} has outputSchema but returned no structuredContent`);s.structuredContent&&!s.content&&(s.content=[{type:"text",text:JSON.stringify(s.structuredContent,null,2)}])}else{if(!s.content&&!s.isError)throw new rs(Ht.InternalError,`Tool ${e.params.name} has no outputSchema and must return content`);if(s.structuredContent)throw new rs(Ht.InternalError,`Tool ${e.params.name} has no outputSchema but returned structuredContent`)}return s})),this._toolHandlersInitialized=!0)}setCompletionRequestHandler(){this._completionHandlerInitialized||(this.server.assertCanSetRequestHandler(Yr.shape.method.value),this.server.setRequestHandler(Yr,(async e=>{switch(e.params.ref.type){case"ref/prompt":return this.handlePromptCompletion(e,e.params.ref);case"ref/resource":return this.handleResourceCompletion(e,e.params.ref);default:throw new rs(Ht.InvalidParams,`Invalid completion reference: ${e.params.ref}`)}})),this._completionHandlerInitialized=!0)}async handlePromptCompletion(e,t){const r=this._registeredPrompts[t.name];if(!r)throw new rs(Ht.InvalidParams,`Prompt ${t.name} not found`);if(!r.enabled)throw new rs(Ht.InvalidParams,`Prompt ${t.name} disabled`);if(!r.argsSchema)return Js;const s=r.argsSchema.shape[e.params.argument.name];if(!(s instanceof Fs))return Js;const a=s._def;return Ws(await a.complete(e.params.argument.value))}async handleResourceCompletion(e,t){const r=Object.values(this._registeredResourceTemplates).find((e=>e.resourceTemplate.uriTemplate.toString()===t.uri));if(!r){if(this._registeredResources[t.uri])return Js;throw new rs(Ht.InvalidParams,`Resource template ${e.params.ref.uri} not found`)}const s=r.resourceTemplate.completeCallback(e.params.argument.name);return s?Ws(await s(e.params.argument.value)):Js}setResourceRequestHandlers(){this._resourceHandlersInitialized||(this.server.assertCanSetRequestHandler(dr.shape.method.value),this.server.assertCanSetRequestHandler(ur.shape.method.value),this.server.assertCanSetRequestHandler(pr.shape.method.value),this.server.registerCapabilities({resources:{listChanged:!0}}),this.server.setRequestHandler(dr,(async(e,t)=>{const r=Object.entries(this._registeredResources).filter((([e,t])=>t.enabled)).map((([e,t])=>({uri:e,name:t.name,...t.metadata}))),s=[];for(const e of Object.values(this._registeredResourceTemplates)){if(!e.resourceTemplate.listCallback)continue;const r=await e.resourceTemplate.listCallback(t);for(const t of r.resources)s.push({...t,...e.metadata})}return{resources:[...r,...s]}})),this.server.setRequestHandler(ur,(async()=>({resourceTemplates:Object.entries(this._registeredResourceTemplates).map((([e,t])=>({name:e,uriTemplate:t.resourceTemplate.uriTemplate.toString(),...t.metadata})))}))),this.server.setRequestHandler(pr,(async(e,t)=>{const r=new URL(e.params.uri),s=this._registeredResources[r.toString()];if(s){if(!s.enabled)throw new rs(Ht.InvalidParams,`Resource ${r} disabled`);return s.readCallback(r,t)}for(const e of Object.values(this._registeredResourceTemplates)){const s=e.resourceTemplate.uriTemplate.match(r.toString());if(s)return e.readCallback(r,s,t)}throw new rs(Ht.InvalidParams,`Resource ${r} not found`)})),this.setCompletionRequestHandler(),this._resourceHandlersInitialized=!0)}setPromptRequestHandlers(){this._promptHandlersInitialized||(this.server.assertCanSetRequestHandler(br.shape.method.value),this.server.assertCanSetRequestHandler(kr.shape.method.value),this.server.registerCapabilities({prompts:{listChanged:!0}}),this.server.setRequestHandler(br,(()=>({prompts:Object.entries(this._registeredPrompts).filter((([,e])=>e.enabled)).map((([e,t])=>{return{name:e,description:t.description,arguments:t.argsSchema?(r=t.argsSchema,Object.entries(r.shape).map((([e,t])=>({name:e,description:t.description,required:!t.isOptional()})))):void 0};var r}))}))),this.server.setRequestHandler(kr,(async(e,t)=>{const r=this._registeredPrompts[e.params.name];if(!r)throw new rs(Ht.InvalidParams,`Prompt ${e.params.name} not found`);if(!r.enabled)throw new rs(Ht.InvalidParams,`Prompt ${e.params.name} disabled`);if(r.argsSchema){const s=await r.argsSchema.safeParseAsync(e.params.arguments);if(!s.success)throw new rs(Ht.InvalidParams,`Invalid arguments for prompt ${e.params.name}: ${s.error.message}`);const a=s.data,n=r.callback;return await Promise.resolve(n(a,t))}{const e=r.callback;return await Promise.resolve(e(t))}})),this.setCompletionRequestHandler(),this._promptHandlersInitialized=!0)}resource(e,t,...r){let s;"object"==typeof r[0]&&(s=r.shift());const a=r[0];if("string"==typeof t){if(this._registeredResources[t])throw new Error(`Resource ${t} is already registered`);const r={name:e,metadata:s,readCallback:a,enabled:!0,disable:()=>r.update({enabled:!1}),enable:()=>r.update({enabled:!0}),remove:()=>r.update({uri:null}),update:e=>{void 0!==e.uri&&e.uri!==t&&(delete this._registeredResources[t],e.uri&&(this._registeredResources[e.uri]=r)),void 0!==e.name&&(r.name=e.name),void 0!==e.metadata&&(r.metadata=e.metadata),void 0!==e.callback&&(r.readCallback=e.callback),void 0!==e.enabled&&(r.enabled=e.enabled),this.sendResourceListChanged()}};return this._registeredResources[t]=r,this.setResourceRequestHandlers(),this.sendResourceListChanged(),r}{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);const r={resourceTemplate:t,metadata:s,readCallback:a,enabled:!0,disable:()=>r.update({enabled:!1}),enable:()=>r.update({enabled:!0}),remove:()=>r.update({name:null}),update:t=>{void 0!==t.name&&t.name!==e&&(delete this._registeredResourceTemplates[e],t.name&&(this._registeredResourceTemplates[t.name]=r)),void 0!==t.template&&(r.resourceTemplate=t.template),void 0!==t.metadata&&(r.metadata=t.metadata),void 0!==t.callback&&(r.readCallback=t.callback),void 0!==t.enabled&&(r.enabled=t.enabled),this.sendResourceListChanged()}};return this._registeredResourceTemplates[e]=r,this.setResourceRequestHandlers(),this.sendResourceListChanged(),r}}_createRegisteredTool(e,t,r,s,a,n){const i={description:t,inputSchema:void 0===r?void 0:Tt.object(r),outputSchema:void 0===s?void 0:Tt.object(s),annotations:a,callback:n,enabled:!0,disable:()=>i.update({enabled:!1}),enable:()=>i.update({enabled:!0}),remove:()=>i.update({name:null}),update:t=>{void 0!==t.name&&t.name!==e&&(delete this._registeredTools[e],t.name&&(this._registeredTools[t.name]=i)),void 0!==t.description&&(i.description=t.description),void 0!==t.paramsSchema&&(i.inputSchema=Tt.object(t.paramsSchema)),void 0!==t.callback&&(i.callback=t.callback),void 0!==t.annotations&&(i.annotations=t.annotations),void 0!==t.enabled&&(i.enabled=t.enabled),this.sendToolListChanged()}};return this._registeredTools[e]=i,this.setToolRequestHandlers(),this.sendToolListChanged(),i}tool(e,...t){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);let r,s,a;if("string"==typeof t[0]&&(r=t.shift()),t.length>1){const e=t[0];Bs(e)?(s=t.shift(),t.length>1&&"object"==typeof t[0]&&null!==t[0]&&!Bs(t[0])&&(a=t.shift())):"object"==typeof e&&null!==e&&(a=t.shift())}const n=t[0];return this._createRegisteredTool(e,r,s,void 0,a,n)}registerTool(e,t,r){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);const{description:s,inputSchema:a,outputSchema:n,annotations:i}=t;return this._createRegisteredTool(e,s,a,n,i,r)}prompt(e,...t){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);let r,s;"string"==typeof t[0]&&(r=t.shift()),t.length>1&&(s=t.shift());const a=t[0],n={description:r,argsSchema:void 0===s?void 0:Tt.object(s),callback:a,enabled:!0,disable:()=>n.update({enabled:!1}),enable:()=>n.update({enabled:!0}),remove:()=>n.update({name:null}),update:t=>{void 0!==t.name&&t.name!==e&&(delete this._registeredPrompts[e],t.name&&(this._registeredPrompts[t.name]=n)),void 0!==t.description&&(n.description=t.description),void 0!==t.argsSchema&&(n.argsSchema=Tt.object(t.argsSchema)),void 0!==t.callback&&(n.callback=t.callback),void 0!==t.enabled&&(n.enabled=t.enabled),this.sendPromptListChanged()}};return this._registeredPrompts[e]=n,this.setPromptRequestHandlers(),this.sendPromptListChanged(),n}isConnected(){return void 0!==this.server.transport}sendResourceListChanged(){this.isConnected()&&this.server.sendResourceListChanged()}sendToolListChanged(){this.isConnected()&&this.server.sendToolListChanged()}sendPromptListChanged(){this.isConnected()&&this.server.sendPromptListChanged()}}const Vs={type:"object"};function Bs(e){return"object"==typeof e&&null!==e&&(0===Object.keys(e).length||Object.values(e).some(Ks))}function Ks(e){return null!==e&&"object"==typeof e&&"parse"in e&&"function"==typeof e.parse&&"safeParse"in e&&"function"==typeof e.safeParse}function Ws(e){return{completion:{values:e.slice(0,100),total:e.length,hasMore:e.length>100}}}const Js={completion:{values:[],hasMore:!1}},Ys=INJECTED_TOOLS,Gs={name:"MCP Server",version:"0.0.1"};function Xs(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class Qs{start(){try{this.mcpServer.connect(this.transport),console.log("[STDIO] MCP Server running with STDIO transport"),this.setupShutdownHandlers()}catch(e){console.error("[STDIO] Error starting STDIO transport:",e),process.exit(1)}}setupShutdownHandlers(){process.on("SIGINT",this.shutdown.bind(this)),process.on("SIGTERM",this.shutdown.bind(this))}shutdown(){console.log("[STDIO] Shutting down STDIO transport"),process.exit(0)}constructor(e){Xs(this,"mcpServer",void 0),Xs(this,"transport",void 0),this.mcpServer=e,this.transport=new as}}return async function(){return new Promise((async e=>{const t=new Us(Gs),r=Object.keys(Ys).map((e=>Ys[e]()));Promise.all(r).then((r=>{r.forEach((e=>{const{default:r,metadata:s,schema:a}=e;t.tool(s.name,s.description,a,s.annotations,r)})),e(t)}))}))}().then((e=>{new Qs(e).start()})),{}})()));
1
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var s in r)("object"==typeof exports?exports:e)[s]=r[s]}}(this,(()=>(()=>{"use strict";const e=require("node:process");var t,r;!function(e){e.assertEqual=e=>e,e.assertIs=function(e){},e.assertNever=function(e){throw new Error},e.arrayToEnum=e=>{const t={};for(const r of e)t[r]=r;return t},e.getValidEnumValues=t=>{const r=e.objectKeys(t).filter((e=>"number"!=typeof t[t[e]])),s={};for(const e of r)s[e]=t[e];return e.objectValues(s)},e.objectValues=t=>e.objectKeys(t).map((function(e){return t[e]})),e.objectKeys="function"==typeof Object.keys?e=>Object.keys(e):e=>{const t=[];for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.push(r);return t},e.find=(e,t)=>{for(const r of e)if(t(r))return r},e.isInteger="function"==typeof Number.isInteger?e=>Number.isInteger(e):e=>"number"==typeof e&&isFinite(e)&&Math.floor(e)===e,e.joinValues=function(e,t=" | "){return e.map((e=>"string"==typeof e?`'${e}'`:e)).join(t)},e.jsonStringifyReplacer=(e,t)=>"bigint"==typeof t?t.toString():t}(t||(t={})),function(e){e.mergeShapes=(e,t)=>({...e,...t})}(r||(r={}));const s=t.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),a=e=>{switch(typeof e){case"undefined":return s.undefined;case"string":return s.string;case"number":return isNaN(e)?s.nan:s.number;case"boolean":return s.boolean;case"function":return s.function;case"bigint":return s.bigint;case"symbol":return s.symbol;case"object":return Array.isArray(e)?s.array:null===e?s.null:e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch?s.promise:"undefined"!=typeof Map&&e instanceof Map?s.map:"undefined"!=typeof Set&&e instanceof Set?s.set:"undefined"!=typeof Date&&e instanceof Date?s.date:s.object;default:return s.unknown}},n=t.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"]);class i extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=e=>{this.issues=[...this.issues,e]},this.addIssues=(e=[])=>{this.issues=[...this.issues,...e]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(e){return e.message},r={_errors:[]},s=e=>{for(const a of e.issues)if("invalid_union"===a.code)a.unionErrors.map(s);else if("invalid_return_type"===a.code)s(a.returnTypeError);else if("invalid_arguments"===a.code)s(a.argumentsError);else if(0===a.path.length)r._errors.push(t(a));else{let e=r,s=0;for(;s<a.path.length;){const r=a.path[s];s===a.path.length-1?(e[r]=e[r]||{_errors:[]},e[r]._errors.push(t(a))):e[r]=e[r]||{_errors:[]},e=e[r],s++}}};return s(this),r}static assert(e){if(!(e instanceof i))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,t.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(e=e=>e.message){const t={},r=[];for(const s of this.issues)s.path.length>0?(t[s.path[0]]=t[s.path[0]]||[],t[s.path[0]].push(e(s))):r.push(e(s));return{formErrors:r,fieldErrors:t}}get formErrors(){return this.flatten()}}i.create=e=>new i(e);const o=(e,r)=>{let a;switch(e.code){case n.invalid_type:a=e.received===s.undefined?"Required":`Expected ${e.expected}, received ${e.received}`;break;case n.invalid_literal:a=`Invalid literal value, expected ${JSON.stringify(e.expected,t.jsonStringifyReplacer)}`;break;case n.unrecognized_keys:a=`Unrecognized key(s) in object: ${t.joinValues(e.keys,", ")}`;break;case n.invalid_union:a="Invalid input";break;case n.invalid_union_discriminator:a=`Invalid discriminator value. Expected ${t.joinValues(e.options)}`;break;case n.invalid_enum_value:a=`Invalid enum value. Expected ${t.joinValues(e.options)}, received '${e.received}'`;break;case n.invalid_arguments:a="Invalid function arguments";break;case n.invalid_return_type:a="Invalid function return type";break;case n.invalid_date:a="Invalid date";break;case n.invalid_string:"object"==typeof e.validation?"includes"in e.validation?(a=`Invalid input: must include "${e.validation.includes}"`,"number"==typeof e.validation.position&&(a=`${a} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?a=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?a=`Invalid input: must end with "${e.validation.endsWith}"`:t.assertNever(e.validation):a="regex"!==e.validation?`Invalid ${e.validation}`:"Invalid";break;case n.too_small:a="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:"date"===e.type?`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:"Invalid input";break;case n.too_big:a="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"bigint"===e.type?`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"date"===e.type?`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:"Invalid input";break;case n.custom:a="Invalid input";break;case n.invalid_intersection_types:a="Intersection results could not be merged";break;case n.not_multiple_of:a=`Number must be a multiple of ${e.multipleOf}`;break;case n.not_finite:a="Number must be finite";break;default:a=r.defaultError,t.assertNever(e)}return{message:a}};let d=o;function c(){return d}const u=e=>{const{data:t,path:r,errorMaps:s,issueData:a}=e,n=[...r,...a.path||[]],i={...a,path:n};if(void 0!==a.message)return{...a,path:n,message:a.message};let o="";const d=s.filter((e=>!!e)).slice().reverse();for(const e of d)o=e(i,{data:t,defaultError:o}).message;return{...a,path:n,message:o}};function l(e,t){const r=c(),s=u({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,r,r===o?void 0:o].filter((e=>!!e))});e.common.issues.push(s)}class p{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(e,t){const r=[];for(const s of t){if("aborted"===s.status)return h;"dirty"===s.status&&e.dirty(),r.push(s.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,t){const r=[];for(const e of t){const t=await e.key,s=await e.value;r.push({key:t,value:s})}return p.mergeObjectSync(e,r)}static mergeObjectSync(e,t){const r={};for(const s of t){const{key:t,value:a}=s;if("aborted"===t.status)return h;if("aborted"===a.status)return h;"dirty"===t.status&&e.dirty(),"dirty"===a.status&&e.dirty(),"__proto__"===t.value||void 0===a.value&&!s.alwaysSet||(r[t.value]=a.value)}return{status:e.value,value:r}}}const h=Object.freeze({status:"aborted"}),m=e=>({status:"dirty",value:e}),f=e=>({status:"valid",value:e}),g=e=>"aborted"===e.status,v=e=>"dirty"===e.status,y=e=>"valid"===e.status,_=e=>"undefined"!=typeof Promise&&e instanceof Promise;function b(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)}function x(e,t,r,s,a){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?a.call(e,r):a?a.value=r:t.set(e,r),r}var k,w,T;"function"==typeof SuppressedError&&SuppressedError,function(e){e.errToObj=e=>"string"==typeof e?{message:e}:e||{},e.toString=e=>"string"==typeof e?e:null==e?void 0:e.message}(k||(k={}));class S{constructor(e,t,r,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=r,this._key=s}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Z=(e,t)=>{if(y(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new i(e.common.issues);return this._error=t,this._error}}};function j(e){if(!e)return{};const{errorMap:t,invalid_type_error:r,required_error:s,description:a}=e;if(t&&(r||s))throw new Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');return t?{errorMap:t,description:a}:{errorMap:(t,a)=>{var n,i;const{message:o}=e;return"invalid_enum_value"===t.code?{message:null!=o?o:a.defaultError}:void 0===a.data?{message:null!==(n=null!=o?o:s)&&void 0!==n?n:a.defaultError}:"invalid_type"!==t.code?{message:a.defaultError}:{message:null!==(i=null!=o?o:r)&&void 0!==i?i:a.defaultError}},description:a}}class P{get description(){return this._def.description}_getType(e){return a(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:a(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new p,ctx:{common:e.parent.common,data:e.data,parsedType:a(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(_(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const r=this.safeParse(e,t);if(r.success)return r.data;throw r.error}safeParse(e,t){var r;const s={common:{issues:[],async:null!==(r=null==t?void 0:t.async)&&void 0!==r&&r,contextualErrorMap:null==t?void 0:t.errorMap},path:(null==t?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:a(e)},n=this._parseSync({data:e,path:s.path,parent:s});return Z(s,n)}"~validate"(e){var t,r;const s={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:a(e)};if(!this["~standard"].async)try{const t=this._parseSync({data:e,path:[],parent:s});return y(t)?{value:t.value}:{issues:s.common.issues}}catch(e){(null===(r=null===(t=null==e?void 0:e.message)||void 0===t?void 0:t.toLowerCase())||void 0===r?void 0:r.includes("encountered"))&&(this["~standard"].async=!0),s.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:s}).then((e=>y(e)?{value:e.value}:{issues:s.common.issues}))}async parseAsync(e,t){const r=await this.safeParseAsync(e,t);if(r.success)return r.data;throw r.error}async safeParseAsync(e,t){const r={common:{issues:[],contextualErrorMap:null==t?void 0:t.errorMap,async:!0},path:(null==t?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:a(e)},s=this._parse({data:e,path:r.path,parent:r}),n=await(_(s)?s:Promise.resolve(s));return Z(r,n)}refine(e,t){const r=e=>"string"==typeof t||void 0===t?{message:t}:"function"==typeof t?t(e):t;return this._refinement(((t,s)=>{const a=e(t),i=()=>s.addIssue({code:n.custom,...r(t)});return"undefined"!=typeof Promise&&a instanceof Promise?a.then((e=>!!e||(i(),!1))):!!a||(i(),!1)}))}refinement(e,t){return this._refinement(((r,s)=>!!e(r)||(s.addIssue("function"==typeof t?t(r,s):t),!1)))}_refinement(e){return new Pe({schema:this,typeName:He.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return Ce.create(this,this._def)}nullable(){return Oe.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ce.create(this)}promise(){return je.create(this,this._def)}or(e){return pe.create([this,e],this._def)}and(e){return ge.create(this,e,this._def)}transform(e){return new Pe({...j(this._def),schema:this,typeName:He.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t="function"==typeof e?e:()=>e;return new Ie({...j(this._def),innerType:this,defaultValue:t,typeName:He.ZodDefault})}brand(){return new Ne({typeName:He.ZodBranded,type:this,...j(this._def)})}catch(e){const t="function"==typeof e?e:()=>e;return new Ae({...j(this._def),innerType:this,catchValue:t,typeName:He.ZodCatch})}describe(e){return new(0,this.constructor)({...this._def,description:e})}pipe(e){return $e.create(this,e)}readonly(){return Me.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const C=/^c[^\s-]{8,}$/i,O=/^[0-9a-z]+$/,I=/^[0-9A-HJKMNP-TV-Z]{26}$/i,A=/^[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,R=/^[a-z0-9_-]{21}$/i,E=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,N=/^[-+]?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)?)??$/,$=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;let M;const q=/^(?:(?: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])$/,L=/^(?:(?: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])$/,z=/^(([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]))$/,H=/^(([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])$/,F=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,D=/^([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])))",V=new RegExp(`^${U}$`);function B(e){let t="[0-5]\\d";return e.precision?t=`${t}\\.\\d{${e.precision}}`:null==e.precision&&(t=`${t}(\\.\\d+)?`),`([01]\\d|2[0-3]):[0-5]\\d(:${t})${e.precision?"+":"?"}`}function K(e){let t=`${U}T${B(e)}`;const r=[];return r.push(e.local?"Z?":"Z"),e.offset&&r.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${r.join("|")})`,new RegExp(`^${t}$`)}function W(e,t){if(!E.test(e))return!1;try{const[r]=e.split("."),s=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(r.length+(4-r.length%4)%4,"="),a=JSON.parse(atob(s));return!("object"!=typeof a||null===a||!a.typ||!a.alg||t&&a.alg!==t)}catch(e){return!1}}function J(e,t){return!("v4"!==t&&t||!L.test(e))||!("v6"!==t&&t||!H.test(e))}class Y extends P{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==s.string){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.string,received:t.parsedType}),h}const r=new p;let a;for(const s of this._def.checks)if("min"===s.kind)e.data.length<s.value&&(a=this._getOrReturnCtx(e,a),l(a,{code:n.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if("max"===s.kind)e.data.length>s.value&&(a=this._getOrReturnCtx(e,a),l(a,{code:n.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if("length"===s.kind){const t=e.data.length>s.value,i=e.data.length<s.value;(t||i)&&(a=this._getOrReturnCtx(e,a),t?l(a,{code:n.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):i&&l(a,{code:n.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),r.dirty())}else if("email"===s.kind)$.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"email",code:n.invalid_string,message:s.message}),r.dirty());else if("emoji"===s.kind)M||(M=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),M.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"emoji",code:n.invalid_string,message:s.message}),r.dirty());else if("uuid"===s.kind)A.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"uuid",code:n.invalid_string,message:s.message}),r.dirty());else if("nanoid"===s.kind)R.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"nanoid",code:n.invalid_string,message:s.message}),r.dirty());else if("cuid"===s.kind)C.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"cuid",code:n.invalid_string,message:s.message}),r.dirty());else if("cuid2"===s.kind)O.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"cuid2",code:n.invalid_string,message:s.message}),r.dirty());else if("ulid"===s.kind)I.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"ulid",code:n.invalid_string,message:s.message}),r.dirty());else if("url"===s.kind)try{new URL(e.data)}catch(t){a=this._getOrReturnCtx(e,a),l(a,{validation:"url",code:n.invalid_string,message:s.message}),r.dirty()}else"regex"===s.kind?(s.regex.lastIndex=0,s.regex.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"regex",code:n.invalid_string,message:s.message}),r.dirty())):"trim"===s.kind?e.data=e.data.trim():"includes"===s.kind?e.data.includes(s.value,s.position)||(a=this._getOrReturnCtx(e,a),l(a,{code:n.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),r.dirty()):"toLowerCase"===s.kind?e.data=e.data.toLowerCase():"toUpperCase"===s.kind?e.data=e.data.toUpperCase():"startsWith"===s.kind?e.data.startsWith(s.value)||(a=this._getOrReturnCtx(e,a),l(a,{code:n.invalid_string,validation:{startsWith:s.value},message:s.message}),r.dirty()):"endsWith"===s.kind?e.data.endsWith(s.value)||(a=this._getOrReturnCtx(e,a),l(a,{code:n.invalid_string,validation:{endsWith:s.value},message:s.message}),r.dirty()):"datetime"===s.kind?K(s).test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{code:n.invalid_string,validation:"datetime",message:s.message}),r.dirty()):"date"===s.kind?V.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{code:n.invalid_string,validation:"date",message:s.message}),r.dirty()):"time"===s.kind?new RegExp(`^${B(s)}$`).test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{code:n.invalid_string,validation:"time",message:s.message}),r.dirty()):"duration"===s.kind?N.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"duration",code:n.invalid_string,message:s.message}),r.dirty()):"ip"===s.kind?(i=e.data,("v4"!==(o=s.version)&&o||!q.test(i))&&("v6"!==o&&o||!z.test(i))&&(a=this._getOrReturnCtx(e,a),l(a,{validation:"ip",code:n.invalid_string,message:s.message}),r.dirty())):"jwt"===s.kind?W(e.data,s.alg)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"jwt",code:n.invalid_string,message:s.message}),r.dirty()):"cidr"===s.kind?J(e.data,s.version)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"cidr",code:n.invalid_string,message:s.message}),r.dirty()):"base64"===s.kind?F.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"base64",code:n.invalid_string,message:s.message}),r.dirty()):"base64url"===s.kind?D.test(e.data)||(a=this._getOrReturnCtx(e,a),l(a,{validation:"base64url",code:n.invalid_string,message:s.message}),r.dirty()):t.assertNever(s);var i,o;return{status:r.value,value:e.data}}_regex(e,t,r){return this.refinement((t=>e.test(t)),{validation:t,code:n.invalid_string,...k.errToObj(r)})}_addCheck(e){return new Y({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...k.errToObj(e)})}url(e){return this._addCheck({kind:"url",...k.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...k.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...k.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...k.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...k.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...k.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...k.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...k.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...k.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...k.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...k.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...k.errToObj(e)})}datetime(e){var t,r;return"string"==typeof e?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:void 0===(null==e?void 0:e.precision)?null:null==e?void 0:e.precision,offset:null!==(t=null==e?void 0:e.offset)&&void 0!==t&&t,local:null!==(r=null==e?void 0:e.local)&&void 0!==r&&r,...k.errToObj(null==e?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return"string"==typeof e?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:void 0===(null==e?void 0:e.precision)?null:null==e?void 0:e.precision,...k.errToObj(null==e?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...k.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...k.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:null==t?void 0:t.position,...k.errToObj(null==t?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...k.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...k.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...k.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...k.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...k.errToObj(t)})}nonempty(e){return this.min(1,k.errToObj(e))}trim(){return new Y({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Y({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Y({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find((e=>"datetime"===e.kind))}get isDate(){return!!this._def.checks.find((e=>"date"===e.kind))}get isTime(){return!!this._def.checks.find((e=>"time"===e.kind))}get isDuration(){return!!this._def.checks.find((e=>"duration"===e.kind))}get isEmail(){return!!this._def.checks.find((e=>"email"===e.kind))}get isURL(){return!!this._def.checks.find((e=>"url"===e.kind))}get isEmoji(){return!!this._def.checks.find((e=>"emoji"===e.kind))}get isUUID(){return!!this._def.checks.find((e=>"uuid"===e.kind))}get isNANOID(){return!!this._def.checks.find((e=>"nanoid"===e.kind))}get isCUID(){return!!this._def.checks.find((e=>"cuid"===e.kind))}get isCUID2(){return!!this._def.checks.find((e=>"cuid2"===e.kind))}get isULID(){return!!this._def.checks.find((e=>"ulid"===e.kind))}get isIP(){return!!this._def.checks.find((e=>"ip"===e.kind))}get isCIDR(){return!!this._def.checks.find((e=>"cidr"===e.kind))}get isBase64(){return!!this._def.checks.find((e=>"base64"===e.kind))}get isBase64url(){return!!this._def.checks.find((e=>"base64url"===e.kind))}get minLength(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}function G(e,t){const r=(e.toString().split(".")[1]||"").length,s=(t.toString().split(".")[1]||"").length,a=r>s?r:s;return parseInt(e.toFixed(a).replace(".",""))%parseInt(t.toFixed(a).replace(".",""))/Math.pow(10,a)}Y.create=e=>{var t;return new Y({checks:[],typeName:He.ZodString,coerce:null!==(t=null==e?void 0:e.coerce)&&void 0!==t&&t,...j(e)})};class X extends P{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==s.number){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.number,received:t.parsedType}),h}let r;const a=new p;for(const s of this._def.checks)"int"===s.kind?t.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{code:n.invalid_type,expected:"integer",received:"float",message:s.message}),a.dirty()):"min"===s.kind?(s.inclusive?e.data<s.value:e.data<=s.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:n.too_small,minimum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),a.dirty()):"max"===s.kind?(s.inclusive?e.data>s.value:e.data>=s.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:n.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),a.dirty()):"multipleOf"===s.kind?0!==G(e.data,s.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:n.not_multiple_of,multipleOf:s.value,message:s.message}),a.dirty()):"finite"===s.kind?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{code:n.not_finite,message:s.message}),a.dirty()):t.assertNever(s);return{status:a.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,k.toString(t))}gt(e,t){return this.setLimit("min",e,!1,k.toString(t))}lte(e,t){return this.setLimit("max",e,!0,k.toString(t))}lt(e,t){return this.setLimit("max",e,!1,k.toString(t))}setLimit(e,t,r,s){return new X({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:k.toString(s)}]})}_addCheck(e){return new X({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:k.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:k.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:k.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:k.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:k.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:k.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:k.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:k.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:k.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find((e=>"int"===e.kind||"multipleOf"===e.kind&&t.isInteger(e.value)))}get isFinite(){let e=null,t=null;for(const r of this._def.checks){if("finite"===r.kind||"int"===r.kind||"multipleOf"===r.kind)return!0;"min"===r.kind?(null===t||r.value>t)&&(t=r.value):"max"===r.kind&&(null===e||r.value<e)&&(e=r.value)}return Number.isFinite(t)&&Number.isFinite(e)}}X.create=e=>new X({checks:[],typeName:He.ZodNumber,coerce:(null==e?void 0:e.coerce)||!1,...j(e)});class Q extends P{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch(t){return this._getInvalidInput(e)}if(this._getType(e)!==s.bigint)return this._getInvalidInput(e);let r;const a=new p;for(const s of this._def.checks)"min"===s.kind?(s.inclusive?e.data<s.value:e.data<=s.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:n.too_small,type:"bigint",minimum:s.value,inclusive:s.inclusive,message:s.message}),a.dirty()):"max"===s.kind?(s.inclusive?e.data>s.value:e.data>=s.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:n.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),a.dirty()):"multipleOf"===s.kind?e.data%s.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),l(r,{code:n.not_multiple_of,multipleOf:s.value,message:s.message}),a.dirty()):t.assertNever(s);return{status:a.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.bigint,received:t.parsedType}),h}gte(e,t){return this.setLimit("min",e,!0,k.toString(t))}gt(e,t){return this.setLimit("min",e,!1,k.toString(t))}lte(e,t){return this.setLimit("max",e,!0,k.toString(t))}lt(e,t){return this.setLimit("max",e,!1,k.toString(t))}setLimit(e,t,r,s){return new Q({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:k.toString(s)}]})}_addCheck(e){return new Q({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:k.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:k.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:k.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:k.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:k.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}Q.create=e=>{var t;return new Q({checks:[],typeName:He.ZodBigInt,coerce:null!==(t=null==e?void 0:e.coerce)&&void 0!==t&&t,...j(e)})};class ee extends P{_parse(e){if(this._def.coerce&&(e.data=Boolean(e.data)),this._getType(e)!==s.boolean){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.boolean,received:t.parsedType}),h}return f(e.data)}}ee.create=e=>new ee({typeName:He.ZodBoolean,coerce:(null==e?void 0:e.coerce)||!1,...j(e)});class te extends P{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==s.date){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.date,received:t.parsedType}),h}if(isNaN(e.data.getTime()))return l(this._getOrReturnCtx(e),{code:n.invalid_date}),h;const r=new p;let a;for(const s of this._def.checks)"min"===s.kind?e.data.getTime()<s.value&&(a=this._getOrReturnCtx(e,a),l(a,{code:n.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),r.dirty()):"max"===s.kind?e.data.getTime()>s.value&&(a=this._getOrReturnCtx(e,a),l(a,{code:n.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),r.dirty()):t.assertNever(s);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new te({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:k.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:k.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return null!=e?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return null!=e?new Date(e):null}}te.create=e=>new te({checks:[],coerce:(null==e?void 0:e.coerce)||!1,typeName:He.ZodDate,...j(e)});class re extends P{_parse(e){if(this._getType(e)!==s.symbol){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.symbol,received:t.parsedType}),h}return f(e.data)}}re.create=e=>new re({typeName:He.ZodSymbol,...j(e)});class se extends P{_parse(e){if(this._getType(e)!==s.undefined){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.undefined,received:t.parsedType}),h}return f(e.data)}}se.create=e=>new se({typeName:He.ZodUndefined,...j(e)});class ae extends P{_parse(e){if(this._getType(e)!==s.null){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.null,received:t.parsedType}),h}return f(e.data)}}ae.create=e=>new ae({typeName:He.ZodNull,...j(e)});class ne extends P{constructor(){super(...arguments),this._any=!0}_parse(e){return f(e.data)}}ne.create=e=>new ne({typeName:He.ZodAny,...j(e)});class ie extends P{constructor(){super(...arguments),this._unknown=!0}_parse(e){return f(e.data)}}ie.create=e=>new ie({typeName:He.ZodUnknown,...j(e)});class oe extends P{_parse(e){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.never,received:t.parsedType}),h}}oe.create=e=>new oe({typeName:He.ZodNever,...j(e)});class de extends P{_parse(e){if(this._getType(e)!==s.undefined){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.void,received:t.parsedType}),h}return f(e.data)}}de.create=e=>new de({typeName:He.ZodVoid,...j(e)});class ce extends P{_parse(e){const{ctx:t,status:r}=this._processInputParams(e),a=this._def;if(t.parsedType!==s.array)return l(t,{code:n.invalid_type,expected:s.array,received:t.parsedType}),h;if(null!==a.exactLength){const e=t.data.length>a.exactLength.value,s=t.data.length<a.exactLength.value;(e||s)&&(l(t,{code:e?n.too_big:n.too_small,minimum:s?a.exactLength.value:void 0,maximum:e?a.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:a.exactLength.message}),r.dirty())}if(null!==a.minLength&&t.data.length<a.minLength.value&&(l(t,{code:n.too_small,minimum:a.minLength.value,type:"array",inclusive:!0,exact:!1,message:a.minLength.message}),r.dirty()),null!==a.maxLength&&t.data.length>a.maxLength.value&&(l(t,{code:n.too_big,maximum:a.maxLength.value,type:"array",inclusive:!0,exact:!1,message:a.maxLength.message}),r.dirty()),t.common.async)return Promise.all([...t.data].map(((e,r)=>a.type._parseAsync(new S(t,e,t.path,r))))).then((e=>p.mergeArray(r,e)));const i=[...t.data].map(((e,r)=>a.type._parseSync(new S(t,e,t.path,r))));return p.mergeArray(r,i)}get element(){return this._def.type}min(e,t){return new ce({...this._def,minLength:{value:e,message:k.toString(t)}})}max(e,t){return new ce({...this._def,maxLength:{value:e,message:k.toString(t)}})}length(e,t){return new ce({...this._def,exactLength:{value:e,message:k.toString(t)}})}nonempty(e){return this.min(1,e)}}function ue(e){if(e instanceof le){const t={};for(const r in e.shape){const s=e.shape[r];t[r]=Ce.create(ue(s))}return new le({...e._def,shape:()=>t})}return e instanceof ce?new ce({...e._def,type:ue(e.element)}):e instanceof Ce?Ce.create(ue(e.unwrap())):e instanceof Oe?Oe.create(ue(e.unwrap())):e instanceof ve?ve.create(e.items.map((e=>ue(e)))):e}ce.create=(e,t)=>new ce({type:e,minLength:null,maxLength:null,exactLength:null,typeName:He.ZodArray,...j(t)});class le extends P{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;const e=this._def.shape(),r=t.objectKeys(e);return this._cached={shape:e,keys:r}}_parse(e){if(this._getType(e)!==s.object){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.object,received:t.parsedType}),h}const{status:t,ctx:r}=this._processInputParams(e),{shape:a,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof oe&&"strip"===this._def.unknownKeys))for(const e in r.data)i.includes(e)||o.push(e);const d=[];for(const e of i){const t=a[e],s=r.data[e];d.push({key:{status:"valid",value:e},value:t._parse(new S(r,s,r.path,e)),alwaysSet:e in r.data})}if(this._def.catchall instanceof oe){const e=this._def.unknownKeys;if("passthrough"===e)for(const e of o)d.push({key:{status:"valid",value:e},value:{status:"valid",value:r.data[e]}});else if("strict"===e)o.length>0&&(l(r,{code:n.unrecognized_keys,keys:o}),t.dirty());else if("strip"!==e)throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const e=this._def.catchall;for(const t of o){const s=r.data[t];d.push({key:{status:"valid",value:t},value:e._parse(new S(r,s,r.path,t)),alwaysSet:t in r.data})}}return r.common.async?Promise.resolve().then((async()=>{const e=[];for(const t of d){const r=await t.key,s=await t.value;e.push({key:r,value:s,alwaysSet:t.alwaysSet})}return e})).then((e=>p.mergeObjectSync(t,e))):p.mergeObjectSync(t,d)}get shape(){return this._def.shape()}strict(e){return k.errToObj,new le({...this._def,unknownKeys:"strict",...void 0!==e?{errorMap:(t,r)=>{var s,a,n,i;const o=null!==(n=null===(a=(s=this._def).errorMap)||void 0===a?void 0:a.call(s,t,r).message)&&void 0!==n?n:r.defaultError;return"unrecognized_keys"===t.code?{message:null!==(i=k.errToObj(e).message)&&void 0!==i?i:o}:{message:o}}}:{}})}strip(){return new le({...this._def,unknownKeys:"strip"})}passthrough(){return new le({...this._def,unknownKeys:"passthrough"})}extend(e){return new le({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new le({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:He.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new le({...this._def,catchall:e})}pick(e){const r={};return t.objectKeys(e).forEach((t=>{e[t]&&this.shape[t]&&(r[t]=this.shape[t])})),new le({...this._def,shape:()=>r})}omit(e){const r={};return t.objectKeys(this.shape).forEach((t=>{e[t]||(r[t]=this.shape[t])})),new le({...this._def,shape:()=>r})}deepPartial(){return ue(this)}partial(e){const r={};return t.objectKeys(this.shape).forEach((t=>{const s=this.shape[t];e&&!e[t]?r[t]=s:r[t]=s.optional()})),new le({...this._def,shape:()=>r})}required(e){const r={};return t.objectKeys(this.shape).forEach((t=>{if(e&&!e[t])r[t]=this.shape[t];else{let e=this.shape[t];for(;e instanceof Ce;)e=e._def.innerType;r[t]=e}})),new le({...this._def,shape:()=>r})}keyof(){return Te(t.objectKeys(this.shape))}}le.create=(e,t)=>new le({shape:()=>e,unknownKeys:"strip",catchall:oe.create(),typeName:He.ZodObject,...j(t)}),le.strictCreate=(e,t)=>new le({shape:()=>e,unknownKeys:"strict",catchall:oe.create(),typeName:He.ZodObject,...j(t)}),le.lazycreate=(e,t)=>new le({shape:e,unknownKeys:"strip",catchall:oe.create(),typeName:He.ZodObject,...j(t)});class pe extends P{_parse(e){const{ctx:t}=this._processInputParams(e),r=this._def.options;if(t.common.async)return Promise.all(r.map((async e=>{const r={...t,common:{...t.common,issues:[]},parent:null};return{result:await e._parseAsync({data:t.data,path:t.path,parent:r}),ctx:r}}))).then((function(e){for(const t of e)if("valid"===t.result.status)return t.result;for(const r of e)if("dirty"===r.result.status)return t.common.issues.push(...r.ctx.common.issues),r.result;const r=e.map((e=>new i(e.ctx.common.issues)));return l(t,{code:n.invalid_union,unionErrors:r}),h}));{let e;const s=[];for(const a of r){const r={...t,common:{...t.common,issues:[]},parent:null},n=a._parseSync({data:t.data,path:t.path,parent:r});if("valid"===n.status)return n;"dirty"!==n.status||e||(e={result:n,ctx:r}),r.common.issues.length&&s.push(r.common.issues)}if(e)return t.common.issues.push(...e.ctx.common.issues),e.result;const a=s.map((e=>new i(e)));return l(t,{code:n.invalid_union,unionErrors:a}),h}}get options(){return this._def.options}}pe.create=(e,t)=>new pe({options:e,typeName:He.ZodUnion,...j(t)});const he=e=>e instanceof ke?he(e.schema):e instanceof Pe?he(e.innerType()):e instanceof we?[e.value]:e instanceof Se?e.options:e instanceof Ze?t.objectValues(e.enum):e instanceof Ie?he(e._def.innerType):e instanceof se?[void 0]:e instanceof ae?[null]:e instanceof Ce?[void 0,...he(e.unwrap())]:e instanceof Oe?[null,...he(e.unwrap())]:e instanceof Ne||e instanceof Me?he(e.unwrap()):e instanceof Ae?he(e._def.innerType):[];class me extends P{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==s.object)return l(t,{code:n.invalid_type,expected:s.object,received:t.parsedType}),h;const r=this.discriminator,a=t.data[r],i=this.optionsMap.get(a);return i?t.common.async?i._parseAsync({data:t.data,path:t.path,parent:t}):i._parseSync({data:t.data,path:t.path,parent:t}):(l(t,{code:n.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),h)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,r){const s=new Map;for(const r of t){const t=he(r.shape[e]);if(!t.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const a of t){if(s.has(a))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(a)}`);s.set(a,r)}}return new me({typeName:He.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:s,...j(r)})}}function fe(e,r){const n=a(e),i=a(r);if(e===r)return{valid:!0,data:e};if(n===s.object&&i===s.object){const s=t.objectKeys(r),a=t.objectKeys(e).filter((e=>-1!==s.indexOf(e))),n={...e,...r};for(const t of a){const s=fe(e[t],r[t]);if(!s.valid)return{valid:!1};n[t]=s.data}return{valid:!0,data:n}}if(n===s.array&&i===s.array){if(e.length!==r.length)return{valid:!1};const t=[];for(let s=0;s<e.length;s++){const a=fe(e[s],r[s]);if(!a.valid)return{valid:!1};t.push(a.data)}return{valid:!0,data:t}}return n===s.date&&i===s.date&&+e===+r?{valid:!0,data:e}:{valid:!1}}class ge extends P{_parse(e){const{status:t,ctx:r}=this._processInputParams(e),s=(e,s)=>{if(g(e)||g(s))return h;const a=fe(e.value,s.value);return a.valid?((v(e)||v(s))&&t.dirty(),{status:t.value,value:a.data}):(l(r,{code:n.invalid_intersection_types}),h)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then((([e,t])=>s(e,t))):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}ge.create=(e,t,r)=>new ge({left:e,right:t,typeName:He.ZodIntersection,...j(r)});class ve extends P{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==s.array)return l(r,{code:n.invalid_type,expected:s.array,received:r.parsedType}),h;if(r.data.length<this._def.items.length)return l(r,{code:n.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),h;!this._def.rest&&r.data.length>this._def.items.length&&(l(r,{code:n.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const a=[...r.data].map(((e,t)=>{const s=this._def.items[t]||this._def.rest;return s?s._parse(new S(r,e,r.path,t)):null})).filter((e=>!!e));return r.common.async?Promise.all(a).then((e=>p.mergeArray(t,e))):p.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new ve({...this._def,rest:e})}}ve.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ve({items:e,typeName:He.ZodTuple,rest:null,...j(t)})};class ye extends P{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==s.object)return l(r,{code:n.invalid_type,expected:s.object,received:r.parsedType}),h;const a=[],i=this._def.keyType,o=this._def.valueType;for(const e in r.data)a.push({key:i._parse(new S(r,e,r.path,e)),value:o._parse(new S(r,r.data[e],r.path,e)),alwaysSet:e in r.data});return r.common.async?p.mergeObjectAsync(t,a):p.mergeObjectSync(t,a)}get element(){return this._def.valueType}static create(e,t,r){return new ye(t instanceof P?{keyType:e,valueType:t,typeName:He.ZodRecord,...j(r)}:{keyType:Y.create(),valueType:e,typeName:He.ZodRecord,...j(t)})}}class _e extends P{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==s.map)return l(r,{code:n.invalid_type,expected:s.map,received:r.parsedType}),h;const a=this._def.keyType,i=this._def.valueType,o=[...r.data.entries()].map((([e,t],s)=>({key:a._parse(new S(r,e,r.path,[s,"key"])),value:i._parse(new S(r,t,r.path,[s,"value"]))})));if(r.common.async){const e=new Map;return Promise.resolve().then((async()=>{for(const r of o){const s=await r.key,a=await r.value;if("aborted"===s.status||"aborted"===a.status)return h;"dirty"!==s.status&&"dirty"!==a.status||t.dirty(),e.set(s.value,a.value)}return{status:t.value,value:e}}))}{const e=new Map;for(const r of o){const s=r.key,a=r.value;if("aborted"===s.status||"aborted"===a.status)return h;"dirty"!==s.status&&"dirty"!==a.status||t.dirty(),e.set(s.value,a.value)}return{status:t.value,value:e}}}}_e.create=(e,t,r)=>new _e({valueType:t,keyType:e,typeName:He.ZodMap,...j(r)});class be extends P{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==s.set)return l(r,{code:n.invalid_type,expected:s.set,received:r.parsedType}),h;const a=this._def;null!==a.minSize&&r.data.size<a.minSize.value&&(l(r,{code:n.too_small,minimum:a.minSize.value,type:"set",inclusive:!0,exact:!1,message:a.minSize.message}),t.dirty()),null!==a.maxSize&&r.data.size>a.maxSize.value&&(l(r,{code:n.too_big,maximum:a.maxSize.value,type:"set",inclusive:!0,exact:!1,message:a.maxSize.message}),t.dirty());const i=this._def.valueType;function o(e){const r=new Set;for(const s of e){if("aborted"===s.status)return h;"dirty"===s.status&&t.dirty(),r.add(s.value)}return{status:t.value,value:r}}const d=[...r.data.values()].map(((e,t)=>i._parse(new S(r,e,r.path,t))));return r.common.async?Promise.all(d).then((e=>o(e))):o(d)}min(e,t){return new be({...this._def,minSize:{value:e,message:k.toString(t)}})}max(e,t){return new be({...this._def,maxSize:{value:e,message:k.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}be.create=(e,t)=>new be({valueType:e,minSize:null,maxSize:null,typeName:He.ZodSet,...j(t)});class xe extends P{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==s.function)return l(t,{code:n.invalid_type,expected:s.function,received:t.parsedType}),h;function r(e,r){return u({data:e,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,c(),o].filter((e=>!!e)),issueData:{code:n.invalid_arguments,argumentsError:r}})}function a(e,r){return u({data:e,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,c(),o].filter((e=>!!e)),issueData:{code:n.invalid_return_type,returnTypeError:r}})}const d={errorMap:t.common.contextualErrorMap},p=t.data;if(this._def.returns instanceof je){const e=this;return f((async function(...t){const s=new i([]),n=await e._def.args.parseAsync(t,d).catch((e=>{throw s.addIssue(r(t,e)),s})),o=await Reflect.apply(p,this,n);return await e._def.returns._def.type.parseAsync(o,d).catch((e=>{throw s.addIssue(a(o,e)),s}))}))}{const e=this;return f((function(...t){const s=e._def.args.safeParse(t,d);if(!s.success)throw new i([r(t,s.error)]);const n=Reflect.apply(p,this,s.data),o=e._def.returns.safeParse(n,d);if(!o.success)throw new i([a(n,o.error)]);return o.data}))}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new xe({...this._def,args:ve.create(e).rest(ie.create())})}returns(e){return new xe({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,r){return new xe({args:e||ve.create([]).rest(ie.create()),returns:t||ie.create(),typeName:He.ZodFunction,...j(r)})}}class ke extends P{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}ke.create=(e,t)=>new ke({getter:e,typeName:He.ZodLazy,...j(t)});class we extends P{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return l(t,{received:t.data,code:n.invalid_literal,expected:this._def.value}),h}return{status:"valid",value:e.data}}get value(){return this._def.value}}function Te(e,t){return new Se({values:e,typeName:He.ZodEnum,...j(t)})}we.create=(e,t)=>new we({value:e,typeName:He.ZodLiteral,...j(t)});class Se extends P{constructor(){super(...arguments),w.set(this,void 0)}_parse(e){if("string"!=typeof e.data){const r=this._getOrReturnCtx(e),s=this._def.values;return l(r,{expected:t.joinValues(s),received:r.parsedType,code:n.invalid_type}),h}if(b(this,w,"f")||x(this,w,new Set(this._def.values),"f"),!b(this,w,"f").has(e.data)){const t=this._getOrReturnCtx(e),r=this._def.values;return l(t,{received:t.data,code:n.invalid_enum_value,options:r}),h}return f(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return Se.create(e,{...this._def,...t})}exclude(e,t=this._def){return Se.create(this.options.filter((t=>!e.includes(t))),{...this._def,...t})}}w=new WeakMap,Se.create=Te;class Ze extends P{constructor(){super(...arguments),T.set(this,void 0)}_parse(e){const r=t.getValidEnumValues(this._def.values),a=this._getOrReturnCtx(e);if(a.parsedType!==s.string&&a.parsedType!==s.number){const e=t.objectValues(r);return l(a,{expected:t.joinValues(e),received:a.parsedType,code:n.invalid_type}),h}if(b(this,T,"f")||x(this,T,new Set(t.getValidEnumValues(this._def.values)),"f"),!b(this,T,"f").has(e.data)){const e=t.objectValues(r);return l(a,{received:a.data,code:n.invalid_enum_value,options:e}),h}return f(e.data)}get enum(){return this._def.values}}T=new WeakMap,Ze.create=(e,t)=>new Ze({values:e,typeName:He.ZodNativeEnum,...j(t)});class je extends P{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==s.promise&&!1===t.common.async)return l(t,{code:n.invalid_type,expected:s.promise,received:t.parsedType}),h;const r=t.parsedType===s.promise?t.data:Promise.resolve(t.data);return f(r.then((e=>this._def.type.parseAsync(e,{path:t.path,errorMap:t.common.contextualErrorMap}))))}}je.create=(e,t)=>new je({type:e,typeName:He.ZodPromise,...j(t)});class Pe extends P{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===He.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:r,ctx:s}=this._processInputParams(e),a=this._def.effect||null,n={addIssue:e=>{l(s,e),e.fatal?r.abort():r.dirty()},get path(){return s.path}};if(n.addIssue=n.addIssue.bind(n),"preprocess"===a.type){const e=a.transform(s.data,n);if(s.common.async)return Promise.resolve(e).then((async e=>{if("aborted"===r.value)return h;const t=await this._def.schema._parseAsync({data:e,path:s.path,parent:s});return"aborted"===t.status?h:"dirty"===t.status||"dirty"===r.value?m(t.value):t}));{if("aborted"===r.value)return h;const t=this._def.schema._parseSync({data:e,path:s.path,parent:s});return"aborted"===t.status?h:"dirty"===t.status||"dirty"===r.value?m(t.value):t}}if("refinement"===a.type){const e=e=>{const t=a.refinement(e,n);if(s.common.async)return Promise.resolve(t);if(t instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return e};if(!1===s.common.async){const t=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});return"aborted"===t.status?h:("dirty"===t.status&&r.dirty(),e(t.value),{status:r.value,value:t.value})}return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then((t=>"aborted"===t.status?h:("dirty"===t.status&&r.dirty(),e(t.value).then((()=>({status:r.value,value:t.value}))))))}if("transform"===a.type){if(!1===s.common.async){const e=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});if(!y(e))return e;const t=a.transform(e.value,n);if(t instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:t}}return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then((e=>y(e)?Promise.resolve(a.transform(e.value,n)).then((e=>({status:r.value,value:e}))):e))}t.assertNever(a)}}Pe.create=(e,t,r)=>new Pe({schema:e,typeName:He.ZodEffects,effect:t,...j(r)}),Pe.createWithPreprocess=(e,t,r)=>new Pe({schema:t,effect:{type:"preprocess",transform:e},typeName:He.ZodEffects,...j(r)});class Ce extends P{_parse(e){return this._getType(e)===s.undefined?f(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Ce.create=(e,t)=>new Ce({innerType:e,typeName:He.ZodOptional,...j(t)});class Oe extends P{_parse(e){return this._getType(e)===s.null?f(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Oe.create=(e,t)=>new Oe({innerType:e,typeName:He.ZodNullable,...j(t)});class Ie extends P{_parse(e){const{ctx:t}=this._processInputParams(e);let r=t.data;return t.parsedType===s.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}Ie.create=(e,t)=>new Ie({innerType:e,typeName:He.ZodDefault,defaultValue:"function"==typeof t.default?t.default:()=>t.default,...j(t)});class Ae extends P{_parse(e){const{ctx:t}=this._processInputParams(e),r={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return _(s)?s.then((e=>({status:"valid",value:"valid"===e.status?e.value:this._def.catchValue({get error(){return new i(r.common.issues)},input:r.data})}))):{status:"valid",value:"valid"===s.status?s.value:this._def.catchValue({get error(){return new i(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Ae.create=(e,t)=>new Ae({innerType:e,typeName:He.ZodCatch,catchValue:"function"==typeof t.catch?t.catch:()=>t.catch,...j(t)});class Re extends P{_parse(e){if(this._getType(e)!==s.nan){const t=this._getOrReturnCtx(e);return l(t,{code:n.invalid_type,expected:s.nan,received:t.parsedType}),h}return{status:"valid",value:e.data}}}Re.create=e=>new Re({typeName:He.ZodNaN,...j(e)});const Ee=Symbol("zod_brand");class Ne extends P{_parse(e){const{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}class $e extends P{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const e=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return"aborted"===e.status?h:"dirty"===e.status?(t.dirty(),m(e.value)):this._def.out._parseAsync({data:e.value,path:r.path,parent:r})})();{const e=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return"aborted"===e.status?h:"dirty"===e.status?(t.dirty(),{status:"dirty",value:e.value}):this._def.out._parseSync({data:e.value,path:r.path,parent:r})}}static create(e,t){return new $e({in:e,out:t,typeName:He.ZodPipeline})}}class Me extends P{_parse(e){const t=this._def.innerType._parse(e),r=e=>(y(e)&&(e.value=Object.freeze(e.value)),e);return _(t)?t.then((e=>r(e))):r(t)}unwrap(){return this._def.innerType}}function qe(e,t){const r="function"==typeof e?e(t):"string"==typeof e?{message:e}:e;return"string"==typeof r?{message:r}:r}function Le(e,t={},r){return e?ne.create().superRefine(((s,a)=>{var n,i;const o=e(s);if(o instanceof Promise)return o.then((e=>{var n,i;if(!e){const e=qe(t,s),o=null===(i=null!==(n=e.fatal)&&void 0!==n?n:r)||void 0===i||i;a.addIssue({code:"custom",...e,fatal:o})}}));if(!o){const e=qe(t,s),o=null===(i=null!==(n=e.fatal)&&void 0!==n?n:r)||void 0===i||i;a.addIssue({code:"custom",...e,fatal:o})}})):ne.create()}Me.create=(e,t)=>new Me({innerType:e,typeName:He.ZodReadonly,...j(t)});const ze={object:le.lazycreate};var He;!function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"}(He||(He={}));const Fe=Y.create,De=X.create,Ue=Re.create,Ve=Q.create,Be=ee.create,Ke=te.create,We=re.create,Je=se.create,Ye=ae.create,Ge=ne.create,Xe=ie.create,Qe=oe.create,et=de.create,tt=ce.create,rt=le.create,st=le.strictCreate,at=pe.create,nt=me.create,it=ge.create,ot=ve.create,dt=ye.create,ct=_e.create,ut=be.create,lt=xe.create,pt=ke.create,ht=we.create,mt=Se.create,ft=Ze.create,gt=je.create,vt=Pe.create,yt=Ce.create,_t=Oe.create,bt=Pe.createWithPreprocess,xt=$e.create,kt={string:e=>Y.create({...e,coerce:!0}),number:e=>X.create({...e,coerce:!0}),boolean:e=>ee.create({...e,coerce:!0}),bigint:e=>Q.create({...e,coerce:!0}),date:e=>te.create({...e,coerce:!0})},wt=h;var Tt=Object.freeze({__proto__:null,defaultErrorMap:o,setErrorMap:function(e){d=e},getErrorMap:c,makeIssue:u,EMPTY_PATH:[],addIssueToContext:l,ParseStatus:p,INVALID:h,DIRTY:m,OK:f,isAborted:g,isDirty:v,isValid:y,isAsync:_,get util(){return t},get objectUtil(){return r},ZodParsedType:s,getParsedType:a,ZodType:P,datetimeRegex:K,ZodString:Y,ZodNumber:X,ZodBigInt:Q,ZodBoolean:ee,ZodDate:te,ZodSymbol:re,ZodUndefined:se,ZodNull:ae,ZodAny:ne,ZodUnknown:ie,ZodNever:oe,ZodVoid:de,ZodArray:ce,ZodObject:le,ZodUnion:pe,ZodDiscriminatedUnion:me,ZodIntersection:ge,ZodTuple:ve,ZodRecord:ye,ZodMap:_e,ZodSet:be,ZodFunction:xe,ZodLazy:ke,ZodLiteral:we,ZodEnum:Se,ZodNativeEnum:Ze,ZodPromise:je,ZodEffects:Pe,ZodTransformer:Pe,ZodOptional:Ce,ZodNullable:Oe,ZodDefault:Ie,ZodCatch:Ae,ZodNaN:Re,BRAND:Ee,ZodBranded:Ne,ZodPipeline:$e,ZodReadonly:Me,custom:Le,Schema:P,ZodSchema:P,late:ze,get ZodFirstPartyTypeKind(){return He},coerce:kt,any:Ge,array:tt,bigint:Ve,boolean:Be,date:Ke,discriminatedUnion:nt,effect:vt,enum:mt,function:lt,instanceof:(e,t={message:`Input not instance of ${e.name}`})=>Le((t=>t instanceof e),t),intersection:it,lazy:pt,literal:ht,map:ct,nan:Ue,nativeEnum:ft,never:Qe,null:Ye,nullable:_t,number:De,object:rt,oboolean:()=>Be().optional(),onumber:()=>De().optional(),optional:yt,ostring:()=>Fe().optional(),pipeline:xt,preprocess:bt,promise:gt,record:dt,set:ut,strictObject:st,string:Fe,symbol:We,transformer:vt,tuple:ot,undefined:Je,union:at,unknown:Xe,void:et,NEVER:wt,ZodIssueCode:n,quotelessJson:e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:"),ZodError:i});const St="2025-03-26",Zt=[St,"2024-11-05","2024-10-07"],jt="2.0",Pt=Tt.union([Tt.string(),Tt.number().int()]),Ct=Tt.string(),Ot=Tt.object({progressToken:Tt.optional(Pt)}).passthrough(),It=Tt.object({_meta:Tt.optional(Ot)}).passthrough(),At=Tt.object({method:Tt.string(),params:Tt.optional(It)}),Rt=Tt.object({_meta:Tt.optional(Tt.object({}).passthrough())}).passthrough(),Et=Tt.object({method:Tt.string(),params:Tt.optional(Rt)}),Nt=Tt.object({_meta:Tt.optional(Tt.object({}).passthrough())}).passthrough(),$t=Tt.union([Tt.string(),Tt.number().int()]),Mt=Tt.object({jsonrpc:Tt.literal(jt),id:$t}).merge(At).strict(),qt=Tt.object({jsonrpc:Tt.literal(jt)}).merge(Et).strict(),Lt=Tt.object({jsonrpc:Tt.literal(jt),id:$t,result:Nt}).strict(),zt=e=>Lt.safeParse(e).success;var Ht;!function(e){e[e.ConnectionClosed=-32e3]="ConnectionClosed",e[e.RequestTimeout=-32001]="RequestTimeout",e[e.ParseError=-32700]="ParseError",e[e.InvalidRequest=-32600]="InvalidRequest",e[e.MethodNotFound=-32601]="MethodNotFound",e[e.InvalidParams=-32602]="InvalidParams",e[e.InternalError=-32603]="InternalError"}(Ht||(Ht={}));const Ft=Tt.object({jsonrpc:Tt.literal(jt),id:$t,error:Tt.object({code:Tt.number().int(),message:Tt.string(),data:Tt.optional(Tt.unknown())})}).strict(),Dt=Tt.union([Mt,qt,Lt,Ft]),Ut=Nt.strict(),Vt=Et.extend({method:Tt.literal("notifications/cancelled"),params:Rt.extend({requestId:$t,reason:Tt.string().optional()})}),Bt=Tt.object({name:Tt.string(),version:Tt.string()}).passthrough(),Kt=Tt.object({experimental:Tt.optional(Tt.object({}).passthrough()),sampling:Tt.optional(Tt.object({}).passthrough()),roots:Tt.optional(Tt.object({listChanged:Tt.optional(Tt.boolean())}).passthrough())}).passthrough(),Wt=At.extend({method:Tt.literal("initialize"),params:It.extend({protocolVersion:Tt.string(),capabilities:Kt,clientInfo:Bt})}),Jt=Tt.object({experimental:Tt.optional(Tt.object({}).passthrough()),logging:Tt.optional(Tt.object({}).passthrough()),completions:Tt.optional(Tt.object({}).passthrough()),prompts:Tt.optional(Tt.object({listChanged:Tt.optional(Tt.boolean())}).passthrough()),resources:Tt.optional(Tt.object({subscribe:Tt.optional(Tt.boolean()),listChanged:Tt.optional(Tt.boolean())}).passthrough()),tools:Tt.optional(Tt.object({listChanged:Tt.optional(Tt.boolean())}).passthrough())}).passthrough(),Yt=Nt.extend({protocolVersion:Tt.string(),capabilities:Jt,serverInfo:Bt,instructions:Tt.optional(Tt.string())}),Gt=Et.extend({method:Tt.literal("notifications/initialized")}),Xt=At.extend({method:Tt.literal("ping")}),Qt=Tt.object({progress:Tt.number(),total:Tt.optional(Tt.number())}).passthrough(),er=Et.extend({method:Tt.literal("notifications/progress"),params:Rt.merge(Qt).extend({progressToken:Pt})}),tr=At.extend({params:It.extend({cursor:Tt.optional(Ct)}).optional()}),rr=Nt.extend({nextCursor:Tt.optional(Ct)}),sr=Tt.object({uri:Tt.string(),mimeType:Tt.optional(Tt.string())}).passthrough(),ar=sr.extend({text:Tt.string()}),nr=sr.extend({blob:Tt.string().base64()}),ir=Tt.object({uri:Tt.string(),name:Tt.string(),description:Tt.optional(Tt.string()),mimeType:Tt.optional(Tt.string())}).passthrough(),or=Tt.object({uriTemplate:Tt.string(),name:Tt.string(),description:Tt.optional(Tt.string()),mimeType:Tt.optional(Tt.string())}).passthrough(),dr=tr.extend({method:Tt.literal("resources/list")}),cr=rr.extend({resources:Tt.array(ir)}),ur=tr.extend({method:Tt.literal("resources/templates/list")}),lr=rr.extend({resourceTemplates:Tt.array(or)}),pr=At.extend({method:Tt.literal("resources/read"),params:It.extend({uri:Tt.string()})}),hr=Nt.extend({contents:Tt.array(Tt.union([ar,nr]))}),mr=Et.extend({method:Tt.literal("notifications/resources/list_changed")}),fr=At.extend({method:Tt.literal("resources/subscribe"),params:It.extend({uri:Tt.string()})}),gr=At.extend({method:Tt.literal("resources/unsubscribe"),params:It.extend({uri:Tt.string()})}),vr=Et.extend({method:Tt.literal("notifications/resources/updated"),params:Rt.extend({uri:Tt.string()})}),yr=Tt.object({name:Tt.string(),description:Tt.optional(Tt.string()),required:Tt.optional(Tt.boolean())}).passthrough(),_r=Tt.object({name:Tt.string(),description:Tt.optional(Tt.string()),arguments:Tt.optional(Tt.array(yr))}).passthrough(),br=tr.extend({method:Tt.literal("prompts/list")}),xr=rr.extend({prompts:Tt.array(_r)}),kr=At.extend({method:Tt.literal("prompts/get"),params:It.extend({name:Tt.string(),arguments:Tt.optional(Tt.record(Tt.string()))})}),wr=Tt.object({type:Tt.literal("text"),text:Tt.string()}).passthrough(),Tr=Tt.object({type:Tt.literal("image"),data:Tt.string().base64(),mimeType:Tt.string()}).passthrough(),Sr=Tt.object({type:Tt.literal("audio"),data:Tt.string().base64(),mimeType:Tt.string()}).passthrough(),Zr=Tt.object({type:Tt.literal("resource"),resource:Tt.union([ar,nr])}).passthrough(),jr=Tt.object({role:Tt.enum(["user","assistant"]),content:Tt.union([wr,Tr,Sr,Zr])}).passthrough(),Pr=Nt.extend({description:Tt.optional(Tt.string()),messages:Tt.array(jr)}),Cr=Et.extend({method:Tt.literal("notifications/prompts/list_changed")}),Or=Tt.object({title:Tt.optional(Tt.string()),readOnlyHint:Tt.optional(Tt.boolean()),destructiveHint:Tt.optional(Tt.boolean()),idempotentHint:Tt.optional(Tt.boolean()),openWorldHint:Tt.optional(Tt.boolean())}).passthrough(),Ir=Tt.object({name:Tt.string(),description:Tt.optional(Tt.string()),inputSchema:Tt.object({type:Tt.literal("object"),properties:Tt.optional(Tt.object({}).passthrough()),required:Tt.optional(Tt.array(Tt.string()))}).passthrough(),outputSchema:Tt.optional(Tt.object({type:Tt.literal("object"),properties:Tt.optional(Tt.object({}).passthrough()),required:Tt.optional(Tt.array(Tt.string()))}).passthrough()),annotations:Tt.optional(Or)}).passthrough(),Ar=tr.extend({method:Tt.literal("tools/list")}),Rr=rr.extend({tools:Tt.array(Ir)}),Er=Tt.array(Tt.union([wr,Tr,Sr,Zr])),Nr=Nt.extend({content:Er,structuredContent:Tt.never().optional(),isError:Tt.optional(Tt.boolean())}),$r=Nt.extend({structuredContent:Tt.object({}).passthrough(),content:Tt.optional(Er),isError:Tt.optional(Tt.boolean())}),Mr=Tt.union([Nr,$r]),qr=(Mr.or(Nt.extend({toolResult:Tt.unknown()})),At.extend({method:Tt.literal("tools/call"),params:It.extend({name:Tt.string(),arguments:Tt.optional(Tt.record(Tt.unknown()))})})),Lr=Et.extend({method:Tt.literal("notifications/tools/list_changed")}),zr=Tt.enum(["debug","info","notice","warning","error","critical","alert","emergency"]),Hr=At.extend({method:Tt.literal("logging/setLevel"),params:It.extend({level:zr})}),Fr=Et.extend({method:Tt.literal("notifications/message"),params:Rt.extend({level:zr,logger:Tt.optional(Tt.string()),data:Tt.unknown()})}),Dr=Tt.object({name:Tt.string().optional()}).passthrough(),Ur=Tt.object({hints:Tt.optional(Tt.array(Dr)),costPriority:Tt.optional(Tt.number().min(0).max(1)),speedPriority:Tt.optional(Tt.number().min(0).max(1)),intelligencePriority:Tt.optional(Tt.number().min(0).max(1))}).passthrough(),Vr=Tt.object({role:Tt.enum(["user","assistant"]),content:Tt.union([wr,Tr,Sr])}).passthrough(),Br=At.extend({method:Tt.literal("sampling/createMessage"),params:It.extend({messages:Tt.array(Vr),systemPrompt:Tt.optional(Tt.string()),includeContext:Tt.optional(Tt.enum(["none","thisServer","allServers"])),temperature:Tt.optional(Tt.number()),maxTokens:Tt.number().int(),stopSequences:Tt.optional(Tt.array(Tt.string())),metadata:Tt.optional(Tt.object({}).passthrough()),modelPreferences:Tt.optional(Ur)})}),Kr=Nt.extend({model:Tt.string(),stopReason:Tt.optional(Tt.enum(["endTurn","stopSequence","maxTokens"]).or(Tt.string())),role:Tt.enum(["user","assistant"]),content:Tt.discriminatedUnion("type",[wr,Tr,Sr])}),Wr=Tt.object({type:Tt.literal("ref/resource"),uri:Tt.string()}).passthrough(),Jr=Tt.object({type:Tt.literal("ref/prompt"),name:Tt.string()}).passthrough(),Yr=At.extend({method:Tt.literal("completion/complete"),params:It.extend({ref:Tt.union([Jr,Wr]),argument:Tt.object({name:Tt.string(),value:Tt.string()}).passthrough()})}),Gr=Nt.extend({completion:Tt.object({values:Tt.array(Tt.string()).max(100),total:Tt.optional(Tt.number().int()),hasMore:Tt.optional(Tt.boolean())}).passthrough()}),Xr=Tt.object({uri:Tt.string().startsWith("file://"),name:Tt.optional(Tt.string())}).passthrough(),Qr=At.extend({method:Tt.literal("roots/list")}),es=Nt.extend({roots:Tt.array(Xr)}),ts=Et.extend({method:Tt.literal("notifications/roots/list_changed")});Tt.union([Xt,Wt,Yr,Hr,kr,br,dr,ur,pr,fr,gr,qr,Ar]),Tt.union([Vt,er,Gt,ts]),Tt.union([Ut,Kr,es]),Tt.union([Xt,Br,Qr]),Tt.union([Vt,er,Fr,vr,mr,Lr,Cr]),Tt.union([Ut,Yt,Gr,Pr,xr,cr,lr,hr,Mr,Rr]);class rs extends Error{constructor(e,t,r){super(`MCP error ${e}: ${t}`),this.code=e,this.data=r,this.name="McpError"}}class ss{append(e){this._buffer=this._buffer?Buffer.concat([this._buffer,e]):e}readMessage(){if(!this._buffer)return null;const e=this._buffer.indexOf("\n");if(-1===e)return null;const t=this._buffer.toString("utf8",0,e).replace(/\r$/,"");return this._buffer=this._buffer.subarray(e+1),function(e){return Dt.parse(JSON.parse(e))}(t)}clear(){this._buffer=void 0}}class as{constructor(t=e.stdin,r=e.stdout){this._stdin=t,this._stdout=r,this._readBuffer=new ss,this._started=!1,this._ondata=e=>{this._readBuffer.append(e),this.processReadBuffer()},this._onerror=e=>{var t;null===(t=this.onerror)||void 0===t||t.call(this,e)}}async start(){if(this._started)throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");this._started=!0,this._stdin.on("data",this._ondata),this._stdin.on("error",this._onerror)}processReadBuffer(){for(var e,t;;)try{const t=this._readBuffer.readMessage();if(null===t)break;null===(e=this.onmessage)||void 0===e||e.call(this,t)}catch(e){null===(t=this.onerror)||void 0===t||t.call(this,e)}}async close(){var e;this._stdin.off("data",this._ondata),this._stdin.off("error",this._onerror),0===this._stdin.listenerCount("data")&&this._stdin.pause(),this._readBuffer.clear(),null===(e=this.onclose)||void 0===e||e.call(this)}send(e){return new Promise((t=>{const r=function(e){return JSON.stringify(e)+"\n"}(e);this._stdout.write(r)?t():this._stdout.once("drain",t)}))}}class ns{constructor(e){this._options=e,this._requestMessageId=0,this._requestHandlers=new Map,this._requestHandlerAbortControllers=new Map,this._notificationHandlers=new Map,this._responseHandlers=new Map,this._progressHandlers=new Map,this._timeoutInfo=new Map,this.setNotificationHandler(Vt,(e=>{const t=this._requestHandlerAbortControllers.get(e.params.requestId);null==t||t.abort(e.params.reason)})),this.setNotificationHandler(er,(e=>{this._onprogress(e)})),this.setRequestHandler(Xt,(e=>({})))}_setupTimeout(e,t,r,s,a=!1){this._timeoutInfo.set(e,{timeoutId:setTimeout(s,t),startTime:Date.now(),timeout:t,maxTotalTimeout:r,resetTimeoutOnProgress:a,onTimeout:s})}_resetTimeout(e){const t=this._timeoutInfo.get(e);if(!t)return!1;const r=Date.now()-t.startTime;if(t.maxTotalTimeout&&r>=t.maxTotalTimeout)throw this._timeoutInfo.delete(e),new rs(Ht.RequestTimeout,"Maximum total timeout exceeded",{maxTotalTimeout:t.maxTotalTimeout,totalElapsed:r});return clearTimeout(t.timeoutId),t.timeoutId=setTimeout(t.onTimeout,t.timeout),!0}_cleanupTimeout(e){const t=this._timeoutInfo.get(e);t&&(clearTimeout(t.timeoutId),this._timeoutInfo.delete(e))}async connect(e){this._transport=e,this._transport.onclose=()=>{this._onclose()},this._transport.onerror=e=>{this._onerror(e)},this._transport.onmessage=(e,t)=>{var r;zt(e)||(r=e,Ft.safeParse(r).success)?this._onresponse(e):(e=>Mt.safeParse(e).success)(e)?this._onrequest(e,t):(e=>qt.safeParse(e).success)(e)?this._onnotification(e):this._onerror(new Error(`Unknown message type: ${JSON.stringify(e)}`))},await this._transport.start()}_onclose(){var e;const t=this._responseHandlers;this._responseHandlers=new Map,this._progressHandlers.clear(),this._transport=void 0,null===(e=this.onclose)||void 0===e||e.call(this);const r=new rs(Ht.ConnectionClosed,"Connection closed");for(const e of t.values())e(r)}_onerror(e){var t;null===(t=this.onerror)||void 0===t||t.call(this,e)}_onnotification(e){var t;const r=null!==(t=this._notificationHandlers.get(e.method))&&void 0!==t?t:this.fallbackNotificationHandler;void 0!==r&&Promise.resolve().then((()=>r(e))).catch((e=>this._onerror(new Error(`Uncaught error in notification handler: ${e}`))))}_onrequest(e,t){var r,s,a,n;const i=null!==(r=this._requestHandlers.get(e.method))&&void 0!==r?r:this.fallbackRequestHandler;if(void 0===i)return void(null===(s=this._transport)||void 0===s||s.send({jsonrpc:"2.0",id:e.id,error:{code:Ht.MethodNotFound,message:"Method not found"}}).catch((e=>this._onerror(new Error(`Failed to send an error response: ${e}`)))));const o=new AbortController;this._requestHandlerAbortControllers.set(e.id,o);const d={signal:o.signal,sessionId:null===(a=this._transport)||void 0===a?void 0:a.sessionId,_meta:null===(n=e.params)||void 0===n?void 0:n._meta,sendNotification:t=>this.notification(t,{relatedRequestId:e.id}),sendRequest:(t,r,s)=>this.request(t,r,{...s,relatedRequestId:e.id}),authInfo:null==t?void 0:t.authInfo,requestId:e.id};Promise.resolve().then((()=>i(e,d))).then((t=>{var r;if(!o.signal.aborted)return null===(r=this._transport)||void 0===r?void 0:r.send({result:t,jsonrpc:"2.0",id:e.id})}),(t=>{var r,s;if(!o.signal.aborted)return null===(r=this._transport)||void 0===r?void 0:r.send({jsonrpc:"2.0",id:e.id,error:{code:Number.isSafeInteger(t.code)?t.code:Ht.InternalError,message:null!==(s=t.message)&&void 0!==s?s:"Internal error"}})})).catch((e=>this._onerror(new Error(`Failed to send response: ${e}`)))).finally((()=>{this._requestHandlerAbortControllers.delete(e.id)}))}_onprogress(e){const{progressToken:t,...r}=e.params,s=Number(t),a=this._progressHandlers.get(s);if(!a)return void this._onerror(new Error(`Received a progress notification for an unknown token: ${JSON.stringify(e)}`));const n=this._responseHandlers.get(s),i=this._timeoutInfo.get(s);if(i&&n&&i.resetTimeoutOnProgress)try{this._resetTimeout(s)}catch(e){return void n(e)}a(r)}_onresponse(e){const t=Number(e.id),r=this._responseHandlers.get(t);void 0!==r?(this._responseHandlers.delete(t),this._progressHandlers.delete(t),this._cleanupTimeout(t),zt(e)?r(e):r(new rs(e.error.code,e.error.message,e.error.data))):this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(e)}`))}get transport(){return this._transport}async close(){var e;await(null===(e=this._transport)||void 0===e?void 0:e.close())}request(e,t,r){const{relatedRequestId:s,resumptionToken:a,onresumptiontoken:n}=null!=r?r:{};return new Promise(((i,o)=>{var d,c,u,l,p;if(!this._transport)return void o(new Error("Not connected"));!0===(null===(d=this._options)||void 0===d?void 0:d.enforceStrictCapabilities)&&this.assertCapabilityForMethod(e.method),null===(c=null==r?void 0:r.signal)||void 0===c||c.throwIfAborted();const h=this._requestMessageId++,m={...e,jsonrpc:"2.0",id:h};(null==r?void 0:r.onprogress)&&(this._progressHandlers.set(h,r.onprogress),m.params={...e.params,_meta:{progressToken:h}});const f=e=>{var t;this._responseHandlers.delete(h),this._progressHandlers.delete(h),this._cleanupTimeout(h),null===(t=this._transport)||void 0===t||t.send({jsonrpc:"2.0",method:"notifications/cancelled",params:{requestId:h,reason:String(e)}},{relatedRequestId:s,resumptionToken:a,onresumptiontoken:n}).catch((e=>this._onerror(new Error(`Failed to send cancellation: ${e}`)))),o(e)};this._responseHandlers.set(h,(e=>{var s;if(!(null===(s=null==r?void 0:r.signal)||void 0===s?void 0:s.aborted)){if(e instanceof Error)return o(e);try{const r=t.parse(e.result);i(r)}catch(e){o(e)}}})),null===(u=null==r?void 0:r.signal)||void 0===u||u.addEventListener("abort",(()=>{var e;f(null===(e=null==r?void 0:r.signal)||void 0===e?void 0:e.reason)}));const g=null!==(l=null==r?void 0:r.timeout)&&void 0!==l?l:6e4;this._setupTimeout(h,g,null==r?void 0:r.maxTotalTimeout,(()=>f(new rs(Ht.RequestTimeout,"Request timed out",{timeout:g}))),null!==(p=null==r?void 0:r.resetTimeoutOnProgress)&&void 0!==p&&p),this._transport.send(m,{relatedRequestId:s,resumptionToken:a,onresumptiontoken:n}).catch((e=>{this._cleanupTimeout(h),o(e)}))}))}async notification(e,t){if(!this._transport)throw new Error("Not connected");this.assertNotificationCapability(e.method);const r={...e,jsonrpc:"2.0"};await this._transport.send(r,t)}setRequestHandler(e,t){const r=e.shape.method.value;this.assertRequestHandlerCapability(r),this._requestHandlers.set(r,((r,s)=>Promise.resolve(t(e.parse(r),s))))}removeRequestHandler(e){this._requestHandlers.delete(e)}assertCanSetRequestHandler(e){if(this._requestHandlers.has(e))throw new Error(`A request handler for ${e} already exists, which would be overridden`)}setNotificationHandler(e,t){this._notificationHandlers.set(e.shape.method.value,(r=>Promise.resolve(t(e.parse(r)))))}removeNotificationHandler(e){this._notificationHandlers.delete(e)}}class is extends ns{constructor(e,t){var r;super(t),this._serverInfo=e,this._capabilities=null!==(r=null==t?void 0:t.capabilities)&&void 0!==r?r:{},this._instructions=null==t?void 0:t.instructions,this.setRequestHandler(Wt,(e=>this._oninitialize(e))),this.setNotificationHandler(Gt,(()=>{var e;return null===(e=this.oninitialized)||void 0===e?void 0:e.call(this)}))}registerCapabilities(e){if(this.transport)throw new Error("Cannot register capabilities after connecting to transport");var t,r;this._capabilities=(t=this._capabilities,r=e,Object.entries(r).reduce(((e,[t,r])=>(e[t]=r&&"object"==typeof r&&e[t]?{...e[t],...r}:r,e)),{...t}))}assertCapabilityForMethod(e){var t,r;switch(e){case"sampling/createMessage":if(!(null===(t=this._clientCapabilities)||void 0===t?void 0:t.sampling))throw new Error(`Client does not support sampling (required for ${e})`);break;case"roots/list":if(!(null===(r=this._clientCapabilities)||void 0===r?void 0:r.roots))throw new Error(`Client does not support listing roots (required for ${e})`)}}assertNotificationCapability(e){switch(e){case"notifications/message":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"notifications/resources/updated":case"notifications/resources/list_changed":if(!this._capabilities.resources)throw new Error(`Server does not support notifying about resources (required for ${e})`);break;case"notifications/tools/list_changed":if(!this._capabilities.tools)throw new Error(`Server does not support notifying of tool list changes (required for ${e})`);break;case"notifications/prompts/list_changed":if(!this._capabilities.prompts)throw new Error(`Server does not support notifying of prompt list changes (required for ${e})`)}}assertRequestHandlerCapability(e){switch(e){case"sampling/createMessage":if(!this._capabilities.sampling)throw new Error(`Server does not support sampling (required for ${e})`);break;case"logging/setLevel":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"prompts/get":case"prompts/list":if(!this._capabilities.prompts)throw new Error(`Server does not support prompts (required for ${e})`);break;case"resources/list":case"resources/templates/list":case"resources/read":if(!this._capabilities.resources)throw new Error(`Server does not support resources (required for ${e})`);break;case"tools/call":case"tools/list":if(!this._capabilities.tools)throw new Error(`Server does not support tools (required for ${e})`)}}async _oninitialize(e){const t=e.params.protocolVersion;return this._clientCapabilities=e.params.capabilities,this._clientVersion=e.params.clientInfo,{protocolVersion:Zt.includes(t)?t:St,capabilities:this.getCapabilities(),serverInfo:this._serverInfo,...this._instructions&&{instructions:this._instructions}}}getClientCapabilities(){return this._clientCapabilities}getClientVersion(){return this._clientVersion}getCapabilities(){return this._capabilities}async ping(){return this.request({method:"ping"},Ut)}async createMessage(e,t){return this.request({method:"sampling/createMessage",params:e},Kr,t)}async listRoots(e,t){return this.request({method:"roots/list",params:e},es,t)}async sendLoggingMessage(e){return this.notification({method:"notifications/message",params:e})}async sendResourceUpdated(e){return this.notification({method:"notifications/resources/updated",params:e})}async sendResourceListChanged(){return this.notification({method:"notifications/resources/list_changed"})}async sendToolListChanged(){return this.notification({method:"notifications/tools/list_changed"})}async sendPromptListChanged(){return this.notification({method:"notifications/prompts/list_changed"})}}const os=Symbol("Let zodToJsonSchema decide on which parser to use"),ds={name:void 0,$refStrategy:"root",basePath:["#"],effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",removeAdditionalStrategy:"passthrough",allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:"definitions",target:"jsonSchema7",strictUnions:!1,definitions:{},errorMessages:!1,markdownDescription:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref"};function cs(e,t,r,s){s?.errorMessages&&r&&(e.errorMessage={...e.errorMessage,[t]:r})}function us(e,t,r,s,a){e[t]=r,cs(e,t,s,a)}function ls(e,t){return $s(e.type._def,t)}function ps(e,t,r){const s=r??t.dateStrategy;if(Array.isArray(s))return{anyOf:s.map(((r,s)=>ps(e,t,r)))};switch(s){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":return hs(e,t)}}const hs=(e,t)=>{const r={type:"integer",format:"unix-time"};if("openApi3"===t.target)return r;for(const s of e.checks)switch(s.kind){case"min":us(r,"minimum",s.value,s.message,t);break;case"max":us(r,"maximum",s.value,s.message,t)}return r};let ms;const fs=/^[cC][^\s-]{8,}$/,gs=/^[0-9a-z]+$/,vs=/^[0-9A-HJKMNP-TV-Z]{26}$/,ys=/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,_s=/^(?:(?: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])$/,bs=/^(([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])$/,xs=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,ks=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,ws=/^[a-zA-Z0-9_-]{21}$/,Ts=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;function Ss(e,t){const r={type:"string"};if(e.checks)for(const s of e.checks)switch(s.kind){case"min":us(r,"minLength","number"==typeof r.minLength?Math.max(r.minLength,s.value):s.value,s.message,t);break;case"max":us(r,"maxLength","number"==typeof r.maxLength?Math.min(r.maxLength,s.value):s.value,s.message,t);break;case"email":switch(t.emailStrategy){case"format:email":Ps(r,"email",s.message,t);break;case"format:idn-email":Ps(r,"idn-email",s.message,t);break;case"pattern:zod":Cs(r,ys,s.message,t)}break;case"url":Ps(r,"uri",s.message,t);break;case"uuid":Ps(r,"uuid",s.message,t);break;case"regex":Cs(r,s.regex,s.message,t);break;case"cuid":Cs(r,fs,s.message,t);break;case"cuid2":Cs(r,gs,s.message,t);break;case"startsWith":Cs(r,RegExp(`^${Zs(s.value,t)}`),s.message,t);break;case"endsWith":Cs(r,RegExp(`${Zs(s.value,t)}$`),s.message,t);break;case"datetime":Ps(r,"date-time",s.message,t);break;case"date":Ps(r,"date",s.message,t);break;case"time":Ps(r,"time",s.message,t);break;case"duration":Ps(r,"duration",s.message,t);break;case"length":us(r,"minLength","number"==typeof r.minLength?Math.max(r.minLength,s.value):s.value,s.message,t),us(r,"maxLength","number"==typeof r.maxLength?Math.min(r.maxLength,s.value):s.value,s.message,t);break;case"includes":Cs(r,RegExp(Zs(s.value,t)),s.message,t);break;case"ip":"v6"!==s.version&&Ps(r,"ipv4",s.message,t),"v4"!==s.version&&Ps(r,"ipv6",s.message,t);break;case"base64url":Cs(r,ks,s.message,t);break;case"jwt":Cs(r,Ts,s.message,t);break;case"cidr":"v6"!==s.version&&Cs(r,_s,s.message,t),"v4"!==s.version&&Cs(r,bs,s.message,t);break;case"emoji":Cs(r,(void 0===ms&&(ms=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),ms),s.message,t);break;case"ulid":Cs(r,vs,s.message,t);break;case"base64":switch(t.base64Strategy){case"format:binary":Ps(r,"binary",s.message,t);break;case"contentEncoding:base64":us(r,"contentEncoding","base64",s.message,t);break;case"pattern:zod":Cs(r,xs,s.message,t)}break;case"nanoid":Cs(r,ws,s.message,t)}return r}function Zs(e,t){return"escape"===t.patternStrategy?function(e){let t="";for(let r=0;r<e.length;r++)js.has(e[r])||(t+="\\"),t+=e[r];return t}(e):e}const js=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function Ps(e,t,r,s){e.format||e.anyOf?.some((e=>e.format))?(e.anyOf||(e.anyOf=[]),e.format&&(e.anyOf.push({format:e.format,...e.errorMessage&&s.errorMessages&&{errorMessage:{format:e.errorMessage.format}}}),delete e.format,e.errorMessage&&(delete e.errorMessage.format,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.anyOf.push({format:t,...r&&s.errorMessages&&{errorMessage:{format:r}}})):us(e,"format",t,r,s)}function Cs(e,t,r,s){e.pattern||e.allOf?.some((e=>e.pattern))?(e.allOf||(e.allOf=[]),e.pattern&&(e.allOf.push({pattern:e.pattern,...e.errorMessage&&s.errorMessages&&{errorMessage:{pattern:e.errorMessage.pattern}}}),delete e.pattern,e.errorMessage&&(delete e.errorMessage.pattern,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.allOf.push({pattern:Os(t,s),...r&&s.errorMessages&&{errorMessage:{pattern:r}}})):us(e,"pattern",Os(t,s),r,s)}function Os(e,t){if(!t.applyRegexFlags||!e.flags)return e.source;const r=e.flags.includes("i"),s=e.flags.includes("m"),a=e.flags.includes("s"),n=r?e.source.toLowerCase():e.source;let i="",o=!1,d=!1,c=!1;for(let e=0;e<n.length;e++)if(o)i+=n[e],o=!1;else{if(r)if(d){if(n[e].match(/[a-z]/)){c?(i+=n[e],i+=`${n[e-2]}-${n[e]}`.toUpperCase(),c=!1):"-"===n[e+1]&&n[e+2]?.match(/[a-z]/)?(i+=n[e],c=!0):i+=`${n[e]}${n[e].toUpperCase()}`;continue}}else if(n[e].match(/[a-z]/)){i+=`[${n[e]}${n[e].toUpperCase()}]`;continue}if(s){if("^"===n[e]){i+="(^|(?<=[\r\n]))";continue}if("$"===n[e]){i+="($|(?=[\r\n]))";continue}}a&&"."===n[e]?i+=d?`${n[e]}\r\n`:`[${n[e]}\r\n]`:(i+=n[e],"\\"===n[e]?o=!0:d&&"]"===n[e]?d=!1:d||"["!==n[e]||(d=!0))}try{new RegExp(i)}catch{return console.warn(`Could not convert regex pattern at ${t.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),e.source}return i}function Is(e,t){if("openAi"===t.target&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),"openApi3"===t.target&&e.keyType?._def.typeName===He.ZodEnum)return{type:"object",required:e.keyType._def.values,properties:e.keyType._def.values.reduce(((r,s)=>({...r,[s]:$s(e.valueType._def,{...t,currentPath:[...t.currentPath,"properties",s]})??{}})),{}),additionalProperties:t.rejectedAdditionalProperties};const r={type:"object",additionalProperties:$s(e.valueType._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??t.allowedAdditionalProperties};if("openApi3"===t.target)return r;if(e.keyType?._def.typeName===He.ZodString&&e.keyType._def.checks?.length){const{type:s,...a}=Ss(e.keyType._def,t);return{...r,propertyNames:a}}if(e.keyType?._def.typeName===He.ZodEnum)return{...r,propertyNames:{enum:e.keyType._def.values}};if(e.keyType?._def.typeName===He.ZodBranded&&e.keyType._def.type._def.typeName===He.ZodString&&e.keyType._def.type._def.checks?.length){const{type:s,...a}=ls(e.keyType._def,t);return{...r,propertyNames:a}}return r}const As={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"},Rs=(e,t)=>{const r=(e.options instanceof Map?Array.from(e.options.values()):e.options).map(((e,r)=>$s(e._def,{...t,currentPath:[...t.currentPath,"anyOf",`${r}`]}))).filter((e=>!!e&&(!t.strictUnions||"object"==typeof e&&Object.keys(e).length>0)));return r.length?{anyOf:r}:void 0};function Es(e){try{return e.isOptional()}catch{return!0}}const Ns=(e,t,r)=>{switch(t){case He.ZodString:return Ss(e,r);case He.ZodNumber:return function(e,t){const r={type:"number"};if(!e.checks)return r;for(const s of e.checks)switch(s.kind){case"int":r.type="integer",cs(r,"type",s.message,t);break;case"min":"jsonSchema7"===t.target?s.inclusive?us(r,"minimum",s.value,s.message,t):us(r,"exclusiveMinimum",s.value,s.message,t):(s.inclusive||(r.exclusiveMinimum=!0),us(r,"minimum",s.value,s.message,t));break;case"max":"jsonSchema7"===t.target?s.inclusive?us(r,"maximum",s.value,s.message,t):us(r,"exclusiveMaximum",s.value,s.message,t):(s.inclusive||(r.exclusiveMaximum=!0),us(r,"maximum",s.value,s.message,t));break;case"multipleOf":us(r,"multipleOf",s.value,s.message,t)}return r}(e,r);case He.ZodObject:return function(e,t){const r="openAi"===t.target,s={type:"object",properties:{}},a=[],n=e.shape();for(const e in n){let i=n[e];if(void 0===i||void 0===i._def)continue;let o=Es(i);o&&r&&(i instanceof Ce&&(i=i._def.innerType),i.isNullable()||(i=i.nullable()),o=!1);const d=$s(i._def,{...t,currentPath:[...t.currentPath,"properties",e],propertyPath:[...t.currentPath,"properties",e]});void 0!==d&&(s.properties[e]=d,o||a.push(e))}a.length&&(s.required=a);const i=function(e,t){if("ZodNever"!==e.catchall._def.typeName)return $s(e.catchall._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]});switch(e.unknownKeys){case"passthrough":return t.allowedAdditionalProperties;case"strict":return t.rejectedAdditionalProperties;case"strip":return"strict"===t.removeAdditionalStrategy?t.allowedAdditionalProperties:t.rejectedAdditionalProperties}}(e,t);return void 0!==i&&(s.additionalProperties=i),s}(e,r);case He.ZodBigInt:return function(e,t){const r={type:"integer",format:"int64"};if(!e.checks)return r;for(const s of e.checks)switch(s.kind){case"min":"jsonSchema7"===t.target?s.inclusive?us(r,"minimum",s.value,s.message,t):us(r,"exclusiveMinimum",s.value,s.message,t):(s.inclusive||(r.exclusiveMinimum=!0),us(r,"minimum",s.value,s.message,t));break;case"max":"jsonSchema7"===t.target?s.inclusive?us(r,"maximum",s.value,s.message,t):us(r,"exclusiveMaximum",s.value,s.message,t):(s.inclusive||(r.exclusiveMaximum=!0),us(r,"maximum",s.value,s.message,t));break;case"multipleOf":us(r,"multipleOf",s.value,s.message,t)}return r}(e,r);case He.ZodBoolean:return{type:"boolean"};case He.ZodDate:return ps(e,r);case He.ZodUndefined:return{not:{}};case He.ZodNull:return function(e){return"openApi3"===e.target?{enum:["null"],nullable:!0}:{type:"null"}}(r);case He.ZodArray:return function(e,t){const r={type:"array"};return e.type?._def&&e.type?._def?.typeName!==He.ZodAny&&(r.items=$s(e.type._def,{...t,currentPath:[...t.currentPath,"items"]})),e.minLength&&us(r,"minItems",e.minLength.value,e.minLength.message,t),e.maxLength&&us(r,"maxItems",e.maxLength.value,e.maxLength.message,t),e.exactLength&&(us(r,"minItems",e.exactLength.value,e.exactLength.message,t),us(r,"maxItems",e.exactLength.value,e.exactLength.message,t)),r}(e,r);case He.ZodUnion:case He.ZodDiscriminatedUnion:return function(e,t){if("openApi3"===t.target)return Rs(e,t);const r=e.options instanceof Map?Array.from(e.options.values()):e.options;if(r.every((e=>e._def.typeName in As&&(!e._def.checks||!e._def.checks.length)))){const e=r.reduce(((e,t)=>{const r=As[t._def.typeName];return r&&!e.includes(r)?[...e,r]:e}),[]);return{type:e.length>1?e:e[0]}}if(r.every((e=>"ZodLiteral"===e._def.typeName&&!e.description))){const e=r.reduce(((e,t)=>{const r=typeof t._def.value;switch(r){case"string":case"number":case"boolean":return[...e,r];case"bigint":return[...e,"integer"];case"object":if(null===t._def.value)return[...e,"null"];default:return e}}),[]);if(e.length===r.length){const t=e.filter(((e,t,r)=>r.indexOf(e)===t));return{type:t.length>1?t:t[0],enum:r.reduce(((e,t)=>e.includes(t._def.value)?e:[...e,t._def.value]),[])}}}else if(r.every((e=>"ZodEnum"===e._def.typeName)))return{type:"string",enum:r.reduce(((e,t)=>[...e,...t._def.values.filter((t=>!e.includes(t)))]),[])};return Rs(e,t)}(e,r);case He.ZodIntersection:return function(e,t){const r=[$s(e.left._def,{...t,currentPath:[...t.currentPath,"allOf","0"]}),$s(e.right._def,{...t,currentPath:[...t.currentPath,"allOf","1"]})].filter((e=>!!e));let s="jsonSchema2019-09"===t.target?{unevaluatedProperties:!1}:void 0;const a=[];return r.forEach((e=>{if("type"in(t=e)&&"string"===t.type||!("allOf"in t)){let t=e;if("additionalProperties"in e&&!1===e.additionalProperties){const{additionalProperties:r,...s}=e;t=s}else s=void 0;a.push(t)}else a.push(...e.allOf),void 0===e.unevaluatedProperties&&(s=void 0);var t})),a.length?{allOf:a,...s}:void 0}(e,r);case He.ZodTuple:return function(e,t){return e.rest?{type:"array",minItems:e.items.length,items:e.items.map(((e,r)=>$s(e._def,{...t,currentPath:[...t.currentPath,"items",`${r}`]}))).reduce(((e,t)=>void 0===t?e:[...e,t]),[]),additionalItems:$s(e.rest._def,{...t,currentPath:[...t.currentPath,"additionalItems"]})}:{type:"array",minItems:e.items.length,maxItems:e.items.length,items:e.items.map(((e,r)=>$s(e._def,{...t,currentPath:[...t.currentPath,"items",`${r}`]}))).reduce(((e,t)=>void 0===t?e:[...e,t]),[])}}(e,r);case He.ZodRecord:return Is(e,r);case He.ZodLiteral:return function(e,t){const r=typeof e.value;return"bigint"!==r&&"number"!==r&&"boolean"!==r&&"string"!==r?{type:Array.isArray(e.value)?"array":"object"}:"openApi3"===t.target?{type:"bigint"===r?"integer":r,enum:[e.value]}:{type:"bigint"===r?"integer":r,const:e.value}}(e,r);case He.ZodEnum:return function(e){return{type:"string",enum:Array.from(e.values)}}(e);case He.ZodNativeEnum:return function(e){const t=e.values,r=Object.keys(e.values).filter((e=>"number"!=typeof t[t[e]])).map((e=>t[e])),s=Array.from(new Set(r.map((e=>typeof e))));return{type:1===s.length?"string"===s[0]?"string":"number":["string","number"],enum:r}}(e);case He.ZodNullable:return function(e,t){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(e.innerType._def.typeName)&&(!e.innerType._def.checks||!e.innerType._def.checks.length))return"openApi3"===t.target?{type:As[e.innerType._def.typeName],nullable:!0}:{type:[As[e.innerType._def.typeName],"null"]};if("openApi3"===t.target){const r=$s(e.innerType._def,{...t,currentPath:[...t.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}const r=$s(e.innerType._def,{...t,currentPath:[...t.currentPath,"anyOf","0"]});return r&&{anyOf:[r,{type:"null"}]}}(e,r);case He.ZodOptional:return((e,t)=>{if(t.currentPath.toString()===t.propertyPath?.toString())return $s(e.innerType._def,t);const r=$s(e.innerType._def,{...t,currentPath:[...t.currentPath,"anyOf","1"]});return r?{anyOf:[{not:{}},r]}:{}})(e,r);case He.ZodMap:return function(e,t){return"record"===t.mapStrategy?Is(e,t):{type:"array",maxItems:125,items:{type:"array",items:[$s(e.keyType._def,{...t,currentPath:[...t.currentPath,"items","items","0"]})||{},$s(e.valueType._def,{...t,currentPath:[...t.currentPath,"items","items","1"]})||{}],minItems:2,maxItems:2}}}(e,r);case He.ZodSet:return function(e,t){const r={type:"array",uniqueItems:!0,items:$s(e.valueType._def,{...t,currentPath:[...t.currentPath,"items"]})};return e.minSize&&us(r,"minItems",e.minSize.value,e.minSize.message,t),e.maxSize&&us(r,"maxItems",e.maxSize.value,e.maxSize.message,t),r}(e,r);case He.ZodLazy:return()=>e.getter()._def;case He.ZodPromise:return function(e,t){return $s(e.type._def,t)}(e,r);case He.ZodNaN:case He.ZodNever:return{not:{}};case He.ZodEffects:return function(e,t){return"input"===t.effectStrategy?$s(e.schema._def,t):{}}(e,r);case He.ZodAny:case He.ZodUnknown:return{};case He.ZodDefault:return function(e,t){return{...$s(e.innerType._def,t),default:e.defaultValue()}}(e,r);case He.ZodBranded:return ls(e,r);case He.ZodReadonly:case He.ZodCatch:return((e,t)=>$s(e.innerType._def,t))(e,r);case He.ZodPipeline:return((e,t)=>{if("input"===t.pipeStrategy)return $s(e.in._def,t);if("output"===t.pipeStrategy)return $s(e.out._def,t);const r=$s(e.in._def,{...t,currentPath:[...t.currentPath,"allOf","0"]});return{allOf:[r,$s(e.out._def,{...t,currentPath:[...t.currentPath,"allOf",r?"1":"0"]})].filter((e=>void 0!==e))}})(e,r);case He.ZodFunction:case He.ZodVoid:case He.ZodSymbol:default:return}};function $s(e,t,r=!1){const s=t.seen.get(e);if(t.override){const a=t.override?.(e,t,s,r);if(a!==os)return a}if(s&&!r){const e=Ms(s,t);if(void 0!==e)return e}const a={def:e,path:t.currentPath,jsonSchema:void 0};t.seen.set(e,a);const n=Ns(e,e.typeName,t),i="function"==typeof n?$s(n(),t):n;if(i&&Ls(e,t,i),t.postProcess){const r=t.postProcess(i,e,t);return a.jsonSchema=i,r}return a.jsonSchema=i,i}const Ms=(e,t)=>{switch(t.$refStrategy){case"root":return{$ref:e.path.join("/")};case"relative":return{$ref:qs(t.currentPath,e.path)};case"none":case"seen":return e.path.length<t.currentPath.length&&e.path.every(((e,r)=>t.currentPath[r]===e))?(console.warn(`Recursive reference detected at ${t.currentPath.join("/")}! Defaulting to any`),{}):"seen"===t.$refStrategy?{}:void 0}},qs=(e,t)=>{let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];r++);return[(e.length-r).toString(),...t.slice(r)].join("/")},Ls=(e,t,r)=>(e.description&&(r.description=e.description,t.markdownDescription&&(r.markdownDescription=e.description)),r),zs=(e,t)=>{const r=(e=>{const t=(e=>"string"==typeof e?{...ds,name:e}:{...ds,...e})(e),r=void 0!==t.name?[...t.basePath,t.definitionPath,t.name]:t.basePath;return{...t,currentPath:r,propertyPath:void 0,seen:new Map(Object.entries(t.definitions).map((([e,r])=>[r._def,{def:r._def,path:[...t.basePath,t.definitionPath,e],jsonSchema:void 0}])))}})(t),s="object"==typeof t&&t.definitions?Object.entries(t.definitions).reduce(((e,[t,s])=>({...e,[t]:$s(s._def,{...r,currentPath:[...r.basePath,r.definitionPath,t]},!0)??{}})),{}):void 0,a="string"==typeof t?t:"title"===t?.nameStrategy?void 0:t?.name,n=$s(e._def,void 0===a?r:{...r,currentPath:[...r.basePath,r.definitionPath,a]},!1)??{},i="object"==typeof t&&void 0!==t.name&&"title"===t.nameStrategy?t.name:void 0;void 0!==i&&(n.title=i);const o=void 0===a?s?{...n,[r.definitionPath]:s}:n:{$ref:[..."relative"===r.$refStrategy?[]:r.basePath,r.definitionPath,a].join("/"),[r.definitionPath]:{...s,[a]:n}};return"jsonSchema7"===r.target?o.$schema="http://json-schema.org/draft-07/schema#":"jsonSchema2019-09"!==r.target&&"openAi"!==r.target||(o.$schema="https://json-schema.org/draft/2019-09/schema#"),"openAi"===r.target&&("anyOf"in o||"oneOf"in o||"allOf"in o||"type"in o&&Array.isArray(o.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),o};var Hs;!function(e){e.Completable="McpCompletable"}(Hs||(Hs={}));class Fs extends P{_parse(e){const{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}function Ds(e){if(!e)return{};const{errorMap:t,invalid_type_error:r,required_error:s,description:a}=e;if(t&&(r||s))throw new Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');return t?{errorMap:t,description:a}:{errorMap:(t,a)=>{var n,i;const{message:o}=e;return"invalid_enum_value"===t.code?{message:null!=o?o:a.defaultError}:void 0===a.data?{message:null!==(n=null!=o?o:s)&&void 0!==n?n:a.defaultError}:"invalid_type"!==t.code?{message:a.defaultError}:{message:null!==(i=null!=o?o:r)&&void 0!==i?i:a.defaultError}},description:a}}Fs.create=(e,t)=>new Fs({type:e,typeName:Hs.Completable,complete:t.complete,...Ds(t)});class Us{constructor(e,t){this._registeredResources={},this._registeredResourceTemplates={},this._registeredTools={},this._registeredPrompts={},this._toolHandlersInitialized=!1,this._completionHandlerInitialized=!1,this._resourceHandlersInitialized=!1,this._promptHandlersInitialized=!1,this.server=new is(e,t)}async connect(e){return await this.server.connect(e)}async close(){await this.server.close()}setToolRequestHandlers(){this._toolHandlersInitialized||(this.server.assertCanSetRequestHandler(Ar.shape.method.value),this.server.assertCanSetRequestHandler(qr.shape.method.value),this.server.registerCapabilities({tools:{listChanged:!0}}),this.server.setRequestHandler(Ar,(()=>({tools:Object.entries(this._registeredTools).filter((([,e])=>e.enabled)).map((([e,t])=>{const r={name:e,description:t.description,inputSchema:t.inputSchema?zs(t.inputSchema,{strictUnions:!0}):Vs,annotations:t.annotations};return t.outputSchema&&(r.outputSchema=zs(t.outputSchema,{strictUnions:!0})),r}))}))),this.server.setRequestHandler(qr,(async(e,t)=>{const r=this._registeredTools[e.params.name];if(!r)throw new rs(Ht.InvalidParams,`Tool ${e.params.name} not found`);if(!r.enabled)throw new rs(Ht.InvalidParams,`Tool ${e.params.name} disabled`);let s;if(r.inputSchema){const a=await r.inputSchema.safeParseAsync(e.params.arguments);if(!a.success)throw new rs(Ht.InvalidParams,`Invalid arguments for tool ${e.params.name}: ${a.error.message}`);const n=a.data,i=r.callback;try{s=await Promise.resolve(i(n,t))}catch(e){s={content:[{type:"text",text:e instanceof Error?e.message:String(e)}],isError:!0}}}else{const e=r.callback;try{s=await Promise.resolve(e(t))}catch(e){s={content:[{type:"text",text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(r.outputSchema){if(!s.structuredContent&&!s.isError)throw new rs(Ht.InternalError,`Tool ${e.params.name} has outputSchema but returned no structuredContent`);s.structuredContent&&!s.content&&(s.content=[{type:"text",text:JSON.stringify(s.structuredContent,null,2)}])}else{if(!s.content&&!s.isError)throw new rs(Ht.InternalError,`Tool ${e.params.name} has no outputSchema and must return content`);if(s.structuredContent)throw new rs(Ht.InternalError,`Tool ${e.params.name} has no outputSchema but returned structuredContent`)}return s})),this._toolHandlersInitialized=!0)}setCompletionRequestHandler(){this._completionHandlerInitialized||(this.server.assertCanSetRequestHandler(Yr.shape.method.value),this.server.setRequestHandler(Yr,(async e=>{switch(e.params.ref.type){case"ref/prompt":return this.handlePromptCompletion(e,e.params.ref);case"ref/resource":return this.handleResourceCompletion(e,e.params.ref);default:throw new rs(Ht.InvalidParams,`Invalid completion reference: ${e.params.ref}`)}})),this._completionHandlerInitialized=!0)}async handlePromptCompletion(e,t){const r=this._registeredPrompts[t.name];if(!r)throw new rs(Ht.InvalidParams,`Prompt ${t.name} not found`);if(!r.enabled)throw new rs(Ht.InvalidParams,`Prompt ${t.name} disabled`);if(!r.argsSchema)return Js;const s=r.argsSchema.shape[e.params.argument.name];if(!(s instanceof Fs))return Js;const a=s._def;return Ws(await a.complete(e.params.argument.value))}async handleResourceCompletion(e,t){const r=Object.values(this._registeredResourceTemplates).find((e=>e.resourceTemplate.uriTemplate.toString()===t.uri));if(!r){if(this._registeredResources[t.uri])return Js;throw new rs(Ht.InvalidParams,`Resource template ${e.params.ref.uri} not found`)}const s=r.resourceTemplate.completeCallback(e.params.argument.name);return s?Ws(await s(e.params.argument.value)):Js}setResourceRequestHandlers(){this._resourceHandlersInitialized||(this.server.assertCanSetRequestHandler(dr.shape.method.value),this.server.assertCanSetRequestHandler(ur.shape.method.value),this.server.assertCanSetRequestHandler(pr.shape.method.value),this.server.registerCapabilities({resources:{listChanged:!0}}),this.server.setRequestHandler(dr,(async(e,t)=>{const r=Object.entries(this._registeredResources).filter((([e,t])=>t.enabled)).map((([e,t])=>({uri:e,name:t.name,...t.metadata}))),s=[];for(const e of Object.values(this._registeredResourceTemplates)){if(!e.resourceTemplate.listCallback)continue;const r=await e.resourceTemplate.listCallback(t);for(const t of r.resources)s.push({...t,...e.metadata})}return{resources:[...r,...s]}})),this.server.setRequestHandler(ur,(async()=>({resourceTemplates:Object.entries(this._registeredResourceTemplates).map((([e,t])=>({name:e,uriTemplate:t.resourceTemplate.uriTemplate.toString(),...t.metadata})))}))),this.server.setRequestHandler(pr,(async(e,t)=>{const r=new URL(e.params.uri),s=this._registeredResources[r.toString()];if(s){if(!s.enabled)throw new rs(Ht.InvalidParams,`Resource ${r} disabled`);return s.readCallback(r,t)}for(const e of Object.values(this._registeredResourceTemplates)){const s=e.resourceTemplate.uriTemplate.match(r.toString());if(s)return e.readCallback(r,s,t)}throw new rs(Ht.InvalidParams,`Resource ${r} not found`)})),this.setCompletionRequestHandler(),this._resourceHandlersInitialized=!0)}setPromptRequestHandlers(){this._promptHandlersInitialized||(this.server.assertCanSetRequestHandler(br.shape.method.value),this.server.assertCanSetRequestHandler(kr.shape.method.value),this.server.registerCapabilities({prompts:{listChanged:!0}}),this.server.setRequestHandler(br,(()=>({prompts:Object.entries(this._registeredPrompts).filter((([,e])=>e.enabled)).map((([e,t])=>{return{name:e,description:t.description,arguments:t.argsSchema?(r=t.argsSchema,Object.entries(r.shape).map((([e,t])=>({name:e,description:t.description,required:!t.isOptional()})))):void 0};var r}))}))),this.server.setRequestHandler(kr,(async(e,t)=>{const r=this._registeredPrompts[e.params.name];if(!r)throw new rs(Ht.InvalidParams,`Prompt ${e.params.name} not found`);if(!r.enabled)throw new rs(Ht.InvalidParams,`Prompt ${e.params.name} disabled`);if(r.argsSchema){const s=await r.argsSchema.safeParseAsync(e.params.arguments);if(!s.success)throw new rs(Ht.InvalidParams,`Invalid arguments for prompt ${e.params.name}: ${s.error.message}`);const a=s.data,n=r.callback;return await Promise.resolve(n(a,t))}{const e=r.callback;return await Promise.resolve(e(t))}})),this.setCompletionRequestHandler(),this._promptHandlersInitialized=!0)}resource(e,t,...r){let s;"object"==typeof r[0]&&(s=r.shift());const a=r[0];if("string"==typeof t){if(this._registeredResources[t])throw new Error(`Resource ${t} is already registered`);const r={name:e,metadata:s,readCallback:a,enabled:!0,disable:()=>r.update({enabled:!1}),enable:()=>r.update({enabled:!0}),remove:()=>r.update({uri:null}),update:e=>{void 0!==e.uri&&e.uri!==t&&(delete this._registeredResources[t],e.uri&&(this._registeredResources[e.uri]=r)),void 0!==e.name&&(r.name=e.name),void 0!==e.metadata&&(r.metadata=e.metadata),void 0!==e.callback&&(r.readCallback=e.callback),void 0!==e.enabled&&(r.enabled=e.enabled),this.sendResourceListChanged()}};return this._registeredResources[t]=r,this.setResourceRequestHandlers(),this.sendResourceListChanged(),r}{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);const r={resourceTemplate:t,metadata:s,readCallback:a,enabled:!0,disable:()=>r.update({enabled:!1}),enable:()=>r.update({enabled:!0}),remove:()=>r.update({name:null}),update:t=>{void 0!==t.name&&t.name!==e&&(delete this._registeredResourceTemplates[e],t.name&&(this._registeredResourceTemplates[t.name]=r)),void 0!==t.template&&(r.resourceTemplate=t.template),void 0!==t.metadata&&(r.metadata=t.metadata),void 0!==t.callback&&(r.readCallback=t.callback),void 0!==t.enabled&&(r.enabled=t.enabled),this.sendResourceListChanged()}};return this._registeredResourceTemplates[e]=r,this.setResourceRequestHandlers(),this.sendResourceListChanged(),r}}_createRegisteredTool(e,t,r,s,a,n){const i={description:t,inputSchema:void 0===r?void 0:Tt.object(r),outputSchema:void 0===s?void 0:Tt.object(s),annotations:a,callback:n,enabled:!0,disable:()=>i.update({enabled:!1}),enable:()=>i.update({enabled:!0}),remove:()=>i.update({name:null}),update:t=>{void 0!==t.name&&t.name!==e&&(delete this._registeredTools[e],t.name&&(this._registeredTools[t.name]=i)),void 0!==t.description&&(i.description=t.description),void 0!==t.paramsSchema&&(i.inputSchema=Tt.object(t.paramsSchema)),void 0!==t.callback&&(i.callback=t.callback),void 0!==t.annotations&&(i.annotations=t.annotations),void 0!==t.enabled&&(i.enabled=t.enabled),this.sendToolListChanged()}};return this._registeredTools[e]=i,this.setToolRequestHandlers(),this.sendToolListChanged(),i}tool(e,...t){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);let r,s,a;if("string"==typeof t[0]&&(r=t.shift()),t.length>1){const e=t[0];Bs(e)?(s=t.shift(),t.length>1&&"object"==typeof t[0]&&null!==t[0]&&!Bs(t[0])&&(a=t.shift())):"object"==typeof e&&null!==e&&(a=t.shift())}const n=t[0];return this._createRegisteredTool(e,r,s,void 0,a,n)}registerTool(e,t,r){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);const{description:s,inputSchema:a,outputSchema:n,annotations:i}=t;return this._createRegisteredTool(e,s,a,n,i,r)}prompt(e,...t){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);let r,s;"string"==typeof t[0]&&(r=t.shift()),t.length>1&&(s=t.shift());const a=t[0],n={description:r,argsSchema:void 0===s?void 0:Tt.object(s),callback:a,enabled:!0,disable:()=>n.update({enabled:!1}),enable:()=>n.update({enabled:!0}),remove:()=>n.update({name:null}),update:t=>{void 0!==t.name&&t.name!==e&&(delete this._registeredPrompts[e],t.name&&(this._registeredPrompts[t.name]=n)),void 0!==t.description&&(n.description=t.description),void 0!==t.argsSchema&&(n.argsSchema=Tt.object(t.argsSchema)),void 0!==t.callback&&(n.callback=t.callback),void 0!==t.enabled&&(n.enabled=t.enabled),this.sendPromptListChanged()}};return this._registeredPrompts[e]=n,this.setPromptRequestHandlers(),this.sendPromptListChanged(),n}isConnected(){return void 0!==this.server.transport}sendResourceListChanged(){this.isConnected()&&this.server.sendResourceListChanged()}sendToolListChanged(){this.isConnected()&&this.server.sendToolListChanged()}sendPromptListChanged(){this.isConnected()&&this.server.sendPromptListChanged()}}const Vs={type:"object"};function Bs(e){return"object"==typeof e&&null!==e&&(0===Object.keys(e).length||Object.values(e).some(Ks))}function Ks(e){return null!==e&&"object"==typeof e&&"parse"in e&&"function"==typeof e.parse&&"safeParse"in e&&"function"==typeof e.safeParse}function Ws(e){return{completion:{values:e.slice(0,100),total:e.length,hasMore:e.length>100}}}const Js={completion:{values:[],hasMore:!1}},Ys=INJECTED_TOOLS,Gs={name:"MCP Server",version:"0.0.1",capabilities:{tools:{listChanged:!0}}};function Xs(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class Qs{start(){try{this.mcpServer.connect(this.transport),console.log("[STDIO] MCP Server running with STDIO transport"),this.setupShutdownHandlers()}catch(e){console.error("[STDIO] Error starting STDIO transport:",e),process.exit(1)}}setupShutdownHandlers(){process.on("SIGINT",this.shutdown.bind(this)),process.on("SIGTERM",this.shutdown.bind(this))}shutdown(){console.log("[STDIO] Shutting down STDIO transport"),process.exit(0)}constructor(e){Xs(this,"mcpServer",void 0),Xs(this,"transport",void 0),this.mcpServer=e,this.transport=new as}}return async function(){return new Promise((async e=>{const t=new Us(Gs),r=Object.keys(Ys).map((e=>Ys[e]()));Promise.all(r).then((r=>{r.forEach((e=>{const{default:r,metadata:s,schema:a}=e;t.tool(s.name,s.description,a,s.annotations,r)})),e(t)}))}))}().then((e=>{new Qs(e).start()})),{}})()));