xmcp 1.9.0 → 1.10.0

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,4 +1,4 @@
1
- import{createRequire as t}from"node:module";let r=t(import.meta.url);var a={6982(t){t.exports=r("crypto")},9896(t){t.exports=r("fs")},6928(t){t.exports=r("path")}},i={};function n(t){var r=i[t];if(void 0!==r)return r.exports;var o=i[t]={exports:{}};return a[t](o,o.exports,n),o.exports}n.d=(t,r)=>{for(var a in r)n.o(r,a)&&!n.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:r[a]})},n.o=(t,r)=>Object.prototype.hasOwnProperty.call(t,r);var o={};(()=>{let t,a,i,s,l,c,u,d,p,m,h,f,g,y,v,_,b,S,$,w,R;n.d(o,{r:()=>fJ});var k,x,P,E,T,j,O,C,I,N,q,A,M,z,L=Object.create,Z=Object.defineProperty,D=Object.getOwnPropertyDescriptor,V=Object.getOwnPropertyNames,U=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty,H=(t,r)=>()=>(r||t((r={exports:{}}).exports,r),r.exports),J=(t,r,a)=>(a=null!=t?L(U(t)):{},((t,r,a,i)=>{if(r&&"object"==typeof r||"function"==typeof r)for(var n,o=V(r),s=0,l=o.length;s<l;s++)n=o[s],F.call(t,n)||n===a||Z(t,n,{get:(t=>r[t]).bind(null,n),enumerable:!(i=D(r,n))||i.enumerable});return t})(!r&&t&&t.__esModule?a:Z(a,"default",{value:t,enumerable:!0}),t));let B=new Set(["https://json-schema.org/draft/2020-12/schema","http://json-schema.org/draft/2020-12/schema"]),K=new Set(["https://json-schema.org/draft/2019-09/schema","http://json-schema.org/draft/2019-09/schema"]),G=new Set(["https://json-schema.org/draft-07/schema","http://json-schema.org/draft-07/schema"]),W=new Set(["https://json-schema.org/draft-06/schema","http://json-schema.org/draft-06/schema"]);function Y(t){let r=Object.values(t).filter(t=>"number"==typeof t);return Object.entries(t).filter(([t,a])=>-1===r.indexOf(+t)).map(([t,r])=>r)}function X(t,r="|"){return t.map(t=>eb(t)).join(r)}function Q(t,r){return"bigint"==typeof r?r.toString():r}class ee{constructor(t){this._getter=t,this._value=void 0}get value(){let t=this._getter;return void 0!==t&&(this._value=t(),this._getter=void 0),this._value}}function et(t){return new ee(t)}function er(t){let r=+!!t.startsWith("^"),a=t.endsWith("$")?t.length-1:t.length;return t.slice(r,a)}let ea=Symbol("evaluating");function ei(t,r,a){Object.defineProperty(t,r,{value:a,writable:!0,enumerable:!0,configurable:!0})}function en(t){let r=Object.getOwnPropertyDescriptor(t,"shape");return r?.get?r.get.raw:r?.value}function eo(t){return en(t._zod.def)??t._zod.def.shape}function es(t,r,a){Object.defineProperty(t,r,{get(){let t=a();return ei(this,r,t),t},enumerable:!0,configurable:!0})}function el(t,r,a){r in t?ei(t,r,a):t[r]=a}function ec(t,r,a,i){let n=eo(r);for(let o of a){let a=Object.getOwnPropertyDescriptor(n,o);a.enumerable&&(a.get?es(t,o,()=>{let t=r._zod.def.shape[o];return i?i(t,o):t}):el(t,o,i?i(a.value,o):a.value))}}function eu(...t){let r={};for(let a of t)Object.assign(r,Object.getOwnPropertyDescriptors(a));return Object.defineProperties({},r)}let ed="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function ep(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}let em=et(()=>{if(eJ.jitless||"undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return Function(""),!0}catch(t){return!1}});function eh(t){if(!1===ep(t))return!1;let r=t.constructor;if(void 0===r||"function"!=typeof r)return!0;let a=r.prototype;return!1!==ep(a)&&!1!==Object.prototype.hasOwnProperty.call(a,"isPrototypeOf")}function ef(t){return eh(t)?{...t}:Array.isArray(t)?[...t]:t instanceof Map?new Map(t):t instanceof Set?new Set(t):t}let eg=new Set(["string","number","symbol"]);function ey(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ev(t,r,a){let i=new t._zod.constr(r??t._zod.def);return(!r||a?.parent)&&(i._zod.parent=t),i}function e_(t){if(!t)return{};if("string"==typeof t)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return(delete t.message,"string"==typeof t.error)?{...t,error:()=>t.error}:t}function eb(t){return"bigint"==typeof t?t.toString()+"n":"string"==typeof t?`"${t}"`:`${t}`}let eS={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-0x80000000,0x7fffffff],uint32:[0,0xffffffff],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},e$={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function ew(t,r){let a=eo(t),i=[];for(let t of Reflect.ownKeys(r)){if(!Object.getOwnPropertyDescriptor(a,t)?.enumerable)throw Error(`Unrecognized key: "${String(t)}"`);r[t]&&i.push(t)}return i}function eR(t,r){let a={};ec(a,t,Reflect.ownKeys(eo(t)));for(let t of Reflect.ownKeys(r)){let i=Object.getOwnPropertyDescriptor(r,t);i.enumerable&&(i.get?es(a,t,()=>r[t]):el(a,t,i.value))}return a}function ek(t,r,a,i="partial"){let n=r._zod.def.checks;if(n&&n.length>0)throw Error(`.${i}() cannot be used on object schemas containing refinements`);let o=a?new Set(ew(r,a)):void 0,s={};return ec(s,r,Reflect.ownKeys(eo(r)),t&&((r,a)=>o&&!o.has(a)?r:new t({type:"optional",innerType:r}))),ev(r,eu(r._zod.def,{shape:s,checks:[]}))}function ex(t,r=0){if(!0===t.aborted)return!0;for(let a=r;a<t.issues.length;a++)if(t.issues[a]?.continue!==!0)return!0;return!1}function eP(t,r){return r.map(r=>(r.path??(r.path=[]),r.path.unshift(t),r))}function eE(t){return"string"==typeof t?t:t?.message}function eT(t,r,a){var i;for(let n=r;n<t.length;n++)(i=t[n]).schema??(i.schema=a)}function ej(t,r,a){let i=t.inst?._zod?.traits;i?.has("$ZodType")&&(i.has("$ZodCheck")?t.schema??(t.schema=t.inst):t.schema=t.inst);let n=t.schema!==t.inst?t.schema?._zod.def?.error:void 0,o=t.message?t.message:eE(t.inst?._zod.def?.error?.(t))??eE(n?.(t))??eE(r?.error?.(t))??eE(a.customError?.(t))??eE(a.localeError?.(t))??"Invalid input",s={};for(let r of Object.keys(t))"inst"!==r&&"schema"!==r&&"continue"!==r&&"input"!==r&&"__proto__"!==r&&(s[r]=t[r]);return s.path??(s.path=[]),s.message=o,r?.reportInput&&(s.input=t.input),s}let eO=/[\uD800-\uDBFF]/;function eC(t){let r=t.length;if(!eO.test(t))return r;let a=r;for(let i=0;i<r-1;i++)(64512&t.charCodeAt(i))==55296&&(64512&t.charCodeAt(i+1))==56320&&(a--,i++);return a}function eI(t){return Array.isArray(t)?"array":"string"==typeof t?"string":"unknown"}function eN(...t){let[r,a,i]=t;return"string"==typeof r?{message:r,code:"custom",input:a,inst:i}:{...r}}function eq(t,r,a,i=!0){return Object.defineProperty(t,r,{configurable:!0,writable:!0,enumerable:i,value:a}),a}function eA(t,r){for(let a in t){let i=t[a];Object.defineProperty(r,a,{configurable:!0,enumerable:!0,get(){return eq(this,a,i(this))},set(t){eq(this,a,t)}})}return r}let eM=!1,ez={configurable:!0,get(){eM=!0}};function eL(r,a,i){let n=Object.getPrototypeOf(r._zod);if(a in n&&t!==r._zod){t=void 0;return}t=r._zod,Object.defineProperty(n,a,{configurable:!0,get(){Object.defineProperty(this,a,ez);let t=eM;eM=!1;try{let r=i(this);return eM?delete this[a]:Object.defineProperty(this,a,{configurable:!0,writable:!0,value:r}),eM=eM||t,r}catch(r){throw delete this[a],eM=eM||t,r}},set(t){Object.defineProperty(this,a,{configurable:!0,writable:!0,value:t})}})}let eZ=Object.freeze({status:"aborted"}),eD={value:void 0,enumerable:!1},eV="captureStackTrace"in Error?Error:null;function eU(t,r,a,i){function n(t){this.def=t,this.constr=u,this.traits=new Set}n.prototype={};let o=a&&new WeakSet;function s(i,s){if(i._zod){if(i._zod.traits.has(t))return}else{eD.value=new n(s);try{Object.defineProperty(i,"_zod",eD)}finally{eD.value=void 0}}if(i._zod.traits.add(t),r(i,s),o){let t=Object.getPrototypeOf(i),r=i._zod.constr.prototype,n=t;for(;n&&n!==r;)n=Object.getPrototypeOf(n);let s=n??t;if(!o.has(s)){o.add(s);for(let t in a){let r=Object.getOwnPropertyDescriptor(a,t);r.get?Object.defineProperty(s,t,{...r,enumerable:!1}):function(t,r,a){Object.defineProperty(t,r,{configurable:!0,get(){return this==null?a:eq(this,r,a.bind(this))},set(t){eq(this,r,t)}})}(s,t,r.value)}}}let l=u.prototype;for(let t in l)Object.prototype.hasOwnProperty.call(l,t)&&(t in i||(i[t]=l[t].bind(i)))}let l=i?.Parent??Object;class c extends l{}function u(t){let r=i?.Parent?function(t){let r=eV;if(r){let a=r.stackTraceLimit;if("number"==typeof a){try{r.stackTraceLimit=0}catch{return eV=null,new t}try{return new t}finally{r.stackTraceLimit=a}}}return new t}(c):this;s(r,t);let a=r._zod.deferred;if(a){for(let t of a)t();r._zod.deferred=void 0}let n=globalThis.__zod_globalConfig?.postProcessor;return n&&n(r),r}return Object.defineProperty(c,"name",{value:t}),Object.defineProperty(u,"init",{value:s}),Object.defineProperty(u,Symbol.hasInstance,{value:r=>!!i?.Parent&&r instanceof i.Parent||r?._zod?.traits?.has(t)}),Object.defineProperty(u,"name",{value:t}),u}class eF extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class eH extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}(C=globalThis).__zod_globalConfig??(C.__zod_globalConfig={});let eJ=globalThis.__zod_globalConfig;function eB(t){return t&&Object.assign(eJ,t),eJ}class eK extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform"),this.name="ZodCyclicError"}}let eG="~memo",eW=[];function eY(t){return null!==t&&"object"==typeof t}function eX(t){return t.map(t=>t.path?{...t,path:t.path.slice()}:{...t})}let eQ=new WeakMap,e0=[],e1={alloc(t,r,i){let n=a;if(!n)return i;a=void 0;let o={value:i,issues:null};return n.set(r.value,o),e0.push(o),i},guard(t){var r;(r=t._zod).deferred??(r.deferred=[]),t._zod.deferred.push(()=>{let r=t._zod.parse,a=(t,a)=>{var i,n;let o;if("backward"!==a.direction&&(i=a,n=t.value,void 0!==(o=i[eG]?.backEdges)&&eY(n)&&o.has(n)))throw new eK;return r(t,a)};t._zod.parse=a,t._zod.run===r&&(t._zod.run=a)})},attach(t){var r;let i,n,o,s=!1;(r=t._zod).deferred??(r.deferred=[]),t._zod.deferred.push(()=>{let r=t._zod.parse,l=(c,u)=>{let d;if(void 0===i){let a=function t(r,a,i){var n,o;let s=eQ.get(r);if(void 0!==s)return 2*!!s;if(a.has(r))return 2;a.add(r);let l=0,c=r=>{if(2!==l&&r?._zod){let n=t(r,a,i);n>l&&(l=n)}},u=t=>{t>l&&(l=t)},d=r._zod.def;switch(d.type){case"object":{let r=en(d);u(r?((r,n)=>{let o=0;for(let s of Reflect.ownKeys(r)){let l=Object.getOwnPropertyDescriptor(r,s);if(n&&!l.enumerable)continue;let c=l.get?1:l.value?._zod?t(l.value,a,i):0;c>o&&(o=c)}return o})(r,!0):1),c(d.catchall);break}case"array":c(d.element);break;case"tuple":for(let t of d.items)c(t);c(d.rest);break;case"record":case"map":c(d.keyType),c(d.valueType);break;case"set":c(d.valueType);break;case"union":for(let t of d.options)c(t);break;case"intersection":c(d.left),c(d.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":c(d.innerType);break;case"pipe":c(d.in),c(d.out);break;case"function":c(d.input),c(d.output);break;case"lazy":{let n=d._cachedInner??(i?r._zod.innerType:void 0);u(n?t(n,a,!1):1);break}case"template_literal":case"string":case"number":case"int":case"boolean":case"bigint":case"symbol":case"undefined":case"null":case"void":case"never":case"any":case"unknown":case"date":case"nan":case"enum":case"literal":case"file":case"transform":case"custom":break;default:for(let t in d){let r=Object.getOwnPropertyDescriptor(d,t);if(!r||r.get)continue;let a=r.value;if(a&&"object"==typeof a){if(a._zod)c(a);else if(Array.isArray(a))for(let t of a)c(t)}}}return a.delete(r),n=r,1!==(o=l)&&eQ.set(n,2===o),o}(t,new Set,!1);if(0===a)return t._zod.parse=r,t._zod.run===l&&(t._zod.run=r),r(c,u);2===a||s?i=!0:s=!0}let p=c.value;if(!eY(p))return r(c,u);let m=u[eG];if(m||(m={buckets:new WeakMap,backEdges:void 0},u[eG]=m),n===u)d=o;else{var h;let r;(r=(h=m).buckets.get(t))||(r=new WeakMap,h.buckets.set(t,r)),d=r,n=u,o=d}let f=d.get(p);if(f)return c.value=f.value,f.issues?f.issues.length&&c.issues.push(...eX(f.issues)):(c.memo=!0,m.backEdges??(m.backEdges=new WeakSet),m.backEdges.add(f.value)),c;a=d;let g=e0.length,y=r(c,u);a=void 0;let v=e0.length>g?e0.pop():void 0;return y instanceof Promise?y.then(t=>(v&&(v.issues=t.issues.length?eX(t.issues):eW),t)):(v&&(v.issues=y.issues.length?eX(y.issues):eW),y)};t._zod.parse=l,t._zod.run===r&&(t._zod.run=l)})}},e2=/^[cC][0-9a-z]{6,}$/,e9=/^[0-9a-z]+$/,e4=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,e3=/^[0-9a-vA-V]{20}$/,e6=/^[A-Za-z0-9]{27}$/,e5=/^[a-zA-Z0-9_-]{21}$/,e7=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,e8=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,te=t=>t?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,tt=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,tr=`^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`,ta=/^(?:(?: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])$/,ti=/^(([0-9a-fA-F]{1,4}:){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}|:))$/,tn=/^((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])\/([0-9]|[1-2][0-9]|3[0-2])$/,to=/^(([0-9a-fA-F]{1,4}:){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}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ts=/^https?$/,tl=/^\+[1-9]\d{6,14}$/,tc="(?:(?:\\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])))",tu=RegExp(`^${tc}$`);function td(t){let r="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof t.precision?-1===t.precision?`${r}`:0===t.precision?`${r}:[0-5]\\d`:`${r}:[0-5]\\d\\.\\d{${t.precision}}`:t.seconds?`${r}:[0-5]\\d(?:\\.\\d+)?`:`${r}(?::[0-5]\\d(?:\\.\\d+)?)?`}let tp=/^[\s\S]{0,}$/,tm=/^-?\d+$/,th=/^-?\d+(?:\.\d+)?$/,tf=/^(?:true|false)$/i,tg=/^null$/i,ty=/^[^A-Z]*$/,tv=/^[^a-z]*$/,t_=eU("$ZodCheck",(t,r)=>{var a;t._zod??(t._zod={}),t._zod.def=r,(a=t._zod).onattach??(a.onattach=[])}),tb=t=>{let r=t.value;return null!=r&&void 0!==r.length},tS={number:"number",bigint:"bigint",object:"date"},t$=eU("$ZodCheckLessThan",(t,r)=>{t_.init(t,r);let a=tS[typeof r.value];t._zod.check=i=>{(r.inclusive?i.value<=r.value:i.value<r.value)||i.issues.push({origin:tS[typeof i.value]??a,code:"too_big",maximum:"object"==typeof r.value?r.value.getTime():r.value,input:i.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),tw=eU("$ZodCheckGreaterThan",(t,r)=>{t_.init(t,r);let a=tS[typeof r.value];t._zod.check=i=>{(r.inclusive?i.value>=r.value:i.value>r.value)||i.issues.push({origin:tS[typeof i.value]??a,code:"too_small",minimum:"object"==typeof r.value?r.value.getTime():r.value,input:i.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),tR=eU("$ZodCheckMultipleOf",(t,r)=>{t_.init(t,r),t._zod.check=a=>{let i,n,o;if(typeof a.value!=typeof r.value)throw Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof a.value?r.value!==BigInt(0)&&a.value%r.value===BigInt(0):0==(n=Math.round(i=a.value/r.value),o=4*Number.EPSILON*Math.max(Math.abs(i),1),Math.abs(i-n)<o?0:i-n))||a.issues.push({origin:typeof a.value,code:"not_multiple_of",divisor:r.value,input:a.value,inst:t,continue:!r.abort})}}),tk=eU("$ZodCheckNumberFormat",(t,r)=>{t_.init(t,r),r.format=r.format||"float64";let a=r.format?.includes("int"),i=a?"int":"number",[n,o]=eS[r.format];t._zod.check=s=>{let l=s.value;if(a){if(!Number.isInteger(l))return void s.issues.push({expected:i,format:r.format,code:"invalid_type",continue:!1,input:l,inst:t});if(!Number.isSafeInteger(l))return void(l>0?s.issues.push({input:l,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:i,inclusive:!0,continue:!r.abort}):s.issues.push({input:l,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:i,inclusive:!0,continue:!r.abort}))}l<n&&s.issues.push({origin:"number",input:l,code:"too_small",minimum:n,inclusive:!0,inst:t,continue:!r.abort}),l>o&&s.issues.push({origin:"number",input:l,code:"too_big",maximum:o,inclusive:!0,inst:t,continue:!r.abort})}}),tx=eU("$ZodCheckMaxLength",(t,r)=>{var a;t_.init(t,r),(a=t._zod.def).when??(a.when=tb),t._zod.check=a=>{let i=a.value,n=i.length;if(("string"==typeof i&&n>r.maximum?eC(i):n)<=r.maximum)return;let o=eI(i);a.issues.push({origin:o,code:"too_big",maximum:r.maximum,inclusive:!0,input:i,inst:t,continue:!r.abort})}}),tP=eU("$ZodCheckMinLength",(t,r)=>{var a;t_.init(t,r),(a=t._zod.def).when??(a.when=tb),t._zod.check=a=>{let i=a.value,n=i.length;if(("string"==typeof i&&n>=r.minimum&&n<2*r.minimum?eC(i):n)>=r.minimum)return;let o=eI(i);a.issues.push({origin:o,code:"too_small",minimum:r.minimum,inclusive:!0,input:i,inst:t,continue:!r.abort})}}),tE=eU("$ZodCheckLengthEquals",(t,r)=>{var a;t_.init(t,r),(a=t._zod.def).when??(a.when=tb),t._zod.check=a=>{let i=a.value,n=i.length,o="string"==typeof i&&n>=r.length&&n<=2*r.length?eC(i):n;if(o===r.length)return;let s=eI(i),l=o>r.length;a.issues.push({origin:s,...l?{code:"too_big",maximum:r.length}:{code:"too_small",minimum:r.length},inclusive:!0,exact:!0,input:a.value,inst:t,continue:!r.abort})}}),tT=eU("$ZodCheckStringFormat",(t,r)=>{var a,i;t_.init(t,r),r.pattern?(a=t._zod).check??(a.check=a=>{r.pattern.lastIndex=0,r.pattern.test(a.value)||a.issues.push({origin:"string",code:"invalid_format",format:r.format,input:a.value,...r.pattern?{pattern:r.pattern.toString()}:{},inst:t,continue:!r.abort})}):(i=t._zod).check??(i.check=()=>{})}),tj=eU("$ZodCheckRegex",(t,r)=>{tT.init(t,r),t._zod.check=a=>{r.pattern.lastIndex=0,r.pattern.test(a.value)||a.issues.push({origin:"string",code:"invalid_format",format:"regex",input:a.value,pattern:r.pattern.toString(),inst:t,continue:!r.abort})}}),tO=eU("$ZodCheckLowerCase",(t,r)=>{r.pattern??(r.pattern=ty),tT.init(t,r)}),tC=eU("$ZodCheckUpperCase",(t,r)=>{r.pattern??(r.pattern=tv),tT.init(t,r)}),tI=eU("$ZodCheckIncludes",(t,r)=>{t_.init(t,r);let a=ey(r.includes),i=new RegExp("number"==typeof r.position?`^.{${r.position},}${a}`:a);r.pattern=i,t._zod.check=a=>{a.value.includes(r.includes,r.position)||a.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:r.includes,input:a.value,inst:t,continue:!r.abort})}}),tN=eU("$ZodCheckStartsWith",(t,r)=>{t_.init(t,r);let a=RegExp(`^${ey(r.prefix)}.*`);r.pattern??(r.pattern=a),t._zod.check=a=>{a.value.startsWith(r.prefix)||a.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:r.prefix,input:a.value,inst:t,continue:!r.abort})}}),tq=eU("$ZodCheckEndsWith",(t,r)=>{t_.init(t,r);let a=RegExp(`.*${ey(r.suffix)}$`);r.pattern??(r.pattern=a),t._zod.check=a=>{a.value.endsWith(r.suffix)||a.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:r.suffix,input:a.value,inst:t,continue:!r.abort})}}),tA=eU("$ZodCheckOverwrite",(t,r)=>{t_.init(t,r),t._zod.check=t=>{t.value=r.tx(t.value)}});class tM{constructor(t=[],r={}){this.content=[],this.indent=0,this.args=t,this.closed=r}indented(t){this.indent+=1;try{t(this)}finally{this.indent-=1}}write(t){if("function"==typeof t){t(this,{execution:"sync"}),t(this,{execution:"async"});return}let r=t.split("\n").filter(t=>t),a=Math.min(...r.map(t=>t.length-t.trimStart().length));for(let t of r.map(t=>t.slice(a)).map(t=>" ".repeat(2*this.indent)+t))this.content.push(t)}compile(){let t=Function,r=this?.content??[""];return new t(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
1
+ import{createRequire as t}from"node:module";let r=t(import.meta.url);var a={6982(t){t.exports=r("crypto")},9896(t){t.exports=r("fs")},6928(t){t.exports=r("path")}},i={};function n(t){var r=i[t];if(void 0!==r)return r.exports;var o=i[t]={exports:{}};return a[t](o,o.exports,n),o.exports}n.d=(t,r)=>{for(var a in r)n.o(r,a)&&!n.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:r[a]})},n.o=(t,r)=>Object.prototype.hasOwnProperty.call(t,r);var o={};(()=>{let t,a,i,s,l,c,u,d,p,m,h,f,g,y,v,_,b,S,$,w,R;n.d(o,{r:()=>fQ});var k,x,P,E,T,j,O,C,I,N,q,A,M,z,L=Object.create,Z=Object.defineProperty,D=Object.getOwnPropertyDescriptor,V=Object.getOwnPropertyNames,U=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty,H=(t,r)=>()=>(r||t((r={exports:{}}).exports,r),r.exports),J=(t,r,a)=>(a=null!=t?L(U(t)):{},((t,r,a,i)=>{if(r&&"object"==typeof r||"function"==typeof r)for(var n,o=V(r),s=0,l=o.length;s<l;s++)n=o[s],F.call(t,n)||n===a||Z(t,n,{get:(t=>r[t]).bind(null,n),enumerable:!(i=D(r,n))||i.enumerable});return t})(!r&&t&&t.__esModule?a:Z(a,"default",{value:t,enumerable:!0}),t));let B=new Set(["https://json-schema.org/draft/2020-12/schema","http://json-schema.org/draft/2020-12/schema"]),K=new Set(["https://json-schema.org/draft/2019-09/schema","http://json-schema.org/draft/2019-09/schema"]),G=new Set(["https://json-schema.org/draft-07/schema","http://json-schema.org/draft-07/schema"]),W=new Set(["https://json-schema.org/draft-06/schema","http://json-schema.org/draft-06/schema"]);function Y(t){let r=Object.values(t).filter(t=>"number"==typeof t);return Object.entries(t).filter(([t,a])=>-1===r.indexOf(+t)).map(([t,r])=>r)}function X(t,r="|"){return t.map(t=>eb(t)).join(r)}function Q(t,r){return"bigint"==typeof r?r.toString():r}class ee{constructor(t){this._getter=t,this._value=void 0}get value(){let t=this._getter;return void 0!==t&&(this._value=t(),this._getter=void 0),this._value}}function et(t){return new ee(t)}function er(t){let r=+!!t.startsWith("^"),a=t.endsWith("$")?t.length-1:t.length;return t.slice(r,a)}let ea=Symbol("evaluating");function ei(t,r,a){Object.defineProperty(t,r,{value:a,writable:!0,enumerable:!0,configurable:!0})}function en(t){let r=Object.getOwnPropertyDescriptor(t,"shape");return r?.get?r.get.raw:r?.value}function eo(t){return en(t._zod.def)??t._zod.def.shape}function es(t,r,a){Object.defineProperty(t,r,{get(){let t=a();return ei(this,r,t),t},enumerable:!0,configurable:!0})}function el(t,r,a){r in t?ei(t,r,a):t[r]=a}function ec(t,r,a,i){let n=eo(r);for(let o of a){let a=Object.getOwnPropertyDescriptor(n,o);a.enumerable&&(a.get?es(t,o,()=>{let t=r._zod.def.shape[o];return i?i(t,o):t}):el(t,o,i?i(a.value,o):a.value))}}function eu(...t){let r={};for(let a of t)Object.assign(r,Object.getOwnPropertyDescriptors(a));return Object.defineProperties({},r)}let ed="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function ep(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}let em=et(()=>{if(eJ.jitless||"undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return Function(""),!0}catch(t){return!1}});function eh(t){if(!1===ep(t))return!1;let r=t.constructor;if(void 0===r||"function"!=typeof r)return!0;let a=r.prototype;return!1!==ep(a)&&!1!==Object.prototype.hasOwnProperty.call(a,"isPrototypeOf")}function ef(t){return eh(t)?{...t}:Array.isArray(t)?[...t]:t instanceof Map?new Map(t):t instanceof Set?new Set(t):t}let eg=new Set(["string","number","symbol"]);function ey(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ev(t,r,a){let i=new t._zod.constr(r??t._zod.def);return(!r||a?.parent)&&(i._zod.parent=t),i}function e_(t){if(!t)return{};if("string"==typeof t)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return(delete t.message,"string"==typeof t.error)?{...t,error:()=>t.error}:t}function eb(t){return"bigint"==typeof t?t.toString()+"n":"string"==typeof t?`"${t}"`:`${t}`}let eS={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-0x80000000,0x7fffffff],uint32:[0,0xffffffff],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},e$={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function ew(t,r){let a=eo(t),i=[];for(let t of Reflect.ownKeys(r)){if(!Object.getOwnPropertyDescriptor(a,t)?.enumerable)throw Error(`Unrecognized key: "${String(t)}"`);r[t]&&i.push(t)}return i}function eR(t,r){let a={};ec(a,t,Reflect.ownKeys(eo(t)));for(let t of Reflect.ownKeys(r)){let i=Object.getOwnPropertyDescriptor(r,t);i.enumerable&&(i.get?es(a,t,()=>r[t]):el(a,t,i.value))}return a}function ek(t,r,a,i="partial"){let n=r._zod.def.checks;if(n&&n.length>0)throw Error(`.${i}() cannot be used on object schemas containing refinements`);let o=a?new Set(ew(r,a)):void 0,s={};return ec(s,r,Reflect.ownKeys(eo(r)),t&&((r,a)=>o&&!o.has(a)?r:new t({type:"optional",innerType:r}))),ev(r,eu(r._zod.def,{shape:s,checks:[]}))}function ex(t,r=0){if(!0===t.aborted)return!0;for(let a=r;a<t.issues.length;a++)if(t.issues[a]?.continue!==!0)return!0;return!1}function eP(t,r){return r.map(r=>(r.path??(r.path=[]),r.path.unshift(t),r))}function eE(t){return"string"==typeof t?t:t?.message}function eT(t,r,a){var i;for(let n=r;n<t.length;n++)(i=t[n]).schema??(i.schema=a)}function ej(t,r,a){let i=t.inst?._zod?.traits;i?.has("$ZodType")&&(i.has("$ZodCheck")?t.schema??(t.schema=t.inst):t.schema=t.inst);let n=t.schema!==t.inst?t.schema?._zod.def?.error:void 0,o=t.message?t.message:eE(t.inst?._zod.def?.error?.(t))??eE(n?.(t))??eE(r?.error?.(t))??eE(a.customError?.(t))??eE(a.localeError?.(t))??"Invalid input",s={};for(let r of Object.keys(t))"inst"!==r&&"schema"!==r&&"continue"!==r&&"input"!==r&&"__proto__"!==r&&(s[r]=t[r]);return s.path??(s.path=[]),s.message=o,r?.reportInput&&(s.input=t.input),s}let eO=/[\uD800-\uDBFF]/;function eC(t){let r=t.length;if(!eO.test(t))return r;let a=r;for(let i=0;i<r-1;i++)(64512&t.charCodeAt(i))==55296&&(64512&t.charCodeAt(i+1))==56320&&(a--,i++);return a}function eI(t){return Array.isArray(t)?"array":"string"==typeof t?"string":"unknown"}function eN(...t){let[r,a,i]=t;return"string"==typeof r?{message:r,code:"custom",input:a,inst:i}:{...r}}function eq(t,r,a,i=!0){return Object.defineProperty(t,r,{configurable:!0,writable:!0,enumerable:i,value:a}),a}function eA(t,r){for(let a in t){let i=t[a];Object.defineProperty(r,a,{configurable:!0,enumerable:!0,get(){return eq(this,a,i(this))},set(t){eq(this,a,t)}})}return r}let eM=!1,ez={configurable:!0,get(){eM=!0}};function eL(r,a,i){let n=Object.getPrototypeOf(r._zod);if(a in n&&t!==r._zod){t=void 0;return}t=r._zod,Object.defineProperty(n,a,{configurable:!0,get(){Object.defineProperty(this,a,ez);let t=eM;eM=!1;try{let r=i(this);return eM?delete this[a]:Object.defineProperty(this,a,{configurable:!0,writable:!0,value:r}),eM=eM||t,r}catch(r){throw delete this[a],eM=eM||t,r}},set(t){Object.defineProperty(this,a,{configurable:!0,writable:!0,value:t})}})}let eZ=Object.freeze({status:"aborted"}),eD={value:void 0,enumerable:!1},eV="captureStackTrace"in Error?Error:null;function eU(t,r,a,i){function n(t){this.def=t,this.constr=u,this.traits=new Set}n.prototype={};let o=a&&new WeakSet;function s(i,s){if(i._zod){if(i._zod.traits.has(t))return}else{eD.value=new n(s);try{Object.defineProperty(i,"_zod",eD)}finally{eD.value=void 0}}if(i._zod.traits.add(t),r(i,s),o){let t=Object.getPrototypeOf(i),r=i._zod.constr.prototype,n=t;for(;n&&n!==r;)n=Object.getPrototypeOf(n);let s=n??t;if(!o.has(s)){o.add(s);for(let t in a){let r=Object.getOwnPropertyDescriptor(a,t);r.get?Object.defineProperty(s,t,{...r,enumerable:!1}):function(t,r,a){Object.defineProperty(t,r,{configurable:!0,get(){return this==null?a:eq(this,r,a.bind(this))},set(t){eq(this,r,t)}})}(s,t,r.value)}}}let l=u.prototype;for(let t in l)Object.prototype.hasOwnProperty.call(l,t)&&(t in i||(i[t]=l[t].bind(i)))}let l=i?.Parent??Object;class c extends l{}function u(t){let r=i?.Parent?function(t){let r=eV;if(r){let a=r.stackTraceLimit;if("number"==typeof a){try{r.stackTraceLimit=0}catch{return eV=null,new t}try{return new t}finally{r.stackTraceLimit=a}}}return new t}(c):this;s(r,t);let a=r._zod.deferred;if(a){for(let t of a)t();r._zod.deferred=void 0}let n=globalThis.__zod_globalConfig?.postProcessor;return n&&n(r),r}return Object.defineProperty(c,"name",{value:t}),Object.defineProperty(u,"init",{value:s}),Object.defineProperty(u,Symbol.hasInstance,{value:r=>!!i?.Parent&&r instanceof i.Parent||r?._zod?.traits?.has(t)}),Object.defineProperty(u,"name",{value:t}),u}class eF extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class eH extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}(C=globalThis).__zod_globalConfig??(C.__zod_globalConfig={});let eJ=globalThis.__zod_globalConfig;function eB(t){return t&&Object.assign(eJ,t),eJ}class eK extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform"),this.name="ZodCyclicError"}}let eG="~memo",eW=[];function eY(t){return null!==t&&"object"==typeof t}function eX(t){return t.map(t=>t.path?{...t,path:t.path.slice()}:{...t})}let eQ=new WeakMap,e0=[],e1={alloc(t,r,i){let n=a;if(!n)return i;a=void 0;let o={value:i,issues:null};return n.set(r.value,o),e0.push(o),i},guard(t){var r;(r=t._zod).deferred??(r.deferred=[]),t._zod.deferred.push(()=>{let r=t._zod.parse,a=(t,a)=>{var i,n;let o;if("backward"!==a.direction&&(i=a,n=t.value,void 0!==(o=i[eG]?.backEdges)&&eY(n)&&o.has(n)))throw new eK;return r(t,a)};t._zod.parse=a,t._zod.run===r&&(t._zod.run=a)})},attach(t){var r;let i,n,o,s=!1;(r=t._zod).deferred??(r.deferred=[]),t._zod.deferred.push(()=>{let r=t._zod.parse,l=(c,u)=>{let d;if(void 0===i){let a=function t(r,a,i){var n,o;let s=eQ.get(r);if(void 0!==s)return 2*!!s;if(a.has(r))return 2;a.add(r);let l=0,c=r=>{if(2!==l&&r?._zod){let n=t(r,a,i);n>l&&(l=n)}},u=t=>{t>l&&(l=t)},d=r._zod.def;switch(d.type){case"object":{let r=en(d);u(r?((r,n)=>{let o=0;for(let s of Reflect.ownKeys(r)){let l=Object.getOwnPropertyDescriptor(r,s);if(n&&!l.enumerable)continue;let c=l.get?1:l.value?._zod?t(l.value,a,i):0;c>o&&(o=c)}return o})(r,!0):1),c(d.catchall);break}case"array":c(d.element);break;case"tuple":for(let t of d.items)c(t);c(d.rest);break;case"record":case"map":c(d.keyType),c(d.valueType);break;case"set":c(d.valueType);break;case"union":for(let t of d.options)c(t);break;case"intersection":c(d.left),c(d.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":c(d.innerType);break;case"pipe":c(d.in),c(d.out);break;case"function":c(d.input),c(d.output);break;case"lazy":{let n=d._cachedInner??(i?r._zod.innerType:void 0);u(n?t(n,a,!1):1);break}case"template_literal":case"string":case"number":case"int":case"boolean":case"bigint":case"symbol":case"undefined":case"null":case"void":case"never":case"any":case"unknown":case"date":case"nan":case"enum":case"literal":case"file":case"transform":case"custom":break;default:for(let t in d){let r=Object.getOwnPropertyDescriptor(d,t);if(!r||r.get)continue;let a=r.value;if(a&&"object"==typeof a){if(a._zod)c(a);else if(Array.isArray(a))for(let t of a)c(t)}}}return a.delete(r),n=r,1!==(o=l)&&eQ.set(n,2===o),o}(t,new Set,!1);if(0===a)return t._zod.parse=r,t._zod.run===l&&(t._zod.run=r),r(c,u);2===a||s?i=!0:s=!0}let p=c.value;if(!eY(p))return r(c,u);let m=u[eG];if(m||(m={buckets:new WeakMap,backEdges:void 0},u[eG]=m),n===u)d=o;else{var h;let r;(r=(h=m).buckets.get(t))||(r=new WeakMap,h.buckets.set(t,r)),d=r,n=u,o=d}let f=d.get(p);if(f)return c.value=f.value,f.issues?f.issues.length&&c.issues.push(...eX(f.issues)):(c.memo=!0,m.backEdges??(m.backEdges=new WeakSet),m.backEdges.add(f.value)),c;a=d;let g=e0.length,y=r(c,u);a=void 0;let v=e0.length>g?e0.pop():void 0;return y instanceof Promise?y.then(t=>(v&&(v.issues=t.issues.length?eX(t.issues):eW),t)):(v&&(v.issues=y.issues.length?eX(y.issues):eW),y)};t._zod.parse=l,t._zod.run===r&&(t._zod.run=l)})}},e2=/^[cC][0-9a-z]{6,}$/,e9=/^[0-9a-z]+$/,e4=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,e3=/^[0-9a-vA-V]{20}$/,e6=/^[A-Za-z0-9]{27}$/,e5=/^[a-zA-Z0-9_-]{21}$/,e7=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,e8=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,te=t=>t?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,tt=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,tr=`^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`,ta=/^(?:(?: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])$/,ti=/^(([0-9a-fA-F]{1,4}:){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}|:))$/,tn=/^((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])\/([0-9]|[1-2][0-9]|3[0-2])$/,to=/^(([0-9a-fA-F]{1,4}:){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}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ts=/^https?$/,tl=/^\+[1-9]\d{6,14}$/,tc="(?:(?:\\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])))",tu=RegExp(`^${tc}$`);function td(t){let r="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof t.precision?-1===t.precision?`${r}`:0===t.precision?`${r}:[0-5]\\d`:`${r}:[0-5]\\d\\.\\d{${t.precision}}`:t.seconds?`${r}:[0-5]\\d(?:\\.\\d+)?`:`${r}(?::[0-5]\\d(?:\\.\\d+)?)?`}let tp=/^[\s\S]{0,}$/,tm=/^-?\d+$/,th=/^-?\d+(?:\.\d+)?$/,tf=/^(?:true|false)$/i,tg=/^null$/i,ty=/^[^A-Z]*$/,tv=/^[^a-z]*$/,t_=eU("$ZodCheck",(t,r)=>{var a;t._zod??(t._zod={}),t._zod.def=r,(a=t._zod).onattach??(a.onattach=[])}),tb=t=>{let r=t.value;return null!=r&&void 0!==r.length},tS={number:"number",bigint:"bigint",object:"date"},t$=eU("$ZodCheckLessThan",(t,r)=>{t_.init(t,r);let a=tS[typeof r.value];t._zod.check=i=>{(r.inclusive?i.value<=r.value:i.value<r.value)||i.issues.push({origin:tS[typeof i.value]??a,code:"too_big",maximum:"object"==typeof r.value?r.value.getTime():r.value,input:i.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),tw=eU("$ZodCheckGreaterThan",(t,r)=>{t_.init(t,r);let a=tS[typeof r.value];t._zod.check=i=>{(r.inclusive?i.value>=r.value:i.value>r.value)||i.issues.push({origin:tS[typeof i.value]??a,code:"too_small",minimum:"object"==typeof r.value?r.value.getTime():r.value,input:i.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),tR=eU("$ZodCheckMultipleOf",(t,r)=>{t_.init(t,r),t._zod.check=a=>{let i,n,o;if(typeof a.value!=typeof r.value)throw Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof a.value?r.value!==BigInt(0)&&a.value%r.value===BigInt(0):0==(n=Math.round(i=a.value/r.value),o=4*Number.EPSILON*Math.max(Math.abs(i),1),Math.abs(i-n)<o?0:i-n))||a.issues.push({origin:typeof a.value,code:"not_multiple_of",divisor:r.value,input:a.value,inst:t,continue:!r.abort})}}),tk=eU("$ZodCheckNumberFormat",(t,r)=>{t_.init(t,r),r.format=r.format||"float64";let a=r.format?.includes("int"),i=a?"int":"number",[n,o]=eS[r.format];t._zod.check=s=>{let l=s.value;if(a){if(!Number.isInteger(l))return void s.issues.push({expected:i,format:r.format,code:"invalid_type",continue:!1,input:l,inst:t});if(!Number.isSafeInteger(l))return void(l>0?s.issues.push({input:l,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:i,inclusive:!0,continue:!r.abort}):s.issues.push({input:l,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:i,inclusive:!0,continue:!r.abort}))}l<n&&s.issues.push({origin:"number",input:l,code:"too_small",minimum:n,inclusive:!0,inst:t,continue:!r.abort}),l>o&&s.issues.push({origin:"number",input:l,code:"too_big",maximum:o,inclusive:!0,inst:t,continue:!r.abort})}}),tx=eU("$ZodCheckMaxLength",(t,r)=>{var a;t_.init(t,r),(a=t._zod.def).when??(a.when=tb),t._zod.check=a=>{let i=a.value,n=i.length;if(("string"==typeof i&&n>r.maximum?eC(i):n)<=r.maximum)return;let o=eI(i);a.issues.push({origin:o,code:"too_big",maximum:r.maximum,inclusive:!0,input:i,inst:t,continue:!r.abort})}}),tP=eU("$ZodCheckMinLength",(t,r)=>{var a;t_.init(t,r),(a=t._zod.def).when??(a.when=tb),t._zod.check=a=>{let i=a.value,n=i.length;if(("string"==typeof i&&n>=r.minimum&&n<2*r.minimum?eC(i):n)>=r.minimum)return;let o=eI(i);a.issues.push({origin:o,code:"too_small",minimum:r.minimum,inclusive:!0,input:i,inst:t,continue:!r.abort})}}),tE=eU("$ZodCheckLengthEquals",(t,r)=>{var a;t_.init(t,r),(a=t._zod.def).when??(a.when=tb),t._zod.check=a=>{let i=a.value,n=i.length,o="string"==typeof i&&n>=r.length&&n<=2*r.length?eC(i):n;if(o===r.length)return;let s=eI(i),l=o>r.length;a.issues.push({origin:s,...l?{code:"too_big",maximum:r.length}:{code:"too_small",minimum:r.length},inclusive:!0,exact:!0,input:a.value,inst:t,continue:!r.abort})}}),tT=eU("$ZodCheckStringFormat",(t,r)=>{var a,i;t_.init(t,r),r.pattern?(a=t._zod).check??(a.check=a=>{r.pattern.lastIndex=0,r.pattern.test(a.value)||a.issues.push({origin:"string",code:"invalid_format",format:r.format,input:a.value,...r.pattern?{pattern:r.pattern.toString()}:{},inst:t,continue:!r.abort})}):(i=t._zod).check??(i.check=()=>{})}),tj=eU("$ZodCheckRegex",(t,r)=>{tT.init(t,r),t._zod.check=a=>{r.pattern.lastIndex=0,r.pattern.test(a.value)||a.issues.push({origin:"string",code:"invalid_format",format:"regex",input:a.value,pattern:r.pattern.toString(),inst:t,continue:!r.abort})}}),tO=eU("$ZodCheckLowerCase",(t,r)=>{r.pattern??(r.pattern=ty),tT.init(t,r)}),tC=eU("$ZodCheckUpperCase",(t,r)=>{r.pattern??(r.pattern=tv),tT.init(t,r)}),tI=eU("$ZodCheckIncludes",(t,r)=>{t_.init(t,r);let a=ey(r.includes),i=new RegExp("number"==typeof r.position?`^.{${r.position},}${a}`:a);r.pattern=i,t._zod.check=a=>{a.value.includes(r.includes,r.position)||a.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:r.includes,input:a.value,inst:t,continue:!r.abort})}}),tN=eU("$ZodCheckStartsWith",(t,r)=>{t_.init(t,r);let a=RegExp(`^${ey(r.prefix)}.*`);r.pattern??(r.pattern=a),t._zod.check=a=>{a.value.startsWith(r.prefix)||a.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:r.prefix,input:a.value,inst:t,continue:!r.abort})}}),tq=eU("$ZodCheckEndsWith",(t,r)=>{t_.init(t,r);let a=RegExp(`.*${ey(r.suffix)}$`);r.pattern??(r.pattern=a),t._zod.check=a=>{a.value.endsWith(r.suffix)||a.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:r.suffix,input:a.value,inst:t,continue:!r.abort})}}),tA=eU("$ZodCheckOverwrite",(t,r)=>{t_.init(t,r),t._zod.check=t=>{t.value=r.tx(t.value)}});class tM{constructor(t=[],r={}){this.content=[],this.indent=0,this.args=t,this.closed=r}indented(t){this.indent+=1;try{t(this)}finally{this.indent-=1}}write(t){if("function"==typeof t){t(this,{execution:"sync"}),t(this,{execution:"async"});return}let r=t.split("\n").filter(t=>t),a=Math.min(...r.map(t=>t.length-t.trimStart().length));for(let t of r.map(t=>t.slice(a)).map(t=>" ".repeat(2*this.indent)+t))this.content.push(t)}compile(){let t=Function,r=this?.content??[""];return new t(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
2
2
  ${r.join("\n")}
3
3
  };`)(...Object.values(this.closed))}}let tz={major:4,minor:6,patch:5},tL=eU("$ZodType",(t,r)=>{var a;t??(t={}),t._zod.def=r,t._zod.bag=t._zod.bag||{},t._zod.version=tz;let i=t._zod.def.checks,n=t._zod.traits.has("$ZodCheck")?[t,...i??[]]:i?.length?[...i]:[];for(let r of n)for(let a of r._zod.onattach)a(t);if(0===n.length)(a=t._zod).deferred??(a.deferred=[]),t._zod.deferred?.push(()=>{t._zod.run=t._zod.parse});else{let r=(r,a,i)=>{let n;if(r.memo)return r;let o=ex(r);for(let s of a){if(s._zod.def.when){if(function(t,r=0){if(!0===t.aborted)return!0;for(let a=r;a<t.issues.length;a++)if(t.issues[a]?.continue===!1)return!0;return!1}(r)||!s._zod.def.when(r))continue}else if(o)continue;let a=r.issues.length,l=s._zod.check(r);if(l instanceof Promise&&i?.async===!1)throw new eF;if(n||l instanceof Promise)n=(n??Promise.resolve()).then(async()=>{await l,r.issues.length!==a&&(eT(r.issues,a,t),o||(o=ex(r,a)))});else{if(r.issues.length===a)continue;eT(r.issues,a,t),o||(o=ex(r,a))}}return n?n.then(()=>r):r},a=(a,i,o)=>{if(ex(a))return a.aborted=!0,a;let s=r(i,n,o);if(s instanceof Promise){if(!1===o.async)throw new eF;return s.then(r=>t._zod.parse(r,o))}return t._zod.parse(s,o)};t._zod.run=(i,o)=>{if(o.skipChecks)return t._zod.parse(i,o);if("backward"===o.direction){let r=t._zod.parse({value:i.value,issues:[]},{...o,skipChecks:!0});return r instanceof Promise?r.then(t=>a(t,i,o)):a(r,i,o)}let s=t._zod.parse(i,o);if(s instanceof Promise){if(!1===o.async)throw new eF;return s.then(t=>r(t,n,o))}return r(s,n,o)}}},{get"~standard"(){return eq(this,"~standard",tV(this),!1)},set"~standard"(value){eq(this,"~standard",value)}}),tZ=(t,r)=>t.issues.length?{issues:t.issues.map(t=>ej(t,r,eB()))}:{value:t.value};async function tD(t,r){let a={async:!0};return tZ(await t._zod.run({value:r,issues:[]},a),a)}function tV(t){return{validate:r=>{let a={async:!1};try{let i=t._zod.run({value:r,issues:[]},a);if(!(i instanceof Promise))return tZ(i,a)}catch(t){}return tD(t,r)},vendor:"zod",version:1}}let tU=eU("$ZodString",(t,r)=>{tL.init(t,r),t._zod.pattern=r.pattern??tp,t._zod.parse=(a,i)=>{if(r.coerce)try{a.value=String(a.value)}catch(t){}return"string"==typeof a.value||a.issues.push({expected:"string",code:"invalid_type",input:a.value,inst:t}),a}}),tF=eU("$ZodStringFormat",(t,r)=>{tT.init(t,r),tU.init(t,r)}),tH=eU("$ZodGUID",(t,r)=>{r.pattern??(r.pattern=e8),tF.init(t,r)}),tJ=eU("$ZodUUID",(t,r)=>{if(r.version){let t={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[r.version];if(void 0===t)throw Error(`Invalid UUID version: "${r.version}"`);r.pattern??(r.pattern=te(t))}else r.pattern??(r.pattern=te());tF.init(t,r)}),tB=eU("$ZodEmail",(t,r)=>{r.pattern??(r.pattern=tt),tF.init(t,r)});function tK(t){try{if("undefined"!=typeof URL&&"function"==typeof URL.canParse)return URL.canParse(t);return new URL(t),!0}catch{return!1}}let tG=/[\t\n\r]/g;function tW(t){return t.replace(tG,"")}let tY=eU("$ZodURL",(t,r)=>{tF.init(t,r),t._zod.check=a=>{try{var i,n;let o=a.value.trim(),s="normalize"in r||"hostname"in r||"protocol"in r?function(t,r){if(!r.normalize&&r.protocol?.source===ts.source&&!/^https?:\/\//i.test(t))return 1;try{if("undefined"!=typeof URL){let r=URL;if("function"==typeof r.parse)return r.parse(t)??2}return new URL(t)}catch{return 2}}(o,r):tK(o)||2;if(1===s)return void a.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:a.value,inst:t,continue:!r.abort});if(2===s)return void a.issues.push({code:"invalid_format",format:"url",input:a.value,inst:t,continue:!r.abort});if(!0===s){a.value=tW(o);return}r.hostname&&((i=r.hostname).lastIndex=0,!i.test(s.hostname))&&a.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:r.hostname.source,input:a.value,inst:t,continue:!r.abort}),r.protocol&&((n=r.protocol).lastIndex=0,!n.test(s.protocol.endsWith(":")?s.protocol.slice(0,-1):s.protocol))&&a.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:r.protocol.source,input:a.value,inst:t,continue:!r.abort}),a.value=r.normalize?s.href:tW(o);return}catch(i){a.issues.push({code:"invalid_format",format:"url",input:a.value,inst:t,continue:!r.abort})}}}),tX=eU("$ZodEmoji",(t,r)=>{r.pattern??(r.pattern=RegExp(tr,"u")),tF.init(t,r)}),tQ=eU("$ZodNanoID",(t,r)=>{var a;if(void 0!==r.length&&(!Number.isInteger(r.length)||r.length<1))throw Error(`Invalid nanoid length: ${r.length}`);r.pattern??(r.pattern=void 0===r.length?e5:(a=r.length,RegExp(`^[a-zA-Z0-9_-]{${a}}$`))),tF.init(t,r)}),t0=eU("$ZodCUID",(t,r)=>{r.pattern??(r.pattern=e2),tF.init(t,r)}),t1=eU("$ZodCUID2",(t,r)=>{r.pattern??(r.pattern=e9),tF.init(t,r)}),t2=eU("$ZodULID",(t,r)=>{r.pattern??(r.pattern=e4),tF.init(t,r)}),t9=eU("$ZodXID",(t,r)=>{r.pattern??(r.pattern=e3),tF.init(t,r)}),t4=eU("$ZodKSUID",(t,r)=>{r.pattern??(r.pattern=e6),tF.init(t,r)}),t3=eU("$ZodISODateTime",(t,r)=>{let a,i,n;r.pattern??(a=["Z"],r.offset&&a.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)"),i=`${td({precision:r.precision,seconds:!0})}(?:${a.join("|")})`,n=r.local?`${i}|${td({precision:r.precision})}`:i,r.pattern=RegExp(`^${tc}T(?:${n})$`)),tF.init(t,r)}),t6=eU("$ZodISODate",(t,r)=>{r.pattern??(r.pattern=tu),tF.init(t,r)}),t5=eU("$ZodISOTime",(t,r)=>{r.pattern??(r.pattern=RegExp(`^${td(r)}$`)),tF.init(t,r)}),t7=eU("$ZodISODuration",(t,r)=>{r.pattern??(r.pattern=e7),tF.init(t,r)}),t8=eU("$ZodIPv4",(t,r)=>{r.pattern??(r.pattern=ta),tF.init(t,r)}),re=/^[0-9a-fA-F:.]+$/;function rt(t){return!!re.test(t)&&tK(`http://[${t}]`)}let rr=eU("$ZodIPv6",(t,r)=>{r.pattern??(r.pattern=ti),tF.init(t,r),t._zod.check=a=>{rt(a.value)||a.issues.push({code:"invalid_format",format:"ipv6",input:a.value,inst:t,continue:!r.abort})}}),ra=eU("$ZodCIDRv4",(t,r)=>{r.pattern??(r.pattern=tn),tF.init(t,r)}),ri=eU("$ZodCIDRv6",(t,r)=>{r.pattern??(r.pattern=to),tF.init(t,r),t._zod.check=a=>{!function(t){let r=t.split("/");if(2!==r.length)return!1;let[a,i]=r;if(!i)return!1;let n=Number(i);return`${n}`===i&&!(n<0)&&!(n>128)&&rt(a)}(a.value)&&a.issues.push({code:"invalid_format",format:"cidrv6",input:a.value,inst:t,continue:!r.abort})}});function rn(t){if(""===t)return!0;if(/\s/.test(t)||t.length%4!=0)return!1;try{return atob(t),!0}catch{return!1}}let ro=/^[0-9a-zA-Z+/]*={0,2}$/,rs=eU("$ZodBase64",(t,r)=>{r.pattern??(r.pattern=ro),tF.init(t,r),t._zod.check=a=>{rn(a.value)||a.issues.push({code:"invalid_format",format:"base64",input:a.value,inst:t,continue:!r.abort})}}),rl=/^[A-Za-z0-9_-]*$/,rc=eU("$ZodBase64URL",(t,r)=>{r.pattern??(r.pattern=rl),tF.init(t,r),t._zod.check=a=>{!function(t){if(!rl.test(t))return!1;let r=t.replace(/[-_]/g,t=>"-"===t?"+":"/");return rn(r.padEnd(4*Math.ceil(r.length/4),"="))}(a.value)&&a.issues.push({code:"invalid_format",format:"base64url",input:a.value,inst:t,continue:!r.abort})}}),ru=eU("$ZodE164",(t,r)=>{r.pattern??(r.pattern=tl),tF.init(t,r)}),rd=eU("$ZodJWT",(t,r)=>{tF.init(t,r),t._zod.check=a=>{!function(t,r=null){try{let a=t.split(".");if(3!==a.length)return!1;let[i]=a;if(!i)return!1;let n=JSON.parse(atob(i));if("typ"in n&&n?.typ!=="JWT"||!n.alg||r&&(!("alg"in n)||n.alg!==r))return!1;return!0}catch{return!1}}(a.value,r.alg)&&a.issues.push({code:"invalid_format",format:"jwt",input:a.value,inst:t,continue:!r.abort})}}),rp=eU("$ZodNumber",(t,r)=>{tL.init(t,r),t._zod.pattern=th,t._zod.parse=(a,i)=>{if(r.coerce)try{a.value=Number(a.value)}catch(t){}let n=a.value;if("number"==typeof n&&!Number.isNaN(n)&&Number.isFinite(n))return a;let o="number"==typeof n?Number.isNaN(n)?"NaN":Number.isFinite(n)?void 0:String(n):void 0;return a.issues.push({expected:"number",code:"invalid_type",input:n,inst:t,...o?{received:o}:{}}),a}}),rm=eU("$ZodNumberFormat",(t,r)=>{tk.init(t,r),rp.init(t,r)}),rh=eU("$ZodBoolean",(t,r)=>{tL.init(t,r),t._zod.pattern=tf,t._zod.parse=(a,i)=>{if(r.coerce)try{a.value=!!a.value}catch(t){}let n=a.value;return"boolean"==typeof n||a.issues.push({expected:"boolean",code:"invalid_type",input:n,inst:t}),a}}),rf=eU("$ZodNull",(t,r)=>{tL.init(t,r),t._zod.pattern=tg,t._zod.values=new Set([null]),t._zod.parse=(r,a)=>{let i=r.value;return null===i||r.issues.push({expected:"null",code:"invalid_type",input:i,inst:t}),r}}),rg=eU("$ZodAny",(t,r)=>{tL.init(t,r),t._zod.parse=t=>t}),ry=eU("$ZodUnknown",(t,r)=>{tL.init(t,r),t._zod.parse=t=>t}),rv=eU("$ZodNever",(t,r)=>{tL.init(t,r),t._zod.parse=(r,a)=>(r.issues.push({expected:"never",code:"invalid_type",input:r.value,inst:t}),r)});function r_(t,r,a){t.issues.length&&r.issues.push(...eP(a,t.issues)),r.value[a]=t.value}let rb=eU("$ZodArray",(t,r)=>{tL.init(t,r);let a=eJ.memoizer;a?.attach(t),t._zod.parse=(i,n)=>{let o=i.value;if(!Array.isArray(o))return i.issues.push({expected:"array",code:"invalid_type",input:o,inst:t}),i;i.value=a?a.alloc(t,i,Array(o.length),n):Array(o.length);let s=[],l=n?.abortEarly;for(let t=0;t<o.length;t++){let a=o[t],c=r.element._zod.run({value:a,issues:[]},n);if(c instanceof Promise)s.push(c.then(r=>r_(r,i,t)));else if(r_(c,i,t),l&&0!==c.issues.length&&ex(c))break}return s.length?Promise.all(s).then(()=>i):i}});function rS(t,r,a,i,n,o){let s=a in i,l="optional"===o;if(s||!l||"optional"!==n){if(t.issues.length){if(void 0!==n&&l&&!s)return;r.issues.push(...eP(a,t.issues))}if(!s&&void 0===n){t.issues.length||r.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[a]});return}void 0===t.value?(s||"defaulted"===n&&!l)&&(r.value[a]=void 0):r.value[a]=t.value}}let r$=[];function rw(t){var r;let a=Object.keys(t.shape),i=Object.getOwnPropertySymbols(t.shape),n=i.length?i:r$,o=n.length?[...a,...n]:a;for(let r of o)if(!t.shape?.[r]?._zod?.traits?.has("$ZodType"))throw Error(`Invalid element at key "${String(r)}": expected a Zod schema`);let s=Object.keys(r=t.shape).filter(t=>void 0!==r[t]._zod.optin&&"optional"===r[t]._zod.optout);return{...t,allKeys:o,symbolKeys:n,keySet:new Set(a),numKeys:a.length,optionalKeys:new Set(s)}}function rR(t,r,a,i,n,o,s){let l=[],c=n.keySet,u=n.catchall._zod,d=u.def.type,p=u.optin,m=u.optout,h=0;for(let n in r){if(s&&a.issues.length!==h){if(ex(a,h))break;h=a.issues.length}if(c.has(n))continue;if("__proto__"===n){"never"===d&&l.push(n);continue}if("never"===d){l.push(n);continue}let o=u.run({value:r[n],issues:[]},i);o instanceof Promise?t.push(o.then(t=>rS(t,a,n,r,p,m))):rS(o,a,n,r,p,m)}return(l.length&&a.issues.push({code:"unrecognized_keys",keys:l,input:r,inst:o,continue:!0}),t.length)?Promise.all(t).then(()=>a):a}let rk=eU("$ZodObject",(t,r)=>{let a;tL.init(t,r);let i=Object.getOwnPropertyDescriptor(r,"shape"),n=i?.get?i.get.raw:r.shape??{};if(n){let t=()=>{let a={...n};return Object.defineProperty(r,"shape",{value:a}),t.raw=a,a};t.raw=n,Object.defineProperty(r,"shape",{get:t})}let o=et(()=>rw(r));eL(t,"propValues",t=>{let r=t.def.shape,a={};for(let t in r){let i=r[t]._zod;if(i.values){for(let r of(Object.prototype.hasOwnProperty.call(a,t)||ei(a,t,new Set),i.values))a[t].add(r);void 0!==i.optin&&a[t].add(void 0)}}return a});let s=r.catchall,l=eJ.memoizer;l?.attach(t),t._zod.parse=(r,i)=>{a??(a=o.value);let n=r.value;if(!ep(n))return r.issues.push({expected:"object",code:"invalid_type",input:n,inst:t}),r;r.value=l?l.alloc(t,r,{},i):{};let c=[],u=a.shape,d=i?.abortEarly,p=r.issues.length;for(let t of a.allKeys){if(d&&r.issues.length!==p){if(ex(r,p))break;p=r.issues.length}if("__proto__"===t)continue;let a=u[t],o=a._zod.optin,s=a._zod.optout,l=a._zod.run({value:n[t],issues:[]},i);l instanceof Promise?c.push(l.then(a=>rS(a,r,t,n,o,s))):rS(l,r,t,n,o,s)}return s?rR(c,n,r,i,o.value,t,!0===d):c.length?Promise.all(c).then(()=>r):r}}),rx=eU("$ZodObjectJIT",(t,r)=>{let a,i;rk.init(t,r);let n=t._zod.parse,o=et(()=>rw(r)),s=eJ.memoizer,l=!eJ.jitless,c=l&&em.value,u=r.catchall;t._zod.parse=(d,p)=>{i??(i=o.value);let m=d.value;return ep(m)?l&&c&&p?.async===!1&&!0!==p.jitless?(a||(a=(r=>{let a=o.value,i=a.symbolKeys,n=new tM(["payload","ctx"],{shape:r,inst:t,memo:s,syms:i}),l=t=>`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`,c=(t,r)=>`
4
4
  let ${t}_ab = false;
@@ -74,17 +74,17 @@ data:
74
74
  `;return i&&(n+=`id: ${i}
75
75
  `),n+=`data: ${JSON.stringify(a)}
76
76
 
77
- `,t.enqueue(r.encode(n)),!0}catch(t){return this.onerror?.(t),!1}}handleUnsupportedRequest(){return this.onerror?.(Error("Method not allowed.")),Response.json({jsonrpc:"2.0",error:{code:-32e3,message:"Method not allowed."},id:null},{status:405,headers:{Allow:"GET, POST, DELETE","Content-Type":"application/json"}})}async handlePostRequest(t,r){try{let a,i,n,o,s,l=t.headers.get("accept");if(!l?.includes("application/json")||!l.includes("text/event-stream"))return this.onerror?.(Error("Not Acceptable: Client must accept both application/json and text/event-stream")),this.createJsonErrorResponse(406,-32e3,"Not Acceptable: Client must accept both application/json and text/event-stream");if(!uA(t.headers.get("content-type")))return this.onerror?.(Error("Unsupported Media Type: Content-Type must be application/json")),this.createJsonErrorResponse(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");if(r?.parsedBody===void 0)try{let r=await p0(t,this._maxRequestBodySize);if(r.tooLarge){let t=pX(this._maxRequestBodySize);return this.onerror?.(Error(t)),this.createJsonErrorResponse(413,-32e3,t)}a=JSON.parse(r.text)}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON")}else a=r.parsedBody;if(Array.isArray(a)&&a.length>100)return this.onerror?.(Error("Invalid Request: Batch must not exceed 100 messages")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Batch must not exceed 100 messages");try{i=Array.isArray(a)?a.map(t=>ol.parse(t)):[ol.parse(a)]}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON-RPC message")}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");let c=i.some(t=>ow.safeParse(t).success);if(c){if(this._initialized&&void 0!==this.sessionId)return this.onerror?.(Error("Invalid Request: Server already initialized")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Server already initialized");if(i.length>1)return this.onerror?.(Error("Invalid Request: Only one initialization request is allowed")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Only one initialization request is allowed");this.sessionId=this.sessionIdGenerator?.(),this._initialized=!0,this.sessionId&&this._onsessioninitialized&&await Promise.resolve(this._onsessioninitialized(this.sessionId))}if(!c){let r=this.validateSession(t);if(r)return r;let a=this.validateProtocolVersion(t);if(a)return a}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");try{n=await this._checkScopeChallenge(i,r?.authInfo)}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(500,-32603,"Internal server error")}if(n)return n;if(!i.some(t=>cK(t))){for(let a of i)this.onmessage?.(a,{authInfo:r?.authInfo,request:t});return new Response(null,{status:202})}let u=crypto.randomUUID(),d=i.find(t=>ow.safeParse(t).success),p=d?d.params.protocolVersion:t.headers.get("mcp-protocol-version")??"2025-03-26";if(this._enableJsonResponse)return new Promise(a=>{for(let t of(this._streamMapping.set(u,{resolveJson:a,cleanup:()=>{this._streamMapping.delete(u)}}),i))cK(t)&&this._requestToStreamMapping.set(t.id,u);for(let a of i)this.onmessage?.(a,{authInfo:r?.authInfo,request:t})});let m=new TextEncoder,h=new ReadableStream({start:t=>{o=t},cancel:()=>{void 0!==s&&clearInterval(s),this._streamMapping.get(u)?.controller===o&&this._streamMapping.delete(u)}}),f={"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"};for(let t of(void 0!==this.sessionId&&(f["mcp-session-id"]=this.sessionId),i))cK(t)&&(this._streamMapping.set(u,{controller:o,encoder:m,cleanup:()=>{void 0!==s&&clearInterval(s),this._streamMapping.delete(u);try{o.close()}catch{}}}),this._requestToStreamMapping.set(t.id,u));for(let a of(await this.writePrimingEvent(o,m,u,p),i)){let i,n;cK(a)&&this._eventStore&&this.supportsEmptySSEData(p)&&(i=()=>{this.closeSSEStream(a.id)},n=()=>{this.closeStandaloneSSEStream()}),this.onmessage?.(a,{authInfo:r?.authInfo,request:t,closeSSEStream:i,closeStandaloneSSEStream:n})}return this._streamMapping.get(u)?.controller===o&&(s=this.startKeepAlive(o,m)),new Response(h,{status:200,headers:f})}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error",{data:String(t)})}}async handleDeleteRequest(t){let r=this.validateSession(t);if(r)return r;let a=this.validateProtocolVersion(t);if(a)return a;try{return await Promise.resolve(this._onsessionclosed?.(this.sessionId)),new Response(null,{status:200})}finally{await this.close()}}validateSession(t){if(void 0===this.sessionIdGenerator)return;if(!this._initialized)return this.onerror?.(Error("Bad Request: Server not initialized")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Server not initialized");let r=t.headers.get("mcp-session-id");return r?r!==this.sessionId?(this.onerror?.(Error("Session not found")),this.createJsonErrorResponse(404,-32001,"Session not found")):void 0:(this.onerror?.(Error("Bad Request: Mcp-Session-Id header is required")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Mcp-Session-Id header is required"))}validateProtocolVersion(t){let r=t.headers.get("mcp-protocol-version");if(null!==r&&!this._supportedProtocolVersions.includes(r)){let t=`Bad Request: Unsupported protocol version: ${r} (supported versions: ${this._supportedProtocolVersions.join(", ")})`;return this.onerror?.(Error(t)),this.createJsonErrorResponse(400,-32e3,t)}}async close(){if(!this._closed){for(let{cleanup:t}of(this._closed=!0,this._streamMapping.values()))t();this._streamMapping.clear(),this._requestResponseMap.clear(),this.onclose?.()}}closeSSEStream(t){let r=this._requestToStreamMapping.get(t);if(!r)return;let a=this._streamMapping.get(r);a&&a.cleanup()}closeStandaloneSSEStream(){let t=this._streamMapping.get(this._standaloneSseStreamId);t&&t.cleanup()}async send(t,r){let a=r?.relatedRequestId;if((cW(t)||cY(t))&&(a=t.id),void 0===a){let r;if(cW(t)||cY(t))throw Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");this._eventStore&&(r=await this._eventStore.storeEvent(this._standaloneSseStreamId,t));let a=this._streamMapping.get(this._standaloneSseStreamId);if(void 0===a)return;a.controller&&a.encoder&&(void 0===r||!a.replayedEventIds?.has(r))&&this.writeSSEEvent(a.controller,a.encoder,t,r);return}let i=this._requestToStreamMapping.get(a);if(!i)throw Error(`No connection established for request ID: ${String(a)}`);let n=this._streamMapping.get(i);if(!this._enableJsonResponse){let r;this._eventStore&&(r=await this._eventStore.storeEvent(i,t),n=this._streamMapping.get(i)),n?.controller&&n?.encoder&&(void 0===r||!n.replayedEventIds?.has(r))&&this.writeSSEEvent(n.controller,n.encoder,t,r)}if(cW(t)||cY(t)){this._requestResponseMap.set(a,t);let r=[...this._requestToStreamMapping.entries()].filter(([t,r])=>r===i).map(([t])=>t);if(r.every(t=>this._requestResponseMap.has(t))){if(!n){if(this._enableJsonResponse)throw Error(`No connection established for request ID: ${String(a)}`);if(!this._eventStore){for(let t of(this.onerror?.(Error(`Response for request ID ${String(a)} is undeliverable: per-request stream is disconnected and no eventStore is configured`)),r))this._requestResponseMap.delete(t),this._requestToStreamMapping.delete(t);return}for(let t of r)this._requestResponseMap.delete(t),this._requestToStreamMapping.delete(t);return}if(this._enableJsonResponse&&n.resolveJson){let t={"Content-Type":"application/json"};void 0!==this.sessionId&&(t["mcp-session-id"]=this.sessionId);let a=r.map(t=>this._requestResponseMap.get(t));1===a.length?n.resolveJson(Response.json(a[0],{status:200,headers:t})):n.resolveJson(Response.json(a,{status:200,headers:t})),n.cleanup()}else n.cleanup();for(let t of r)this._requestResponseMap.delete(t),this._requestToStreamMapping.delete(t)}}}};function p2(t){if(null===t||"object"!=typeof t||Array.isArray(t))return null;let{method:r,id:a}=t;return"string"!=typeof r?null:"string"==typeof a||"number"==typeof a?a:null}function p9(t,r,a,i,n=null){return Response.json({jsonrpc:"2.0",error:{code:r,message:a,...void 0!==i&&{data:i}},id:n},{status:t})}function p4(t,r=null){return p9(t.httpStatus,t.code,t.message,t.data,r)}function p3(t){return t instanceof Error?t:Error(String(t))}function p6(t=null){return p9(500,-32603,"Internal server error",void 0,t)}function p5(t){if(void 0!==t.transport)throw Error("The factory returned an instance that is still serving another request. Return a new instance for each request.")}function p7(t){return{protocolVersionHeader:t.headers.get("mcp-protocol-version")??void 0,mcpMethodHeader:t.headers.get("mcp-method")??void 0,mcpNameHeader:t.headers.get("mcp-name")??void 0}}async function p8(t,r,a=!0,i=4194304){let n,o=t.method.toUpperCase(),s=r,l=t,c=!1;if("POST"===o){if(void 0===s){let r;a&&(l=t.clone());try{let a=await p0(t,i);if(a.tooLarge)return{step:"body-too-large"};r=a.text}catch{return{step:"unreadable-body"}}try{n=0===r.length?void 0:JSON.parse(r)}catch{c=!0}c||void 0===n||(s=n)}else n=s;if(c||void 0===n)return{step:"no-json-body",forwardRequest:l}}return{step:"classified",outcome:function(t){if("POST"!==(t={...t,...void 0!==t.protocolVersionHeader&&{protocolVersionHeader:un(t.protocolVersionHeader)},...void 0!==t.mcpMethodHeader&&{mcpMethodHeader:un(t.mcpMethodHeader)},...void 0!==t.mcpNameHeader&&{mcpNameHeader:un(t.mcpNameHeader)}}).httpMethod.toUpperCase())return{kind:"legacy",reason:"http-method"};let r=t.body;if(Array.isArray(r)){if(0===r.length)return ur("jsonrpc-shape","empty-batch",400,new cg(cf.InvalidRequest,"Bad Request: empty JSON-RPC batch"),!0);for(let t of r){if(cF(uo(t)?t.params:void 0))return ur("jsonrpc-shape","batch-with-modern-element",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC batches may not contain requests for protocol revision 2026-07-28 or later"),!0);if(!(cK(t)||cG(t)||cW(t)||cY(t)))return ur("jsonrpc-shape","batch-with-invalid-element",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC batch contains an invalid message"),!0)}return{kind:"legacy",reason:"batch"}}return cW(r)||cY(r)?{kind:"legacy",reason:"response"}:uo(r)&&cK(r)?function(t,r){let a=r.params,i=r.method,n=t.protocolVersionHeader,o=void 0!==n&&n>=lW;if("initialize"===i&&!function(t){if(!cF(t))return!1;let r=cH(t);if(void 0===r||!(r>=lW))return!1;let a=cU(t);return void 0!==a&&0===cJ(a).length}(a)){if(o)return ua("initialize-with-modern-header",n,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let t=uo(a)&&"string"==typeof a.protocolVersion?a.protocolVersion:void 0;return{kind:"legacy",reason:"initialize",...void 0!==t&&{requestedVersion:t}}}if(cF(a)){let o=cU(a),s=(void 0===o?[]:cJ(o))[0];if(void 0!==s)return ur("envelope","envelope-invalid",400,new cg(cf.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${s.key}: ${s.problem}`,{envelope:s}),!0);let l=cH(a);return void 0!==n&&void 0!==l&&n!==l?ua("header-body-version-mismatch",n,`the body envelope names protocol version ${l} but the MCP-Protocol-Version header names ${n}`):void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==i?ua("method-header-mismatch",t.mcpMethodHeader,`the body names method ${i} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"request",message:r,classification:us(l)}}if(o){let t=cU(a),r=cJ(t??{}).filter(t=>"missing"===t.problem).map(t=>t.key),i=void 0===t?["_meta"]:r.length>0?r:[nJ];return ur("envelope","modern-header-without-claim",400,new cg(cf.InvalidParams,`Invalid params: the MCP-Protocol-Version header names protocol revision ${n}, but the request is missing the required per-request envelope key(s): ${i.join(", ")}`,{envelope:{missing:i}}),!0)}return{kind:"legacy",reason:"no-claim",...void 0!==n&&{requestedVersion:n}}}(t,r):uo(r)&&cG(r)?function(t,r){let a=r.params,i=r.method,n=t.protocolVersionHeader,o=void 0!==n&&n>=lW;if(cF(a)){let o=cH(a);if(void 0===o){let t=cU(a),r=(void 0===t?[]:cJ(t)).find(t=>t.key===nJ)??{key:nJ,problem:"expected a protocol version string"};return ur("envelope","notification-envelope-invalid",400,new cg(cf.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${r.key}: ${r.problem}`,{envelope:r}),!0)}if(void 0!==n&&n!==o)return ua("notification-header-body-version-mismatch",n,`the notification envelope names protocol version ${o} but the MCP-Protocol-Version header names ${n}`);let s=us(o);return"modern"===s.era&&void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==i?ua("notification-method-header-mismatch",t.mcpMethodHeader,`the notification body names method ${i} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:r,classification:s}}return o?void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==i?ua("notification-method-header-mismatch",t.mcpMethodHeader,`the notification body names method ${i} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:r,classification:{era:"modern",revision:n}}:{kind:"legacy",reason:"notification",...void 0!==n&&{requestedVersion:n}}}(t,r):ur("jsonrpc-shape","invalid-json-rpc-body",400,new cg(cf.InvalidRequest,"Bad Request: the request body is not a valid JSON-RPC message"),!0)}({httpMethod:o,...p7(t),...void 0!==n&&{body:n}}),body:n,parsedBody:s,forwardRequest:l}}let me=r("async_hooks"),mt=(t,r)=>{globalThis[t]=r},mr=t=>globalThis[t];function ma({name:t,fallback:r=!0}){let a=Symbol.for(`xmcp-context-${t}`),i=Symbol.for(`xmcp-context-${t}-fallback-store`);if(mr(a))return mr(a);let n=new me.AsyncLocalStorage,o=globalThis[i]??{current:null};mt(i,o);let s={provider:(t,a)=>(r&&(o.current=t),n.run(t,a)),getContext:()=>{let a=n.getStore();if(a)return a;if(r&&o.current)return o.current;throw Error(`getContext() can only be used within the ${t} context.`)},setContext:a=>{let i=n.getStore()??(r?o.current:null);if(!i)throw Error(`setContext() can only be used within the ${t} context.`);Object.assign(i,a)}};return mt(a,s),s}let mi=ma({name:"http-request-context"});mi.setContext;let mn=mi.getContext,mo=mi.provider,ms=t=>"object"==typeof t&&null!==t&&!Array.isArray(t),ml=t=>{if(!ms(t)||"string"!=typeof t.name||"string"!=typeof t.version)return;let r={name:t.name,version:t.version};return"string"==typeof t.title&&(r.title=t.title),"string"==typeof t.websiteUrl&&(r.websiteUrl=t.websiteUrl),"string"==typeof t.description&&(r.description=t.description),r},mc=t=>{if(t&&"initialize"===t.method&&ms(t.params))return ml(t.params.clientInfo)},mu=(t,r)=>{let a=r.toLowerCase();for(let[r,i]of Object.entries(t)){if(r.toLowerCase()!==a)continue;let t=Array.isArray(i)?i[0]:i;if("string"!=typeof t)break;let n=t.trim();return n.length>0?n:void 0}};function md(t){let{tags:r,enabled:a,...i}=t;return{...i,_meta:void 0===r?i._meta:{...i._meta,"xmcp/tags":r}}}let mp=new class{add(t,r){this.resources.set(t,r)}getAll(){return this.resources}clear(){this.resources.clear()}has(t){return this.resources.has(t)}constructor(){var t,r;t="resources",r=new Map,t in this?Object.defineProperty(this,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):this[t]=r}},mm=ma({name:"request-context",fallback:!1}),mh=ma({name:"client-info-context"});mh.setContext;let mf=mh.getContext;mh.provider;let mg=new Set(["message","mode","requestedSchema"]),my=new Set(["elicitationId","message","mode","url"]),mv=new Set(["properties","required","type"]),m_=new Set(["default","description","format","maxLength","minLength","title","type"]),mb=new Set(["default","description","enum","enumNames","title","type"]),mS=new Set(["default","description","title","type"]),m$=new Set(["default","description","maximum","minimum","title","type"]),mw=new Set(["date","date-time","email","uri"]);async function mR(t,r,a){let i=function(t){let r=t.mode??"form";if("url"===r)return function(t){let r;mx(t,"Elicitation request must be a plain object."),mk(t,my,"URL elicitation"),mP(t.message,"URL elicitation requires a string message."),mE(t.elicitationId,"URL elicitation requires a non-empty elicitationId."),mE(t.url,"URL elicitation requires a non-empty URL.");try{r=new URL(t.url)}catch{throw Error("URL elicitation requires a valid http or https URL.")}if("http:"!==r.protocol&&"https:"!==r.protocol)throw Error("URL elicitation requires a valid http or https URL.")}(t),t;if("form"!==r)throw Error(`Unsupported elicitation mode "${String(t.mode)}". Expected "form" or "url".`);return function(t){mx(t,"Elicitation request must be a plain object."),mk(t,mg,"Form elicitation"),mP(t.message,"Form elicitation requires a string message.");let r=t.requestedSchema;if(mx(r,"Form elicitation requires a flat object schema."),mk(r,mv,"Form elicitation schema"),"object"!==r.type)throw Error('Form elicitation schema must use type "object".');for(let[t,a]of(mx(r.properties,"Form elicitation schema requires a properties object."),Object.entries(r.properties)))!function(t,r){if(mx(r,`Form elicitation field "${t}" must be a plain object.`),mT(r.title,`Form elicitation field "${t}" title must be a string.`),mT(r.description,`Form elicitation field "${t}" description must be a string.`),"string"===r.type&&"enum"in r){var a,i;if(mk(r,mb,`Form elicitation field "${t}"`),mO(r.enum,`Form elicitation field "${t}" enum values must be strings.`),a=r.enumNames,i=`Form elicitation field "${t}" enumNames must be strings.`,void 0!==a&&mO(a,i),void 0!==r.enumNames&&r.enumNames.length!==r.enum.length)throw Error(`Form elicitation field "${t}" enumNames length must match enum length.`);if(mT(r.default,`Form elicitation field "${t}" default must be a string.`),void 0!==r.default&&!r.enum.includes(r.default))throw Error(`Form elicitation field "${t}" default must be one of its enum values.`);return}if("string"===r.type&&!("enum"in r)){mk(r,m_,`Form elicitation field "${t}"`),mj(r.minLength,`Form elicitation field "${t}" minLength must be a number.`),mj(r.maxLength,`Form elicitation field "${t}" maxLength must be a number.`),mT(r.default,`Form elicitation field "${t}" default must be a string.`);let a=r.format;if(mT(a,`Form elicitation field "${t}" format must be a string.`),void 0!==a&&!mw.has(a))throw Error(`Form elicitation field "${t}" format must be one of: ${Array.from(mw).join(", ")}.`);return}if("boolean"===r.type){if(mk(r,mS,`Form elicitation field "${t}"`),void 0!==r.default&&"boolean"!=typeof r.default)throw Error(`Form elicitation field "${t}" default must be a boolean.`);return}if("number"===r.type||"integer"===r.type){mk(r,m$,`Form elicitation field "${t}"`),mj(r.minimum,`Form elicitation field "${t}" minimum must be a number.`),mj(r.maximum,`Form elicitation field "${t}" maximum must be a number.`),mj(r.default,`Form elicitation field "${t}" default must be a number.`);return}throw Error(`Form elicitation field "${t}" uses unsupported type "${String(r.type)}". Supported types are string, boolean, number, integer, and string enums.`)}(t,a);if(void 0!==r.required){if(!Array.isArray(r.required)||r.required.some(t=>"string"!=typeof t))throw Error("Form elicitation schema required fields must be a string array.");for(let t of r.required)if(!(t in r.properties))throw Error(`Form elicitation schema required field "${t}" is not defined in properties.`)}}(t),{...t,mode:"form"}}(r);try{let r=await t.mcpReq.elicitInput(i,a);return{...r,content:r.content??void 0}}catch(t){if(t instanceof lJ&&t.code===lH.MethodNotSupportedByProtocolVersion)throw Error("extra.elicit() is not available on protocol revision 2026-07-28: server-initiated elicitation was replaced by multi round-trip requests. Return inputRequired({ ... }) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw t}}function mk(t,r,a){let i=Object.keys(t).filter(t=>!r.has(t));if(0!==i.length)throw Error(`${a} includes unsupported key(s): ${i.join(", ")}.`)}function mx(t,r){if("object"!=typeof t||null===t||Array.isArray(t))throw Error(r)}function mP(t,r){if("string"!=typeof t)throw Error(r)}function mE(t,r){if("string"!=typeof t||0===t.trim().length)throw Error(r)}function mT(t,r){if(void 0!==t&&"string"!=typeof t)throw Error(r)}function mj(t,r){if(void 0!==t&&"number"!=typeof t)throw Error(r)}function mO(t,r){if(!Array.isArray(t)||t.some(t=>"string"!=typeof t))throw Error(r)}let mC=new Set(["_meta","includeContext","maxTokens","messages","metadata","modelPreferences","stopSequences","systemPrompt","temperature"]),mI=new Set(["task","toolChoice","tools"]),mN=new Set(["text","image","audio"]);async function mq(t,r,a){let i=function(t){mA(t,"Sampling request must be a plain object.");let r=Object.keys(t),a=r.filter(t=>mI.has(t));if(a.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${a.join(", ")}.`);let i=r.filter(t=>!mC.has(t));if(i.length>0)throw Error(`Sampling request includes unsupported key(s): ${i.join(", ")}.`);if(!Array.isArray(t.messages)||0===t.messages.length)throw Error("Sampling requires at least one message.");for(let[r,a]of t.messages.entries())!function(t,r){if(mA(r,`Sampling message at index ${t} must be a plain object.`),"user"!==r.role&&"assistant"!==r.role)throw Error(`Sampling message at index ${t} requires role "user" or "assistant".`);let a=r.content;mA(a,`Sampling message at index ${t} requires a content object.`);let i=a.type;if("string"!=typeof i||!mN.has(i))throw Error(`Sampling message at index ${t} uses unsupported content type "${String(i)}". Supported types are text, image, and audio.`);if("text"===i&&"string"!=typeof a.text)throw Error(`Sampling message at index ${t} requires string text content.`);if(("image"===i||"audio"===i)&&("string"!=typeof a.data||"string"!=typeof a.mimeType))throw Error(`Sampling message at index ${t} requires base64 data and a mimeType.`)}(r,a);if("number"!=typeof t.maxTokens)throw Error("Sampling requires a numeric maxTokens.");return t}(r);try{return await t.mcpReq.requestSampling(i,a)}catch(t){if(t instanceof lJ&&t.code===lH.MethodNotSupportedByProtocolVersion)throw Error("extra.sample() is not available on protocol revision 2026-07-28: server-initiated sampling was replaced by multi round-trip requests. Return inputRequired({ ... }) with inputRequired.createMessage(...) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw t}}function mA(t,r){if("object"!=typeof t||null===t||Array.isArray(t))throw Error(r)}let mM={text:t=>"string"!=typeof t.text?{valid:!1,error:'Text content must have a "text" property of type string'}:{valid:!0},image:t=>"string"!=typeof t.data?{valid:!1,error:'Image content must have a "data" property of type string (base64-encoded image)'}:"string"!=typeof t.mimeType?{valid:!1,error:'Image content must have a "mimeType" property of type string'}:{valid:!0},audio:t=>"string"!=typeof t.data?{valid:!1,error:'Audio content must have a "data" property of type string (base64-encoded audio)'}:"string"!=typeof t.mimeType?{valid:!1,error:'Audio content must have a "mimeType" property of type string'}:{valid:!0},resource_link:t=>"string"!=typeof t.name?{valid:!1,error:'Resource link content must have a "name" property of type string'}:"string"!=typeof t.uri?{valid:!1,error:'Resource link content must have a "uri" property of type string'}:void 0!==t.title&&"string"!=typeof t.title?{valid:!1,error:'Resource link "title" property must be a string if provided'}:void 0!==t.description&&"string"!=typeof t.description?{valid:!1,error:'Resource link "description" property must be a string if provided'}:void 0!==t.mimeType&&"string"!=typeof t.mimeType?{valid:!1,error:'Resource link "mimeType" property must be a string if provided'}:{valid:!0}};function mz(t){if(!t||"object"!=typeof t)return{valid:!1,error:"Content must be an object"};if("string"!=typeof t.type)return{valid:!1,error:'Content must have a "type" property of type string'};if(void 0!==t._meta&&(null===t._meta||"object"!=typeof t._meta))return{valid:!1,error:'Content "_meta" property must be an object if provided'};let r=mM[t.type];return r?r(t):{valid:!0}}function mL(t,r,a,i){if(null===t||"object"!=typeof t||Array.isArray(t))throw Error(`Tool "${a}" ${i}: expected a plain object.`);let n=new Set(Object.keys(r)),o=Object.keys(t).filter(t=>!n.has(t));if(o.length>0)throw Error(`Tool "${a}" ${i}: unrecognized key(s): ${o.join(", ")}`);for(let[n,o]of Object.entries(r))try{o.parse(t[n])}catch(t){throw Error(`Tool "${a}" ${i}: ${t?.message??`invalid field "${n}"`}`)}}function mZ(t){return!!(t&&"object"==typeof t&&Object.keys(t).some(t=>t.startsWith("ui/")))}function mD(t){let r=t.mcpReq.envelope,a=ml(r?.[nB]);if(!a)try{let t,r=mn();a=r.clientInfo??(t=r.headers,ml({name:mu(t,"x-mcp-client-name"),version:mu(t,"x-mcp-client-version"),title:mu(t,"x-mcp-client-title"),websiteUrl:mu(t,"x-mcp-client-website-url"),description:mu(t,"x-mcp-client-description")}))}catch{}if(!a)try{a=mf().clientInfo}catch{}return a}function mV(t){let r=[...t];return(t,a,i)=>(function(t,r,a){let i,n=new Map;if(t.http){let t=mn(),r=Object.fromEntries(Object.entries(t.headers).map(([t,r])=>[t,Array.isArray(r)?Object.freeze([...r]):r]));i=Object.freeze({id:t.id,headers:Object.freeze(r)})}return mm.provider(Object.freeze({clientInfo:r?Object.freeze({...r}):void 0,http:i,authInfo:t.http?.authInfo,signal:t.mcpReq.signal,set(t,r){n.set(t,r)},get:t=>n.get(t),async progress(r,a){let i=t.mcpReq._meta?.progressToken;void 0!==i&&await t.mcpReq.notify({method:"notifications/progress",params:{progressToken:i,progress:r,...void 0===a?{}:{total:a}}})},log:(r,a)=>t.mcpReq.log(r,a)}),a)})(a,mD(a),async()=>{if(0===r.length)return i();let a=Object.freeze({...function(){try{return mm.getContext()}catch{throw Error("getRequestContext() can only be used while handling an MCP request.")}}(),...t,params:Object.freeze({...t.params})}),n=-1,o=async t=>{if(t<=n)throw Error("MCP middleware next() can only be called once");n=t;let s=r[t];return s?s(a,()=>o(t+1)):i()};return o(0)})}let mU=new Set(["tools/list","prompts/get","prompts/list","resources/read","resources/list","resources/templates/list","completion/complete"]);function mF(t){return t.endsWith(".tsx")}let mH=Symbol("Let zodToJsonSchema decide on which parser to use"),mJ={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",openAiAnyTypeName:"OpenAiAnyType"};(T=q||(q={})).assertEqual=t=>{},T.assertIs=function(t){},T.assertNever=function(t){throw Error()},T.arrayToEnum=t=>{let r={};for(let a of t)r[a]=a;return r},T.getValidEnumValues=t=>{let r=T.objectKeys(t).filter(r=>"number"!=typeof t[t[r]]),a={};for(let i of r)a[i]=t[i];return T.objectValues(a)},T.objectValues=t=>T.objectKeys(t).map(function(r){return t[r]}),T.objectKeys="function"==typeof Object.keys?t=>Object.keys(t):t=>{let r=[];for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&r.push(a);return r},T.find=(t,r)=>{for(let a of t)if(r(a))return a},T.isInteger="function"==typeof Number.isInteger?t=>Number.isInteger(t):t=>"number"==typeof t&&Number.isFinite(t)&&Math.floor(t)===t,T.joinValues=function(t,r=" | "){return t.map(t=>"string"==typeof t?`'${t}'`:t).join(r)},T.jsonStringifyReplacer=(t,r)=>"bigint"==typeof r?r.toString():r,(A||(A={})).mergeShapes=(t,r)=>({...t,...r});let mB=q.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),mK=t=>{switch(typeof t){case"undefined":return mB.undefined;case"string":return mB.string;case"number":return Number.isNaN(t)?mB.nan:mB.number;case"boolean":return mB.boolean;case"function":return mB.function;case"bigint":return mB.bigint;case"symbol":return mB.symbol;case"object":if(Array.isArray(t))return mB.array;if(null===t)return mB.null;if(t.then&&"function"==typeof t.then&&t.catch&&"function"==typeof t.catch)return mB.promise;if("undefined"!=typeof Map&&t instanceof Map)return mB.map;if("undefined"!=typeof Set&&t instanceof Set)return mB.set;if("undefined"!=typeof Date&&t instanceof Date)return mB.date;return mB.object;default:return mB.unknown}},mG=q.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 mW extends Error{get errors(){return this.issues}constructor(t){super(),this.issues=[],this.addIssue=t=>{this.issues=[...this.issues,t]},this.addIssues=(t=[])=>{this.issues=[...this.issues,...t]};let r=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,r):this.__proto__=r,this.name="ZodError",this.issues=t}format(t){let r=t||function(t){return t.message},a={_errors:[]},i=t=>{for(let n of t.issues)if("invalid_union"===n.code)n.unionErrors.map(i);else if("invalid_return_type"===n.code)i(n.returnTypeError);else if("invalid_arguments"===n.code)i(n.argumentsError);else if(0===n.path.length)a._errors.push(r(n));else{let t=a,i=0;for(;i<n.path.length;){let a=n.path[i],o=i===n.path.length-1;if("_errors"===a){o&&t._errors.push(r(n)),i++;continue}Object.prototype.hasOwnProperty.call(t,a)||("__proto__"===a?Object.defineProperty(t,a,{value:{_errors:[]},writable:!0,enumerable:!0,configurable:!0}):t[a]={_errors:[]}),t=t[a],o&&t._errors.push(r(n)),i++}}};return i(this),a}static assert(t){if(!(t instanceof mW))throw Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,q.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(t=t=>t.message){let r=Object.create(null),a=[];for(let i of this.issues)if(i.path.length>0){let a=i.path[0];r[a]=r[a]||[],r[a].push(t(i))}else a.push(t(i));return{formErrors:a,fieldErrors:r}}get formErrors(){return this.flatten()}}mW.create=t=>new mW(t);let mY=(t,r)=>{let a;switch(t.code){case mG.invalid_type:a=t.received===mB.undefined?"Required":`Expected ${t.expected}, received ${t.received}`;break;case mG.invalid_literal:a=`Invalid literal value, expected ${JSON.stringify(t.expected,q.jsonStringifyReplacer)}`;break;case mG.unrecognized_keys:a=`Unrecognized key(s) in object: ${q.joinValues(t.keys,", ")}`;break;case mG.invalid_union:a="Invalid input";break;case mG.invalid_union_discriminator:a=`Invalid discriminator value. Expected ${q.joinValues(t.options)}`;break;case mG.invalid_enum_value:a=`Invalid enum value. Expected ${q.joinValues(t.options)}, received '${t.received}'`;break;case mG.invalid_arguments:a="Invalid function arguments";break;case mG.invalid_return_type:a="Invalid function return type";break;case mG.invalid_date:a="Invalid date";break;case mG.invalid_string:"object"==typeof t.validation?"includes"in t.validation?(a=`Invalid input: must include "${t.validation.includes}"`,"number"==typeof t.validation.position&&(a=`${a} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?a=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?a=`Invalid input: must end with "${t.validation.endsWith}"`:q.assertNever(t.validation):a="regex"!==t.validation?`Invalid ${t.validation}`:"Invalid";break;case mG.too_small:a="array"===t.type?`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:"string"===t.type?`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:"number"===t.type||"bigint"===t.type?`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:"date"===t.type?`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:"Invalid input";break;case mG.too_big:a="array"===t.type?`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:"string"===t.type?`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:"number"===t.type?`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:"bigint"===t.type?`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:"date"===t.type?`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:"Invalid input";break;case mG.custom:a="Invalid input";break;case mG.invalid_intersection_types:a="Intersection results could not be merged";break;case mG.not_multiple_of:a=`Number must be a multiple of ${t.multipleOf}`;break;case mG.not_finite:a="Number must be finite";break;default:a=r.defaultError,q.assertNever(t)}return{message:a}};(j=M||(M={})).errToObj=t=>"string"==typeof t?{message:t}:t||{},j.toString=t=>"string"==typeof t?t:t?.message;let mX=t=>{let{data:r,path:a,errorMaps:i,issueData:n}=t,o=[...a,...n.path||[]],s={...n,path:o};if(void 0!==n.message)return{...n,path:o,message:n.message};let l="";for(let t of i.filter(t=>!!t).slice().reverse())l=t(s,{data:r,defaultError:l}).message;return{...n,path:o,message:l}};function mQ(t,r){let a=mX({issueData:r,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,mY,void 0].filter(t=>!!t)});t.common.issues.push(a)}class m0{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(t,r){let a=[];for(let i of r){if("aborted"===i.status)return m1;"dirty"===i.status&&t.dirty(),a.push(i.value)}return{status:t.value,value:a}}static async mergeObjectAsync(t,r){let a=[];for(let t of r){let r=await t.key,i=await t.value;a.push({key:r,value:i})}return m0.mergeObjectSync(t,a)}static mergeObjectSync(t,r){let a={};for(let i of r){let{key:r,value:n}=i;if("aborted"===r.status||"aborted"===n.status)return m1;"dirty"===r.status&&t.dirty(),"dirty"===n.status&&t.dirty(),"__proto__"!==r.value&&(void 0!==n.value||i.alwaysSet)&&(a[r.value]=n.value)}return{status:t.value,value:a}}}let m1=Object.freeze({status:"aborted"}),m2=t=>({status:"dirty",value:t}),m9=t=>({status:"valid",value:t}),m4=t=>"undefined"!=typeof Promise&&t instanceof Promise;class m3{constructor(t,r,a,i){this._cachedPath=[],this.parent=t,this.data=r,this._path=a,this._key=i}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}let m6=(t,r)=>{if("valid"===r.status)return{success:!0,data:r.value};if(!t.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let r=new mW(t.common.issues);return this._error=r,this._error}}};function m5(t){if(!t)return{};let{errorMap:r,invalid_type_error:a,required_error:i,description:n}=t;if(r&&(a||i))throw Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');return r?{errorMap:r,description:n}:{errorMap:(r,n)=>{let{message:o}=t;return"invalid_enum_value"===r.code?{message:o??n.defaultError}:void 0===n.data?{message:o??i??n.defaultError}:"invalid_type"!==r.code?{message:n.defaultError}:{message:o??a??n.defaultError}},description:n}}class m7{get description(){return this._def.description}_getType(t){return mK(t.data)}_getOrReturnCtx(t,r){return r||{common:t.parent.common,data:t.data,parsedType:mK(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new m0,ctx:{common:t.parent.common,data:t.data,parsedType:mK(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){let r=this._parse(t);if(m4(r))throw Error("Synchronous parse encountered promise.");return r}_parseAsync(t){return Promise.resolve(this._parse(t))}parse(t,r){let a=this.safeParse(t,r);if(a.success)return a.data;throw a.error}safeParse(t,r){let a={common:{issues:[],async:r?.async??!1,contextualErrorMap:r?.errorMap},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:mK(t)},i=this._parseSync({data:t,path:a.path,parent:a});return m6(a,i)}"~validate"(t){let r={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:mK(t)};if(!this["~standard"].async)try{let a=this._parseSync({data:t,path:[],parent:r});return"valid"===a.status?{value:a.value}:{issues:r.common.issues}}catch(t){t?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),r.common={issues:[],async:!0}}return this._parseAsync({data:t,path:[],parent:r}).then(t=>"valid"===t.status?{value:t.value}:{issues:r.common.issues})}async parseAsync(t,r){let a=await this.safeParseAsync(t,r);if(a.success)return a.data;throw a.error}async safeParseAsync(t,r){let a={common:{issues:[],contextualErrorMap:r?.errorMap,async:!0},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:mK(t)},i=this._parse({data:t,path:a.path,parent:a});return m6(a,await (m4(i)?i:Promise.resolve(i)))}refine(t,r){return this._refinement((a,i)=>{let n=t(a),o=()=>i.addIssue({code:mG.custom,..."string"==typeof r||void 0===r?{message:r}:"function"==typeof r?r(a):r});return"undefined"!=typeof Promise&&n instanceof Promise?n.then(t=>!!t||(o(),!1)):!!n||(o(),!1)})}refinement(t,r){return this._refinement((a,i)=>!!t(a)||(i.addIssue("function"==typeof r?r(a,i):r),!1))}_refinement(t){return new hH({schema:this,typeName:z.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}constructor(t){this.spa=this.safeParseAsync,this._def=t,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:t=>this["~validate"](t)}}optional(){return hJ.create(this,this._def)}nullable(){return hB.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return hE.create(this)}promise(){return hF.create(this,this._def)}or(t){return hj.create([this,t],this._def)}and(t){return hI.create(this,t,this._def)}transform(t){return new hH({...m5(this._def),schema:this,typeName:z.ZodEffects,effect:{type:"transform",transform:t}})}default(t){return new hK({...m5(this._def),innerType:this,defaultValue:"function"==typeof t?t:()=>t,typeName:z.ZodDefault})}brand(){return new hY({typeName:z.ZodBranded,type:this,...m5(this._def)})}catch(t){return new hG({...m5(this._def),innerType:this,catchValue:"function"==typeof t?t:()=>t,typeName:z.ZodCatch})}describe(t){return new this.constructor({...this._def,description:t})}pipe(t){return hX.create(this,t)}readonly(){return hQ.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}let m8=/^c[^\s-]{8,}$/i,he=/^[0-9a-z]+$/,ht=/^[0-9A-HJKMNP-TV-Z]{26}$/i,hr=/^[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,ha=/^[a-z0-9_-]{21}$/i,hi=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,hn=/^[-+]?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)?)??$/,ho=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,hs=/^(?:(?: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])$/,hl=/^(?:(?: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])$/,hc=/^(([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]))$/,hu=/^(([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])$/,hd=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,hp=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,hm="((\\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])))",hh=RegExp(`^${hm}$`);function hf(t){let r="[0-5]\\d";t.precision?r=`${r}\\.\\d{${t.precision}}`:null==t.precision&&(r=`${r}(\\.\\d+)?`);let a=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${r})${a}`}class hg extends m7{_parse(t){var r,a,i,n;let o;if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==mB.string){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.string,received:r.parsedType}),m1}let s=new m0;for(let l of this._def.checks)if("min"===l.kind)t.data.length<l.value&&(mQ(o=this._getOrReturnCtx(t,o),{code:mG.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),s.dirty());else if("max"===l.kind)t.data.length>l.value&&(mQ(o=this._getOrReturnCtx(t,o),{code:mG.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),s.dirty());else if("length"===l.kind){let r=t.data.length>l.value,a=t.data.length<l.value;(r||a)&&(o=this._getOrReturnCtx(t,o),r?mQ(o,{code:mG.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}):a&&mQ(o,{code:mG.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}),s.dirty())}else if("email"===l.kind)ho.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"email",code:mG.invalid_string,message:l.message}),s.dirty());else if("emoji"===l.kind)f||(f=RegExp("^[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$","u")),f.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"emoji",code:mG.invalid_string,message:l.message}),s.dirty());else if("uuid"===l.kind)hr.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"uuid",code:mG.invalid_string,message:l.message}),s.dirty());else if("nanoid"===l.kind)ha.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"nanoid",code:mG.invalid_string,message:l.message}),s.dirty());else if("cuid"===l.kind)m8.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"cuid",code:mG.invalid_string,message:l.message}),s.dirty());else if("cuid2"===l.kind)he.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"cuid2",code:mG.invalid_string,message:l.message}),s.dirty());else if("ulid"===l.kind)ht.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"ulid",code:mG.invalid_string,message:l.message}),s.dirty());else if("url"===l.kind)try{new URL(t.data)}catch{mQ(o=this._getOrReturnCtx(t,o),{validation:"url",code:mG.invalid_string,message:l.message}),s.dirty()}else"regex"===l.kind?(l.regex.lastIndex=0,l.regex.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"regex",code:mG.invalid_string,message:l.message}),s.dirty())):"trim"===l.kind?t.data=t.data.trim():"includes"===l.kind?t.data.includes(l.value,l.position)||(mQ(o=this._getOrReturnCtx(t,o),{code:mG.invalid_string,validation:{includes:l.value,position:l.position},message:l.message}),s.dirty()):"toLowerCase"===l.kind?t.data=t.data.toLowerCase():"toUpperCase"===l.kind?t.data=t.data.toUpperCase():"startsWith"===l.kind?t.data.startsWith(l.value)||(mQ(o=this._getOrReturnCtx(t,o),{code:mG.invalid_string,validation:{startsWith:l.value},message:l.message}),s.dirty()):"endsWith"===l.kind?t.data.endsWith(l.value)||(mQ(o=this._getOrReturnCtx(t,o),{code:mG.invalid_string,validation:{endsWith:l.value},message:l.message}),s.dirty()):"datetime"===l.kind?(function(t){let r=`${hm}T${hf(t)}`,a=[];return a.push(t.local?"Z?":"Z"),t.offset&&a.push("([+-]\\d{2}:?\\d{2})"),r=`${r}(${a.join("|")})`,RegExp(`^${r}$`)})(l).test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{code:mG.invalid_string,validation:"datetime",message:l.message}),s.dirty()):"date"===l.kind?hh.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{code:mG.invalid_string,validation:"date",message:l.message}),s.dirty()):"time"===l.kind?RegExp(`^${hf(l)}$`).test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{code:mG.invalid_string,validation:"time",message:l.message}),s.dirty()):"duration"===l.kind?hn.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"duration",code:mG.invalid_string,message:l.message}),s.dirty()):"ip"===l.kind?(r=t.data,!(("v4"===(a=l.version)||!a)&&hs.test(r)||("v6"===a||!a)&&hc.test(r))&&1&&(mQ(o=this._getOrReturnCtx(t,o),{validation:"ip",code:mG.invalid_string,message:l.message}),s.dirty())):"jwt"===l.kind?!function(t,r){if(!hi.test(t))return!1;try{let[a]=t.split(".");if(!a)return!1;let i=a.replace(/-/g,"+").replace(/_/g,"/").padEnd(a.length+(4-a.length%4)%4,"="),n=JSON.parse(atob(i));if("object"!=typeof n||null===n||"typ"in n&&n?.typ!=="JWT"||!n.alg||r&&n.alg!==r)return!1;return!0}catch{return!1}}(t.data,l.alg)&&(mQ(o=this._getOrReturnCtx(t,o),{validation:"jwt",code:mG.invalid_string,message:l.message}),s.dirty()):"cidr"===l.kind?(i=t.data,!(("v4"===(n=l.version)||!n)&&hl.test(i)||("v6"===n||!n)&&hu.test(i))&&1&&(mQ(o=this._getOrReturnCtx(t,o),{validation:"cidr",code:mG.invalid_string,message:l.message}),s.dirty())):"base64"===l.kind?hd.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"base64",code:mG.invalid_string,message:l.message}),s.dirty()):"base64url"===l.kind?hp.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"base64url",code:mG.invalid_string,message:l.message}),s.dirty()):q.assertNever(l);return{status:s.value,value:t.data}}_regex(t,r,a){return this.refinement(r=>t.test(r),{validation:r,code:mG.invalid_string,...M.errToObj(a)})}_addCheck(t){return new hg({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...M.errToObj(t)})}url(t){return this._addCheck({kind:"url",...M.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...M.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...M.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...M.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...M.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...M.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...M.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...M.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...M.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...M.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...M.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...M.errToObj(t)})}datetime(t){return"string"==typeof t?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:t}):this._addCheck({kind:"datetime",precision:void 0===t?.precision?null:t?.precision,offset:t?.offset??!1,local:t?.local??!1,...M.errToObj(t?.message)})}date(t){return this._addCheck({kind:"date",message:t})}time(t){return"string"==typeof t?this._addCheck({kind:"time",precision:null,message:t}):this._addCheck({kind:"time",precision:void 0===t?.precision?null:t?.precision,...M.errToObj(t?.message)})}duration(t){return this._addCheck({kind:"duration",...M.errToObj(t)})}regex(t,r){return this._addCheck({kind:"regex",regex:t,...M.errToObj(r)})}includes(t,r){return this._addCheck({kind:"includes",value:t,position:r?.position,...M.errToObj(r?.message)})}startsWith(t,r){return this._addCheck({kind:"startsWith",value:t,...M.errToObj(r)})}endsWith(t,r){return this._addCheck({kind:"endsWith",value:t,...M.errToObj(r)})}min(t,r){return this._addCheck({kind:"min",value:t,...M.errToObj(r)})}max(t,r){return this._addCheck({kind:"max",value:t,...M.errToObj(r)})}length(t,r){return this._addCheck({kind:"length",value:t,...M.errToObj(r)})}nonempty(t){return this.min(1,M.errToObj(t))}trim(){return new hg({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new hg({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new hg({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(t=>"datetime"===t.kind)}get isDate(){return!!this._def.checks.find(t=>"date"===t.kind)}get isTime(){return!!this._def.checks.find(t=>"time"===t.kind)}get isDuration(){return!!this._def.checks.find(t=>"duration"===t.kind)}get isEmail(){return!!this._def.checks.find(t=>"email"===t.kind)}get isURL(){return!!this._def.checks.find(t=>"url"===t.kind)}get isEmoji(){return!!this._def.checks.find(t=>"emoji"===t.kind)}get isUUID(){return!!this._def.checks.find(t=>"uuid"===t.kind)}get isNANOID(){return!!this._def.checks.find(t=>"nanoid"===t.kind)}get isCUID(){return!!this._def.checks.find(t=>"cuid"===t.kind)}get isCUID2(){return!!this._def.checks.find(t=>"cuid2"===t.kind)}get isULID(){return!!this._def.checks.find(t=>"ulid"===t.kind)}get isIP(){return!!this._def.checks.find(t=>"ip"===t.kind)}get isCIDR(){return!!this._def.checks.find(t=>"cidr"===t.kind)}get isBase64(){return!!this._def.checks.find(t=>"base64"===t.kind)}get isBase64url(){return!!this._def.checks.find(t=>"base64url"===t.kind)}get minLength(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxLength(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}}hg.create=t=>new hg({checks:[],typeName:z.ZodString,coerce:t?.coerce??!1,...m5(t)});class hy extends m7{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){let r;if(this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==mB.number){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.number,received:r.parsedType}),m1}let a=new m0;for(let i of this._def.checks)"int"===i.kind?q.isInteger(t.data)||(mQ(r=this._getOrReturnCtx(t,r),{code:mG.invalid_type,expected:"integer",received:"float",message:i.message}),a.dirty()):"min"===i.kind?(i.inclusive?t.data<i.value:t.data<=i.value)&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),a.dirty()):"max"===i.kind?(i.inclusive?t.data>i.value:t.data>=i.value)&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),a.dirty()):"multipleOf"===i.kind?0!==function(t,r){let a=(t.toString().split(".")[1]||"").length,i=(r.toString().split(".")[1]||"").length,n=a>i?a:i;return Number.parseInt(t.toFixed(n).replace(".",""))%Number.parseInt(r.toFixed(n).replace(".",""))/10**n}(t.data,i.value)&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.not_multiple_of,multipleOf:i.value,message:i.message}),a.dirty()):"finite"===i.kind?Number.isFinite(t.data)||(mQ(r=this._getOrReturnCtx(t,r),{code:mG.not_finite,message:i.message}),a.dirty()):q.assertNever(i);return{status:a.value,value:t.data}}gte(t,r){return this.setLimit("min",t,!0,M.toString(r))}gt(t,r){return this.setLimit("min",t,!1,M.toString(r))}lte(t,r){return this.setLimit("max",t,!0,M.toString(r))}lt(t,r){return this.setLimit("max",t,!1,M.toString(r))}setLimit(t,r,a,i){return new hy({...this._def,checks:[...this._def.checks,{kind:t,value:r,inclusive:a,message:M.toString(i)}]})}_addCheck(t){return new hy({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:M.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:M.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:M.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:M.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:M.toString(t)})}multipleOf(t,r){return this._addCheck({kind:"multipleOf",value:t,message:M.toString(r)})}finite(t){return this._addCheck({kind:"finite",message:M.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:M.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:M.toString(t)})}get minValue(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxValue(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}get isInt(){return!!this._def.checks.find(t=>"int"===t.kind||"multipleOf"===t.kind&&q.isInteger(t.value))}get isFinite(){let t=null,r=null;for(let a of this._def.checks)if("finite"===a.kind||"int"===a.kind||"multipleOf"===a.kind)return!0;else"min"===a.kind?(null===r||a.value>r)&&(r=a.value):"max"===a.kind&&(null===t||a.value<t)&&(t=a.value);return Number.isFinite(r)&&Number.isFinite(t)}}hy.create=t=>new hy({checks:[],typeName:z.ZodNumber,coerce:t?.coerce||!1,...m5(t)});class hv extends m7{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){let r;if(this._def.coerce)try{t.data=BigInt(t.data)}catch{return this._getInvalidInput(t)}if(this._getType(t)!==mB.bigint)return this._getInvalidInput(t);let a=new m0;for(let i of this._def.checks)"min"===i.kind?(i.inclusive?t.data<i.value:t.data<=i.value)&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),a.dirty()):"max"===i.kind?(i.inclusive?t.data>i.value:t.data>=i.value)&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),a.dirty()):"multipleOf"===i.kind?t.data%i.value!==BigInt(0)&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.not_multiple_of,multipleOf:i.value,message:i.message}),a.dirty()):q.assertNever(i);return{status:a.value,value:t.data}}_getInvalidInput(t){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.bigint,received:r.parsedType}),m1}gte(t,r){return this.setLimit("min",t,!0,M.toString(r))}gt(t,r){return this.setLimit("min",t,!1,M.toString(r))}lte(t,r){return this.setLimit("max",t,!0,M.toString(r))}lt(t,r){return this.setLimit("max",t,!1,M.toString(r))}setLimit(t,r,a,i){return new hv({...this._def,checks:[...this._def.checks,{kind:t,value:r,inclusive:a,message:M.toString(i)}]})}_addCheck(t){return new hv({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:M.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:M.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:M.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:M.toString(t)})}multipleOf(t,r){return this._addCheck({kind:"multipleOf",value:t,message:M.toString(r)})}get minValue(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxValue(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}}hv.create=t=>new hv({checks:[],typeName:z.ZodBigInt,coerce:t?.coerce??!1,...m5(t)});class h_ extends m7{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==mB.boolean){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.boolean,received:r.parsedType}),m1}return m9(t.data)}}h_.create=t=>new h_({typeName:z.ZodBoolean,coerce:t?.coerce||!1,...m5(t)});class hb extends m7{_parse(t){let r;if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==mB.date){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.date,received:r.parsedType}),m1}if(Number.isNaN(t.data.getTime()))return mQ(this._getOrReturnCtx(t),{code:mG.invalid_date}),m1;let a=new m0;for(let i of this._def.checks)"min"===i.kind?t.data.getTime()<i.value&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),a.dirty()):"max"===i.kind?t.data.getTime()>i.value&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),a.dirty()):q.assertNever(i);return{status:a.value,value:new Date(t.data.getTime())}}_addCheck(t){return new hb({...this._def,checks:[...this._def.checks,t]})}min(t,r){return this._addCheck({kind:"min",value:t.getTime(),message:M.toString(r)})}max(t,r){return this._addCheck({kind:"max",value:t.getTime(),message:M.toString(r)})}get minDate(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return null!=t?new Date(t):null}get maxDate(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return null!=t?new Date(t):null}}hb.create=t=>new hb({checks:[],coerce:t?.coerce||!1,typeName:z.ZodDate,...m5(t)});class hS extends m7{_parse(t){if(this._getType(t)!==mB.symbol){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.symbol,received:r.parsedType}),m1}return m9(t.data)}}hS.create=t=>new hS({typeName:z.ZodSymbol,...m5(t)});class h$ extends m7{_parse(t){if(this._getType(t)!==mB.undefined){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.undefined,received:r.parsedType}),m1}return m9(t.data)}}h$.create=t=>new h$({typeName:z.ZodUndefined,...m5(t)});class hw extends m7{_parse(t){if(this._getType(t)!==mB.null){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.null,received:r.parsedType}),m1}return m9(t.data)}}hw.create=t=>new hw({typeName:z.ZodNull,...m5(t)});class hR extends m7{constructor(){super(...arguments),this._any=!0}_parse(t){return m9(t.data)}}hR.create=t=>new hR({typeName:z.ZodAny,...m5(t)});class hk extends m7{constructor(){super(...arguments),this._unknown=!0}_parse(t){return m9(t.data)}}hk.create=t=>new hk({typeName:z.ZodUnknown,...m5(t)});class hx extends m7{_parse(t){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.never,received:r.parsedType}),m1}}hx.create=t=>new hx({typeName:z.ZodNever,...m5(t)});class hP extends m7{_parse(t){if(this._getType(t)!==mB.undefined){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.void,received:r.parsedType}),m1}return m9(t.data)}}hP.create=t=>new hP({typeName:z.ZodVoid,...m5(t)});class hE extends m7{_parse(t){let{ctx:r,status:a}=this._processInputParams(t),i=this._def;if(r.parsedType!==mB.array)return mQ(r,{code:mG.invalid_type,expected:mB.array,received:r.parsedType}),m1;if(null!==i.exactLength){let t=r.data.length>i.exactLength.value,n=r.data.length<i.exactLength.value;(t||n)&&(mQ(r,{code:t?mG.too_big:mG.too_small,minimum:n?i.exactLength.value:void 0,maximum:t?i.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:i.exactLength.message}),a.dirty())}if(null!==i.minLength&&r.data.length<i.minLength.value&&(mQ(r,{code:mG.too_small,minimum:i.minLength.value,type:"array",inclusive:!0,exact:!1,message:i.minLength.message}),a.dirty()),null!==i.maxLength&&r.data.length>i.maxLength.value&&(mQ(r,{code:mG.too_big,maximum:i.maxLength.value,type:"array",inclusive:!0,exact:!1,message:i.maxLength.message}),a.dirty()),r.common.async)return Promise.all([...r.data].map((t,a)=>i.type._parseAsync(new m3(r,t,r.path,a)))).then(t=>m0.mergeArray(a,t));let n=[...r.data].map((t,a)=>i.type._parseSync(new m3(r,t,r.path,a)));return m0.mergeArray(a,n)}get element(){return this._def.type}min(t,r){return new hE({...this._def,minLength:{value:t,message:M.toString(r)}})}max(t,r){return new hE({...this._def,maxLength:{value:t,message:M.toString(r)}})}length(t,r){return new hE({...this._def,exactLength:{value:t,message:M.toString(r)}})}nonempty(t){return this.min(1,t)}}hE.create=(t,r)=>new hE({type:t,minLength:null,maxLength:null,exactLength:null,typeName:z.ZodArray,...m5(r)});class hT extends m7{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;let t=this._def.shape(),r=q.objectKeys(t);return this._cached={shape:t,keys:r},this._cached}_parse(t){if(this._getType(t)!==mB.object){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.object,received:r.parsedType}),m1}let{status:r,ctx:a}=this._processInputParams(t),{shape:i,keys:n}=this._getCached(),o=[];if(!(this._def.catchall instanceof hx&&"strip"===this._def.unknownKeys))for(let t in a.data)n.includes(t)||o.push(t);let s=[];for(let t of n){let r=i[t],n=a.data[t];s.push({key:{status:"valid",value:t},value:r._parse(new m3(a,n,a.path,t)),alwaysSet:t in a.data})}if(this._def.catchall instanceof hx){let t=this._def.unknownKeys;if("passthrough"===t)for(let t of o)s.push({key:{status:"valid",value:t},value:{status:"valid",value:a.data[t]}});else if("strict"===t)o.length>0&&(mQ(a,{code:mG.unrecognized_keys,keys:o}),r.dirty());else if("strip"===t);else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let t=this._def.catchall;for(let r of o){let i=a.data[r];s.push({key:{status:"valid",value:r},value:t._parse(new m3(a,i,a.path,r)),alwaysSet:r in a.data})}}return a.common.async?Promise.resolve().then(async()=>{let t=[];for(let r of s){let a=await r.key,i=await r.value;t.push({key:a,value:i,alwaysSet:r.alwaysSet})}return t}).then(t=>m0.mergeObjectSync(r,t)):m0.mergeObjectSync(r,s)}get shape(){return this._def.shape()}strict(t){return M.errToObj,new hT({...this._def,unknownKeys:"strict",...void 0!==t?{errorMap:(r,a)=>{let i=this._def.errorMap?.(r,a).message??a.defaultError;return"unrecognized_keys"===r.code?{message:M.errToObj(t).message??i}:{message:i}}}:{}})}strip(){return new hT({...this._def,unknownKeys:"strip"})}passthrough(){return new hT({...this._def,unknownKeys:"passthrough"})}extend(t){return new hT({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new hT({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:z.ZodObject})}setKey(t,r){return this.augment({[t]:r})}catchall(t){return new hT({...this._def,catchall:t})}pick(t){let r={};for(let a of q.objectKeys(t))t[a]&&this.shape[a]&&(r[a]=this.shape[a]);return new hT({...this._def,shape:()=>r})}omit(t){let r={};for(let a of q.objectKeys(this.shape))t[a]||(r[a]=this.shape[a]);return new hT({...this._def,shape:()=>r})}deepPartial(){return function t(r){if(r instanceof hT){let a={};for(let i in r.shape){let n=r.shape[i];a[i]=hJ.create(t(n))}return new hT({...r._def,shape:()=>a})}if(r instanceof hE)return new hE({...r._def,type:t(r.element)});if(r instanceof hJ)return hJ.create(t(r.unwrap()));if(r instanceof hB)return hB.create(t(r.unwrap()));if(r instanceof hN)return hN.create(r.items.map(r=>t(r)));else return r}(this)}partial(t){let r={};for(let a of q.objectKeys(this.shape)){let i=this.shape[a];t&&!t[a]?r[a]=i:r[a]=i.optional()}return new hT({...this._def,shape:()=>r})}required(t){let r={};for(let a of q.objectKeys(this.shape))if(t&&!t[a])r[a]=this.shape[a];else{let t=this.shape[a];for(;t instanceof hJ;)t=t._def.innerType;r[a]=t}return new hT({...this._def,shape:()=>r})}keyof(){return hD(q.objectKeys(this.shape))}}hT.create=(t,r)=>new hT({shape:()=>t,unknownKeys:"strip",catchall:hx.create(),typeName:z.ZodObject,...m5(r)}),hT.strictCreate=(t,r)=>new hT({shape:()=>t,unknownKeys:"strict",catchall:hx.create(),typeName:z.ZodObject,...m5(r)}),hT.lazycreate=(t,r)=>new hT({shape:t,unknownKeys:"strip",catchall:hx.create(),typeName:z.ZodObject,...m5(r)});class hj extends m7{_parse(t){let{ctx:r}=this._processInputParams(t),a=this._def.options;if(r.common.async)return Promise.all(a.map(async t=>{let a={...r,common:{...r.common,issues:[]},parent:null};return{result:await t._parseAsync({data:r.data,path:r.path,parent:a}),ctx:a}})).then(function(t){for(let r of t)if("valid"===r.result.status)return r.result;for(let a of t)if("dirty"===a.result.status)return r.common.issues.push(...a.ctx.common.issues),a.result;let a=t.map(t=>new mW(t.ctx.common.issues));return mQ(r,{code:mG.invalid_union,unionErrors:a}),m1});{let t,i=[];for(let n of a){let a={...r,common:{...r.common,issues:[]},parent:null},o=n._parseSync({data:r.data,path:r.path,parent:a});if("valid"===o.status)return o;"dirty"!==o.status||t||(t={result:o,ctx:a}),a.common.issues.length&&i.push(a.common.issues)}if(t)return r.common.issues.push(...t.ctx.common.issues),t.result;let n=i.map(t=>new mW(t));return mQ(r,{code:mG.invalid_union,unionErrors:n}),m1}}get options(){return this._def.options}}hj.create=(t,r)=>new hj({options:t,typeName:z.ZodUnion,...m5(r)});let hO=t=>{if(t instanceof hL)return hO(t.schema);if(t instanceof hH)return hO(t.innerType());if(t instanceof hZ)return[t.value];if(t instanceof hV)return t.options;if(t instanceof hU)return q.objectValues(t.enum);else if(t instanceof hK)return hO(t._def.innerType);else if(t instanceof h$)return[void 0];else if(t instanceof hw)return[null];else if(t instanceof hJ)return[void 0,...hO(t.unwrap())];else if(t instanceof hB)return[null,...hO(t.unwrap())];else if(t instanceof hY)return hO(t.unwrap());else if(t instanceof hQ)return hO(t.unwrap());else if(t instanceof hG)return hO(t._def.innerType);else return[]};class hC extends m7{_parse(t){let{ctx:r}=this._processInputParams(t);if(r.parsedType!==mB.object)return mQ(r,{code:mG.invalid_type,expected:mB.object,received:r.parsedType}),m1;let a=this.discriminator,i=r.data[a],n=this.optionsMap.get(i);return n?r.common.async?n._parseAsync({data:r.data,path:r.path,parent:r}):n._parseSync({data:r.data,path:r.path,parent:r}):(mQ(r,{code:mG.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[a]}),m1)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,r,a){let i=new Map;for(let a of r){let r=hO(a.shape[t]);if(!r.length)throw Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(let n of r){if(i.has(n))throw Error(`Discriminator property ${String(t)} has duplicate value ${String(n)}`);i.set(n,a)}}return new hC({typeName:z.ZodDiscriminatedUnion,discriminator:t,options:r,optionsMap:i,...m5(a)})}}class hI extends m7{_parse(t){let{status:r,ctx:a}=this._processInputParams(t),i=(t,i)=>{if("aborted"===t.status||"aborted"===i.status)return m1;let n=function t(r,a){let i=mK(r),n=mK(a);if(r===a)return{valid:!0,data:r};if(i===mB.object&&n===mB.object){let i=q.objectKeys(a),n=q.objectKeys(r).filter(t=>-1!==i.indexOf(t)),o={...r,...a};for(let i of(Object.prototype.hasOwnProperty.call(o,"__proto__")&&delete o.__proto__,n)){if("__proto__"===i)continue;let n=t(r[i],a[i]);if(!n.valid)return{valid:!1};o[i]=n.data}return{valid:!0,data:o}}if(i===mB.array&&n===mB.array){if(r.length!==a.length)return{valid:!1};let i=[];for(let n=0;n<r.length;n++){let o=t(r[n],a[n]);if(!o.valid)return{valid:!1};i.push(o.data)}return{valid:!0,data:i}}if(i===mB.date&&n===mB.date&&+r==+a)return{valid:!0,data:r};return{valid:!1}}(t.value,i.value);return n.valid?(("dirty"===t.status||"dirty"===i.status)&&r.dirty(),{status:r.value,value:n.data}):(mQ(a,{code:mG.invalid_intersection_types}),m1)};return a.common.async?Promise.all([this._def.left._parseAsync({data:a.data,path:a.path,parent:a}),this._def.right._parseAsync({data:a.data,path:a.path,parent:a})]).then(([t,r])=>i(t,r)):i(this._def.left._parseSync({data:a.data,path:a.path,parent:a}),this._def.right._parseSync({data:a.data,path:a.path,parent:a}))}}hI.create=(t,r,a)=>new hI({left:t,right:r,typeName:z.ZodIntersection,...m5(a)});class hN extends m7{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==mB.array)return mQ(a,{code:mG.invalid_type,expected:mB.array,received:a.parsedType}),m1;if(a.data.length<this._def.items.length)return mQ(a,{code:mG.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),m1;!this._def.rest&&a.data.length>this._def.items.length&&(mQ(a,{code:mG.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),r.dirty());let i=[...a.data].map((t,r)=>{let i=this._def.items[r]||this._def.rest;return i?i._parse(new m3(a,t,a.path,r)):null}).filter(t=>!!t);return a.common.async?Promise.all(i).then(t=>m0.mergeArray(r,t)):m0.mergeArray(r,i)}get items(){return this._def.items}rest(t){return new hN({...this._def,rest:t})}}hN.create=(t,r)=>{if(!Array.isArray(t))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new hN({items:t,typeName:z.ZodTuple,rest:null,...m5(r)})};class hq extends m7{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==mB.object)return mQ(a,{code:mG.invalid_type,expected:mB.object,received:a.parsedType}),m1;let i=[],n=this._def.keyType,o=this._def.valueType;for(let t in a.data)i.push({key:n._parse(new m3(a,t,a.path,t)),value:o._parse(new m3(a,a.data[t],a.path,t)),alwaysSet:t in a.data});return a.common.async?m0.mergeObjectAsync(r,i):m0.mergeObjectSync(r,i)}get element(){return this._def.valueType}static create(t,r,a){return new hq(r instanceof m7?{keyType:t,valueType:r,typeName:z.ZodRecord,...m5(a)}:{keyType:hg.create(),valueType:t,typeName:z.ZodRecord,...m5(r)})}}class hA extends m7{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==mB.map)return mQ(a,{code:mG.invalid_type,expected:mB.map,received:a.parsedType}),m1;let i=this._def.keyType,n=this._def.valueType,o=[...a.data.entries()].map(([t,r],o)=>({key:i._parse(new m3(a,t,a.path,[o,"key"])),value:n._parse(new m3(a,r,a.path,[o,"value"]))}));if(a.common.async){let t=new Map;return Promise.resolve().then(async()=>{for(let a of o){let i=await a.key,n=await a.value;if("aborted"===i.status||"aborted"===n.status)return m1;("dirty"===i.status||"dirty"===n.status)&&r.dirty(),t.set(i.value,n.value)}return{status:r.value,value:t}})}{let t=new Map;for(let a of o){let i=a.key,n=a.value;if("aborted"===i.status||"aborted"===n.status)return m1;("dirty"===i.status||"dirty"===n.status)&&r.dirty(),t.set(i.value,n.value)}return{status:r.value,value:t}}}}hA.create=(t,r,a)=>new hA({valueType:r,keyType:t,typeName:z.ZodMap,...m5(a)});class hM extends m7{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==mB.set)return mQ(a,{code:mG.invalid_type,expected:mB.set,received:a.parsedType}),m1;let i=this._def;null!==i.minSize&&a.data.size<i.minSize.value&&(mQ(a,{code:mG.too_small,minimum:i.minSize.value,type:"set",inclusive:!0,exact:!1,message:i.minSize.message}),r.dirty()),null!==i.maxSize&&a.data.size>i.maxSize.value&&(mQ(a,{code:mG.too_big,maximum:i.maxSize.value,type:"set",inclusive:!0,exact:!1,message:i.maxSize.message}),r.dirty());let n=this._def.valueType;function o(t){let a=new Set;for(let i of t){if("aborted"===i.status)return m1;"dirty"===i.status&&r.dirty(),a.add(i.value)}return{status:r.value,value:a}}let s=[...a.data.values()].map((t,r)=>n._parse(new m3(a,t,a.path,r)));return a.common.async?Promise.all(s).then(t=>o(t)):o(s)}min(t,r){return new hM({...this._def,minSize:{value:t,message:M.toString(r)}})}max(t,r){return new hM({...this._def,maxSize:{value:t,message:M.toString(r)}})}size(t,r){return this.min(t,r).max(t,r)}nonempty(t){return this.min(1,t)}}hM.create=(t,r)=>new hM({valueType:t,minSize:null,maxSize:null,typeName:z.ZodSet,...m5(r)});class hz extends m7{constructor(){super(...arguments),this.validate=this.implement}_parse(t){let{ctx:r}=this._processInputParams(t);if(r.parsedType!==mB.function)return mQ(r,{code:mG.invalid_type,expected:mB.function,received:r.parsedType}),m1;function a(t,a){return mX({data:t,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,mY,mY].filter(t=>!!t),issueData:{code:mG.invalid_arguments,argumentsError:a}})}function i(t,a){return mX({data:t,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,mY,mY].filter(t=>!!t),issueData:{code:mG.invalid_return_type,returnTypeError:a}})}let n={errorMap:r.common.contextualErrorMap},o=r.data;if(this._def.returns instanceof hF){let t=this;return m9(async function(...r){let s=new mW([]),l=await t._def.args.parseAsync(r,n).catch(t=>{throw s.addIssue(a(r,t)),s}),c=await Reflect.apply(o,this,l);return await t._def.returns._def.type.parseAsync(c,n).catch(t=>{throw s.addIssue(i(c,t)),s})})}{let t=this;return m9(function(...r){let s=t._def.args.safeParse(r,n);if(!s.success)throw new mW([a(r,s.error)]);let l=Reflect.apply(o,this,s.data),c=t._def.returns.safeParse(l,n);if(!c.success)throw new mW([i(l,c.error)]);return c.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new hz({...this._def,args:hN.create(t).rest(hk.create())})}returns(t){return new hz({...this._def,returns:t})}implement(t){return this.parse(t)}strictImplement(t){return this.parse(t)}static create(t,r,a){return new hz({args:t||hN.create([]).rest(hk.create()),returns:r||hk.create(),typeName:z.ZodFunction,...m5(a)})}}class hL extends m7{get schema(){return this._def.getter()}_parse(t){let{ctx:r}=this._processInputParams(t);return this._def.getter()._parse({data:r.data,path:r.path,parent:r})}}hL.create=(t,r)=>new hL({getter:t,typeName:z.ZodLazy,...m5(r)});class hZ extends m7{_parse(t){if(t.data!==this._def.value){let r=this._getOrReturnCtx(t);return mQ(r,{received:r.data,code:mG.invalid_literal,expected:this._def.value}),m1}return{status:"valid",value:t.data}}get value(){return this._def.value}}function hD(t,r){return new hV({values:t,typeName:z.ZodEnum,...m5(r)})}hZ.create=(t,r)=>new hZ({value:t,typeName:z.ZodLiteral,...m5(r)});class hV extends m7{_parse(t){if("string"!=typeof t.data){let r=this._getOrReturnCtx(t),a=this._def.values;return mQ(r,{expected:q.joinValues(a),received:r.parsedType,code:mG.invalid_type}),m1}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(t.data)){let r=this._getOrReturnCtx(t),a=this._def.values;return mQ(r,{received:r.data,code:mG.invalid_enum_value,options:a}),m1}return m9(t.data)}get options(){return this._def.values}get enum(){let t={};for(let r of this._def.values)t[r]=r;return t}get Values(){let t={};for(let r of this._def.values)t[r]=r;return t}get Enum(){let t={};for(let r of this._def.values)t[r]=r;return t}extract(t,r=this._def){return hV.create(t,{...this._def,...r})}exclude(t,r=this._def){return hV.create(this.options.filter(r=>!t.includes(r)),{...this._def,...r})}}hV.create=hD;class hU extends m7{_parse(t){let r=q.getValidEnumValues(this._def.values),a=this._getOrReturnCtx(t);if(a.parsedType!==mB.string&&a.parsedType!==mB.number){let t=q.objectValues(r);return mQ(a,{expected:q.joinValues(t),received:a.parsedType,code:mG.invalid_type}),m1}if(this._cache||(this._cache=new Set(q.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){let t=q.objectValues(r);return mQ(a,{received:a.data,code:mG.invalid_enum_value,options:t}),m1}return m9(t.data)}get enum(){return this._def.values}}hU.create=(t,r)=>new hU({values:t,typeName:z.ZodNativeEnum,...m5(r)});class hF extends m7{unwrap(){return this._def.type}_parse(t){let{ctx:r}=this._processInputParams(t);return r.parsedType!==mB.promise&&!1===r.common.async?(mQ(r,{code:mG.invalid_type,expected:mB.promise,received:r.parsedType}),m1):m9((r.parsedType===mB.promise?r.data:Promise.resolve(r.data)).then(t=>this._def.type.parseAsync(t,{path:r.path,errorMap:r.common.contextualErrorMap})))}}hF.create=(t,r)=>new hF({type:t,typeName:z.ZodPromise,...m5(r)});class hH extends m7{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===z.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){let{status:r,ctx:a}=this._processInputParams(t),i=this._def.effect||null,n={addIssue:t=>{mQ(a,t),t.fatal?r.abort():r.dirty()},get path(){return a.path}};if(n.addIssue=n.addIssue.bind(n),"preprocess"===i.type){let t=i.transform(a.data,n);if(a.common.async)return Promise.resolve(t).then(async t=>{if("aborted"===r.value)return m1;let i=await this._def.schema._parseAsync({data:t,path:a.path,parent:a});return"aborted"===i.status?m1:"dirty"===i.status||"dirty"===r.value?m2(i.value):i});{if("aborted"===r.value)return m1;let i=this._def.schema._parseSync({data:t,path:a.path,parent:a});return"aborted"===i.status?m1:"dirty"===i.status||"dirty"===r.value?m2(i.value):i}}if("refinement"===i.type){let t=t=>{let r=i.refinement(t,n);if(a.common.async)return Promise.resolve(r);if(r instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return t};if(!1!==a.common.async)return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then(a=>"aborted"===a.status?m1:("dirty"===a.status&&r.dirty(),t(a.value).then(()=>({status:r.value,value:a.value}))));{let i=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});return"aborted"===i.status?m1:("dirty"===i.status&&r.dirty(),t(i.value),{status:r.value,value:i.value})}}if("transform"===i.type)if(!1!==a.common.async)return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then(t=>"valid"!==t.status?m1:Promise.resolve(i.transform(t.value,n)).then(t=>({status:r.value,value:t})));else{let t=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});if("valid"!==t.status)return m1;let o=i.transform(t.value,n);if(o instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:o}}q.assertNever(i)}}hH.create=(t,r,a)=>new hH({schema:t,typeName:z.ZodEffects,effect:r,...m5(a)}),hH.createWithPreprocess=(t,r,a)=>new hH({schema:r,effect:{type:"preprocess",transform:t},typeName:z.ZodEffects,...m5(a)});class hJ extends m7{_parse(t){return this._getType(t)===mB.undefined?m9(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}hJ.create=(t,r)=>new hJ({innerType:t,typeName:z.ZodOptional,...m5(r)});class hB extends m7{_parse(t){return this._getType(t)===mB.null?m9(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}hB.create=(t,r)=>new hB({innerType:t,typeName:z.ZodNullable,...m5(r)});class hK extends m7{_parse(t){let{ctx:r}=this._processInputParams(t),a=r.data;return r.parsedType===mB.undefined&&(a=this._def.defaultValue()),this._def.innerType._parse({data:a,path:r.path,parent:r})}removeDefault(){return this._def.innerType}}hK.create=(t,r)=>new hK({innerType:t,typeName:z.ZodDefault,defaultValue:"function"==typeof r.default?r.default:()=>r.default,...m5(r)});class hG extends m7{_parse(t){let{ctx:r}=this._processInputParams(t),a={...r,common:{...r.common,issues:[]}},i=this._def.innerType._parse({data:a.data,path:a.path,parent:{...a}});return m4(i)?i.then(t=>({status:"valid",value:"valid"===t.status?t.value:this._def.catchValue({get error(){return new mW(a.common.issues)},input:a.data})})):{status:"valid",value:"valid"===i.status?i.value:this._def.catchValue({get error(){return new mW(a.common.issues)},input:a.data})}}removeCatch(){return this._def.innerType}}hG.create=(t,r)=>new hG({innerType:t,typeName:z.ZodCatch,catchValue:"function"==typeof r.catch?r.catch:()=>r.catch,...m5(r)});class hW extends m7{_parse(t){if(this._getType(t)!==mB.nan){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.nan,received:r.parsedType}),m1}return{status:"valid",value:t.data}}}hW.create=t=>new hW({typeName:z.ZodNaN,...m5(t)}),Symbol("zod_brand");class hY extends m7{_parse(t){let{ctx:r}=this._processInputParams(t),a=r.data;return this._def.type._parse({data:a,path:r.path,parent:r})}unwrap(){return this._def.type}}class hX extends m7{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.common.async)return(async()=>{let t=await this._def.in._parseAsync({data:a.data,path:a.path,parent:a});return"aborted"===t.status?m1:"dirty"===t.status?(r.dirty(),m2(t.value)):this._def.out._parseAsync({data:t.value,path:a.path,parent:a})})();{let t=this._def.in._parseSync({data:a.data,path:a.path,parent:a});return"aborted"===t.status?m1:"dirty"===t.status?(r.dirty(),{status:"dirty",value:t.value}):this._def.out._parseSync({data:t.value,path:a.path,parent:a})}}static create(t,r){return new hX({in:t,out:r,typeName:z.ZodPipeline})}}class hQ extends m7{_parse(t){let r=this._def.innerType._parse(t),a=t=>("valid"===t.status&&(t.value=Object.freeze(t.value)),t);return m4(r)?r.then(t=>a(t)):a(r)}unwrap(){return this._def.innerType}}hQ.create=(t,r)=>new hQ({innerType:t,typeName:z.ZodReadonly,...m5(r)}),hT.lazycreate,(O=z||(z={})).ZodString="ZodString",O.ZodNumber="ZodNumber",O.ZodNaN="ZodNaN",O.ZodBigInt="ZodBigInt",O.ZodBoolean="ZodBoolean",O.ZodDate="ZodDate",O.ZodSymbol="ZodSymbol",O.ZodUndefined="ZodUndefined",O.ZodNull="ZodNull",O.ZodAny="ZodAny",O.ZodUnknown="ZodUnknown",O.ZodNever="ZodNever",O.ZodVoid="ZodVoid",O.ZodArray="ZodArray",O.ZodObject="ZodObject",O.ZodUnion="ZodUnion",O.ZodDiscriminatedUnion="ZodDiscriminatedUnion",O.ZodIntersection="ZodIntersection",O.ZodTuple="ZodTuple",O.ZodRecord="ZodRecord",O.ZodMap="ZodMap",O.ZodSet="ZodSet",O.ZodFunction="ZodFunction",O.ZodLazy="ZodLazy",O.ZodLiteral="ZodLiteral",O.ZodEnum="ZodEnum",O.ZodEffects="ZodEffects",O.ZodNativeEnum="ZodNativeEnum",O.ZodOptional="ZodOptional",O.ZodNullable="ZodNullable",O.ZodDefault="ZodDefault",O.ZodCatch="ZodCatch",O.ZodPromise="ZodPromise",O.ZodBranded="ZodBranded",O.ZodPipeline="ZodPipeline",O.ZodReadonly="ZodReadonly",hg.create,hy.create,hW.create,hv.create,h_.create,hb.create,hS.create,h$.create,hw.create,hR.create,hk.create,hx.create,hP.create,hE.create,hT.create,hT.strictCreate,hj.create,hC.create,hI.create,hN.create,hq.create,hA.create,hM.create,hz.create,hL.create,hZ.create,hV.create,hU.create,hF.create,hH.create,hJ.create,hB.create,hH.createWithPreprocess,hX.create;let h0=(t,r)=>{let a=0;for(;a<t.length&&a<r.length&&t[a]===r[a];a++);return[(t.length-a).toString(),...r.slice(a)].join("/")};function h1(t){if("openAi"!==t.target)return{};let r=[...t.basePath,t.definitionPath,t.openAiAnyTypeName];return t.flags.hasReferencedOpenAiAnyType=!0,{$ref:"relative"===t.$refStrategy?h0(r,t.currentPath):r.join("/")}}function h2(t,r,a,i){i?.errorMessages&&a&&(t.errorMessage={...t.errorMessage,[r]:a})}function h9(t,r,a,i,n){t[r]=a,h2(t,r,i,n)}function h4(t,r){return ff(t.type._def,r)}let h3=/^[cC][^\s-]{8,}$/,h6=/^[0-9a-z]+$/,h5=/^[0-9A-HJKMNP-TV-Z]{26}$/,h7=/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,h8=()=>(void 0===R&&(R=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),R),fe=/^(?:(?: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])$/,ft=/^(([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])$/,fr=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,fa=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,fi=/^[a-zA-Z0-9_-]{21}$/,fn=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;function fo(t,r){let a={type:"string"};if(t.checks)for(let i of t.checks)switch(i.kind){case"min":h9(a,"minLength","number"==typeof a.minLength?Math.max(a.minLength,i.value):i.value,i.message,r);break;case"max":h9(a,"maxLength","number"==typeof a.maxLength?Math.min(a.maxLength,i.value):i.value,i.message,r);break;case"email":switch(r.emailStrategy){case"format:email":fc(a,"email",i.message,r);break;case"format:idn-email":fc(a,"idn-email",i.message,r);break;case"pattern:zod":fu(a,h7,i.message,r)}break;case"url":fc(a,"uri",i.message,r);break;case"uuid":fc(a,"uuid",i.message,r);break;case"regex":fu(a,i.regex,i.message,r);break;case"cuid":fu(a,h3,i.message,r);break;case"cuid2":fu(a,h6,i.message,r);break;case"startsWith":fu(a,RegExp(`^${fs(i.value,r)}`),i.message,r);break;case"endsWith":fu(a,RegExp(`${fs(i.value,r)}$`),i.message,r);break;case"datetime":fc(a,"date-time",i.message,r);break;case"date":fc(a,"date",i.message,r);break;case"time":fc(a,"time",i.message,r);break;case"duration":fc(a,"duration",i.message,r);break;case"length":h9(a,"minLength","number"==typeof a.minLength?Math.max(a.minLength,i.value):i.value,i.message,r),h9(a,"maxLength","number"==typeof a.maxLength?Math.min(a.maxLength,i.value):i.value,i.message,r);break;case"includes":fu(a,RegExp(fs(i.value,r)),i.message,r);break;case"ip":"v6"!==i.version&&fc(a,"ipv4",i.message,r),"v4"!==i.version&&fc(a,"ipv6",i.message,r);break;case"base64url":fu(a,fa,i.message,r);break;case"jwt":fu(a,fn,i.message,r);break;case"cidr":"v6"!==i.version&&fu(a,fe,i.message,r),"v4"!==i.version&&fu(a,ft,i.message,r);break;case"emoji":fu(a,h8(),i.message,r);break;case"ulid":fu(a,h5,i.message,r);break;case"base64":switch(r.base64Strategy){case"format:binary":fc(a,"binary",i.message,r);break;case"contentEncoding:base64":h9(a,"contentEncoding","base64",i.message,r);break;case"pattern:zod":fu(a,fr,i.message,r)}break;case"nanoid":fu(a,fi,i.message,r)}return a}function fs(t,r){return"escape"===r.patternStrategy?function(t){let r="";for(let a=0;a<t.length;a++)fl.has(t[a])||(r+="\\"),r+=t[a];return r}(t):t}let fl=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function fc(t,r,a,i){t.format||t.anyOf?.some(t=>t.format)?(t.anyOf||(t.anyOf=[]),t.format&&(t.anyOf.push({format:t.format,...t.errorMessage&&i.errorMessages&&{errorMessage:{format:t.errorMessage.format}}}),delete t.format,t.errorMessage&&(delete t.errorMessage.format,0===Object.keys(t.errorMessage).length&&delete t.errorMessage)),t.anyOf.push({format:r,...a&&i.errorMessages&&{errorMessage:{format:a}}})):h9(t,"format",r,a,i)}function fu(t,r,a,i){t.pattern||t.allOf?.some(t=>t.pattern)?(t.allOf||(t.allOf=[]),t.pattern&&(t.allOf.push({pattern:t.pattern,...t.errorMessage&&i.errorMessages&&{errorMessage:{pattern:t.errorMessage.pattern}}}),delete t.pattern,t.errorMessage&&(delete t.errorMessage.pattern,0===Object.keys(t.errorMessage).length&&delete t.errorMessage)),t.allOf.push({pattern:fd(r,i),...a&&i.errorMessages&&{errorMessage:{pattern:a}}})):h9(t,"pattern",fd(r,i),a,i)}function fd(t,r){if(!r.applyRegexFlags||!t.flags)return t.source;let a={i:t.flags.includes("i"),m:t.flags.includes("m"),s:t.flags.includes("s")},i=a.i?t.source.toLowerCase():t.source,n="",o=!1,s=!1,l=!1;for(let t=0;t<i.length;t++){if(o){n+=i[t],o=!1;continue}if(a.i){if(s){if(i[t].match(/[a-z]/)){l?(n+=i[t],n+=`${i[t-2]}-${i[t]}`.toUpperCase(),l=!1):"-"===i[t+1]&&i[t+2]?.match(/[a-z]/)?(n+=i[t],l=!0):n+=`${i[t]}${i[t].toUpperCase()}`;continue}}else if(i[t].match(/[a-z]/)){n+=`[${i[t]}${i[t].toUpperCase()}]`;continue}}if(a.m){if("^"===i[t]){n+=`(^|(?<=[\r
77
+ `,t.enqueue(r.encode(n)),!0}catch(t){return this.onerror?.(t),!1}}handleUnsupportedRequest(){return this.onerror?.(Error("Method not allowed.")),Response.json({jsonrpc:"2.0",error:{code:-32e3,message:"Method not allowed."},id:null},{status:405,headers:{Allow:"GET, POST, DELETE","Content-Type":"application/json"}})}async handlePostRequest(t,r){try{let a,i,n,o,s,l=t.headers.get("accept");if(!l?.includes("application/json")||!l.includes("text/event-stream"))return this.onerror?.(Error("Not Acceptable: Client must accept both application/json and text/event-stream")),this.createJsonErrorResponse(406,-32e3,"Not Acceptable: Client must accept both application/json and text/event-stream");if(!uA(t.headers.get("content-type")))return this.onerror?.(Error("Unsupported Media Type: Content-Type must be application/json")),this.createJsonErrorResponse(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");if(r?.parsedBody===void 0)try{let r=await p0(t,this._maxRequestBodySize);if(r.tooLarge){let t=pX(this._maxRequestBodySize);return this.onerror?.(Error(t)),this.createJsonErrorResponse(413,-32e3,t)}a=JSON.parse(r.text)}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON")}else a=r.parsedBody;if(Array.isArray(a)&&a.length>100)return this.onerror?.(Error("Invalid Request: Batch must not exceed 100 messages")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Batch must not exceed 100 messages");try{i=Array.isArray(a)?a.map(t=>ol.parse(t)):[ol.parse(a)]}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON-RPC message")}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");let c=i.some(t=>ow.safeParse(t).success);if(c){if(this._initialized&&void 0!==this.sessionId)return this.onerror?.(Error("Invalid Request: Server already initialized")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Server already initialized");if(i.length>1)return this.onerror?.(Error("Invalid Request: Only one initialization request is allowed")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Only one initialization request is allowed");this.sessionId=this.sessionIdGenerator?.(),this._initialized=!0,this.sessionId&&this._onsessioninitialized&&await Promise.resolve(this._onsessioninitialized(this.sessionId))}if(!c){let r=this.validateSession(t);if(r)return r;let a=this.validateProtocolVersion(t);if(a)return a}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");try{n=await this._checkScopeChallenge(i,r?.authInfo)}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(500,-32603,"Internal server error")}if(n)return n;if(!i.some(t=>cK(t))){for(let a of i)this.onmessage?.(a,{authInfo:r?.authInfo,request:t});return new Response(null,{status:202})}let u=crypto.randomUUID(),d=i.find(t=>ow.safeParse(t).success),p=d?d.params.protocolVersion:t.headers.get("mcp-protocol-version")??"2025-03-26";if(this._enableJsonResponse)return new Promise(a=>{for(let t of(this._streamMapping.set(u,{resolveJson:a,cleanup:()=>{this._streamMapping.delete(u)}}),i))cK(t)&&this._requestToStreamMapping.set(t.id,u);for(let a of i)this.onmessage?.(a,{authInfo:r?.authInfo,request:t})});let m=new TextEncoder,h=new ReadableStream({start:t=>{o=t},cancel:()=>{void 0!==s&&clearInterval(s),this._streamMapping.get(u)?.controller===o&&this._streamMapping.delete(u)}}),f={"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"};for(let t of(void 0!==this.sessionId&&(f["mcp-session-id"]=this.sessionId),i))cK(t)&&(this._streamMapping.set(u,{controller:o,encoder:m,cleanup:()=>{void 0!==s&&clearInterval(s),this._streamMapping.delete(u);try{o.close()}catch{}}}),this._requestToStreamMapping.set(t.id,u));for(let a of(await this.writePrimingEvent(o,m,u,p),i)){let i,n;cK(a)&&this._eventStore&&this.supportsEmptySSEData(p)&&(i=()=>{this.closeSSEStream(a.id)},n=()=>{this.closeStandaloneSSEStream()}),this.onmessage?.(a,{authInfo:r?.authInfo,request:t,closeSSEStream:i,closeStandaloneSSEStream:n})}return this._streamMapping.get(u)?.controller===o&&(s=this.startKeepAlive(o,m)),new Response(h,{status:200,headers:f})}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error",{data:String(t)})}}async handleDeleteRequest(t){let r=this.validateSession(t);if(r)return r;let a=this.validateProtocolVersion(t);if(a)return a;try{return await Promise.resolve(this._onsessionclosed?.(this.sessionId)),new Response(null,{status:200})}finally{await this.close()}}validateSession(t){if(void 0===this.sessionIdGenerator)return;if(!this._initialized)return this.onerror?.(Error("Bad Request: Server not initialized")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Server not initialized");let r=t.headers.get("mcp-session-id");return r?r!==this.sessionId?(this.onerror?.(Error("Session not found")),this.createJsonErrorResponse(404,-32001,"Session not found")):void 0:(this.onerror?.(Error("Bad Request: Mcp-Session-Id header is required")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Mcp-Session-Id header is required"))}validateProtocolVersion(t){let r=t.headers.get("mcp-protocol-version");if(null!==r&&!this._supportedProtocolVersions.includes(r)){let t=`Bad Request: Unsupported protocol version: ${r} (supported versions: ${this._supportedProtocolVersions.join(", ")})`;return this.onerror?.(Error(t)),this.createJsonErrorResponse(400,-32e3,t)}}async close(){if(!this._closed){for(let{cleanup:t}of(this._closed=!0,this._streamMapping.values()))t();this._streamMapping.clear(),this._requestResponseMap.clear(),this.onclose?.()}}closeSSEStream(t){let r=this._requestToStreamMapping.get(t);if(!r)return;let a=this._streamMapping.get(r);a&&a.cleanup()}closeStandaloneSSEStream(){let t=this._streamMapping.get(this._standaloneSseStreamId);t&&t.cleanup()}async send(t,r){let a=r?.relatedRequestId;if((cW(t)||cY(t))&&(a=t.id),void 0===a){let r;if(cW(t)||cY(t))throw Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");this._eventStore&&(r=await this._eventStore.storeEvent(this._standaloneSseStreamId,t));let a=this._streamMapping.get(this._standaloneSseStreamId);if(void 0===a)return;a.controller&&a.encoder&&(void 0===r||!a.replayedEventIds?.has(r))&&this.writeSSEEvent(a.controller,a.encoder,t,r);return}let i=this._requestToStreamMapping.get(a);if(!i)throw Error(`No connection established for request ID: ${String(a)}`);let n=this._streamMapping.get(i);if(!this._enableJsonResponse){let r;this._eventStore&&(r=await this._eventStore.storeEvent(i,t),n=this._streamMapping.get(i)),n?.controller&&n?.encoder&&(void 0===r||!n.replayedEventIds?.has(r))&&this.writeSSEEvent(n.controller,n.encoder,t,r)}if(cW(t)||cY(t)){this._requestResponseMap.set(a,t);let r=[...this._requestToStreamMapping.entries()].filter(([t,r])=>r===i).map(([t])=>t);if(r.every(t=>this._requestResponseMap.has(t))){if(!n){if(this._enableJsonResponse)throw Error(`No connection established for request ID: ${String(a)}`);if(!this._eventStore){for(let t of(this.onerror?.(Error(`Response for request ID ${String(a)} is undeliverable: per-request stream is disconnected and no eventStore is configured`)),r))this._requestResponseMap.delete(t),this._requestToStreamMapping.delete(t);return}for(let t of r)this._requestResponseMap.delete(t),this._requestToStreamMapping.delete(t);return}if(this._enableJsonResponse&&n.resolveJson){let t={"Content-Type":"application/json"};void 0!==this.sessionId&&(t["mcp-session-id"]=this.sessionId);let a=r.map(t=>this._requestResponseMap.get(t));1===a.length?n.resolveJson(Response.json(a[0],{status:200,headers:t})):n.resolveJson(Response.json(a,{status:200,headers:t})),n.cleanup()}else n.cleanup();for(let t of r)this._requestResponseMap.delete(t),this._requestToStreamMapping.delete(t)}}}};function p2(t){if(null===t||"object"!=typeof t||Array.isArray(t))return null;let{method:r,id:a}=t;return"string"!=typeof r?null:"string"==typeof a||"number"==typeof a?a:null}function p9(t,r,a,i,n=null){return Response.json({jsonrpc:"2.0",error:{code:r,message:a,...void 0!==i&&{data:i}},id:n},{status:t})}function p4(t,r=null){return p9(t.httpStatus,t.code,t.message,t.data,r)}function p3(t){return t instanceof Error?t:Error(String(t))}function p6(t=null){return p9(500,-32603,"Internal server error",void 0,t)}function p5(t){if(void 0!==t.transport)throw Error("The factory returned an instance that is still serving another request. Return a new instance for each request.")}function p7(t){return{protocolVersionHeader:t.headers.get("mcp-protocol-version")??void 0,mcpMethodHeader:t.headers.get("mcp-method")??void 0,mcpNameHeader:t.headers.get("mcp-name")??void 0}}async function p8(t,r,a=!0,i=4194304){let n,o=t.method.toUpperCase(),s=r,l=t,c=!1;if("POST"===o){if(void 0===s){let r;a&&(l=t.clone());try{let a=await p0(t,i);if(a.tooLarge)return{step:"body-too-large"};r=a.text}catch{return{step:"unreadable-body"}}try{n=0===r.length?void 0:JSON.parse(r)}catch{c=!0}c||void 0===n||(s=n)}else n=s;if(c||void 0===n)return{step:"no-json-body",forwardRequest:l}}return{step:"classified",outcome:function(t){if("POST"!==(t={...t,...void 0!==t.protocolVersionHeader&&{protocolVersionHeader:un(t.protocolVersionHeader)},...void 0!==t.mcpMethodHeader&&{mcpMethodHeader:un(t.mcpMethodHeader)},...void 0!==t.mcpNameHeader&&{mcpNameHeader:un(t.mcpNameHeader)}}).httpMethod.toUpperCase())return{kind:"legacy",reason:"http-method"};let r=t.body;if(Array.isArray(r)){if(0===r.length)return ur("jsonrpc-shape","empty-batch",400,new cg(cf.InvalidRequest,"Bad Request: empty JSON-RPC batch"),!0);for(let t of r){if(cF(uo(t)?t.params:void 0))return ur("jsonrpc-shape","batch-with-modern-element",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC batches may not contain requests for protocol revision 2026-07-28 or later"),!0);if(!(cK(t)||cG(t)||cW(t)||cY(t)))return ur("jsonrpc-shape","batch-with-invalid-element",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC batch contains an invalid message"),!0)}return{kind:"legacy",reason:"batch"}}return cW(r)||cY(r)?{kind:"legacy",reason:"response"}:uo(r)&&cK(r)?function(t,r){let a=r.params,i=r.method,n=t.protocolVersionHeader,o=void 0!==n&&n>=lW;if("initialize"===i&&!function(t){if(!cF(t))return!1;let r=cH(t);if(void 0===r||!(r>=lW))return!1;let a=cU(t);return void 0!==a&&0===cJ(a).length}(a)){if(o)return ua("initialize-with-modern-header",n,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let t=uo(a)&&"string"==typeof a.protocolVersion?a.protocolVersion:void 0;return{kind:"legacy",reason:"initialize",...void 0!==t&&{requestedVersion:t}}}if(cF(a)){let o=cU(a),s=(void 0===o?[]:cJ(o))[0];if(void 0!==s)return ur("envelope","envelope-invalid",400,new cg(cf.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${s.key}: ${s.problem}`,{envelope:s}),!0);let l=cH(a);return void 0!==n&&void 0!==l&&n!==l?ua("header-body-version-mismatch",n,`the body envelope names protocol version ${l} but the MCP-Protocol-Version header names ${n}`):void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==i?ua("method-header-mismatch",t.mcpMethodHeader,`the body names method ${i} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"request",message:r,classification:us(l)}}if(o){let t=cU(a),r=cJ(t??{}).filter(t=>"missing"===t.problem).map(t=>t.key),i=void 0===t?["_meta"]:r.length>0?r:[nJ];return ur("envelope","modern-header-without-claim",400,new cg(cf.InvalidParams,`Invalid params: the MCP-Protocol-Version header names protocol revision ${n}, but the request is missing the required per-request envelope key(s): ${i.join(", ")}`,{envelope:{missing:i}}),!0)}return{kind:"legacy",reason:"no-claim",...void 0!==n&&{requestedVersion:n}}}(t,r):uo(r)&&cG(r)?function(t,r){let a=r.params,i=r.method,n=t.protocolVersionHeader,o=void 0!==n&&n>=lW;if(cF(a)){let o=cH(a);if(void 0===o){let t=cU(a),r=(void 0===t?[]:cJ(t)).find(t=>t.key===nJ)??{key:nJ,problem:"expected a protocol version string"};return ur("envelope","notification-envelope-invalid",400,new cg(cf.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${r.key}: ${r.problem}`,{envelope:r}),!0)}if(void 0!==n&&n!==o)return ua("notification-header-body-version-mismatch",n,`the notification envelope names protocol version ${o} but the MCP-Protocol-Version header names ${n}`);let s=us(o);return"modern"===s.era&&void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==i?ua("notification-method-header-mismatch",t.mcpMethodHeader,`the notification body names method ${i} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:r,classification:s}}return o?void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==i?ua("notification-method-header-mismatch",t.mcpMethodHeader,`the notification body names method ${i} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:r,classification:{era:"modern",revision:n}}:{kind:"legacy",reason:"notification",...void 0!==n&&{requestedVersion:n}}}(t,r):ur("jsonrpc-shape","invalid-json-rpc-body",400,new cg(cf.InvalidRequest,"Bad Request: the request body is not a valid JSON-RPC message"),!0)}({httpMethod:o,...p7(t),...void 0!==n&&{body:n}}),body:n,parsedBody:s,forwardRequest:l}}let me=r("async_hooks"),mt=(t,r)=>{globalThis[t]=r},mr=t=>globalThis[t];function ma({name:t,fallback:r=!0}){let a=Symbol.for(`xmcp-context-${t}`),i=Symbol.for(`xmcp-context-${t}-fallback-store`);if(mr(a))return mr(a);let n=new me.AsyncLocalStorage,o=globalThis[i]??{current:null};mt(i,o);let s={provider:(t,a)=>(r&&(o.current=t),n.run(t,a)),getContext:()=>{let a=n.getStore();if(a)return a;if(r&&o.current)return o.current;throw Error(`getContext() can only be used within the ${t} context.`)},setContext:a=>{let i=n.getStore()??(r?o.current:null);if(!i)throw Error(`setContext() can only be used within the ${t} context.`);Object.assign(i,a)}};return mt(a,s),s}let mi=ma({name:"http-request-context"});mi.setContext;let mn=mi.getContext,mo=mi.provider,ms=t=>"object"==typeof t&&null!==t&&!Array.isArray(t),ml=t=>{if(!ms(t)||"string"!=typeof t.name||"string"!=typeof t.version)return;let r={name:t.name,version:t.version};return"string"==typeof t.title&&(r.title=t.title),"string"==typeof t.websiteUrl&&(r.websiteUrl=t.websiteUrl),"string"==typeof t.description&&(r.description=t.description),r},mc=t=>{if(t&&"initialize"===t.method&&ms(t.params))return ml(t.params.clientInfo)},mu=(t,r)=>{let a=r.toLowerCase();for(let[r,i]of Object.entries(t)){if(r.toLowerCase()!==a)continue;let t=Array.isArray(i)?i[0]:i;if("string"!=typeof t)break;let n=t.trim();return n.length>0?n:void 0}};function md(t){let{tags:r,enabled:a,...i}=t;return{...i,_meta:void 0===r?i._meta:{...i._meta,"xmcp/tags":r}}}let mp=new class{add(t,r){this.resources.set(t,r)}getAll(){return this.resources}clear(){this.resources.clear()}has(t){return this.resources.has(t)}constructor(){var t,r;t="resources",r=new Map,t in this?Object.defineProperty(this,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):this[t]=r}},mm=ma({name:"request-context",fallback:!1}),mh=ma({name:"client-info-context"});mh.setContext;let mf=mh.getContext;mh.provider;let mg=new Set(["message","mode","requestedSchema"]),my=new Set(["elicitationId","message","mode","url"]),mv=new Set(["properties","required","type"]),m_=new Set(["default","description","format","maxLength","minLength","title","type"]),mb=new Set(["default","description","enum","enumNames","title","type"]),mS=new Set(["default","description","title","type"]),m$=new Set(["default","description","maximum","minimum","title","type"]),mw=new Set(["date","date-time","email","uri"]);async function mR(t,r,a){let i=function(t){let r=t.mode??"form";if("url"===r)return function(t){let r;mx(t,"Elicitation request must be a plain object."),mk(t,my,"URL elicitation"),mP(t.message,"URL elicitation requires a string message."),mE(t.elicitationId,"URL elicitation requires a non-empty elicitationId."),mE(t.url,"URL elicitation requires a non-empty URL.");try{r=new URL(t.url)}catch{throw Error("URL elicitation requires a valid http or https URL.")}if("http:"!==r.protocol&&"https:"!==r.protocol)throw Error("URL elicitation requires a valid http or https URL.")}(t),t;if("form"!==r)throw Error(`Unsupported elicitation mode "${String(t.mode)}". Expected "form" or "url".`);return function(t){mx(t,"Elicitation request must be a plain object."),mk(t,mg,"Form elicitation"),mP(t.message,"Form elicitation requires a string message.");let r=t.requestedSchema;if(mx(r,"Form elicitation requires a flat object schema."),mk(r,mv,"Form elicitation schema"),"object"!==r.type)throw Error('Form elicitation schema must use type "object".');for(let[t,a]of(mx(r.properties,"Form elicitation schema requires a properties object."),Object.entries(r.properties)))!function(t,r){if(mx(r,`Form elicitation field "${t}" must be a plain object.`),mT(r.title,`Form elicitation field "${t}" title must be a string.`),mT(r.description,`Form elicitation field "${t}" description must be a string.`),"string"===r.type&&"enum"in r){var a,i;if(mk(r,mb,`Form elicitation field "${t}"`),mO(r.enum,`Form elicitation field "${t}" enum values must be strings.`),a=r.enumNames,i=`Form elicitation field "${t}" enumNames must be strings.`,void 0!==a&&mO(a,i),void 0!==r.enumNames&&r.enumNames.length!==r.enum.length)throw Error(`Form elicitation field "${t}" enumNames length must match enum length.`);if(mT(r.default,`Form elicitation field "${t}" default must be a string.`),void 0!==r.default&&!r.enum.includes(r.default))throw Error(`Form elicitation field "${t}" default must be one of its enum values.`);return}if("string"===r.type&&!("enum"in r)){mk(r,m_,`Form elicitation field "${t}"`),mj(r.minLength,`Form elicitation field "${t}" minLength must be a number.`),mj(r.maxLength,`Form elicitation field "${t}" maxLength must be a number.`),mT(r.default,`Form elicitation field "${t}" default must be a string.`);let a=r.format;if(mT(a,`Form elicitation field "${t}" format must be a string.`),void 0!==a&&!mw.has(a))throw Error(`Form elicitation field "${t}" format must be one of: ${Array.from(mw).join(", ")}.`);return}if("boolean"===r.type){if(mk(r,mS,`Form elicitation field "${t}"`),void 0!==r.default&&"boolean"!=typeof r.default)throw Error(`Form elicitation field "${t}" default must be a boolean.`);return}if("number"===r.type||"integer"===r.type){mk(r,m$,`Form elicitation field "${t}"`),mj(r.minimum,`Form elicitation field "${t}" minimum must be a number.`),mj(r.maximum,`Form elicitation field "${t}" maximum must be a number.`),mj(r.default,`Form elicitation field "${t}" default must be a number.`);return}throw Error(`Form elicitation field "${t}" uses unsupported type "${String(r.type)}". Supported types are string, boolean, number, integer, and string enums.`)}(t,a);if(void 0!==r.required){if(!Array.isArray(r.required)||r.required.some(t=>"string"!=typeof t))throw Error("Form elicitation schema required fields must be a string array.");for(let t of r.required)if(!(t in r.properties))throw Error(`Form elicitation schema required field "${t}" is not defined in properties.`)}}(t),{...t,mode:"form"}}(r);try{let r=await t.mcpReq.elicitInput(i,a);return{...r,content:r.content??void 0}}catch(t){if(t instanceof lJ&&t.code===lH.MethodNotSupportedByProtocolVersion)throw Error("extra.elicit() is not available on protocol revision 2026-07-28: server-initiated elicitation was replaced by multi round-trip requests. Return inputRequired({ ... }) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw t}}function mk(t,r,a){let i=Object.keys(t).filter(t=>!r.has(t));if(0!==i.length)throw Error(`${a} includes unsupported key(s): ${i.join(", ")}.`)}function mx(t,r){if("object"!=typeof t||null===t||Array.isArray(t))throw Error(r)}function mP(t,r){if("string"!=typeof t)throw Error(r)}function mE(t,r){if("string"!=typeof t||0===t.trim().length)throw Error(r)}function mT(t,r){if(void 0!==t&&"string"!=typeof t)throw Error(r)}function mj(t,r){if(void 0!==t&&"number"!=typeof t)throw Error(r)}function mO(t,r){if(!Array.isArray(t)||t.some(t=>"string"!=typeof t))throw Error(r)}let mC=new Set(["_meta","includeContext","maxTokens","messages","metadata","modelPreferences","stopSequences","systemPrompt","temperature"]),mI=new Set(["task","toolChoice","tools"]),mN=new Set(["text","image","audio"]);async function mq(t,r,a){let i=function(t){mA(t,"Sampling request must be a plain object.");let r=Object.keys(t),a=r.filter(t=>mI.has(t));if(a.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${a.join(", ")}.`);let i=r.filter(t=>!mC.has(t));if(i.length>0)throw Error(`Sampling request includes unsupported key(s): ${i.join(", ")}.`);if(!Array.isArray(t.messages)||0===t.messages.length)throw Error("Sampling requires at least one message.");for(let[r,a]of t.messages.entries())!function(t,r){if(mA(r,`Sampling message at index ${t} must be a plain object.`),"user"!==r.role&&"assistant"!==r.role)throw Error(`Sampling message at index ${t} requires role "user" or "assistant".`);let a=r.content;mA(a,`Sampling message at index ${t} requires a content object.`);let i=a.type;if("string"!=typeof i||!mN.has(i))throw Error(`Sampling message at index ${t} uses unsupported content type "${String(i)}". Supported types are text, image, and audio.`);if("text"===i&&"string"!=typeof a.text)throw Error(`Sampling message at index ${t} requires string text content.`);if(("image"===i||"audio"===i)&&("string"!=typeof a.data||"string"!=typeof a.mimeType))throw Error(`Sampling message at index ${t} requires base64 data and a mimeType.`)}(r,a);if("number"!=typeof t.maxTokens)throw Error("Sampling requires a numeric maxTokens.");return t}(r);try{return await t.mcpReq.requestSampling(i,a)}catch(t){if(t instanceof lJ&&t.code===lH.MethodNotSupportedByProtocolVersion)throw Error("extra.sample() is not available on protocol revision 2026-07-28: server-initiated sampling was replaced by multi round-trip requests. Return inputRequired({ ... }) with inputRequired.createMessage(...) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw t}}function mA(t,r){if("object"!=typeof t||null===t||Array.isArray(t))throw Error(r)}let mM={text:t=>"string"!=typeof t.text?{valid:!1,error:'Text content must have a "text" property of type string'}:{valid:!0},image:t=>"string"!=typeof t.data?{valid:!1,error:'Image content must have a "data" property of type string (base64-encoded image)'}:"string"!=typeof t.mimeType?{valid:!1,error:'Image content must have a "mimeType" property of type string'}:{valid:!0},audio:t=>"string"!=typeof t.data?{valid:!1,error:'Audio content must have a "data" property of type string (base64-encoded audio)'}:"string"!=typeof t.mimeType?{valid:!1,error:'Audio content must have a "mimeType" property of type string'}:{valid:!0},resource_link:t=>"string"!=typeof t.name?{valid:!1,error:'Resource link content must have a "name" property of type string'}:"string"!=typeof t.uri?{valid:!1,error:'Resource link content must have a "uri" property of type string'}:void 0!==t.title&&"string"!=typeof t.title?{valid:!1,error:'Resource link "title" property must be a string if provided'}:void 0!==t.description&&"string"!=typeof t.description?{valid:!1,error:'Resource link "description" property must be a string if provided'}:void 0!==t.mimeType&&"string"!=typeof t.mimeType?{valid:!1,error:'Resource link "mimeType" property must be a string if provided'}:{valid:!0}};function mz(t){if(!t||"object"!=typeof t)return{valid:!1,error:"Content must be an object"};if("string"!=typeof t.type)return{valid:!1,error:'Content must have a "type" property of type string'};if(void 0!==t._meta&&(null===t._meta||"object"!=typeof t._meta))return{valid:!1,error:'Content "_meta" property must be an object if provided'};let r=mM[t.type];return r?r(t):{valid:!0}}function mL(t,r,a,i){if(null===t||"object"!=typeof t||Array.isArray(t))throw Error(`Tool "${a}" ${i}: expected a plain object.`);let n=new Set(Object.keys(r)),o=Object.keys(t).filter(t=>!n.has(t));if(o.length>0)throw Error(`Tool "${a}" ${i}: unrecognized key(s): ${o.join(", ")}`);for(let[n,o]of Object.entries(r))try{o.parse(t[n])}catch(t){throw Error(`Tool "${a}" ${i}: ${t?.message??`invalid field "${n}"`}`)}}function mZ(t){return!!(t&&"object"==typeof t&&Object.keys(t).some(t=>t.startsWith("ui/")))}function mD(t){let r=t.mcpReq.envelope,a=ml(r?.[nB]);if(!a)try{let t,r=mn();a=r.clientInfo??(t=r.headers,ml({name:mu(t,"x-mcp-client-name"),version:mu(t,"x-mcp-client-version"),title:mu(t,"x-mcp-client-title"),websiteUrl:mu(t,"x-mcp-client-website-url"),description:mu(t,"x-mcp-client-description")}))}catch{}if(!a)try{a=mf().clientInfo}catch{}return a}function mV(t){let r=[...t];return(t,a,i)=>(function(t,r,a){let i,n=new Map;if(t.http){let t=mn(),r=Object.fromEntries(Object.entries(t.headers).map(([t,r])=>[t,Array.isArray(r)?Object.freeze([...r]):r]));i=Object.freeze({id:t.id,headers:Object.freeze(r)})}return mm.provider(Object.freeze({clientInfo:r?Object.freeze({...r}):void 0,http:i,authInfo:t.http?.authInfo,signal:t.mcpReq.signal,set(t,r){n.set(t,r)},get:t=>n.get(t),async progress(r,a){let i=t.mcpReq._meta?.progressToken;void 0!==i&&await t.mcpReq.notify({method:"notifications/progress",params:{progressToken:i,progress:r,...void 0===a?{}:{total:a}}})},log:(r,a)=>t.mcpReq.log(r,a)}),a)})(a,mD(a),async()=>{if(0===r.length)return i();let a=Object.freeze({...function(){try{return mm.getContext()}catch{throw Error("getRequestContext() can only be used while handling an MCP request.")}}(),...t,params:Object.freeze({...t.params})}),n=-1,o=async t=>{if(t<=n)throw Error("MCP middleware next() can only be called once");n=t;let s=r[t];return s?s(a,()=>o(t+1)):i()};return o(0)})}let mU=new Set(["tools/list","prompts/get","prompts/list","resources/read","resources/list","resources/templates/list","completion/complete"]);function mF(t){return t.endsWith(".tsx")}let mH=Symbol("Let zodToJsonSchema decide on which parser to use"),mJ={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",openAiAnyTypeName:"OpenAiAnyType"};(T=q||(q={})).assertEqual=t=>{},T.assertIs=function(t){},T.assertNever=function(t){throw Error()},T.arrayToEnum=t=>{let r={};for(let a of t)r[a]=a;return r},T.getValidEnumValues=t=>{let r=T.objectKeys(t).filter(r=>"number"!=typeof t[t[r]]),a={};for(let i of r)a[i]=t[i];return T.objectValues(a)},T.objectValues=t=>T.objectKeys(t).map(function(r){return t[r]}),T.objectKeys="function"==typeof Object.keys?t=>Object.keys(t):t=>{let r=[];for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&r.push(a);return r},T.find=(t,r)=>{for(let a of t)if(r(a))return a},T.isInteger="function"==typeof Number.isInteger?t=>Number.isInteger(t):t=>"number"==typeof t&&Number.isFinite(t)&&Math.floor(t)===t,T.joinValues=function(t,r=" | "){return t.map(t=>"string"==typeof t?`'${t}'`:t).join(r)},T.jsonStringifyReplacer=(t,r)=>"bigint"==typeof r?r.toString():r,(A||(A={})).mergeShapes=(t,r)=>({...t,...r});let mB=q.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),mK=t=>{switch(typeof t){case"undefined":return mB.undefined;case"string":return mB.string;case"number":return Number.isNaN(t)?mB.nan:mB.number;case"boolean":return mB.boolean;case"function":return mB.function;case"bigint":return mB.bigint;case"symbol":return mB.symbol;case"object":if(Array.isArray(t))return mB.array;if(null===t)return mB.null;if(t.then&&"function"==typeof t.then&&t.catch&&"function"==typeof t.catch)return mB.promise;if("undefined"!=typeof Map&&t instanceof Map)return mB.map;if("undefined"!=typeof Set&&t instanceof Set)return mB.set;if("undefined"!=typeof Date&&t instanceof Date)return mB.date;return mB.object;default:return mB.unknown}},mG=q.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 mW extends Error{get errors(){return this.issues}constructor(t){super(),this.issues=[],this.addIssue=t=>{this.issues=[...this.issues,t]},this.addIssues=(t=[])=>{this.issues=[...this.issues,...t]};let r=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,r):this.__proto__=r,this.name="ZodError",this.issues=t}format(t){let r=t||function(t){return t.message},a={_errors:[]},i=t=>{for(let n of t.issues)if("invalid_union"===n.code)n.unionErrors.map(i);else if("invalid_return_type"===n.code)i(n.returnTypeError);else if("invalid_arguments"===n.code)i(n.argumentsError);else if(0===n.path.length)a._errors.push(r(n));else{let t=a,i=0;for(;i<n.path.length;){let a=n.path[i],o=i===n.path.length-1;if("_errors"===a){o&&t._errors.push(r(n)),i++;continue}Object.prototype.hasOwnProperty.call(t,a)||("__proto__"===a?Object.defineProperty(t,a,{value:{_errors:[]},writable:!0,enumerable:!0,configurable:!0}):t[a]={_errors:[]}),t=t[a],o&&t._errors.push(r(n)),i++}}};return i(this),a}static assert(t){if(!(t instanceof mW))throw Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,q.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(t=t=>t.message){let r=Object.create(null),a=[];for(let i of this.issues)if(i.path.length>0){let a=i.path[0];r[a]=r[a]||[],r[a].push(t(i))}else a.push(t(i));return{formErrors:a,fieldErrors:r}}get formErrors(){return this.flatten()}}mW.create=t=>new mW(t);let mY=(t,r)=>{let a;switch(t.code){case mG.invalid_type:a=t.received===mB.undefined?"Required":`Expected ${t.expected}, received ${t.received}`;break;case mG.invalid_literal:a=`Invalid literal value, expected ${JSON.stringify(t.expected,q.jsonStringifyReplacer)}`;break;case mG.unrecognized_keys:a=`Unrecognized key(s) in object: ${q.joinValues(t.keys,", ")}`;break;case mG.invalid_union:a="Invalid input";break;case mG.invalid_union_discriminator:a=`Invalid discriminator value. Expected ${q.joinValues(t.options)}`;break;case mG.invalid_enum_value:a=`Invalid enum value. Expected ${q.joinValues(t.options)}, received '${t.received}'`;break;case mG.invalid_arguments:a="Invalid function arguments";break;case mG.invalid_return_type:a="Invalid function return type";break;case mG.invalid_date:a="Invalid date";break;case mG.invalid_string:"object"==typeof t.validation?"includes"in t.validation?(a=`Invalid input: must include "${t.validation.includes}"`,"number"==typeof t.validation.position&&(a=`${a} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?a=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?a=`Invalid input: must end with "${t.validation.endsWith}"`:q.assertNever(t.validation):a="regex"!==t.validation?`Invalid ${t.validation}`:"Invalid";break;case mG.too_small:a="array"===t.type?`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:"string"===t.type?`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:"number"===t.type||"bigint"===t.type?`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:"date"===t.type?`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:"Invalid input";break;case mG.too_big:a="array"===t.type?`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:"string"===t.type?`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:"number"===t.type?`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:"bigint"===t.type?`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:"date"===t.type?`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:"Invalid input";break;case mG.custom:a="Invalid input";break;case mG.invalid_intersection_types:a="Intersection results could not be merged";break;case mG.not_multiple_of:a=`Number must be a multiple of ${t.multipleOf}`;break;case mG.not_finite:a="Number must be finite";break;default:a=r.defaultError,q.assertNever(t)}return{message:a}};(j=M||(M={})).errToObj=t=>"string"==typeof t?{message:t}:t||{},j.toString=t=>"string"==typeof t?t:t?.message;let mX=t=>{let{data:r,path:a,errorMaps:i,issueData:n}=t,o=[...a,...n.path||[]],s={...n,path:o};if(void 0!==n.message)return{...n,path:o,message:n.message};let l="";for(let t of i.filter(t=>!!t).slice().reverse())l=t(s,{data:r,defaultError:l}).message;return{...n,path:o,message:l}};function mQ(t,r){let a=mX({issueData:r,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,mY,void 0].filter(t=>!!t)});t.common.issues.push(a)}class m0{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(t,r){let a=[];for(let i of r){if("aborted"===i.status)return m1;"dirty"===i.status&&t.dirty(),a.push(i.value)}return{status:t.value,value:a}}static async mergeObjectAsync(t,r){let a=[];for(let t of r){let r=await t.key,i=await t.value;a.push({key:r,value:i})}return m0.mergeObjectSync(t,a)}static mergeObjectSync(t,r){let a={};for(let i of r){let{key:r,value:n}=i;if("aborted"===r.status||"aborted"===n.status)return m1;"dirty"===r.status&&t.dirty(),"dirty"===n.status&&t.dirty(),"__proto__"!==r.value&&(void 0!==n.value||i.alwaysSet)&&(a[r.value]=n.value)}return{status:t.value,value:a}}}let m1=Object.freeze({status:"aborted"}),m2=t=>({status:"dirty",value:t}),m9=t=>({status:"valid",value:t}),m4=t=>"undefined"!=typeof Promise&&t instanceof Promise;class m3{constructor(t,r,a,i){this._cachedPath=[],this.parent=t,this.data=r,this._path=a,this._key=i}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}let m6=(t,r)=>{if("valid"===r.status)return{success:!0,data:r.value};if(!t.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let r=new mW(t.common.issues);return this._error=r,this._error}}};function m5(t){if(!t)return{};let{errorMap:r,invalid_type_error:a,required_error:i,description:n}=t;if(r&&(a||i))throw Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');return r?{errorMap:r,description:n}:{errorMap:(r,n)=>{let{message:o}=t;return"invalid_enum_value"===r.code?{message:o??n.defaultError}:void 0===n.data?{message:o??i??n.defaultError}:"invalid_type"!==r.code?{message:n.defaultError}:{message:o??a??n.defaultError}},description:n}}class m7{get description(){return this._def.description}_getType(t){return mK(t.data)}_getOrReturnCtx(t,r){return r||{common:t.parent.common,data:t.data,parsedType:mK(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new m0,ctx:{common:t.parent.common,data:t.data,parsedType:mK(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){let r=this._parse(t);if(m4(r))throw Error("Synchronous parse encountered promise.");return r}_parseAsync(t){return Promise.resolve(this._parse(t))}parse(t,r){let a=this.safeParse(t,r);if(a.success)return a.data;throw a.error}safeParse(t,r){let a={common:{issues:[],async:r?.async??!1,contextualErrorMap:r?.errorMap},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:mK(t)},i=this._parseSync({data:t,path:a.path,parent:a});return m6(a,i)}"~validate"(t){let r={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:mK(t)};if(!this["~standard"].async)try{let a=this._parseSync({data:t,path:[],parent:r});return"valid"===a.status?{value:a.value}:{issues:r.common.issues}}catch(t){t?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),r.common={issues:[],async:!0}}return this._parseAsync({data:t,path:[],parent:r}).then(t=>"valid"===t.status?{value:t.value}:{issues:r.common.issues})}async parseAsync(t,r){let a=await this.safeParseAsync(t,r);if(a.success)return a.data;throw a.error}async safeParseAsync(t,r){let a={common:{issues:[],contextualErrorMap:r?.errorMap,async:!0},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:mK(t)},i=this._parse({data:t,path:a.path,parent:a});return m6(a,await (m4(i)?i:Promise.resolve(i)))}refine(t,r){return this._refinement((a,i)=>{let n=t(a),o=()=>i.addIssue({code:mG.custom,..."string"==typeof r||void 0===r?{message:r}:"function"==typeof r?r(a):r});return"undefined"!=typeof Promise&&n instanceof Promise?n.then(t=>!!t||(o(),!1)):!!n||(o(),!1)})}refinement(t,r){return this._refinement((a,i)=>!!t(a)||(i.addIssue("function"==typeof r?r(a,i):r),!1))}_refinement(t){return new hH({schema:this,typeName:z.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}constructor(t){this.spa=this.safeParseAsync,this._def=t,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:t=>this["~validate"](t)}}optional(){return hJ.create(this,this._def)}nullable(){return hB.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return hE.create(this)}promise(){return hF.create(this,this._def)}or(t){return hj.create([this,t],this._def)}and(t){return hI.create(this,t,this._def)}transform(t){return new hH({...m5(this._def),schema:this,typeName:z.ZodEffects,effect:{type:"transform",transform:t}})}default(t){return new hK({...m5(this._def),innerType:this,defaultValue:"function"==typeof t?t:()=>t,typeName:z.ZodDefault})}brand(){return new hY({typeName:z.ZodBranded,type:this,...m5(this._def)})}catch(t){return new hG({...m5(this._def),innerType:this,catchValue:"function"==typeof t?t:()=>t,typeName:z.ZodCatch})}describe(t){return new this.constructor({...this._def,description:t})}pipe(t){return hX.create(this,t)}readonly(){return hQ.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}let m8=/^c[^\s-]{8,}$/i,he=/^[0-9a-z]+$/,ht=/^[0-9A-HJKMNP-TV-Z]{26}$/i,hr=/^[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,ha=/^[a-z0-9_-]{21}$/i,hi=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,hn=/^[-+]?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)?)??$/,ho=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,hs=/^(?:(?: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])$/,hl=/^(?:(?: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])$/,hc=/^(([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]))$/,hu=/^(([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])$/,hd=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,hp=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,hm="((\\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])))",hh=RegExp(`^${hm}$`);function hf(t){let r="[0-5]\\d";t.precision?r=`${r}\\.\\d{${t.precision}}`:null==t.precision&&(r=`${r}(\\.\\d+)?`);let a=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${r})${a}`}class hg extends m7{_parse(t){var r,a,i,n;let o;if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==mB.string){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.string,received:r.parsedType}),m1}let s=new m0;for(let l of this._def.checks)if("min"===l.kind)t.data.length<l.value&&(mQ(o=this._getOrReturnCtx(t,o),{code:mG.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),s.dirty());else if("max"===l.kind)t.data.length>l.value&&(mQ(o=this._getOrReturnCtx(t,o),{code:mG.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),s.dirty());else if("length"===l.kind){let r=t.data.length>l.value,a=t.data.length<l.value;(r||a)&&(o=this._getOrReturnCtx(t,o),r?mQ(o,{code:mG.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}):a&&mQ(o,{code:mG.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}),s.dirty())}else if("email"===l.kind)ho.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"email",code:mG.invalid_string,message:l.message}),s.dirty());else if("emoji"===l.kind)f||(f=RegExp("^[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$","u")),f.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"emoji",code:mG.invalid_string,message:l.message}),s.dirty());else if("uuid"===l.kind)hr.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"uuid",code:mG.invalid_string,message:l.message}),s.dirty());else if("nanoid"===l.kind)ha.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"nanoid",code:mG.invalid_string,message:l.message}),s.dirty());else if("cuid"===l.kind)m8.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"cuid",code:mG.invalid_string,message:l.message}),s.dirty());else if("cuid2"===l.kind)he.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"cuid2",code:mG.invalid_string,message:l.message}),s.dirty());else if("ulid"===l.kind)ht.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"ulid",code:mG.invalid_string,message:l.message}),s.dirty());else if("url"===l.kind)try{new URL(t.data)}catch{mQ(o=this._getOrReturnCtx(t,o),{validation:"url",code:mG.invalid_string,message:l.message}),s.dirty()}else"regex"===l.kind?(l.regex.lastIndex=0,l.regex.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"regex",code:mG.invalid_string,message:l.message}),s.dirty())):"trim"===l.kind?t.data=t.data.trim():"includes"===l.kind?t.data.includes(l.value,l.position)||(mQ(o=this._getOrReturnCtx(t,o),{code:mG.invalid_string,validation:{includes:l.value,position:l.position},message:l.message}),s.dirty()):"toLowerCase"===l.kind?t.data=t.data.toLowerCase():"toUpperCase"===l.kind?t.data=t.data.toUpperCase():"startsWith"===l.kind?t.data.startsWith(l.value)||(mQ(o=this._getOrReturnCtx(t,o),{code:mG.invalid_string,validation:{startsWith:l.value},message:l.message}),s.dirty()):"endsWith"===l.kind?t.data.endsWith(l.value)||(mQ(o=this._getOrReturnCtx(t,o),{code:mG.invalid_string,validation:{endsWith:l.value},message:l.message}),s.dirty()):"datetime"===l.kind?(function(t){let r=`${hm}T${hf(t)}`,a=[];return a.push(t.local?"Z?":"Z"),t.offset&&a.push("([+-]\\d{2}:?\\d{2})"),r=`${r}(${a.join("|")})`,RegExp(`^${r}$`)})(l).test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{code:mG.invalid_string,validation:"datetime",message:l.message}),s.dirty()):"date"===l.kind?hh.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{code:mG.invalid_string,validation:"date",message:l.message}),s.dirty()):"time"===l.kind?RegExp(`^${hf(l)}$`).test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{code:mG.invalid_string,validation:"time",message:l.message}),s.dirty()):"duration"===l.kind?hn.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"duration",code:mG.invalid_string,message:l.message}),s.dirty()):"ip"===l.kind?(r=t.data,!(("v4"===(a=l.version)||!a)&&hs.test(r)||("v6"===a||!a)&&hc.test(r))&&1&&(mQ(o=this._getOrReturnCtx(t,o),{validation:"ip",code:mG.invalid_string,message:l.message}),s.dirty())):"jwt"===l.kind?!function(t,r){if(!hi.test(t))return!1;try{let[a]=t.split(".");if(!a)return!1;let i=a.replace(/-/g,"+").replace(/_/g,"/").padEnd(a.length+(4-a.length%4)%4,"="),n=JSON.parse(atob(i));if("object"!=typeof n||null===n||"typ"in n&&n?.typ!=="JWT"||!n.alg||r&&n.alg!==r)return!1;return!0}catch{return!1}}(t.data,l.alg)&&(mQ(o=this._getOrReturnCtx(t,o),{validation:"jwt",code:mG.invalid_string,message:l.message}),s.dirty()):"cidr"===l.kind?(i=t.data,!(("v4"===(n=l.version)||!n)&&hl.test(i)||("v6"===n||!n)&&hu.test(i))&&1&&(mQ(o=this._getOrReturnCtx(t,o),{validation:"cidr",code:mG.invalid_string,message:l.message}),s.dirty())):"base64"===l.kind?hd.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"base64",code:mG.invalid_string,message:l.message}),s.dirty()):"base64url"===l.kind?hp.test(t.data)||(mQ(o=this._getOrReturnCtx(t,o),{validation:"base64url",code:mG.invalid_string,message:l.message}),s.dirty()):q.assertNever(l);return{status:s.value,value:t.data}}_regex(t,r,a){return this.refinement(r=>t.test(r),{validation:r,code:mG.invalid_string,...M.errToObj(a)})}_addCheck(t){return new hg({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...M.errToObj(t)})}url(t){return this._addCheck({kind:"url",...M.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...M.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...M.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...M.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...M.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...M.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...M.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...M.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...M.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...M.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...M.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...M.errToObj(t)})}datetime(t){return"string"==typeof t?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:t}):this._addCheck({kind:"datetime",precision:void 0===t?.precision?null:t?.precision,offset:t?.offset??!1,local:t?.local??!1,...M.errToObj(t?.message)})}date(t){return this._addCheck({kind:"date",message:t})}time(t){return"string"==typeof t?this._addCheck({kind:"time",precision:null,message:t}):this._addCheck({kind:"time",precision:void 0===t?.precision?null:t?.precision,...M.errToObj(t?.message)})}duration(t){return this._addCheck({kind:"duration",...M.errToObj(t)})}regex(t,r){return this._addCheck({kind:"regex",regex:t,...M.errToObj(r)})}includes(t,r){return this._addCheck({kind:"includes",value:t,position:r?.position,...M.errToObj(r?.message)})}startsWith(t,r){return this._addCheck({kind:"startsWith",value:t,...M.errToObj(r)})}endsWith(t,r){return this._addCheck({kind:"endsWith",value:t,...M.errToObj(r)})}min(t,r){return this._addCheck({kind:"min",value:t,...M.errToObj(r)})}max(t,r){return this._addCheck({kind:"max",value:t,...M.errToObj(r)})}length(t,r){return this._addCheck({kind:"length",value:t,...M.errToObj(r)})}nonempty(t){return this.min(1,M.errToObj(t))}trim(){return new hg({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new hg({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new hg({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(t=>"datetime"===t.kind)}get isDate(){return!!this._def.checks.find(t=>"date"===t.kind)}get isTime(){return!!this._def.checks.find(t=>"time"===t.kind)}get isDuration(){return!!this._def.checks.find(t=>"duration"===t.kind)}get isEmail(){return!!this._def.checks.find(t=>"email"===t.kind)}get isURL(){return!!this._def.checks.find(t=>"url"===t.kind)}get isEmoji(){return!!this._def.checks.find(t=>"emoji"===t.kind)}get isUUID(){return!!this._def.checks.find(t=>"uuid"===t.kind)}get isNANOID(){return!!this._def.checks.find(t=>"nanoid"===t.kind)}get isCUID(){return!!this._def.checks.find(t=>"cuid"===t.kind)}get isCUID2(){return!!this._def.checks.find(t=>"cuid2"===t.kind)}get isULID(){return!!this._def.checks.find(t=>"ulid"===t.kind)}get isIP(){return!!this._def.checks.find(t=>"ip"===t.kind)}get isCIDR(){return!!this._def.checks.find(t=>"cidr"===t.kind)}get isBase64(){return!!this._def.checks.find(t=>"base64"===t.kind)}get isBase64url(){return!!this._def.checks.find(t=>"base64url"===t.kind)}get minLength(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxLength(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}}hg.create=t=>new hg({checks:[],typeName:z.ZodString,coerce:t?.coerce??!1,...m5(t)});class hy extends m7{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){let r;if(this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==mB.number){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.number,received:r.parsedType}),m1}let a=new m0;for(let i of this._def.checks)"int"===i.kind?q.isInteger(t.data)||(mQ(r=this._getOrReturnCtx(t,r),{code:mG.invalid_type,expected:"integer",received:"float",message:i.message}),a.dirty()):"min"===i.kind?(i.inclusive?t.data<i.value:t.data<=i.value)&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),a.dirty()):"max"===i.kind?(i.inclusive?t.data>i.value:t.data>=i.value)&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),a.dirty()):"multipleOf"===i.kind?0!==function(t,r){let a=(t.toString().split(".")[1]||"").length,i=(r.toString().split(".")[1]||"").length,n=a>i?a:i;return Number.parseInt(t.toFixed(n).replace(".",""))%Number.parseInt(r.toFixed(n).replace(".",""))/10**n}(t.data,i.value)&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.not_multiple_of,multipleOf:i.value,message:i.message}),a.dirty()):"finite"===i.kind?Number.isFinite(t.data)||(mQ(r=this._getOrReturnCtx(t,r),{code:mG.not_finite,message:i.message}),a.dirty()):q.assertNever(i);return{status:a.value,value:t.data}}gte(t,r){return this.setLimit("min",t,!0,M.toString(r))}gt(t,r){return this.setLimit("min",t,!1,M.toString(r))}lte(t,r){return this.setLimit("max",t,!0,M.toString(r))}lt(t,r){return this.setLimit("max",t,!1,M.toString(r))}setLimit(t,r,a,i){return new hy({...this._def,checks:[...this._def.checks,{kind:t,value:r,inclusive:a,message:M.toString(i)}]})}_addCheck(t){return new hy({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:M.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:M.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:M.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:M.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:M.toString(t)})}multipleOf(t,r){return this._addCheck({kind:"multipleOf",value:t,message:M.toString(r)})}finite(t){return this._addCheck({kind:"finite",message:M.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:M.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:M.toString(t)})}get minValue(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxValue(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}get isInt(){return!!this._def.checks.find(t=>"int"===t.kind||"multipleOf"===t.kind&&q.isInteger(t.value))}get isFinite(){let t=null,r=null;for(let a of this._def.checks)if("finite"===a.kind||"int"===a.kind||"multipleOf"===a.kind)return!0;else"min"===a.kind?(null===r||a.value>r)&&(r=a.value):"max"===a.kind&&(null===t||a.value<t)&&(t=a.value);return Number.isFinite(r)&&Number.isFinite(t)}}hy.create=t=>new hy({checks:[],typeName:z.ZodNumber,coerce:t?.coerce||!1,...m5(t)});class hv extends m7{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){let r;if(this._def.coerce)try{t.data=BigInt(t.data)}catch{return this._getInvalidInput(t)}if(this._getType(t)!==mB.bigint)return this._getInvalidInput(t);let a=new m0;for(let i of this._def.checks)"min"===i.kind?(i.inclusive?t.data<i.value:t.data<=i.value)&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),a.dirty()):"max"===i.kind?(i.inclusive?t.data>i.value:t.data>=i.value)&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),a.dirty()):"multipleOf"===i.kind?t.data%i.value!==BigInt(0)&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.not_multiple_of,multipleOf:i.value,message:i.message}),a.dirty()):q.assertNever(i);return{status:a.value,value:t.data}}_getInvalidInput(t){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.bigint,received:r.parsedType}),m1}gte(t,r){return this.setLimit("min",t,!0,M.toString(r))}gt(t,r){return this.setLimit("min",t,!1,M.toString(r))}lte(t,r){return this.setLimit("max",t,!0,M.toString(r))}lt(t,r){return this.setLimit("max",t,!1,M.toString(r))}setLimit(t,r,a,i){return new hv({...this._def,checks:[...this._def.checks,{kind:t,value:r,inclusive:a,message:M.toString(i)}]})}_addCheck(t){return new hv({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:M.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:M.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:M.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:M.toString(t)})}multipleOf(t,r){return this._addCheck({kind:"multipleOf",value:t,message:M.toString(r)})}get minValue(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxValue(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}}hv.create=t=>new hv({checks:[],typeName:z.ZodBigInt,coerce:t?.coerce??!1,...m5(t)});class h_ extends m7{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==mB.boolean){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.boolean,received:r.parsedType}),m1}return m9(t.data)}}h_.create=t=>new h_({typeName:z.ZodBoolean,coerce:t?.coerce||!1,...m5(t)});class hb extends m7{_parse(t){let r;if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==mB.date){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.date,received:r.parsedType}),m1}if(Number.isNaN(t.data.getTime()))return mQ(this._getOrReturnCtx(t),{code:mG.invalid_date}),m1;let a=new m0;for(let i of this._def.checks)"min"===i.kind?t.data.getTime()<i.value&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),a.dirty()):"max"===i.kind?t.data.getTime()>i.value&&(mQ(r=this._getOrReturnCtx(t,r),{code:mG.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),a.dirty()):q.assertNever(i);return{status:a.value,value:new Date(t.data.getTime())}}_addCheck(t){return new hb({...this._def,checks:[...this._def.checks,t]})}min(t,r){return this._addCheck({kind:"min",value:t.getTime(),message:M.toString(r)})}max(t,r){return this._addCheck({kind:"max",value:t.getTime(),message:M.toString(r)})}get minDate(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return null!=t?new Date(t):null}get maxDate(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return null!=t?new Date(t):null}}hb.create=t=>new hb({checks:[],coerce:t?.coerce||!1,typeName:z.ZodDate,...m5(t)});class hS extends m7{_parse(t){if(this._getType(t)!==mB.symbol){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.symbol,received:r.parsedType}),m1}return m9(t.data)}}hS.create=t=>new hS({typeName:z.ZodSymbol,...m5(t)});class h$ extends m7{_parse(t){if(this._getType(t)!==mB.undefined){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.undefined,received:r.parsedType}),m1}return m9(t.data)}}h$.create=t=>new h$({typeName:z.ZodUndefined,...m5(t)});class hw extends m7{_parse(t){if(this._getType(t)!==mB.null){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.null,received:r.parsedType}),m1}return m9(t.data)}}hw.create=t=>new hw({typeName:z.ZodNull,...m5(t)});class hR extends m7{constructor(){super(...arguments),this._any=!0}_parse(t){return m9(t.data)}}hR.create=t=>new hR({typeName:z.ZodAny,...m5(t)});class hk extends m7{constructor(){super(...arguments),this._unknown=!0}_parse(t){return m9(t.data)}}hk.create=t=>new hk({typeName:z.ZodUnknown,...m5(t)});class hx extends m7{_parse(t){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.never,received:r.parsedType}),m1}}hx.create=t=>new hx({typeName:z.ZodNever,...m5(t)});class hP extends m7{_parse(t){if(this._getType(t)!==mB.undefined){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.void,received:r.parsedType}),m1}return m9(t.data)}}hP.create=t=>new hP({typeName:z.ZodVoid,...m5(t)});class hE extends m7{_parse(t){let{ctx:r,status:a}=this._processInputParams(t),i=this._def;if(r.parsedType!==mB.array)return mQ(r,{code:mG.invalid_type,expected:mB.array,received:r.parsedType}),m1;if(null!==i.exactLength){let t=r.data.length>i.exactLength.value,n=r.data.length<i.exactLength.value;(t||n)&&(mQ(r,{code:t?mG.too_big:mG.too_small,minimum:n?i.exactLength.value:void 0,maximum:t?i.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:i.exactLength.message}),a.dirty())}if(null!==i.minLength&&r.data.length<i.minLength.value&&(mQ(r,{code:mG.too_small,minimum:i.minLength.value,type:"array",inclusive:!0,exact:!1,message:i.minLength.message}),a.dirty()),null!==i.maxLength&&r.data.length>i.maxLength.value&&(mQ(r,{code:mG.too_big,maximum:i.maxLength.value,type:"array",inclusive:!0,exact:!1,message:i.maxLength.message}),a.dirty()),r.common.async)return Promise.all([...r.data].map((t,a)=>i.type._parseAsync(new m3(r,t,r.path,a)))).then(t=>m0.mergeArray(a,t));let n=[...r.data].map((t,a)=>i.type._parseSync(new m3(r,t,r.path,a)));return m0.mergeArray(a,n)}get element(){return this._def.type}min(t,r){return new hE({...this._def,minLength:{value:t,message:M.toString(r)}})}max(t,r){return new hE({...this._def,maxLength:{value:t,message:M.toString(r)}})}length(t,r){return new hE({...this._def,exactLength:{value:t,message:M.toString(r)}})}nonempty(t){return this.min(1,t)}}hE.create=(t,r)=>new hE({type:t,minLength:null,maxLength:null,exactLength:null,typeName:z.ZodArray,...m5(r)});class hT extends m7{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;let t=this._def.shape(),r=q.objectKeys(t);return this._cached={shape:t,keys:r},this._cached}_parse(t){if(this._getType(t)!==mB.object){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.object,received:r.parsedType}),m1}let{status:r,ctx:a}=this._processInputParams(t),{shape:i,keys:n}=this._getCached(),o=[];if(!(this._def.catchall instanceof hx&&"strip"===this._def.unknownKeys))for(let t in a.data)n.includes(t)||o.push(t);let s=[];for(let t of n){let r=i[t],n=a.data[t];s.push({key:{status:"valid",value:t},value:r._parse(new m3(a,n,a.path,t)),alwaysSet:t in a.data})}if(this._def.catchall instanceof hx){let t=this._def.unknownKeys;if("passthrough"===t)for(let t of o)s.push({key:{status:"valid",value:t},value:{status:"valid",value:a.data[t]}});else if("strict"===t)o.length>0&&(mQ(a,{code:mG.unrecognized_keys,keys:o}),r.dirty());else if("strip"===t);else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let t=this._def.catchall;for(let r of o){let i=a.data[r];s.push({key:{status:"valid",value:r},value:t._parse(new m3(a,i,a.path,r)),alwaysSet:r in a.data})}}return a.common.async?Promise.resolve().then(async()=>{let t=[];for(let r of s){let a=await r.key,i=await r.value;t.push({key:a,value:i,alwaysSet:r.alwaysSet})}return t}).then(t=>m0.mergeObjectSync(r,t)):m0.mergeObjectSync(r,s)}get shape(){return this._def.shape()}strict(t){return M.errToObj,new hT({...this._def,unknownKeys:"strict",...void 0!==t?{errorMap:(r,a)=>{let i=this._def.errorMap?.(r,a).message??a.defaultError;return"unrecognized_keys"===r.code?{message:M.errToObj(t).message??i}:{message:i}}}:{}})}strip(){return new hT({...this._def,unknownKeys:"strip"})}passthrough(){return new hT({...this._def,unknownKeys:"passthrough"})}extend(t){return new hT({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new hT({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:z.ZodObject})}setKey(t,r){return this.augment({[t]:r})}catchall(t){return new hT({...this._def,catchall:t})}pick(t){let r={};for(let a of q.objectKeys(t))t[a]&&this.shape[a]&&(r[a]=this.shape[a]);return new hT({...this._def,shape:()=>r})}omit(t){let r={};for(let a of q.objectKeys(this.shape))t[a]||(r[a]=this.shape[a]);return new hT({...this._def,shape:()=>r})}deepPartial(){return function t(r){if(r instanceof hT){let a={};for(let i in r.shape){let n=r.shape[i];a[i]=hJ.create(t(n))}return new hT({...r._def,shape:()=>a})}if(r instanceof hE)return new hE({...r._def,type:t(r.element)});if(r instanceof hJ)return hJ.create(t(r.unwrap()));if(r instanceof hB)return hB.create(t(r.unwrap()));if(r instanceof hN)return hN.create(r.items.map(r=>t(r)));else return r}(this)}partial(t){let r={};for(let a of q.objectKeys(this.shape)){let i=this.shape[a];t&&!t[a]?r[a]=i:r[a]=i.optional()}return new hT({...this._def,shape:()=>r})}required(t){let r={};for(let a of q.objectKeys(this.shape))if(t&&!t[a])r[a]=this.shape[a];else{let t=this.shape[a];for(;t instanceof hJ;)t=t._def.innerType;r[a]=t}return new hT({...this._def,shape:()=>r})}keyof(){return hD(q.objectKeys(this.shape))}}hT.create=(t,r)=>new hT({shape:()=>t,unknownKeys:"strip",catchall:hx.create(),typeName:z.ZodObject,...m5(r)}),hT.strictCreate=(t,r)=>new hT({shape:()=>t,unknownKeys:"strict",catchall:hx.create(),typeName:z.ZodObject,...m5(r)}),hT.lazycreate=(t,r)=>new hT({shape:t,unknownKeys:"strip",catchall:hx.create(),typeName:z.ZodObject,...m5(r)});class hj extends m7{_parse(t){let{ctx:r}=this._processInputParams(t),a=this._def.options;if(r.common.async)return Promise.all(a.map(async t=>{let a={...r,common:{...r.common,issues:[]},parent:null};return{result:await t._parseAsync({data:r.data,path:r.path,parent:a}),ctx:a}})).then(function(t){for(let r of t)if("valid"===r.result.status)return r.result;for(let a of t)if("dirty"===a.result.status)return r.common.issues.push(...a.ctx.common.issues),a.result;let a=t.map(t=>new mW(t.ctx.common.issues));return mQ(r,{code:mG.invalid_union,unionErrors:a}),m1});{let t,i=[];for(let n of a){let a={...r,common:{...r.common,issues:[]},parent:null},o=n._parseSync({data:r.data,path:r.path,parent:a});if("valid"===o.status)return o;"dirty"!==o.status||t||(t={result:o,ctx:a}),a.common.issues.length&&i.push(a.common.issues)}if(t)return r.common.issues.push(...t.ctx.common.issues),t.result;let n=i.map(t=>new mW(t));return mQ(r,{code:mG.invalid_union,unionErrors:n}),m1}}get options(){return this._def.options}}hj.create=(t,r)=>new hj({options:t,typeName:z.ZodUnion,...m5(r)});let hO=t=>{if(t instanceof hL)return hO(t.schema);if(t instanceof hH)return hO(t.innerType());if(t instanceof hZ)return[t.value];if(t instanceof hV)return t.options;if(t instanceof hU)return q.objectValues(t.enum);else if(t instanceof hK)return hO(t._def.innerType);else if(t instanceof h$)return[void 0];else if(t instanceof hw)return[null];else if(t instanceof hJ)return[void 0,...hO(t.unwrap())];else if(t instanceof hB)return[null,...hO(t.unwrap())];else if(t instanceof hY)return hO(t.unwrap());else if(t instanceof hQ)return hO(t.unwrap());else if(t instanceof hG)return hO(t._def.innerType);else return[]};class hC extends m7{_parse(t){let{ctx:r}=this._processInputParams(t);if(r.parsedType!==mB.object)return mQ(r,{code:mG.invalid_type,expected:mB.object,received:r.parsedType}),m1;let a=this.discriminator,i=r.data[a],n=this.optionsMap.get(i);return n?r.common.async?n._parseAsync({data:r.data,path:r.path,parent:r}):n._parseSync({data:r.data,path:r.path,parent:r}):(mQ(r,{code:mG.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[a]}),m1)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,r,a){let i=new Map;for(let a of r){let r=hO(a.shape[t]);if(!r.length)throw Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(let n of r){if(i.has(n))throw Error(`Discriminator property ${String(t)} has duplicate value ${String(n)}`);i.set(n,a)}}return new hC({typeName:z.ZodDiscriminatedUnion,discriminator:t,options:r,optionsMap:i,...m5(a)})}}class hI extends m7{_parse(t){let{status:r,ctx:a}=this._processInputParams(t),i=(t,i)=>{if("aborted"===t.status||"aborted"===i.status)return m1;let n=function t(r,a){let i=mK(r),n=mK(a);if(r===a)return{valid:!0,data:r};if(i===mB.object&&n===mB.object){let i=q.objectKeys(a),n=q.objectKeys(r).filter(t=>-1!==i.indexOf(t)),o={...r,...a};for(let i of(Object.prototype.hasOwnProperty.call(o,"__proto__")&&delete o.__proto__,n)){if("__proto__"===i)continue;let n=t(r[i],a[i]);if(!n.valid)return{valid:!1};o[i]=n.data}return{valid:!0,data:o}}if(i===mB.array&&n===mB.array){if(r.length!==a.length)return{valid:!1};let i=[];for(let n=0;n<r.length;n++){let o=t(r[n],a[n]);if(!o.valid)return{valid:!1};i.push(o.data)}return{valid:!0,data:i}}if(i===mB.date&&n===mB.date&&+r==+a)return{valid:!0,data:r};return{valid:!1}}(t.value,i.value);return n.valid?(("dirty"===t.status||"dirty"===i.status)&&r.dirty(),{status:r.value,value:n.data}):(mQ(a,{code:mG.invalid_intersection_types}),m1)};return a.common.async?Promise.all([this._def.left._parseAsync({data:a.data,path:a.path,parent:a}),this._def.right._parseAsync({data:a.data,path:a.path,parent:a})]).then(([t,r])=>i(t,r)):i(this._def.left._parseSync({data:a.data,path:a.path,parent:a}),this._def.right._parseSync({data:a.data,path:a.path,parent:a}))}}hI.create=(t,r,a)=>new hI({left:t,right:r,typeName:z.ZodIntersection,...m5(a)});class hN extends m7{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==mB.array)return mQ(a,{code:mG.invalid_type,expected:mB.array,received:a.parsedType}),m1;if(a.data.length<this._def.items.length)return mQ(a,{code:mG.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),m1;!this._def.rest&&a.data.length>this._def.items.length&&(mQ(a,{code:mG.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),r.dirty());let i=[...a.data].map((t,r)=>{let i=this._def.items[r]||this._def.rest;return i?i._parse(new m3(a,t,a.path,r)):null}).filter(t=>!!t);return a.common.async?Promise.all(i).then(t=>m0.mergeArray(r,t)):m0.mergeArray(r,i)}get items(){return this._def.items}rest(t){return new hN({...this._def,rest:t})}}hN.create=(t,r)=>{if(!Array.isArray(t))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new hN({items:t,typeName:z.ZodTuple,rest:null,...m5(r)})};class hq extends m7{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==mB.object)return mQ(a,{code:mG.invalid_type,expected:mB.object,received:a.parsedType}),m1;let i=[],n=this._def.keyType,o=this._def.valueType;for(let t in a.data)i.push({key:n._parse(new m3(a,t,a.path,t)),value:o._parse(new m3(a,a.data[t],a.path,t)),alwaysSet:t in a.data});return a.common.async?m0.mergeObjectAsync(r,i):m0.mergeObjectSync(r,i)}get element(){return this._def.valueType}static create(t,r,a){return new hq(r instanceof m7?{keyType:t,valueType:r,typeName:z.ZodRecord,...m5(a)}:{keyType:hg.create(),valueType:t,typeName:z.ZodRecord,...m5(r)})}}class hA extends m7{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==mB.map)return mQ(a,{code:mG.invalid_type,expected:mB.map,received:a.parsedType}),m1;let i=this._def.keyType,n=this._def.valueType,o=[...a.data.entries()].map(([t,r],o)=>({key:i._parse(new m3(a,t,a.path,[o,"key"])),value:n._parse(new m3(a,r,a.path,[o,"value"]))}));if(a.common.async){let t=new Map;return Promise.resolve().then(async()=>{for(let a of o){let i=await a.key,n=await a.value;if("aborted"===i.status||"aborted"===n.status)return m1;("dirty"===i.status||"dirty"===n.status)&&r.dirty(),t.set(i.value,n.value)}return{status:r.value,value:t}})}{let t=new Map;for(let a of o){let i=a.key,n=a.value;if("aborted"===i.status||"aborted"===n.status)return m1;("dirty"===i.status||"dirty"===n.status)&&r.dirty(),t.set(i.value,n.value)}return{status:r.value,value:t}}}}hA.create=(t,r,a)=>new hA({valueType:r,keyType:t,typeName:z.ZodMap,...m5(a)});class hM extends m7{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==mB.set)return mQ(a,{code:mG.invalid_type,expected:mB.set,received:a.parsedType}),m1;let i=this._def;null!==i.minSize&&a.data.size<i.minSize.value&&(mQ(a,{code:mG.too_small,minimum:i.minSize.value,type:"set",inclusive:!0,exact:!1,message:i.minSize.message}),r.dirty()),null!==i.maxSize&&a.data.size>i.maxSize.value&&(mQ(a,{code:mG.too_big,maximum:i.maxSize.value,type:"set",inclusive:!0,exact:!1,message:i.maxSize.message}),r.dirty());let n=this._def.valueType;function o(t){let a=new Set;for(let i of t){if("aborted"===i.status)return m1;"dirty"===i.status&&r.dirty(),a.add(i.value)}return{status:r.value,value:a}}let s=[...a.data.values()].map((t,r)=>n._parse(new m3(a,t,a.path,r)));return a.common.async?Promise.all(s).then(t=>o(t)):o(s)}min(t,r){return new hM({...this._def,minSize:{value:t,message:M.toString(r)}})}max(t,r){return new hM({...this._def,maxSize:{value:t,message:M.toString(r)}})}size(t,r){return this.min(t,r).max(t,r)}nonempty(t){return this.min(1,t)}}hM.create=(t,r)=>new hM({valueType:t,minSize:null,maxSize:null,typeName:z.ZodSet,...m5(r)});class hz extends m7{constructor(){super(...arguments),this.validate=this.implement}_parse(t){let{ctx:r}=this._processInputParams(t);if(r.parsedType!==mB.function)return mQ(r,{code:mG.invalid_type,expected:mB.function,received:r.parsedType}),m1;function a(t,a){return mX({data:t,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,mY,mY].filter(t=>!!t),issueData:{code:mG.invalid_arguments,argumentsError:a}})}function i(t,a){return mX({data:t,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,mY,mY].filter(t=>!!t),issueData:{code:mG.invalid_return_type,returnTypeError:a}})}let n={errorMap:r.common.contextualErrorMap},o=r.data;if(this._def.returns instanceof hF){let t=this;return m9(async function(...r){let s=new mW([]),l=await t._def.args.parseAsync(r,n).catch(t=>{throw s.addIssue(a(r,t)),s}),c=await Reflect.apply(o,this,l);return await t._def.returns._def.type.parseAsync(c,n).catch(t=>{throw s.addIssue(i(c,t)),s})})}{let t=this;return m9(function(...r){let s=t._def.args.safeParse(r,n);if(!s.success)throw new mW([a(r,s.error)]);let l=Reflect.apply(o,this,s.data),c=t._def.returns.safeParse(l,n);if(!c.success)throw new mW([i(l,c.error)]);return c.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new hz({...this._def,args:hN.create(t).rest(hk.create())})}returns(t){return new hz({...this._def,returns:t})}implement(t){return this.parse(t)}strictImplement(t){return this.parse(t)}static create(t,r,a){return new hz({args:t||hN.create([]).rest(hk.create()),returns:r||hk.create(),typeName:z.ZodFunction,...m5(a)})}}class hL extends m7{get schema(){return this._def.getter()}_parse(t){let{ctx:r}=this._processInputParams(t);return this._def.getter()._parse({data:r.data,path:r.path,parent:r})}}hL.create=(t,r)=>new hL({getter:t,typeName:z.ZodLazy,...m5(r)});class hZ extends m7{_parse(t){if(t.data!==this._def.value){let r=this._getOrReturnCtx(t);return mQ(r,{received:r.data,code:mG.invalid_literal,expected:this._def.value}),m1}return{status:"valid",value:t.data}}get value(){return this._def.value}}function hD(t,r){return new hV({values:t,typeName:z.ZodEnum,...m5(r)})}hZ.create=(t,r)=>new hZ({value:t,typeName:z.ZodLiteral,...m5(r)});class hV extends m7{_parse(t){if("string"!=typeof t.data){let r=this._getOrReturnCtx(t),a=this._def.values;return mQ(r,{expected:q.joinValues(a),received:r.parsedType,code:mG.invalid_type}),m1}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(t.data)){let r=this._getOrReturnCtx(t),a=this._def.values;return mQ(r,{received:r.data,code:mG.invalid_enum_value,options:a}),m1}return m9(t.data)}get options(){return this._def.values}get enum(){let t={};for(let r of this._def.values)t[r]=r;return t}get Values(){let t={};for(let r of this._def.values)t[r]=r;return t}get Enum(){let t={};for(let r of this._def.values)t[r]=r;return t}extract(t,r=this._def){return hV.create(t,{...this._def,...r})}exclude(t,r=this._def){return hV.create(this.options.filter(r=>!t.includes(r)),{...this._def,...r})}}hV.create=hD;class hU extends m7{_parse(t){let r=q.getValidEnumValues(this._def.values),a=this._getOrReturnCtx(t);if(a.parsedType!==mB.string&&a.parsedType!==mB.number){let t=q.objectValues(r);return mQ(a,{expected:q.joinValues(t),received:a.parsedType,code:mG.invalid_type}),m1}if(this._cache||(this._cache=new Set(q.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){let t=q.objectValues(r);return mQ(a,{received:a.data,code:mG.invalid_enum_value,options:t}),m1}return m9(t.data)}get enum(){return this._def.values}}hU.create=(t,r)=>new hU({values:t,typeName:z.ZodNativeEnum,...m5(r)});class hF extends m7{unwrap(){return this._def.type}_parse(t){let{ctx:r}=this._processInputParams(t);return r.parsedType!==mB.promise&&!1===r.common.async?(mQ(r,{code:mG.invalid_type,expected:mB.promise,received:r.parsedType}),m1):m9((r.parsedType===mB.promise?r.data:Promise.resolve(r.data)).then(t=>this._def.type.parseAsync(t,{path:r.path,errorMap:r.common.contextualErrorMap})))}}hF.create=(t,r)=>new hF({type:t,typeName:z.ZodPromise,...m5(r)});class hH extends m7{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===z.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){let{status:r,ctx:a}=this._processInputParams(t),i=this._def.effect||null,n={addIssue:t=>{mQ(a,t),t.fatal?r.abort():r.dirty()},get path(){return a.path}};if(n.addIssue=n.addIssue.bind(n),"preprocess"===i.type){let t=i.transform(a.data,n);if(a.common.async)return Promise.resolve(t).then(async t=>{if("aborted"===r.value)return m1;let i=await this._def.schema._parseAsync({data:t,path:a.path,parent:a});return"aborted"===i.status?m1:"dirty"===i.status||"dirty"===r.value?m2(i.value):i});{if("aborted"===r.value)return m1;let i=this._def.schema._parseSync({data:t,path:a.path,parent:a});return"aborted"===i.status?m1:"dirty"===i.status||"dirty"===r.value?m2(i.value):i}}if("refinement"===i.type){let t=t=>{let r=i.refinement(t,n);if(a.common.async)return Promise.resolve(r);if(r instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return t};if(!1!==a.common.async)return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then(a=>"aborted"===a.status?m1:("dirty"===a.status&&r.dirty(),t(a.value).then(()=>({status:r.value,value:a.value}))));{let i=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});return"aborted"===i.status?m1:("dirty"===i.status&&r.dirty(),t(i.value),{status:r.value,value:i.value})}}if("transform"===i.type)if(!1!==a.common.async)return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then(t=>"valid"!==t.status?m1:Promise.resolve(i.transform(t.value,n)).then(t=>({status:r.value,value:t})));else{let t=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});if("valid"!==t.status)return m1;let o=i.transform(t.value,n);if(o instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:o}}q.assertNever(i)}}hH.create=(t,r,a)=>new hH({schema:t,typeName:z.ZodEffects,effect:r,...m5(a)}),hH.createWithPreprocess=(t,r,a)=>new hH({schema:r,effect:{type:"preprocess",transform:t},typeName:z.ZodEffects,...m5(a)});class hJ extends m7{_parse(t){return this._getType(t)===mB.undefined?m9(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}hJ.create=(t,r)=>new hJ({innerType:t,typeName:z.ZodOptional,...m5(r)});class hB extends m7{_parse(t){return this._getType(t)===mB.null?m9(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}hB.create=(t,r)=>new hB({innerType:t,typeName:z.ZodNullable,...m5(r)});class hK extends m7{_parse(t){let{ctx:r}=this._processInputParams(t),a=r.data;return r.parsedType===mB.undefined&&(a=this._def.defaultValue()),this._def.innerType._parse({data:a,path:r.path,parent:r})}removeDefault(){return this._def.innerType}}hK.create=(t,r)=>new hK({innerType:t,typeName:z.ZodDefault,defaultValue:"function"==typeof r.default?r.default:()=>r.default,...m5(r)});class hG extends m7{_parse(t){let{ctx:r}=this._processInputParams(t),a={...r,common:{...r.common,issues:[]}},i=this._def.innerType._parse({data:a.data,path:a.path,parent:{...a}});return m4(i)?i.then(t=>({status:"valid",value:"valid"===t.status?t.value:this._def.catchValue({get error(){return new mW(a.common.issues)},input:a.data})})):{status:"valid",value:"valid"===i.status?i.value:this._def.catchValue({get error(){return new mW(a.common.issues)},input:a.data})}}removeCatch(){return this._def.innerType}}hG.create=(t,r)=>new hG({innerType:t,typeName:z.ZodCatch,catchValue:"function"==typeof r.catch?r.catch:()=>r.catch,...m5(r)});class hW extends m7{_parse(t){if(this._getType(t)!==mB.nan){let r=this._getOrReturnCtx(t);return mQ(r,{code:mG.invalid_type,expected:mB.nan,received:r.parsedType}),m1}return{status:"valid",value:t.data}}}hW.create=t=>new hW({typeName:z.ZodNaN,...m5(t)}),Symbol("zod_brand");class hY extends m7{_parse(t){let{ctx:r}=this._processInputParams(t),a=r.data;return this._def.type._parse({data:a,path:r.path,parent:r})}unwrap(){return this._def.type}}class hX extends m7{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.common.async)return(async()=>{let t=await this._def.in._parseAsync({data:a.data,path:a.path,parent:a});return"aborted"===t.status?m1:"dirty"===t.status?(r.dirty(),m2(t.value)):this._def.out._parseAsync({data:t.value,path:a.path,parent:a})})();{let t=this._def.in._parseSync({data:a.data,path:a.path,parent:a});return"aborted"===t.status?m1:"dirty"===t.status?(r.dirty(),{status:"dirty",value:t.value}):this._def.out._parseSync({data:t.value,path:a.path,parent:a})}}static create(t,r){return new hX({in:t,out:r,typeName:z.ZodPipeline})}}class hQ extends m7{_parse(t){let r=this._def.innerType._parse(t),a=t=>("valid"===t.status&&(t.value=Object.freeze(t.value)),t);return m4(r)?r.then(t=>a(t)):a(r)}unwrap(){return this._def.innerType}}hQ.create=(t,r)=>new hQ({innerType:t,typeName:z.ZodReadonly,...m5(r)}),hT.lazycreate,(O=z||(z={})).ZodString="ZodString",O.ZodNumber="ZodNumber",O.ZodNaN="ZodNaN",O.ZodBigInt="ZodBigInt",O.ZodBoolean="ZodBoolean",O.ZodDate="ZodDate",O.ZodSymbol="ZodSymbol",O.ZodUndefined="ZodUndefined",O.ZodNull="ZodNull",O.ZodAny="ZodAny",O.ZodUnknown="ZodUnknown",O.ZodNever="ZodNever",O.ZodVoid="ZodVoid",O.ZodArray="ZodArray",O.ZodObject="ZodObject",O.ZodUnion="ZodUnion",O.ZodDiscriminatedUnion="ZodDiscriminatedUnion",O.ZodIntersection="ZodIntersection",O.ZodTuple="ZodTuple",O.ZodRecord="ZodRecord",O.ZodMap="ZodMap",O.ZodSet="ZodSet",O.ZodFunction="ZodFunction",O.ZodLazy="ZodLazy",O.ZodLiteral="ZodLiteral",O.ZodEnum="ZodEnum",O.ZodEffects="ZodEffects",O.ZodNativeEnum="ZodNativeEnum",O.ZodOptional="ZodOptional",O.ZodNullable="ZodNullable",O.ZodDefault="ZodDefault",O.ZodCatch="ZodCatch",O.ZodPromise="ZodPromise",O.ZodBranded="ZodBranded",O.ZodPipeline="ZodPipeline",O.ZodReadonly="ZodReadonly";let h0=hg.create;hy.create,hW.create,hv.create,h_.create,hb.create,hS.create,h$.create,hw.create,hR.create,hk.create,hx.create,hP.create,hE.create;let h1=hT.create;hT.strictCreate,hj.create,hC.create,hI.create,hN.create,hq.create,hA.create,hM.create,hz.create,hL.create,hZ.create,hV.create,hU.create,hF.create,hH.create,hJ.create,hB.create,hH.createWithPreprocess,hX.create;let h2=(t,r)=>{let a=0;for(;a<t.length&&a<r.length&&t[a]===r[a];a++);return[(t.length-a).toString(),...r.slice(a)].join("/")};function h9(t){if("openAi"!==t.target)return{};let r=[...t.basePath,t.definitionPath,t.openAiAnyTypeName];return t.flags.hasReferencedOpenAiAnyType=!0,{$ref:"relative"===t.$refStrategy?h2(r,t.currentPath):r.join("/")}}function h4(t,r,a,i){i?.errorMessages&&a&&(t.errorMessage={...t.errorMessage,[r]:a})}function h3(t,r,a,i,n){t[r]=a,h4(t,r,i,n)}function h6(t,r){return fy(t.type._def,r)}let h5=/^[cC][^\s-]{8,}$/,h7=/^[0-9a-z]+$/,h8=/^[0-9A-HJKMNP-TV-Z]{26}$/,fe=/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,ft=()=>(void 0===R&&(R=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),R),fr=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,fa=/^(([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])$/,fi=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,fn=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,fo=/^[a-zA-Z0-9_-]{21}$/,fs=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;function fl(t,r){let a={type:"string"};if(t.checks)for(let i of t.checks)switch(i.kind){case"min":h3(a,"minLength","number"==typeof a.minLength?Math.max(a.minLength,i.value):i.value,i.message,r);break;case"max":h3(a,"maxLength","number"==typeof a.maxLength?Math.min(a.maxLength,i.value):i.value,i.message,r);break;case"email":switch(r.emailStrategy){case"format:email":fd(a,"email",i.message,r);break;case"format:idn-email":fd(a,"idn-email",i.message,r);break;case"pattern:zod":fp(a,fe,i.message,r)}break;case"url":fd(a,"uri",i.message,r);break;case"uuid":fd(a,"uuid",i.message,r);break;case"regex":fp(a,i.regex,i.message,r);break;case"cuid":fp(a,h5,i.message,r);break;case"cuid2":fp(a,h7,i.message,r);break;case"startsWith":fp(a,RegExp(`^${fc(i.value,r)}`),i.message,r);break;case"endsWith":fp(a,RegExp(`${fc(i.value,r)}$`),i.message,r);break;case"datetime":fd(a,"date-time",i.message,r);break;case"date":fd(a,"date",i.message,r);break;case"time":fd(a,"time",i.message,r);break;case"duration":fd(a,"duration",i.message,r);break;case"length":h3(a,"minLength","number"==typeof a.minLength?Math.max(a.minLength,i.value):i.value,i.message,r),h3(a,"maxLength","number"==typeof a.maxLength?Math.min(a.maxLength,i.value):i.value,i.message,r);break;case"includes":fp(a,RegExp(fc(i.value,r)),i.message,r);break;case"ip":"v6"!==i.version&&fd(a,"ipv4",i.message,r),"v4"!==i.version&&fd(a,"ipv6",i.message,r);break;case"base64url":fp(a,fn,i.message,r);break;case"jwt":fp(a,fs,i.message,r);break;case"cidr":"v6"!==i.version&&fp(a,fr,i.message,r),"v4"!==i.version&&fp(a,fa,i.message,r);break;case"emoji":fp(a,ft(),i.message,r);break;case"ulid":fp(a,h8,i.message,r);break;case"base64":switch(r.base64Strategy){case"format:binary":fd(a,"binary",i.message,r);break;case"contentEncoding:base64":h3(a,"contentEncoding","base64",i.message,r);break;case"pattern:zod":fp(a,fi,i.message,r)}break;case"nanoid":fp(a,fo,i.message,r)}return a}function fc(t,r){return"escape"===r.patternStrategy?function(t){let r="";for(let a=0;a<t.length;a++)fu.has(t[a])||(r+="\\"),r+=t[a];return r}(t):t}let fu=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function fd(t,r,a,i){t.format||t.anyOf?.some(t=>t.format)?(t.anyOf||(t.anyOf=[]),t.format&&(t.anyOf.push({format:t.format,...t.errorMessage&&i.errorMessages&&{errorMessage:{format:t.errorMessage.format}}}),delete t.format,t.errorMessage&&(delete t.errorMessage.format,0===Object.keys(t.errorMessage).length&&delete t.errorMessage)),t.anyOf.push({format:r,...a&&i.errorMessages&&{errorMessage:{format:a}}})):h3(t,"format",r,a,i)}function fp(t,r,a,i){t.pattern||t.allOf?.some(t=>t.pattern)?(t.allOf||(t.allOf=[]),t.pattern&&(t.allOf.push({pattern:t.pattern,...t.errorMessage&&i.errorMessages&&{errorMessage:{pattern:t.errorMessage.pattern}}}),delete t.pattern,t.errorMessage&&(delete t.errorMessage.pattern,0===Object.keys(t.errorMessage).length&&delete t.errorMessage)),t.allOf.push({pattern:fm(r,i),...a&&i.errorMessages&&{errorMessage:{pattern:a}}})):h3(t,"pattern",fm(r,i),a,i)}function fm(t,r){if(!r.applyRegexFlags||!t.flags)return t.source;let a={i:t.flags.includes("i"),m:t.flags.includes("m"),s:t.flags.includes("s")},i=a.i?t.source.toLowerCase():t.source,n="",o=!1,s=!1,l=!1;for(let t=0;t<i.length;t++){if(o){n+=i[t],o=!1;continue}if(a.i){if(s){if(i[t].match(/[a-z]/)){l?(n+=i[t],n+=`${i[t-2]}-${i[t]}`.toUpperCase(),l=!1):"-"===i[t+1]&&i[t+2]?.match(/[a-z]/)?(n+=i[t],l=!0):n+=`${i[t]}${i[t].toUpperCase()}`;continue}}else if(i[t].match(/[a-z]/)){n+=`[${i[t]}${i[t].toUpperCase()}]`;continue}}if(a.m){if("^"===i[t]){n+=`(^|(?<=[\r
78
78
  ]))`;continue}else if("$"===i[t]){n+=`($|(?=[\r
79
79
  ]))`;continue}}if(a.s&&"."===i[t]){n+=s?`${i[t]}\r
80
80
  `:`[${i[t]}\r
81
- ]`;continue}n+=i[t],"\\"===i[t]?o=!0:s&&"]"===i[t]?s=!1:s||"["!==i[t]||(s=!0)}try{new RegExp(n)}catch{return console.warn(`Could not convert regex pattern at ${r.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),t.source}return n}function fp(t,r){if("openAi"===r.target&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),"openApi3"===r.target&&t.keyType?._def.typeName===z.ZodEnum)return{type:"object",required:t.keyType._def.values,properties:t.keyType._def.values.reduce((a,i)=>({...a,[i]:ff(t.valueType._def,{...r,currentPath:[...r.currentPath,"properties",i]})??h1(r)}),{}),additionalProperties:r.rejectedAdditionalProperties};let a={type:"object",additionalProperties:ff(t.valueType._def,{...r,currentPath:[...r.currentPath,"additionalProperties"]})??r.allowedAdditionalProperties};if("openApi3"===r.target)return a;if(t.keyType?._def.typeName===z.ZodString&&t.keyType._def.checks?.length){let{type:i,...n}=fo(t.keyType._def,r);return{...a,propertyNames:n}}if(t.keyType?._def.typeName===z.ZodEnum)return{...a,propertyNames:{enum:t.keyType._def.values}};if(t.keyType?._def.typeName===z.ZodBranded&&t.keyType._def.type._def.typeName===z.ZodString&&t.keyType._def.type._def.checks?.length){let{type:i,...n}=h4(t.keyType._def,r);return{...a,propertyNames:n}}return a}let fm={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"},fh=(t,r)=>{let a=(t.options instanceof Map?Array.from(t.options.values()):t.options).map((t,a)=>ff(t._def,{...r,currentPath:[...r.currentPath,"anyOf",`${a}`]})).filter(t=>!!t&&(!r.strictUnions||"object"==typeof t&&Object.keys(t).length>0));return a.length?{anyOf:a}:void 0};function ff(t,r,a=!1){let i=r.seen.get(t);if(r.override){let n=r.override?.(t,r,i,a);if(n!==mH)return n}if(i&&!a){let t=fg(i,r);if(void 0!==t)return t}let n={def:t,path:r.currentPath,jsonSchema:void 0};r.seen.set(t,n);let o=((t,r,a)=>{switch(r){case z.ZodString:return fo(t,a);case z.ZodNumber:let i={type:"number"};if(!t.checks)return i;for(let r of t.checks)switch(r.kind){case"int":i.type="integer",h2(i,"type",r.message,a);break;case"min":"jsonSchema7"===a.target?r.inclusive?h9(i,"minimum",r.value,r.message,a):h9(i,"exclusiveMinimum",r.value,r.message,a):(r.inclusive||(i.exclusiveMinimum=!0),h9(i,"minimum",r.value,r.message,a));break;case"max":"jsonSchema7"===a.target?r.inclusive?h9(i,"maximum",r.value,r.message,a):h9(i,"exclusiveMaximum",r.value,r.message,a):(r.inclusive||(i.exclusiveMaximum=!0),h9(i,"maximum",r.value,r.message,a));break;case"multipleOf":h9(i,"multipleOf",r.value,r.message,a)}return i;case z.ZodObject:return function(t,r){let a="openAi"===r.target,i={type:"object",properties:{}},n=[],o=t.shape();for(let t in o){let s=o[t];if(void 0===s||void 0===s._def)continue;let l=function(t){try{return t.isOptional()}catch{return!0}}(s);l&&a&&("ZodOptional"===s._def.typeName&&(s=s._def.innerType),s.isNullable()||(s=s.nullable()),l=!1);let c=ff(s._def,{...r,currentPath:[...r.currentPath,"properties",t],propertyPath:[...r.currentPath,"properties",t]});void 0!==c&&(i.properties[t]=c,l||n.push(t))}n.length&&(i.required=n);let s=function(t,r){if("ZodNever"!==t.catchall._def.typeName)return ff(t.catchall._def,{...r,currentPath:[...r.currentPath,"additionalProperties"]});switch(t.unknownKeys){case"passthrough":return r.allowedAdditionalProperties;case"strict":return r.rejectedAdditionalProperties;case"strip":return"strict"===r.removeAdditionalStrategy?r.allowedAdditionalProperties:r.rejectedAdditionalProperties}}(t,r);return void 0!==s&&(i.additionalProperties=s),i}(t,a);case z.ZodBigInt:let n={type:"integer",format:"int64"};if(!t.checks)return n;for(let r of t.checks)switch(r.kind){case"min":"jsonSchema7"===a.target?r.inclusive?h9(n,"minimum",r.value,r.message,a):h9(n,"exclusiveMinimum",r.value,r.message,a):(r.inclusive||(n.exclusiveMinimum=!0),h9(n,"minimum",r.value,r.message,a));break;case"max":"jsonSchema7"===a.target?r.inclusive?h9(n,"maximum",r.value,r.message,a):h9(n,"exclusiveMaximum",r.value,r.message,a):(r.inclusive||(n.exclusiveMaximum=!0),h9(n,"maximum",r.value,r.message,a));break;case"multipleOf":h9(n,"multipleOf",r.value,r.message,a)}return n;case z.ZodBoolean:return{type:"boolean"};case z.ZodDate:return function t(r,a,i){let n=i??a.dateStrategy;if(Array.isArray(n))return{anyOf:n.map((i,n)=>t(r,a,i))};switch(n){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":var o=r,s=a;let l={type:"integer",format:"unix-time"};if("openApi3"===s.target)return l;for(let t of o.checks)switch(t.kind){case"min":h9(l,"minimum",t.value,t.message,s);break;case"max":h9(l,"maximum",t.value,t.message,s)}return l}}(t,a);case z.ZodUndefined:return{not:h1(a)};case z.ZodNull:return"openApi3"===a.target?{enum:["null"],nullable:!0}:{type:"null"};case z.ZodArray:let o;return o={type:"array"},t.type?._def&&t.type?._def?.typeName!==z.ZodAny&&(o.items=ff(t.type._def,{...a,currentPath:[...a.currentPath,"items"]})),t.minLength&&h9(o,"minItems",t.minLength.value,t.minLength.message,a),t.maxLength&&h9(o,"maxItems",t.maxLength.value,t.maxLength.message,a),t.exactLength&&(h9(o,"minItems",t.exactLength.value,t.exactLength.message,a),h9(o,"maxItems",t.exactLength.value,t.exactLength.message,a)),o;case z.ZodUnion:case z.ZodDiscriminatedUnion:if("openApi3"===a.target)return fh(t,a);let s=t.options instanceof Map?Array.from(t.options.values()):t.options;if(s.every(t=>t._def.typeName in fm&&(!t._def.checks||!t._def.checks.length))){let t=s.reduce((t,r)=>{let a=fm[r._def.typeName];return a&&!t.includes(a)?[...t,a]:t},[]);return{type:t.length>1?t:t[0]}}if(s.every(t=>"ZodLiteral"===t._def.typeName&&!t.description)){let t=s.reduce((t,r)=>{let a=typeof r._def.value;switch(a){case"string":case"number":case"boolean":return[...t,a];case"bigint":return[...t,"integer"];case"object":if(null===r._def.value)return[...t,"null"];default:return t}},[]);if(t.length===s.length){let r=t.filter((t,r,a)=>a.indexOf(t)===r);return{type:r.length>1?r:r[0],enum:s.reduce((t,r)=>t.includes(r._def.value)?t:[...t,r._def.value],[])}}}else if(s.every(t=>"ZodEnum"===t._def.typeName))return{type:"string",enum:s.reduce((t,r)=>[...t,...r._def.values.filter(r=>!t.includes(r))],[])};return fh(t,a);case z.ZodIntersection:let l,c,u;return l=[ff(t.left._def,{...a,currentPath:[...a.currentPath,"allOf","0"]}),ff(t.right._def,{...a,currentPath:[...a.currentPath,"allOf","1"]})].filter(t=>!!t),c="jsonSchema2019-09"===a.target?{unevaluatedProperties:!1}:void 0,u=[],l.forEach(t=>{if((!("type"in t)||"string"!==t.type)&&"allOf"in t)u.push(...t.allOf),void 0===t.unevaluatedProperties&&(c=void 0);else{let r=t;if("additionalProperties"in t&&!1===t.additionalProperties){let{additionalProperties:a,...i}=t;r=i}else c=void 0;u.push(r)}}),u.length?{allOf:u,...c}:void 0;case z.ZodTuple:return t.rest?{type:"array",minItems:t.items.length,items:t.items.map((t,r)=>ff(t._def,{...a,currentPath:[...a.currentPath,"items",`${r}`]})).reduce((t,r)=>void 0===r?t:[...t,r],[]),additionalItems:ff(t.rest._def,{...a,currentPath:[...a.currentPath,"additionalItems"]})}:{type:"array",minItems:t.items.length,maxItems:t.items.length,items:t.items.map((t,r)=>ff(t._def,{...a,currentPath:[...a.currentPath,"items",`${r}`]})).reduce((t,r)=>void 0===r?t:[...t,r],[])};case z.ZodRecord:return fp(t,a);case z.ZodLiteral:let d;return"bigint"!=(d=typeof t.value)&&"number"!==d&&"boolean"!==d&&"string"!==d?{type:Array.isArray(t.value)?"array":"object"}:"openApi3"===a.target?{type:"bigint"===d?"integer":d,enum:[t.value]}:{type:"bigint"===d?"integer":d,const:t.value};case z.ZodEnum:return{type:"string",enum:Array.from(t.values)};case z.ZodNativeEnum:let p,m,h;return p=t.values,{type:1===(h=Array.from(new Set((m=Object.keys(t.values).filter(t=>"number"!=typeof p[p[t]]).map(t=>p[t])).map(t=>typeof t)))).length?"string"===h[0]?"string":"number":["string","number"],enum:m};case z.ZodNullable:if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(t.innerType._def.typeName)&&(!t.innerType._def.checks||!t.innerType._def.checks.length))return"openApi3"===a.target?{type:fm[t.innerType._def.typeName],nullable:!0}:{type:[fm[t.innerType._def.typeName],"null"]};if("openApi3"===a.target){let r=ff(t.innerType._def,{...a,currentPath:[...a.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}let f=ff(t.innerType._def,{...a,currentPath:[...a.currentPath,"anyOf","0"]});return f&&{anyOf:[f,{type:"null"}]};case z.ZodOptional:if(a.currentPath.toString()===a.propertyPath?.toString())return ff(t.innerType._def,a);let g=ff(t.innerType._def,{...a,currentPath:[...a.currentPath,"anyOf","1"]});return g?{anyOf:[{not:h1(a)},g]}:h1(a);case z.ZodMap:if("record"===a.mapStrategy)return fp(t,a);return{type:"array",maxItems:125,items:{type:"array",items:[ff(t.keyType._def,{...a,currentPath:[...a.currentPath,"items","items","0"]})||h1(a),ff(t.valueType._def,{...a,currentPath:[...a.currentPath,"items","items","1"]})||h1(a)],minItems:2,maxItems:2}};case z.ZodSet:let y;return y={type:"array",uniqueItems:!0,items:ff(t.valueType._def,{...a,currentPath:[...a.currentPath,"items"]})},t.minSize&&h9(y,"minItems",t.minSize.value,t.minSize.message,a),t.maxSize&&h9(y,"maxItems",t.maxSize.value,t.maxSize.message,a),y;case z.ZodLazy:return()=>t.getter()._def;case z.ZodPromise:return ff(t.type._def,a);case z.ZodNaN:case z.ZodNever:return"openAi"===a.target?void 0:{not:h1({...a,currentPath:[...a.currentPath,"not"]})};case z.ZodEffects:return"input"===a.effectStrategy?ff(t.schema._def,a):h1(a);case z.ZodAny:case z.ZodUnknown:return h1(a);case z.ZodDefault:return{...ff(t.innerType._def,a),default:t.defaultValue()};case z.ZodBranded:return h4(t,a);case z.ZodReadonly:case z.ZodCatch:return ff(t.innerType._def,a);case z.ZodPipeline:if("input"===a.pipeStrategy)return ff(t.in._def,a);if("output"===a.pipeStrategy)return ff(t.out._def,a);let v=ff(t.in._def,{...a,currentPath:[...a.currentPath,"allOf","0"]}),_=ff(t.out._def,{...a,currentPath:[...a.currentPath,"allOf",v?"1":"0"]});return{allOf:[v,_].filter(t=>void 0!==t)};case z.ZodFunction:case z.ZodVoid:case z.ZodSymbol:default:return}})(t,t.typeName,r),s="function"==typeof o?ff(o(),r):o;if(s&&fy(t,r,s),r.postProcess){let a=r.postProcess(s,t,r);return n.jsonSchema=s,a}return n.jsonSchema=s,s}let fg=(t,r)=>{switch(r.$refStrategy){case"root":return{$ref:t.path.join("/")};case"relative":return{$ref:h0(r.currentPath,t.path)};case"none":case"seen":if(t.path.length<r.currentPath.length&&t.path.every((t,a)=>r.currentPath[a]===t))return console.warn(`Recursive reference detected at ${r.currentPath.join("/")}! Defaulting to any`),h1(r);return"seen"===r.$refStrategy?h1(r):void 0}},fy=(t,r,a)=>(t.description&&(a.description=t.description,r.markdownDescription&&(a.markdownDescription=t.description)),a);function fv(t,r={}){let{strict:a=!1}=r,i=Object.entries(t),n=t=>({target:r})=>{let n={},o=[];for(let[a,s]of i)n[a]=function(t,r,a){let i=t["~standard"];if(i.jsonSchema)return i.jsonSchema[a]({target:r});if("zod"===t["~standard"].vendor&&!("_zod"in t)&&"_def"in t){let a=((t,r)=>{let a,i,n=(i=void 0!==(a="string"==typeof r?{...mJ,name:r}:{...mJ,...r}).name?[...a.basePath,a.definitionPath,a.name]:a.basePath,{...a,flags:{hasReferencedOpenAiAnyType:!1},currentPath:i,propertyPath:void 0,seen:new Map(Object.entries(a.definitions).map(([t,r])=>[r._def,{def:r._def,path:[...a.basePath,a.definitionPath,t],jsonSchema:void 0}]))}),o="object"==typeof r&&r.definitions?Object.entries(r.definitions).reduce((t,[r,a])=>({...t,[r]:ff(a._def,{...n,currentPath:[...n.basePath,n.definitionPath,r]},!0)??h1(n)}),{}):void 0,s="string"==typeof r?r:r?.nameStrategy==="title"?void 0:r?.name,l=ff(t._def,void 0===s?n:{...n,currentPath:[...n.basePath,n.definitionPath,s]},!1)??h1(n),c="object"==typeof r&&void 0!==r.name&&"title"===r.nameStrategy?r.name:void 0;void 0!==c&&(l.title=c),n.flags.hasReferencedOpenAiAnyType&&(o||(o={}),o[n.openAiAnyTypeName]||(o[n.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:"relative"===n.$refStrategy?"1":[...n.basePath,n.definitionPath,n.openAiAnyTypeName].join("/")}}));let u=void 0===s?o?{...l,[n.definitionPath]:o}:l:{$ref:[..."relative"===n.$refStrategy?[]:n.basePath,n.definitionPath,s].join("/"),[n.definitionPath]:{...o,[s]:l}};return"jsonSchema7"===n.target?u.$schema="http://json-schema.org/draft-07/schema#":("jsonSchema2019-09"===n.target||"openAi"===n.target)&&(u.$schema="https://json-schema.org/draft/2019-09/schema#"),"openAi"===n.target&&("anyOf"in u||"oneOf"in u||"allOf"in u||"type"in u&&Array.isArray(u.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),u})(t,{$refStrategy:"none",target:"openapi-3.0"===r?"openApi3":"jsonSchema7"});return delete a.$schema,a}if("zod"===i.vendor&&"_zod"in t)try{let r=a8(t);return delete r.$schema,r}catch(t){throw Error(`Failed to convert a zod schema to JSON Schema (zod v4 without "~standard.jsonSchema"). Upgrade to zod >= 4.2.0. Original error: ${t instanceof Error?t.message:String(t)}`)}throw Error(`Schema library "${i.vendor}" cannot be converted to JSON Schema. Use zod v3 (>= 3.25.76), zod >= 4.2.0, or a Standard Schema library implementing "~standard.jsonSchema".`)}(s,r,t),!function(t,r){if("function"!=typeof t.safeParse)return!1;try{let a=t.safeParse(void 0);return a.success&&("input"===r||void 0===a.data)}catch{return!1}}(s,t)&&o.push(a);let s={type:"object",properties:n};return o.length>0&&(s.required=o),a&&(s.additionalProperties=!1),s},o=async r=>{if("object"!=typeof r||null===r||Array.isArray(r))return{issues:[{message:"Expected an object."}]};let n={},o=[];for(let[t,a]of i){let i=await a["~standard"].validate(r[t]);if(i.issues)for(let r of i.issues)o.push({message:r.message,path:[t,...r.path??[]]});else(t in r||void 0!==i.value)&&(n[t]=i.value)}if(a)for(let a of Object.keys(r))a in t||o.push({message:`Unrecognized key: "${a}"`,path:[a]});return o.length>0?{issues:o}:{value:n}};return{shape:t,"~standard":{version:1,vendor:"xmcp",validate:o,jsonSchema:{input:n("input"),output:n("output")}}}}function f_(t){let r={};return!function t(a,i=""){if(a&&"object"==typeof a)for(let[n,o]of Object.entries(a)){let a=i?`${i}/${n}`:n;!o||"object"!=typeof o||Array.isArray(o)||o instanceof Date||o instanceof RegExp?r[a]=o:t(o,a)}}(t),r}let fb=["ui/resourceUri","resourceUri","visibility"],fS=["prefersBorder","domain","csp","permissions","connectDomains","resourceDomains","frameDomains","baseUriDomains"];function f$(t){return"object"==typeof t&&null!==t&&Object.entries(t).every(([t,r])=>"string"==typeof t&&"object"==typeof r&&null!==r&&"parse"in r&&"function"==typeof r.parse)}function fw(t){return(t.split("/").pop()||t).replace(/\.[^/.]+$/,"")}function fR(t,r,a){return t.names?.includes(r)===!0||t.tags?.some(t=>a.includes(t))===!0}function fk(t,r){return r?new Map([...t].filter(([t,{metadata:a}])=>{if(a?.enabled===!1)return!1;let i=a?.name??fw(t),n=a?.tags??[];return(!r.include||fR(r.include,i,n))&&(!r.exclude||!fR(r.exclude,i,n))})):t}function fx(t){return Error(`[xmcp] Invalid prompt file: ${t}
82
- -> Default export must be a prompt handler function.`)}async function fP(t){let r=new Map,a=[];for(let i of(await Promise.all(Object.entries(t).map(async([t,r])=>{let a=await r(),i=function(t,r){if("object"!=typeof t||null===t)throw fx(r);let a=Object.keys(t),i=t.default,n=a.filter(t=>"__esModule"!==t);if(0===a.length||1===n.length&&"default"===n[0]&&"object"==typeof i&&null!==i&&0===Object.keys(i).length)return"empty";if(!("default"in t)||void 0===t.default)return"missing-default";if("function"!=typeof t.default)throw fx(r);return"valid"}(a,t);return"empty"===i?{skipped:!0,issue:{path:t,message:"File is empty."}}:"missing-default"===i?{skipped:!0,issue:{path:t,message:"File does not export a default prompt handler."}}:{skipped:!1,path:t,promptModule:a}})))){if(i.skipped){a.push(i.issue);continue}r.set(i.path,i.promptModule)}return{promptModules:r,skippedPrompts:a}}let fE=function(t=console){let r="";return a=>{let i=a.map(({path:t,message:r})=>`${t}:${r}`).sort().join("|");if(i===r||(r=i,0===a.length))return;a.forEach(({path:r,message:a})=>{t.warn(`[xmcp] Failed to load prompt file: ${r}
83
- -> ${a}`)});let n=a.length;t.warn(`[xmcp] ${n} prompt${1===n?"":"s"} skipped due to empty files or missing default exports`)}}();function fT(t){return Error(`[xmcp] Invalid resource file: ${t}
84
- -> Default export must be a resource handler function.`)}async function fj(t){let r=new Map,a=[];for(let i of(await Promise.all(Object.entries(t).map(async([t,r])=>{let a=await r(),i=function(t,r){if("object"!=typeof t||null===t)throw fT(r);let a=Object.keys(t),i=t.default,n=a.filter(t=>"__esModule"!==t);if(0===a.length||1===n.length&&"default"===n[0]&&"object"==typeof i&&null!==i&&0===Object.keys(i).length)return"empty";if(!("default"in t)||void 0===t.default)return"missing-default";if("function"!=typeof t.default)throw fT(r);return"valid"}(a,t);return"empty"===i?{skipped:!0,issue:{path:t,message:"File is empty."}}:"missing-default"===i?{skipped:!0,issue:{path:t,message:"File does not export a default resource handler."}}:{skipped:!1,path:t,resourceModule:a}})))){if(i.skipped){a.push(i.issue);continue}r.set(i.path,i.resourceModule)}return{resourceModules:r,skippedResources:a}}let fO=function(t=console){let r="";return a=>{let i=a.map(({path:t,message:r})=>`${t}:${r}`).sort().join("|");if(i===r||(r=i,0===a.length))return;a.forEach(({path:r,message:a})=>{t.warn(`[xmcp] Failed to load resource file: ${r}
85
- -> ${a}`)});let n=a.length;t.warn(`[xmcp] ${n} resource${1===n?"":"s"} skipped due to empty files or missing default exports`)}}();function fC(t){let r=t.replace(/\\/g,"/");if(!r)throw Error("Invalid tool path: path is empty");let a=r.replace(/\.[^/.]+$/,"").replace(/\//g,"_");return{normalizedPath:r,baseName:a}}function fI(t){let r=t.split("/").filter(t=>""!==t),a=r.findIndex(t=>t.match(/^\(.+\)$/));if(-1===a)return null;let i=r[r.length-1];if(i&&i.match(/^\[.+\]\.ts$/))return null;let n=r[a].slice(1,-1),o=r.slice(a+1),s=o[o.length-1];if(s&&s.includes(".")){let t=s.split(".")[0];"index"!==t?o[o.length-1]=t:o.pop()}let l=[],c=[],u=o.map(t=>{if(!t.match(/^\[.+\]$/))return c.push(t),t;{let r=t.slice(1,-1);return l.push(r),`{${r}}`}}),d=`${n}://${u.join("/")}`,p=l.length>0?"template":"direct";return{filePath:t,uriTemplate:d,scheme:n,parameters:l,pathSegments:c,type:p}}function fN(t){return Error(`[xmcp] Invalid tool file: ${t}
86
- -> Default export must be a tool handler function.`)}async function fq(t){let r=new Map,a=[];for(let i of(await Promise.all(Object.entries(t).map(async([t,r])=>{let a=await r(),i=function(t,r){if("object"!=typeof t||null===t)throw fN(r);let a=Object.keys(t),i=t.default,n=a.filter(t=>"__esModule"!==t);if(0===a.length||1===n.length&&"default"===n[0]&&"object"==typeof i&&null!==i&&0===Object.keys(i).length)return"empty";if(!("default"in t)||void 0===t.default)return"missing-default";if("function"!=typeof t.default)throw fN(r);return"valid"}(a,t);return"empty"===i?{skipped:!0,issue:{path:t,message:"File is empty."}}:"missing-default"===i?{skipped:!0,issue:{path:t,message:"File does not export a default tool handler."}}:{skipped:!1,path:t,toolModule:a}})))){if(i.skipped){a.push(i.issue);continue}r.set(i.path,i.toolModule)}return{toolModules:r,skippedTools:a}}let fA=function(t=console){let r="";return a=>{let i=a.map(({path:t,message:r})=>`${t}:${r}`).sort().join("|");if(i===r||(r=i,0===a.length))return;a.forEach(({path:r,message:a})=>{t.warn(`[xmcp] Failed to load tool file: ${r}
87
- -> ${a}`)});let n=a.length;t.warn(`[xmcp] ${n} tool${1===n?"":"s"} skipped due to empty files or missing default exports`)}}(),fM=INJECTED_TOOLS,fz=INJECTED_PROMPTS,fL=INJECTED_RESOURCES,fZ=SERVER_INFO;async function fD(t,r,a,i){let o=await INJECTED_MIDDLEWARE?.(),s=function(t){if(void 0===t)return[];let r=Array.isArray(t)?[...t]:[t];if(!r.every(t=>"function"==typeof t))throw Error("src/middleware.ts must export mcp as a function or an array of functions");return r}(o?.mcp),l="undefined"!=typeof OBSERVABILITY_CONFIG&&OBSERVABILITY_CONFIG.enabled?function(t=t=>console.error(t)){let r=new Map,a=[];function i(r){try{t(JSON.stringify({"@timestamp":new Date().toISOString(),...r}))}catch{}}return{middleware:async(t,n)=>{let o,s,l;if("tools/call"!==t.method&&"prompts/get"!==t.method&&"resources/read"!==t.method)return n();try{s=performance.now(),o={log:{level:"info"},...function(t){let r=t.http?.headers.traceparent;if("string"!=typeof r)return{};let a=/^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/.exec(r);return!a||"ff"===a[1]||/^0+$/.test(a[2])||/^0+$/.test(a[3])||"00"===a[1]&&void 0!==a[5]?{}:{trace:{id:a[2]},parent:{id:a[3]}}}(t),transaction:{id:crypto.randomUUID()},...t.http?{http:{request:{id:t.http.id}}}:{},xmcp:{method:t.method,component:"resources/read"===t.method?function(t){try{let i=new URL(t).href;return r.get(i)??a.find(({template:t})=>t.uriTemplate.match(i))?.name??"unknown"}catch{return"unknown"}}(t.params.uri):t.params.name}}}catch{return n()}i({...o,event:{kind:"event",category:["api"],type:["start"],action:"execution.start"}});let c="unknown";try{let r=await n();try{c=t.signal.aborted?"cancelled":cX(r)?"input_required":"isError"in r&&!0===r.isError?"failure":"success","failure"===c&&(l={message:"Operation returned an error result"})}catch{}return r}catch(r){throw l={message:"cancelled"==(c=t.signal.aborted?"cancelled":"failure")?"Operation cancelled":"Operation threw an exception"},r}finally{try{i({...o,log:{level:"failure"===c?"error":"info"},event:{kind:"event",category:["api"],type:["end"],action:"execution.end",duration:Math.round((performance.now()-s)*1e6),outcome:"success"===c?"success":"failure"===c?"failure":"unknown"},xmcp:{...o.xmcp,status:c},...l?{error:l}:{}})}catch{}}},registerResource(t,i){try{"string"==typeof i?r.set(new URL(i).href,t):a.push({name:t,template:i})}catch{}}}}():void 0;l&&s.unshift(l.middleware),mp.clear();let c="undefined"==typeof COMPONENTS_CONFIG?void 0:COMPONENTS_CONFIG;return!function(t,r,a){let i=t.server,n=i.setRequestHandler,o=mV(r);i.setRequestHandler=(t,...r)=>{if(mU.has(t)&&1===r.length&&"function"==typeof r[0]){let t=r[0];r[0]=(r,a)=>o({method:r.method,params:r.params??{}},a,()=>t(r,a))}Reflect.apply(n,i,[t,...r])};try{a()}finally{i.setRequestHandler=n}}(t,s,()=>{var o,u;!function(t,r,a=[]){r.forEach((r,i)=>{var n,o;let s,l,c,u,d={name:fw(i),description:"No description provided"},{default:p,metadata:m,schema:h,outputSchema:f}=r;if("object"==typeof m&&null!==m&&Object.assign(d,m),!1===d.enabled)return;if("function"==typeof p&&"__x402"in p){let t=global.__XMCP_X402_REGISTRY;t&&t.set(d.name,p.__x402)}let g={};if(f$(h)?g=h:null!=h&&console.warn(`Invalid schema for tool "${d.name}" at ${i}. Expected Record<string, z.ZodType>`),null!=f)if(f$(f))s=f;else throw Error(`Invalid outputSchema for tool "${d.name}" at ${i}. Expected Record<string, z.ZodType>`);d.annotations={...d.annotations??{}},void 0===d.annotations.title&&(d.annotations.title=d.name),d._meta={...md(d)._meta};let y=mF(i),v=!!(n=d._meta)&&"object"==typeof n&&"ui"in n&&"object"==typeof n.ui||y,_=d._meta;if(v){let t=`ui://app/${d.name}.html`;d._meta.ui||(d._meta.ui={}),d._meta.ui.resourceUri||(d._meta.ui.resourceUri=t);let r=function(t){let r={},a={};if(t.ui&&"object"==typeof t.ui){let i=t.ui,n={},o={};for(let[t,r]of Object.entries(i))fb.includes(t)?n[t]=r:fS.includes(t)?o[t]=r:n[t]=r;Object.keys(n).length>0&&(r.ui=n),Object.keys(o).length>0&&(a.ui=o)}for(let[a,i]of Object.entries(t))"ui"!==a&&(r[a]=i);return{toolMeta:r,resourceMeta:a}}(_);_=r.toolMeta;let a=r.resourceMeta;a.ui=a.ui||{},a.ui.csp=a.ui.csp||{},a.ui.csp.resourceDomains=a.ui.csp.resourceDomains||[],a.ui.csp.resourceDomains.includes("https://esm.sh")||a.ui.csp.resourceDomains.push("https://esm.sh"),mp.add(d.name,{name:d.name,uri:t,handler:p,mimeType:"text/html;profile=mcp-app",_meta:a,toolPath:y?i:void 0})}let b=f_(_),S=v?b:void 0;l=mF(i)&&v?async(t,r)=>({content:[{type:"text",text:""}],_meta:S,structuredContent:{args:t}}):function(t,r,a,i="unknown-tool"){return async(n,o)=>{let s,l,c=t(n,(s=mD(o),l=function(t){if(!t)return;let r={};return t.headers.forEach((t,a)=>{r[a]=t}),r}(o.http?.req),{signal:o.mcpReq.signal,authInfo:o.http?.authInfo,sessionId:o.sessionId,_meta:o.mcpReq._meta,requestId:o.mcpReq.id,requestInfo:l?{headers:l}:void 0,clientInfo:s,sendNotification:t=>o.mcpReq.notify(t),sendRequest:(t,r,a)=>o.mcpReq.send(t,r,a),elicit:(t,r)=>mR(o,t,r),sample:(t,r)=>mq(o,t,r),inputResponses:o.mcpReq.inputResponses,requestState:o.mcpReq.requestState}));if(c instanceof Promise&&(c=await c),cX(c))return c;if("string"==typeof c||"number"==typeof c){if(a){let t=Object.entries(a);if(1===t.length){let[r,a]=t[0];try{return a.parse(c),{content:[{type:"text",text:"number"==typeof c?`${c}`:c}],structuredContent:{[r]:c}}}catch{}}}return mZ(r)?{content:[{type:"text",text:""}],structuredContent:{args:n},_meta:r}:{content:[{type:"text",text:"number"==typeof c?`${c}`:c}]}}if(!a||!c||"object"!=typeof c||Array.isArray(c)||"structuredContent"in c||"content"in c&&Array.isArray(c.content)||"_meta"in c||"isError"in c||(mL(c,a,i,"returned data that does not match outputSchema"),c={structuredContent:c}),c&&"object"==typeof c&&"_meta"in c&&!("content"in c)&&!("structuredContent"in c)){let t=c._meta;if(mZ(t))return{content:[{type:"text",text:""}],_meta:t}}if(!c||"object"!=typeof c){let t=null===c?"null":typeof c,r=void 0===c?"undefined":null===c?"null":"object"==typeof c?JSON.stringify(c,null,2):String(c);throw Error(`Tool handler must return a CallToolResult, string, or number. Got ${t}: ${r}
81
+ ]`;continue}n+=i[t],"\\"===i[t]?o=!0:s&&"]"===i[t]?s=!1:s||"["!==i[t]||(s=!0)}try{new RegExp(n)}catch{return console.warn(`Could not convert regex pattern at ${r.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),t.source}return n}function fh(t,r){if("openAi"===r.target&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),"openApi3"===r.target&&t.keyType?._def.typeName===z.ZodEnum)return{type:"object",required:t.keyType._def.values,properties:t.keyType._def.values.reduce((a,i)=>({...a,[i]:fy(t.valueType._def,{...r,currentPath:[...r.currentPath,"properties",i]})??h9(r)}),{}),additionalProperties:r.rejectedAdditionalProperties};let a={type:"object",additionalProperties:fy(t.valueType._def,{...r,currentPath:[...r.currentPath,"additionalProperties"]})??r.allowedAdditionalProperties};if("openApi3"===r.target)return a;if(t.keyType?._def.typeName===z.ZodString&&t.keyType._def.checks?.length){let{type:i,...n}=fl(t.keyType._def,r);return{...a,propertyNames:n}}if(t.keyType?._def.typeName===z.ZodEnum)return{...a,propertyNames:{enum:t.keyType._def.values}};if(t.keyType?._def.typeName===z.ZodBranded&&t.keyType._def.type._def.typeName===z.ZodString&&t.keyType._def.type._def.checks?.length){let{type:i,...n}=h6(t.keyType._def,r);return{...a,propertyNames:n}}return a}let ff={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"},fg=(t,r)=>{let a=(t.options instanceof Map?Array.from(t.options.values()):t.options).map((t,a)=>fy(t._def,{...r,currentPath:[...r.currentPath,"anyOf",`${a}`]})).filter(t=>!!t&&(!r.strictUnions||"object"==typeof t&&Object.keys(t).length>0));return a.length?{anyOf:a}:void 0};function fy(t,r,a=!1){let i=r.seen.get(t);if(r.override){let n=r.override?.(t,r,i,a);if(n!==mH)return n}if(i&&!a){let t=fv(i,r);if(void 0!==t)return t}let n={def:t,path:r.currentPath,jsonSchema:void 0};r.seen.set(t,n);let o=((t,r,a)=>{switch(r){case z.ZodString:return fl(t,a);case z.ZodNumber:let i={type:"number"};if(!t.checks)return i;for(let r of t.checks)switch(r.kind){case"int":i.type="integer",h4(i,"type",r.message,a);break;case"min":"jsonSchema7"===a.target?r.inclusive?h3(i,"minimum",r.value,r.message,a):h3(i,"exclusiveMinimum",r.value,r.message,a):(r.inclusive||(i.exclusiveMinimum=!0),h3(i,"minimum",r.value,r.message,a));break;case"max":"jsonSchema7"===a.target?r.inclusive?h3(i,"maximum",r.value,r.message,a):h3(i,"exclusiveMaximum",r.value,r.message,a):(r.inclusive||(i.exclusiveMaximum=!0),h3(i,"maximum",r.value,r.message,a));break;case"multipleOf":h3(i,"multipleOf",r.value,r.message,a)}return i;case z.ZodObject:return function(t,r){let a="openAi"===r.target,i={type:"object",properties:{}},n=[],o=t.shape();for(let t in o){let s=o[t];if(void 0===s||void 0===s._def)continue;let l=function(t){try{return t.isOptional()}catch{return!0}}(s);l&&a&&("ZodOptional"===s._def.typeName&&(s=s._def.innerType),s.isNullable()||(s=s.nullable()),l=!1);let c=fy(s._def,{...r,currentPath:[...r.currentPath,"properties",t],propertyPath:[...r.currentPath,"properties",t]});void 0!==c&&(i.properties[t]=c,l||n.push(t))}n.length&&(i.required=n);let s=function(t,r){if("ZodNever"!==t.catchall._def.typeName)return fy(t.catchall._def,{...r,currentPath:[...r.currentPath,"additionalProperties"]});switch(t.unknownKeys){case"passthrough":return r.allowedAdditionalProperties;case"strict":return r.rejectedAdditionalProperties;case"strip":return"strict"===r.removeAdditionalStrategy?r.allowedAdditionalProperties:r.rejectedAdditionalProperties}}(t,r);return void 0!==s&&(i.additionalProperties=s),i}(t,a);case z.ZodBigInt:let n={type:"integer",format:"int64"};if(!t.checks)return n;for(let r of t.checks)switch(r.kind){case"min":"jsonSchema7"===a.target?r.inclusive?h3(n,"minimum",r.value,r.message,a):h3(n,"exclusiveMinimum",r.value,r.message,a):(r.inclusive||(n.exclusiveMinimum=!0),h3(n,"minimum",r.value,r.message,a));break;case"max":"jsonSchema7"===a.target?r.inclusive?h3(n,"maximum",r.value,r.message,a):h3(n,"exclusiveMaximum",r.value,r.message,a):(r.inclusive||(n.exclusiveMaximum=!0),h3(n,"maximum",r.value,r.message,a));break;case"multipleOf":h3(n,"multipleOf",r.value,r.message,a)}return n;case z.ZodBoolean:return{type:"boolean"};case z.ZodDate:return function t(r,a,i){let n=i??a.dateStrategy;if(Array.isArray(n))return{anyOf:n.map((i,n)=>t(r,a,i))};switch(n){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":var o=r,s=a;let l={type:"integer",format:"unix-time"};if("openApi3"===s.target)return l;for(let t of o.checks)switch(t.kind){case"min":h3(l,"minimum",t.value,t.message,s);break;case"max":h3(l,"maximum",t.value,t.message,s)}return l}}(t,a);case z.ZodUndefined:return{not:h9(a)};case z.ZodNull:return"openApi3"===a.target?{enum:["null"],nullable:!0}:{type:"null"};case z.ZodArray:let o;return o={type:"array"},t.type?._def&&t.type?._def?.typeName!==z.ZodAny&&(o.items=fy(t.type._def,{...a,currentPath:[...a.currentPath,"items"]})),t.minLength&&h3(o,"minItems",t.minLength.value,t.minLength.message,a),t.maxLength&&h3(o,"maxItems",t.maxLength.value,t.maxLength.message,a),t.exactLength&&(h3(o,"minItems",t.exactLength.value,t.exactLength.message,a),h3(o,"maxItems",t.exactLength.value,t.exactLength.message,a)),o;case z.ZodUnion:case z.ZodDiscriminatedUnion:if("openApi3"===a.target)return fg(t,a);let s=t.options instanceof Map?Array.from(t.options.values()):t.options;if(s.every(t=>t._def.typeName in ff&&(!t._def.checks||!t._def.checks.length))){let t=s.reduce((t,r)=>{let a=ff[r._def.typeName];return a&&!t.includes(a)?[...t,a]:t},[]);return{type:t.length>1?t:t[0]}}if(s.every(t=>"ZodLiteral"===t._def.typeName&&!t.description)){let t=s.reduce((t,r)=>{let a=typeof r._def.value;switch(a){case"string":case"number":case"boolean":return[...t,a];case"bigint":return[...t,"integer"];case"object":if(null===r._def.value)return[...t,"null"];default:return t}},[]);if(t.length===s.length){let r=t.filter((t,r,a)=>a.indexOf(t)===r);return{type:r.length>1?r:r[0],enum:s.reduce((t,r)=>t.includes(r._def.value)?t:[...t,r._def.value],[])}}}else if(s.every(t=>"ZodEnum"===t._def.typeName))return{type:"string",enum:s.reduce((t,r)=>[...t,...r._def.values.filter(r=>!t.includes(r))],[])};return fg(t,a);case z.ZodIntersection:let l,c,u;return l=[fy(t.left._def,{...a,currentPath:[...a.currentPath,"allOf","0"]}),fy(t.right._def,{...a,currentPath:[...a.currentPath,"allOf","1"]})].filter(t=>!!t),c="jsonSchema2019-09"===a.target?{unevaluatedProperties:!1}:void 0,u=[],l.forEach(t=>{if((!("type"in t)||"string"!==t.type)&&"allOf"in t)u.push(...t.allOf),void 0===t.unevaluatedProperties&&(c=void 0);else{let r=t;if("additionalProperties"in t&&!1===t.additionalProperties){let{additionalProperties:a,...i}=t;r=i}else c=void 0;u.push(r)}}),u.length?{allOf:u,...c}:void 0;case z.ZodTuple:return t.rest?{type:"array",minItems:t.items.length,items:t.items.map((t,r)=>fy(t._def,{...a,currentPath:[...a.currentPath,"items",`${r}`]})).reduce((t,r)=>void 0===r?t:[...t,r],[]),additionalItems:fy(t.rest._def,{...a,currentPath:[...a.currentPath,"additionalItems"]})}:{type:"array",minItems:t.items.length,maxItems:t.items.length,items:t.items.map((t,r)=>fy(t._def,{...a,currentPath:[...a.currentPath,"items",`${r}`]})).reduce((t,r)=>void 0===r?t:[...t,r],[])};case z.ZodRecord:return fh(t,a);case z.ZodLiteral:let d;return"bigint"!=(d=typeof t.value)&&"number"!==d&&"boolean"!==d&&"string"!==d?{type:Array.isArray(t.value)?"array":"object"}:"openApi3"===a.target?{type:"bigint"===d?"integer":d,enum:[t.value]}:{type:"bigint"===d?"integer":d,const:t.value};case z.ZodEnum:return{type:"string",enum:Array.from(t.values)};case z.ZodNativeEnum:let p,m,h;return p=t.values,{type:1===(h=Array.from(new Set((m=Object.keys(t.values).filter(t=>"number"!=typeof p[p[t]]).map(t=>p[t])).map(t=>typeof t)))).length?"string"===h[0]?"string":"number":["string","number"],enum:m};case z.ZodNullable:if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(t.innerType._def.typeName)&&(!t.innerType._def.checks||!t.innerType._def.checks.length))return"openApi3"===a.target?{type:ff[t.innerType._def.typeName],nullable:!0}:{type:[ff[t.innerType._def.typeName],"null"]};if("openApi3"===a.target){let r=fy(t.innerType._def,{...a,currentPath:[...a.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}let f=fy(t.innerType._def,{...a,currentPath:[...a.currentPath,"anyOf","0"]});return f&&{anyOf:[f,{type:"null"}]};case z.ZodOptional:if(a.currentPath.toString()===a.propertyPath?.toString())return fy(t.innerType._def,a);let g=fy(t.innerType._def,{...a,currentPath:[...a.currentPath,"anyOf","1"]});return g?{anyOf:[{not:h9(a)},g]}:h9(a);case z.ZodMap:if("record"===a.mapStrategy)return fh(t,a);return{type:"array",maxItems:125,items:{type:"array",items:[fy(t.keyType._def,{...a,currentPath:[...a.currentPath,"items","items","0"]})||h9(a),fy(t.valueType._def,{...a,currentPath:[...a.currentPath,"items","items","1"]})||h9(a)],minItems:2,maxItems:2}};case z.ZodSet:let y;return y={type:"array",uniqueItems:!0,items:fy(t.valueType._def,{...a,currentPath:[...a.currentPath,"items"]})},t.minSize&&h3(y,"minItems",t.minSize.value,t.minSize.message,a),t.maxSize&&h3(y,"maxItems",t.maxSize.value,t.maxSize.message,a),y;case z.ZodLazy:return()=>t.getter()._def;case z.ZodPromise:return fy(t.type._def,a);case z.ZodNaN:case z.ZodNever:return"openAi"===a.target?void 0:{not:h9({...a,currentPath:[...a.currentPath,"not"]})};case z.ZodEffects:return"input"===a.effectStrategy?fy(t.schema._def,a):h9(a);case z.ZodAny:case z.ZodUnknown:return h9(a);case z.ZodDefault:return{...fy(t.innerType._def,a),default:t.defaultValue()};case z.ZodBranded:return h6(t,a);case z.ZodReadonly:case z.ZodCatch:return fy(t.innerType._def,a);case z.ZodPipeline:if("input"===a.pipeStrategy)return fy(t.in._def,a);if("output"===a.pipeStrategy)return fy(t.out._def,a);let v=fy(t.in._def,{...a,currentPath:[...a.currentPath,"allOf","0"]}),_=fy(t.out._def,{...a,currentPath:[...a.currentPath,"allOf",v?"1":"0"]});return{allOf:[v,_].filter(t=>void 0!==t)};case z.ZodFunction:case z.ZodVoid:case z.ZodSymbol:default:return}})(t,t.typeName,r),s="function"==typeof o?fy(o(),r):o;if(s&&f_(t,r,s),r.postProcess){let a=r.postProcess(s,t,r);return n.jsonSchema=s,a}return n.jsonSchema=s,s}let fv=(t,r)=>{switch(r.$refStrategy){case"root":return{$ref:t.path.join("/")};case"relative":return{$ref:h2(r.currentPath,t.path)};case"none":case"seen":if(t.path.length<r.currentPath.length&&t.path.every((t,a)=>r.currentPath[a]===t))return console.warn(`Recursive reference detected at ${r.currentPath.join("/")}! Defaulting to any`),h9(r);return"seen"===r.$refStrategy?h9(r):void 0}},f_=(t,r,a)=>(t.description&&(a.description=t.description,r.markdownDescription&&(a.markdownDescription=t.description)),a);function fb(t,r={}){let{strict:a=!1}=r,i=Object.entries(t),n=t=>({target:r})=>{let n={},o=[];for(let[a,s]of i)n[a]=function(t,r,a){let i=t["~standard"];if(i.jsonSchema)return i.jsonSchema[a]({target:r});if("zod"===t["~standard"].vendor&&!("_zod"in t)&&"_def"in t){let a=((t,r)=>{let a,i,n=(i=void 0!==(a="string"==typeof r?{...mJ,name:r}:{...mJ,...r}).name?[...a.basePath,a.definitionPath,a.name]:a.basePath,{...a,flags:{hasReferencedOpenAiAnyType:!1},currentPath:i,propertyPath:void 0,seen:new Map(Object.entries(a.definitions).map(([t,r])=>[r._def,{def:r._def,path:[...a.basePath,a.definitionPath,t],jsonSchema:void 0}]))}),o="object"==typeof r&&r.definitions?Object.entries(r.definitions).reduce((t,[r,a])=>({...t,[r]:fy(a._def,{...n,currentPath:[...n.basePath,n.definitionPath,r]},!0)??h9(n)}),{}):void 0,s="string"==typeof r?r:r?.nameStrategy==="title"?void 0:r?.name,l=fy(t._def,void 0===s?n:{...n,currentPath:[...n.basePath,n.definitionPath,s]},!1)??h9(n),c="object"==typeof r&&void 0!==r.name&&"title"===r.nameStrategy?r.name:void 0;void 0!==c&&(l.title=c),n.flags.hasReferencedOpenAiAnyType&&(o||(o={}),o[n.openAiAnyTypeName]||(o[n.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:"relative"===n.$refStrategy?"1":[...n.basePath,n.definitionPath,n.openAiAnyTypeName].join("/")}}));let u=void 0===s?o?{...l,[n.definitionPath]:o}:l:{$ref:[..."relative"===n.$refStrategy?[]:n.basePath,n.definitionPath,s].join("/"),[n.definitionPath]:{...o,[s]:l}};return"jsonSchema7"===n.target?u.$schema="http://json-schema.org/draft-07/schema#":("jsonSchema2019-09"===n.target||"openAi"===n.target)&&(u.$schema="https://json-schema.org/draft/2019-09/schema#"),"openAi"===n.target&&("anyOf"in u||"oneOf"in u||"allOf"in u||"type"in u&&Array.isArray(u.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),u})(t,{$refStrategy:"none",target:"openapi-3.0"===r?"openApi3":"jsonSchema7"});return delete a.$schema,a}if("zod"===i.vendor&&"_zod"in t)try{let r=a8(t);return delete r.$schema,r}catch(t){throw Error(`Failed to convert a zod schema to JSON Schema (zod v4 without "~standard.jsonSchema"). Upgrade to zod >= 4.2.0. Original error: ${t instanceof Error?t.message:String(t)}`)}throw Error(`Schema library "${i.vendor}" cannot be converted to JSON Schema. Use zod v3 (>= 3.25.76), zod >= 4.2.0, or a Standard Schema library implementing "~standard.jsonSchema".`)}(s,r,t),!function(t,r){if("function"!=typeof t.safeParse)return!1;try{let a=t.safeParse(void 0);return a.success&&("input"===r||void 0===a.data)}catch{return!1}}(s,t)&&o.push(a);let s={type:"object",properties:n};return o.length>0&&(s.required=o),a&&(s.additionalProperties=!1),s},o=async r=>{if("object"!=typeof r||null===r||Array.isArray(r))return{issues:[{message:"Expected an object."}]};let n={},o=[];for(let[t,a]of i){let i=await a["~standard"].validate(r[t]);if(i.issues)for(let r of i.issues)o.push({message:r.message,path:[t,...r.path??[]]});else(t in r||void 0!==i.value)&&(n[t]=i.value)}if(a)for(let a of Object.keys(r))a in t||o.push({message:`Unrecognized key: "${a}"`,path:[a]});return o.length>0?{issues:o}:{value:n}};return{shape:t,"~standard":{version:1,vendor:"xmcp",validate:o,jsonSchema:{input:n("input"),output:n("output")}}}}function fS(t){let r={};return!function t(a,i=""){if(a&&"object"==typeof a)for(let[n,o]of Object.entries(a)){let a=i?`${i}/${n}`:n;!o||"object"!=typeof o||Array.isArray(o)||o instanceof Date||o instanceof RegExp?r[a]=o:t(o,a)}}(t),r}let f$=["ui/resourceUri","resourceUri","visibility"],fw=["prefersBorder","domain","csp","permissions","connectDomains","resourceDomains","frameDomains","baseUriDomains"];function fR(t){return"object"==typeof t&&null!==t&&Object.entries(t).every(([t,r])=>"string"==typeof t&&"object"==typeof r&&null!==r&&"parse"in r&&"function"==typeof r.parse)}function fk(t){return(t.split("/").pop()||t).replace(/\.[^/.]+$/,"")}function fx(t,r,a){return t.names?.includes(r)===!0||t.tags?.some(t=>a.includes(t))===!0}function fP(t,r){return r?new Map([...t].filter(([t,{metadata:a}])=>{if(a?.enabled===!1)return!1;let i=a?.name??fk(t),n=a?.tags??[];return(!r.include||fx(r.include,i,n))&&(!r.exclude||!fx(r.exclude,i,n))})):t}function fE(t){return Error(`[xmcp] Invalid prompt file: ${t}
82
+ -> Default export must be a prompt handler function.`)}async function fT(t){let r=new Map,a=[];for(let i of(await Promise.all(Object.entries(t).map(async([t,r])=>{let a=await r(),i=function(t,r){if("object"!=typeof t||null===t)throw fE(r);let a=Object.keys(t),i=t.default,n=a.filter(t=>"__esModule"!==t);if(0===a.length||1===n.length&&"default"===n[0]&&"object"==typeof i&&null!==i&&0===Object.keys(i).length)return"empty";if(!("default"in t)||void 0===t.default)return"missing-default";if("function"!=typeof t.default)throw fE(r);return"valid"}(a,t);return"empty"===i?{skipped:!0,issue:{path:t,message:"File is empty."}}:"missing-default"===i?{skipped:!0,issue:{path:t,message:"File does not export a default prompt handler."}}:{skipped:!1,path:t,promptModule:a}})))){if(i.skipped){a.push(i.issue);continue}r.set(i.path,i.promptModule)}return{promptModules:r,skippedPrompts:a}}let fj=function(t=console){let r="";return a=>{let i=a.map(({path:t,message:r})=>`${t}:${r}`).sort().join("|");if(i===r||(r=i,0===a.length))return;a.forEach(({path:r,message:a})=>{t.warn(`[xmcp] Failed to load prompt file: ${r}
83
+ -> ${a}`)});let n=a.length;t.warn(`[xmcp] ${n} prompt${1===n?"":"s"} skipped due to empty files or missing default exports`)}}();function fO(t){return Error(`[xmcp] Invalid resource file: ${t}
84
+ -> Default export must be a resource handler function.`)}async function fC(t){let r=new Map,a=[];for(let i of(await Promise.all(Object.entries(t).map(async([t,r])=>{let a=await r(),i=function(t,r){if("object"!=typeof t||null===t)throw fO(r);let a=Object.keys(t),i=t.default,n=a.filter(t=>"__esModule"!==t);if(0===a.length||1===n.length&&"default"===n[0]&&"object"==typeof i&&null!==i&&0===Object.keys(i).length)return"empty";if(!("default"in t)||void 0===t.default)return"missing-default";if("function"!=typeof t.default)throw fO(r);return"valid"}(a,t);return"empty"===i?{skipped:!0,issue:{path:t,message:"File is empty."}}:"missing-default"===i?{skipped:!0,issue:{path:t,message:"File does not export a default resource handler."}}:{skipped:!1,path:t,resourceModule:a}})))){if(i.skipped){a.push(i.issue);continue}r.set(i.path,i.resourceModule)}return{resourceModules:r,skippedResources:a}}let fI=function(t=console){let r="";return a=>{let i=a.map(({path:t,message:r})=>`${t}:${r}`).sort().join("|");if(i===r||(r=i,0===a.length))return;a.forEach(({path:r,message:a})=>{t.warn(`[xmcp] Failed to load resource file: ${r}
85
+ -> ${a}`)});let n=a.length;t.warn(`[xmcp] ${n} resource${1===n?"":"s"} skipped due to empty files or missing default exports`)}}();function fN(t){let r=t.replace(/\\/g,"/");if(!r)throw Error("Invalid tool path: path is empty");let a=r.replace(/\.[^/.]+$/,"").replace(/\//g,"_");return{normalizedPath:r,baseName:a}}function fq(t){let r=t.split("/").filter(t=>""!==t),a=r.findIndex(t=>t.match(/^\(.+\)$/));if(-1===a)return null;let i=r[r.length-1];if(i&&i.match(/^\[.+\]\.ts$/))return null;let n=r[a].slice(1,-1),o=r.slice(a+1),s=o[o.length-1];if(s&&s.includes(".")){let t=s.split(".")[0];"index"!==t?o[o.length-1]=t:o.pop()}let l=[],c=[],u=o.map(t=>{if(!t.match(/^\[.+\]$/))return c.push(t),t;{let r=t.slice(1,-1);return l.push(r),`{${r}}`}}),d=`${n}://${u.join("/")}`,p=l.length>0?"template":"direct";return{filePath:t,uriTemplate:d,scheme:n,parameters:l,pathSegments:c,type:p}}let fA={ttlMs:0,cacheScope:"private"},fM=h1({cursor:h0().optional()}).passthrough().optional(),fz=h1({uri:h0()}).passthrough();function fL({uri:t,frontmatter:r,files:a}){return{uri:t,frontmatter:r,resources:a.map(({uri:t,digest:r,size:a})=>({uri:t,digest:r,size:a}))}}function fZ(t){return Error(`[xmcp] Invalid tool file: ${t}
86
+ -> Default export must be a tool handler function.`)}async function fD(t){let r=new Map,a=[];for(let i of(await Promise.all(Object.entries(t).map(async([t,r])=>{let a=await r(),i=function(t,r){if("object"!=typeof t||null===t)throw fZ(r);let a=Object.keys(t),i=t.default,n=a.filter(t=>"__esModule"!==t);if(0===a.length||1===n.length&&"default"===n[0]&&"object"==typeof i&&null!==i&&0===Object.keys(i).length)return"empty";if(!("default"in t)||void 0===t.default)return"missing-default";if("function"!=typeof t.default)throw fZ(r);return"valid"}(a,t);return"empty"===i?{skipped:!0,issue:{path:t,message:"File is empty."}}:"missing-default"===i?{skipped:!0,issue:{path:t,message:"File does not export a default tool handler."}}:{skipped:!1,path:t,toolModule:a}})))){if(i.skipped){a.push(i.issue);continue}r.set(i.path,i.toolModule)}return{toolModules:r,skippedTools:a}}let fV=function(t=console){let r="";return a=>{let i=a.map(({path:t,message:r})=>`${t}:${r}`).sort().join("|");if(i===r||(r=i,0===a.length))return;a.forEach(({path:r,message:a})=>{t.warn(`[xmcp] Failed to load tool file: ${r}
87
+ -> ${a}`)});let n=a.length;t.warn(`[xmcp] ${n} tool${1===n?"":"s"} skipped due to empty files or missing default exports`)}}(),fU=INJECTED_TOOLS,fF=INJECTED_PROMPTS,fH=INJECTED_RESOURCES,fJ="undefined"==typeof INJECTED_SKILLS?[]:INJECTED_SKILLS??[],fB=SERVER_INFO;async function fK(t,r,a,i){let o=await INJECTED_MIDDLEWARE?.(),s=function(t){if(void 0===t)return[];let r=Array.isArray(t)?[...t]:[t];if(!r.every(t=>"function"==typeof t))throw Error("src/middleware.ts must export mcp as a function or an array of functions");return r}(o?.mcp),l="undefined"!=typeof OBSERVABILITY_CONFIG&&OBSERVABILITY_CONFIG.enabled?function(t=t=>console.error(t)){let r=new Map,a=[];function i(r){try{t(JSON.stringify({"@timestamp":new Date().toISOString(),...r}))}catch{}}return{middleware:async(t,n)=>{let o,s,l;if("tools/call"!==t.method&&"prompts/get"!==t.method&&"resources/read"!==t.method)return n();try{s=performance.now(),o={log:{level:"info"},...function(t){let r=t.http?.headers.traceparent;if("string"!=typeof r)return{};let a=/^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/.exec(r);return!a||"ff"===a[1]||/^0+$/.test(a[2])||/^0+$/.test(a[3])||"00"===a[1]&&void 0!==a[5]?{}:{trace:{id:a[2]},parent:{id:a[3]}}}(t),transaction:{id:crypto.randomUUID()},...t.http?{http:{request:{id:t.http.id}}}:{},xmcp:{method:t.method,component:"resources/read"===t.method?function(t){try{let i=new URL(t).href;return r.get(i)??a.find(({template:t})=>t.uriTemplate.match(i))?.name??"unknown"}catch{return"unknown"}}(t.params.uri):t.params.name}}}catch{return n()}i({...o,event:{kind:"event",category:["api"],type:["start"],action:"execution.start"}});let c="unknown";try{let r=await n();try{c=t.signal.aborted?"cancelled":cX(r)?"input_required":"isError"in r&&!0===r.isError?"failure":"success","failure"===c&&(l={message:"Operation returned an error result"})}catch{}return r}catch(r){throw l={message:"cancelled"==(c=t.signal.aborted?"cancelled":"failure")?"Operation cancelled":"Operation threw an exception"},r}finally{try{i({...o,log:{level:"failure"===c?"error":"info"},event:{kind:"event",category:["api"],type:["end"],action:"execution.end",duration:Math.round((performance.now()-s)*1e6),outcome:"success"===c?"success":"failure"===c?"failure":"unknown"},xmcp:{...o.xmcp,status:c},...l?{error:l}:{}})}catch{}}},registerResource(t,i){try{"string"==typeof i?r.set(new URL(i).href,t):a.push({name:t,template:i})}catch{}}}}():void 0;l&&s.unshift(l.middleware),mp.clear();let c="undefined"==typeof COMPONENTS_CONFIG?void 0:COMPONENTS_CONFIG;return!function(t,r,a){let i=t.server,n=i.setRequestHandler,o=mV(r);i.setRequestHandler=(t,...r)=>{if(mU.has(t)&&1===r.length&&"function"==typeof r[0]){let t=r[0];r[0]=(r,a)=>o({method:r.method,params:r.params??{}},a,()=>t(r,a))}Reflect.apply(n,i,[t,...r])};try{a()}finally{i.setRequestHandler=n}}(t,s,()=>{var o,u;!function(t,r,a=[]){r.forEach((r,i)=>{var n,o;let s,l,c,u,d={name:fk(i),description:"No description provided"},{default:p,metadata:m,schema:h,outputSchema:f}=r;if("object"==typeof m&&null!==m&&Object.assign(d,m),!1===d.enabled)return;if("function"==typeof p&&"__x402"in p){let t=global.__XMCP_X402_REGISTRY;t&&t.set(d.name,p.__x402)}let g={};if(fR(h)?g=h:null!=h&&console.warn(`Invalid schema for tool "${d.name}" at ${i}. Expected Record<string, z.ZodType>`),null!=f)if(fR(f))s=f;else throw Error(`Invalid outputSchema for tool "${d.name}" at ${i}. Expected Record<string, z.ZodType>`);d.annotations={...d.annotations??{}},void 0===d.annotations.title&&(d.annotations.title=d.name),d._meta={...md(d)._meta};let y=mF(i),v=!!(n=d._meta)&&"object"==typeof n&&"ui"in n&&"object"==typeof n.ui||y,_=d._meta;if(v){let t=`ui://app/${d.name}.html`;d._meta.ui||(d._meta.ui={}),d._meta.ui.resourceUri||(d._meta.ui.resourceUri=t);let r=function(t){let r={},a={};if(t.ui&&"object"==typeof t.ui){let i=t.ui,n={},o={};for(let[t,r]of Object.entries(i))f$.includes(t)?n[t]=r:fw.includes(t)?o[t]=r:n[t]=r;Object.keys(n).length>0&&(r.ui=n),Object.keys(o).length>0&&(a.ui=o)}for(let[a,i]of Object.entries(t))"ui"!==a&&(r[a]=i);return{toolMeta:r,resourceMeta:a}}(_);_=r.toolMeta;let a=r.resourceMeta;a.ui=a.ui||{},a.ui.csp=a.ui.csp||{},a.ui.csp.resourceDomains=a.ui.csp.resourceDomains||[],a.ui.csp.resourceDomains.includes("https://esm.sh")||a.ui.csp.resourceDomains.push("https://esm.sh"),mp.add(d.name,{name:d.name,uri:t,handler:p,mimeType:"text/html;profile=mcp-app",_meta:a,toolPath:y?i:void 0})}let b=fS(_),S=v?b:void 0;l=mF(i)&&v?async(t,r)=>({content:[{type:"text",text:""}],_meta:S,structuredContent:{args:t}}):function(t,r,a,i="unknown-tool"){return async(n,o)=>{let s,l,c=t(n,(s=mD(o),l=function(t){if(!t)return;let r={};return t.headers.forEach((t,a)=>{r[a]=t}),r}(o.http?.req),{signal:o.mcpReq.signal,authInfo:o.http?.authInfo,sessionId:o.sessionId,_meta:o.mcpReq._meta,requestId:o.mcpReq.id,requestInfo:l?{headers:l}:void 0,clientInfo:s,sendNotification:t=>o.mcpReq.notify(t),sendRequest:(t,r,a)=>o.mcpReq.send(t,r,a),elicit:(t,r)=>mR(o,t,r),sample:(t,r)=>mq(o,t,r),inputResponses:o.mcpReq.inputResponses,requestState:o.mcpReq.requestState}));if(c instanceof Promise&&(c=await c),cX(c))return c;if("string"==typeof c||"number"==typeof c){if(a){let t=Object.entries(a);if(1===t.length){let[r,a]=t[0];try{return a.parse(c),{content:[{type:"text",text:"number"==typeof c?`${c}`:c}],structuredContent:{[r]:c}}}catch{}}}return mZ(r)?{content:[{type:"text",text:""}],structuredContent:{args:n},_meta:r}:{content:[{type:"text",text:"number"==typeof c?`${c}`:c}]}}if(!a||!c||"object"!=typeof c||Array.isArray(c)||"structuredContent"in c||"content"in c&&Array.isArray(c.content)||"_meta"in c||"isError"in c||(mL(c,a,i,"returned data that does not match outputSchema"),c={structuredContent:c}),c&&"object"==typeof c&&"_meta"in c&&!("content"in c)&&!("structuredContent"in c)){let t=c._meta;if(mZ(t))return{content:[{type:"text",text:""}],_meta:t}}if(!c||"object"!=typeof c){let t=null===c?"null":typeof c,r=void 0===c?"undefined":null===c?"null":"object"==typeof c?JSON.stringify(c,null,2):String(c);throw Error(`Tool handler must return a CallToolResult, string, or number. Got ${t}: ${r}
88
88
 
89
89
  Expected CallToolResult format:
90
90
  {
@@ -151,7 +151,7 @@ Expected format:
151
151
  key: "value",
152
152
  nested: { data: "here" }
153
153
  }
154
- }`)}}return c}}(p,S,s,d.name);let $={title:d.annotations?.title,description:d.description,inputSchema:fv(g),outputSchema:s?fv(s,{strict:!0}):void 0,annotations:d.annotations,icons:d.icons,_meta:b};t.registerTool(d.name,$,(o={name:d.name,description:$.description,annotations:$.annotations,icons:$.icons,tags:d.tags,_meta:$._meta},c=mV(a),u=Object.freeze({metadata:function t(r,a=new WeakMap){if(null===r||"object"!=typeof r)return r;let i=Object.getPrototypeOf(r);if(!Array.isArray(r)&&i!==Object.prototype&&null!==i)return r;if(a.has(r))return a.get(r);let n=Array.isArray(r)?[]:Object.create(i);for(let[i,o]of(a.set(r,n),Object.entries(r)))Object.defineProperty(n,i,{value:t(o,a),enumerable:!0,configurable:!0,writable:!0});return Object.freeze(n)}(o)}),(t,r)=>c({method:"tools/call",params:{name:u.metadata.name,arguments:t},tool:u},r,()=>l(t,r))))})}(t,fk(r,c),s),fk(a,c).forEach((r,a)=>{let i=fw(a),n={name:i,title:i,description:"No description provided"},o={},{default:s,metadata:l,schema:c}=r;if("object"==typeof l&&null!==l&&Object.assign(n,l),!1===n.enabled)return;let u=function(t,r="assistant"){return async(a,i)=>{let n,o=t(a,i);if(o instanceof Promise&&(o=await o),Array.isArray(o)||null!==o&&"object"==typeof o&&"messages"in o){let t=Array.isArray(o)?{messages:o}:o,r=await uR.GetPromptResult["~standard"].validate(t);if(r.issues){let t=r.issues.map(t=>{let r=t.path?.map(t=>"object"==typeof t?t.key:t).join(".");return`${r||"result"}: ${t.message}`});throw Error(`Invalid prompt result: ${t.join("; ")}`)}return t}if("string"==typeof o||"number"==typeof o)n={type:"text",text:"number"==typeof o?`${o}`:o};else{let t=mz(o);if(t.valid)n=o;else{let r=null===o?"null":typeof o,a=void 0===o?"undefined":null===o?"null":"object"==typeof o?JSON.stringify(o,null,2):String(o);throw Error(`Prompt handler must return a PromptContent object, string, number, PromptMessage[], or GetPromptResult. Got ${r}: ${a}
154
+ }`)}}return c}}(p,S,s,d.name);let $={title:d.annotations?.title,description:d.description,inputSchema:fb(g),outputSchema:s?fb(s,{strict:!0}):void 0,annotations:d.annotations,icons:d.icons,_meta:b};t.registerTool(d.name,$,(o={name:d.name,description:$.description,annotations:$.annotations,icons:$.icons,tags:d.tags,_meta:$._meta},c=mV(a),u=Object.freeze({metadata:function t(r,a=new WeakMap){if(null===r||"object"!=typeof r)return r;let i=Object.getPrototypeOf(r);if(!Array.isArray(r)&&i!==Object.prototype&&null!==i)return r;if(a.has(r))return a.get(r);let n=Array.isArray(r)?[]:Object.create(i);for(let[i,o]of(a.set(r,n),Object.entries(r)))Object.defineProperty(n,i,{value:t(o,a),enumerable:!0,configurable:!0,writable:!0});return Object.freeze(n)}(o)}),(t,r)=>c({method:"tools/call",params:{name:u.metadata.name,arguments:t},tool:u},r,()=>l(t,r))))})}(t,fP(r,c),s),fP(a,c).forEach((r,a)=>{let i=fk(a),n={name:i,title:i,description:"No description provided"},o={},{default:s,metadata:l,schema:c}=r;if("object"==typeof l&&null!==l&&Object.assign(n,l),!1===n.enabled)return;let u=function(t,r="assistant"){return async(a,i)=>{let n,o=t(a,i);if(o instanceof Promise&&(o=await o),Array.isArray(o)||null!==o&&"object"==typeof o&&"messages"in o){let t=Array.isArray(o)?{messages:o}:o,r=await uR.GetPromptResult["~standard"].validate(t);if(r.issues){let t=r.issues.map(t=>{let r=t.path?.map(t=>"object"==typeof t?t.key:t).join(".");return`${r||"result"}: ${t.message}`});throw Error(`Invalid prompt result: ${t.join("; ")}`)}return t}if("string"==typeof o||"number"==typeof o)n={type:"text",text:"number"==typeof o?`${o}`:o};else{let t=mz(o);if(t.valid)n=o;else{let r=null===o?"null":typeof o,a=void 0===o?"undefined":null===o?"null":"object"==typeof o?JSON.stringify(o,null,2):String(o);throw Error(`Prompt handler must return a PromptContent object, string, number, PromptMessage[], or GetPromptResult. Got ${r}: ${a}
155
155
 
156
156
  Validation error: ${t.error}
157
157
 
@@ -164,7 +164,7 @@ Expected formats:
164
164
  - Image content: { type: "image", data: "base64data", mimeType: "image/jpeg" }
165
165
  - Audio content: { type: "audio", data: "base64data", mimeType: "audio/mpeg" }
166
166
  - Resource link: { type: "resource_link", name: "resource name", uri: "resource://uri" }
167
- - All content types support an optional "_meta" object property`)}}if("user"!==r&&"assistant"!==r)throw Error(`Invalid role: ${r}`);return{messages:[{role:r,content:n}]}}}(s,n.role||"assistant");f$(c)?Object.assign(o,c):null!=c&&console.warn(`Invalid schema for prompt "${n.name}" at ${a}. Expected Record<string, z.ZodType>`),t.registerPrompt(n.name,{title:n.title,description:n.description,icons:n.icons,_meta:md(n)._meta,argsSchema:fv(o)},u)}),o=fk(i,c),u=l?.registerResource,[...mp.getAll()].forEach(([r,a])=>{let i=a.mimeType||"text/html;profile=mcp-app",o=a?._meta?f_(a._meta):void 0,s={name:a.name,description:`Auto-generated resource for ${a.name} tool`,mimeType:a.mimeType,_meta:o},l=async(t,r)=>{if(a.mimeType&&a.toolPath)try{var o;let t,r,s=(o=a.toolPath,IS_CLOUDFLARE?function(t){let{normalizedPath:r,baseName:a}=fC(t),i=5381;for(let t=0;t<r.length;t++)i=Math.imul(i,33)+r.charCodeAt(t)>>>0;let n=i.toString(16).slice(0,6).padStart(6,"0");return`${a}_${n}`}(o):function(t){let{normalizedPath:r,baseName:a}=fC(t),i=n(6982).createHash("md5").update(r).digest("hex").slice(0,6);return`${a}_${i}`}(o)),l=function(t){if(INJECTED_CLIENT_BUNDLES)return INJECTED_CLIENT_BUNDLES[t]||null;if(!IS_CLOUDFLARE)try{let r=n(9896),a=n(6928);for(let i of[a.join(process.cwd(),"dist","client"),a.join(process.cwd(),"client")]){let n=a.join(i,`${t}.bundle.js`),o=a.join(i,`${t}.bundle.css`);if(r.existsSync(n)){let t,a=r.readFileSync(n,"utf-8");return r.existsSync(o)&&(t=r.readFileSync(o,"utf-8")),{js:a,css:t}}}}catch{}return null}(s);if(!l)throw Error(`React client bundle not found for "${a.name}" (bundle: "${s}").
167
+ - All content types support an optional "_meta" object property`)}}if("user"!==r&&"assistant"!==r)throw Error(`Invalid role: ${r}`);return{messages:[{role:r,content:n}]}}}(s,n.role||"assistant");fR(c)?Object.assign(o,c):null!=c&&console.warn(`Invalid schema for prompt "${n.name}" at ${a}. Expected Record<string, z.ZodType>`),t.registerPrompt(n.name,{title:n.title,description:n.description,icons:n.icons,_meta:md(n)._meta,argsSchema:fb(o)},u)}),o=fP(i,c),u=l?.registerResource,[...mp.getAll()].forEach(([r,a])=>{let i=a.mimeType||"text/html;profile=mcp-app",o=a?._meta?fS(a._meta):void 0,s={name:a.name,description:`Auto-generated resource for ${a.name} tool`,mimeType:a.mimeType,_meta:o},l=async(t,r)=>{if(a.mimeType&&a.toolPath)try{var o;let t,r,s=(o=a.toolPath,IS_CLOUDFLARE?function(t){let{normalizedPath:r,baseName:a}=fN(t),i=5381;for(let t=0;t<r.length;t++)i=Math.imul(i,33)+r.charCodeAt(t)>>>0;let n=i.toString(16).slice(0,6).padStart(6,"0");return`${a}_${n}`}(o):function(t){let{normalizedPath:r,baseName:a}=fN(t),i=n(6982).createHash("md5").update(r).digest("hex").slice(0,6);return`${a}_${i}`}(o)),l=function(t){if(INJECTED_CLIENT_BUNDLES)return INJECTED_CLIENT_BUNDLES[t]||null;if(!IS_CLOUDFLARE)try{let r=n(9896),a=n(6928);for(let i of[a.join(process.cwd(),"dist","client"),a.join(process.cwd(),"client")]){let n=a.join(i,`${t}.bundle.js`),o=a.join(i,`${t}.bundle.css`);if(r.existsSync(n)){let t,a=r.readFileSync(n,"utf-8");return r.existsSync(o)&&(t=r.readFileSync(o,"utf-8")),{js:a,css:t}}}}catch{}return null}(s);if(!l)throw Error(`React client bundle not found for "${a.name}" (bundle: "${s}").
168
168
  React tool bundles are generated automatically when you run "xmcp build" (or "xmcp dev").
169
169
  Please re-run the build so the framework can regenerate the bundle.`);let c=l.js,u=l.css,d=(t=`
170
170
  <script type="module">
@@ -219,7 +219,7 @@ Please re-run the build so the framework can regenerate the bundle.`);let c=l.js
219
219
  <div id="root"></div>
220
220
  ${t}
221
221
  </body>
222
- </html>`);return{contents:[{uri:a.uri,text:d,mimeType:i,_meta:a._meta}]}}catch(t){throw console.error(`React failed for ${a.name}:`,t),t}let s=a.handler({},r);if(s instanceof Promise&&(s=await s),"string"==typeof s)return{contents:[{uri:a.uri,text:s,mimeType:i,_meta:a._meta}]};if(s&&"object"==typeof s&&"_meta"in s&&!("content"in s))return{contents:[{uri:a.uri,text:"",mimeType:i,_meta:a._meta}]};if(s&&"object"==typeof s&&"content"in s&&Array.isArray(s.content)){let t=s.content.find(t=>"text"===t.type);if(t&&"text"===t.type&&"string"==typeof t.text)return{contents:[{uri:a.uri,text:t.text,mimeType:i,_meta:a._meta}]}}return{contents:[{uri:a.uri,text:"",mimeType:i,_meta:a._meta}]}};u?.(a.name,a.uri),t.registerResource(a.name,a.uri,s,l)}),o.forEach((r,a)=>{let i={name:fw(a),description:"No description provided"},{default:n,metadata:o,schema:s,complete:l}=r;if("object"==typeof o&&null!==o&&Object.assign(i,o),!1===i.enabled)return;let c={};f$(s)?c=s:null!=s&&console.warn(`Invalid schema for resource "${i.name}" at ${a}. Expected Record<string, z.ZodType>`);let d=fI(a);if(!d)return void console.warn(`Skipping resource "${i.name}" at ${a}: Invalid file path format`);let p=d.uriTemplate;i.mimeType&&i.mimeType.includes("html")&&(p=p.endsWith(".html")?p:`${p}.html`);let m=function(t,r,a={}){let i=fI(r);if(!i)throw Error(`Invalid resource file path: ${r}. Must follow (scheme)/path/[param] convention.`);return async(r,n)=>{let o=t(function(t,r,a){let i={},n={};if(0===r.parameters.length)return n;let o=r.uriTemplate.split("://")[1]||"",s=t.split("://")[1]||"",l=o.split("/"),c=s.split("/");for(let t=0;t<l.length&&t<c.length;t++){let r=l[t],a=c[t],n=r.match(/^\{(.+)\}$/);n&&(i[n[1]]=a)}for(let t of r.parameters){let r=i[t],o=a[t];if(void 0===r)throw Error(`Missing required parameter: ${t}`);if(!o){n[t]=r;continue}try{n[t]=o.parse(r)}catch(a){throw Error(`Invalid parameter "${t}": ${r}. Validation error: ${a instanceof Error?a.message:String(a)}`)}}return n}(r.href,i,a),n);if(o instanceof Promise&&(o=await o),cX(o))return o;if("string"==typeof o)return{contents:[{uri:r.href,text:o}]};if(!o||"object"!=typeof o||!Array.isArray(o.contents)){let t=null===o?"null":typeof o,r=void 0===o?"undefined":null===o?"null":"object"==typeof o?JSON.stringify(o,null,2):String(o);throw Error(`Resource handler must return a ReadResourceResult, InputRequiredResult, or string. Got ${t}: ${r}
222
+ </html>`);return{contents:[{uri:a.uri,text:d,mimeType:i,_meta:a._meta}]}}catch(t){throw console.error(`React failed for ${a.name}:`,t),t}let s=a.handler({},r);if(s instanceof Promise&&(s=await s),"string"==typeof s)return{contents:[{uri:a.uri,text:s,mimeType:i,_meta:a._meta}]};if(s&&"object"==typeof s&&"_meta"in s&&!("content"in s))return{contents:[{uri:a.uri,text:"",mimeType:i,_meta:a._meta}]};if(s&&"object"==typeof s&&"content"in s&&Array.isArray(s.content)){let t=s.content.find(t=>"text"===t.type);if(t&&"text"===t.type&&"string"==typeof t.text)return{contents:[{uri:a.uri,text:t.text,mimeType:i,_meta:a._meta}]}}return{contents:[{uri:a.uri,text:"",mimeType:i,_meta:a._meta}]}};u?.(a.name,a.uri),t.registerResource(a.name,a.uri,s,l)}),o.forEach((r,a)=>{let i={name:fk(a),description:"No description provided"},{default:n,metadata:o,schema:s,complete:l}=r;if("object"==typeof o&&null!==o&&Object.assign(i,o),!1===i.enabled)return;let c={};fR(s)?c=s:null!=s&&console.warn(`Invalid schema for resource "${i.name}" at ${a}. Expected Record<string, z.ZodType>`);let d=fq(a);if(!d)return void console.warn(`Skipping resource "${i.name}" at ${a}: Invalid file path format`);let p=d.uriTemplate;i.mimeType&&i.mimeType.includes("html")&&(p=p.endsWith(".html")?p:`${p}.html`);let m=function(t,r,a={}){let i=fq(r);if(!i)throw Error(`Invalid resource file path: ${r}. Must follow (scheme)/path/[param] convention.`);return async(r,n)=>{let o=t(function(t,r,a){let i={},n={};if(0===r.parameters.length)return n;let o=r.uriTemplate.split("://")[1]||"",s=t.split("://")[1]||"",l=o.split("/"),c=s.split("/");for(let t=0;t<l.length&&t<c.length;t++){let r=l[t],a=c[t],n=r.match(/^\{(.+)\}$/);n&&(i[n[1]]=a)}for(let t of r.parameters){let r=i[t],o=a[t];if(void 0===r)throw Error(`Missing required parameter: ${t}`);if(!o){n[t]=r;continue}try{n[t]=o.parse(r)}catch(a){throw Error(`Invalid parameter "${t}": ${r}. Validation error: ${a instanceof Error?a.message:String(a)}`)}}return n}(r.href,i,a),n);if(o instanceof Promise&&(o=await o),cX(o))return o;if("string"==typeof o)return{contents:[{uri:r.href,text:o}]};if(!o||"object"!=typeof o||!Array.isArray(o.contents)){let t=null===o?"null":typeof o,r=void 0===o?"undefined":null===o?"null":"object"==typeof o?JSON.stringify(o,null,2):String(o);throw Error(`Resource handler must return a ReadResourceResult, InputRequiredResult, or string. Got ${t}: ${r}
223
223
 
224
224
  Expected ReadResourceResult format:
225
225
  {
@@ -228,10 +228,10 @@ Expected ReadResourceResult format:
228
228
  { uri: "resource://uri", mimeType: "application/json", text: "json content" },
229
229
  { uri: "resource://uri", blob: base64data }
230
230
  ]
231
- }`)}return o.contents.forEach(t=>{t.uri||(t.uri=r.href)}),o}}(n,a,c);if("direct"===d.type)u?.(i.name,p),t.registerResource(i.name,p,md(i),m);else{let r=Object.create(null);for(let t of d.parameters)l&&Object.hasOwn(l,t)&&(r[t]=l[t]);let a=new pD(p,{list:void 0,complete:r}),o=async(t,r,a)=>{let i={};for(let t of d.parameters){let a=r[t],n=c[t];if(void 0===a)throw Error(`Missing required parameter: ${t}. Available variables: ${Object.keys(r)}`);n?i[t]=n.parse(a):i[t]=a}let o=n(i,a);return o instanceof Promise&&(o=await o),"string"==typeof o?{contents:[{uri:t.href,text:o}]}:o};u?.(i.name,a),t.registerResource(i.name,a,md(i),o)}})}),t}async function fV(){let{toolModules:t,skippedTools:r}=await fq(fM);return fA(r),t}async function fU(){let{promptModules:t,skippedPrompts:r}=await fP(fz);return fE(r),t}async function fF(){let{resourceModules:t,skippedResources:r}=await fj(fL);return fO(r),t}let fH=function(t,r={}){var a;let{legacy:i,onerror:n,responseMode:o}=r,s=pQ(r.maxRequestBodySize);if("function"==typeof i)throw TypeError("The 'legacy' option only accepts 'stateless' or 'reject', not a handler function. To serve 2025-era traffic with your own handler, route in user land with the exported isLegacyRequest(request) predicate in front of a strict (legacy: 'reject') handler.");let l=new Set,c=!1,u=t=>{try{n?.(t)}catch{}},f=r.bus??new pP(u),g={toolsChanged:()=>f.publish({kind:"tools_list_changed"}),promptsChanged:()=>f.publish({kind:"prompts_list_changed"}),resourcesChanged:()=>f.publish({kind:"resources_list_changed"}),resourceUpdated:t=>f.publish({kind:"resource_updated",uri:t})},y=function(t){let{bus:r,onerror:a}=t,i=t.maxSubscriptions??1024,n=t.keepAliveMs??15e3,o=new Set;return{serve:function(t,s,l,c){var u,d,p;let m,h,f,g,y,v,_;if(o.size>=i)return a?.(Error(`subscriptions/listen refused: subscription limit reached (${i})`)),pE(t.id,-32603,"Subscription limit reached");let b=(u=t,(y=cA(cq).validateRequest("subscriptions/listen",u)).ok?y.value.params?.notifications:void 0);if(void 0===b)return pE(t.id,-32602,"Invalid params: 'notifications' is required and must be a valid SubscriptionFilter");let S=(d=b,p=l,v={},_=t=>void 0===p||!0===t,!0===d.toolsListChanged&&_(p?.tools?.listChanged)&&(v.toolsListChanged=!0),!0===d.promptsListChanged&&_(p?.prompts?.listChanged)&&(v.promptsListChanged=!0),!0===d.resourcesListChanged&&_(p?.resources?.listChanged)&&(v.resourcesListChanged=!0),void 0!==d.resourceSubscriptions&&d.resourceSubscriptions.length>0&&_(p?.resources?.subscribe)&&(v.resourceSubscriptions=[...d.resourceSubscriptions]),v),$=t.id,w=new TextEncoder,R=!1,k=t=>{if(!R)try{m.enqueue(w.encode(t))}catch(t){a?.(t instanceof Error?t:Error(String(t)))}},x=(t,r)=>{k(`event: message
231
+ }`)}return o.contents.forEach(t=>{t.uri||(t.uri=r.href)}),o}}(n,a,c);if("direct"===d.type)u?.(i.name,p),t.registerResource(i.name,p,md(i),m);else{let r=Object.create(null);for(let t of d.parameters)l&&Object.hasOwn(l,t)&&(r[t]=l[t]);let a=new pD(p,{list:void 0,complete:r}),o=async(t,r,a)=>{let i={};for(let t of d.parameters){let a=r[t],n=c[t];if(void 0===a)throw Error(`Missing required parameter: ${t}. Available variables: ${Object.keys(r)}`);n?i[t]=n.parse(a):i[t]=a}let o=n(i,a);return o instanceof Promise&&(o=await o),"string"==typeof o?{contents:[{uri:t.href,text:o}]}:o};u?.(i.name,a),t.registerResource(i.name,a,md(i),o)}}),function(t,r,a,i){let n=[...fP(new Map(r.map(t=>[t.uri,{metadata:{name:t.frontmatter.name},skill:t}])),a).values()].map(({skill:t})=>t);if(0===n.length)return;for(let{frontmatter:r,files:a}of n){let n=a[0].uri.slice(0,a[0].uri.lastIndexOf("/")+1);a.forEach(({uri:a,mimeType:o,text:s,blob:l},c)=>{let u=0===c?{mimeType:o,description:r.description}:{mimeType:o},d=0===c?r.name:`${r.name}/${decodeURIComponent(a.slice(n.length))}`,p=void 0!==s?{uri:a,mimeType:o,text:s}:{uri:a,mimeType:o,blob:l??""};i?.(d,a),t.registerResource(d,a,u,()=>({contents:[p]}))})}let o=n.map(fL),s=new Map(o.map(t=>[t.uri,t]));t.server.registerCapabilities({extensions:{"io.modelcontextprotocol/skills":{}}}),t.server.setRequestHandler("skills/list",{params:fM},t=>{let r=t?.cursor===void 0?0:function(t,r){let a=NaN;try{a=Number(atob(t))}catch{}if(!Number.isSafeInteger(a)||a<=0||a>=r)throw new cg(cf.InvalidParams,`Invalid cursor: ${t}`);return a}(t.cursor,o.length),a=r+50;return{skills:o.slice(r,a),...a<o.length?{nextCursor:btoa(String(a))}:{},...fA}}),t.server.setRequestHandler("skills/get",{params:fz},({uri:t})=>{let r=s.get(t);if(!r)throw new cg(cf.InvalidParams,`No skill is served at ${t}`);return{skill:r,...fA}})}(t,fJ,c,l?.registerResource)}),t}async function fG(){let{toolModules:t,skippedTools:r}=await fD(fU);return fV(r),t}async function fW(){let{promptModules:t,skippedPrompts:r}=await fT(fF);return fj(r),t}async function fY(){let{resourceModules:t,skippedResources:r}=await fC(fH);return fI(r),t}let fX=function(t,r={}){var a;let{legacy:i,onerror:n,responseMode:o}=r,s=pQ(r.maxRequestBodySize);if("function"==typeof i)throw TypeError("The 'legacy' option only accepts 'stateless' or 'reject', not a handler function. To serve 2025-era traffic with your own handler, route in user land with the exported isLegacyRequest(request) predicate in front of a strict (legacy: 'reject') handler.");let l=new Set,c=!1,u=t=>{try{n?.(t)}catch{}},f=r.bus??new pP(u),g={toolsChanged:()=>f.publish({kind:"tools_list_changed"}),promptsChanged:()=>f.publish({kind:"prompts_list_changed"}),resourcesChanged:()=>f.publish({kind:"resources_list_changed"}),resourceUpdated:t=>f.publish({kind:"resource_updated",uri:t})},y=function(t){let{bus:r,onerror:a}=t,i=t.maxSubscriptions??1024,n=t.keepAliveMs??15e3,o=new Set;return{serve:function(t,s,l,c){var u,d,p;let m,h,f,g,y,v,_;if(o.size>=i)return a?.(Error(`subscriptions/listen refused: subscription limit reached (${i})`)),pE(t.id,-32603,"Subscription limit reached");let b=(u=t,(y=cA(cq).validateRequest("subscriptions/listen",u)).ok?y.value.params?.notifications:void 0);if(void 0===b)return pE(t.id,-32602,"Invalid params: 'notifications' is required and must be a valid SubscriptionFilter");let S=(d=b,p=l,v={},_=t=>void 0===p||!0===t,!0===d.toolsListChanged&&_(p?.tools?.listChanged)&&(v.toolsListChanged=!0),!0===d.promptsListChanged&&_(p?.prompts?.listChanged)&&(v.promptsListChanged=!0),!0===d.resourcesListChanged&&_(p?.resources?.listChanged)&&(v.resourcesListChanged=!0),void 0!==d.resourceSubscriptions&&d.resourceSubscriptions.length>0&&_(p?.resources?.subscribe)&&(v.resourceSubscriptions=[...d.resourceSubscriptions]),v),$=t.id,w=new TextEncoder,R=!1,k=t=>{if(!R)try{m.enqueue(w.encode(t))}catch(t){a?.(t instanceof Error?t:Error(String(t)))}},x=(t,r)=>{k(`event: message
232
232
  data: ${JSON.stringify({jsonrpc:"2.0",method:t,params:r})}
233
233
 
234
234
  `)},P=t=>{if(!R){t&&k(`event: message
235
235
  data: ${JSON.stringify({jsonrpc:"2.0",id:$,result:{resultType:"complete",_meta:{[nW]:$,[nK]:c}}})}
236
236
 
237
- `),R=!0;try{h?.()}catch(t){a?.(t instanceof Error?t:Error(String(t)))}void 0!==f&&clearInterval(f),g?.(),o.delete(P);try{m.close()}catch{}}},E=new ReadableStream({start(t){m=t;let a=pT({method:"notifications/subscriptions/acknowledged",params:{notifications:S}},$);(x(a.method,a.params),0===Object.keys(S).length)?P(!0):(h=r.subscribe(t=>{if(R||!function(t,r){switch(r.kind){case"tools_list_changed":return!0===t.toolsListChanged;case"prompts_list_changed":return!0===t.promptsListChanged;case"resources_list_changed":return!0===t.resourcesListChanged;case"resource_updated":return void 0!==t.resourceSubscriptions&&t.resourceSubscriptions.includes(r.uri)}}(S,t))return;let r=pT(function(t){switch(t.kind){case"tools_list_changed":return{method:"notifications/tools/list_changed"};case"prompts_list_changed":return{method:"notifications/prompts/list_changed"};case"resources_list_changed":return{method:"notifications/resources/list_changed"};case"resource_updated":return{method:"notifications/resources/updated",params:{uri:t.uri}}}}(t),$);x(r.method,r.params)}),f=px(n,()=>k(": keepalive\n\n")),o.add(P))},cancel(){P(!1)}});if(void 0!==s)if(s.aborted)P(!1);else{let t=()=>P(!1);s.addEventListener("abort",t,{once:!0}),g=()=>s.removeEventListener("abort",t)}return new Response(E,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"}})},closeAll(){for(let t of o)t(!0)},get openCount(){return o.size}}}({bus:f,maxSubscriptions:r.maxSubscriptions??1024,keepAliveMs:r.keepAliveMs??15e3,onerror:u});"json"===o&&console.warn("responseMode: 'json' drops mid-call notifications. subscriptions/listen streams are always served over SSE regardless; other notifications emitted before a result are dropped.");let v="reject"===i?void 0:(a=r.keepAliveMs,async(r,i)=>{if("POST"!==r.method.toUpperCase())return p9(405,-32e3,"Method not allowed.");try{let n=await t({era:"legacy",...i?.authInfo!==void 0&&{authInfo:i.authInfo},requestInfo:r}),o=new p1({sessionIdGenerator:void 0,...void 0!==a&&{keepAliveMs:a},...void 0!==s&&{maxRequestBodySize:s}});await n.connect(o);let l=()=>{o.close().catch(()=>{}),n.close().catch(()=>{})};r.signal?.addEventListener("abort",l,{once:!0});let c=await o.handleRequest(r,{...i?.authInfo!==void 0&&{authInfo:i.authInfo},...i?.parsedBody!==void 0&&{parsedBody:i.parsedBody}});if(null===c.body||"text/event-stream"!==uq(c.headers.get("content-type")))return l(),c;let u=c.body.getReader(),d=!1,p=()=>{d||(d=!0,l())},m=new ReadableStream({pull:async t=>{try{let{done:r,value:a}=await u.read();if(r){p(),t.close();return}void 0!==a&&t.enqueue(a)}catch(r){p(),t.error(r)}},cancel:t=>(p(),u.cancel(t).catch(()=>{}))});return new Response(m,{status:c.status,statusText:c.statusText,headers:c.headers})}catch(t){try{u?.(p3(t))}catch{}return p6(p2(i?.parsedBody))}});async function _(a,i,n){var s,c;let f=a.classification.revision;if(void 0===f||!lY.includes(f)){let t=new c_({supported:[...lY],requested:f??"unknown"});return u(t),p9(400,t.code,t.message,t.data,p2(a.message))}let g=function(t,r){if("request"!==r.messageKind)return;let a=r.message.method;if(void 0===t.protocolVersionHeader){let t=r.classification.revision;return ua("version-header-missing","(missing)",void 0===t?"the body carries a modern per-request envelope but the required MCP-Protocol-Version header is absent":`the body envelope names protocol version ${t} but the required MCP-Protocol-Version header is absent`,"standard-header-validation")}if(void 0===t.mcpMethodHeader)return ua("method-header-missing","(missing)",`the body names method ${a} but the required Mcp-Method header is absent`,"standard-header-validation");let i=function(t,r){let a=Object.hasOwn(ui,t)?ui[t]:void 0;if(void 0===a)return;let i=uo(r)?r[a]:void 0;return{field:a,value:"string"==typeof i?i:void 0}}(a,r.message.params);if(void 0===i)return;let{field:n,value:o}=i;if(void 0===t.mcpNameHeader){if(void 0===o)return;return ua("name-header-missing","(missing)",`the body carries params.${n}="${o}" but the required Mcp-Name header is absent`,"standard-header-validation")}let s=un(t.mcpNameHeader),l=c7(s);return void 0===l?ua("name-header-invalid-encoding",s,"the Mcp-Name header carries an invalid Base64 sentinel value","standard-header-validation"):void 0!==o&&l!==o?ua("name-header-mismatch",s,`the body carries params.${n}="${o}" but the Mcp-Name header names "${l}"`,"standard-header-validation"):void 0}({httpMethod:i.method,...p7(i)},a);if(void 0!==g)return u(Error(`Rejected inbound request (${g.cell}): ${g.message}`)),p4(g,p2(a.message));let v="request"===a.messageKind?cU(a.message.params):void 0,_=v?.[nG];if("request"===a.messageKind){let t=Object.hasOwn(lB,s=a.message.method)?lB[s]:void 0;if(void 0!==t){let r=lG(t,_);if(void 0!==r){let t=new cb({requiredCapabilities:r});return u(t),p9(ut[t.code]??400,t.code,t.message,t.data,a.message.id)}}}let b=await t({era:"modern",...void 0!==n&&{authInfo:n},requestInfo:i}),S=b instanceof pZ?b.server:b;if(p5(S),"request"===a.messageKind&&"subscriptions/listen"===a.message.method){let t=S.getCapabilities(),r=h(S);return b.close().catch(u),y.serve(a.message,i.signal,t,r)}if("request"===a.messageKind&&"tools/call"===a.message.method&&b instanceof pZ){let t=a.message.params,r="string"==typeof t?.name?t.name:void 0,n=void 0===r?void 0:b.toolInputSchemaJson(r);if(void 0!==n){let r=c2(n);if(r.valid&&r.declarations.length>0){let n=function(t,r,a){for(let i of t){let t=`Mcp-Param-${i.headerName}`,n=a.get(t),o=function(t,r){let a=t;for(let t of r){if(null===a||"object"!=typeof a)return;a=a[t]}return a}(r,i.path);if(null==o)continue;let s=function(t){if("string"==typeof t)return t;if("boolean"==typeof t)return t?"true":"false";if("number"==typeof t){if(!Number.isFinite(t)||Number.isInteger(t)&&!Number.isSafeInteger(t))return;return String(t)}}(o);if(void 0===s)continue;if(null===n)return c8("param-header-missing",t,`the body carries ${c3(i.path)}=${JSON.stringify(o)} but the ${t} header is absent`);let l=c7(n);if(void 0===l)return c8("param-header-invalid-encoding",t,`the ${t} header carries an invalid Base64 sentinel value`);if(!(("integer"===i.type||"number"===i.type)&&c5.test(l)&&"number"==typeof o?Number(l)===o:l===s))return c8("param-header-mismatch",t,`the ${t} header decodes to ${JSON.stringify(l)} but the body carries ${c3(i.path)}=${JSON.stringify(o)}`)}}(r.declarations,t?.arguments,i.headers);if(void 0!==n)return b.close().catch(u),u(Error(`Rejected inbound request (${n.cell}): ${n.message}`)),p4(n,a.message.id)}}}if("request"===a.messageKind&&b instanceof pZ)try{let t=await pC([a.message],n,t=>b.resolveScopeChallenge(t));if(void 0!==t)return b.close().catch(u),pN(t,pI(n))}catch(t){return b.close().catch(u),u(p3(t)),p6(a.message.id)}p5(S),d(S,f),m(S,lY),void 0!==v&&(c={clientInfo:v[nB],clientCapabilities:_},p(S,c));let $=S.onclose;l.add(S);let w=()=>{l.delete(S),S.onclose===w&&(S.onclose=$),$?.()};S.onclose=w;try{let t=await pY(b,a.message,{classification:a.classification,request:i,...void 0!==n&&{authInfo:n},...void 0!==o&&{responseMode:o},...void 0!==r.keepAliveMs&&{keepAliveMs:r.keepAliveMs}});return"notification"===a.messageKind&&queueMicrotask(()=>void S.close().catch(()=>{})),t}catch(t){if(t instanceof lJ&&t.code===lH.ConnectionClosed)return new Response(null,{status:499});return await S.close().catch(()=>{}),l.delete(S),u(p3(t)),p6(p2(a.message))}}async function b(t,r,a,i){if(void 0!==v)return v(r,{...void 0!==a&&{authInfo:a},...void 0!==i&&{parsedBody:i}});let n=function(t,r){switch(t.reason){case"http-method":return ur("http-method","modern-only-method-not-allowed",405,new cg(-32e3,"Method not allowed."),!0);case"batch":return ur("jsonrpc-shape","modern-only-batch-not-supported",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC batches are not supported by this endpoint"),!0);case"response":return ur("jsonrpc-shape","modern-only-response-post",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"),!0);case"notification":return;case"initialize":case"no-claim":{let a=t.requestedVersion;return ur("era-classification","modern-only-missing-envelope",400,void 0===a?new cg(cf.UnsupportedProtocolVersion,"Unsupported protocol version: the request did not name a protocol version",{supported:[...r]}):new c_({supported:[...r],requested:a}),!0)}}}(t,lY);return void 0===n?new Response(null,{status:202}):(u(Error(`Rejected 2025-era request on a modern-only endpoint (${n.cell}): ${n.message}`)),p4(n,p2(i)))}async function S(t,r){let a=r?.authInfo;if("POST"===t.method.toUpperCase()&&!uA(t.headers.get("content-type")))return u(Error("Unsupported Media Type: Content-Type must be application/json")),p9(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");let i=await p8(t,r?.parsedBody,!0,s);if("unreadable-body"===i.step)return p9(400,-32700,"Parse error: the request body could not be read");if("body-too-large"===i.step)return p9(413,-32e3,pX(s));if("no-json-body"===i.step)return void 0!==v?v(i.forwardRequest,{...void 0!==a&&{authInfo:a}}):p9(400,-32700,"Parse error: the request body is not valid JSON");let{outcome:n,body:o,parsedBody:l,forwardRequest:c}=i;try{switch(n.kind){case"reject":return u(Error(`Rejected inbound request (${n.cell}): ${n.message}`)),p4(n,p2(o));case"modern":return await _(n,t,a);case"legacy":return await b(n,c,a,l)}}catch(t){return u(p3(t)),p6(p2(o))}}return{fetch:async(t,r)=>{if(c)throw Error("This MCP handler has been closed");try{return await S(t,r)}catch(t){return u(p3(t)),p6(p2(r?.parsedBody))}},notify:g,bus:f,close:async()=>{c=!0,y.closeAll();let t=[...l].map(t=>t.close().catch(()=>{}));l.clear(),await Promise.all(t)}}}(async function(){let{instructions:t,...r}=fZ,a=new pZ(r,{instructions:t}),i=fV(),n=fU(),o=fF(),[s,l,c]=await Promise.all([i,n,o]);return fD(a,s,l,c)},{legacy:"stateless",maxSubscriptions:HTTP_CONFIG.maxSubscriptions});async function fJ(t,r={}){let a="POST"===t.method?await t.clone().json().catch(()=>void 0):void 0;return mo({id:crypto.randomUUID(),headers:Object.fromEntries(t.headers.entries()),clientInfo:(t=>{for(let r of Array.isArray(t)?t:[t]){let t=mc(r);if(t)return t}})(a)},()=>fH.fetch(t,{parsedBody:a,authInfo:r.authInfo}))}})();var s=o.r;export{s as xmcpHandler};
237
+ `),R=!0;try{h?.()}catch(t){a?.(t instanceof Error?t:Error(String(t)))}void 0!==f&&clearInterval(f),g?.(),o.delete(P);try{m.close()}catch{}}},E=new ReadableStream({start(t){m=t;let a=pT({method:"notifications/subscriptions/acknowledged",params:{notifications:S}},$);(x(a.method,a.params),0===Object.keys(S).length)?P(!0):(h=r.subscribe(t=>{if(R||!function(t,r){switch(r.kind){case"tools_list_changed":return!0===t.toolsListChanged;case"prompts_list_changed":return!0===t.promptsListChanged;case"resources_list_changed":return!0===t.resourcesListChanged;case"resource_updated":return void 0!==t.resourceSubscriptions&&t.resourceSubscriptions.includes(r.uri)}}(S,t))return;let r=pT(function(t){switch(t.kind){case"tools_list_changed":return{method:"notifications/tools/list_changed"};case"prompts_list_changed":return{method:"notifications/prompts/list_changed"};case"resources_list_changed":return{method:"notifications/resources/list_changed"};case"resource_updated":return{method:"notifications/resources/updated",params:{uri:t.uri}}}}(t),$);x(r.method,r.params)}),f=px(n,()=>k(": keepalive\n\n")),o.add(P))},cancel(){P(!1)}});if(void 0!==s)if(s.aborted)P(!1);else{let t=()=>P(!1);s.addEventListener("abort",t,{once:!0}),g=()=>s.removeEventListener("abort",t)}return new Response(E,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"}})},closeAll(){for(let t of o)t(!0)},get openCount(){return o.size}}}({bus:f,maxSubscriptions:r.maxSubscriptions??1024,keepAliveMs:r.keepAliveMs??15e3,onerror:u});"json"===o&&console.warn("responseMode: 'json' drops mid-call notifications. subscriptions/listen streams are always served over SSE regardless; other notifications emitted before a result are dropped.");let v="reject"===i?void 0:(a=r.keepAliveMs,async(r,i)=>{if("POST"!==r.method.toUpperCase())return p9(405,-32e3,"Method not allowed.");try{let n=await t({era:"legacy",...i?.authInfo!==void 0&&{authInfo:i.authInfo},requestInfo:r}),o=new p1({sessionIdGenerator:void 0,...void 0!==a&&{keepAliveMs:a},...void 0!==s&&{maxRequestBodySize:s}});await n.connect(o);let l=()=>{o.close().catch(()=>{}),n.close().catch(()=>{})};r.signal?.addEventListener("abort",l,{once:!0});let c=await o.handleRequest(r,{...i?.authInfo!==void 0&&{authInfo:i.authInfo},...i?.parsedBody!==void 0&&{parsedBody:i.parsedBody}});if(null===c.body||"text/event-stream"!==uq(c.headers.get("content-type")))return l(),c;let u=c.body.getReader(),d=!1,p=()=>{d||(d=!0,l())},m=new ReadableStream({pull:async t=>{try{let{done:r,value:a}=await u.read();if(r){p(),t.close();return}void 0!==a&&t.enqueue(a)}catch(r){p(),t.error(r)}},cancel:t=>(p(),u.cancel(t).catch(()=>{}))});return new Response(m,{status:c.status,statusText:c.statusText,headers:c.headers})}catch(t){try{u?.(p3(t))}catch{}return p6(p2(i?.parsedBody))}});async function _(a,i,n){var s,c;let f=a.classification.revision;if(void 0===f||!lY.includes(f)){let t=new c_({supported:[...lY],requested:f??"unknown"});return u(t),p9(400,t.code,t.message,t.data,p2(a.message))}let g=function(t,r){if("request"!==r.messageKind)return;let a=r.message.method;if(void 0===t.protocolVersionHeader){let t=r.classification.revision;return ua("version-header-missing","(missing)",void 0===t?"the body carries a modern per-request envelope but the required MCP-Protocol-Version header is absent":`the body envelope names protocol version ${t} but the required MCP-Protocol-Version header is absent`,"standard-header-validation")}if(void 0===t.mcpMethodHeader)return ua("method-header-missing","(missing)",`the body names method ${a} but the required Mcp-Method header is absent`,"standard-header-validation");let i=function(t,r){let a=Object.hasOwn(ui,t)?ui[t]:void 0;if(void 0===a)return;let i=uo(r)?r[a]:void 0;return{field:a,value:"string"==typeof i?i:void 0}}(a,r.message.params);if(void 0===i)return;let{field:n,value:o}=i;if(void 0===t.mcpNameHeader){if(void 0===o)return;return ua("name-header-missing","(missing)",`the body carries params.${n}="${o}" but the required Mcp-Name header is absent`,"standard-header-validation")}let s=un(t.mcpNameHeader),l=c7(s);return void 0===l?ua("name-header-invalid-encoding",s,"the Mcp-Name header carries an invalid Base64 sentinel value","standard-header-validation"):void 0!==o&&l!==o?ua("name-header-mismatch",s,`the body carries params.${n}="${o}" but the Mcp-Name header names "${l}"`,"standard-header-validation"):void 0}({httpMethod:i.method,...p7(i)},a);if(void 0!==g)return u(Error(`Rejected inbound request (${g.cell}): ${g.message}`)),p4(g,p2(a.message));let v="request"===a.messageKind?cU(a.message.params):void 0,_=v?.[nG];if("request"===a.messageKind){let t=Object.hasOwn(lB,s=a.message.method)?lB[s]:void 0;if(void 0!==t){let r=lG(t,_);if(void 0!==r){let t=new cb({requiredCapabilities:r});return u(t),p9(ut[t.code]??400,t.code,t.message,t.data,a.message.id)}}}let b=await t({era:"modern",...void 0!==n&&{authInfo:n},requestInfo:i}),S=b instanceof pZ?b.server:b;if(p5(S),"request"===a.messageKind&&"subscriptions/listen"===a.message.method){let t=S.getCapabilities(),r=h(S);return b.close().catch(u),y.serve(a.message,i.signal,t,r)}if("request"===a.messageKind&&"tools/call"===a.message.method&&b instanceof pZ){let t=a.message.params,r="string"==typeof t?.name?t.name:void 0,n=void 0===r?void 0:b.toolInputSchemaJson(r);if(void 0!==n){let r=c2(n);if(r.valid&&r.declarations.length>0){let n=function(t,r,a){for(let i of t){let t=`Mcp-Param-${i.headerName}`,n=a.get(t),o=function(t,r){let a=t;for(let t of r){if(null===a||"object"!=typeof a)return;a=a[t]}return a}(r,i.path);if(null==o)continue;let s=function(t){if("string"==typeof t)return t;if("boolean"==typeof t)return t?"true":"false";if("number"==typeof t){if(!Number.isFinite(t)||Number.isInteger(t)&&!Number.isSafeInteger(t))return;return String(t)}}(o);if(void 0===s)continue;if(null===n)return c8("param-header-missing",t,`the body carries ${c3(i.path)}=${JSON.stringify(o)} but the ${t} header is absent`);let l=c7(n);if(void 0===l)return c8("param-header-invalid-encoding",t,`the ${t} header carries an invalid Base64 sentinel value`);if(!(("integer"===i.type||"number"===i.type)&&c5.test(l)&&"number"==typeof o?Number(l)===o:l===s))return c8("param-header-mismatch",t,`the ${t} header decodes to ${JSON.stringify(l)} but the body carries ${c3(i.path)}=${JSON.stringify(o)}`)}}(r.declarations,t?.arguments,i.headers);if(void 0!==n)return b.close().catch(u),u(Error(`Rejected inbound request (${n.cell}): ${n.message}`)),p4(n,a.message.id)}}}if("request"===a.messageKind&&b instanceof pZ)try{let t=await pC([a.message],n,t=>b.resolveScopeChallenge(t));if(void 0!==t)return b.close().catch(u),pN(t,pI(n))}catch(t){return b.close().catch(u),u(p3(t)),p6(a.message.id)}p5(S),d(S,f),m(S,lY),void 0!==v&&(c={clientInfo:v[nB],clientCapabilities:_},p(S,c));let $=S.onclose;l.add(S);let w=()=>{l.delete(S),S.onclose===w&&(S.onclose=$),$?.()};S.onclose=w;try{let t=await pY(b,a.message,{classification:a.classification,request:i,...void 0!==n&&{authInfo:n},...void 0!==o&&{responseMode:o},...void 0!==r.keepAliveMs&&{keepAliveMs:r.keepAliveMs}});return"notification"===a.messageKind&&queueMicrotask(()=>void S.close().catch(()=>{})),t}catch(t){if(t instanceof lJ&&t.code===lH.ConnectionClosed)return new Response(null,{status:499});return await S.close().catch(()=>{}),l.delete(S),u(p3(t)),p6(p2(a.message))}}async function b(t,r,a,i){if(void 0!==v)return v(r,{...void 0!==a&&{authInfo:a},...void 0!==i&&{parsedBody:i}});let n=function(t,r){switch(t.reason){case"http-method":return ur("http-method","modern-only-method-not-allowed",405,new cg(-32e3,"Method not allowed."),!0);case"batch":return ur("jsonrpc-shape","modern-only-batch-not-supported",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC batches are not supported by this endpoint"),!0);case"response":return ur("jsonrpc-shape","modern-only-response-post",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"),!0);case"notification":return;case"initialize":case"no-claim":{let a=t.requestedVersion;return ur("era-classification","modern-only-missing-envelope",400,void 0===a?new cg(cf.UnsupportedProtocolVersion,"Unsupported protocol version: the request did not name a protocol version",{supported:[...r]}):new c_({supported:[...r],requested:a}),!0)}}}(t,lY);return void 0===n?new Response(null,{status:202}):(u(Error(`Rejected 2025-era request on a modern-only endpoint (${n.cell}): ${n.message}`)),p4(n,p2(i)))}async function S(t,r){let a=r?.authInfo;if("POST"===t.method.toUpperCase()&&!uA(t.headers.get("content-type")))return u(Error("Unsupported Media Type: Content-Type must be application/json")),p9(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");let i=await p8(t,r?.parsedBody,!0,s);if("unreadable-body"===i.step)return p9(400,-32700,"Parse error: the request body could not be read");if("body-too-large"===i.step)return p9(413,-32e3,pX(s));if("no-json-body"===i.step)return void 0!==v?v(i.forwardRequest,{...void 0!==a&&{authInfo:a}}):p9(400,-32700,"Parse error: the request body is not valid JSON");let{outcome:n,body:o,parsedBody:l,forwardRequest:c}=i;try{switch(n.kind){case"reject":return u(Error(`Rejected inbound request (${n.cell}): ${n.message}`)),p4(n,p2(o));case"modern":return await _(n,t,a);case"legacy":return await b(n,c,a,l)}}catch(t){return u(p3(t)),p6(p2(o))}}return{fetch:async(t,r)=>{if(c)throw Error("This MCP handler has been closed");try{return await S(t,r)}catch(t){return u(p3(t)),p6(p2(r?.parsedBody))}},notify:g,bus:f,close:async()=>{c=!0,y.closeAll();let t=[...l].map(t=>t.close().catch(()=>{}));l.clear(),await Promise.all(t)}}}(async function(){let{instructions:t,...r}=fB,a=new pZ(r,{instructions:t}),i=fG(),n=fW(),o=fY(),[s,l,c]=await Promise.all([i,n,o]);return fK(a,s,l,c)},{legacy:"stateless",maxSubscriptions:HTTP_CONFIG.maxSubscriptions});async function fQ(t,r={}){let a="POST"===t.method?await t.clone().json().catch(()=>void 0):void 0;return mo({id:crypto.randomUUID(),headers:Object.fromEntries(t.headers.entries()),clientInfo:(t=>{for(let r of Array.isArray(t)?t:[t]){let t=mc(r);if(t)return t}})(a)},()=>fX.fetch(t,{parsedBody:a,authInfo:r.authInfo}))}})();var s=o.r;export{s as xmcpHandler};