xmcp 1.10.4 → 1.12.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 e}from"node:module";let t=e(import.meta.url);var r={6982(e){e.exports=t("crypto")},9896(e){e.exports=t("fs")},6928(e){e.exports=t("path")}},a={};function i(e){var t=a[e];if(void 0!==t)return t.exports;var n=a[e]={exports:{}};return r[e](n,n.exports,i),n.exports}i.d=(e,t,r)=>{var a=(t,r)=>{for(var a in t)i.o(t,a)&&!i.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,[r]:t[a]})};a(t,"get"),a(r,"value")},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var n={};(()=>{let e,r,a,o,s,l,c,u,d,p,m,h,f,g,y,v,_,b,S,$,w,R;i.d(n,{r:()=>fA});var k,x,P,E,T,j,O,C,I,N,q,A,z,M,L=Object.create,Z=Object.defineProperty,D=Object.getOwnPropertyDescriptor,U=Object.getOwnPropertyNames,V=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty,H=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),J=(e,t,r)=>(r=null!=e?L(V(e)):{},((e,t,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(var a,i=U(t),n=0,o=i.length;n<o;n++)a=i[n],F.call(e,a)||void 0===a||Z(e,a,{get:(e=>t[e]).bind(null,a),enumerable:!(r=D(t,a))||r.enumerable});return e})(!t&&e&&e.__esModule?r:Z(r,"default",{value:e,enumerable:!0}),e));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(e){let t=Object.values(e).filter(e=>"number"==typeof e);return Object.entries(e).filter(([e,r])=>-1===t.indexOf(+e)).map(([e,t])=>t)}function X(e,t="|"){return e.map(e=>eb(e)).join(t)}function Q(e,t){return"bigint"==typeof t?t.toString():t}class ee{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;return void 0!==e&&(this._value=e(),this._getter=void 0),this._value}}function et(e){return new ee(e)}function er(e){let t=+!!e.startsWith("^"),r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}let ea=Symbol("evaluating");function ei(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function en(e){let t=Object.getOwnPropertyDescriptor(e,"shape");return t?.get?t.get.raw:t?.value}function eo(e){return en(e._zod.def)??e._zod.def.shape}function es(e,t,r){Object.defineProperty(e,t,{get(){let e=r();return ei(this,t,e),e},enumerable:!0,configurable:!0})}function el(e,t,r){t in e?ei(e,t,r):e[t]=r}function ec(e,t,r,a){let i=eo(t);for(let n of r){let r=Object.getOwnPropertyDescriptor(i,n);r.enumerable&&(r.get?es(e,n,()=>{let e=t._zod.def.shape[n];return a?a(e,n):e}):el(e,n,a?a(r.value,n):r.value))}}function eu(...e){let t={};for(let r of e)Object.assign(t,Object.getOwnPropertyDescriptors(r));return Object.defineProperties({},t)}let ed="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ep(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}let em=et(()=>{if(eB.jitless||"u">typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return Function(""),!0}catch(e){return!1}});function eh(e){if(!1===ep(e))return!1;let t=e.constructor;if(void 0===t||"function"!=typeof t)return!0;let r=t.prototype;return!1!==ep(r)&&!1!==Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")}function ef(e){return eh(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}let eg=new Set(["string","number","symbol"]);function ey(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ev(e,t,r){let a=new e._zod.constr(t??e._zod.def);return(!t||r?.parent)&&(a._zod.parent=e),a}function e_(e){if(!e)return{};if("string"==typeof e)return{error:()=>e};if(e?.message!==void 0){if(e?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");e.error=e.message}return(delete e.message,"string"==typeof e.error)?{...e,error:()=>e.error}:e}function eb(e){return"bigint"==typeof e?e.toString()+"n":"string"==typeof e?`"${e}"`:`${e}`}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(e,t){let r=eo(e),a=[];for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(r,e)?.enumerable)throw Error(`Unrecognized key: "${String(e)}"`);t[e]&&a.push(e)}return a}function eR(e,t){let r={};ec(r,e,Reflect.ownKeys(eo(e)));for(let e of Reflect.ownKeys(t)){let a=Object.getOwnPropertyDescriptor(t,e);a.enumerable&&(a.get?es(r,e,()=>t[e]):el(r,e,a.value))}return r}function ek(e,t,r,a="partial"){let i=t._zod.def.checks;if(i&&i.length>0)throw Error(`.${a}() cannot be used on object schemas containing refinements`);let n=r?new Set(ew(t,r)):void 0,o={};return ec(o,t,Reflect.ownKeys(eo(t)),e&&((t,r)=>n&&!n.has(r)?t:new e({type:"optional",innerType:t}))),ev(t,eu(t._zod.def,{shape:o,checks:[]}))}function ex(e,t=0){if(!0===e.aborted)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue!==!0)return!0;return!1}function eP(e,t){return t.map(t=>(t.path??(t.path=[]),t.path.unshift(e),t))}function eE(e){return"string"==typeof e?e:e?.message}function eT(e){let t=[];for(let r of e??[]){let e=r._zod.def;if(!/_(length|size)$|_equals$/.test(e.check))break;let a=e.maximum??e.length??e.size;a>=0&&t.push([a,r])}return t}function ej(e,t,r){var a;for(let i=t;i<e.length;i++)(a=e[i]).schema??(a.schema=r)}function eO(e,t,r){let a=e.inst?._zod?.traits;a?.has("$ZodType")&&(a.has("$ZodCheck")?e.schema??(e.schema=e.inst):e.schema=e.inst);let i=e.schema!==e.inst?e.schema?._zod.def?.error:void 0,n=e.message?e.message:eE(e.inst?._zod.def?.error?.(e))??eE(i?.(e))??eE(t?.error?.(e))??eE(r.customError?.(e))??eE(r.localeError?.(e))??"Invalid input",o={};for(let t of Object.keys(e))"inst"!==t&&"schema"!==t&&"continue"!==t&&"input"!==t&&"__proto__"!==t&&(o[t]=e[t]);return o.path??(o.path=[]),o.message=n,t?.reportInput&&(o.input=e.input),o}let eC=/[\uD800-\uDBFF]/;function eI(e){let t=e.length;if(!eC.test(e))return t;let r=t;for(let a=0;a<t-1;a++)(64512&e.charCodeAt(a))==55296&&(64512&e.charCodeAt(a+1))==56320&&(r--,a++);return r}function eN(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function eq(...e){let[t,r,a]=e;return"string"==typeof t?{message:t,code:"custom",input:r,inst:a}:{...t}}function eA(e,t,r,a=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:a,value:r}),r}function ez(e,t){for(let r in e){let a=e[r];Object.defineProperty(t,r,{configurable:!0,enumerable:!0,get(){return eA(this,r,a(this))},set(e){eA(this,r,e)}})}return t}let eM=!1,eL={configurable:!0,get(){eM=!0}};function eZ(t,r,a){let i=Object.getPrototypeOf(t._zod);if(r in i&&e!==t._zod){e=void 0;return}e=t._zod,Object.defineProperty(i,r,{configurable:!0,get(){Object.defineProperty(this,r,eL);let e=eM;eM=!1;try{let t=a(this);return eM?delete this[r]:Object.defineProperty(this,r,{configurable:!0,writable:!0,value:t}),eM=eM||e,t}catch(t){throw delete this[r],eM=eM||e,t}},set(e){Object.defineProperty(this,r,{configurable:!0,writable:!0,value:e})}})}let eD=Object.freeze({status:"aborted"}),eU={value:void 0,enumerable:!1},eV="captureStackTrace"in Error?Error:null;function eF(e,t,r,a){function i(e){this.def=e,this.constr=c,this.traits=new Set}i.prototype={};let n=r&&new WeakSet;function o(a,o){if(a._zod){if(a._zod.traits.has(e))return}else{eU.value=new i(o);try{Object.defineProperty(a,"_zod",eU)}finally{eU.value=void 0}}if(a._zod.traits.add(e),t(a,o),n){let e=Object.getPrototypeOf(a),t=a._zod.constr.prototype,i=e;for(;i&&i!==t;)i=Object.getPrototypeOf(i);let o=i??e;if(!n.has(o)){n.add(o);for(let e in r){let t=Object.getOwnPropertyDescriptor(r,e);t.get?Object.defineProperty(o,e,{...t,enumerable:!1}):function(e,t,r){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?r:eA(this,t,r.bind(this))},set(e){eA(this,t,e)}})}(o,e,t.value)}}}let s=c.prototype;for(let e in s)Object.prototype.hasOwnProperty.call(s,e)&&(e in a||(a[e]=s[e].bind(a)))}let s=a?.Parent??Object;class l extends s{}function c(e){let t=a?.Parent?function(e){let t=eV;if(t){let r=t.stackTraceLimit;if("number"==typeof r){try{t.stackTraceLimit=0}catch{return eV=null,new e}try{return new e}finally{t.stackTraceLimit=r}}}return new e}(l):this;o(t,e);let r=t._zod.deferred;if(r){for(let e of r)e();t._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(t),t}return Object.defineProperty(l,"name",{value:e}),Object.defineProperty(c,"init",{value:o}),Object.defineProperty(c,Symbol.hasInstance,{value:t=>!!a?.Parent&&t instanceof a.Parent||t?._zod?.traits?.has(e)}),Object.defineProperty(c,"name",{value:e}),c}class eH extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class eJ extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}(C=globalThis).__zod_globalConfig??(C.__zod_globalConfig={});let eB=globalThis.__zod_globalConfig;function eK(e){return e&&Object.assign(eB,e),eB}class eG extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform"),this.name="ZodCyclicError"}}let eW="~memo",eY=[];function eX(e){return null!==e&&"object"==typeof e}function eQ(e){return e.map(e=>e.path?{...e,path:e.path.slice()}:{...e})}let e0=new WeakMap,e1=[],e2={alloc(e,t,a){let i=r;if(!i)return a;r=void 0;let n={value:a,issues:null};return i.set(t.value,n),e1.push(n),a},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,r=(e,r)=>{var a,i;let n;if("backward"!==r.direction&&(a=r,i=e.value,void 0!==(n=a[eW]?.backEdges)&&eX(i)&&n.has(i)))throw new eG;return t(e,r)};e._zod.parse=r,e._zod.run===t&&(e._zod.run=r)})},attach(e){var t;let a,i,n,o=!1;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,s=(l,c)=>{let u;if(void 0===a){let r=function e(t,r,a){var i,n;let o=e0.get(t);if(void 0!==o)return 2*!!o;if(r.has(t))return 2;r.add(t);let s=0,l=t=>{if(2!==s&&t?._zod){let i=e(t,r,a);i>s&&(s=i)}},c=e=>{e>s&&(s=e)},u=t._zod.def;switch(u.type){case"object":{let t=en(u);c(t?((t,i)=>{let n=0;for(let o of Reflect.ownKeys(t)){let s=Object.getOwnPropertyDescriptor(t,o);if(i&&!s.enumerable)continue;let l=s.get?1:s.value?._zod?e(s.value,r,a):0;l>n&&(n=l)}return n})(t,!0):1),l(u.catchall);break}case"array":l(u.element);break;case"tuple":for(let e of u.items)l(e);l(u.rest);break;case"record":case"map":l(u.keyType),l(u.valueType);break;case"set":l(u.valueType);break;case"union":for(let e of u.options)l(e);break;case"intersection":l(u.left),l(u.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":l(u.innerType);break;case"pipe":l(u.in),l(u.out);break;case"function":l(u.input),l(u.output);break;case"lazy":{let i=u._cachedInner??(a?t._zod.innerType:void 0);c(i?e(i,r,!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 e in u){let t=Object.getOwnPropertyDescriptor(u,e);if(!t||t.get)continue;let r=t.value;if(r&&"object"==typeof r){if(r._zod)l(r);else if(Array.isArray(r))for(let e of r)l(e)}}}return r.delete(t),i=t,1!==(n=s)&&e0.set(i,2===n),n}(e,new Set,!1);if(0===r)return e._zod.parse=t,e._zod.run===s&&(e._zod.run=t),t(l,c);2===r||o?a=!0:o=!0}let d=l.value;if(!eX(d))return t(l,c);let p=c[eW];if(p||(p={buckets:new WeakMap,backEdges:void 0},c[eW]=p),i===c)u=n;else{var m;let t;(t=(m=p).buckets.get(e))||(t=new WeakMap,m.buckets.set(e,t)),u=t,i=c,n=u}let h=u.get(d);if(h)return l.value=h.value,h.issues?h.issues.length&&l.issues.push(...eQ(h.issues)):(l.memo=!0,p.backEdges??(p.backEdges=new WeakSet),p.backEdges.add(h.value)),l;r=u;let f=e1.length,g=t(l,c);r=void 0;let y=e1.length>f?e1.pop():void 0;return g instanceof Promise?g.then(e=>(y&&(y.issues=e.issues.length?eQ(e.issues):eY),e)):(y&&(y.issues=g.issues.length?eQ(g.issues):eY),g)};e._zod.parse=s,e._zod.run===t&&(e._zod.run=s)})}},e9=/^[cC][0-9a-z]{6,}$/,e4=/^[0-9a-z]+$/,e3=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,e5=/^[0-9a-vA-V]{20}$/,e6=/^[A-Za-z0-9]{27}$/,e7=/^[a-zA-Z0-9_-]{21}$/,e8=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,te=/^([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})$/,tt=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[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)$/,tr=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,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(e){let t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof e.precision?-1===e.precision?`${t}`:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?`${t}:[0-5]\\d(?:\\.\\d+)?`:`${t}(?::[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_=eF("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])}),tb=e=>{let t=e.value;return null!=t&&void 0!==t.length},tS={number:"number",bigint:"bigint",object:"date"},t$=eF("$ZodCheckLessThan",(e,t)=>{t_.init(e,t);let r=tS[typeof t.value];e._zod.check=a=>{(t.inclusive?a.value<=t.value:a.value<t.value)||a.issues.push({origin:tS[typeof a.value]??r,code:"too_big",maximum:"object"==typeof t.value?t.value.getTime():t.value,input:a.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),tw=eF("$ZodCheckGreaterThan",(e,t)=>{t_.init(e,t);let r=tS[typeof t.value];e._zod.check=a=>{(t.inclusive?a.value>=t.value:a.value>t.value)||a.issues.push({origin:tS[typeof a.value]??r,code:"too_small",minimum:"object"==typeof t.value?t.value.getTime():t.value,input:a.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),tR=eF("$ZodCheckMultipleOf",(e,t)=>{t_.init(e,t),e._zod.check=r=>{let a,i,n;if(typeof r.value!=typeof t.value)throw Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof r.value?t.value!==BigInt(0)&&r.value%t.value===BigInt(0):0==(i=Math.round(a=r.value/t.value),n=4*Number.EPSILON*Math.max(Math.abs(a),1),Math.abs(a-i)<n?0:a-i))||r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:t.value,input:r.value,inst:e,continue:!t.abort})}}),tk=eF("$ZodCheckNumberFormat",(e,t)=>{t_.init(e,t),t.format=t.format||"float64";let r=t.format?.includes("int"),a=r?"int":"number",[i,n]=eS[t.format];e._zod.check=o=>{let s=o.value;if(r){if(!Number.isInteger(s))return void o.issues.push({expected:a,format:t.format,code:"invalid_type",continue:!1,input:s,inst:e});if(!Number.isSafeInteger(s))return void(s>0?o.issues.push({input:s,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:a,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:a,inclusive:!0,continue:!t.abort}))}s<i&&o.issues.push({origin:"number",input:s,code:"too_small",minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>n&&o.issues.push({origin:"number",input:s,code:"too_big",maximum:n,inclusive:!0,inst:e,continue:!t.abort})}}),tx=eF("$ZodCheckMaxLength",(e,t)=>{var r;t_.init(e,t),(r=e._zod.def).when??(r.when=tb),e._zod.check=r=>{let a=r.value,i=a.length;if(("string"==typeof a&&i>t.maximum?eI(a):i)<=t.maximum)return;let n=eN(a);r.issues.push({origin:n,code:"too_big",maximum:t.maximum,inclusive:!0,input:a,inst:e,continue:!t.abort})}}),tP=eF("$ZodCheckMinLength",(e,t)=>{var r;t_.init(e,t),(r=e._zod.def).when??(r.when=tb),e._zod.check=r=>{let a=r.value,i=a.length;if(("string"==typeof a&&i>=t.minimum&&i<2*t.minimum?eI(a):i)>=t.minimum)return;let n=eN(a);r.issues.push({origin:n,code:"too_small",minimum:t.minimum,inclusive:!0,input:a,inst:e,continue:!t.abort})}}),tE=eF("$ZodCheckLengthEquals",(e,t)=>{var r;t_.init(e,t),(r=e._zod.def).when??(r.when=tb),e._zod.check=r=>{let a=r.value,i=a.length,n="string"==typeof a&&i>=t.length&&i<=2*t.length?eI(a):i;if(n===t.length)return;let o=eN(a),s=n>t.length;r.issues.push({origin:o,...s?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),tT=eF("$ZodCheckStringFormat",(e,t)=>{var r,a;t_.init(e,t),t.pattern?(r=e._zod).check??(r.check=r=>{t.pattern.lastIndex=0,t.pattern.test(r.value)||r.issues.push({origin:"string",code:"invalid_format",format:t.format,input:r.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(a=e._zod).check??(a.check=()=>{})}),tj=eF("$ZodCheckRegex",(e,t)=>{tT.init(e,t),e._zod.check=r=>{t.pattern.lastIndex=0,t.pattern.test(r.value)||r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),tO=eF("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=ty),tT.init(e,t)}),tC=eF("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=tv),tT.init(e,t)}),tI=eF("$ZodCheckIncludes",(e,t)=>{t_.init(e,t);let r=ey(t.includes),a=new RegExp("number"==typeof t.position?`^.{${t.position},}${r}`:r);t.pattern=a,e._zod.check=r=>{r.value.includes(t.includes,t.position)||r.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:r.value,inst:e,continue:!t.abort})}}),tN=eF("$ZodCheckStartsWith",(e,t)=>{t_.init(e,t);let r=RegExp(`^${ey(t.prefix)}.*`);t.pattern??(t.pattern=r),e._zod.check=r=>{r.value.startsWith(t.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:r.value,inst:e,continue:!t.abort})}}),tq=eF("$ZodCheckEndsWith",(e,t)=>{t_.init(e,t);let r=RegExp(`.*${ey(t.suffix)}$`);t.pattern??(t.pattern=r),e._zod.check=r=>{r.value.endsWith(t.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:r.value,inst:e,continue:!t.abort})}}),tA=eF("$ZodCheckOverwrite",(e,t)=>{t_.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});class tz{constructor(e=[],t={}){this.content=[],this.indent=0,this.args=e,this.closed=t}indented(e){this.indent+=1;try{e(this)}finally{this.indent-=1}}write(e){if("function"==typeof e){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let t=e.split("\n").filter(e=>e),r=Math.min(...t.map(e=>e.length-e.trimStart().length));for(let e of t.map(e=>e.slice(r)).map(e=>" ".repeat(2*this.indent)+e))this.content.push(e)}compile(){let e=Function,t=this?.content??[""];return new e(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
1
+ import{createRequire as e}from"node:module";let t=e(import.meta.url);var r={6982(e){e.exports=t("crypto")},9896(e){e.exports=t("fs")},6928(e){e.exports=t("path")}},a={};function i(e){var t=a[e];if(void 0!==t)return t.exports;var n=a[e]={exports:{}};return r[e](n,n.exports,i),n.exports}i.d=(e,t,r)=>{var a=(t,r)=>{for(var a in t)i.o(t,a)&&!i.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,[r]:t[a]})};a(t,"get"),a(r,"value")},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var n={};(()=>{let e,r,a,o,s,l,c,u,d,p,m,h,f,g,y,v,_,b,S,$,w,R;i.d(n,{r:()=>fJ});var k,x,P,E,T,j,O,C,I,N,q,A,z,M,L=Object.create,Z=Object.defineProperty,D=Object.getOwnPropertyDescriptor,U=Object.getOwnPropertyNames,V=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty,H=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),J=(e,t,r)=>(r=null!=e?L(V(e)):{},((e,t,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(var a,i=U(t),n=0,o=i.length;n<o;n++)a=i[n],F.call(e,a)||void 0===a||Z(e,a,{get:(e=>t[e]).bind(null,a),enumerable:!(r=D(t,a))||r.enumerable});return e})(!t&&e&&e.__esModule?r:Z(r,"default",{value:e,enumerable:!0}),e));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(e){let t=Object.values(e).filter(e=>"number"==typeof e);return Object.entries(e).filter(([e,r])=>-1===t.indexOf(+e)).map(([e,t])=>t)}function X(e,t="|"){return e.map(e=>eb(e)).join(t)}function Q(e,t){return"bigint"==typeof t?t.toString():t}class ee{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;return void 0!==e&&(this._value=e(),this._getter=void 0),this._value}}function et(e){return new ee(e)}function er(e){let t=+!!e.startsWith("^"),r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}let ea=Symbol("evaluating");function ei(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function en(e){let t=Object.getOwnPropertyDescriptor(e,"shape");return t?.get?t.get.raw:t?.value}function eo(e){return en(e._zod.def)??e._zod.def.shape}function es(e,t,r){Object.defineProperty(e,t,{get(){let e=r();return ei(this,t,e),e},enumerable:!0,configurable:!0})}function el(e,t,r){t in e?ei(e,t,r):e[t]=r}function ec(e,t,r,a){let i=eo(t);for(let n of r){let r=Object.getOwnPropertyDescriptor(i,n);r.enumerable&&(r.get?es(e,n,()=>{let e=t._zod.def.shape[n];return a?a(e,n):e}):el(e,n,a?a(r.value,n):r.value))}}function eu(...e){let t={};for(let r of e)Object.assign(t,Object.getOwnPropertyDescriptors(r));return Object.defineProperties({},t)}let ed="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ep(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}let em=et(()=>{if(eB.jitless||"u">typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return Function(""),!0}catch(e){return!1}});function eh(e){if(!1===ep(e))return!1;let t=e.constructor;if(void 0===t||"function"!=typeof t)return!0;let r=t.prototype;return!1!==ep(r)&&!1!==Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")}function ef(e){return eh(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}let eg=new Set(["string","number","symbol"]);function ey(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ev(e,t,r){let a=new e._zod.constr(t??e._zod.def);return(!t||r?.parent)&&(a._zod.parent=e),a}function e_(e){if(!e)return{};if("string"==typeof e)return{error:()=>e};if(e?.message!==void 0){if(e?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");e.error=e.message}return(delete e.message,"string"==typeof e.error)?{...e,error:()=>e.error}:e}function eb(e){return"bigint"==typeof e?e.toString()+"n":"string"==typeof e?`"${e}"`:`${e}`}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(e,t){let r=eo(e),a=[];for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(r,e)?.enumerable)throw Error(`Unrecognized key: "${String(e)}"`);t[e]&&a.push(e)}return a}function eR(e,t){let r={};ec(r,e,Reflect.ownKeys(eo(e)));for(let e of Reflect.ownKeys(t)){let a=Object.getOwnPropertyDescriptor(t,e);a.enumerable&&(a.get?es(r,e,()=>t[e]):el(r,e,a.value))}return r}function ek(e,t,r,a="partial"){let i=t._zod.def.checks;if(i&&i.length>0)throw Error(`.${a}() cannot be used on object schemas containing refinements`);let n=r?new Set(ew(t,r)):void 0,o={};return ec(o,t,Reflect.ownKeys(eo(t)),e&&((t,r)=>n&&!n.has(r)?t:new e({type:"optional",innerType:t}))),ev(t,eu(t._zod.def,{shape:o,checks:[]}))}function ex(e,t=0){if(!0===e.aborted)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue!==!0)return!0;return!1}function eP(e,t){return t.map(t=>(t.path??(t.path=[]),t.path.unshift(e),t))}function eE(e){return"string"==typeof e?e:e?.message}function eT(e){let t=[];for(let r of e??[]){let e=r._zod.def;if(!/_(length|size)$|_equals$/.test(e.check))break;let a=e.maximum??e.length??e.size;a>=0&&t.push([a,r])}return t}function ej(e,t,r){var a;for(let i=t;i<e.length;i++)(a=e[i]).schema??(a.schema=r)}function eO(e,t,r){let a=e.inst?._zod?.traits;a?.has("$ZodType")&&(a.has("$ZodCheck")?e.schema??(e.schema=e.inst):e.schema=e.inst);let i=e.schema!==e.inst?e.schema?._zod.def?.error:void 0,n=e.message?e.message:eE(e.inst?._zod.def?.error?.(e))??eE(i?.(e))??eE(t?.error?.(e))??eE(r.customError?.(e))??eE(r.localeError?.(e))??"Invalid input",o={};for(let t of Object.keys(e))"inst"!==t&&"schema"!==t&&"continue"!==t&&"input"!==t&&"__proto__"!==t&&(o[t]=e[t]);return o.path??(o.path=[]),o.message=n,t?.reportInput&&(o.input=e.input),o}let eC=/[\uD800-\uDBFF]/;function eI(e){let t=e.length;if(!eC.test(e))return t;let r=t;for(let a=0;a<t-1;a++)(64512&e.charCodeAt(a))==55296&&(64512&e.charCodeAt(a+1))==56320&&(r--,a++);return r}function eN(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function eq(...e){let[t,r,a]=e;return"string"==typeof t?{message:t,code:"custom",input:r,inst:a}:{...t}}function eA(e,t,r,a=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:a,value:r}),r}function ez(e,t){for(let r in e){let a=e[r];Object.defineProperty(t,r,{configurable:!0,enumerable:!0,get(){return eA(this,r,a(this))},set(e){eA(this,r,e)}})}return t}let eM=!1,eL={configurable:!0,get(){eM=!0}};function eZ(t,r,a){let i=Object.getPrototypeOf(t._zod);if(r in i&&e!==t._zod){e=void 0;return}e=t._zod,Object.defineProperty(i,r,{configurable:!0,get(){Object.defineProperty(this,r,eL);let e=eM;eM=!1;try{let t=a(this);return eM?delete this[r]:Object.defineProperty(this,r,{configurable:!0,writable:!0,value:t}),eM=eM||e,t}catch(t){throw delete this[r],eM=eM||e,t}},set(e){Object.defineProperty(this,r,{configurable:!0,writable:!0,value:e})}})}let eD=Object.freeze({status:"aborted"}),eU={value:void 0,enumerable:!1},eV="captureStackTrace"in Error?Error:null;function eF(e,t,r,a){function i(e){this.def=e,this.constr=c,this.traits=new Set}i.prototype={};let n=r&&new WeakSet;function o(a,o){if(a._zod){if(a._zod.traits.has(e))return}else{eU.value=new i(o);try{Object.defineProperty(a,"_zod",eU)}finally{eU.value=void 0}}if(a._zod.traits.add(e),t(a,o),n){let e=Object.getPrototypeOf(a),t=a._zod.constr.prototype,i=e;for(;i&&i!==t;)i=Object.getPrototypeOf(i);let o=i??e;if(!n.has(o)){n.add(o);for(let e in r){let t=Object.getOwnPropertyDescriptor(r,e);t.get?Object.defineProperty(o,e,{...t,enumerable:!1}):function(e,t,r){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?r:eA(this,t,r.bind(this))},set(e){eA(this,t,e)}})}(o,e,t.value)}}}let s=c.prototype;for(let e in s)Object.prototype.hasOwnProperty.call(s,e)&&(e in a||(a[e]=s[e].bind(a)))}let s=a?.Parent??Object;class l extends s{}function c(e){let t=a?.Parent?function(e){let t=eV;if(t){let r=t.stackTraceLimit;if("number"==typeof r){try{t.stackTraceLimit=0}catch{return eV=null,new e}try{return new e}finally{t.stackTraceLimit=r}}}return new e}(l):this;o(t,e);let r=t._zod.deferred;if(r){for(let e of r)e();t._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(t),t}return Object.defineProperty(l,"name",{value:e}),Object.defineProperty(c,"init",{value:o}),Object.defineProperty(c,Symbol.hasInstance,{value:t=>!!a?.Parent&&t instanceof a.Parent||t?._zod?.traits?.has(e)}),Object.defineProperty(c,"name",{value:e}),c}class eH extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class eJ extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}(C=globalThis).__zod_globalConfig??(C.__zod_globalConfig={});let eB=globalThis.__zod_globalConfig;function eK(e){return e&&Object.assign(eB,e),eB}class eG extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform"),this.name="ZodCyclicError"}}let eW="~memo",eY=[];function eX(e){return null!==e&&"object"==typeof e}function eQ(e){return e.map(e=>e.path?{...e,path:e.path.slice()}:{...e})}let e0=new WeakMap,e1=[],e2={alloc(e,t,a){let i=r;if(!i)return a;r=void 0;let n={value:a,issues:null};return i.set(t.value,n),e1.push(n),a},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,r=(e,r)=>{var a,i;let n;if("backward"!==r.direction&&(a=r,i=e.value,void 0!==(n=a[eW]?.backEdges)&&eX(i)&&n.has(i)))throw new eG;return t(e,r)};e._zod.parse=r,e._zod.run===t&&(e._zod.run=r)})},attach(e){var t;let a,i,n,o=!1;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,s=(l,c)=>{let u;if(void 0===a){let r=function e(t,r,a){var i,n;let o=e0.get(t);if(void 0!==o)return 2*!!o;if(r.has(t))return 2;r.add(t);let s=0,l=t=>{if(2!==s&&t?._zod){let i=e(t,r,a);i>s&&(s=i)}},c=e=>{e>s&&(s=e)},u=t._zod.def;switch(u.type){case"object":{let t=en(u);c(t?((t,i)=>{let n=0;for(let o of Reflect.ownKeys(t)){let s=Object.getOwnPropertyDescriptor(t,o);if(i&&!s.enumerable)continue;let l=s.get?1:s.value?._zod?e(s.value,r,a):0;l>n&&(n=l)}return n})(t,!0):1),l(u.catchall);break}case"array":l(u.element);break;case"tuple":for(let e of u.items)l(e);l(u.rest);break;case"record":case"map":l(u.keyType),l(u.valueType);break;case"set":l(u.valueType);break;case"union":for(let e of u.options)l(e);break;case"intersection":l(u.left),l(u.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":l(u.innerType);break;case"pipe":l(u.in),l(u.out);break;case"function":l(u.input),l(u.output);break;case"lazy":{let i=u._cachedInner??(a?t._zod.innerType:void 0);c(i?e(i,r,!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 e in u){let t=Object.getOwnPropertyDescriptor(u,e);if(!t||t.get)continue;let r=t.value;if(r&&"object"==typeof r){if(r._zod)l(r);else if(Array.isArray(r))for(let e of r)l(e)}}}return r.delete(t),i=t,1!==(n=s)&&e0.set(i,2===n),n}(e,new Set,!1);if(0===r)return e._zod.parse=t,e._zod.run===s&&(e._zod.run=t),t(l,c);2===r||o?a=!0:o=!0}let d=l.value;if(!eX(d))return t(l,c);let p=c[eW];if(p||(p={buckets:new WeakMap,backEdges:void 0},c[eW]=p),i===c)u=n;else{var m;let t;(t=(m=p).buckets.get(e))||(t=new WeakMap,m.buckets.set(e,t)),u=t,i=c,n=u}let h=u.get(d);if(h)return l.value=h.value,h.issues?h.issues.length&&l.issues.push(...eQ(h.issues)):(l.memo=!0,p.backEdges??(p.backEdges=new WeakSet),p.backEdges.add(h.value)),l;r=u;let f=e1.length,g=t(l,c);r=void 0;let y=e1.length>f?e1.pop():void 0;return g instanceof Promise?g.then(e=>(y&&(y.issues=e.issues.length?eQ(e.issues):eY),e)):(y&&(y.issues=g.issues.length?eQ(g.issues):eY),g)};e._zod.parse=s,e._zod.run===t&&(e._zod.run=s)})}},e9=/^[cC][0-9a-z]{6,}$/,e4=/^[0-9a-z]+$/,e3=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,e5=/^[0-9a-vA-V]{20}$/,e6=/^[A-Za-z0-9]{27}$/,e7=/^[a-zA-Z0-9_-]{21}$/,e8=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,te=/^([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})$/,tt=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[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)$/,tr=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,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(e){let t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof e.precision?-1===e.precision?`${t}`:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?`${t}:[0-5]\\d(?:\\.\\d+)?`:`${t}(?::[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_=eF("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])}),tb=e=>{let t=e.value;return null!=t&&void 0!==t.length},tS={number:"number",bigint:"bigint",object:"date"},t$=eF("$ZodCheckLessThan",(e,t)=>{t_.init(e,t);let r=tS[typeof t.value];e._zod.check=a=>{(t.inclusive?a.value<=t.value:a.value<t.value)||a.issues.push({origin:tS[typeof a.value]??r,code:"too_big",maximum:"object"==typeof t.value?t.value.getTime():t.value,input:a.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),tw=eF("$ZodCheckGreaterThan",(e,t)=>{t_.init(e,t);let r=tS[typeof t.value];e._zod.check=a=>{(t.inclusive?a.value>=t.value:a.value>t.value)||a.issues.push({origin:tS[typeof a.value]??r,code:"too_small",minimum:"object"==typeof t.value?t.value.getTime():t.value,input:a.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),tR=eF("$ZodCheckMultipleOf",(e,t)=>{t_.init(e,t),e._zod.check=r=>{let a,i,n;if(typeof r.value!=typeof t.value)throw Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof r.value?t.value!==BigInt(0)&&r.value%t.value===BigInt(0):0==(i=Math.round(a=r.value/t.value),n=4*Number.EPSILON*Math.max(Math.abs(a),1),Math.abs(a-i)<n?0:a-i))||r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:t.value,input:r.value,inst:e,continue:!t.abort})}}),tk=eF("$ZodCheckNumberFormat",(e,t)=>{t_.init(e,t),t.format=t.format||"float64";let r=t.format?.includes("int"),a=r?"int":"number",[i,n]=eS[t.format];e._zod.check=o=>{let s=o.value;if(r){if(!Number.isInteger(s))return void o.issues.push({expected:a,format:t.format,code:"invalid_type",continue:!1,input:s,inst:e});if(!Number.isSafeInteger(s))return void(s>0?o.issues.push({input:s,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:a,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:a,inclusive:!0,continue:!t.abort}))}s<i&&o.issues.push({origin:"number",input:s,code:"too_small",minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>n&&o.issues.push({origin:"number",input:s,code:"too_big",maximum:n,inclusive:!0,inst:e,continue:!t.abort})}}),tx=eF("$ZodCheckMaxLength",(e,t)=>{var r;t_.init(e,t),(r=e._zod.def).when??(r.when=tb),e._zod.check=r=>{let a=r.value,i=a.length;if(("string"==typeof a&&i>t.maximum?eI(a):i)<=t.maximum)return;let n=eN(a);r.issues.push({origin:n,code:"too_big",maximum:t.maximum,inclusive:!0,input:a,inst:e,continue:!t.abort})}}),tP=eF("$ZodCheckMinLength",(e,t)=>{var r;t_.init(e,t),(r=e._zod.def).when??(r.when=tb),e._zod.check=r=>{let a=r.value,i=a.length;if(("string"==typeof a&&i>=t.minimum&&i<2*t.minimum?eI(a):i)>=t.minimum)return;let n=eN(a);r.issues.push({origin:n,code:"too_small",minimum:t.minimum,inclusive:!0,input:a,inst:e,continue:!t.abort})}}),tE=eF("$ZodCheckLengthEquals",(e,t)=>{var r;t_.init(e,t),(r=e._zod.def).when??(r.when=tb),e._zod.check=r=>{let a=r.value,i=a.length,n="string"==typeof a&&i>=t.length&&i<=2*t.length?eI(a):i;if(n===t.length)return;let o=eN(a),s=n>t.length;r.issues.push({origin:o,...s?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),tT=eF("$ZodCheckStringFormat",(e,t)=>{var r,a;t_.init(e,t),t.pattern?(r=e._zod).check??(r.check=r=>{t.pattern.lastIndex=0,t.pattern.test(r.value)||r.issues.push({origin:"string",code:"invalid_format",format:t.format,input:r.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(a=e._zod).check??(a.check=()=>{})}),tj=eF("$ZodCheckRegex",(e,t)=>{tT.init(e,t),e._zod.check=r=>{t.pattern.lastIndex=0,t.pattern.test(r.value)||r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),tO=eF("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=ty),tT.init(e,t)}),tC=eF("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=tv),tT.init(e,t)}),tI=eF("$ZodCheckIncludes",(e,t)=>{t_.init(e,t);let r=ey(t.includes),a=new RegExp("number"==typeof t.position?`^.{${t.position},}${r}`:r);t.pattern=a,e._zod.check=r=>{r.value.includes(t.includes,t.position)||r.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:r.value,inst:e,continue:!t.abort})}}),tN=eF("$ZodCheckStartsWith",(e,t)=>{t_.init(e,t);let r=RegExp(`^${ey(t.prefix)}.*`);t.pattern??(t.pattern=r),e._zod.check=r=>{r.value.startsWith(t.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:r.value,inst:e,continue:!t.abort})}}),tq=eF("$ZodCheckEndsWith",(e,t)=>{t_.init(e,t);let r=RegExp(`.*${ey(t.suffix)}$`);t.pattern??(t.pattern=r),e._zod.check=r=>{r.value.endsWith(t.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:r.value,inst:e,continue:!t.abort})}}),tA=eF("$ZodCheckOverwrite",(e,t)=>{t_.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});class tz{constructor(e=[],t={}){this.content=[],this.indent=0,this.args=e,this.closed=t}indented(e){this.indent+=1;try{e(this)}finally{this.indent-=1}}write(e){if("function"==typeof e){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let t=e.split("\n").filter(e=>e),r=Math.min(...t.map(e=>e.length-e.trimStart().length));for(let e of t.map(e=>e.slice(r)).map(e=>" ".repeat(2*this.indent)+e))this.content.push(e)}compile(){let e=Function,t=this?.content??[""];return new e(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
2
2
  ${t.join("\n")}
3
3
  };`)(...Object.values(this.closed))}}let tM={major:4,minor:6,patch:7},tL=eF("$ZodType",(e,t)=>{var r;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=tM;let a=e._zod.def.checks,i=e._zod.traits.has("$ZodCheck")?[e,...a??[]]:a?.length?[...a]:[];for(let t of i)for(let r of t._zod.onattach)r(e);if(0===i.length)(r=e._zod).deferred??(r.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(t,r,a)=>{let i;if(t.memo)return t;let n=ex(t);for(let o of r){if(o._zod.def.when){if(function(e,t=0){if(!0===e.aborted)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue===!1)return!0;return!1}(t)||!o._zod.def.when(t))continue}else if(n)continue;let r=t.issues.length,s=o._zod.check(t);if(s instanceof Promise&&a?.async===!1)throw new eH;if(i||s instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await s,t.issues.length!==r&&(ej(t.issues,r,e),n||(n=ex(t,r)))});else{if(t.issues.length===r)continue;ej(t.issues,r,e),n||(n=ex(t,r))}}return i?i.then(()=>t):t},r=(r,a,n)=>{if(ex(r))return r.aborted=!0,r;let o=t(a,i,n);if(o instanceof Promise){if(!1===n.async)throw new eH;return o.then(t=>e._zod.parse(t,n))}return e._zod.parse(o,n)};e._zod.run=(a,n)=>{if(n.skipChecks)return e._zod.parse(a,n);if("backward"===n.direction){let t=e._zod.parse({value:a.value,issues:[]},{...n,skipChecks:!0});return t instanceof Promise?t.then(e=>r(e,a,n)):r(t,a,n)}let o=e._zod.parse(a,n);if(o instanceof Promise){if(!1===n.async)throw new eH;return o.then(e=>t(e,i,n))}return t(o,i,n)}}},{get"~standard"(){return eA(this,"~standard",tD(this),!1)},set"~standard"(e){eA(this,"~standard",e)}}),tZ=(e,t)=>e.issues.length?{issues:e.issues.map(e=>eO(e,t,eK()))}:{value:e.value};function tD(e){return{validate:t=>{let r={async:!1};try{let a=e._zod.run({value:t,issues:[]},r);if(!(a instanceof Promise))return tZ(a,r)}catch(e){}return async function(e,t){let r={async:!0};return tZ(await e._zod.run({value:t,issues:[]},r),r)}(e,t)},vendor:"zod",version:1}}let tU=eF("$ZodString",(e,t)=>{tL.init(e,t),e._zod.pattern=t.pattern??tp,e._zod.parse=(r,a)=>{if(t.coerce)try{r.value=String(r.value)}catch(e){}return"string"==typeof r.value||r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:e}),r}}),tV=eF("$ZodStringFormat",(e,t)=>{tT.init(e,t),tU.init(e,t)}),tF=eF("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=te),tV.init(e,t)}),tH=eF("$ZodUUID",(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(void 0===e)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=tt(e))}else t.pattern??(t.pattern=tt());tV.init(e,t)}),tJ=eF("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=tr),tV.init(e,t)});function tB(e){try{if("u">typeof URL&&"function"==typeof URL.canParse)return URL.canParse(e);return new URL(e),!0}catch{return!1}}let tK=/[\t\n\r]/g;function tG(e){return e.replace(tK,"")}let tW=eF("$ZodURL",(e,t)=>{tV.init(e,t),e._zod.check=r=>{try{var a,i;let n=r.value.trim(),o="normalize"in t||"hostname"in t||"protocol"in t?function(e,t){if(!t.normalize&&t.protocol?.source===ts.source&&!/^https?:\/\//i.test(e))return 1;try{if("u">typeof URL){let t=URL;if("function"==typeof t.parse)return t.parse(e)??2}return new URL(e)}catch{return 2}}(n,t):tB(n)||2;if(1===o)return void r.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:r.value,inst:e,continue:!t.abort});if(2===o)return void r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort});if(!0===o){r.value=tG(n);return}t.hostname&&((a=t.hostname).lastIndex=0,!a.test(o.hostname))&&r.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:r.value,inst:e,continue:!t.abort}),t.protocol&&((i=t.protocol).lastIndex=0,!i.test(o.protocol.endsWith(":")?o.protocol.slice(0,-1):o.protocol))&&r.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:r.value,inst:e,continue:!t.abort}),r.value=t.normalize?o.href:tG(n);return}catch(a){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort})}}}),tY=eF("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=RegExp("^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$","u")),tV.init(e,t)}),tX=eF("$ZodNanoID",(e,t)=>{var r;if(void 0!==t.length&&(!Number.isInteger(t.length)||t.length<1))throw Error(`Invalid nanoid length: ${t.length}`);t.pattern??(t.pattern=void 0===t.length?e7:(r=t.length,RegExp(`^[a-zA-Z0-9_-]{${r}}$`))),tV.init(e,t)}),tQ=eF("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=e9),tV.init(e,t)}),t0=eF("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=e4),tV.init(e,t)}),t1=eF("$ZodULID",(e,t)=>{t.pattern??(t.pattern=e3),tV.init(e,t)}),t2=eF("$ZodXID",(e,t)=>{t.pattern??(t.pattern=e5),tV.init(e,t)}),t9=eF("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=e6),tV.init(e,t)}),t4=eF("$ZodISODateTime",(e,t)=>{let r,a,i;t.pattern??(r=["Z"],t.offset&&r.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)"),a=`${td({precision:t.precision,seconds:!0})}(?:${r.join("|")})`,i=t.local?`${a}|${td({precision:t.precision})}`:a,t.pattern=RegExp(`^${tc}T(?:${i})$`)),tV.init(e,t)}),t3=eF("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=tu),tV.init(e,t)}),t5=eF("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=RegExp(`^${td(t)}$`)),tV.init(e,t)}),t6=eF("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=e8),tV.init(e,t)}),t7=eF("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=ta),tV.init(e,t)}),t8=/^[0-9a-fA-F:.]+$/;function re(e){return!!t8.test(e)&&tB(`http://[${e}]`)}let rt=eF("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=ti),tV.init(e,t),e._zod.check=r=>{re(r.value)||r.issues.push({code:"invalid_format",format:"ipv6",input:r.value,inst:e,continue:!t.abort})}}),rr=eF("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=tn),tV.init(e,t)}),ra=eF("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=to),tV.init(e,t),e._zod.check=r=>{!function(e){let t=e.split("/");if(2!==t.length)return!1;let[r,a]=t;if(!a)return!1;let i=Number(a);return`${i}`===a&&!(i<0)&&!(i>128)&&re(r)}(r.value)&&r.issues.push({code:"invalid_format",format:"cidrv6",input:r.value,inst:e,continue:!t.abort})}});function ri(e){if(""===e)return!0;if(/\s/.test(e)||e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}let rn=/^[0-9a-zA-Z+/]*={0,2}$/,ro=eF("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=rn),tV.init(e,t),e._zod.check=r=>{ri(r.value)||r.issues.push({code:"invalid_format",format:"base64",input:r.value,inst:e,continue:!t.abort})}}),rs=/^[A-Za-z0-9_-]*$/,rl=eF("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=rs),tV.init(e,t),e._zod.check=r=>{!function(e){if(!rs.test(e))return!1;let t=e.replace(/[-_]/g,e=>"-"===e?"+":"/");return ri(t.padEnd(4*Math.ceil(t.length/4),"="))}(r.value)&&r.issues.push({code:"invalid_format",format:"base64url",input:r.value,inst:e,continue:!t.abort})}}),rc=eF("$ZodE164",(e,t)=>{t.pattern??(t.pattern=tl),tV.init(e,t)}),ru=eF("$ZodJWT",(e,t)=>{tV.init(e,t),e._zod.check=r=>{!function(e,t=null){try{let r=e.split(".");if(3!==r.length)return!1;let[a]=r;if(!a)return!1;let i=JSON.parse(atob(a));if("typ"in i&&i?.typ!=="JWT"||!i.alg||t&&(!("alg"in i)||i.alg!==t))return!1;return!0}catch{return!1}}(r.value,t.alg)&&r.issues.push({code:"invalid_format",format:"jwt",input:r.value,inst:e,continue:!t.abort})}}),rd=eF("$ZodNumber",(e,t)=>{tL.init(e,t),e._zod.pattern=th,e._zod.parse=(r,a)=>{if(t.coerce)try{r.value=Number(r.value)}catch(e){}let i=r.value;if("number"==typeof i&&!Number.isNaN(i)&&Number.isFinite(i))return r;let n="number"==typeof i?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:String(i):void 0;return r.issues.push({expected:"number",code:"invalid_type",input:i,inst:e,...n?{received:n}:{}}),r}}),rp=eF("$ZodNumberFormat",(e,t)=>{tk.init(e,t),rd.init(e,t)}),rm=eF("$ZodBoolean",(e,t)=>{tL.init(e,t),e._zod.pattern=tf,e._zod.parse=(r,a)=>{if(t.coerce)try{r.value=!!r.value}catch(e){}let i=r.value;return"boolean"==typeof i||r.issues.push({expected:"boolean",code:"invalid_type",input:i,inst:e}),r}}),rh=eF("$ZodNull",(e,t)=>{tL.init(e,t),e._zod.pattern=tg,e._zod.values=new Set([null]),e._zod.parse=(t,r)=>{let a=t.value;return null===a||t.issues.push({expected:"null",code:"invalid_type",input:a,inst:e}),t}}),rf=eF("$ZodAny",(e,t)=>{tL.init(e,t),e._zod.parse=e=>e}),rg=eF("$ZodUnknown",(e,t)=>{tL.init(e,t),e._zod.parse=e=>e}),ry=eF("$ZodNever",(e,t)=>{tL.init(e,t),e._zod.parse=(t,r)=>(t.issues.push({expected:"never",code:"invalid_type",input:t.value,inst:e}),t)}),rv=e=>Array.isArray(e)?e.length:-1;function r_(e,t,r){e.issues.length&&t.issues.push(...eP(r,e.issues)),t.value[r]=e.value}let rb=eF("$ZodArray",(e,t)=>{tL.init(e,t);let r=eB.memoizer;r?.attach(e),e._zod.parse=(a,i)=>{let n=a.value;if(!Array.isArray(n))return a.issues.push({expected:"array",code:"invalid_type",input:n,inst:e}),a;a.value=r?r.alloc(e,a,Array(n.length),i):Array(n.length);let o=[],s=i?.abortEarly;for(let e=0;e<n.length;e++){let r=n[e],l=t.element._zod.run({value:r,issues:[]},i);if(l instanceof Promise)o.push(l.then(t=>r_(t,a,e)));else if(r_(l,a,e),s&&0!==l.issues.length&&ex(l))break}return o.length?Promise.all(o).then(()=>a):a},function(e,t){let r=eT(e._zod.def.checks);if(!r.length)return;let a=Math.min(...r.map(e=>e[0])),i=e._zod.parse;e._zod.parse=(r,n)=>{let o=t(r.value);if(o>a&&!n?.skipChecks&&n?.direction!=="backward"){for(let[t,a]of eT(e._zod.def.checks))if(o>t&&a._zod.def.when(r)){let t=r.issues.length;return a._zod.check(r),r.issues[t].continue=!1,ej(r.issues,t,e),r}}return i(r,n)}}(e,rv)});function rS(e,t,r,a,i,n){let o=r in a,s="optional"===n;if(o||!s||"optional"!==i){if(e.issues.length){if(void 0!==i&&s&&!o)return;t.issues.push(...eP(r,e.issues))}if(!o&&void 0===i){e.issues.length||t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[r]});return}void 0===e.value?(o||"defaulted"===i&&!s)&&(t.value[r]=void 0):t.value[r]=e.value}}let r$=[];function rw(e){var t;let r=Object.keys(e.shape),a=Object.getOwnPropertySymbols(e.shape),i=a.length?a:r$,n=i.length?[...r,...i]:r;for(let t of n)if(!e.shape?.[t]?._zod?.traits?.has("$ZodType"))throw Error(`Invalid element at key "${String(t)}": expected a Zod schema`);let o=Object.keys(t=e.shape).filter(e=>void 0!==t[e]._zod.optin&&"optional"===t[e]._zod.optout);return{...e,allKeys:n,symbolKeys:i,keySet:new Set(r),numKeys:r.length,optionalKeys:new Set(o)}}function rR(e,t,r,a,i,n,o){let s=[],l=i.keySet,c=i.catchall._zod,u=c.def.type,d=c.optin,p=c.optout,m=0;for(let i in t){if(o&&r.issues.length!==m){if(ex(r,m))break;m=r.issues.length}if(l.has(i))continue;if("__proto__"===i){"never"===u&&s.push(i);continue}if("never"===u){s.push(i);continue}let n=c.run({value:t[i],issues:[]},a);n instanceof Promise?e.push(n.then(e=>rS(e,r,i,t,d,p))):rS(n,r,i,t,d,p)}return(s.length&&r.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:n,continue:!0}),e.length)?Promise.all(e).then(()=>r):r}let rk=eF("$ZodObject",(e,t)=>{let r;tL.init(e,t);let a=Object.getOwnPropertyDescriptor(t,"shape"),i=a?.get?a.get.raw:t.shape??{};if(i){let e=()=>{let r={...i};return Object.defineProperty(t,"shape",{value:r}),e.raw=r,r};e.raw=i,Object.defineProperty(t,"shape",{get:e})}let n=et(()=>rw(t));eZ(e,"propValues",e=>{let t=e.def.shape,r={};for(let e in t){let a=t[e]._zod;if(a.values){for(let t of(Object.prototype.hasOwnProperty.call(r,e)||ei(r,e,new Set),a.values))r[e].add(t);void 0!==a.optin&&r[e].add(void 0)}}return r});let o=t.catchall,s=eB.memoizer;s?.attach(e),e._zod.parse=(t,a)=>{r??(r=n.value);let i=t.value;if(!ep(i))return t.issues.push({expected:"object",code:"invalid_type",input:i,inst:e}),t;t.value=s?s.alloc(e,t,{},a):{};let l=[],c=r.shape,u=a?.abortEarly,d=t.issues.length;for(let e of r.allKeys){if(u&&t.issues.length!==d){if(ex(t,d))break;d=t.issues.length}if("__proto__"===e)continue;let r=c[e],n=r._zod.optin,o=r._zod.optout,s=r._zod.run({value:i[e],issues:[]},a);s instanceof Promise?l.push(s.then(r=>rS(r,t,e,i,n,o))):rS(s,t,e,i,n,o)}return o?rR(l,i,t,a,n.value,e,!0===u):l.length?Promise.all(l).then(()=>t):t}}),rx=eF("$ZodObjectJIT",(e,t)=>{let r,a;rk.init(e,t);let i=e._zod.parse,n=et(()=>rw(t)),o=eB.memoizer,s=!eB.jitless,l=s&&em.value,c=t.catchall;e._zod.parse=(u,d)=>{a??(a=n.value);let p=u.value;return ep(p)?s&&l&&d?.async===!1&&!0!==d.jitless?(r||(r=(t=>{let r=n.value,a=r.symbolKeys,i=new tz(["payload","ctx"],{shape:t,inst:e,memo:o,syms:a}),s=e=>`shape[${e}]._zod.run({ value: input[${e}], issues: [] }, ctx)`,l=(e,t)=>`
4
4
  let ${e}_ab = false;
@@ -74,23 +74,23 @@ data:
74
74
  `;return a&&(i+=`id: ${a}
75
75
  `),i+=`data: ${JSON.stringify(r)}
76
76
 
77
- `,e.enqueue(t.encode(i)),!0}catch(e){return this.onerror?.(e),!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(e,t){try{let r,a,i,n,o,s=e.headers.get("accept");if(!s?.includes("application/json")||!s.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(e.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(t?.parsedBody===void 0)try{let t=await pX(e,this._maxRequestBodySize);if(t.tooLarge){let e=pW(this._maxRequestBodySize);return this.onerror?.(Error(e)),this.createJsonErrorResponse(413,-32e3,e)}r=JSON.parse(t.text)}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON")}else r=t.parsedBody;if(Array.isArray(r)&&r.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{a=Array.isArray(r)?r.map(e=>os.parse(e)):[os.parse(r)]}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON-RPC message")}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");let l=a.some(e=>o$.safeParse(e).success);if(l){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(a.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(!l){let t=this.validateSession(e);if(t)return t;let r=this.validateProtocolVersion(e);if(r)return r}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");try{i=await this._checkScopeChallenge(a,t?.authInfo)}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(500,-32603,"Internal server error")}if(i)return i;if(!a.some(e=>cB(e))){for(let r of a)this.onmessage?.(r,{authInfo:t?.authInfo,request:e});return new Response(null,{status:202})}let c=crypto.randomUUID(),u=a.find(e=>o$.safeParse(e).success),d=u?u.params.protocolVersion:e.headers.get("mcp-protocol-version")??"2025-03-26";if(this._enableJsonResponse)return new Promise(r=>{for(let e of(this._streamMapping.set(c,{resolveJson:r,cleanup:()=>{this._streamMapping.delete(c)}}),a))cB(e)&&this._requestToStreamMapping.set(e.id,c);for(let r of a)this.onmessage?.(r,{authInfo:t?.authInfo,request:e})});let p=new TextEncoder,m=new ReadableStream({start:e=>{n=e},cancel:()=>{void 0!==o&&clearInterval(o),this._streamMapping.get(c)?.controller===n&&this._streamMapping.delete(c)}}),h={"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"};for(let e of(void 0!==this.sessionId&&(h["mcp-session-id"]=this.sessionId),a))cB(e)&&(this._streamMapping.set(c,{controller:n,encoder:p,cleanup:()=>{void 0!==o&&clearInterval(o),this._streamMapping.delete(c);try{n.close()}catch{}}}),this._requestToStreamMapping.set(e.id,c));for(let r of(await this.writePrimingEvent(n,p,c,d),a)){let a,i;cB(r)&&this._eventStore&&this.supportsEmptySSEData(d)&&(a=()=>{this.closeSSEStream(r.id)},i=()=>{this.closeStandaloneSSEStream()}),this.onmessage?.(r,{authInfo:t?.authInfo,request:e,closeSSEStream:a,closeStandaloneSSEStream:i})}return this._streamMapping.get(c)?.controller===n&&(o=this.startKeepAlive(n,p)),new Response(m,{status:200,headers:h})}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(400,-32700,"Parse error",{data:String(e)})}}async handleDeleteRequest(e){let t=this.validateSession(e);if(t)return t;let r=this.validateProtocolVersion(e);if(r)return r;try{return await Promise.resolve(this._onsessionclosed?.(this.sessionId)),new Response(null,{status:200})}finally{await this.close()}}validateSession(e){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 t=e.headers.get("mcp-session-id");return t?t!==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(e){let t=e.headers.get("mcp-protocol-version");if(null!==t&&!this._supportedProtocolVersions.includes(t)){let e=`Bad Request: Unsupported protocol version: ${t} (supported versions: ${this._supportedProtocolVersions.join(", ")})`;return this.onerror?.(Error(e)),this.createJsonErrorResponse(400,-32e3,e)}}async close(){if(!this._closed){for(let{cleanup:e}of(this._closed=!0,this._streamMapping.values()))e();this._streamMapping.clear(),this._requestResponseMap.clear(),this.onclose?.()}}closeSSEStream(e){let t=this._requestToStreamMapping.get(e);if(!t)return;let r=this._streamMapping.get(t);r&&r.cleanup()}closeStandaloneSSEStream(){let e=this._streamMapping.get(this._standaloneSseStreamId);e&&e.cleanup()}async send(e,t){let r=t?.relatedRequestId;if((cG(e)||cW(e))&&(r=e.id),void 0===r){let t;if(cG(e)||cW(e))throw Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");this._eventStore&&(t=await this._eventStore.storeEvent(this._standaloneSseStreamId,e));let r=this._streamMapping.get(this._standaloneSseStreamId);if(void 0===r)return;r.controller&&r.encoder&&(void 0===t||!r.replayedEventIds?.has(t))&&this.writeSSEEvent(r.controller,r.encoder,e,t);return}let a=this._requestToStreamMapping.get(r);if(!a)throw Error(`No connection established for request ID: ${String(r)}`);let i=this._streamMapping.get(a);if(!this._enableJsonResponse){let t;this._eventStore&&(t=await this._eventStore.storeEvent(a,e),i=this._streamMapping.get(a)),i?.controller&&i?.encoder&&(void 0===t||!i.replayedEventIds?.has(t))&&this.writeSSEEvent(i.controller,i.encoder,e,t)}if(cG(e)||cW(e)){this._requestResponseMap.set(r,e);let t=[...this._requestToStreamMapping.entries()].filter(([e,t])=>t===a).map(([e])=>e);if(t.every(e=>this._requestResponseMap.has(e))){if(!i){if(this._enableJsonResponse)throw Error(`No connection established for request ID: ${String(r)}`);if(!this._eventStore){for(let e of(this.onerror?.(Error(`Response for request ID ${String(r)} is undeliverable: per-request stream is disconnected and no eventStore is configured`)),t))this._requestResponseMap.delete(e),this._requestToStreamMapping.delete(e);return}for(let e of t)this._requestResponseMap.delete(e),this._requestToStreamMapping.delete(e);return}if(this._enableJsonResponse&&i.resolveJson){let e={"Content-Type":"application/json"};void 0!==this.sessionId&&(e["mcp-session-id"]=this.sessionId);let r=t.map(e=>this._requestResponseMap.get(e));1===r.length?i.resolveJson(Response.json(r[0],{status:200,headers:e})):i.resolveJson(Response.json(r,{status:200,headers:e})),i.cleanup()}else i.cleanup();for(let e of t)this._requestResponseMap.delete(e),this._requestToStreamMapping.delete(e)}}}};function p0(e){if(null===e||"object"!=typeof e||Array.isArray(e))return null;let{method:t,id:r}=e;return"string"!=typeof t?null:"string"==typeof r||"number"==typeof r?r:null}function p1(e,t,r,a,i=null){return Response.json({jsonrpc:"2.0",error:{code:t,message:r,...void 0!==a&&{data:a}},id:i},{status:e,...405===e&&{headers:{Allow:"POST"}}})}function p2(e,t=null){return p1(e.httpStatus,e.code,e.message,e.data,t)}function p9(e){return e instanceof Error?e:Error(String(e))}function p4(e=null){return p1(500,-32603,"Internal server error",void 0,e)}function p3(e){if(void 0!==e.transport)throw Error("The factory returned an instance that is still serving another request. Return a new instance for each request.")}function p5(e){return{protocolVersionHeader:e.headers.get("mcp-protocol-version")??void 0,mcpMethodHeader:e.headers.get("mcp-method")??void 0,mcpNameHeader:e.headers.get("mcp-name")??void 0}}let p6=t("async_hooks"),p7=(e,t)=>{globalThis[e]=t},p8=e=>globalThis[e];function me({name:e,fallback:t=!0}){let r=Symbol.for(`xmcp-context-${e}`),a=Symbol.for(`xmcp-context-${e}-fallback-store`);if(p8(r))return p8(r);let i=new p6.AsyncLocalStorage,n=globalThis[a]??{current:null};p7(a,n);let o={provider:(e,r)=>(t&&(n.current=e),i.run(e,r)),getContext:()=>{let r=i.getStore();if(r)return r;if(t&&n.current)return n.current;throw Error(`getContext() can only be used within the ${e} context.`)},setContext:r=>{let a=i.getStore()??(t?n.current:null);if(!a)throw Error(`setContext() can only be used within the ${e} context.`);Object.assign(a,r)}};return p7(r,o),o}let mt=me({name:"http-request-context"});mt.setContext;let mr=mt.getContext,ma=mt.provider,mi=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),mn=e=>{if(!mi(e)||"string"!=typeof e.name||"string"!=typeof e.version)return;let t={name:e.name,version:e.version};return"string"==typeof e.title&&(t.title=e.title),"string"==typeof e.websiteUrl&&(t.websiteUrl=e.websiteUrl),"string"==typeof e.description&&(t.description=e.description),t},mo=e=>{if(e&&"initialize"===e.method&&mi(e.params))return mn(e.params.clientInfo)},ms=(e,t)=>{let r=t.toLowerCase();for(let[t,a]of Object.entries(e)){if(t.toLowerCase()!==r)continue;let e=Array.isArray(a)?a[0]:a;if("string"!=typeof e)break;let i=e.trim();return i.length>0?i:void 0}};function ml(e){let{tags:t,enabled:r,...a}=e;return{...a,_meta:void 0===t?a._meta:{...a._meta,"xmcp/tags":t}}}let mc=new class{add(e,t){this.resources.set(e,t)}getAll(){return this.resources}clear(){this.resources.clear()}has(e){return this.resources.has(e)}constructor(){var e,t;e="resources",t=new Map,e in this?Object.defineProperty(this,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):this[e]=t}},mu=me({name:"request-context",fallback:!1}),md=me({name:"client-info-context"});md.setContext;let mp=md.getContext;md.provider;let mm=new Set(["message","mode","requestedSchema"]),mh=new Set(["elicitationId","message","mode","url"]),mf=new Set(["properties","required","type"]),mg=new Set(["default","description","format","maxLength","minLength","title","type"]),my=new Set(["default","description","enum","enumNames","title","type"]),mv=new Set(["default","description","title","type"]),m_=new Set(["default","description","maximum","minimum","title","type"]),mb=new Set(["date","date-time","email","uri"]);function mS(e,t,r){let a=Object.keys(e).filter(e=>!t.has(e));if(0!==a.length)throw Error(`${r} includes unsupported key(s): ${a.join(", ")}.`)}function m$(e,t){if("object"!=typeof e||null===e||Array.isArray(e))throw Error(t)}function mw(e,t){if("string"!=typeof e)throw Error(t)}function mR(e,t){if("string"!=typeof e||0===e.trim().length)throw Error(t)}function mk(e,t){if(void 0!==e&&"string"!=typeof e)throw Error(t)}function mx(e,t){if(void 0!==e&&"number"!=typeof e)throw Error(t)}function mP(e,t){if(!Array.isArray(e)||e.some(e=>"string"!=typeof e))throw Error(t)}let mE=new Set(["_meta","includeContext","maxTokens","messages","metadata","modelPreferences","stopSequences","systemPrompt","temperature"]),mT=new Set(["task","toolChoice","tools"]),mj=new Set(["text","image","audio"]);function mO(e,t){if("object"!=typeof e||null===e||Array.isArray(e))throw Error(t)}let mC={text:e=>"string"!=typeof e.text?{valid:!1,error:'Text content must have a "text" property of type string'}:{valid:!0},image:e=>"string"!=typeof e.data?{valid:!1,error:'Image content must have a "data" property of type string (base64-encoded image)'}:"string"!=typeof e.mimeType?{valid:!1,error:'Image content must have a "mimeType" property of type string'}:{valid:!0},audio:e=>"string"!=typeof e.data?{valid:!1,error:'Audio content must have a "data" property of type string (base64-encoded audio)'}:"string"!=typeof e.mimeType?{valid:!1,error:'Audio content must have a "mimeType" property of type string'}:{valid:!0},resource_link:e=>"string"!=typeof e.name?{valid:!1,error:'Resource link content must have a "name" property of type string'}:"string"!=typeof e.uri?{valid:!1,error:'Resource link content must have a "uri" property of type string'}:void 0!==e.title&&"string"!=typeof e.title?{valid:!1,error:'Resource link "title" property must be a string if provided'}:void 0!==e.description&&"string"!=typeof e.description?{valid:!1,error:'Resource link "description" property must be a string if provided'}:void 0!==e.mimeType&&"string"!=typeof e.mimeType?{valid:!1,error:'Resource link "mimeType" property must be a string if provided'}:{valid:!0}};function mI(e){if(!e||"object"!=typeof e)return{valid:!1,error:"Content must be an object"};if("string"!=typeof e.type)return{valid:!1,error:'Content must have a "type" property of type string'};if(void 0!==e._meta&&(null===e._meta||"object"!=typeof e._meta))return{valid:!1,error:'Content "_meta" property must be an object if provided'};let t=mC[e.type];return t?t(e):{valid:!0}}function mN(e,t,r,a){if(null===e||"object"!=typeof e||Array.isArray(e))throw Error(`Tool "${r}" ${a}: expected a plain object.`);let i=new Set(Object.keys(t)),n=Object.keys(e).filter(e=>!i.has(e));if(n.length>0)throw Error(`Tool "${r}" ${a}: unrecognized key(s): ${n.join(", ")}`);for(let[i,n]of Object.entries(t))try{n.parse(e[i])}catch(e){throw Error(`Tool "${r}" ${a}: ${e?.message??`invalid field "${i}"`}`)}}function mq(e){return!!(e&&"object"==typeof e&&Object.keys(e).some(e=>e.startsWith("ui/")))}function mA(e){let t=e.mcpReq.envelope,r=mn(t?.[nJ]);if(!r)try{let e,t=mr();r=t.clientInfo??(e=t.headers,mn({name:ms(e,"x-mcp-client-name"),version:ms(e,"x-mcp-client-version"),title:ms(e,"x-mcp-client-title"),websiteUrl:ms(e,"x-mcp-client-website-url"),description:ms(e,"x-mcp-client-description")}))}catch{}if(!r)try{r=mp().clientInfo}catch{}return r}function mz(e){let t=[...e];return(e,r,a)=>(function(e,t,r){let a,i=new Map;if(e.http){let e=mr(),t=Object.fromEntries(Object.entries(e.headers).map(([e,t])=>[e,Array.isArray(t)?Object.freeze([...t]):t]));a=Object.freeze({id:e.id,headers:Object.freeze(t)})}return mu.provider(Object.freeze({clientInfo:t?Object.freeze({...t}):void 0,http:a,authInfo:e.http?.authInfo,signal:e.mcpReq.signal,set(e,t){i.set(e,t)},get:e=>i.get(e),async progress(t,r){let a=e.mcpReq._meta?.progressToken;void 0!==a&&await e.mcpReq.notify({method:"notifications/progress",params:{progressToken:a,progress:t,...void 0===r?{}:{total:r}}})},log:(t,r)=>e.mcpReq.log(t,r)}),r)})(r,mA(r),async()=>{if(0===t.length)return a();let r=Object.freeze({...function(){try{return mu.getContext()}catch{throw Error("getRequestContext() can only be used while handling an MCP request.")}}(),...e,params:Object.freeze({...e.params})}),i=-1,n=async e=>{if(e<=i)throw Error("MCP middleware next() can only be called once");i=e;let o=t[e];return o?o(r,()=>n(e+1)):a()};return n(0)})}let mM=new Set(["tools/list","prompts/get","prompts/list","resources/read","resources/list","resources/templates/list","completion/complete"]);function mL(e){return e.endsWith(".tsx")}let mZ=Symbol("Let zodToJsonSchema decide on which parser to use"),mD={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=e=>{},T.assertIs=function(e){},T.assertNever=function(e){throw Error()},T.arrayToEnum=e=>{let t={};for(let r of e)t[r]=r;return t},T.getValidEnumValues=e=>{let t=T.objectKeys(e).filter(t=>"number"!=typeof e[e[t]]),r={};for(let a of t)r[a]=e[a];return T.objectValues(r)},T.objectValues=e=>T.objectKeys(e).map(function(t){return e[t]}),T.objectKeys="function"==typeof Object.keys?e=>Object.keys(e):e=>{let t=[];for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.push(r);return t},T.find=(e,t)=>{for(let r of e)if(t(r))return r},T.isInteger="function"==typeof Number.isInteger?e=>Number.isInteger(e):e=>"number"==typeof e&&Number.isFinite(e)&&Math.floor(e)===e,T.joinValues=function(e,t=" | "){return e.map(e=>"string"==typeof e?`'${e}'`:e).join(t)},T.jsonStringifyReplacer=(e,t)=>"bigint"==typeof t?t.toString():t,(A||(A={})).mergeShapes=(e,t)=>({...e,...t});let mU=q.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),mV=e=>{switch(typeof e){case"undefined":return mU.undefined;case"string":return mU.string;case"number":return Number.isNaN(e)?mU.nan:mU.number;case"boolean":return mU.boolean;case"function":return mU.function;case"bigint":return mU.bigint;case"symbol":return mU.symbol;case"object":if(Array.isArray(e))return mU.array;if(null===e)return mU.null;if(e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch)return mU.promise;if("u">typeof Map&&e instanceof Map)return mU.map;if("u">typeof Set&&e instanceof Set)return mU.set;if("u">typeof Date&&e instanceof Date)return mU.date;return mU.object;default:return mU.unknown}},mF=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 mH extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=e=>{this.issues=[...this.issues,e]},this.addIssues=(e=[])=>{this.issues=[...this.issues,...e]};let t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){let t=e||function(e){return e.message},r={_errors:[]},a=e=>{for(let i of e.issues)if("invalid_union"===i.code)i.unionErrors.map(a);else if("invalid_return_type"===i.code)a(i.returnTypeError);else if("invalid_arguments"===i.code)a(i.argumentsError);else if(0===i.path.length)r._errors.push(t(i));else{let e=r,a=0;for(;a<i.path.length;){let r=i.path[a],n=a===i.path.length-1;if("_errors"===r){n&&e._errors.push(t(i)),a++;continue}Object.prototype.hasOwnProperty.call(e,r)||("__proto__"===r?Object.defineProperty(e,r,{value:{_errors:[]},writable:!0,enumerable:!0,configurable:!0}):e[r]={_errors:[]}),e=e[r],n&&e._errors.push(t(i)),a++}}};return a(this),r}static assert(e){if(!(e instanceof mH))throw Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,q.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(e=e=>e.message){let t=Object.create(null),r=[];for(let a of this.issues)if(a.path.length>0){let r=a.path[0];t[r]=t[r]||[],t[r].push(e(a))}else r.push(e(a));return{formErrors:r,fieldErrors:t}}get formErrors(){return this.flatten()}}mH.create=e=>new mH(e);let mJ=(e,t)=>{let r;switch(e.code){case mF.invalid_type:r=e.received===mU.undefined?"Required":`Expected ${e.expected}, received ${e.received}`;break;case mF.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(e.expected,q.jsonStringifyReplacer)}`;break;case mF.unrecognized_keys:r=`Unrecognized key(s) in object: ${q.joinValues(e.keys,", ")}`;break;case mF.invalid_union:r="Invalid input";break;case mF.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${q.joinValues(e.options)}`;break;case mF.invalid_enum_value:r=`Invalid enum value. Expected ${q.joinValues(e.options)}, received '${e.received}'`;break;case mF.invalid_arguments:r="Invalid function arguments";break;case mF.invalid_return_type:r="Invalid function return type";break;case mF.invalid_date:r="Invalid date";break;case mF.invalid_string:"object"==typeof e.validation?"includes"in e.validation?(r=`Invalid input: must include "${e.validation.includes}"`,"number"==typeof e.validation.position&&(r=`${r} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?r=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?r=`Invalid input: must end with "${e.validation.endsWith}"`:q.assertNever(e.validation):r="regex"!==e.validation?`Invalid ${e.validation}`:"Invalid";break;case mF.too_small:r="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:"number"===e.type||"bigint"===e.type?`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:"date"===e.type?`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:"Invalid input";break;case mF.too_big:r="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"bigint"===e.type?`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"date"===e.type?`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:"Invalid input";break;case mF.custom:r="Invalid input";break;case mF.invalid_intersection_types:r="Intersection results could not be merged";break;case mF.not_multiple_of:r=`Number must be a multiple of ${e.multipleOf}`;break;case mF.not_finite:r="Number must be finite";break;default:r=t.defaultError,q.assertNever(e)}return{message:r}};(j=z||(z={})).errToObj=e=>"string"==typeof e?{message:e}:e||{},j.toString=e=>"string"==typeof e?e:e?.message;function mB(e,t){let r=(e=>{let{data:t,path:r,errorMaps:a,issueData:i}=e,n=[...r,...i.path||[]],o={...i,path:n};if(void 0!==i.message)return{...i,path:n,message:i.message};let s="";for(let e of a.filter(e=>!!e).slice().reverse())s=e(o,{data:t,defaultError:s}).message;return{...i,path:n,message:s}})({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,mJ,void 0].filter(e=>!!e)});e.common.issues.push(r)}class mK{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(e,t){let r=[];for(let a of t){if("aborted"===a.status)return mG;"dirty"===a.status&&e.dirty(),r.push(a.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,t){let r=[];for(let e of t){let t=await e.key,a=await e.value;r.push({key:t,value:a})}return mK.mergeObjectSync(e,r)}static mergeObjectSync(e,t){let r={};for(let a of t){let{key:t,value:i}=a;if("aborted"===t.status||"aborted"===i.status)return mG;"dirty"===t.status&&e.dirty(),"dirty"===i.status&&e.dirty(),"__proto__"!==t.value&&(void 0!==i.value||a.alwaysSet)&&(r[t.value]=i.value)}return{status:e.value,value:r}}}let mG=Object.freeze({status:"aborted"}),mW=e=>({status:"dirty",value:e}),mY=e=>({status:"valid",value:e}),mX=e=>"u">typeof Promise&&e instanceof Promise;class mQ{constructor(e,t,r,a){this._cachedPath=[],this.parent=e,this.data=t,this._path=r,this._key=a}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 m0=(e,t)=>{if("valid"===t.status)return{success:!0,data:t.value};if(!e.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let t=new mH(e.common.issues);return this._error=t,this._error}}};function m1(e){if(!e)return{};let{errorMap:t,invalid_type_error:r,required_error:a,description:i}=e;if(t&&(r||a))throw Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');return t?{errorMap:t,description:i}:{errorMap:(t,i)=>{let{message:n}=e;return"invalid_enum_value"===t.code?{message:n??i.defaultError}:void 0===i.data?{message:n??a??i.defaultError}:"invalid_type"!==t.code?{message:i.defaultError}:{message:n??r??i.defaultError}},description:i}}class m2{get description(){return this._def.description}_getType(e){return mV(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:mV(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new mK,ctx:{common:e.parent.common,data:e.data,parsedType:mV(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let t=this._parse(e);if(mX(t))throw Error("Synchronous parse encountered promise.");return t}_parseAsync(e){return Promise.resolve(this._parse(e))}parse(e,t){let r=this.safeParse(e,t);if(r.success)return r.data;throw r.error}safeParse(e,t){let r={common:{issues:[],async:t?.async??!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:mV(e)},a=this._parseSync({data:e,path:r.path,parent:r});return m0(r,a)}"~validate"(e){let t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:mV(e)};if(!this["~standard"].async)try{let r=this._parseSync({data:e,path:[],parent:t});return"valid"===r.status?{value:r.value}:{issues:t.common.issues}}catch(e){e?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(e=>"valid"===e.status?{value:e.value}:{issues:t.common.issues})}async parseAsync(e,t){let r=await this.safeParseAsync(e,t);if(r.success)return r.data;throw r.error}async safeParseAsync(e,t){let r={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:mV(e)},a=this._parse({data:e,path:r.path,parent:r});return m0(r,await (mX(a)?a:Promise.resolve(a)))}refine(e,t){return this._refinement((r,a)=>{let i=e(r),n=()=>a.addIssue({code:mF.custom,..."string"==typeof t||void 0===t?{message:t}:"function"==typeof t?t(r):t});return"u">typeof Promise&&i instanceof Promise?i.then(e=>!!e||(n(),!1)):!!i||(n(),!1)})}refinement(e,t){return this._refinement((r,a)=>!!e(r)||(a.addIssue("function"==typeof t?t(r,a):t),!1))}_refinement(e){return new hq({schema:this,typeName:M.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return hA.create(this,this._def)}nullable(){return hz.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return h$.create(this)}promise(){return hN.create(this,this._def)}or(e){return hR.create([this,e],this._def)}and(e){return hk.create(this,e,this._def)}transform(e){return new hq({...m1(this._def),schema:this,typeName:M.ZodEffects,effect:{type:"transform",transform:e}})}default(e){return new hM({...m1(this._def),innerType:this,defaultValue:"function"==typeof e?e:()=>e,typeName:M.ZodDefault})}brand(){return new hD({typeName:M.ZodBranded,type:this,...m1(this._def)})}catch(e){return new hL({...m1(this._def),innerType:this,catchValue:"function"==typeof e?e:()=>e,typeName:M.ZodCatch})}describe(e){return new this.constructor({...this._def,description:e})}pipe(e){return hU.create(this,e)}readonly(){return hV.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}let m9=/^c[^\s-]{8,}$/i,m4=/^[0-9a-z]+$/,m3=/^[0-9A-HJKMNP-TV-Z]{26}$/i,m5=/^[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,m6=/^[a-z0-9_-]{21}$/i,m7=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,m8=/^[-+]?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)?)??$/,he=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,ht=/^(?:(?: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])$/,hr=/^(?:(?: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])$/,ha=/^(([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]))$/,hi=/^(([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])$/,hn=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,ho=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,hs="((\\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])))",hl=RegExp(`^${hs}$`);function hc(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:null==e.precision&&(t=`${t}(\\.\\d+)?`);let r=e.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${r}`}class hu extends m2{_parse(e){var t,r,a,i;let n;if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==mU.string){let t=this._getOrReturnCtx(e);return mB(t,{code:mF.invalid_type,expected:mU.string,received:t.parsedType}),mG}let o=new mK;for(let s of this._def.checks)if("min"===s.kind)e.data.length<s.value&&(mB(n=this._getOrReturnCtx(e,n),{code:mF.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),o.dirty());else if("max"===s.kind)e.data.length>s.value&&(mB(n=this._getOrReturnCtx(e,n),{code:mF.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),o.dirty());else if("length"===s.kind){let t=e.data.length>s.value,r=e.data.length<s.value;(t||r)&&(n=this._getOrReturnCtx(e,n),t?mB(n,{code:mF.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):r&&mB(n,{code:mF.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),o.dirty())}else if("email"===s.kind)he.test(e.data)||(mB(n=this._getOrReturnCtx(e,n),{validation:"email",code:mF.invalid_string,message:s.message}),o.dirty());else if("emoji"===s.kind)f||(f=RegExp("^[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$","u")),f.test(e.data)||(mB(n=this._getOrReturnCtx(e,n),{validation:"emoji",code:mF.invalid_string,message:s.message}),o.dirty());else if("uuid"===s.kind)m5.test(e.data)||(mB(n=this._getOrReturnCtx(e,n),{validation:"uuid",code:mF.invalid_string,message:s.message}),o.dirty());else if("nanoid"===s.kind)m6.test(e.data)||(mB(n=this._getOrReturnCtx(e,n),{validation:"nanoid",code:mF.invalid_string,message:s.message}),o.dirty());else if("cuid"===s.kind)m9.test(e.data)||(mB(n=this._getOrReturnCtx(e,n),{validation:"cuid",code:mF.invalid_string,message:s.message}),o.dirty());else if("cuid2"===s.kind)m4.test(e.data)||(mB(n=this._getOrReturnCtx(e,n),{validation:"cuid2",code:mF.invalid_string,message:s.message}),o.dirty());else if("ulid"===s.kind)m3.test(e.data)||(mB(n=this._getOrReturnCtx(e,n),{validation:"ulid",code:mF.invalid_string,message:s.message}),o.dirty());else if("url"===s.kind)try{new URL(e.data)}catch{mB(n=this._getOrReturnCtx(e,n),{validation:"url",code:mF.invalid_string,message:s.message}),o.dirty()}else"regex"===s.kind?(s.regex.lastIndex=0,s.regex.test(e.data)||(mB(n=this._getOrReturnCtx(e,n),{validation:"regex",code:mF.invalid_string,message:s.message}),o.dirty())):"trim"===s.kind?e.data=e.data.trim():"includes"===s.kind?e.data.includes(s.value,s.position)||(mB(n=this._getOrReturnCtx(e,n),{code:mF.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),o.dirty()):"toLowerCase"===s.kind?e.data=e.data.toLowerCase():"toUpperCase"===s.kind?e.data=e.data.toUpperCase():"startsWith"===s.kind?e.data.startsWith(s.value)||(mB(n=this._getOrReturnCtx(e,n),{code:mF.invalid_string,validation:{startsWith:s.value},message:s.message}),o.dirty()):"endsWith"===s.kind?e.data.endsWith(s.value)||(mB(n=this._getOrReturnCtx(e,n),{code:mF.invalid_string,validation:{endsWith:s.value},message:s.message}),o.dirty()):"datetime"===s.kind?(function(e){let t=`${hs}T${hc(e)}`,r=[];return r.push(e.local?"Z?":"Z"),e.offset&&r.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${r.join("|")})`,RegExp(`^${t}$`)})(s).test(e.data)||(mB(n=this._getOrReturnCtx(e,n),{code:mF.invalid_string,validation:"datetime",message:s.message}),o.dirty()):"date"===s.kind?hl.test(e.data)||(mB(n=this._getOrReturnCtx(e,n),{code:mF.invalid_string,validation:"date",message:s.message}),o.dirty()):"time"===s.kind?RegExp(`^${hc(s)}$`).test(e.data)||(mB(n=this._getOrReturnCtx(e,n),{code:mF.invalid_string,validation:"time",message:s.message}),o.dirty()):"duration"===s.kind?m8.test(e.data)||(mB(n=this._getOrReturnCtx(e,n),{validation:"duration",code:mF.invalid_string,message:s.message}),o.dirty()):"ip"===s.kind?(t=e.data,!(("v4"===(r=s.version)||!r)&&ht.test(t)||("v6"===r||!r)&&ha.test(t))&&1&&(mB(n=this._getOrReturnCtx(e,n),{validation:"ip",code:mF.invalid_string,message:s.message}),o.dirty())):"jwt"===s.kind?!function(e,t){if(!m7.test(e))return!1;try{let[r]=e.split(".");if(!r)return!1;let a=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(r.length+(4-r.length%4)%4,"="),i=JSON.parse(atob(a));if("object"!=typeof i||null===i||"typ"in i&&i?.typ!=="JWT"||!i.alg||t&&i.alg!==t)return!1;return!0}catch{return!1}}(e.data,s.alg)&&(mB(n=this._getOrReturnCtx(e,n),{validation:"jwt",code:mF.invalid_string,message:s.message}),o.dirty()):"cidr"===s.kind?(a=e.data,!(("v4"===(i=s.version)||!i)&&hr.test(a)||("v6"===i||!i)&&hi.test(a))&&1&&(mB(n=this._getOrReturnCtx(e,n),{validation:"cidr",code:mF.invalid_string,message:s.message}),o.dirty())):"base64"===s.kind?hn.test(e.data)||(mB(n=this._getOrReturnCtx(e,n),{validation:"base64",code:mF.invalid_string,message:s.message}),o.dirty()):"base64url"===s.kind?ho.test(e.data)||(mB(n=this._getOrReturnCtx(e,n),{validation:"base64url",code:mF.invalid_string,message:s.message}),o.dirty()):q.assertNever(s);return{status:o.value,value:e.data}}_regex(e,t,r){return this.refinement(t=>e.test(t),{validation:t,code:mF.invalid_string,...z.errToObj(r)})}_addCheck(e){return new hu({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...z.errToObj(e)})}url(e){return this._addCheck({kind:"url",...z.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...z.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...z.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...z.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...z.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...z.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...z.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...z.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...z.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...z.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...z.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...z.errToObj(e)})}datetime(e){return"string"==typeof e?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:void 0===e?.precision?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...z.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return"string"==typeof e?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:void 0===e?.precision?null:e?.precision,...z.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...z.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...z.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...z.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...z.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...z.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...z.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...z.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...z.errToObj(t)})}nonempty(e){return this.min(1,z.errToObj(e))}trim(){return new hu({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new hu({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new hu({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>"datetime"===e.kind)}get isDate(){return!!this._def.checks.find(e=>"date"===e.kind)}get isTime(){return!!this._def.checks.find(e=>"time"===e.kind)}get isDuration(){return!!this._def.checks.find(e=>"duration"===e.kind)}get isEmail(){return!!this._def.checks.find(e=>"email"===e.kind)}get isURL(){return!!this._def.checks.find(e=>"url"===e.kind)}get isEmoji(){return!!this._def.checks.find(e=>"emoji"===e.kind)}get isUUID(){return!!this._def.checks.find(e=>"uuid"===e.kind)}get isNANOID(){return!!this._def.checks.find(e=>"nanoid"===e.kind)}get isCUID(){return!!this._def.checks.find(e=>"cuid"===e.kind)}get isCUID2(){return!!this._def.checks.find(e=>"cuid2"===e.kind)}get isULID(){return!!this._def.checks.find(e=>"ulid"===e.kind)}get isIP(){return!!this._def.checks.find(e=>"ip"===e.kind)}get isCIDR(){return!!this._def.checks.find(e=>"cidr"===e.kind)}get isBase64(){return!!this._def.checks.find(e=>"base64"===e.kind)}get isBase64url(){return!!this._def.checks.find(e=>"base64url"===e.kind)}get minLength(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}hu.create=e=>new hu({checks:[],typeName:M.ZodString,coerce:e?.coerce??!1,...m1(e)});class hd extends m2{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){let t;if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==mU.number){let t=this._getOrReturnCtx(e);return mB(t,{code:mF.invalid_type,expected:mU.number,received:t.parsedType}),mG}let r=new mK;for(let a of this._def.checks)"int"===a.kind?q.isInteger(e.data)||(mB(t=this._getOrReturnCtx(e,t),{code:mF.invalid_type,expected:"integer",received:"float",message:a.message}),r.dirty()):"min"===a.kind?(a.inclusive?e.data<a.value:e.data<=a.value)&&(mB(t=this._getOrReturnCtx(e,t),{code:mF.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):"max"===a.kind?(a.inclusive?e.data>a.value:e.data>=a.value)&&(mB(t=this._getOrReturnCtx(e,t),{code:mF.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):"multipleOf"===a.kind?0!==function(e,t){let r=(e.toString().split(".")[1]||"").length,a=(t.toString().split(".")[1]||"").length,i=r>a?r:a;return Number.parseInt(e.toFixed(i).replace(".",""))%Number.parseInt(t.toFixed(i).replace(".",""))/10**i}(e.data,a.value)&&(mB(t=this._getOrReturnCtx(e,t),{code:mF.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):"finite"===a.kind?Number.isFinite(e.data)||(mB(t=this._getOrReturnCtx(e,t),{code:mF.not_finite,message:a.message}),r.dirty()):q.assertNever(a);return{status:r.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,z.toString(t))}gt(e,t){return this.setLimit("min",e,!1,z.toString(t))}lte(e,t){return this.setLimit("max",e,!0,z.toString(t))}lt(e,t){return this.setLimit("max",e,!1,z.toString(t))}setLimit(e,t,r,a){return new hd({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:z.toString(a)}]})}_addCheck(e){return new hd({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:z.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:z.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:z.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:z.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:z.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:z.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:z.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:z.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:z.toString(e)})}get minValue(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>"int"===e.kind||"multipleOf"===e.kind&&q.isInteger(e.value))}get isFinite(){let e=null,t=null;for(let r of this._def.checks)if("finite"===r.kind||"int"===r.kind||"multipleOf"===r.kind)return!0;else"min"===r.kind?(null===t||r.value>t)&&(t=r.value):"max"===r.kind&&(null===e||r.value<e)&&(e=r.value);return Number.isFinite(t)&&Number.isFinite(e)}}hd.create=e=>new hd({checks:[],typeName:M.ZodNumber,coerce:e?.coerce||!1,...m1(e)});class hp extends m2{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){let t;if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==mU.bigint)return this._getInvalidInput(e);let r=new mK;for(let a of this._def.checks)"min"===a.kind?(a.inclusive?e.data<a.value:e.data<=a.value)&&(mB(t=this._getOrReturnCtx(e,t),{code:mF.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):"max"===a.kind?(a.inclusive?e.data>a.value:e.data>=a.value)&&(mB(t=this._getOrReturnCtx(e,t),{code:mF.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):"multipleOf"===a.kind?e.data%a.value!==BigInt(0)&&(mB(t=this._getOrReturnCtx(e,t),{code:mF.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):q.assertNever(a);return{status:r.value,value:e.data}}_getInvalidInput(e){let t=this._getOrReturnCtx(e);return mB(t,{code:mF.invalid_type,expected:mU.bigint,received:t.parsedType}),mG}gte(e,t){return this.setLimit("min",e,!0,z.toString(t))}gt(e,t){return this.setLimit("min",e,!1,z.toString(t))}lte(e,t){return this.setLimit("max",e,!0,z.toString(t))}lt(e,t){return this.setLimit("max",e,!1,z.toString(t))}setLimit(e,t,r,a){return new hp({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:z.toString(a)}]})}_addCheck(e){return new hp({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:z.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:z.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:z.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:z.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:z.toString(t)})}get minValue(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}hp.create=e=>new hp({checks:[],typeName:M.ZodBigInt,coerce:e?.coerce??!1,...m1(e)});class hm extends m2{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==mU.boolean){let t=this._getOrReturnCtx(e);return mB(t,{code:mF.invalid_type,expected:mU.boolean,received:t.parsedType}),mG}return mY(e.data)}}hm.create=e=>new hm({typeName:M.ZodBoolean,coerce:e?.coerce||!1,...m1(e)});class hh extends m2{_parse(e){let t;if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==mU.date){let t=this._getOrReturnCtx(e);return mB(t,{code:mF.invalid_type,expected:mU.date,received:t.parsedType}),mG}if(Number.isNaN(e.data.getTime()))return mB(this._getOrReturnCtx(e),{code:mF.invalid_date}),mG;let r=new mK;for(let a of this._def.checks)"min"===a.kind?e.data.getTime()<a.value&&(mB(t=this._getOrReturnCtx(e,t),{code:mF.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),r.dirty()):"max"===a.kind?e.data.getTime()>a.value&&(mB(t=this._getOrReturnCtx(e,t),{code:mF.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),r.dirty()):q.assertNever(a);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new hh({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:z.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:z.toString(t)})}get minDate(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return null!=e?new Date(e):null}get maxDate(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return null!=e?new Date(e):null}}hh.create=e=>new hh({checks:[],coerce:e?.coerce||!1,typeName:M.ZodDate,...m1(e)});class hf extends m2{_parse(e){if(this._getType(e)!==mU.symbol){let t=this._getOrReturnCtx(e);return mB(t,{code:mF.invalid_type,expected:mU.symbol,received:t.parsedType}),mG}return mY(e.data)}}hf.create=e=>new hf({typeName:M.ZodSymbol,...m1(e)});class hg extends m2{_parse(e){if(this._getType(e)!==mU.undefined){let t=this._getOrReturnCtx(e);return mB(t,{code:mF.invalid_type,expected:mU.undefined,received:t.parsedType}),mG}return mY(e.data)}}hg.create=e=>new hg({typeName:M.ZodUndefined,...m1(e)});class hy extends m2{_parse(e){if(this._getType(e)!==mU.null){let t=this._getOrReturnCtx(e);return mB(t,{code:mF.invalid_type,expected:mU.null,received:t.parsedType}),mG}return mY(e.data)}}hy.create=e=>new hy({typeName:M.ZodNull,...m1(e)});class hv extends m2{constructor(){super(...arguments),this._any=!0}_parse(e){return mY(e.data)}}hv.create=e=>new hv({typeName:M.ZodAny,...m1(e)});class h_ extends m2{constructor(){super(...arguments),this._unknown=!0}_parse(e){return mY(e.data)}}h_.create=e=>new h_({typeName:M.ZodUnknown,...m1(e)});class hb extends m2{_parse(e){let t=this._getOrReturnCtx(e);return mB(t,{code:mF.invalid_type,expected:mU.never,received:t.parsedType}),mG}}hb.create=e=>new hb({typeName:M.ZodNever,...m1(e)});class hS extends m2{_parse(e){if(this._getType(e)!==mU.undefined){let t=this._getOrReturnCtx(e);return mB(t,{code:mF.invalid_type,expected:mU.void,received:t.parsedType}),mG}return mY(e.data)}}hS.create=e=>new hS({typeName:M.ZodVoid,...m1(e)});class h$ extends m2{_parse(e){let{ctx:t,status:r}=this._processInputParams(e),a=this._def;if(t.parsedType!==mU.array)return mB(t,{code:mF.invalid_type,expected:mU.array,received:t.parsedType}),mG;if(null!==a.exactLength){let e=t.data.length>a.exactLength.value,i=t.data.length<a.exactLength.value;(e||i)&&(mB(t,{code:e?mF.too_big:mF.too_small,minimum:i?a.exactLength.value:void 0,maximum:e?a.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:a.exactLength.message}),r.dirty())}if(null!==a.minLength&&t.data.length<a.minLength.value&&(mB(t,{code:mF.too_small,minimum:a.minLength.value,type:"array",inclusive:!0,exact:!1,message:a.minLength.message}),r.dirty()),null!==a.maxLength&&t.data.length>a.maxLength.value&&(mB(t,{code:mF.too_big,maximum:a.maxLength.value,type:"array",inclusive:!0,exact:!1,message:a.maxLength.message}),r.dirty()),t.common.async)return Promise.all([...t.data].map((e,r)=>a.type._parseAsync(new mQ(t,e,t.path,r)))).then(e=>mK.mergeArray(r,e));let i=[...t.data].map((e,r)=>a.type._parseSync(new mQ(t,e,t.path,r)));return mK.mergeArray(r,i)}get element(){return this._def.type}min(e,t){return new h$({...this._def,minLength:{value:e,message:z.toString(t)}})}max(e,t){return new h$({...this._def,maxLength:{value:e,message:z.toString(t)}})}length(e,t){return new h$({...this._def,exactLength:{value:e,message:z.toString(t)}})}nonempty(e){return this.min(1,e)}}h$.create=(e,t)=>new h$({type:e,minLength:null,maxLength:null,exactLength:null,typeName:M.ZodArray,...m1(t)});class hw extends m2{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;let e=this._def.shape(),t=q.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==mU.object){let t=this._getOrReturnCtx(e);return mB(t,{code:mF.invalid_type,expected:mU.object,received:t.parsedType}),mG}let{status:t,ctx:r}=this._processInputParams(e),{shape:a,keys:i}=this._getCached(),n=[];if(!(this._def.catchall instanceof hb&&"strip"===this._def.unknownKeys))for(let e in r.data)i.includes(e)||n.push(e);let o=[];for(let e of i){let t=a[e],i=r.data[e];o.push({key:{status:"valid",value:e},value:t._parse(new mQ(r,i,r.path,e)),alwaysSet:e in r.data})}if(this._def.catchall instanceof hb){let e=this._def.unknownKeys;if("passthrough"===e)for(let e of n)o.push({key:{status:"valid",value:e},value:{status:"valid",value:r.data[e]}});else if("strict"===e)n.length>0&&(mB(r,{code:mF.unrecognized_keys,keys:n}),t.dirty());else if("strip"===e);else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let e=this._def.catchall;for(let t of n){let a=r.data[t];o.push({key:{status:"valid",value:t},value:e._parse(new mQ(r,a,r.path,t)),alwaysSet:t in r.data})}}return r.common.async?Promise.resolve().then(async()=>{let e=[];for(let t of o){let r=await t.key,a=await t.value;e.push({key:r,value:a,alwaysSet:t.alwaysSet})}return e}).then(e=>mK.mergeObjectSync(t,e)):mK.mergeObjectSync(t,o)}get shape(){return this._def.shape()}strict(e){return z.errToObj,new hw({...this._def,unknownKeys:"strict",...void 0!==e?{errorMap:(t,r)=>{let a=this._def.errorMap?.(t,r).message??r.defaultError;return"unrecognized_keys"===t.code?{message:z.errToObj(e).message??a}:{message:a}}}:{}})}strip(){return new hw({...this._def,unknownKeys:"strip"})}passthrough(){return new hw({...this._def,unknownKeys:"passthrough"})}extend(e){return new hw({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new hw({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:M.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new hw({...this._def,catchall:e})}pick(e){let t={};for(let r of q.objectKeys(e))e[r]&&this.shape[r]&&(t[r]=this.shape[r]);return new hw({...this._def,shape:()=>t})}omit(e){let t={};for(let r of q.objectKeys(this.shape))e[r]||(t[r]=this.shape[r]);return new hw({...this._def,shape:()=>t})}deepPartial(){return function e(t){if(t instanceof hw){let r={};for(let a in t.shape){let i=t.shape[a];r[a]=hA.create(e(i))}return new hw({...t._def,shape:()=>r})}if(t instanceof h$)return new h$({...t._def,type:e(t.element)});if(t instanceof hA)return hA.create(e(t.unwrap()));if(t instanceof hz)return hz.create(e(t.unwrap()));if(t instanceof hx)return hx.create(t.items.map(t=>e(t)));else return t}(this)}partial(e){let t={};for(let r of q.objectKeys(this.shape)){let a=this.shape[r];e&&!e[r]?t[r]=a:t[r]=a.optional()}return new hw({...this._def,shape:()=>t})}required(e){let t={};for(let r of q.objectKeys(this.shape))if(e&&!e[r])t[r]=this.shape[r];else{let e=this.shape[r];for(;e instanceof hA;)e=e._def.innerType;t[r]=e}return new hw({...this._def,shape:()=>t})}keyof(){return hO(q.objectKeys(this.shape))}}hw.create=(e,t)=>new hw({shape:()=>e,unknownKeys:"strip",catchall:hb.create(),typeName:M.ZodObject,...m1(t)}),hw.strictCreate=(e,t)=>new hw({shape:()=>e,unknownKeys:"strict",catchall:hb.create(),typeName:M.ZodObject,...m1(t)}),hw.lazycreate=(e,t)=>new hw({shape:e,unknownKeys:"strip",catchall:hb.create(),typeName:M.ZodObject,...m1(t)});class hR extends m2{_parse(e){let{ctx:t}=this._processInputParams(e),r=this._def.options;if(t.common.async)return Promise.all(r.map(async e=>{let r={...t,common:{...t.common,issues:[]},parent:null};return{result:await e._parseAsync({data:t.data,path:t.path,parent:r}),ctx:r}})).then(function(e){for(let t of e)if("valid"===t.result.status)return t.result;for(let r of e)if("dirty"===r.result.status)return t.common.issues.push(...r.ctx.common.issues),r.result;let r=e.map(e=>new mH(e.ctx.common.issues));return mB(t,{code:mF.invalid_union,unionErrors:r}),mG});{let e,a=[];for(let i of r){let r={...t,common:{...t.common,issues:[]},parent:null},n=i._parseSync({data:t.data,path:t.path,parent:r});if("valid"===n.status)return n;"dirty"!==n.status||e||(e={result:n,ctx:r}),r.common.issues.length&&a.push(r.common.issues)}if(e)return t.common.issues.push(...e.ctx.common.issues),e.result;let i=a.map(e=>new mH(e));return mB(t,{code:mF.invalid_union,unionErrors:i}),mG}}get options(){return this._def.options}}hR.create=(e,t)=>new hR({options:e,typeName:M.ZodUnion,...m1(t)});class hk extends m2{_parse(e){let{status:t,ctx:r}=this._processInputParams(e),a=(e,a)=>{if("aborted"===e.status||"aborted"===a.status)return mG;let i=function e(t,r){let a=mV(t),i=mV(r);if(t===r)return{valid:!0,data:t};if(a===mU.object&&i===mU.object){let a=q.objectKeys(r),i=q.objectKeys(t).filter(e=>-1!==a.indexOf(e)),n={...t,...r};for(let a of(Object.prototype.hasOwnProperty.call(n,"__proto__")&&delete n.__proto__,i)){if("__proto__"===a)continue;let i=e(t[a],r[a]);if(!i.valid)return{valid:!1};n[a]=i.data}return{valid:!0,data:n}}if(a===mU.array&&i===mU.array){if(t.length!==r.length)return{valid:!1};let a=[];for(let i=0;i<t.length;i++){let n=e(t[i],r[i]);if(!n.valid)return{valid:!1};a.push(n.data)}return{valid:!0,data:a}}if(a===mU.date&&i===mU.date&&+t==+r)return{valid:!0,data:t};return{valid:!1}}(e.value,a.value);return i.valid?(("dirty"===e.status||"dirty"===a.status)&&t.dirty(),{status:t.value,value:i.data}):(mB(r,{code:mF.invalid_intersection_types}),mG)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([e,t])=>a(e,t)):a(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}hk.create=(e,t,r)=>new hk({left:e,right:t,typeName:M.ZodIntersection,...m1(r)});class hx extends m2{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==mU.array)return mB(r,{code:mF.invalid_type,expected:mU.array,received:r.parsedType}),mG;if(r.data.length<this._def.items.length)return mB(r,{code:mF.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),mG;!this._def.rest&&r.data.length>this._def.items.length&&(mB(r,{code:mF.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());let a=[...r.data].map((e,t)=>{let a=this._def.items[t]||this._def.rest;return a?a._parse(new mQ(r,e,r.path,t)):null}).filter(e=>!!e);return r.common.async?Promise.all(a).then(e=>mK.mergeArray(t,e)):mK.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new hx({...this._def,rest:e})}}hx.create=(e,t)=>{if(!Array.isArray(e))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new hx({items:e,typeName:M.ZodTuple,rest:null,...m1(t)})};class hP extends m2{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==mU.map)return mB(r,{code:mF.invalid_type,expected:mU.map,received:r.parsedType}),mG;let a=this._def.keyType,i=this._def.valueType,n=[...r.data.entries()].map(([e,t],n)=>({key:a._parse(new mQ(r,e,r.path,[n,"key"])),value:i._parse(new mQ(r,t,r.path,[n,"value"]))}));if(r.common.async){let e=new Map;return Promise.resolve().then(async()=>{for(let r of n){let a=await r.key,i=await r.value;if("aborted"===a.status||"aborted"===i.status)return mG;("dirty"===a.status||"dirty"===i.status)&&t.dirty(),e.set(a.value,i.value)}return{status:t.value,value:e}})}{let e=new Map;for(let r of n){let a=r.key,i=r.value;if("aborted"===a.status||"aborted"===i.status)return mG;("dirty"===a.status||"dirty"===i.status)&&t.dirty(),e.set(a.value,i.value)}return{status:t.value,value:e}}}}hP.create=(e,t,r)=>new hP({valueType:t,keyType:e,typeName:M.ZodMap,...m1(r)});class hE extends m2{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==mU.set)return mB(r,{code:mF.invalid_type,expected:mU.set,received:r.parsedType}),mG;let a=this._def;null!==a.minSize&&r.data.size<a.minSize.value&&(mB(r,{code:mF.too_small,minimum:a.minSize.value,type:"set",inclusive:!0,exact:!1,message:a.minSize.message}),t.dirty()),null!==a.maxSize&&r.data.size>a.maxSize.value&&(mB(r,{code:mF.too_big,maximum:a.maxSize.value,type:"set",inclusive:!0,exact:!1,message:a.maxSize.message}),t.dirty());let i=this._def.valueType;function n(e){let r=new Set;for(let a of e){if("aborted"===a.status)return mG;"dirty"===a.status&&t.dirty(),r.add(a.value)}return{status:t.value,value:r}}let o=[...r.data.values()].map((e,t)=>i._parse(new mQ(r,e,r.path,t)));return r.common.async?Promise.all(o).then(e=>n(e)):n(o)}min(e,t){return new hE({...this._def,minSize:{value:e,message:z.toString(t)}})}max(e,t){return new hE({...this._def,maxSize:{value:e,message:z.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}hE.create=(e,t)=>new hE({valueType:e,minSize:null,maxSize:null,typeName:M.ZodSet,...m1(t)});class hT extends m2{get schema(){return this._def.getter()}_parse(e){let{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}hT.create=(e,t)=>new hT({getter:e,typeName:M.ZodLazy,...m1(t)});class hj extends m2{_parse(e){if(e.data!==this._def.value){let t=this._getOrReturnCtx(e);return mB(t,{received:t.data,code:mF.invalid_literal,expected:this._def.value}),mG}return{status:"valid",value:e.data}}get value(){return this._def.value}}function hO(e,t){return new hC({values:e,typeName:M.ZodEnum,...m1(t)})}hj.create=(e,t)=>new hj({value:e,typeName:M.ZodLiteral,...m1(t)});class hC extends m2{_parse(e){if("string"!=typeof e.data){let t=this._getOrReturnCtx(e),r=this._def.values;return mB(t,{expected:q.joinValues(r),received:t.parsedType,code:mF.invalid_type}),mG}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let t=this._getOrReturnCtx(e),r=this._def.values;return mB(t,{received:t.data,code:mF.invalid_enum_value,options:r}),mG}return mY(e.data)}get options(){return this._def.values}get enum(){let e={};for(let t of this._def.values)e[t]=t;return e}get Values(){let e={};for(let t of this._def.values)e[t]=t;return e}get Enum(){let e={};for(let t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return hC.create(e,{...this._def,...t})}exclude(e,t=this._def){return hC.create(this.options.filter(t=>!e.includes(t)),{...this._def,...t})}}hC.create=hO;class hI extends m2{_parse(e){let t=q.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==mU.string&&r.parsedType!==mU.number){let e=q.objectValues(t);return mB(r,{expected:q.joinValues(e),received:r.parsedType,code:mF.invalid_type}),mG}if(this._cache||(this._cache=new Set(q.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let e=q.objectValues(t);return mB(r,{received:r.data,code:mF.invalid_enum_value,options:e}),mG}return mY(e.data)}get enum(){return this._def.values}}hI.create=(e,t)=>new hI({values:e,typeName:M.ZodNativeEnum,...m1(t)});class hN extends m2{unwrap(){return this._def.type}_parse(e){let{ctx:t}=this._processInputParams(e);return t.parsedType!==mU.promise&&!1===t.common.async?(mB(t,{code:mF.invalid_type,expected:mU.promise,received:t.parsedType}),mG):mY((t.parsedType===mU.promise?t.data:Promise.resolve(t.data)).then(e=>this._def.type.parseAsync(e,{path:t.path,errorMap:t.common.contextualErrorMap})))}}hN.create=(e,t)=>new hN({type:e,typeName:M.ZodPromise,...m1(t)});class hq extends m2{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===M.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:t,ctx:r}=this._processInputParams(e),a=this._def.effect||null,i={addIssue:e=>{mB(r,e),e.fatal?t.abort():t.dirty()},get path(){return r.path}};if(i.addIssue=i.addIssue.bind(i),"preprocess"===a.type){let e=a.transform(r.data,i);if(r.common.async)return Promise.resolve(e).then(async e=>{if("aborted"===t.value)return mG;let a=await this._def.schema._parseAsync({data:e,path:r.path,parent:r});return"aborted"===a.status?mG:"dirty"===a.status||"dirty"===t.value?mW(a.value):a});{if("aborted"===t.value)return mG;let a=this._def.schema._parseSync({data:e,path:r.path,parent:r});return"aborted"===a.status?mG:"dirty"===a.status||"dirty"===t.value?mW(a.value):a}}if("refinement"===a.type){let e=e=>{let t=a.refinement(e,i);if(r.common.async)return Promise.resolve(t);if(t instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return e};if(!1!==r.common.async)return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(r=>"aborted"===r.status?mG:("dirty"===r.status&&t.dirty(),e(r.value).then(()=>({status:t.value,value:r.value}))));{let a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return"aborted"===a.status?mG:("dirty"===a.status&&t.dirty(),e(a.value),{status:t.value,value:a.value})}}if("transform"===a.type)if(!1!==r.common.async)return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(e=>"valid"!==e.status?mG:Promise.resolve(a.transform(e.value,i)).then(e=>({status:t.value,value:e})));else{let e=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if("valid"!==e.status)return mG;let n=a.transform(e.value,i);if(n instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:n}}q.assertNever(a)}}hq.create=(e,t,r)=>new hq({schema:e,typeName:M.ZodEffects,effect:t,...m1(r)}),hq.createWithPreprocess=(e,t,r)=>new hq({schema:t,effect:{type:"preprocess",transform:e},typeName:M.ZodEffects,...m1(r)});class hA extends m2{_parse(e){return this._getType(e)===mU.undefined?mY(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}hA.create=(e,t)=>new hA({innerType:e,typeName:M.ZodOptional,...m1(t)});class hz extends m2{_parse(e){return this._getType(e)===mU.null?mY(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}hz.create=(e,t)=>new hz({innerType:e,typeName:M.ZodNullable,...m1(t)});class hM extends m2{_parse(e){let{ctx:t}=this._processInputParams(e),r=t.data;return t.parsedType===mU.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}hM.create=(e,t)=>new hM({innerType:e,typeName:M.ZodDefault,defaultValue:"function"==typeof t.default?t.default:()=>t.default,...m1(t)});class hL extends m2{_parse(e){let{ctx:t}=this._processInputParams(e),r={...t,common:{...t.common,issues:[]}},a=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return mX(a)?a.then(e=>({status:"valid",value:"valid"===e.status?e.value:this._def.catchValue({get error(){return new mH(r.common.issues)},input:r.data})})):{status:"valid",value:"valid"===a.status?a.value:this._def.catchValue({get error(){return new mH(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}hL.create=(e,t)=>new hL({innerType:e,typeName:M.ZodCatch,catchValue:"function"==typeof t.catch?t.catch:()=>t.catch,...m1(t)});class hZ extends m2{_parse(e){if(this._getType(e)!==mU.nan){let t=this._getOrReturnCtx(e);return mB(t,{code:mF.invalid_type,expected:mU.nan,received:t.parsedType}),mG}return{status:"valid",value:e.data}}}hZ.create=e=>new hZ({typeName:M.ZodNaN,...m1(e)}),Symbol("zod_brand");class hD extends m2{_parse(e){let{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}class hU extends m2{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{let e=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return"aborted"===e.status?mG:"dirty"===e.status?(t.dirty(),mW(e.value)):this._def.out._parseAsync({data:e.value,path:r.path,parent:r})})();{let e=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return"aborted"===e.status?mG:"dirty"===e.status?(t.dirty(),{status:"dirty",value:e.value}):this._def.out._parseSync({data:e.value,path:r.path,parent:r})}}static create(e,t){return new hU({in:e,out:t,typeName:M.ZodPipeline})}}class hV extends m2{_parse(e){let t=this._def.innerType._parse(e),r=e=>("valid"===e.status&&(e.value=Object.freeze(e.value)),e);return mX(t)?t.then(e=>r(e)):r(t)}unwrap(){return this._def.innerType}}hV.create=(e,t)=>new hV({innerType:e,typeName:M.ZodReadonly,...m1(t)}),hw.lazycreate,(O=M||(M={})).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 hF=hu.create;hd.create,hZ.create,hp.create,hm.create,hh.create,hf.create,hg.create,hy.create,hv.create,h_.create,hb.create,hS.create,h$.create;let hH=hw.create;hw.strictCreate,hR.create,hk.create,hx.create,hP.create,hE.create,hT.create,hj.create,hC.create,hI.create,hN.create,hq.create,hA.create,hz.create,hq.createWithPreprocess,hU.create;let hJ=(e,t)=>{let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];r++);return[(e.length-r).toString(),...t.slice(r)].join("/")};function hB(e){if("openAi"!==e.target)return{};let t=[...e.basePath,e.definitionPath,e.openAiAnyTypeName];return e.flags.hasReferencedOpenAiAnyType=!0,{$ref:"relative"===e.$refStrategy?hJ(t,e.currentPath):t.join("/")}}function hK(e,t,r,a){a?.errorMessages&&r&&(e.errorMessage={...e.errorMessage,[t]:r})}function hG(e,t,r,a,i){e[t]=r,hK(e,t,a,i)}function hW(e,t){return fs(e.type._def,t)}let hY=/^[cC][^\s-]{8,}$/,hX=/^[0-9a-z]+$/,hQ=/^[0-9A-HJKMNP-TV-Z]{26}$/,h0=/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,h1=()=>(void 0===R&&(R=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),R),h2=/^(?:(?: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])$/,h9=/^(([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])$/,h4=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,h3=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,h5=/^[a-zA-Z0-9_-]{21}$/,h6=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;function h7(e,t){let r={type:"string"};if(e.checks)for(let a of e.checks)switch(a.kind){case"min":hG(r,"minLength","number"==typeof r.minLength?Math.max(r.minLength,a.value):a.value,a.message,t);break;case"max":hG(r,"maxLength","number"==typeof r.maxLength?Math.min(r.maxLength,a.value):a.value,a.message,t);break;case"email":switch(t.emailStrategy){case"format:email":ft(r,"email",a.message,t);break;case"format:idn-email":ft(r,"idn-email",a.message,t);break;case"pattern:zod":fr(r,h0,a.message,t)}break;case"url":ft(r,"uri",a.message,t);break;case"uuid":ft(r,"uuid",a.message,t);break;case"regex":fr(r,a.regex,a.message,t);break;case"cuid":fr(r,hY,a.message,t);break;case"cuid2":fr(r,hX,a.message,t);break;case"startsWith":fr(r,RegExp(`^${h8(a.value,t)}`),a.message,t);break;case"endsWith":fr(r,RegExp(`${h8(a.value,t)}$`),a.message,t);break;case"datetime":ft(r,"date-time",a.message,t);break;case"date":ft(r,"date",a.message,t);break;case"time":ft(r,"time",a.message,t);break;case"duration":ft(r,"duration",a.message,t);break;case"length":hG(r,"minLength","number"==typeof r.minLength?Math.max(r.minLength,a.value):a.value,a.message,t),hG(r,"maxLength","number"==typeof r.maxLength?Math.min(r.maxLength,a.value):a.value,a.message,t);break;case"includes":fr(r,RegExp(h8(a.value,t)),a.message,t);break;case"ip":"v6"!==a.version&&ft(r,"ipv4",a.message,t),"v4"!==a.version&&ft(r,"ipv6",a.message,t);break;case"base64url":fr(r,h3,a.message,t);break;case"jwt":fr(r,h6,a.message,t);break;case"cidr":"v6"!==a.version&&fr(r,h2,a.message,t),"v4"!==a.version&&fr(r,h9,a.message,t);break;case"emoji":fr(r,h1(),a.message,t);break;case"ulid":fr(r,hQ,a.message,t);break;case"base64":switch(t.base64Strategy){case"format:binary":ft(r,"binary",a.message,t);break;case"contentEncoding:base64":hG(r,"contentEncoding","base64",a.message,t);break;case"pattern:zod":fr(r,h4,a.message,t)}break;case"nanoid":fr(r,h5,a.message,t)}return r}function h8(e,t){return"escape"===t.patternStrategy?function(e){let t="";for(let r=0;r<e.length;r++)fe.has(e[r])||(t+="\\"),t+=e[r];return t}(e):e}let fe=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function ft(e,t,r,a){e.format||e.anyOf?.some(e=>e.format)?(e.anyOf||(e.anyOf=[]),e.format&&(e.anyOf.push({format:e.format,...e.errorMessage&&a.errorMessages&&{errorMessage:{format:e.errorMessage.format}}}),delete e.format,e.errorMessage&&(delete e.errorMessage.format,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.anyOf.push({format:t,...r&&a.errorMessages&&{errorMessage:{format:r}}})):hG(e,"format",t,r,a)}function fr(e,t,r,a){e.pattern||e.allOf?.some(e=>e.pattern)?(e.allOf||(e.allOf=[]),e.pattern&&(e.allOf.push({pattern:e.pattern,...e.errorMessage&&a.errorMessages&&{errorMessage:{pattern:e.errorMessage.pattern}}}),delete e.pattern,e.errorMessage&&(delete e.errorMessage.pattern,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.allOf.push({pattern:fa(t,a),...r&&a.errorMessages&&{errorMessage:{pattern:r}}})):hG(e,"pattern",fa(t,a),r,a)}function fa(e,t){if(!t.applyRegexFlags||!e.flags)return e.source;let r={i:e.flags.includes("i"),m:e.flags.includes("m"),s:e.flags.includes("s")},a=r.i?e.source.toLowerCase():e.source,i="",n=!1,o=!1,s=!1;for(let e=0;e<a.length;e++){if(n){i+=a[e],n=!1;continue}if(r.i){if(o){if(a[e].match(/[a-z]/)){s?(i+=a[e],i+=`${a[e-2]}-${a[e]}`.toUpperCase(),s=!1):"-"===a[e+1]&&a[e+2]?.match(/[a-z]/)?(i+=a[e],s=!0):i+=`${a[e]}${a[e].toUpperCase()}`;continue}}else if(a[e].match(/[a-z]/)){i+=`[${a[e]}${a[e].toUpperCase()}]`;continue}}if(r.m){if("^"===a[e]){i+=`(^|(?<=[\r
77
+ `,e.enqueue(t.encode(i)),!0}catch(e){return this.onerror?.(e),!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(e,t){try{let r,a,i,n,o,s=e.headers.get("accept");if(!s?.includes("application/json")||!s.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(e.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(t?.parsedBody===void 0)try{let t=await pX(e,this._maxRequestBodySize);if(t.tooLarge){let e=pW(this._maxRequestBodySize);return this.onerror?.(Error(e)),this.createJsonErrorResponse(413,-32e3,e)}r=JSON.parse(t.text)}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON")}else r=t.parsedBody;if(Array.isArray(r)&&r.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{a=Array.isArray(r)?r.map(e=>os.parse(e)):[os.parse(r)]}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON-RPC message")}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");let l=a.some(e=>o$.safeParse(e).success);if(l){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(a.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(!l){let t=this.validateSession(e);if(t)return t;let r=this.validateProtocolVersion(e);if(r)return r}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");try{i=await this._checkScopeChallenge(a,t?.authInfo)}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(500,-32603,"Internal server error")}if(i)return i;if(!a.some(e=>cB(e))){for(let r of a)this.onmessage?.(r,{authInfo:t?.authInfo,request:e});return new Response(null,{status:202})}let c=crypto.randomUUID(),u=a.find(e=>o$.safeParse(e).success),d=u?u.params.protocolVersion:e.headers.get("mcp-protocol-version")??"2025-03-26";if(this._enableJsonResponse)return new Promise(r=>{for(let e of(this._streamMapping.set(c,{resolveJson:r,cleanup:()=>{this._streamMapping.delete(c)}}),a))cB(e)&&this._requestToStreamMapping.set(e.id,c);for(let r of a)this.onmessage?.(r,{authInfo:t?.authInfo,request:e})});let p=new TextEncoder,m=new ReadableStream({start:e=>{n=e},cancel:()=>{void 0!==o&&clearInterval(o),this._streamMapping.get(c)?.controller===n&&this._streamMapping.delete(c)}}),h={"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"};for(let e of(void 0!==this.sessionId&&(h["mcp-session-id"]=this.sessionId),a))cB(e)&&(this._streamMapping.set(c,{controller:n,encoder:p,cleanup:()=>{void 0!==o&&clearInterval(o),this._streamMapping.delete(c);try{n.close()}catch{}}}),this._requestToStreamMapping.set(e.id,c));for(let r of(await this.writePrimingEvent(n,p,c,d),a)){let a,i;cB(r)&&this._eventStore&&this.supportsEmptySSEData(d)&&(a=()=>{this.closeSSEStream(r.id)},i=()=>{this.closeStandaloneSSEStream()}),this.onmessage?.(r,{authInfo:t?.authInfo,request:e,closeSSEStream:a,closeStandaloneSSEStream:i})}return this._streamMapping.get(c)?.controller===n&&(o=this.startKeepAlive(n,p)),new Response(m,{status:200,headers:h})}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(400,-32700,"Parse error",{data:String(e)})}}async handleDeleteRequest(e){let t=this.validateSession(e);if(t)return t;let r=this.validateProtocolVersion(e);if(r)return r;try{return await Promise.resolve(this._onsessionclosed?.(this.sessionId)),new Response(null,{status:200})}finally{await this.close()}}validateSession(e){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 t=e.headers.get("mcp-session-id");return t?t!==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(e){let t=e.headers.get("mcp-protocol-version");if(null!==t&&!this._supportedProtocolVersions.includes(t)){let e=`Bad Request: Unsupported protocol version: ${t} (supported versions: ${this._supportedProtocolVersions.join(", ")})`;return this.onerror?.(Error(e)),this.createJsonErrorResponse(400,-32e3,e)}}async close(){if(!this._closed){for(let{cleanup:e}of(this._closed=!0,this._streamMapping.values()))e();this._streamMapping.clear(),this._requestResponseMap.clear(),this.onclose?.()}}closeSSEStream(e){let t=this._requestToStreamMapping.get(e);if(!t)return;let r=this._streamMapping.get(t);r&&r.cleanup()}closeStandaloneSSEStream(){let e=this._streamMapping.get(this._standaloneSseStreamId);e&&e.cleanup()}async send(e,t){let r=t?.relatedRequestId;if((cG(e)||cW(e))&&(r=e.id),void 0===r){let t;if(cG(e)||cW(e))throw Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");this._eventStore&&(t=await this._eventStore.storeEvent(this._standaloneSseStreamId,e));let r=this._streamMapping.get(this._standaloneSseStreamId);if(void 0===r)return;r.controller&&r.encoder&&(void 0===t||!r.replayedEventIds?.has(t))&&this.writeSSEEvent(r.controller,r.encoder,e,t);return}let a=this._requestToStreamMapping.get(r);if(!a)throw Error(`No connection established for request ID: ${String(r)}`);let i=this._streamMapping.get(a);if(!this._enableJsonResponse){let t;this._eventStore&&(t=await this._eventStore.storeEvent(a,e),i=this._streamMapping.get(a)),i?.controller&&i?.encoder&&(void 0===t||!i.replayedEventIds?.has(t))&&this.writeSSEEvent(i.controller,i.encoder,e,t)}if(cG(e)||cW(e)){this._requestResponseMap.set(r,e);let t=[...this._requestToStreamMapping.entries()].filter(([e,t])=>t===a).map(([e])=>e);if(t.every(e=>this._requestResponseMap.has(e))){if(!i){if(this._enableJsonResponse)throw Error(`No connection established for request ID: ${String(r)}`);if(!this._eventStore){for(let e of(this.onerror?.(Error(`Response for request ID ${String(r)} is undeliverable: per-request stream is disconnected and no eventStore is configured`)),t))this._requestResponseMap.delete(e),this._requestToStreamMapping.delete(e);return}for(let e of t)this._requestResponseMap.delete(e),this._requestToStreamMapping.delete(e);return}if(this._enableJsonResponse&&i.resolveJson){let e={"Content-Type":"application/json"};void 0!==this.sessionId&&(e["mcp-session-id"]=this.sessionId);let r=t.map(e=>this._requestResponseMap.get(e));1===r.length?i.resolveJson(Response.json(r[0],{status:200,headers:e})):i.resolveJson(Response.json(r,{status:200,headers:e})),i.cleanup()}else i.cleanup();for(let e of t)this._requestResponseMap.delete(e),this._requestToStreamMapping.delete(e)}}}};function p0(e){if(null===e||"object"!=typeof e||Array.isArray(e))return null;let{method:t,id:r}=e;return"string"!=typeof t?null:"string"==typeof r||"number"==typeof r?r:null}function p1(e,t,r,a,i=null){return Response.json({jsonrpc:"2.0",error:{code:t,message:r,...void 0!==a&&{data:a}},id:i},{status:e,...405===e&&{headers:{Allow:"POST"}}})}function p2(e,t=null){return p1(e.httpStatus,e.code,e.message,e.data,t)}function p9(e){return e instanceof Error?e:Error(String(e))}function p4(e=null){return p1(500,-32603,"Internal server error",void 0,e)}function p3(e){if(void 0!==e.transport)throw Error("The factory returned an instance that is still serving another request. Return a new instance for each request.")}function p5(e){return{protocolVersionHeader:e.headers.get("mcp-protocol-version")??void 0,mcpMethodHeader:e.headers.get("mcp-method")??void 0,mcpNameHeader:e.headers.get("mcp-name")??void 0}}let p6=t("async_hooks"),p7=(e,t)=>{globalThis[e]=t},p8=e=>globalThis[e];function me({name:e,fallback:t=!0}){let r=Symbol.for(`xmcp-context-${e}`),a=Symbol.for(`xmcp-context-${e}-fallback-store`);if(p8(r))return p8(r);let i=new p6.AsyncLocalStorage,n=globalThis[a]??{current:null};p7(a,n);let o={provider:(e,r)=>(t&&(n.current=e),i.run(e,r)),getContext:()=>{let r=i.getStore();if(r)return r;if(t&&n.current)return n.current;throw Error(`getContext() can only be used within the ${e} context.`)},setContext:r=>{let a=i.getStore()??(t?n.current:null);if(!a)throw Error(`setContext() can only be used within the ${e} context.`);Object.assign(a,r)}};return p7(r,o),o}let mt=me({name:"http-request-context"});mt.setContext;let mr=mt.getContext,ma=mt.provider,mi=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),mn=e=>{if(!mi(e)||"string"!=typeof e.name||"string"!=typeof e.version)return;let t={name:e.name,version:e.version};return"string"==typeof e.title&&(t.title=e.title),"string"==typeof e.websiteUrl&&(t.websiteUrl=e.websiteUrl),"string"==typeof e.description&&(t.description=e.description),t},mo=e=>{if(e&&"initialize"===e.method&&mi(e.params))return mn(e.params.clientInfo)},ms=(e,t)=>{let r=t.toLowerCase();for(let[t,a]of Object.entries(e)){if(t.toLowerCase()!==r)continue;let e=Array.isArray(a)?a[0]:a;if("string"!=typeof e)break;let i=e.trim();return i.length>0?i:void 0}};function ml(e){let{tags:t,enabled:r,...a}=e;return{...a,_meta:void 0===t?a._meta:{...a._meta,"xmcp/tags":t}}}let mc=new class{add(e,t){this.resources.set(e,t)}getAll(){return this.resources}clear(){this.resources.clear()}has(e){return this.resources.has(e)}constructor(){var e,t;e="resources",t=new Map,e in this?Object.defineProperty(this,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):this[e]=t}},mu=me({name:"request-context",fallback:!1});function md(){try{return mu.getContext().value}catch{throw Error("getRequestContext() can only be used while handling an MCP request.")}}function mp(e,t,r,a=!1){let i;if(a){let t;try{t=mu.getContext()}catch{}if(t?.request===e.mcpReq)return r()}let n=new Map;if(e.http){let e=mr(),t=Object.fromEntries(Object.entries(e.headers).map(([e,t])=>[e,Array.isArray(t)?Object.freeze([...t]):t]));i=Object.freeze({id:e.id,headers:Object.freeze(t)})}let o=Object.freeze({clientInfo:t?Object.freeze({...t}):void 0,http:i,authInfo:e.http?.authInfo,_meta:e.mcpReq._meta?Object.freeze({...e.mcpReq._meta}):void 0,signal:e.mcpReq.signal,set(e,t){n.set(e,t)},get:e=>n.get(e),async progress(t,r){let a=e.mcpReq._meta?.progressToken;void 0!==a&&await e.mcpReq.notify({method:"notifications/progress",params:{progressToken:a,progress:t,...void 0===r?{}:{total:r}}})},log:(t,r)=>e.mcpReq.log(t,r)});return mu.provider({request:e.mcpReq,value:o},r)}function mm(e){let t=e?.["xmcp/tags"];return Array.isArray(t)?t:void 0}function mh(e,t,r=!1){let a;try{a=new URL(t).toString()}catch{return}for(let i of r?[t,a]:[a]){let t=e.uiOwners.get(i)??e.resources.get(i);if(t)return t}for(let{component:t,template:r}of e.templates.values())if(r.uriTemplate.match(a))return t}let mf=me({name:"client-info-context"});mf.setContext;let mg=mf.getContext;mf.provider;let my=new Set(["message","mode","requestedSchema"]),mv=new Set(["elicitationId","message","mode","url"]),m_=new Set(["properties","required","type"]),mb=new Set(["default","description","format","maxLength","minLength","title","type"]),mS=new Set(["default","description","enum","enumNames","title","type"]),m$=new Set(["default","description","title","type"]),mw=new Set(["default","description","maximum","minimum","title","type"]),mR=new Set(["date","date-time","email","uri"]);function mk(e,t,r){let a=Object.keys(e).filter(e=>!t.has(e));if(0!==a.length)throw Error(`${r} includes unsupported key(s): ${a.join(", ")}.`)}function mx(e,t){if("object"!=typeof e||null===e||Array.isArray(e))throw Error(t)}function mP(e,t){if("string"!=typeof e)throw Error(t)}function mE(e,t){if("string"!=typeof e||0===e.trim().length)throw Error(t)}function mT(e,t){if(void 0!==e&&"string"!=typeof e)throw Error(t)}function mj(e,t){if(void 0!==e&&"number"!=typeof e)throw Error(t)}function mO(e,t){if(!Array.isArray(e)||e.some(e=>"string"!=typeof e))throw Error(t)}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"]);function mq(e,t){if("object"!=typeof e||null===e||Array.isArray(e))throw Error(t)}let mA={text:e=>"string"!=typeof e.text?{valid:!1,error:'Text content must have a "text" property of type string'}:{valid:!0},image:e=>"string"!=typeof e.data?{valid:!1,error:'Image content must have a "data" property of type string (base64-encoded image)'}:"string"!=typeof e.mimeType?{valid:!1,error:'Image content must have a "mimeType" property of type string'}:{valid:!0},audio:e=>"string"!=typeof e.data?{valid:!1,error:'Audio content must have a "data" property of type string (base64-encoded audio)'}:"string"!=typeof e.mimeType?{valid:!1,error:'Audio content must have a "mimeType" property of type string'}:{valid:!0},resource_link:e=>"string"!=typeof e.name?{valid:!1,error:'Resource link content must have a "name" property of type string'}:"string"!=typeof e.uri?{valid:!1,error:'Resource link content must have a "uri" property of type string'}:void 0!==e.title&&"string"!=typeof e.title?{valid:!1,error:'Resource link "title" property must be a string if provided'}:void 0!==e.description&&"string"!=typeof e.description?{valid:!1,error:'Resource link "description" property must be a string if provided'}:void 0!==e.mimeType&&"string"!=typeof e.mimeType?{valid:!1,error:'Resource link "mimeType" property must be a string if provided'}:{valid:!0}};function mz(e){if(!e||"object"!=typeof e)return{valid:!1,error:"Content must be an object"};if("string"!=typeof e.type)return{valid:!1,error:'Content must have a "type" property of type string'};if(void 0!==e._meta&&(null===e._meta||"object"!=typeof e._meta))return{valid:!1,error:'Content "_meta" property must be an object if provided'};let t=mA[e.type];return t?t(e):{valid:!0}}let mM=Symbol("Let zodToJsonSchema decide on which parser to use"),mL={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=e=>{},T.assertIs=function(e){},T.assertNever=function(e){throw Error()},T.arrayToEnum=e=>{let t={};for(let r of e)t[r]=r;return t},T.getValidEnumValues=e=>{let t=T.objectKeys(e).filter(t=>"number"!=typeof e[e[t]]),r={};for(let a of t)r[a]=e[a];return T.objectValues(r)},T.objectValues=e=>T.objectKeys(e).map(function(t){return e[t]}),T.objectKeys="function"==typeof Object.keys?e=>Object.keys(e):e=>{let t=[];for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.push(r);return t},T.find=(e,t)=>{for(let r of e)if(t(r))return r},T.isInteger="function"==typeof Number.isInteger?e=>Number.isInteger(e):e=>"number"==typeof e&&Number.isFinite(e)&&Math.floor(e)===e,T.joinValues=function(e,t=" | "){return e.map(e=>"string"==typeof e?`'${e}'`:e).join(t)},T.jsonStringifyReplacer=(e,t)=>"bigint"==typeof t?t.toString():t,(A||(A={})).mergeShapes=(e,t)=>({...e,...t});let mZ=q.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),mD=e=>{switch(typeof e){case"undefined":return mZ.undefined;case"string":return mZ.string;case"number":return Number.isNaN(e)?mZ.nan:mZ.number;case"boolean":return mZ.boolean;case"function":return mZ.function;case"bigint":return mZ.bigint;case"symbol":return mZ.symbol;case"object":if(Array.isArray(e))return mZ.array;if(null===e)return mZ.null;if(e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch)return mZ.promise;if("u">typeof Map&&e instanceof Map)return mZ.map;if("u">typeof Set&&e instanceof Set)return mZ.set;if("u">typeof Date&&e instanceof Date)return mZ.date;return mZ.object;default:return mZ.unknown}},mU=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 mV extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=e=>{this.issues=[...this.issues,e]},this.addIssues=(e=[])=>{this.issues=[...this.issues,...e]};let t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){let t=e||function(e){return e.message},r={_errors:[]},a=e=>{for(let i of e.issues)if("invalid_union"===i.code)i.unionErrors.map(a);else if("invalid_return_type"===i.code)a(i.returnTypeError);else if("invalid_arguments"===i.code)a(i.argumentsError);else if(0===i.path.length)r._errors.push(t(i));else{let e=r,a=0;for(;a<i.path.length;){let r=i.path[a],n=a===i.path.length-1;if("_errors"===r){n&&e._errors.push(t(i)),a++;continue}Object.prototype.hasOwnProperty.call(e,r)||("__proto__"===r?Object.defineProperty(e,r,{value:{_errors:[]},writable:!0,enumerable:!0,configurable:!0}):e[r]={_errors:[]}),e=e[r],n&&e._errors.push(t(i)),a++}}};return a(this),r}static assert(e){if(!(e instanceof mV))throw Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,q.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(e=e=>e.message){let t=Object.create(null),r=[];for(let a of this.issues)if(a.path.length>0){let r=a.path[0];t[r]=t[r]||[],t[r].push(e(a))}else r.push(e(a));return{formErrors:r,fieldErrors:t}}get formErrors(){return this.flatten()}}mV.create=e=>new mV(e);let mF=(e,t)=>{let r;switch(e.code){case mU.invalid_type:r=e.received===mZ.undefined?"Required":`Expected ${e.expected}, received ${e.received}`;break;case mU.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(e.expected,q.jsonStringifyReplacer)}`;break;case mU.unrecognized_keys:r=`Unrecognized key(s) in object: ${q.joinValues(e.keys,", ")}`;break;case mU.invalid_union:r="Invalid input";break;case mU.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${q.joinValues(e.options)}`;break;case mU.invalid_enum_value:r=`Invalid enum value. Expected ${q.joinValues(e.options)}, received '${e.received}'`;break;case mU.invalid_arguments:r="Invalid function arguments";break;case mU.invalid_return_type:r="Invalid function return type";break;case mU.invalid_date:r="Invalid date";break;case mU.invalid_string:"object"==typeof e.validation?"includes"in e.validation?(r=`Invalid input: must include "${e.validation.includes}"`,"number"==typeof e.validation.position&&(r=`${r} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?r=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?r=`Invalid input: must end with "${e.validation.endsWith}"`:q.assertNever(e.validation):r="regex"!==e.validation?`Invalid ${e.validation}`:"Invalid";break;case mU.too_small:r="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:"number"===e.type||"bigint"===e.type?`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:"date"===e.type?`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:"Invalid input";break;case mU.too_big:r="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"bigint"===e.type?`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"date"===e.type?`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:"Invalid input";break;case mU.custom:r="Invalid input";break;case mU.invalid_intersection_types:r="Intersection results could not be merged";break;case mU.not_multiple_of:r=`Number must be a multiple of ${e.multipleOf}`;break;case mU.not_finite:r="Number must be finite";break;default:r=t.defaultError,q.assertNever(e)}return{message:r}};(j=z||(z={})).errToObj=e=>"string"==typeof e?{message:e}:e||{},j.toString=e=>"string"==typeof e?e:e?.message;function mH(e,t){let r=(e=>{let{data:t,path:r,errorMaps:a,issueData:i}=e,n=[...r,...i.path||[]],o={...i,path:n};if(void 0!==i.message)return{...i,path:n,message:i.message};let s="";for(let e of a.filter(e=>!!e).slice().reverse())s=e(o,{data:t,defaultError:s}).message;return{...i,path:n,message:s}})({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,mF,void 0].filter(e=>!!e)});e.common.issues.push(r)}class mJ{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(e,t){let r=[];for(let a of t){if("aborted"===a.status)return mB;"dirty"===a.status&&e.dirty(),r.push(a.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,t){let r=[];for(let e of t){let t=await e.key,a=await e.value;r.push({key:t,value:a})}return mJ.mergeObjectSync(e,r)}static mergeObjectSync(e,t){let r={};for(let a of t){let{key:t,value:i}=a;if("aborted"===t.status||"aborted"===i.status)return mB;"dirty"===t.status&&e.dirty(),"dirty"===i.status&&e.dirty(),"__proto__"!==t.value&&(void 0!==i.value||a.alwaysSet)&&(r[t.value]=i.value)}return{status:e.value,value:r}}}let mB=Object.freeze({status:"aborted"}),mK=e=>({status:"dirty",value:e}),mG=e=>({status:"valid",value:e}),mW=e=>"u">typeof Promise&&e instanceof Promise;class mY{constructor(e,t,r,a){this._cachedPath=[],this.parent=e,this.data=t,this._path=r,this._key=a}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 mX=(e,t)=>{if("valid"===t.status)return{success:!0,data:t.value};if(!e.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let t=new mV(e.common.issues);return this._error=t,this._error}}};function mQ(e){if(!e)return{};let{errorMap:t,invalid_type_error:r,required_error:a,description:i}=e;if(t&&(r||a))throw Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');return t?{errorMap:t,description:i}:{errorMap:(t,i)=>{let{message:n}=e;return"invalid_enum_value"===t.code?{message:n??i.defaultError}:void 0===i.data?{message:n??a??i.defaultError}:"invalid_type"!==t.code?{message:i.defaultError}:{message:n??r??i.defaultError}},description:i}}class m0{get description(){return this._def.description}_getType(e){return mD(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:mD(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new mJ,ctx:{common:e.parent.common,data:e.data,parsedType:mD(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let t=this._parse(e);if(mW(t))throw Error("Synchronous parse encountered promise.");return t}_parseAsync(e){return Promise.resolve(this._parse(e))}parse(e,t){let r=this.safeParse(e,t);if(r.success)return r.data;throw r.error}safeParse(e,t){let r={common:{issues:[],async:t?.async??!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:mD(e)},a=this._parseSync({data:e,path:r.path,parent:r});return mX(r,a)}"~validate"(e){let t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:mD(e)};if(!this["~standard"].async)try{let r=this._parseSync({data:e,path:[],parent:t});return"valid"===r.status?{value:r.value}:{issues:t.common.issues}}catch(e){e?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(e=>"valid"===e.status?{value:e.value}:{issues:t.common.issues})}async parseAsync(e,t){let r=await this.safeParseAsync(e,t);if(r.success)return r.data;throw r.error}async safeParseAsync(e,t){let r={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:mD(e)},a=this._parse({data:e,path:r.path,parent:r});return mX(r,await (mW(a)?a:Promise.resolve(a)))}refine(e,t){return this._refinement((r,a)=>{let i=e(r),n=()=>a.addIssue({code:mU.custom,..."string"==typeof t||void 0===t?{message:t}:"function"==typeof t?t(r):t});return"u">typeof Promise&&i instanceof Promise?i.then(e=>!!e||(n(),!1)):!!i||(n(),!1)})}refinement(e,t){return this._refinement((r,a)=>!!e(r)||(a.addIssue("function"==typeof t?t(r,a):t),!1))}_refinement(e){return new hI({schema:this,typeName:M.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return hN.create(this,this._def)}nullable(){return hq.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return hb.create(this)}promise(){return hC.create(this,this._def)}or(e){return h$.create([this,e],this._def)}and(e){return hw.create(this,e,this._def)}transform(e){return new hI({...mQ(this._def),schema:this,typeName:M.ZodEffects,effect:{type:"transform",transform:e}})}default(e){return new hA({...mQ(this._def),innerType:this,defaultValue:"function"==typeof e?e:()=>e,typeName:M.ZodDefault})}brand(){return new hL({typeName:M.ZodBranded,type:this,...mQ(this._def)})}catch(e){return new hz({...mQ(this._def),innerType:this,catchValue:"function"==typeof e?e:()=>e,typeName:M.ZodCatch})}describe(e){return new this.constructor({...this._def,description:e})}pipe(e){return hZ.create(this,e)}readonly(){return hD.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}let m1=/^c[^\s-]{8,}$/i,m2=/^[0-9a-z]+$/,m9=/^[0-9A-HJKMNP-TV-Z]{26}$/i,m4=/^[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,m3=/^[a-z0-9_-]{21}$/i,m5=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,m6=/^[-+]?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)?)??$/,m7=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,m8=/^(?:(?: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])$/,he=/^(?:(?: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])$/,ht=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,hr=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ha=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,hi=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,hn="((\\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])))",ho=RegExp(`^${hn}$`);function hs(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:null==e.precision&&(t=`${t}(\\.\\d+)?`);let r=e.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${r}`}class hl extends m0{_parse(e){var t,r,a,i;let n;if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==mZ.string){let t=this._getOrReturnCtx(e);return mH(t,{code:mU.invalid_type,expected:mZ.string,received:t.parsedType}),mB}let o=new mJ;for(let s of this._def.checks)if("min"===s.kind)e.data.length<s.value&&(mH(n=this._getOrReturnCtx(e,n),{code:mU.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),o.dirty());else if("max"===s.kind)e.data.length>s.value&&(mH(n=this._getOrReturnCtx(e,n),{code:mU.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),o.dirty());else if("length"===s.kind){let t=e.data.length>s.value,r=e.data.length<s.value;(t||r)&&(n=this._getOrReturnCtx(e,n),t?mH(n,{code:mU.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):r&&mH(n,{code:mU.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),o.dirty())}else if("email"===s.kind)m7.test(e.data)||(mH(n=this._getOrReturnCtx(e,n),{validation:"email",code:mU.invalid_string,message:s.message}),o.dirty());else if("emoji"===s.kind)f||(f=RegExp("^[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$","u")),f.test(e.data)||(mH(n=this._getOrReturnCtx(e,n),{validation:"emoji",code:mU.invalid_string,message:s.message}),o.dirty());else if("uuid"===s.kind)m4.test(e.data)||(mH(n=this._getOrReturnCtx(e,n),{validation:"uuid",code:mU.invalid_string,message:s.message}),o.dirty());else if("nanoid"===s.kind)m3.test(e.data)||(mH(n=this._getOrReturnCtx(e,n),{validation:"nanoid",code:mU.invalid_string,message:s.message}),o.dirty());else if("cuid"===s.kind)m1.test(e.data)||(mH(n=this._getOrReturnCtx(e,n),{validation:"cuid",code:mU.invalid_string,message:s.message}),o.dirty());else if("cuid2"===s.kind)m2.test(e.data)||(mH(n=this._getOrReturnCtx(e,n),{validation:"cuid2",code:mU.invalid_string,message:s.message}),o.dirty());else if("ulid"===s.kind)m9.test(e.data)||(mH(n=this._getOrReturnCtx(e,n),{validation:"ulid",code:mU.invalid_string,message:s.message}),o.dirty());else if("url"===s.kind)try{new URL(e.data)}catch{mH(n=this._getOrReturnCtx(e,n),{validation:"url",code:mU.invalid_string,message:s.message}),o.dirty()}else"regex"===s.kind?(s.regex.lastIndex=0,s.regex.test(e.data)||(mH(n=this._getOrReturnCtx(e,n),{validation:"regex",code:mU.invalid_string,message:s.message}),o.dirty())):"trim"===s.kind?e.data=e.data.trim():"includes"===s.kind?e.data.includes(s.value,s.position)||(mH(n=this._getOrReturnCtx(e,n),{code:mU.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),o.dirty()):"toLowerCase"===s.kind?e.data=e.data.toLowerCase():"toUpperCase"===s.kind?e.data=e.data.toUpperCase():"startsWith"===s.kind?e.data.startsWith(s.value)||(mH(n=this._getOrReturnCtx(e,n),{code:mU.invalid_string,validation:{startsWith:s.value},message:s.message}),o.dirty()):"endsWith"===s.kind?e.data.endsWith(s.value)||(mH(n=this._getOrReturnCtx(e,n),{code:mU.invalid_string,validation:{endsWith:s.value},message:s.message}),o.dirty()):"datetime"===s.kind?(function(e){let t=`${hn}T${hs(e)}`,r=[];return r.push(e.local?"Z?":"Z"),e.offset&&r.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${r.join("|")})`,RegExp(`^${t}$`)})(s).test(e.data)||(mH(n=this._getOrReturnCtx(e,n),{code:mU.invalid_string,validation:"datetime",message:s.message}),o.dirty()):"date"===s.kind?ho.test(e.data)||(mH(n=this._getOrReturnCtx(e,n),{code:mU.invalid_string,validation:"date",message:s.message}),o.dirty()):"time"===s.kind?RegExp(`^${hs(s)}$`).test(e.data)||(mH(n=this._getOrReturnCtx(e,n),{code:mU.invalid_string,validation:"time",message:s.message}),o.dirty()):"duration"===s.kind?m6.test(e.data)||(mH(n=this._getOrReturnCtx(e,n),{validation:"duration",code:mU.invalid_string,message:s.message}),o.dirty()):"ip"===s.kind?(t=e.data,!(("v4"===(r=s.version)||!r)&&m8.test(t)||("v6"===r||!r)&&ht.test(t))&&1&&(mH(n=this._getOrReturnCtx(e,n),{validation:"ip",code:mU.invalid_string,message:s.message}),o.dirty())):"jwt"===s.kind?!function(e,t){if(!m5.test(e))return!1;try{let[r]=e.split(".");if(!r)return!1;let a=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(r.length+(4-r.length%4)%4,"="),i=JSON.parse(atob(a));if("object"!=typeof i||null===i||"typ"in i&&i?.typ!=="JWT"||!i.alg||t&&i.alg!==t)return!1;return!0}catch{return!1}}(e.data,s.alg)&&(mH(n=this._getOrReturnCtx(e,n),{validation:"jwt",code:mU.invalid_string,message:s.message}),o.dirty()):"cidr"===s.kind?(a=e.data,!(("v4"===(i=s.version)||!i)&&he.test(a)||("v6"===i||!i)&&hr.test(a))&&1&&(mH(n=this._getOrReturnCtx(e,n),{validation:"cidr",code:mU.invalid_string,message:s.message}),o.dirty())):"base64"===s.kind?ha.test(e.data)||(mH(n=this._getOrReturnCtx(e,n),{validation:"base64",code:mU.invalid_string,message:s.message}),o.dirty()):"base64url"===s.kind?hi.test(e.data)||(mH(n=this._getOrReturnCtx(e,n),{validation:"base64url",code:mU.invalid_string,message:s.message}),o.dirty()):q.assertNever(s);return{status:o.value,value:e.data}}_regex(e,t,r){return this.refinement(t=>e.test(t),{validation:t,code:mU.invalid_string,...z.errToObj(r)})}_addCheck(e){return new hl({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...z.errToObj(e)})}url(e){return this._addCheck({kind:"url",...z.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...z.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...z.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...z.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...z.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...z.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...z.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...z.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...z.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...z.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...z.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...z.errToObj(e)})}datetime(e){return"string"==typeof e?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:void 0===e?.precision?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...z.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return"string"==typeof e?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:void 0===e?.precision?null:e?.precision,...z.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...z.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...z.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...z.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...z.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...z.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...z.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...z.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...z.errToObj(t)})}nonempty(e){return this.min(1,z.errToObj(e))}trim(){return new hl({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new hl({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new hl({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>"datetime"===e.kind)}get isDate(){return!!this._def.checks.find(e=>"date"===e.kind)}get isTime(){return!!this._def.checks.find(e=>"time"===e.kind)}get isDuration(){return!!this._def.checks.find(e=>"duration"===e.kind)}get isEmail(){return!!this._def.checks.find(e=>"email"===e.kind)}get isURL(){return!!this._def.checks.find(e=>"url"===e.kind)}get isEmoji(){return!!this._def.checks.find(e=>"emoji"===e.kind)}get isUUID(){return!!this._def.checks.find(e=>"uuid"===e.kind)}get isNANOID(){return!!this._def.checks.find(e=>"nanoid"===e.kind)}get isCUID(){return!!this._def.checks.find(e=>"cuid"===e.kind)}get isCUID2(){return!!this._def.checks.find(e=>"cuid2"===e.kind)}get isULID(){return!!this._def.checks.find(e=>"ulid"===e.kind)}get isIP(){return!!this._def.checks.find(e=>"ip"===e.kind)}get isCIDR(){return!!this._def.checks.find(e=>"cidr"===e.kind)}get isBase64(){return!!this._def.checks.find(e=>"base64"===e.kind)}get isBase64url(){return!!this._def.checks.find(e=>"base64url"===e.kind)}get minLength(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}hl.create=e=>new hl({checks:[],typeName:M.ZodString,coerce:e?.coerce??!1,...mQ(e)});class hc extends m0{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){let t;if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==mZ.number){let t=this._getOrReturnCtx(e);return mH(t,{code:mU.invalid_type,expected:mZ.number,received:t.parsedType}),mB}let r=new mJ;for(let a of this._def.checks)"int"===a.kind?q.isInteger(e.data)||(mH(t=this._getOrReturnCtx(e,t),{code:mU.invalid_type,expected:"integer",received:"float",message:a.message}),r.dirty()):"min"===a.kind?(a.inclusive?e.data<a.value:e.data<=a.value)&&(mH(t=this._getOrReturnCtx(e,t),{code:mU.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):"max"===a.kind?(a.inclusive?e.data>a.value:e.data>=a.value)&&(mH(t=this._getOrReturnCtx(e,t),{code:mU.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):"multipleOf"===a.kind?0!==function(e,t){let r=(e.toString().split(".")[1]||"").length,a=(t.toString().split(".")[1]||"").length,i=r>a?r:a;return Number.parseInt(e.toFixed(i).replace(".",""))%Number.parseInt(t.toFixed(i).replace(".",""))/10**i}(e.data,a.value)&&(mH(t=this._getOrReturnCtx(e,t),{code:mU.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):"finite"===a.kind?Number.isFinite(e.data)||(mH(t=this._getOrReturnCtx(e,t),{code:mU.not_finite,message:a.message}),r.dirty()):q.assertNever(a);return{status:r.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,z.toString(t))}gt(e,t){return this.setLimit("min",e,!1,z.toString(t))}lte(e,t){return this.setLimit("max",e,!0,z.toString(t))}lt(e,t){return this.setLimit("max",e,!1,z.toString(t))}setLimit(e,t,r,a){return new hc({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:z.toString(a)}]})}_addCheck(e){return new hc({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:z.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:z.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:z.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:z.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:z.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:z.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:z.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:z.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:z.toString(e)})}get minValue(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>"int"===e.kind||"multipleOf"===e.kind&&q.isInteger(e.value))}get isFinite(){let e=null,t=null;for(let r of this._def.checks)if("finite"===r.kind||"int"===r.kind||"multipleOf"===r.kind)return!0;else"min"===r.kind?(null===t||r.value>t)&&(t=r.value):"max"===r.kind&&(null===e||r.value<e)&&(e=r.value);return Number.isFinite(t)&&Number.isFinite(e)}}hc.create=e=>new hc({checks:[],typeName:M.ZodNumber,coerce:e?.coerce||!1,...mQ(e)});class hu extends m0{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){let t;if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==mZ.bigint)return this._getInvalidInput(e);let r=new mJ;for(let a of this._def.checks)"min"===a.kind?(a.inclusive?e.data<a.value:e.data<=a.value)&&(mH(t=this._getOrReturnCtx(e,t),{code:mU.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):"max"===a.kind?(a.inclusive?e.data>a.value:e.data>=a.value)&&(mH(t=this._getOrReturnCtx(e,t),{code:mU.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):"multipleOf"===a.kind?e.data%a.value!==BigInt(0)&&(mH(t=this._getOrReturnCtx(e,t),{code:mU.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):q.assertNever(a);return{status:r.value,value:e.data}}_getInvalidInput(e){let t=this._getOrReturnCtx(e);return mH(t,{code:mU.invalid_type,expected:mZ.bigint,received:t.parsedType}),mB}gte(e,t){return this.setLimit("min",e,!0,z.toString(t))}gt(e,t){return this.setLimit("min",e,!1,z.toString(t))}lte(e,t){return this.setLimit("max",e,!0,z.toString(t))}lt(e,t){return this.setLimit("max",e,!1,z.toString(t))}setLimit(e,t,r,a){return new hu({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:z.toString(a)}]})}_addCheck(e){return new hu({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:z.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:z.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:z.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:z.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:z.toString(t)})}get minValue(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}hu.create=e=>new hu({checks:[],typeName:M.ZodBigInt,coerce:e?.coerce??!1,...mQ(e)});class hd extends m0{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==mZ.boolean){let t=this._getOrReturnCtx(e);return mH(t,{code:mU.invalid_type,expected:mZ.boolean,received:t.parsedType}),mB}return mG(e.data)}}hd.create=e=>new hd({typeName:M.ZodBoolean,coerce:e?.coerce||!1,...mQ(e)});class hp extends m0{_parse(e){let t;if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==mZ.date){let t=this._getOrReturnCtx(e);return mH(t,{code:mU.invalid_type,expected:mZ.date,received:t.parsedType}),mB}if(Number.isNaN(e.data.getTime()))return mH(this._getOrReturnCtx(e),{code:mU.invalid_date}),mB;let r=new mJ;for(let a of this._def.checks)"min"===a.kind?e.data.getTime()<a.value&&(mH(t=this._getOrReturnCtx(e,t),{code:mU.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),r.dirty()):"max"===a.kind?e.data.getTime()>a.value&&(mH(t=this._getOrReturnCtx(e,t),{code:mU.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),r.dirty()):q.assertNever(a);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new hp({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:z.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:z.toString(t)})}get minDate(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return null!=e?new Date(e):null}get maxDate(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return null!=e?new Date(e):null}}hp.create=e=>new hp({checks:[],coerce:e?.coerce||!1,typeName:M.ZodDate,...mQ(e)});class hm extends m0{_parse(e){if(this._getType(e)!==mZ.symbol){let t=this._getOrReturnCtx(e);return mH(t,{code:mU.invalid_type,expected:mZ.symbol,received:t.parsedType}),mB}return mG(e.data)}}hm.create=e=>new hm({typeName:M.ZodSymbol,...mQ(e)});class hh extends m0{_parse(e){if(this._getType(e)!==mZ.undefined){let t=this._getOrReturnCtx(e);return mH(t,{code:mU.invalid_type,expected:mZ.undefined,received:t.parsedType}),mB}return mG(e.data)}}hh.create=e=>new hh({typeName:M.ZodUndefined,...mQ(e)});class hf extends m0{_parse(e){if(this._getType(e)!==mZ.null){let t=this._getOrReturnCtx(e);return mH(t,{code:mU.invalid_type,expected:mZ.null,received:t.parsedType}),mB}return mG(e.data)}}hf.create=e=>new hf({typeName:M.ZodNull,...mQ(e)});class hg extends m0{constructor(){super(...arguments),this._any=!0}_parse(e){return mG(e.data)}}hg.create=e=>new hg({typeName:M.ZodAny,...mQ(e)});class hy extends m0{constructor(){super(...arguments),this._unknown=!0}_parse(e){return mG(e.data)}}hy.create=e=>new hy({typeName:M.ZodUnknown,...mQ(e)});class hv extends m0{_parse(e){let t=this._getOrReturnCtx(e);return mH(t,{code:mU.invalid_type,expected:mZ.never,received:t.parsedType}),mB}}hv.create=e=>new hv({typeName:M.ZodNever,...mQ(e)});class h_ extends m0{_parse(e){if(this._getType(e)!==mZ.undefined){let t=this._getOrReturnCtx(e);return mH(t,{code:mU.invalid_type,expected:mZ.void,received:t.parsedType}),mB}return mG(e.data)}}h_.create=e=>new h_({typeName:M.ZodVoid,...mQ(e)});class hb extends m0{_parse(e){let{ctx:t,status:r}=this._processInputParams(e),a=this._def;if(t.parsedType!==mZ.array)return mH(t,{code:mU.invalid_type,expected:mZ.array,received:t.parsedType}),mB;if(null!==a.exactLength){let e=t.data.length>a.exactLength.value,i=t.data.length<a.exactLength.value;(e||i)&&(mH(t,{code:e?mU.too_big:mU.too_small,minimum:i?a.exactLength.value:void 0,maximum:e?a.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:a.exactLength.message}),r.dirty())}if(null!==a.minLength&&t.data.length<a.minLength.value&&(mH(t,{code:mU.too_small,minimum:a.minLength.value,type:"array",inclusive:!0,exact:!1,message:a.minLength.message}),r.dirty()),null!==a.maxLength&&t.data.length>a.maxLength.value&&(mH(t,{code:mU.too_big,maximum:a.maxLength.value,type:"array",inclusive:!0,exact:!1,message:a.maxLength.message}),r.dirty()),t.common.async)return Promise.all([...t.data].map((e,r)=>a.type._parseAsync(new mY(t,e,t.path,r)))).then(e=>mJ.mergeArray(r,e));let i=[...t.data].map((e,r)=>a.type._parseSync(new mY(t,e,t.path,r)));return mJ.mergeArray(r,i)}get element(){return this._def.type}min(e,t){return new hb({...this._def,minLength:{value:e,message:z.toString(t)}})}max(e,t){return new hb({...this._def,maxLength:{value:e,message:z.toString(t)}})}length(e,t){return new hb({...this._def,exactLength:{value:e,message:z.toString(t)}})}nonempty(e){return this.min(1,e)}}hb.create=(e,t)=>new hb({type:e,minLength:null,maxLength:null,exactLength:null,typeName:M.ZodArray,...mQ(t)});class hS extends m0{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;let e=this._def.shape(),t=q.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==mZ.object){let t=this._getOrReturnCtx(e);return mH(t,{code:mU.invalid_type,expected:mZ.object,received:t.parsedType}),mB}let{status:t,ctx:r}=this._processInputParams(e),{shape:a,keys:i}=this._getCached(),n=[];if(!(this._def.catchall instanceof hv&&"strip"===this._def.unknownKeys))for(let e in r.data)i.includes(e)||n.push(e);let o=[];for(let e of i){let t=a[e],i=r.data[e];o.push({key:{status:"valid",value:e},value:t._parse(new mY(r,i,r.path,e)),alwaysSet:e in r.data})}if(this._def.catchall instanceof hv){let e=this._def.unknownKeys;if("passthrough"===e)for(let e of n)o.push({key:{status:"valid",value:e},value:{status:"valid",value:r.data[e]}});else if("strict"===e)n.length>0&&(mH(r,{code:mU.unrecognized_keys,keys:n}),t.dirty());else if("strip"===e);else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let e=this._def.catchall;for(let t of n){let a=r.data[t];o.push({key:{status:"valid",value:t},value:e._parse(new mY(r,a,r.path,t)),alwaysSet:t in r.data})}}return r.common.async?Promise.resolve().then(async()=>{let e=[];for(let t of o){let r=await t.key,a=await t.value;e.push({key:r,value:a,alwaysSet:t.alwaysSet})}return e}).then(e=>mJ.mergeObjectSync(t,e)):mJ.mergeObjectSync(t,o)}get shape(){return this._def.shape()}strict(e){return z.errToObj,new hS({...this._def,unknownKeys:"strict",...void 0!==e?{errorMap:(t,r)=>{let a=this._def.errorMap?.(t,r).message??r.defaultError;return"unrecognized_keys"===t.code?{message:z.errToObj(e).message??a}:{message:a}}}:{}})}strip(){return new hS({...this._def,unknownKeys:"strip"})}passthrough(){return new hS({...this._def,unknownKeys:"passthrough"})}extend(e){return new hS({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new hS({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:M.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new hS({...this._def,catchall:e})}pick(e){let t={};for(let r of q.objectKeys(e))e[r]&&this.shape[r]&&(t[r]=this.shape[r]);return new hS({...this._def,shape:()=>t})}omit(e){let t={};for(let r of q.objectKeys(this.shape))e[r]||(t[r]=this.shape[r]);return new hS({...this._def,shape:()=>t})}deepPartial(){return function e(t){if(t instanceof hS){let r={};for(let a in t.shape){let i=t.shape[a];r[a]=hN.create(e(i))}return new hS({...t._def,shape:()=>r})}if(t instanceof hb)return new hb({...t._def,type:e(t.element)});if(t instanceof hN)return hN.create(e(t.unwrap()));if(t instanceof hq)return hq.create(e(t.unwrap()));if(t instanceof hR)return hR.create(t.items.map(t=>e(t)));else return t}(this)}partial(e){let t={};for(let r of q.objectKeys(this.shape)){let a=this.shape[r];e&&!e[r]?t[r]=a:t[r]=a.optional()}return new hS({...this._def,shape:()=>t})}required(e){let t={};for(let r of q.objectKeys(this.shape))if(e&&!e[r])t[r]=this.shape[r];else{let e=this.shape[r];for(;e instanceof hN;)e=e._def.innerType;t[r]=e}return new hS({...this._def,shape:()=>t})}keyof(){return hT(q.objectKeys(this.shape))}}hS.create=(e,t)=>new hS({shape:()=>e,unknownKeys:"strip",catchall:hv.create(),typeName:M.ZodObject,...mQ(t)}),hS.strictCreate=(e,t)=>new hS({shape:()=>e,unknownKeys:"strict",catchall:hv.create(),typeName:M.ZodObject,...mQ(t)}),hS.lazycreate=(e,t)=>new hS({shape:e,unknownKeys:"strip",catchall:hv.create(),typeName:M.ZodObject,...mQ(t)});class h$ extends m0{_parse(e){let{ctx:t}=this._processInputParams(e),r=this._def.options;if(t.common.async)return Promise.all(r.map(async e=>{let r={...t,common:{...t.common,issues:[]},parent:null};return{result:await e._parseAsync({data:t.data,path:t.path,parent:r}),ctx:r}})).then(function(e){for(let t of e)if("valid"===t.result.status)return t.result;for(let r of e)if("dirty"===r.result.status)return t.common.issues.push(...r.ctx.common.issues),r.result;let r=e.map(e=>new mV(e.ctx.common.issues));return mH(t,{code:mU.invalid_union,unionErrors:r}),mB});{let e,a=[];for(let i of r){let r={...t,common:{...t.common,issues:[]},parent:null},n=i._parseSync({data:t.data,path:t.path,parent:r});if("valid"===n.status)return n;"dirty"!==n.status||e||(e={result:n,ctx:r}),r.common.issues.length&&a.push(r.common.issues)}if(e)return t.common.issues.push(...e.ctx.common.issues),e.result;let i=a.map(e=>new mV(e));return mH(t,{code:mU.invalid_union,unionErrors:i}),mB}}get options(){return this._def.options}}h$.create=(e,t)=>new h$({options:e,typeName:M.ZodUnion,...mQ(t)});class hw extends m0{_parse(e){let{status:t,ctx:r}=this._processInputParams(e),a=(e,a)=>{if("aborted"===e.status||"aborted"===a.status)return mB;let i=function e(t,r){let a=mD(t),i=mD(r);if(t===r)return{valid:!0,data:t};if(a===mZ.object&&i===mZ.object){let a=q.objectKeys(r),i=q.objectKeys(t).filter(e=>-1!==a.indexOf(e)),n={...t,...r};for(let a of(Object.prototype.hasOwnProperty.call(n,"__proto__")&&delete n.__proto__,i)){if("__proto__"===a)continue;let i=e(t[a],r[a]);if(!i.valid)return{valid:!1};n[a]=i.data}return{valid:!0,data:n}}if(a===mZ.array&&i===mZ.array){if(t.length!==r.length)return{valid:!1};let a=[];for(let i=0;i<t.length;i++){let n=e(t[i],r[i]);if(!n.valid)return{valid:!1};a.push(n.data)}return{valid:!0,data:a}}if(a===mZ.date&&i===mZ.date&&+t==+r)return{valid:!0,data:t};return{valid:!1}}(e.value,a.value);return i.valid?(("dirty"===e.status||"dirty"===a.status)&&t.dirty(),{status:t.value,value:i.data}):(mH(r,{code:mU.invalid_intersection_types}),mB)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([e,t])=>a(e,t)):a(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}hw.create=(e,t,r)=>new hw({left:e,right:t,typeName:M.ZodIntersection,...mQ(r)});class hR extends m0{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==mZ.array)return mH(r,{code:mU.invalid_type,expected:mZ.array,received:r.parsedType}),mB;if(r.data.length<this._def.items.length)return mH(r,{code:mU.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),mB;!this._def.rest&&r.data.length>this._def.items.length&&(mH(r,{code:mU.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());let a=[...r.data].map((e,t)=>{let a=this._def.items[t]||this._def.rest;return a?a._parse(new mY(r,e,r.path,t)):null}).filter(e=>!!e);return r.common.async?Promise.all(a).then(e=>mJ.mergeArray(t,e)):mJ.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new hR({...this._def,rest:e})}}hR.create=(e,t)=>{if(!Array.isArray(e))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new hR({items:e,typeName:M.ZodTuple,rest:null,...mQ(t)})};class hk extends m0{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==mZ.map)return mH(r,{code:mU.invalid_type,expected:mZ.map,received:r.parsedType}),mB;let a=this._def.keyType,i=this._def.valueType,n=[...r.data.entries()].map(([e,t],n)=>({key:a._parse(new mY(r,e,r.path,[n,"key"])),value:i._parse(new mY(r,t,r.path,[n,"value"]))}));if(r.common.async){let e=new Map;return Promise.resolve().then(async()=>{for(let r of n){let a=await r.key,i=await r.value;if("aborted"===a.status||"aborted"===i.status)return mB;("dirty"===a.status||"dirty"===i.status)&&t.dirty(),e.set(a.value,i.value)}return{status:t.value,value:e}})}{let e=new Map;for(let r of n){let a=r.key,i=r.value;if("aborted"===a.status||"aborted"===i.status)return mB;("dirty"===a.status||"dirty"===i.status)&&t.dirty(),e.set(a.value,i.value)}return{status:t.value,value:e}}}}hk.create=(e,t,r)=>new hk({valueType:t,keyType:e,typeName:M.ZodMap,...mQ(r)});class hx extends m0{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==mZ.set)return mH(r,{code:mU.invalid_type,expected:mZ.set,received:r.parsedType}),mB;let a=this._def;null!==a.minSize&&r.data.size<a.minSize.value&&(mH(r,{code:mU.too_small,minimum:a.minSize.value,type:"set",inclusive:!0,exact:!1,message:a.minSize.message}),t.dirty()),null!==a.maxSize&&r.data.size>a.maxSize.value&&(mH(r,{code:mU.too_big,maximum:a.maxSize.value,type:"set",inclusive:!0,exact:!1,message:a.maxSize.message}),t.dirty());let i=this._def.valueType;function n(e){let r=new Set;for(let a of e){if("aborted"===a.status)return mB;"dirty"===a.status&&t.dirty(),r.add(a.value)}return{status:t.value,value:r}}let o=[...r.data.values()].map((e,t)=>i._parse(new mY(r,e,r.path,t)));return r.common.async?Promise.all(o).then(e=>n(e)):n(o)}min(e,t){return new hx({...this._def,minSize:{value:e,message:z.toString(t)}})}max(e,t){return new hx({...this._def,maxSize:{value:e,message:z.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}hx.create=(e,t)=>new hx({valueType:e,minSize:null,maxSize:null,typeName:M.ZodSet,...mQ(t)});class hP extends m0{get schema(){return this._def.getter()}_parse(e){let{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}hP.create=(e,t)=>new hP({getter:e,typeName:M.ZodLazy,...mQ(t)});class hE extends m0{_parse(e){if(e.data!==this._def.value){let t=this._getOrReturnCtx(e);return mH(t,{received:t.data,code:mU.invalid_literal,expected:this._def.value}),mB}return{status:"valid",value:e.data}}get value(){return this._def.value}}function hT(e,t){return new hj({values:e,typeName:M.ZodEnum,...mQ(t)})}hE.create=(e,t)=>new hE({value:e,typeName:M.ZodLiteral,...mQ(t)});class hj extends m0{_parse(e){if("string"!=typeof e.data){let t=this._getOrReturnCtx(e),r=this._def.values;return mH(t,{expected:q.joinValues(r),received:t.parsedType,code:mU.invalid_type}),mB}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let t=this._getOrReturnCtx(e),r=this._def.values;return mH(t,{received:t.data,code:mU.invalid_enum_value,options:r}),mB}return mG(e.data)}get options(){return this._def.values}get enum(){let e={};for(let t of this._def.values)e[t]=t;return e}get Values(){let e={};for(let t of this._def.values)e[t]=t;return e}get Enum(){let e={};for(let t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return hj.create(e,{...this._def,...t})}exclude(e,t=this._def){return hj.create(this.options.filter(t=>!e.includes(t)),{...this._def,...t})}}hj.create=hT;class hO extends m0{_parse(e){let t=q.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==mZ.string&&r.parsedType!==mZ.number){let e=q.objectValues(t);return mH(r,{expected:q.joinValues(e),received:r.parsedType,code:mU.invalid_type}),mB}if(this._cache||(this._cache=new Set(q.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let e=q.objectValues(t);return mH(r,{received:r.data,code:mU.invalid_enum_value,options:e}),mB}return mG(e.data)}get enum(){return this._def.values}}hO.create=(e,t)=>new hO({values:e,typeName:M.ZodNativeEnum,...mQ(t)});class hC extends m0{unwrap(){return this._def.type}_parse(e){let{ctx:t}=this._processInputParams(e);return t.parsedType!==mZ.promise&&!1===t.common.async?(mH(t,{code:mU.invalid_type,expected:mZ.promise,received:t.parsedType}),mB):mG((t.parsedType===mZ.promise?t.data:Promise.resolve(t.data)).then(e=>this._def.type.parseAsync(e,{path:t.path,errorMap:t.common.contextualErrorMap})))}}hC.create=(e,t)=>new hC({type:e,typeName:M.ZodPromise,...mQ(t)});class hI extends m0{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===M.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:t,ctx:r}=this._processInputParams(e),a=this._def.effect||null,i={addIssue:e=>{mH(r,e),e.fatal?t.abort():t.dirty()},get path(){return r.path}};if(i.addIssue=i.addIssue.bind(i),"preprocess"===a.type){let e=a.transform(r.data,i);if(r.common.async)return Promise.resolve(e).then(async e=>{if("aborted"===t.value)return mB;let a=await this._def.schema._parseAsync({data:e,path:r.path,parent:r});return"aborted"===a.status?mB:"dirty"===a.status||"dirty"===t.value?mK(a.value):a});{if("aborted"===t.value)return mB;let a=this._def.schema._parseSync({data:e,path:r.path,parent:r});return"aborted"===a.status?mB:"dirty"===a.status||"dirty"===t.value?mK(a.value):a}}if("refinement"===a.type){let e=e=>{let t=a.refinement(e,i);if(r.common.async)return Promise.resolve(t);if(t instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return e};if(!1!==r.common.async)return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(r=>"aborted"===r.status?mB:("dirty"===r.status&&t.dirty(),e(r.value).then(()=>({status:t.value,value:r.value}))));{let a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return"aborted"===a.status?mB:("dirty"===a.status&&t.dirty(),e(a.value),{status:t.value,value:a.value})}}if("transform"===a.type)if(!1!==r.common.async)return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(e=>"valid"!==e.status?mB:Promise.resolve(a.transform(e.value,i)).then(e=>({status:t.value,value:e})));else{let e=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if("valid"!==e.status)return mB;let n=a.transform(e.value,i);if(n instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:n}}q.assertNever(a)}}hI.create=(e,t,r)=>new hI({schema:e,typeName:M.ZodEffects,effect:t,...mQ(r)}),hI.createWithPreprocess=(e,t,r)=>new hI({schema:t,effect:{type:"preprocess",transform:e},typeName:M.ZodEffects,...mQ(r)});class hN extends m0{_parse(e){return this._getType(e)===mZ.undefined?mG(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}hN.create=(e,t)=>new hN({innerType:e,typeName:M.ZodOptional,...mQ(t)});class hq extends m0{_parse(e){return this._getType(e)===mZ.null?mG(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}hq.create=(e,t)=>new hq({innerType:e,typeName:M.ZodNullable,...mQ(t)});class hA extends m0{_parse(e){let{ctx:t}=this._processInputParams(e),r=t.data;return t.parsedType===mZ.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}hA.create=(e,t)=>new hA({innerType:e,typeName:M.ZodDefault,defaultValue:"function"==typeof t.default?t.default:()=>t.default,...mQ(t)});class hz extends m0{_parse(e){let{ctx:t}=this._processInputParams(e),r={...t,common:{...t.common,issues:[]}},a=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return mW(a)?a.then(e=>({status:"valid",value:"valid"===e.status?e.value:this._def.catchValue({get error(){return new mV(r.common.issues)},input:r.data})})):{status:"valid",value:"valid"===a.status?a.value:this._def.catchValue({get error(){return new mV(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}hz.create=(e,t)=>new hz({innerType:e,typeName:M.ZodCatch,catchValue:"function"==typeof t.catch?t.catch:()=>t.catch,...mQ(t)});class hM extends m0{_parse(e){if(this._getType(e)!==mZ.nan){let t=this._getOrReturnCtx(e);return mH(t,{code:mU.invalid_type,expected:mZ.nan,received:t.parsedType}),mB}return{status:"valid",value:e.data}}}hM.create=e=>new hM({typeName:M.ZodNaN,...mQ(e)}),Symbol("zod_brand");class hL extends m0{_parse(e){let{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}class hZ extends m0{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{let e=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return"aborted"===e.status?mB:"dirty"===e.status?(t.dirty(),mK(e.value)):this._def.out._parseAsync({data:e.value,path:r.path,parent:r})})();{let e=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return"aborted"===e.status?mB:"dirty"===e.status?(t.dirty(),{status:"dirty",value:e.value}):this._def.out._parseSync({data:e.value,path:r.path,parent:r})}}static create(e,t){return new hZ({in:e,out:t,typeName:M.ZodPipeline})}}class hD extends m0{_parse(e){let t=this._def.innerType._parse(e),r=e=>("valid"===e.status&&(e.value=Object.freeze(e.value)),e);return mW(t)?t.then(e=>r(e)):r(t)}unwrap(){return this._def.innerType}}hD.create=(e,t)=>new hD({innerType:e,typeName:M.ZodReadonly,...mQ(t)}),hS.lazycreate,(O=M||(M={})).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 hU=hl.create;hc.create,hM.create,hu.create,hd.create,hp.create,hm.create,hh.create,hf.create,hg.create,hy.create,hv.create,h_.create,hb.create;let hV=hS.create;hS.strictCreate,h$.create,hw.create,hR.create,hk.create,hx.create,hP.create,hE.create,hj.create,hO.create,hC.create,hI.create,hN.create,hq.create,hI.createWithPreprocess,hZ.create;let hF=(e,t)=>{let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];r++);return[(e.length-r).toString(),...t.slice(r)].join("/")};function hH(e){if("openAi"!==e.target)return{};let t=[...e.basePath,e.definitionPath,e.openAiAnyTypeName];return e.flags.hasReferencedOpenAiAnyType=!0,{$ref:"relative"===e.$refStrategy?hF(t,e.currentPath):t.join("/")}}function hJ(e,t,r,a){a?.errorMessages&&r&&(e.errorMessage={...e.errorMessage,[t]:r})}function hB(e,t,r,a,i){e[t]=r,hJ(e,t,a,i)}function hK(e,t){return fn(e.type._def,t)}let hG=/^[cC][^\s-]{8,}$/,hW=/^[0-9a-z]+$/,hY=/^[0-9A-HJKMNP-TV-Z]{26}$/,hX=/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,hQ=()=>(void 0===R&&(R=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),R),h0=/^(?:(?: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])$/,h1=/^(([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])$/,h2=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,h9=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,h4=/^[a-zA-Z0-9_-]{21}$/,h3=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;function h5(e,t){let r={type:"string"};if(e.checks)for(let a of e.checks)switch(a.kind){case"min":hB(r,"minLength","number"==typeof r.minLength?Math.max(r.minLength,a.value):a.value,a.message,t);break;case"max":hB(r,"maxLength","number"==typeof r.maxLength?Math.min(r.maxLength,a.value):a.value,a.message,t);break;case"email":switch(t.emailStrategy){case"format:email":h8(r,"email",a.message,t);break;case"format:idn-email":h8(r,"idn-email",a.message,t);break;case"pattern:zod":fe(r,hX,a.message,t)}break;case"url":h8(r,"uri",a.message,t);break;case"uuid":h8(r,"uuid",a.message,t);break;case"regex":fe(r,a.regex,a.message,t);break;case"cuid":fe(r,hG,a.message,t);break;case"cuid2":fe(r,hW,a.message,t);break;case"startsWith":fe(r,RegExp(`^${h6(a.value,t)}`),a.message,t);break;case"endsWith":fe(r,RegExp(`${h6(a.value,t)}$`),a.message,t);break;case"datetime":h8(r,"date-time",a.message,t);break;case"date":h8(r,"date",a.message,t);break;case"time":h8(r,"time",a.message,t);break;case"duration":h8(r,"duration",a.message,t);break;case"length":hB(r,"minLength","number"==typeof r.minLength?Math.max(r.minLength,a.value):a.value,a.message,t),hB(r,"maxLength","number"==typeof r.maxLength?Math.min(r.maxLength,a.value):a.value,a.message,t);break;case"includes":fe(r,RegExp(h6(a.value,t)),a.message,t);break;case"ip":"v6"!==a.version&&h8(r,"ipv4",a.message,t),"v4"!==a.version&&h8(r,"ipv6",a.message,t);break;case"base64url":fe(r,h9,a.message,t);break;case"jwt":fe(r,h3,a.message,t);break;case"cidr":"v6"!==a.version&&fe(r,h0,a.message,t),"v4"!==a.version&&fe(r,h1,a.message,t);break;case"emoji":fe(r,hQ(),a.message,t);break;case"ulid":fe(r,hY,a.message,t);break;case"base64":switch(t.base64Strategy){case"format:binary":h8(r,"binary",a.message,t);break;case"contentEncoding:base64":hB(r,"contentEncoding","base64",a.message,t);break;case"pattern:zod":fe(r,h2,a.message,t)}break;case"nanoid":fe(r,h4,a.message,t)}return r}function h6(e,t){return"escape"===t.patternStrategy?function(e){let t="";for(let r=0;r<e.length;r++)h7.has(e[r])||(t+="\\"),t+=e[r];return t}(e):e}let h7=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function h8(e,t,r,a){e.format||e.anyOf?.some(e=>e.format)?(e.anyOf||(e.anyOf=[]),e.format&&(e.anyOf.push({format:e.format,...e.errorMessage&&a.errorMessages&&{errorMessage:{format:e.errorMessage.format}}}),delete e.format,e.errorMessage&&(delete e.errorMessage.format,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.anyOf.push({format:t,...r&&a.errorMessages&&{errorMessage:{format:r}}})):hB(e,"format",t,r,a)}function fe(e,t,r,a){e.pattern||e.allOf?.some(e=>e.pattern)?(e.allOf||(e.allOf=[]),e.pattern&&(e.allOf.push({pattern:e.pattern,...e.errorMessage&&a.errorMessages&&{errorMessage:{pattern:e.errorMessage.pattern}}}),delete e.pattern,e.errorMessage&&(delete e.errorMessage.pattern,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.allOf.push({pattern:ft(t,a),...r&&a.errorMessages&&{errorMessage:{pattern:r}}})):hB(e,"pattern",ft(t,a),r,a)}function ft(e,t){if(!t.applyRegexFlags||!e.flags)return e.source;let r={i:e.flags.includes("i"),m:e.flags.includes("m"),s:e.flags.includes("s")},a=r.i?e.source.toLowerCase():e.source,i="",n=!1,o=!1,s=!1;for(let e=0;e<a.length;e++){if(n){i+=a[e],n=!1;continue}if(r.i){if(o){if(a[e].match(/[a-z]/)){s?(i+=a[e],i+=`${a[e-2]}-${a[e]}`.toUpperCase(),s=!1):"-"===a[e+1]&&a[e+2]?.match(/[a-z]/)?(i+=a[e],s=!0):i+=`${a[e]}${a[e].toUpperCase()}`;continue}}else if(a[e].match(/[a-z]/)){i+=`[${a[e]}${a[e].toUpperCase()}]`;continue}}if(r.m){if("^"===a[e]){i+=`(^|(?<=[\r
78
78
  ]))`;continue}else if("$"===a[e]){i+=`($|(?=[\r
79
79
  ]))`;continue}}if(r.s&&"."===a[e]){i+=o?`${a[e]}\r
80
80
  `:`[${a[e]}\r
81
- ]`;continue}i+=a[e],"\\"===a[e]?n=!0:o&&"]"===a[e]?o=!1:o||"["!==a[e]||(o=!0)}try{new RegExp(i)}catch{return console.warn(`Could not convert regex pattern at ${t.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),e.source}return i}function fi(e,t){if("openAi"===t.target&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),"openApi3"===t.target&&e.keyType?._def.typeName===M.ZodEnum)return{type:"object",required:e.keyType._def.values,properties:e.keyType._def.values.reduce((r,a)=>({...r,[a]:fs(e.valueType._def,{...t,currentPath:[...t.currentPath,"properties",a]})??hB(t)}),{}),additionalProperties:t.rejectedAdditionalProperties};let r={type:"object",additionalProperties:fs(e.valueType._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??t.allowedAdditionalProperties};if("openApi3"===t.target)return r;if(e.keyType?._def.typeName===M.ZodString&&e.keyType._def.checks?.length){let{type:a,...i}=h7(e.keyType._def,t);return{...r,propertyNames:i}}if(e.keyType?._def.typeName===M.ZodEnum)return{...r,propertyNames:{enum:e.keyType._def.values}};if(e.keyType?._def.typeName===M.ZodBranded&&e.keyType._def.type._def.typeName===M.ZodString&&e.keyType._def.type._def.checks?.length){let{type:a,...i}=hW(e.keyType._def,t);return{...r,propertyNames:i}}return r}let fn={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"},fo=(e,t)=>{let r=(e.options instanceof Map?Array.from(e.options.values()):e.options).map((e,r)=>fs(e._def,{...t,currentPath:[...t.currentPath,"anyOf",`${r}`]})).filter(e=>!!e&&(!t.strictUnions||"object"==typeof e&&Object.keys(e).length>0));return r.length?{anyOf:r}:void 0};function fs(e,t,r=!1){let a=t.seen.get(e);if(t.override){let i=t.override?.(e,t,a,r);if(i!==mZ)return i}if(a&&!r){let e=fl(a,t);if(void 0!==e)return e}let i={def:e,path:t.currentPath,jsonSchema:void 0};t.seen.set(e,i);let n=((e,t,r)=>{switch(t){case M.ZodString:return h7(e,r);case M.ZodNumber:let a={type:"number"};if(!e.checks)return a;for(let t of e.checks)switch(t.kind){case"int":a.type="integer",hK(a,"type",t.message,r);break;case"min":"jsonSchema7"===r.target?t.inclusive?hG(a,"minimum",t.value,t.message,r):hG(a,"exclusiveMinimum",t.value,t.message,r):(t.inclusive||(a.exclusiveMinimum=!0),hG(a,"minimum",t.value,t.message,r));break;case"max":"jsonSchema7"===r.target?t.inclusive?hG(a,"maximum",t.value,t.message,r):hG(a,"exclusiveMaximum",t.value,t.message,r):(t.inclusive||(a.exclusiveMaximum=!0),hG(a,"maximum",t.value,t.message,r));break;case"multipleOf":hG(a,"multipleOf",t.value,t.message,r)}return a;case M.ZodObject:return function(e,t){let r="openAi"===t.target,a={type:"object",properties:{}},i=[],n=e.shape();for(let e in n){let o=n[e];if(void 0===o||void 0===o._def)continue;let s=function(e){try{return e.isOptional()}catch{return!0}}(o);s&&r&&("ZodOptional"===o._def.typeName&&(o=o._def.innerType),o.isNullable()||(o=o.nullable()),s=!1);let l=fs(o._def,{...t,currentPath:[...t.currentPath,"properties",e],propertyPath:[...t.currentPath,"properties",e]});void 0!==l&&(a.properties[e]=l,s||i.push(e))}i.length&&(a.required=i);let o=function(e,t){if("ZodNever"!==e.catchall._def.typeName)return fs(e.catchall._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]});switch(e.unknownKeys){case"passthrough":return t.allowedAdditionalProperties;case"strict":return t.rejectedAdditionalProperties;case"strip":return"strict"===t.removeAdditionalStrategy?t.allowedAdditionalProperties:t.rejectedAdditionalProperties}}(e,t);return void 0!==o&&(a.additionalProperties=o),a}(e,r);case M.ZodBigInt:let i={type:"integer",format:"int64"};if(!e.checks)return i;for(let t of e.checks)switch(t.kind){case"min":"jsonSchema7"===r.target?t.inclusive?hG(i,"minimum",t.value,t.message,r):hG(i,"exclusiveMinimum",t.value,t.message,r):(t.inclusive||(i.exclusiveMinimum=!0),hG(i,"minimum",t.value,t.message,r));break;case"max":"jsonSchema7"===r.target?t.inclusive?hG(i,"maximum",t.value,t.message,r):hG(i,"exclusiveMaximum",t.value,t.message,r):(t.inclusive||(i.exclusiveMaximum=!0),hG(i,"maximum",t.value,t.message,r));break;case"multipleOf":hG(i,"multipleOf",t.value,t.message,r)}return i;case M.ZodBoolean:return{type:"boolean"};case M.ZodDate:return function e(t,r,a){let i=a??r.dateStrategy;if(Array.isArray(i))return{anyOf:i.map((a,i)=>e(t,r,a))};switch(i){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":var n=t,o=r;let s={type:"integer",format:"unix-time"};if("openApi3"===o.target)return s;for(let e of n.checks)switch(e.kind){case"min":hG(s,"minimum",e.value,e.message,o);break;case"max":hG(s,"maximum",e.value,e.message,o)}return s}}(e,r);case M.ZodUndefined:return{not:hB(r)};case M.ZodNull:return"openApi3"===r.target?{enum:["null"],nullable:!0}:{type:"null"};case M.ZodArray:let n;return n={type:"array"},e.type?._def&&e.type?._def?.typeName!==M.ZodAny&&(n.items=fs(e.type._def,{...r,currentPath:[...r.currentPath,"items"]})),e.minLength&&hG(n,"minItems",e.minLength.value,e.minLength.message,r),e.maxLength&&hG(n,"maxItems",e.maxLength.value,e.maxLength.message,r),e.exactLength&&(hG(n,"minItems",e.exactLength.value,e.exactLength.message,r),hG(n,"maxItems",e.exactLength.value,e.exactLength.message,r)),n;case M.ZodUnion:case M.ZodDiscriminatedUnion:if("openApi3"===r.target)return fo(e,r);let o=e.options instanceof Map?Array.from(e.options.values()):e.options;if(o.every(e=>e._def.typeName in fn&&(!e._def.checks||!e._def.checks.length))){let e=o.reduce((e,t)=>{let r=fn[t._def.typeName];return r&&!e.includes(r)?[...e,r]:e},[]);return{type:e.length>1?e:e[0]}}if(o.every(e=>"ZodLiteral"===e._def.typeName&&!e.description)){let e=o.reduce((e,t)=>{let r=typeof t._def.value;switch(r){case"string":case"number":case"boolean":return[...e,r];case"bigint":return[...e,"integer"];case"object":if(null===t._def.value)return[...e,"null"];default:return e}},[]);if(e.length===o.length){let t=e.filter((e,t,r)=>r.indexOf(e)===t);return{type:t.length>1?t:t[0],enum:o.reduce((e,t)=>e.includes(t._def.value)?e:[...e,t._def.value],[])}}}else if(o.every(e=>"ZodEnum"===e._def.typeName))return{type:"string",enum:o.reduce((e,t)=>[...e,...t._def.values.filter(t=>!e.includes(t))],[])};return fo(e,r);case M.ZodIntersection:let s,l,c;return s=[fs(e.left._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),fs(e.right._def,{...r,currentPath:[...r.currentPath,"allOf","1"]})].filter(e=>!!e),l="jsonSchema2019-09"===r.target?{unevaluatedProperties:!1}:void 0,c=[],s.forEach(e=>{if((!("type"in e)||"string"!==e.type)&&"allOf"in e)c.push(...e.allOf),void 0===e.unevaluatedProperties&&(l=void 0);else{let t=e;if("additionalProperties"in e&&!1===e.additionalProperties){let{additionalProperties:r,...a}=e;t=a}else l=void 0;c.push(t)}}),c.length?{allOf:c,...l}:void 0;case M.ZodTuple:return e.rest?{type:"array",minItems:e.items.length,items:e.items.map((e,t)=>fs(e._def,{...r,currentPath:[...r.currentPath,"items",`${t}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[]),additionalItems:fs(e.rest._def,{...r,currentPath:[...r.currentPath,"additionalItems"]})}:{type:"array",minItems:e.items.length,maxItems:e.items.length,items:e.items.map((e,t)=>fs(e._def,{...r,currentPath:[...r.currentPath,"items",`${t}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[])};case M.ZodRecord:return fi(e,r);case M.ZodLiteral:let u;return"bigint"!=(u=typeof e.value)&&"number"!==u&&"boolean"!==u&&"string"!==u?{type:Array.isArray(e.value)?"array":"object"}:"openApi3"===r.target?{type:"bigint"===u?"integer":u,enum:[e.value]}:{type:"bigint"===u?"integer":u,const:e.value};case M.ZodEnum:return{type:"string",enum:Array.from(e.values)};case M.ZodNativeEnum:let d,p,m;return d=e.values,{type:1===(m=Array.from(new Set((p=Object.keys(e.values).filter(e=>"number"!=typeof d[d[e]]).map(e=>d[e])).map(e=>typeof e)))).length?"string"===m[0]?"string":"number":["string","number"],enum:p};case M.ZodNullable:if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(e.innerType._def.typeName)&&(!e.innerType._def.checks||!e.innerType._def.checks.length))return"openApi3"===r.target?{type:fn[e.innerType._def.typeName],nullable:!0}:{type:[fn[e.innerType._def.typeName],"null"]};if("openApi3"===r.target){let t=fs(e.innerType._def,{...r,currentPath:[...r.currentPath]});return t&&"$ref"in t?{allOf:[t],nullable:!0}:t&&{...t,nullable:!0}}let h=fs(e.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","0"]});return h&&{anyOf:[h,{type:"null"}]};case M.ZodOptional:if(r.currentPath.toString()===r.propertyPath?.toString())return fs(e.innerType._def,r);let f=fs(e.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","1"]});return f?{anyOf:[{not:hB(r)},f]}:hB(r);case M.ZodMap:if("record"===r.mapStrategy)return fi(e,r);return{type:"array",maxItems:125,items:{type:"array",items:[fs(e.keyType._def,{...r,currentPath:[...r.currentPath,"items","items","0"]})||hB(r),fs(e.valueType._def,{...r,currentPath:[...r.currentPath,"items","items","1"]})||hB(r)],minItems:2,maxItems:2}};case M.ZodSet:let g;return g={type:"array",uniqueItems:!0,items:fs(e.valueType._def,{...r,currentPath:[...r.currentPath,"items"]})},e.minSize&&hG(g,"minItems",e.minSize.value,e.minSize.message,r),e.maxSize&&hG(g,"maxItems",e.maxSize.value,e.maxSize.message,r),g;case M.ZodLazy:return()=>e.getter()._def;case M.ZodPromise:return fs(e.type._def,r);case M.ZodNaN:case M.ZodNever:return"openAi"===r.target?void 0:{not:hB({...r,currentPath:[...r.currentPath,"not"]})};case M.ZodEffects:return"input"===r.effectStrategy?fs(e.schema._def,r):hB(r);case M.ZodAny:case M.ZodUnknown:return hB(r);case M.ZodDefault:return{...fs(e.innerType._def,r),default:e.defaultValue()};case M.ZodBranded:return hW(e,r);case M.ZodReadonly:case M.ZodCatch:return fs(e.innerType._def,r);case M.ZodPipeline:if("input"===r.pipeStrategy)return fs(e.in._def,r);if("output"===r.pipeStrategy)return fs(e.out._def,r);let y=fs(e.in._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),v=fs(e.out._def,{...r,currentPath:[...r.currentPath,"allOf",y?"1":"0"]});return{allOf:[y,v].filter(e=>void 0!==e)};case M.ZodFunction:case M.ZodVoid:case M.ZodSymbol:default:return}})(e,e.typeName,t),o="function"==typeof n?fs(n(),t):n;if(o&&fc(e,t,o),t.postProcess){let r=t.postProcess(o,e,t);return i.jsonSchema=o,r}return i.jsonSchema=o,o}let fl=(e,t)=>{switch(t.$refStrategy){case"root":return{$ref:e.path.join("/")};case"relative":return{$ref:hJ(t.currentPath,e.path)};case"none":case"seen":if(e.path.length<t.currentPath.length&&e.path.every((e,r)=>t.currentPath[r]===e))return console.warn(`Recursive reference detected at ${t.currentPath.join("/")}! Defaulting to any`),hB(t);return"seen"===t.$refStrategy?hB(t):void 0}},fc=(e,t,r)=>(e.description&&(r.description=e.description,t.markdownDescription&&(r.markdownDescription=e.description)),r);function fu(e,t={}){let{strict:r=!1}=t,a=Object.entries(e),i=e=>({target:t})=>{let i={},n=[];for(let[r,o]of a)i[r]=function(e,t,r){let a=e["~standard"];if(a.jsonSchema)return a.jsonSchema[r]({target:t});if("zod"===e["~standard"].vendor&&!("_zod"in e)&&"_def"in e){let r=((e,t)=>{let r,a,i=(a=void 0!==(r="string"==typeof t?{...mD,name:t}:{...mD,...t}).name?[...r.basePath,r.definitionPath,r.name]:r.basePath,{...r,flags:{hasReferencedOpenAiAnyType:!1},currentPath:a,propertyPath:void 0,seen:new Map(Object.entries(r.definitions).map(([e,t])=>[t._def,{def:t._def,path:[...r.basePath,r.definitionPath,e],jsonSchema:void 0}]))}),n="object"==typeof t&&t.definitions?Object.entries(t.definitions).reduce((e,[t,r])=>({...e,[t]:fs(r._def,{...i,currentPath:[...i.basePath,i.definitionPath,t]},!0)??hB(i)}),{}):void 0,o="string"==typeof t?t:t?.nameStrategy==="title"?void 0:t?.name,s=fs(e._def,void 0===o?i:{...i,currentPath:[...i.basePath,i.definitionPath,o]},!1)??hB(i),l="object"==typeof t&&void 0!==t.name&&"title"===t.nameStrategy?t.name:void 0;void 0!==l&&(s.title=l),i.flags.hasReferencedOpenAiAnyType&&(n||(n={}),n[i.openAiAnyTypeName]||(n[i.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:"relative"===i.$refStrategy?"1":[...i.basePath,i.definitionPath,i.openAiAnyTypeName].join("/")}}));let c=void 0===o?n?{...s,[i.definitionPath]:n}:s:{$ref:[..."relative"===i.$refStrategy?[]:i.basePath,i.definitionPath,o].join("/"),[i.definitionPath]:{...n,[o]:s}};return"jsonSchema7"===i.target?c.$schema="http://json-schema.org/draft-07/schema#":("jsonSchema2019-09"===i.target||"openAi"===i.target)&&(c.$schema="https://json-schema.org/draft/2019-09/schema#"),"openAi"===i.target&&("anyOf"in c||"oneOf"in c||"allOf"in c||"type"in c&&Array.isArray(c.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),c})(e,{$refStrategy:"none",target:"openapi-3.0"===t?"openApi3":"jsonSchema7"});return delete r.$schema,r}if("zod"===a.vendor&&"_zod"in e)try{let t=a8(e);return delete t.$schema,t}catch(e){throw Error(`Failed to convert a zod schema to JSON Schema (zod v4 without "~standard.jsonSchema"). Upgrade to zod >= 4.2.0. Original error: ${e instanceof Error?e.message:String(e)}`)}throw Error(`Schema library "${a.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".`)}(o,t,e),!function(e,t){if("function"!=typeof e.safeParse)return!1;try{let r=e.safeParse(void 0);return r.success&&("input"===t||void 0===r.data)}catch{return!1}}(o,e)&&n.push(r);let o={type:"object",properties:i};return n.length>0&&(o.required=n),r&&(o.additionalProperties=!1),o};return{shape:e,"~standard":{version:1,vendor:"xmcp",validate:async t=>{if("object"!=typeof t||null===t||Array.isArray(t))return{issues:[{message:"Expected an object."}]};let i={},n=[];for(let[e,r]of a){let a=await r["~standard"].validate(t[e]);if(a.issues)for(let t of a.issues)n.push({message:t.message,path:[e,...t.path??[]]});else(e in t||void 0!==a.value)&&(i[e]=a.value)}if(r)for(let r of Object.keys(t))r in e||n.push({message:`Unrecognized key: "${r}"`,path:[r]});return n.length>0?{issues:n}:{value:i}},jsonSchema:{input:i("input"),output:i("output")}}}}function fd(e){let t={};return!function e(r,a=""){if(r&&"object"==typeof r)for(let[i,n]of Object.entries(r)){let r=a?`${a}/${i}`:i;!n||"object"!=typeof n||Array.isArray(n)||n instanceof Date||n instanceof RegExp?t[r]=n:e(n,r)}}(e),t}let fp=["ui/resourceUri","resourceUri","visibility"],fm=["prefersBorder","domain","csp","permissions","connectDomains","resourceDomains","frameDomains","baseUriDomains"];function fh(e){return"object"==typeof e&&null!==e&&Object.entries(e).every(([e,t])=>"string"==typeof e&&"object"==typeof t&&null!==t&&"parse"in t&&"function"==typeof t.parse)}function ff(e){return(e.split("/").pop()||e).replace(/\.[^/.]+$/,"")}function fg(e,t,r){return e.names?.includes(t)===!0||e.tags?.some(e=>r.includes(e))===!0}function fy(e,t){return t?new Map([...e].filter(([e,{metadata:r}])=>{if(r?.enabled===!1)return!1;let a=r?.name??ff(e),i=r?.tags??[];return(!t.include||fg(t.include,a,i))&&(!t.exclude||!fg(t.exclude,a,i))})):e}function fv(e){return Error(`[xmcp] Invalid prompt file: ${e}
82
- -> Default export must be a prompt handler function.`)}let f_=function(e=console){let t="";return r=>{let a=r.map(({path:e,message:t})=>`${e}:${t}`).sort().join("|");if(a===t||(t=a,0===r.length))return;r.forEach(({path:t,message:r})=>{e.warn(`[xmcp] Failed to load prompt file: ${t}
83
- -> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} prompt${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function fb(e){return Error(`[xmcp] Invalid resource file: ${e}
84
- -> Default export must be a resource handler function.`)}let fS=function(e=console){let t="";return r=>{let a=r.map(({path:e,message:t})=>`${e}:${t}`).sort().join("|");if(a===t||(t=a,0===r.length))return;r.forEach(({path:t,message:r})=>{e.warn(`[xmcp] Failed to load resource file: ${t}
85
- -> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} resource${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function f$(e){let t=e.replace(/\\/g,"/");if(!t)throw Error("Invalid tool path: path is empty");let r=t.replace(/\.[^/.]+$/,"").replace(/\//g,"_");return{normalizedPath:t,baseName:r}}function fw(e){let t=e.split("/").filter(e=>""!==e),r=t.findIndex(e=>e.match(/^\(.+\)$/));if(-1===r)return null;let a=t[t.length-1];if(a&&a.match(/^\[.+\]\.ts$/))return null;let i=t[r].slice(1,-1),n=t.slice(r+1),o=n[n.length-1];if(o&&o.includes(".")){let e=o.split(".")[0];"index"!==e?n[n.length-1]=e:n.pop()}let s=[],l=[],c=n.map(e=>{if(!e.match(/^\[.+\]$/))return l.push(e),e;{let t=e.slice(1,-1);return s.push(t),`{${t}}`}}),u=`${i}://${c.join("/")}`,d=s.length>0?"template":"direct";return{filePath:e,uriTemplate:u,scheme:i,parameters:s,pathSegments:l,type:d}}let fR={ttlMs:0,cacheScope:"private"},fk=hH({cursor:hF().optional()}).passthrough().optional(),fx=hH({uri:hF()}).passthrough();function fP({uri:e,frontmatter:t,files:r}){return{uri:e,frontmatter:t,resources:r.map(({uri:e,digest:t,size:r})=>({uri:e,digest:t,size:r}))}}function fE(e){return Error(`[xmcp] Invalid tool file: ${e}
86
- -> Default export must be a tool handler function.`)}let fT=function(e=console){let t="";return r=>{let a=r.map(({path:e,message:t})=>`${e}:${t}`).sort().join("|");if(a===t||(t=a,0===r.length))return;r.forEach(({path:t,message:r})=>{e.warn(`[xmcp] Failed to load tool file: ${t}
87
- -> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} tool${1===i?"":"s"} skipped due to empty files or missing default exports`)}}(),fj=INJECTED_TOOLS,fO=INJECTED_PROMPTS,fC=INJECTED_RESOURCES,fI="u"<typeof INJECTED_SKILLS?[]:INJECTED_SKILLS??[],fN=SERVER_INFO,fq=function(e,t={}){var r;let{legacy:a,onerror:i,responseMode:n}=t,o=pY(t.maxRequestBodySize);if("function"==typeof a)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 s=new Set,l=!1,c=e=>{try{i?.(e)}catch{}},d=t.bus??new pB(c),f={toolsChanged:()=>d.publish({kind:"tools_list_changed"}),promptsChanged:()=>d.publish({kind:"prompts_list_changed"}),resourcesChanged:()=>d.publish({kind:"resources_list_changed"}),resourceUpdated:e=>d.publish({kind:"resource_updated",uri:e})},g=function(e){let{bus:t,onerror:r}=e,a=e.maxSubscriptions??1024,i=e.keepAliveMs??15e3,n=new Set;return{serve:function(e,o,s,l){let c,u,d,p,m,h,f;if(n.size>=a)return r?.(Error(`subscriptions/listen refused: subscription limit reached (${a})`)),pK(e.id,-32603,"Subscription limit reached");let g=(m=cq(cN).validateRequest("subscriptions/listen",e)).ok?m.value.params?.notifications:void 0;if(void 0===g)return pK(e.id,-32602,"Invalid params: 'notifications' is required and must be a valid SubscriptionFilter");let y=(h={},f=e=>void 0===s||!0===e,!0===g.toolsListChanged&&f(s?.tools?.listChanged)&&(h.toolsListChanged=!0),!0===g.promptsListChanged&&f(s?.prompts?.listChanged)&&(h.promptsListChanged=!0),!0===g.resourcesListChanged&&f(s?.resources?.listChanged)&&(h.resourcesListChanged=!0),void 0!==g.resourceSubscriptions&&g.resourceSubscriptions.length>0&&f(s?.resources?.subscribe)&&(h.resourceSubscriptions=[...g.resourceSubscriptions]),h),v=e.id,_=new TextEncoder,b=!1,S=e=>{if(!b)try{c.enqueue(_.encode(e))}catch(e){r?.(e instanceof Error?e:Error(String(e)))}},$=(e,t)=>{S(`event: message
81
+ ]`;continue}i+=a[e],"\\"===a[e]?n=!0:o&&"]"===a[e]?o=!1:o||"["!==a[e]||(o=!0)}try{new RegExp(i)}catch{return console.warn(`Could not convert regex pattern at ${t.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),e.source}return i}function fr(e,t){if("openAi"===t.target&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),"openApi3"===t.target&&e.keyType?._def.typeName===M.ZodEnum)return{type:"object",required:e.keyType._def.values,properties:e.keyType._def.values.reduce((r,a)=>({...r,[a]:fn(e.valueType._def,{...t,currentPath:[...t.currentPath,"properties",a]})??hH(t)}),{}),additionalProperties:t.rejectedAdditionalProperties};let r={type:"object",additionalProperties:fn(e.valueType._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??t.allowedAdditionalProperties};if("openApi3"===t.target)return r;if(e.keyType?._def.typeName===M.ZodString&&e.keyType._def.checks?.length){let{type:a,...i}=h5(e.keyType._def,t);return{...r,propertyNames:i}}if(e.keyType?._def.typeName===M.ZodEnum)return{...r,propertyNames:{enum:e.keyType._def.values}};if(e.keyType?._def.typeName===M.ZodBranded&&e.keyType._def.type._def.typeName===M.ZodString&&e.keyType._def.type._def.checks?.length){let{type:a,...i}=hK(e.keyType._def,t);return{...r,propertyNames:i}}return r}let fa={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"},fi=(e,t)=>{let r=(e.options instanceof Map?Array.from(e.options.values()):e.options).map((e,r)=>fn(e._def,{...t,currentPath:[...t.currentPath,"anyOf",`${r}`]})).filter(e=>!!e&&(!t.strictUnions||"object"==typeof e&&Object.keys(e).length>0));return r.length?{anyOf:r}:void 0};function fn(e,t,r=!1){let a=t.seen.get(e);if(t.override){let i=t.override?.(e,t,a,r);if(i!==mM)return i}if(a&&!r){let e=fo(a,t);if(void 0!==e)return e}let i={def:e,path:t.currentPath,jsonSchema:void 0};t.seen.set(e,i);let n=((e,t,r)=>{switch(t){case M.ZodString:return h5(e,r);case M.ZodNumber:let a={type:"number"};if(!e.checks)return a;for(let t of e.checks)switch(t.kind){case"int":a.type="integer",hJ(a,"type",t.message,r);break;case"min":"jsonSchema7"===r.target?t.inclusive?hB(a,"minimum",t.value,t.message,r):hB(a,"exclusiveMinimum",t.value,t.message,r):(t.inclusive||(a.exclusiveMinimum=!0),hB(a,"minimum",t.value,t.message,r));break;case"max":"jsonSchema7"===r.target?t.inclusive?hB(a,"maximum",t.value,t.message,r):hB(a,"exclusiveMaximum",t.value,t.message,r):(t.inclusive||(a.exclusiveMaximum=!0),hB(a,"maximum",t.value,t.message,r));break;case"multipleOf":hB(a,"multipleOf",t.value,t.message,r)}return a;case M.ZodObject:return function(e,t){let r="openAi"===t.target,a={type:"object",properties:{}},i=[],n=e.shape();for(let e in n){let o=n[e];if(void 0===o||void 0===o._def)continue;let s=function(e){try{return e.isOptional()}catch{return!0}}(o);s&&r&&("ZodOptional"===o._def.typeName&&(o=o._def.innerType),o.isNullable()||(o=o.nullable()),s=!1);let l=fn(o._def,{...t,currentPath:[...t.currentPath,"properties",e],propertyPath:[...t.currentPath,"properties",e]});void 0!==l&&(a.properties[e]=l,s||i.push(e))}i.length&&(a.required=i);let o=function(e,t){if("ZodNever"!==e.catchall._def.typeName)return fn(e.catchall._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]});switch(e.unknownKeys){case"passthrough":return t.allowedAdditionalProperties;case"strict":return t.rejectedAdditionalProperties;case"strip":return"strict"===t.removeAdditionalStrategy?t.allowedAdditionalProperties:t.rejectedAdditionalProperties}}(e,t);return void 0!==o&&(a.additionalProperties=o),a}(e,r);case M.ZodBigInt:let i={type:"integer",format:"int64"};if(!e.checks)return i;for(let t of e.checks)switch(t.kind){case"min":"jsonSchema7"===r.target?t.inclusive?hB(i,"minimum",t.value,t.message,r):hB(i,"exclusiveMinimum",t.value,t.message,r):(t.inclusive||(i.exclusiveMinimum=!0),hB(i,"minimum",t.value,t.message,r));break;case"max":"jsonSchema7"===r.target?t.inclusive?hB(i,"maximum",t.value,t.message,r):hB(i,"exclusiveMaximum",t.value,t.message,r):(t.inclusive||(i.exclusiveMaximum=!0),hB(i,"maximum",t.value,t.message,r));break;case"multipleOf":hB(i,"multipleOf",t.value,t.message,r)}return i;case M.ZodBoolean:return{type:"boolean"};case M.ZodDate:return function e(t,r,a){let i=a??r.dateStrategy;if(Array.isArray(i))return{anyOf:i.map((a,i)=>e(t,r,a))};switch(i){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":var n=t,o=r;let s={type:"integer",format:"unix-time"};if("openApi3"===o.target)return s;for(let e of n.checks)switch(e.kind){case"min":hB(s,"minimum",e.value,e.message,o);break;case"max":hB(s,"maximum",e.value,e.message,o)}return s}}(e,r);case M.ZodUndefined:return{not:hH(r)};case M.ZodNull:return"openApi3"===r.target?{enum:["null"],nullable:!0}:{type:"null"};case M.ZodArray:let n;return n={type:"array"},e.type?._def&&e.type?._def?.typeName!==M.ZodAny&&(n.items=fn(e.type._def,{...r,currentPath:[...r.currentPath,"items"]})),e.minLength&&hB(n,"minItems",e.minLength.value,e.minLength.message,r),e.maxLength&&hB(n,"maxItems",e.maxLength.value,e.maxLength.message,r),e.exactLength&&(hB(n,"minItems",e.exactLength.value,e.exactLength.message,r),hB(n,"maxItems",e.exactLength.value,e.exactLength.message,r)),n;case M.ZodUnion:case M.ZodDiscriminatedUnion:if("openApi3"===r.target)return fi(e,r);let o=e.options instanceof Map?Array.from(e.options.values()):e.options;if(o.every(e=>e._def.typeName in fa&&(!e._def.checks||!e._def.checks.length))){let e=o.reduce((e,t)=>{let r=fa[t._def.typeName];return r&&!e.includes(r)?[...e,r]:e},[]);return{type:e.length>1?e:e[0]}}if(o.every(e=>"ZodLiteral"===e._def.typeName&&!e.description)){let e=o.reduce((e,t)=>{let r=typeof t._def.value;switch(r){case"string":case"number":case"boolean":return[...e,r];case"bigint":return[...e,"integer"];case"object":if(null===t._def.value)return[...e,"null"];default:return e}},[]);if(e.length===o.length){let t=e.filter((e,t,r)=>r.indexOf(e)===t);return{type:t.length>1?t:t[0],enum:o.reduce((e,t)=>e.includes(t._def.value)?e:[...e,t._def.value],[])}}}else if(o.every(e=>"ZodEnum"===e._def.typeName))return{type:"string",enum:o.reduce((e,t)=>[...e,...t._def.values.filter(t=>!e.includes(t))],[])};return fi(e,r);case M.ZodIntersection:let s,l,c;return s=[fn(e.left._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),fn(e.right._def,{...r,currentPath:[...r.currentPath,"allOf","1"]})].filter(e=>!!e),l="jsonSchema2019-09"===r.target?{unevaluatedProperties:!1}:void 0,c=[],s.forEach(e=>{if((!("type"in e)||"string"!==e.type)&&"allOf"in e)c.push(...e.allOf),void 0===e.unevaluatedProperties&&(l=void 0);else{let t=e;if("additionalProperties"in e&&!1===e.additionalProperties){let{additionalProperties:r,...a}=e;t=a}else l=void 0;c.push(t)}}),c.length?{allOf:c,...l}:void 0;case M.ZodTuple:return e.rest?{type:"array",minItems:e.items.length,items:e.items.map((e,t)=>fn(e._def,{...r,currentPath:[...r.currentPath,"items",`${t}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[]),additionalItems:fn(e.rest._def,{...r,currentPath:[...r.currentPath,"additionalItems"]})}:{type:"array",minItems:e.items.length,maxItems:e.items.length,items:e.items.map((e,t)=>fn(e._def,{...r,currentPath:[...r.currentPath,"items",`${t}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[])};case M.ZodRecord:return fr(e,r);case M.ZodLiteral:let u;return"bigint"!=(u=typeof e.value)&&"number"!==u&&"boolean"!==u&&"string"!==u?{type:Array.isArray(e.value)?"array":"object"}:"openApi3"===r.target?{type:"bigint"===u?"integer":u,enum:[e.value]}:{type:"bigint"===u?"integer":u,const:e.value};case M.ZodEnum:return{type:"string",enum:Array.from(e.values)};case M.ZodNativeEnum:let d,p,m;return d=e.values,{type:1===(m=Array.from(new Set((p=Object.keys(e.values).filter(e=>"number"!=typeof d[d[e]]).map(e=>d[e])).map(e=>typeof e)))).length?"string"===m[0]?"string":"number":["string","number"],enum:p};case M.ZodNullable:if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(e.innerType._def.typeName)&&(!e.innerType._def.checks||!e.innerType._def.checks.length))return"openApi3"===r.target?{type:fa[e.innerType._def.typeName],nullable:!0}:{type:[fa[e.innerType._def.typeName],"null"]};if("openApi3"===r.target){let t=fn(e.innerType._def,{...r,currentPath:[...r.currentPath]});return t&&"$ref"in t?{allOf:[t],nullable:!0}:t&&{...t,nullable:!0}}let h=fn(e.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","0"]});return h&&{anyOf:[h,{type:"null"}]};case M.ZodOptional:if(r.currentPath.toString()===r.propertyPath?.toString())return fn(e.innerType._def,r);let f=fn(e.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","1"]});return f?{anyOf:[{not:hH(r)},f]}:hH(r);case M.ZodMap:if("record"===r.mapStrategy)return fr(e,r);return{type:"array",maxItems:125,items:{type:"array",items:[fn(e.keyType._def,{...r,currentPath:[...r.currentPath,"items","items","0"]})||hH(r),fn(e.valueType._def,{...r,currentPath:[...r.currentPath,"items","items","1"]})||hH(r)],minItems:2,maxItems:2}};case M.ZodSet:let g;return g={type:"array",uniqueItems:!0,items:fn(e.valueType._def,{...r,currentPath:[...r.currentPath,"items"]})},e.minSize&&hB(g,"minItems",e.minSize.value,e.minSize.message,r),e.maxSize&&hB(g,"maxItems",e.maxSize.value,e.maxSize.message,r),g;case M.ZodLazy:return()=>e.getter()._def;case M.ZodPromise:return fn(e.type._def,r);case M.ZodNaN:case M.ZodNever:return"openAi"===r.target?void 0:{not:hH({...r,currentPath:[...r.currentPath,"not"]})};case M.ZodEffects:return"input"===r.effectStrategy?fn(e.schema._def,r):hH(r);case M.ZodAny:case M.ZodUnknown:return hH(r);case M.ZodDefault:return{...fn(e.innerType._def,r),default:e.defaultValue()};case M.ZodBranded:return hK(e,r);case M.ZodReadonly:case M.ZodCatch:return fn(e.innerType._def,r);case M.ZodPipeline:if("input"===r.pipeStrategy)return fn(e.in._def,r);if("output"===r.pipeStrategy)return fn(e.out._def,r);let y=fn(e.in._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),v=fn(e.out._def,{...r,currentPath:[...r.currentPath,"allOf",y?"1":"0"]});return{allOf:[y,v].filter(e=>void 0!==e)};case M.ZodFunction:case M.ZodVoid:case M.ZodSymbol:default:return}})(e,e.typeName,t),o="function"==typeof n?fn(n(),t):n;if(o&&fs(e,t,o),t.postProcess){let r=t.postProcess(o,e,t);return i.jsonSchema=o,r}return i.jsonSchema=o,o}let fo=(e,t)=>{switch(t.$refStrategy){case"root":return{$ref:e.path.join("/")};case"relative":return{$ref:hF(t.currentPath,e.path)};case"none":case"seen":if(e.path.length<t.currentPath.length&&e.path.every((e,r)=>t.currentPath[r]===e))return console.warn(`Recursive reference detected at ${t.currentPath.join("/")}! Defaulting to any`),hH(t);return"seen"===t.$refStrategy?hH(t):void 0}},fs=(e,t,r)=>(e.description&&(r.description=e.description,t.markdownDescription&&(r.markdownDescription=e.description)),r);function fl(e){if("object"!=typeof e||null===e)return!1;let t=e["~standard"];return"object"==typeof t&&null!==t&&"function"==typeof t.validate}function fc(e,t,r){let a=e["~standard"];if(a.jsonSchema)return a.jsonSchema[r]({target:t});if("zod"===e["~standard"].vendor&&!("_zod"in e)&&"_def"in e){let r=((e,t)=>{let r,a,i=(a=void 0!==(r="string"==typeof t?{...mL,name:t}:{...mL,...t}).name?[...r.basePath,r.definitionPath,r.name]:r.basePath,{...r,flags:{hasReferencedOpenAiAnyType:!1},currentPath:a,propertyPath:void 0,seen:new Map(Object.entries(r.definitions).map(([e,t])=>[t._def,{def:t._def,path:[...r.basePath,r.definitionPath,e],jsonSchema:void 0}]))}),n="object"==typeof t&&t.definitions?Object.entries(t.definitions).reduce((e,[t,r])=>({...e,[t]:fn(r._def,{...i,currentPath:[...i.basePath,i.definitionPath,t]},!0)??hH(i)}),{}):void 0,o="string"==typeof t?t:t?.nameStrategy==="title"?void 0:t?.name,s=fn(e._def,void 0===o?i:{...i,currentPath:[...i.basePath,i.definitionPath,o]},!1)??hH(i),l="object"==typeof t&&void 0!==t.name&&"title"===t.nameStrategy?t.name:void 0;void 0!==l&&(s.title=l),i.flags.hasReferencedOpenAiAnyType&&(n||(n={}),n[i.openAiAnyTypeName]||(n[i.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:"relative"===i.$refStrategy?"1":[...i.basePath,i.definitionPath,i.openAiAnyTypeName].join("/")}}));let c=void 0===o?n?{...s,[i.definitionPath]:n}:s:{$ref:[..."relative"===i.$refStrategy?[]:i.basePath,i.definitionPath,o].join("/"),[i.definitionPath]:{...n,[o]:s}};return"jsonSchema7"===i.target?c.$schema="http://json-schema.org/draft-07/schema#":("jsonSchema2019-09"===i.target||"openAi"===i.target)&&(c.$schema="https://json-schema.org/draft/2019-09/schema#"),"openAi"===i.target&&("anyOf"in c||"oneOf"in c||"allOf"in c||"type"in c&&Array.isArray(c.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),c})(e,{$refStrategy:"none",target:"openapi-3.0"===t?"openApi3":"jsonSchema7"});return delete r.$schema,r}if("zod"===a.vendor&&"_zod"in e)try{let t=a8(e);return delete t.$schema,t}catch(e){throw Error(`Failed to convert a zod schema to JSON Schema (zod v4 without "~standard.jsonSchema"). Upgrade to zod >= 4.2.0. Original error: ${e instanceof Error?e.message:String(e)}`)}throw Error(`Schema library "${a.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".`)}function fu(e,t={}){let{strict:r=!1}=t,a=Object.entries(e),i=e=>({target:t})=>{let i={},n=[];for(let[r,o]of a)i[r]=fc(o,t,e),!function(e,t){if("function"!=typeof e.safeParse)return!1;try{let r=e.safeParse(void 0);return r.success&&("input"===t||void 0===r.data)}catch{return!1}}(o,e)&&n.push(r);let o={type:"object",properties:i};return n.length>0&&(o.required=n),r&&(o.additionalProperties=!1),o};return{shape:e,"~standard":{version:1,vendor:"xmcp",validate:async t=>{if("object"!=typeof t||null===t||Array.isArray(t))return{issues:[{message:"Expected an object."}]};let i={},n=[];for(let[e,r]of a){let a=await r["~standard"].validate(t[e]);if(a.issues)for(let t of a.issues)n.push({message:t.message,path:[e,...t.path??[]]});else(e in t||void 0!==a.value)&&(i[e]=a.value)}if(r)for(let r of Object.keys(t))r in e||n.push({message:`Unrecognized key: "${r}"`,path:[r]});return n.length>0?{issues:n}:{value:i}},jsonSchema:{input:i("input"),output:i("output")}}}}function fd(e,t={}){let r;return fl(e)?{..."object"==typeof(r=e.shape)&&null!==r&&Object.values(r).every(fl)?{shape:r}:{},"~standard":{version:1,vendor:"xmcp",validate:t=>e["~standard"].validate(t),jsonSchema:{input:({target:t})=>fc(e,t,"input"),output:({target:t})=>fc(e,t,"output")}}}:fu(e,t)}async function fp(e,t,r,a){if(fl(t)){let i=await t["~standard"].validate(e);if(i.issues){let e=i.issues.map(e=>{let t=(e.path??[]).map(e=>"object"==typeof e&&null!==e&&"key"in e?String(e.key):String(e)).join(".");return t?`${t}: ${e.message}`:e.message}).join("; ");throw Error(`Tool "${r}" ${a}: ${e}`)}return}if(null===e||"object"!=typeof e||Array.isArray(e))throw Error(`Tool "${r}" ${a}: expected a plain object.`);let i=new Set(Object.keys(t)),n=Object.keys(e).filter(e=>!i.has(e));if(n.length>0)throw Error(`Tool "${r}" ${a}: unrecognized key(s): ${n.join(", ")}`);for(let[i,n]of Object.entries(t))try{n.parse(e[i])}catch(e){throw Error(`Tool "${r}" ${a}: ${e?.message??`invalid field "${i}"`}`)}}function fm(e){return!(!e||"object"!=typeof e||Array.isArray(e))&&("structuredContent"in e||"content"in e&&Array.isArray(e.content)||"_meta"in e||"isError"in e)}function fh(e){return!!(e&&"object"==typeof e&&Object.keys(e).some(e=>e.startsWith("ui/")))}function ff(e){let t=e.mcpReq.envelope,r=mn(t?.[nJ]);if(!r)try{let e,t=mr();r=t.clientInfo??(e=t.headers,mn({name:ms(e,"x-mcp-client-name"),version:ms(e,"x-mcp-client-version"),title:ms(e,"x-mcp-client-title"),websiteUrl:ms(e,"x-mcp-client-website-url"),description:ms(e,"x-mcp-client-description")}))}catch{}if(!r)try{r=mg().clientInfo}catch{}return r}function fg(e,t=!1){let r=[...e];return(e,a,i)=>mp(a,ff(a),async()=>{if(0===r.length)return i();let t=Object.freeze({...md(),...e,params:Object.freeze({...e.params})}),a=-1,n=async e=>{if(e<=a)throw Error("MCP middleware next() can only be called once");a=e;let o=r[e];return o?o(t,()=>n(e+1)):i()};return n(0)},t)}function fy(e,t=new WeakMap){if(null===e||"object"!=typeof e)return e;let r=Object.getPrototypeOf(e);if(!Array.isArray(e)&&r!==Object.prototype&&null!==r)return e;if(t.has(e))return t.get(e);let a=Array.isArray(e)?[]:Object.create(r);for(let[r,i]of(t.set(e,a),Object.entries(e)))Object.defineProperty(a,r,{value:fy(i,t),enumerable:!0,configurable:!0,writable:!0});return Object.freeze(a)}let fv=new Set(["tools/list","prompts/get","prompts/list","resources/read","resources/list","resources/templates/list","completion/complete"]);function f_(e){return e.endsWith(".tsx")}function fb(e){let t={};return!function e(r,a=""){if(r&&"object"==typeof r)for(let[i,n]of Object.entries(r)){let r=a?`${a}/${i}`:i;!n||"object"!=typeof n||Array.isArray(n)||n instanceof Date||n instanceof RegExp?t[r]=n:e(n,r)}}(e),t}let fS=["ui/resourceUri","resourceUri","visibility"],f$=["prefersBorder","domain","csp","permissions","connectDomains","resourceDomains","frameDomains","baseUriDomains"];function fw(e){return"object"==typeof e&&null!==e&&Object.entries(e).every(([e,t])=>"string"==typeof e&&"object"==typeof t&&null!==t&&"parse"in t&&"function"==typeof t.parse)}function fR(e){return(e.split("/").pop()||e).replace(/\.[^/.]+$/,"")}function fk(e,t,r){return e.names?.includes(t)===!0||e.tags?.some(e=>r.includes(e))===!0}function fx(e,t){return t?new Map([...e].filter(([e,{metadata:r}])=>{if(r?.enabled===!1)return!1;let a=r?.name??fR(e),i=r?.tags??[];return(!t.include||fk(t.include,a,i))&&(!t.exclude||!fk(t.exclude,a,i))})):e}function fP(e){if("string"!=typeof e)return;let t=/^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/.exec(e);if(!(!t||"ff"===t[1]||/^0+$/.test(t[2])||/^0+$/.test(t[3]))&&("00"!==t[1]||void 0===t[5]))return{trace:{id:t[2]},parent:{id:t[3]}}}function fE(e){return Error(`[xmcp] Invalid prompt file: ${e}
82
+ -> Default export must be a prompt handler function.`)}let fT=function(e=console){let t="";return r=>{let a=r.map(({path:e,message:t})=>`${e}:${t}`).sort().join("|");if(a===t||(t=a,0===r.length))return;r.forEach(({path:t,message:r})=>{e.warn(`[xmcp] Failed to load prompt file: ${t}
83
+ -> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} prompt${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function fj(e){return Error(`[xmcp] Invalid resource file: ${e}
84
+ -> Default export must be a resource handler function.`)}let fO=function(e=console){let t="";return r=>{let a=r.map(({path:e,message:t})=>`${e}:${t}`).sort().join("|");if(a===t||(t=a,0===r.length))return;r.forEach(({path:t,message:r})=>{e.warn(`[xmcp] Failed to load resource file: ${t}
85
+ -> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} resource${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function fC(e){let t=e.replace(/\\/g,"/");if(!t)throw Error("Invalid tool path: path is empty");let r=t.replace(/\.[^/.]+$/,"").replace(/\//g,"_");return{normalizedPath:t,baseName:r}}function fI(e){let t=e.split("/").filter(e=>""!==e),r=t.findIndex(e=>e.match(/^\(.+\)$/));if(-1===r)return null;let a=t[t.length-1];if(a&&a.match(/^\[.+\]\.ts$/))return null;let i=t[r].slice(1,-1),n=t.slice(r+1),o=n[n.length-1];if(o&&o.includes(".")){let e=o.split(".")[0];"index"!==e?n[n.length-1]=e:n.pop()}let s=[],l=[],c=n.map(e=>{if(!e.match(/^\[.+\]$/))return l.push(e),e;{let t=e.slice(1,-1);return s.push(t),`{${t}}`}}),u=`${i}://${c.join("/")}`,d=s.length>0?"template":"direct";return{filePath:e,uriTemplate:u,scheme:i,parameters:s,pathSegments:l,type:d}}let fN={ttlMs:0,cacheScope:"private"},fq=hV({cursor:hU().optional()}).passthrough().optional(),fA=hV({uri:hU()}).passthrough();function fz({uri:e,frontmatter:t,files:r}){return{uri:e,frontmatter:t,resources:r.map(({uri:e,digest:t,size:r})=>({uri:e,digest:t,size:r}))}}function fM(e){return Error(`[xmcp] Invalid tool file: ${e}
86
+ -> Default export must be a tool handler function.`)}let fL=function(e=console){let t="";return r=>{let a=r.map(({path:e,message:t})=>`${e}:${t}`).sort().join("|");if(a===t||(t=a,0===r.length))return;r.forEach(({path:t,message:r})=>{e.warn(`[xmcp] Failed to load tool file: ${t}
87
+ -> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} tool${1===i?"":"s"} skipped due to empty files or missing default exports`)}}(),fZ=INJECTED_TOOLS,fD=INJECTED_PROMPTS,fU=INJECTED_RESOURCES,fV="u"<typeof INJECTED_SKILLS?[]:INJECTED_SKILLS??[],fF=SERVER_INFO,fH=function(e,t={}){var r;let{legacy:a,onerror:i,responseMode:n}=t,o=pY(t.maxRequestBodySize);if("function"==typeof a)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 s=new Set,l=!1,c=e=>{try{i?.(e)}catch{}},d=t.bus??new pB(c),f={toolsChanged:()=>d.publish({kind:"tools_list_changed"}),promptsChanged:()=>d.publish({kind:"prompts_list_changed"}),resourcesChanged:()=>d.publish({kind:"resources_list_changed"}),resourceUpdated:e=>d.publish({kind:"resource_updated",uri:e})},g=function(e){let{bus:t,onerror:r}=e,a=e.maxSubscriptions??1024,i=e.keepAliveMs??15e3,n=new Set;return{serve:function(e,o,s,l){let c,u,d,p,m,h,f;if(n.size>=a)return r?.(Error(`subscriptions/listen refused: subscription limit reached (${a})`)),pK(e.id,-32603,"Subscription limit reached");let g=(m=cq(cN).validateRequest("subscriptions/listen",e)).ok?m.value.params?.notifications:void 0;if(void 0===g)return pK(e.id,-32602,"Invalid params: 'notifications' is required and must be a valid SubscriptionFilter");let y=(h={},f=e=>void 0===s||!0===e,!0===g.toolsListChanged&&f(s?.tools?.listChanged)&&(h.toolsListChanged=!0),!0===g.promptsListChanged&&f(s?.prompts?.listChanged)&&(h.promptsListChanged=!0),!0===g.resourcesListChanged&&f(s?.resources?.listChanged)&&(h.resourcesListChanged=!0),void 0!==g.resourceSubscriptions&&g.resourceSubscriptions.length>0&&f(s?.resources?.subscribe)&&(h.resourceSubscriptions=[...g.resourceSubscriptions]),h),v=e.id,_=new TextEncoder,b=!1,S=e=>{if(!b)try{c.enqueue(_.encode(e))}catch(e){r?.(e instanceof Error?e:Error(String(e)))}},$=(e,t)=>{S(`event: message
88
88
  data: ${JSON.stringify({jsonrpc:"2.0",method:e,params:t})}
89
89
 
90
90
  `)},w=e=>{if(!b){e&&S(`event: message
91
91
  data: ${JSON.stringify({jsonrpc:"2.0",id:v,result:{resultType:"complete",_meta:{[nG]:v,[nB]:l}}})}
92
92
 
93
- `),b=!0;try{u?.()}catch(e){r?.(e instanceof Error?e:Error(String(e)))}void 0!==d&&clearInterval(d),p?.(),n.delete(w);try{c.close()}catch{}}},R=new ReadableStream({start(e){c=e;let r=pG({method:"notifications/subscriptions/acknowledged",params:{notifications:y}},v);($(r.method,r.params),0===Object.keys(y).length)?w(!0):(u=t.subscribe(e=>{if(b||!function(e,t){switch(t.kind){case"tools_list_changed":return!0===e.toolsListChanged;case"prompts_list_changed":return!0===e.promptsListChanged;case"resources_list_changed":return!0===e.resourcesListChanged;case"resource_updated":return void 0!==e.resourceSubscriptions&&e.resourceSubscriptions.includes(t.uri)}}(y,e))return;let t=pG(function(e){switch(e.kind){case"tools_list_changed":return{method:"notifications/tools/list_changed",...void 0!==e.params&&{params:e.params}};case"prompts_list_changed":return{method:"notifications/prompts/list_changed",...void 0!==e.params&&{params:e.params}};case"resources_list_changed":return{method:"notifications/resources/list_changed",...void 0!==e.params&&{params:e.params}};case"resource_updated":return{method:"notifications/resources/updated",params:{...e.params,uri:e.uri}}}}(e),v);$(t.method,t.params)}),d=pk(i,()=>S(": keepalive\n\n")),n.add(w))},cancel(){w(!1)}});if(void 0!==o)if(o.aborted)w(!1);else{let e=()=>w(!1);o.addEventListener("abort",e,{once:!0}),p=()=>o.removeEventListener("abort",e)}return new Response(R,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"}})},closeAll(){for(let e of n)e(!0)},get openCount(){return n.size}}}({bus:d,maxSubscriptions:t.maxSubscriptions??1024,keepAliveMs:t.keepAliveMs??15e3,onerror:c});"json"===n&&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 y="reject"===a?void 0:(r=t.keepAliveMs,async(t,a)=>{if("POST"!==t.method.toUpperCase())return p1(405,-32e3,"Method not allowed.");try{let i=await e({era:"legacy",...a?.authInfo!==void 0&&{authInfo:a.authInfo},requestInfo:t}),n=new pQ({sessionIdGenerator:void 0,...void 0!==r&&{keepAliveMs:r},...void 0!==o&&{maxRequestBodySize:o}});await i.connect(n);let s=()=>{n.close().catch(()=>{}),i.close().catch(()=>{})};t.signal?.addEventListener("abort",s,{once:!0});let l=await n.handleRequest(t,{...a?.authInfo!==void 0&&{authInfo:a.authInfo},...a?.parsedBody!==void 0&&{parsedBody:a.parsedBody}});if(null===l.body||"text/event-stream"!==uq(l.headers.get("content-type")))return s(),l;let c=l.body.getReader(),u=!1,d=()=>{u||(u=!0,s())},p=new ReadableStream({pull:async e=>{try{let{done:t,value:r}=await c.read();if(t){d(),e.close();return}void 0!==r&&e.enqueue(r)}catch(t){d(),e.error(t)}},cancel:e=>(d(),c.cancel(e).catch(()=>{}))});return new Response(p,{status:l.status,statusText:l.statusText,headers:l.headers})}catch(e){try{c?.(p9(e))}catch{}return p4(p0(a?.parsedBody))}});return{fetch:async(r,a)=>{if(l)throw Error("This MCP handler has been closed");try{return await async function(r,a){let i=a?.authInfo;if("POST"===r.method.toUpperCase()&&!uA(r.headers.get("content-type")))return c(Error("Unsupported Media Type: Content-Type must be application/json")),p1(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");let l=await async function(e,t,r=!0,a=4194304){let i,n=e.method.toUpperCase(),o=t,s=e,l=!1;if("POST"===n){if(void 0===o){let t;r&&(s=e.clone());try{let r=await pX(e,a);if(r.tooLarge)return{step:"body-too-large"};t=r.text}catch{return{step:"unreadable-body"}}try{i=0===t.length?void 0:JSON.parse(t)}catch{l=!0}l||void 0===i||(o=i)}else i=o;if(l||void 0===i)return{step:"no-json-body",forwardRequest:s}}return{step:"classified",outcome:function(e){if("POST"!==(e={...e,...void 0!==e.protocolVersionHeader&&{protocolVersionHeader:ui(e.protocolVersionHeader)},...void 0!==e.mcpMethodHeader&&{mcpMethodHeader:ui(e.mcpMethodHeader)},...void 0!==e.mcpNameHeader&&{mcpNameHeader:ui(e.mcpNameHeader)}}).httpMethod.toUpperCase())return{kind:"legacy",reason:"http-method"};let t=e.body;if(Array.isArray(t)){if(0===t.length)return ut("jsonrpc-shape","empty-batch",400,new cf(ch.InvalidRequest,"Bad Request: empty JSON-RPC batch"),!0);for(let e of t){if(cV(un(e)?e.params:void 0))return ut("jsonrpc-shape","batch-with-modern-element",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC batches may not contain requests for protocol revision 2026-07-28 or later"),!0);if(!(cB(e)||cK(e)||cG(e)||cW(e)))return ut("jsonrpc-shape","batch-with-invalid-element",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC batch contains an invalid message"),!0)}return{kind:"legacy",reason:"batch"}}return cG(t)||cW(t)?{kind:"legacy",reason:"response"}:un(t)&&cB(t)?function(e,t){let r=t.params,a=t.method,i=e.protocolVersionHeader,n=void 0!==i&&i>=lG;if("initialize"===a&&!function(e){if(!cV(e))return!1;let t=cF(e);if(void 0===t||!(t>=lG))return!1;let r=cU(e);return void 0!==r&&0===cH(r).length}(r)){if(n)return ur("initialize-with-modern-header",i,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let e=un(r)&&"string"==typeof r.protocolVersion?r.protocolVersion:void 0;return{kind:"legacy",reason:"initialize",...void 0!==e&&{requestedVersion:e}}}if(cV(r)){let n=cU(r),o=(void 0===n?[]:cH(n))[0];if(void 0!==o)return ut("envelope","envelope-invalid",400,new cf(ch.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${o.key}: ${o.problem}`,{envelope:o}),!0);let s=cF(r);return void 0!==i&&void 0!==s&&i!==s?ur("header-body-version-mismatch",i,`the body envelope names protocol version ${s} but the MCP-Protocol-Version header names ${i}`):void 0!==e.mcpMethodHeader&&e.mcpMethodHeader!==a?ur("method-header-mismatch",e.mcpMethodHeader,`the body names method ${a} but the Mcp-Method header names ${e.mcpMethodHeader}`):{kind:"modern",messageKind:"request",message:t,classification:uo(s)}}if(n){let e=cU(r),t=cH(e??{}).filter(e=>"missing"===e.problem).map(e=>e.key),a=void 0===e?["_meta"]:t.length>0?t:[nH];return ut("envelope","modern-header-without-claim",400,new cf(ch.InvalidParams,`Invalid params: the MCP-Protocol-Version header names protocol revision ${i}, but the request is missing the required per-request envelope key(s): ${a.join(", ")}`,{envelope:{missing:a}}),!0)}return{kind:"legacy",reason:"no-claim",...void 0!==i&&{requestedVersion:i}}}(e,t):un(t)&&cK(t)?function(e,t){let r=t.params,a=t.method,i=e.protocolVersionHeader,n=void 0!==i&&i>=lG;if(cV(r)){let n=cF(r);if(void 0===n){let e=cU(r),t=(void 0===e?[]:cH(e)).find(e=>e.key===nH)??{key:nH,problem:"expected a protocol version string"};return ut("envelope","notification-envelope-invalid",400,new cf(ch.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${t.key}: ${t.problem}`,{envelope:t}),!0)}if(void 0!==i&&i!==n)return ur("notification-header-body-version-mismatch",i,`the notification envelope names protocol version ${n} but the MCP-Protocol-Version header names ${i}`);let o=uo(n);return"modern"===o.era&&void 0!==e.mcpMethodHeader&&e.mcpMethodHeader!==a?ur("notification-method-header-mismatch",e.mcpMethodHeader,`the notification body names method ${a} but the Mcp-Method header names ${e.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:t,classification:o}}return n?void 0!==e.mcpMethodHeader&&e.mcpMethodHeader!==a?ur("notification-method-header-mismatch",e.mcpMethodHeader,`the notification body names method ${a} but the Mcp-Method header names ${e.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:t,classification:{era:"modern",revision:i}}:{kind:"legacy",reason:"notification",...void 0!==i&&{requestedVersion:i}}}(e,t):ut("jsonrpc-shape","invalid-json-rpc-body",400,new cf(ch.InvalidRequest,"Bad Request: the request body is not a valid JSON-RPC message"),!0)}({httpMethod:n,...p5(e),...void 0!==i&&{body:i}}),body:i,parsedBody:o,forwardRequest:s}}(r,a?.parsedBody,!0,o);if("unreadable-body"===l.step)return p1(400,-32700,"Parse error: the request body could not be read");if("body-too-large"===l.step)return p1(413,-32e3,pW(o));if("no-json-body"===l.step)return void 0!==y?y(l.forwardRequest,{...void 0!==i&&{authInfo:i}}):p1(400,-32700,"Parse error: the request body is not valid JSON");let{outcome:d,body:f,parsedBody:v,forwardRequest:_}=l;try{switch(d.kind){case"reject":return c(Error(`Rejected inbound request (${d.cell}): ${d.message}`)),p2(d,p0(f));case"modern":return await async function(r,a,i){var o,l;let d=r.classification.revision;if(void 0===d||!lW.includes(d)){let e=new cv({supported:[...lW],requested:d??"unknown"});return c(e),p1(400,e.code,e.message,e.data,p0(r.message))}let f=function(e,t){if("request"!==t.messageKind)return;let r=t.message.method;if(void 0===e.protocolVersionHeader){let e=t.classification.revision;return ur("version-header-missing","(missing)",void 0===e?"the body carries a modern per-request envelope but the required MCP-Protocol-Version header is absent":`the body envelope names protocol version ${e} but the required MCP-Protocol-Version header is absent`,"standard-header-validation")}if(void 0===e.mcpMethodHeader)return ur("method-header-missing","(missing)",`the body names method ${r} but the required Mcp-Method header is absent`,"standard-header-validation");let a=function(e,t){let r=Object.hasOwn(ua,e)?ua[e]:void 0;if(void 0===r)return;let a=un(t)?t[r]:void 0;return{field:r,value:"string"==typeof a?a:void 0}}(r,t.message.params);if(void 0===a)return;let{field:i,value:n}=a;if(void 0===e.mcpNameHeader){if(void 0===n)return;return ur("name-header-missing","(missing)",`the body carries params.${i}="${n}" but the required Mcp-Name header is absent`,"standard-header-validation")}let o=ui(e.mcpNameHeader),s=c6(o);return void 0===s?ur("name-header-invalid-encoding",o,"the Mcp-Name header carries an invalid Base64 sentinel value","standard-header-validation"):void 0!==n&&s!==n?ur("name-header-mismatch",o,`the body carries params.${i}="${n}" but the Mcp-Name header names "${s}"`,"standard-header-validation"):void 0}({httpMethod:a.method,...p5(a)},r);if(void 0!==f)return c(Error(`Rejected inbound request (${f.cell}): ${f.message}`)),p2(f,p0(r.message));let y="request"===r.messageKind?cU(r.message.params):void 0,v=y?.[nK];if("request"===r.messageKind){let e=Object.hasOwn(lJ,o=r.message.method)?lJ[o]:void 0;if(void 0!==e){let t=lK(e,v);if(void 0!==t){let e=new c_({requiredCapabilities:t});return c(e),p1(ue[e.code]??400,e.code,e.message,e.data,r.message.id)}}}let _=await e({era:"modern",...void 0!==i&&{authInfo:i},requestInfo:a}),b=_ instanceof pz?_.server:_;if(p3(b),"request"===r.messageKind&&"subscriptions/listen"===r.message.method){let e=b.getCapabilities(),t=h(b);return _.close().catch(c),g.serve(r.message,a.signal,e,t)}if("request"===r.messageKind&&"tools/call"===r.message.method&&_ instanceof pz){let e=r.message.params,t="string"==typeof e?.name?e.name:void 0,i=void 0===t?void 0:_.toolInputSchemaJson(t);if(void 0!==i){let t=c1(i);if(void 0!==t.declarations&&t.declarations.length>0){let i=function(e,t,r){for(let a of e){let e=`Mcp-Param-${a.headerName}`,i=r.get(e),n=function(e,t){let r=e;for(let e of t){if(null===r||"object"!=typeof r)return;r=r[e]}return r}(t,a.path);if(null==n)continue;let o=function(e){if("string"==typeof e)return e;if("boolean"==typeof e)return e?"true":"false";if("number"==typeof e){if(!Number.isFinite(e)||Number.isInteger(e)&&!Number.isSafeInteger(e))return;return String(e)}}(n);if(void 0===o)continue;if(null===i)return c7("param-header-missing",e,`the body carries ${c4(a.path)}=${JSON.stringify(n)} but the ${e} header is absent`);let s=c6(i);if(void 0===s)return c7("param-header-invalid-encoding",e,`the ${e} header carries an invalid Base64 sentinel value`);if(!(("integer"===a.type||"number"===a.type)&&c5.test(s)&&"number"==typeof n?Number(s)===n:s===o))return c7("param-header-mismatch",e,`the ${e} header decodes to ${JSON.stringify(s)} but the body carries ${c4(a.path)}=${JSON.stringify(n)}`)}}(t.declarations,e?.arguments,a.headers);if(void 0!==i)return _.close().catch(c),c(Error(`Rejected inbound request (${i.cell}): ${i.message}`)),p2(i,r.message.id)}}}if("request"===r.messageKind&&_ instanceof pz)try{let e=await pT([r.message],i,e=>_.resolveScopeChallenge(e));if(void 0!==e)return _.close().catch(c),pO(e,pj(i))}catch(e){return _.close().catch(c),c(p9(e)),p4(r.message.id)}p3(b),u(b,d),m(b,lW),void 0!==y&&(l={clientInfo:y[nJ],clientCapabilities:v},p(b,l));let S=b.onclose;s.add(b);let $=()=>{s.delete(b),b.onclose===$&&(b.onclose=S),S?.()};b.onclose=$;try{let e=await async function(e,t,r){let a=new px({classification:r.classification,...void 0!==r.responseMode&&{responseMode:r.responseMode},...void 0!==r.keepAliveMs&&{keepAliveMs:r.keepAliveMs}});return await e.connect(a),a.handleMessage(t,{...void 0!==r.request&&{request:r.request},...void 0!==r.authInfo&&{authInfo:r.authInfo}})}(_,r.message,{classification:r.classification,request:a,...void 0!==i&&{authInfo:i},...void 0!==n&&{responseMode:n},...void 0!==t.keepAliveMs&&{keepAliveMs:t.keepAliveMs}});return"notification"===r.messageKind&&queueMicrotask(()=>void b.close().catch(()=>{})),e}catch(e){if(e instanceof lH&&e.code===lF.ConnectionClosed)return new Response(null,{status:499});return await b.close().catch(()=>{}),s.delete(b),c(p9(e)),p4(p0(r.message))}}(d,r,i);case"legacy":return await async function(e,t,r,a){if(void 0!==y)return y(t,{...void 0!==r&&{authInfo:r},...void 0!==a&&{parsedBody:a}});let i=function(e,t){switch(e.reason){case"http-method":return ut("http-method","modern-only-method-not-allowed",405,new cf(-32e3,"Method not allowed."),!0);case"batch":return ut("jsonrpc-shape","modern-only-batch-not-supported",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC batches are not supported by this endpoint"),!0);case"response":return ut("jsonrpc-shape","modern-only-response-post",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"),!0);case"notification":return;case"initialize":case"no-claim":{let r=e.requestedVersion;return ut("era-classification","modern-only-missing-envelope",400,void 0===r?new cf(ch.UnsupportedProtocolVersion,"Unsupported protocol version: the request did not name a protocol version",{supported:[...t]}):new cv({supported:[...t],requested:r}),!0)}}}(e,lW);return void 0===i?new Response(null,{status:202}):(c(Error(`Rejected 2025-era request on a modern-only endpoint (${i.cell}): ${i.message}`)),p2(i,p0(a)))}(d,_,i,v)}}catch(e){return c(p9(e)),p4(p0(f))}}(r,a)}catch(e){return c(p9(e)),p4(p0(a?.parsedBody))}},notify:f,bus:d,close:async()=>{l=!0,g.closeAll();let e=[...s].map(e=>e.close().catch(()=>{}));s.clear(),await Promise.all(e)}}}(async function(){let{instructions:e,...t}=fN,r=new pz(t,{instructions:e}),a=async function(){let{toolModules:e,skippedTools:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw fE(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw fE(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default tool handler."}}:{skipped:!1,path:e,toolModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.toolModule)}return{toolModules:t,skippedTools:r}}(fj);return fT(t),e}(),n=async function(){let{promptModules:e,skippedPrompts:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw fv(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw fv(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default prompt handler."}}:{skipped:!1,path:e,promptModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.promptModule)}return{promptModules:t,skippedPrompts:r}}(fO);return f_(t),e}(),o=async function(){let{resourceModules:e,skippedResources:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw fb(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw fb(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default resource handler."}}:{skipped:!1,path:e,resourceModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.resourceModule)}return{resourceModules:t,skippedResources:r}}(fC);return fS(t),e}(),[s,l,c]=await Promise.all([a,n,o]);return async function(e,t,r,a){let n=await INJECTED_MIDDLEWARE?.(),o=function(e){if(void 0===e)return[];let t=Array.isArray(e)?[...e]:[e];if(!t.every(e=>"function"==typeof e))throw Error("src/middleware.ts must export mcp as a function or an array of functions");return t}(n?.mcp),s="u">typeof OBSERVABILITY_CONFIG&&OBSERVABILITY_CONFIG.enabled?function(e=e=>console.error(e)){let t=new Map,r=[];function a(t){try{e(JSON.stringify({"@timestamp":new Date().toISOString(),...t}))}catch{}}return{middleware:async(e,i)=>{let n,o,s;if("tools/call"!==e.method&&"prompts/get"!==e.method&&"resources/read"!==e.method)return i();try{o=performance.now(),n={log:{level:"info"},...function(e){let t=e.http?.headers.traceparent;if("string"!=typeof t)return{};let r=/^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/.exec(t);return!r||"ff"===r[1]||/^0+$/.test(r[2])||/^0+$/.test(r[3])||"00"===r[1]&&void 0!==r[5]?{}:{trace:{id:r[2]},parent:{id:r[3]}}}(e),transaction:{id:crypto.randomUUID()},...e.http?{http:{request:{id:e.http.id}}}:{},xmcp:{method:e.method,component:"resources/read"===e.method?function(e){try{let a=new URL(e).href;return t.get(a)??r.find(({template:e})=>e.uriTemplate.match(a))?.name??"unknown"}catch{return"unknown"}}(e.params.uri):e.params.name}}}catch{return i()}a({...n,event:{kind:"event",category:["api"],type:["start"],action:"execution.start"}});let l="unknown";try{let t=await i();try{l=e.signal.aborted?"cancelled":cY(t)?"input_required":"isError"in t&&!0===t.isError?"failure":"success","failure"===l&&(s={message:"Operation returned an error result"})}catch{}return t}catch(t){throw s={message:"cancelled"==(l=e.signal.aborted?"cancelled":"failure")?"Operation cancelled":"Operation threw an exception"},t}finally{try{a({...n,log:{level:"failure"===l?"error":"info"},event:{kind:"event",category:["api"],type:["end"],action:"execution.end",duration:Math.round((performance.now()-o)*1e6),outcome:"success"===l?"success":"failure"===l?"failure":"unknown"},xmcp:{...n.xmcp,status:l},...s?{error:s}:{}})}catch{}}},registerResource(e,a){try{"string"==typeof a?t.set(new URL(a).href,e):r.push({name:e,template:a})}catch{}}}}():void 0;s&&o.unshift(s.middleware),mc.clear();let l="u"<typeof COMPONENTS_CONFIG?void 0:COMPONENTS_CONFIG;return!function(e,t,r){let a=e.server,i=a.setRequestHandler,n=mz(t);a.setRequestHandler=(e,...t)=>{if(mM.has(e)&&1===t.length&&"function"==typeof t[0]){let e=t[0];t[0]=(t,r)=>n({method:t.method,params:t.params??{}},r,()=>e(t,r))}Reflect.apply(i,a,[e,...t])};try{r()}finally{a.setRequestHandler=i}}(e,o,()=>{var n,c;!function(e,t,r=[]){t.forEach((t,a)=>{var i,n;let o,s,l,c,u={name:ff(a),description:"No description provided"},{default:d,metadata:p,schema:m,outputSchema:h}=t;if("object"==typeof p&&null!==p&&Object.assign(u,p),!1===u.enabled)return;if("function"==typeof d&&"__x402"in d){let e=global.__XMCP_X402_REGISTRY;e&&e.set(u.name,d.__x402)}let f={};if(fh(m)?f=m:null!=m&&console.warn(`Invalid schema for tool "${u.name}" at ${a}. Expected Record<string, z.ZodType>`),null!=h)if(fh(h))o=h;else throw Error(`Invalid outputSchema for tool "${u.name}" at ${a}. Expected Record<string, z.ZodType>`);u.annotations={...u.annotations??{}},void 0===u.annotations.title&&(u.annotations.title=u.name),u._meta={...ml(u)._meta};let g=mL(a),y=!!(i=u._meta)&&"object"==typeof i&&"ui"in i&&"object"==typeof i.ui||g,v=u._meta;if(y){let e=`ui://app/${u.name}.html`;u._meta.ui||(u._meta.ui={}),u._meta.ui.resourceUri||(u._meta.ui.resourceUri=e);let t=function(e){let t={},r={};if(e.ui&&"object"==typeof e.ui){let a=e.ui,i={},n={};for(let[e,t]of Object.entries(a))fp.includes(e)?i[e]=t:fm.includes(e)?n[e]=t:i[e]=t;Object.keys(i).length>0&&(t.ui=i),Object.keys(n).length>0&&(r.ui=n)}for(let[r,a]of Object.entries(e))"ui"!==r&&(t[r]=a);return{toolMeta:t,resourceMeta:r}}(v);v=t.toolMeta;let r=t.resourceMeta;r.ui=r.ui||{},r.ui.csp=r.ui.csp||{},r.ui.csp.resourceDomains=r.ui.csp.resourceDomains||[],r.ui.csp.resourceDomains.includes("https://esm.sh")||r.ui.csp.resourceDomains.push("https://esm.sh"),mc.add(u.name,{name:u.name,uri:e,handler:d,mimeType:"text/html;profile=mcp-app",_meta:r,toolPath:g?a:void 0})}let _=fd(v),b=y?_:void 0;s=mL(a)&&y?async(e,t)=>({content:[{type:"text",text:""}],_meta:b,structuredContent:{args:e}}):function(e,t,r,a="unknown-tool"){return async(i,n)=>{let o,s,l=e(i,(o=mA(n),s=function(e){if(!e)return;let t={};return e.headers.forEach((e,r)=>{t[r]=e}),t}(n.http?.req),{signal:n.mcpReq.signal,authInfo:n.http?.authInfo,sessionId:n.sessionId,_meta:n.mcpReq._meta,requestId:n.mcpReq.id,requestInfo:s?{headers:s}:void 0,clientInfo:o,sendNotification:e=>n.mcpReq.notify(e),sendRequest:(e,t,r)=>n.mcpReq.send(e,t,r),elicit:(e,t)=>(async function(e,t,r){let a=function(e){let t=e.mode??"form";if("url"===t)return function(e){let t;m$(e,"Elicitation request must be a plain object."),mS(e,mh,"URL elicitation"),mw(e.message,"URL elicitation requires a string message."),mR(e.elicitationId,"URL elicitation requires a non-empty elicitationId."),mR(e.url,"URL elicitation requires a non-empty URL.");try{t=new URL(e.url)}catch{throw Error("URL elicitation requires a valid http or https URL.")}if("http:"!==t.protocol&&"https:"!==t.protocol)throw Error("URL elicitation requires a valid http or https URL.")}(e),e;if("form"!==t)throw Error(`Unsupported elicitation mode "${String(e.mode)}". Expected "form" or "url".`);return function(e){m$(e,"Elicitation request must be a plain object."),mS(e,mm,"Form elicitation"),mw(e.message,"Form elicitation requires a string message.");let t=e.requestedSchema;if(m$(t,"Form elicitation requires a flat object schema."),mS(t,mf,"Form elicitation schema"),"object"!==t.type)throw Error('Form elicitation schema must use type "object".');for(let[e,r]of(m$(t.properties,"Form elicitation schema requires a properties object."),Object.entries(t.properties)))!function(e,t){if(m$(t,`Form elicitation field "${e}" must be a plain object.`),mk(t.title,`Form elicitation field "${e}" title must be a string.`),mk(t.description,`Form elicitation field "${e}" description must be a string.`),"string"===t.type&&"enum"in t){var r,a;if(mS(t,my,`Form elicitation field "${e}"`),mP(t.enum,`Form elicitation field "${e}" enum values must be strings.`),r=t.enumNames,a=`Form elicitation field "${e}" enumNames must be strings.`,void 0!==r&&mP(r,a),void 0!==t.enumNames&&t.enumNames.length!==t.enum.length)throw Error(`Form elicitation field "${e}" enumNames length must match enum length.`);if(mk(t.default,`Form elicitation field "${e}" default must be a string.`),void 0!==t.default&&!t.enum.includes(t.default))throw Error(`Form elicitation field "${e}" default must be one of its enum values.`);return}if("string"===t.type&&!("enum"in t)){mS(t,mg,`Form elicitation field "${e}"`),mx(t.minLength,`Form elicitation field "${e}" minLength must be a number.`),mx(t.maxLength,`Form elicitation field "${e}" maxLength must be a number.`),mk(t.default,`Form elicitation field "${e}" default must be a string.`);let r=t.format;if(mk(r,`Form elicitation field "${e}" format must be a string.`),void 0!==r&&!mb.has(r))throw Error(`Form elicitation field "${e}" format must be one of: ${Array.from(mb).join(", ")}.`);return}if("boolean"===t.type){if(mS(t,mv,`Form elicitation field "${e}"`),void 0!==t.default&&"boolean"!=typeof t.default)throw Error(`Form elicitation field "${e}" default must be a boolean.`);return}if("number"===t.type||"integer"===t.type){mS(t,m_,`Form elicitation field "${e}"`),mx(t.minimum,`Form elicitation field "${e}" minimum must be a number.`),mx(t.maximum,`Form elicitation field "${e}" maximum must be a number.`),mx(t.default,`Form elicitation field "${e}" default must be a number.`);return}throw Error(`Form elicitation field "${e}" uses unsupported type "${String(t.type)}". Supported types are string, boolean, number, integer, and string enums.`)}(e,r);if(void 0!==t.required){if(!Array.isArray(t.required)||t.required.some(e=>"string"!=typeof e))throw Error("Form elicitation schema required fields must be a string array.");for(let e of t.required)if(!(e in t.properties))throw Error(`Form elicitation schema required field "${e}" is not defined in properties.`)}}(e),{...e,mode:"form"}}(t);try{let t=await e.mcpReq.elicitInput(a,r);return{...t,content:t.content??void 0}}catch(e){if(e instanceof lH&&e.code===lF.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 e}})(n,e,t),sample:(e,t)=>(async function(e,t,r){let a=function(e){mO(e,"Sampling request must be a plain object.");let t=Object.keys(e),r=t.filter(e=>mT.has(e));if(r.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${r.join(", ")}.`);let a=t.filter(e=>!mE.has(e));if(a.length>0)throw Error(`Sampling request includes unsupported key(s): ${a.join(", ")}.`);if(!Array.isArray(e.messages)||0===e.messages.length)throw Error("Sampling requires at least one message.");for(let[t,r]of e.messages.entries())!function(e,t){if(mO(t,`Sampling message at index ${e} must be a plain object.`),"user"!==t.role&&"assistant"!==t.role)throw Error(`Sampling message at index ${e} requires role "user" or "assistant".`);let r=t.content;mO(r,`Sampling message at index ${e} requires a content object.`);let a=r.type;if("string"!=typeof a||!mj.has(a))throw Error(`Sampling message at index ${e} uses unsupported content type "${String(a)}". Supported types are text, image, and audio.`);if("text"===a&&"string"!=typeof r.text)throw Error(`Sampling message at index ${e} requires string text content.`);if(("image"===a||"audio"===a)&&("string"!=typeof r.data||"string"!=typeof r.mimeType))throw Error(`Sampling message at index ${e} requires base64 data and a mimeType.`)}(t,r);if("number"!=typeof e.maxTokens)throw Error("Sampling requires a numeric maxTokens.");return e}(t);try{return await e.mcpReq.requestSampling(a,r)}catch(e){if(e instanceof lH&&e.code===lF.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 e}})(n,e,t),inputResponses:n.mcpReq.inputResponses,requestState:n.mcpReq.requestState}));if(l instanceof Promise&&(l=await l),cY(l))return l;if("string"==typeof l||"number"==typeof l){if(r){let e=Object.entries(r);if(1===e.length){let[t,r]=e[0];try{return r.parse(l),{content:[{type:"text",text:"number"==typeof l?`${l}`:l}],structuredContent:{[t]:l}}}catch{}}}return mq(t)?{content:[{type:"text",text:""}],structuredContent:{args:i},_meta:t}:{content:[{type:"text",text:"number"==typeof l?`${l}`:l}]}}if(!r||!l||"object"!=typeof l||Array.isArray(l)||"structuredContent"in l||"content"in l&&Array.isArray(l.content)||"_meta"in l||"isError"in l||(mN(l,r,a,"returned data that does not match outputSchema"),l={structuredContent:l}),l&&"object"==typeof l&&"_meta"in l&&!("content"in l)&&!("structuredContent"in l)){let e=l._meta;if(mq(e))return{content:[{type:"text",text:""}],_meta:e}}if(!l||"object"!=typeof l){let e=null===l?"null":typeof l,t=void 0===l?"undefined":null===l?"null":"object"==typeof l?JSON.stringify(l,null,2):String(l);throw Error(`Tool handler must return a CallToolResult, string, or number. Got ${e}: ${t}
93
+ `),b=!0;try{u?.()}catch(e){r?.(e instanceof Error?e:Error(String(e)))}void 0!==d&&clearInterval(d),p?.(),n.delete(w);try{c.close()}catch{}}},R=new ReadableStream({start(e){c=e;let r=pG({method:"notifications/subscriptions/acknowledged",params:{notifications:y}},v);($(r.method,r.params),0===Object.keys(y).length)?w(!0):(u=t.subscribe(e=>{if(b||!function(e,t){switch(t.kind){case"tools_list_changed":return!0===e.toolsListChanged;case"prompts_list_changed":return!0===e.promptsListChanged;case"resources_list_changed":return!0===e.resourcesListChanged;case"resource_updated":return void 0!==e.resourceSubscriptions&&e.resourceSubscriptions.includes(t.uri)}}(y,e))return;let t=pG(function(e){switch(e.kind){case"tools_list_changed":return{method:"notifications/tools/list_changed",...void 0!==e.params&&{params:e.params}};case"prompts_list_changed":return{method:"notifications/prompts/list_changed",...void 0!==e.params&&{params:e.params}};case"resources_list_changed":return{method:"notifications/resources/list_changed",...void 0!==e.params&&{params:e.params}};case"resource_updated":return{method:"notifications/resources/updated",params:{...e.params,uri:e.uri}}}}(e),v);$(t.method,t.params)}),d=pk(i,()=>S(": keepalive\n\n")),n.add(w))},cancel(){w(!1)}});if(void 0!==o)if(o.aborted)w(!1);else{let e=()=>w(!1);o.addEventListener("abort",e,{once:!0}),p=()=>o.removeEventListener("abort",e)}return new Response(R,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"}})},closeAll(){for(let e of n)e(!0)},get openCount(){return n.size}}}({bus:d,maxSubscriptions:t.maxSubscriptions??1024,keepAliveMs:t.keepAliveMs??15e3,onerror:c});"json"===n&&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 y="reject"===a?void 0:(r=t.keepAliveMs,async(t,a)=>{if("POST"!==t.method.toUpperCase())return p1(405,-32e3,"Method not allowed.");try{let i=await e({era:"legacy",...a?.authInfo!==void 0&&{authInfo:a.authInfo},requestInfo:t}),n=new pQ({sessionIdGenerator:void 0,...void 0!==r&&{keepAliveMs:r},...void 0!==o&&{maxRequestBodySize:o}});await i.connect(n);let s=()=>{n.close().catch(()=>{}),i.close().catch(()=>{})};t.signal?.addEventListener("abort",s,{once:!0});let l=await n.handleRequest(t,{...a?.authInfo!==void 0&&{authInfo:a.authInfo},...a?.parsedBody!==void 0&&{parsedBody:a.parsedBody}});if(null===l.body||"text/event-stream"!==uq(l.headers.get("content-type")))return s(),l;let c=l.body.getReader(),u=!1,d=()=>{u||(u=!0,s())},p=new ReadableStream({pull:async e=>{try{let{done:t,value:r}=await c.read();if(t){d(),e.close();return}void 0!==r&&e.enqueue(r)}catch(t){d(),e.error(t)}},cancel:e=>(d(),c.cancel(e).catch(()=>{}))});return new Response(p,{status:l.status,statusText:l.statusText,headers:l.headers})}catch(e){try{c?.(p9(e))}catch{}return p4(p0(a?.parsedBody))}});return{fetch:async(r,a)=>{if(l)throw Error("This MCP handler has been closed");try{return await async function(r,a){let i=a?.authInfo;if("POST"===r.method.toUpperCase()&&!uA(r.headers.get("content-type")))return c(Error("Unsupported Media Type: Content-Type must be application/json")),p1(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");let l=await async function(e,t,r=!0,a=4194304){let i,n=e.method.toUpperCase(),o=t,s=e,l=!1;if("POST"===n){if(void 0===o){let t;r&&(s=e.clone());try{let r=await pX(e,a);if(r.tooLarge)return{step:"body-too-large"};t=r.text}catch{return{step:"unreadable-body"}}try{i=0===t.length?void 0:JSON.parse(t)}catch{l=!0}l||void 0===i||(o=i)}else i=o;if(l||void 0===i)return{step:"no-json-body",forwardRequest:s}}return{step:"classified",outcome:function(e){if("POST"!==(e={...e,...void 0!==e.protocolVersionHeader&&{protocolVersionHeader:ui(e.protocolVersionHeader)},...void 0!==e.mcpMethodHeader&&{mcpMethodHeader:ui(e.mcpMethodHeader)},...void 0!==e.mcpNameHeader&&{mcpNameHeader:ui(e.mcpNameHeader)}}).httpMethod.toUpperCase())return{kind:"legacy",reason:"http-method"};let t=e.body;if(Array.isArray(t)){if(0===t.length)return ut("jsonrpc-shape","empty-batch",400,new cf(ch.InvalidRequest,"Bad Request: empty JSON-RPC batch"),!0);for(let e of t){if(cV(un(e)?e.params:void 0))return ut("jsonrpc-shape","batch-with-modern-element",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC batches may not contain requests for protocol revision 2026-07-28 or later"),!0);if(!(cB(e)||cK(e)||cG(e)||cW(e)))return ut("jsonrpc-shape","batch-with-invalid-element",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC batch contains an invalid message"),!0)}return{kind:"legacy",reason:"batch"}}return cG(t)||cW(t)?{kind:"legacy",reason:"response"}:un(t)&&cB(t)?function(e,t){let r=t.params,a=t.method,i=e.protocolVersionHeader,n=void 0!==i&&i>=lG;if("initialize"===a&&!function(e){if(!cV(e))return!1;let t=cF(e);if(void 0===t||!(t>=lG))return!1;let r=cU(e);return void 0!==r&&0===cH(r).length}(r)){if(n)return ur("initialize-with-modern-header",i,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let e=un(r)&&"string"==typeof r.protocolVersion?r.protocolVersion:void 0;return{kind:"legacy",reason:"initialize",...void 0!==e&&{requestedVersion:e}}}if(cV(r)){let n=cU(r),o=(void 0===n?[]:cH(n))[0];if(void 0!==o)return ut("envelope","envelope-invalid",400,new cf(ch.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${o.key}: ${o.problem}`,{envelope:o}),!0);let s=cF(r);return void 0!==i&&void 0!==s&&i!==s?ur("header-body-version-mismatch",i,`the body envelope names protocol version ${s} but the MCP-Protocol-Version header names ${i}`):void 0!==e.mcpMethodHeader&&e.mcpMethodHeader!==a?ur("method-header-mismatch",e.mcpMethodHeader,`the body names method ${a} but the Mcp-Method header names ${e.mcpMethodHeader}`):{kind:"modern",messageKind:"request",message:t,classification:uo(s)}}if(n){let e=cU(r),t=cH(e??{}).filter(e=>"missing"===e.problem).map(e=>e.key),a=void 0===e?["_meta"]:t.length>0?t:[nH];return ut("envelope","modern-header-without-claim",400,new cf(ch.InvalidParams,`Invalid params: the MCP-Protocol-Version header names protocol revision ${i}, but the request is missing the required per-request envelope key(s): ${a.join(", ")}`,{envelope:{missing:a}}),!0)}return{kind:"legacy",reason:"no-claim",...void 0!==i&&{requestedVersion:i}}}(e,t):un(t)&&cK(t)?function(e,t){let r=t.params,a=t.method,i=e.protocolVersionHeader,n=void 0!==i&&i>=lG;if(cV(r)){let n=cF(r);if(void 0===n){let e=cU(r),t=(void 0===e?[]:cH(e)).find(e=>e.key===nH)??{key:nH,problem:"expected a protocol version string"};return ut("envelope","notification-envelope-invalid",400,new cf(ch.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${t.key}: ${t.problem}`,{envelope:t}),!0)}if(void 0!==i&&i!==n)return ur("notification-header-body-version-mismatch",i,`the notification envelope names protocol version ${n} but the MCP-Protocol-Version header names ${i}`);let o=uo(n);return"modern"===o.era&&void 0!==e.mcpMethodHeader&&e.mcpMethodHeader!==a?ur("notification-method-header-mismatch",e.mcpMethodHeader,`the notification body names method ${a} but the Mcp-Method header names ${e.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:t,classification:o}}return n?void 0!==e.mcpMethodHeader&&e.mcpMethodHeader!==a?ur("notification-method-header-mismatch",e.mcpMethodHeader,`the notification body names method ${a} but the Mcp-Method header names ${e.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:t,classification:{era:"modern",revision:i}}:{kind:"legacy",reason:"notification",...void 0!==i&&{requestedVersion:i}}}(e,t):ut("jsonrpc-shape","invalid-json-rpc-body",400,new cf(ch.InvalidRequest,"Bad Request: the request body is not a valid JSON-RPC message"),!0)}({httpMethod:n,...p5(e),...void 0!==i&&{body:i}}),body:i,parsedBody:o,forwardRequest:s}}(r,a?.parsedBody,!0,o);if("unreadable-body"===l.step)return p1(400,-32700,"Parse error: the request body could not be read");if("body-too-large"===l.step)return p1(413,-32e3,pW(o));if("no-json-body"===l.step)return void 0!==y?y(l.forwardRequest,{...void 0!==i&&{authInfo:i}}):p1(400,-32700,"Parse error: the request body is not valid JSON");let{outcome:d,body:f,parsedBody:v,forwardRequest:_}=l;try{switch(d.kind){case"reject":return c(Error(`Rejected inbound request (${d.cell}): ${d.message}`)),p2(d,p0(f));case"modern":return await async function(r,a,i){var o,l;let d=r.classification.revision;if(void 0===d||!lW.includes(d)){let e=new cv({supported:[...lW],requested:d??"unknown"});return c(e),p1(400,e.code,e.message,e.data,p0(r.message))}let f=function(e,t){if("request"!==t.messageKind)return;let r=t.message.method;if(void 0===e.protocolVersionHeader){let e=t.classification.revision;return ur("version-header-missing","(missing)",void 0===e?"the body carries a modern per-request envelope but the required MCP-Protocol-Version header is absent":`the body envelope names protocol version ${e} but the required MCP-Protocol-Version header is absent`,"standard-header-validation")}if(void 0===e.mcpMethodHeader)return ur("method-header-missing","(missing)",`the body names method ${r} but the required Mcp-Method header is absent`,"standard-header-validation");let a=function(e,t){let r=Object.hasOwn(ua,e)?ua[e]:void 0;if(void 0===r)return;let a=un(t)?t[r]:void 0;return{field:r,value:"string"==typeof a?a:void 0}}(r,t.message.params);if(void 0===a)return;let{field:i,value:n}=a;if(void 0===e.mcpNameHeader){if(void 0===n)return;return ur("name-header-missing","(missing)",`the body carries params.${i}="${n}" but the required Mcp-Name header is absent`,"standard-header-validation")}let o=ui(e.mcpNameHeader),s=c6(o);return void 0===s?ur("name-header-invalid-encoding",o,"the Mcp-Name header carries an invalid Base64 sentinel value","standard-header-validation"):void 0!==n&&s!==n?ur("name-header-mismatch",o,`the body carries params.${i}="${n}" but the Mcp-Name header names "${s}"`,"standard-header-validation"):void 0}({httpMethod:a.method,...p5(a)},r);if(void 0!==f)return c(Error(`Rejected inbound request (${f.cell}): ${f.message}`)),p2(f,p0(r.message));let y="request"===r.messageKind?cU(r.message.params):void 0,v=y?.[nK];if("request"===r.messageKind){let e=Object.hasOwn(lJ,o=r.message.method)?lJ[o]:void 0;if(void 0!==e){let t=lK(e,v);if(void 0!==t){let e=new c_({requiredCapabilities:t});return c(e),p1(ue[e.code]??400,e.code,e.message,e.data,r.message.id)}}}let _=await e({era:"modern",...void 0!==i&&{authInfo:i},requestInfo:a}),b=_ instanceof pz?_.server:_;if(p3(b),"request"===r.messageKind&&"subscriptions/listen"===r.message.method){let e=b.getCapabilities(),t=h(b);return _.close().catch(c),g.serve(r.message,a.signal,e,t)}if("request"===r.messageKind&&"tools/call"===r.message.method&&_ instanceof pz){let e=r.message.params,t="string"==typeof e?.name?e.name:void 0,i=void 0===t?void 0:_.toolInputSchemaJson(t);if(void 0!==i){let t=c1(i);if(void 0!==t.declarations&&t.declarations.length>0){let i=function(e,t,r){for(let a of e){let e=`Mcp-Param-${a.headerName}`,i=r.get(e),n=function(e,t){let r=e;for(let e of t){if(null===r||"object"!=typeof r)return;r=r[e]}return r}(t,a.path);if(null==n)continue;let o=function(e){if("string"==typeof e)return e;if("boolean"==typeof e)return e?"true":"false";if("number"==typeof e){if(!Number.isFinite(e)||Number.isInteger(e)&&!Number.isSafeInteger(e))return;return String(e)}}(n);if(void 0===o)continue;if(null===i)return c7("param-header-missing",e,`the body carries ${c4(a.path)}=${JSON.stringify(n)} but the ${e} header is absent`);let s=c6(i);if(void 0===s)return c7("param-header-invalid-encoding",e,`the ${e} header carries an invalid Base64 sentinel value`);if(!(("integer"===a.type||"number"===a.type)&&c5.test(s)&&"number"==typeof n?Number(s)===n:s===o))return c7("param-header-mismatch",e,`the ${e} header decodes to ${JSON.stringify(s)} but the body carries ${c4(a.path)}=${JSON.stringify(n)}`)}}(t.declarations,e?.arguments,a.headers);if(void 0!==i)return _.close().catch(c),c(Error(`Rejected inbound request (${i.cell}): ${i.message}`)),p2(i,r.message.id)}}}if("request"===r.messageKind&&_ instanceof pz)try{let e=await pT([r.message],i,e=>_.resolveScopeChallenge(e));if(void 0!==e)return _.close().catch(c),pO(e,pj(i))}catch(e){return _.close().catch(c),c(p9(e)),p4(r.message.id)}p3(b),u(b,d),m(b,lW),void 0!==y&&(l={clientInfo:y[nJ],clientCapabilities:v},p(b,l));let S=b.onclose;s.add(b);let $=()=>{s.delete(b),b.onclose===$&&(b.onclose=S),S?.()};b.onclose=$;try{let e=await async function(e,t,r){let a=new px({classification:r.classification,...void 0!==r.responseMode&&{responseMode:r.responseMode},...void 0!==r.keepAliveMs&&{keepAliveMs:r.keepAliveMs}});return await e.connect(a),a.handleMessage(t,{...void 0!==r.request&&{request:r.request},...void 0!==r.authInfo&&{authInfo:r.authInfo}})}(_,r.message,{classification:r.classification,request:a,...void 0!==i&&{authInfo:i},...void 0!==n&&{responseMode:n},...void 0!==t.keepAliveMs&&{keepAliveMs:t.keepAliveMs}});return"notification"===r.messageKind&&queueMicrotask(()=>void b.close().catch(()=>{})),e}catch(e){if(e instanceof lH&&e.code===lF.ConnectionClosed)return new Response(null,{status:499});return await b.close().catch(()=>{}),s.delete(b),c(p9(e)),p4(p0(r.message))}}(d,r,i);case"legacy":return await async function(e,t,r,a){if(void 0!==y)return y(t,{...void 0!==r&&{authInfo:r},...void 0!==a&&{parsedBody:a}});let i=function(e,t){switch(e.reason){case"http-method":return ut("http-method","modern-only-method-not-allowed",405,new cf(-32e3,"Method not allowed."),!0);case"batch":return ut("jsonrpc-shape","modern-only-batch-not-supported",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC batches are not supported by this endpoint"),!0);case"response":return ut("jsonrpc-shape","modern-only-response-post",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"),!0);case"notification":return;case"initialize":case"no-claim":{let r=e.requestedVersion;return ut("era-classification","modern-only-missing-envelope",400,void 0===r?new cf(ch.UnsupportedProtocolVersion,"Unsupported protocol version: the request did not name a protocol version",{supported:[...t]}):new cv({supported:[...t],requested:r}),!0)}}}(e,lW);return void 0===i?new Response(null,{status:202}):(c(Error(`Rejected 2025-era request on a modern-only endpoint (${i.cell}): ${i.message}`)),p2(i,p0(a)))}(d,_,i,v)}}catch(e){return c(p9(e)),p4(p0(f))}}(r,a)}catch(e){return c(p9(e)),p4(p0(a?.parsedBody))}},notify:f,bus:d,close:async()=>{l=!0,g.closeAll();let e=[...s].map(e=>e.close().catch(()=>{}));s.clear(),await Promise.all(e)}}}(async function(){let e=function(){let{instructions:e,...t}=fF;return new pz(t,{instructions:e,cacheHints:"u"<typeof CACHE_HINTS_CONFIG?void 0:CACHE_HINTS_CONFIG})}(),t=async function(){let{toolModules:e,skippedTools:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw fM(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw fM(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default tool handler."}}:{skipped:!1,path:e,toolModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.toolModule)}return{toolModules:t,skippedTools:r}}(fZ);return fL(t),e}(),r=async function(){let{promptModules:e,skippedPrompts:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw fE(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw fE(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default prompt handler."}}:{skipped:!1,path:e,promptModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.promptModule)}return{promptModules:t,skippedPrompts:r}}(fD);return fT(t),e}(),a=async function(){let{resourceModules:e,skippedResources:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw fj(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw fj(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default resource handler."}}:{skipped:!1,path:e,resourceModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.resourceModule)}return{resourceModules:t,skippedResources:r}}(fU);return fO(t),e}(),[n,o,s]=await Promise.all([t,r,a]);return async function(e,t,r,a){let n=await INJECTED_MIDDLEWARE?.(),o=function(e){if(void 0===e)return[];let t=Array.isArray(e)?[...e]:[e];if(!t.every(e=>"function"==typeof e))throw Error("src/middleware.ts must export mcp as a function or an array of functions");return t}(n?.mcp),s=function(e){if(void 0!==e){if("function"!=typeof e)throw Error("src/middleware.ts must export authorize as a function");return e}}(n?.authorize),l="u">typeof OBSERVABILITY_CONFIG&&OBSERVABILITY_CONFIG.enabled?function(e=e=>console.error(e)){let t=new Map,r=[];function a(t){try{e(JSON.stringify({"@timestamp":new Date().toISOString(),...t}))}catch{}}return{middleware:async(e,i)=>{let n,o,s;if("tools/call"!==e.method&&"prompts/get"!==e.method&&"resources/read"!==e.method)return i();try{o=performance.now(),n={log:{level:"info"},...fP(e._meta?.traceparent)??fP(e.http?.headers.traceparent)??{},transaction:{id:crypto.randomUUID()},...e.http?{http:{request:{id:e.http.id}}}:{},xmcp:{method:e.method,component:"resources/read"===e.method?function(e){try{let a=new URL(e).href;return t.get(a)??r.find(({template:e})=>e.uriTemplate.match(a))?.name??"unknown"}catch{return"unknown"}}(e.params.uri):e.params.name}}}catch{return i()}a({...n,event:{kind:"event",category:["api"],type:["start"],action:"execution.start"}});let l="unknown";try{let t=await i();try{l=e.signal.aborted?"cancelled":cY(t)?"input_required":"isError"in t&&!0===t.isError?"failure":"success","failure"===l&&(s={message:"Operation returned an error result"})}catch{}return t}catch(t){throw s={message:"cancelled"==(l=e.signal.aborted?"cancelled":"failure")?"Operation cancelled":"Operation threw an exception"},t}finally{try{a({...n,log:{level:"failure"===l?"error":"info"},event:{kind:"event",category:["api"],type:["end"],action:"execution.end",duration:Math.round((performance.now()-o)*1e6),outcome:"success"===l?"success":"failure"===l?"failure":"unknown"},xmcp:{...n.xmcp,status:l},...s?{error:s}:{}})}catch{}}},registerResource(e,a){try{"string"==typeof a?t.set(new URL(a).href,e):r.push({name:e,template:a})}catch{}}}}():void 0;l&&o.unshift(l.middleware),mc.clear();let c="u"<typeof COMPONENTS_CONFIG?void 0:COMPONENTS_CONFIG;return!function(e,t,r,a){let i=e.server,n=i.setRequestHandler,o=a?{tools:new Map,prompts:new Map,resources:new Map,templates:new Map,uiOwners:new Map}:void 0,s=a&&o?function(e,t){let r=async(t,r,a)=>!r||await e(t,r,a)===!0;async function a(e,t,a){if(!Array.isArray(t))return t;let i=await Promise.all(t.map(t=>r(e,a(t),"list")));return t.filter((e,t)=>i[t])}return async(e,i)=>{switch(e.method){case"tools/call":{let{name:a}=e.params;if(!await r(e,t.tools.get(a),"call"))throw new cf(ch.InvalidParams,`Tool ${a} not found`);return i()}case"prompts/get":{let{name:a}=e.params;if(!await r(e,t.prompts.get(a),"get"))throw new cf(ch.InvalidParams,`Prompt ${a} not found`);return i()}case"resources/read":{let{uri:a}=e.params;if(!await r(e,mh(t,a),"read"))throw new cg(a);return i()}case"completion/complete":{let{ref:a}=e.params,n="ref/prompt"===a.type?t.prompts.get(a.name):[...t.templates.values()].find(({component:e})=>e.uriTemplate===a.uri)?.component??t.uiOwners.get(a.uri)??t.resources.get(a.uri);if(!await r(e,n,"complete"))throw new cf(ch.InvalidParams,"ref/prompt"===a.type?`Prompt ${a.name} not found`:`Resource template ${a.uri} not found`);return i()}case"tools/list":{let r=await i();return{...r,tools:await a(e,r.tools,e=>t.tools.get(e.name))}}case"prompts/list":{let r=await i();return{...r,prompts:await a(e,r.prompts,e=>t.prompts.get(e.name))}}case"resources/list":{let r=await i();return{...r,resources:await a(e,r.resources,e=>mh(t,e.uri,!0))}}case"resources/templates/list":{let r=await i();return{...r,resourceTemplates:await a(e,r.resourceTemplates,e=>t.templates.get(e.name)?.component)}}default:return i()}}}(a,o):void 0,l=fg(s?[s,...t]:t),c=s?fg([s]):void 0;i.setRequestHandler=(e,...t)=>{if(1===t.length&&"function"==typeof t[0]){let r=t[0];fv.has(e)?t[0]=(e,t)=>l({method:e.method,params:e.params??{}},t,()=>r(e,t)):"tools/call"===e&&c&&o&&(t[0]=(e,t)=>{let a=o.tools.get(e.params.name);return a?c({method:"tools/call",params:{name:e.params.name,arguments:e.params.arguments??{}},tool:{metadata:a.metadata}},t,()=>r(e,t)):r(e,t)})}Reflect.apply(n,i,[e,...t])};try{if(o){let t=async(e,t,r)=>{let i=o.resources.get(t);return!i||await a(e,i,r)===!0},i={registerTool:e.registerTool,registerPrompt:e.registerPrompt,registerResource:e.registerResource};e.registerTool=(t,r,...a)=>{let n=fy({name:t,description:r.description??"",annotations:r.annotations,icons:r.icons,tags:mm(r._meta),_meta:r._meta});return o.tools.set(t,Object.freeze({type:"tool",name:t,metadata:n})),Reflect.apply(i.registerTool,e,[t,r,...a])},e.registerPrompt=(t,r,...a)=>{let n=fy({name:t,title:r.title,description:r.description,icons:r.icons,tags:mm(r._meta),_meta:r._meta});return o.prompts.set(t,Object.freeze({type:"prompt",name:t,metadata:n})),Reflect.apply(i.registerPrompt,e,[t,r,...a])},e.registerResource=(t,r,a,...n)=>{let s=fy({name:t,title:a.title,description:a.description,icons:a.icons,mimeType:a.mimeType,tags:mm(a._meta),_meta:a._meta});if("string"==typeof r)o.resources.set(r,Object.freeze({type:"resource",name:t,uri:r,metadata:s}));else{let e=r.uriTemplate.toString();o.templates.set(t,{component:Object.freeze({type:"resourceTemplate",name:t,uriTemplate:e,metadata:s}),template:r})}return Reflect.apply(i.registerResource,e,[t,r,a,...n])};try{r(t)}finally{Object.assign(e,i)}for(let[e,t]of mc.getAll()){let r=o.tools.get(e);r&&o.uiOwners.set(t.uri,r)}}else r()}finally{i.setRequestHandler=n}}(e,o,n=>{var s,u;!function(e,t,r=[]){t.forEach((t,a)=>{var i,n;let o,s,l,c,u={name:fR(a),description:"No description provided"},{default:d,metadata:p,schema:m,outputSchema:h}=t;if("object"==typeof p&&null!==p&&Object.assign(u,p),!1===u.enabled)return;if("function"==typeof d&&"__x402"in d){let e=global.__XMCP_X402_REGISTRY;e&&e.set(u.name,d.__x402)}let f={};if(fl(m)?(!function(e,t){let{type:r}=fc(e,"draft-2020-12","input");if(void 0!==r&&"object"!==r)throw Error(`Invalid schema for tool "${t}": tool input schemas must describe an object, got JSON Schema type ${JSON.stringify(r)}.`)}(m,u.name),f=m):fw(m)?f=m:null!=m&&console.warn(`Invalid schema for tool "${u.name}" at ${a}. Expected a zod schema or Record<string, z.ZodType>`),null!=h)if(fl(h))o=h;else if(fw(h))o=h;else throw Error(`Invalid outputSchema for tool "${u.name}" at ${a}. Expected a zod schema or Record<string, z.ZodType>`);u.annotations={...u.annotations??{}},void 0===u.annotations.title&&(u.annotations.title=u.name),u._meta={...ml(u)._meta};let g=f_(a),y=!!(i=u._meta)&&"object"==typeof i&&"ui"in i&&"object"==typeof i.ui||g,v=u._meta;if(y){let e=`ui://app/${u.name}.html`;u._meta.ui||(u._meta.ui={}),u._meta.ui.resourceUri||(u._meta.ui.resourceUri=e);let t=function(e){let t={},r={};if(e.ui&&"object"==typeof e.ui){let a=e.ui,i={},n={};for(let[e,t]of Object.entries(a))fS.includes(e)?i[e]=t:f$.includes(e)?n[e]=t:i[e]=t;Object.keys(i).length>0&&(t.ui=i),Object.keys(n).length>0&&(r.ui=n)}for(let[r,a]of Object.entries(e))"ui"!==r&&(t[r]=a);return{toolMeta:t,resourceMeta:r}}(v);v=t.toolMeta;let r=t.resourceMeta;r.ui=r.ui||{},r.ui.csp=r.ui.csp||{},r.ui.csp.resourceDomains=r.ui.csp.resourceDomains||[],r.ui.csp.resourceDomains.includes("https://esm.sh")||r.ui.csp.resourceDomains.push("https://esm.sh"),mc.add(u.name,{name:u.name,uri:e,handler:d,mimeType:"text/html;profile=mcp-app",_meta:r,toolPath:g?a:void 0})}let _=fb(v),b=y?_:void 0;s=f_(a)&&y?async(e,t)=>({content:[{type:"text",text:""}],_meta:b,structuredContent:{args:e}}):function(e,t,r,a="unknown-tool"){return async(i,n)=>{let o,s,l=e(i,(o=ff(n),s=function(e){if(!e)return;let t={};return e.headers.forEach((e,r)=>{t[r]=e}),t}(n.http?.req),{signal:n.mcpReq.signal,authInfo:n.http?.authInfo,sessionId:n.sessionId,_meta:n.mcpReq._meta,requestId:n.mcpReq.id,requestInfo:s?{headers:s}:void 0,clientInfo:o,sendNotification:e=>n.mcpReq.notify(e),sendRequest:(e,t,r)=>n.mcpReq.send(e,t,r),elicit:(e,t)=>(async function(e,t,r){let a=function(e){let t=e.mode??"form";if("url"===t)return function(e){let t;mx(e,"Elicitation request must be a plain object."),mk(e,mv,"URL elicitation"),mP(e.message,"URL elicitation requires a string message."),mE(e.elicitationId,"URL elicitation requires a non-empty elicitationId."),mE(e.url,"URL elicitation requires a non-empty URL.");try{t=new URL(e.url)}catch{throw Error("URL elicitation requires a valid http or https URL.")}if("http:"!==t.protocol&&"https:"!==t.protocol)throw Error("URL elicitation requires a valid http or https URL.")}(e),e;if("form"!==t)throw Error(`Unsupported elicitation mode "${String(e.mode)}". Expected "form" or "url".`);return function(e){mx(e,"Elicitation request must be a plain object."),mk(e,my,"Form elicitation"),mP(e.message,"Form elicitation requires a string message.");let t=e.requestedSchema;if(mx(t,"Form elicitation requires a flat object schema."),mk(t,m_,"Form elicitation schema"),"object"!==t.type)throw Error('Form elicitation schema must use type "object".');for(let[e,r]of(mx(t.properties,"Form elicitation schema requires a properties object."),Object.entries(t.properties)))!function(e,t){if(mx(t,`Form elicitation field "${e}" must be a plain object.`),mT(t.title,`Form elicitation field "${e}" title must be a string.`),mT(t.description,`Form elicitation field "${e}" description must be a string.`),"string"===t.type&&"enum"in t){var r,a;if(mk(t,mS,`Form elicitation field "${e}"`),mO(t.enum,`Form elicitation field "${e}" enum values must be strings.`),r=t.enumNames,a=`Form elicitation field "${e}" enumNames must be strings.`,void 0!==r&&mO(r,a),void 0!==t.enumNames&&t.enumNames.length!==t.enum.length)throw Error(`Form elicitation field "${e}" enumNames length must match enum length.`);if(mT(t.default,`Form elicitation field "${e}" default must be a string.`),void 0!==t.default&&!t.enum.includes(t.default))throw Error(`Form elicitation field "${e}" default must be one of its enum values.`);return}if("string"===t.type&&!("enum"in t)){mk(t,mb,`Form elicitation field "${e}"`),mj(t.minLength,`Form elicitation field "${e}" minLength must be a number.`),mj(t.maxLength,`Form elicitation field "${e}" maxLength must be a number.`),mT(t.default,`Form elicitation field "${e}" default must be a string.`);let r=t.format;if(mT(r,`Form elicitation field "${e}" format must be a string.`),void 0!==r&&!mR.has(r))throw Error(`Form elicitation field "${e}" format must be one of: ${Array.from(mR).join(", ")}.`);return}if("boolean"===t.type){if(mk(t,m$,`Form elicitation field "${e}"`),void 0!==t.default&&"boolean"!=typeof t.default)throw Error(`Form elicitation field "${e}" default must be a boolean.`);return}if("number"===t.type||"integer"===t.type){mk(t,mw,`Form elicitation field "${e}"`),mj(t.minimum,`Form elicitation field "${e}" minimum must be a number.`),mj(t.maximum,`Form elicitation field "${e}" maximum must be a number.`),mj(t.default,`Form elicitation field "${e}" default must be a number.`);return}throw Error(`Form elicitation field "${e}" uses unsupported type "${String(t.type)}". Supported types are string, boolean, number, integer, and string enums.`)}(e,r);if(void 0!==t.required){if(!Array.isArray(t.required)||t.required.some(e=>"string"!=typeof e))throw Error("Form elicitation schema required fields must be a string array.");for(let e of t.required)if(!(e in t.properties))throw Error(`Form elicitation schema required field "${e}" is not defined in properties.`)}}(e),{...e,mode:"form"}}(t);try{let t=await e.mcpReq.elicitInput(a,r);return{...t,content:t.content??void 0}}catch(e){if(e instanceof lH&&e.code===lF.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 e}})(n,e,t),sample:(e,t)=>(async function(e,t,r){let a=function(e){mq(e,"Sampling request must be a plain object.");let t=Object.keys(e),r=t.filter(e=>mI.has(e));if(r.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${r.join(", ")}.`);let a=t.filter(e=>!mC.has(e));if(a.length>0)throw Error(`Sampling request includes unsupported key(s): ${a.join(", ")}.`);if(!Array.isArray(e.messages)||0===e.messages.length)throw Error("Sampling requires at least one message.");for(let[t,r]of e.messages.entries())!function(e,t){if(mq(t,`Sampling message at index ${e} must be a plain object.`),"user"!==t.role&&"assistant"!==t.role)throw Error(`Sampling message at index ${e} requires role "user" or "assistant".`);let r=t.content;mq(r,`Sampling message at index ${e} requires a content object.`);let a=r.type;if("string"!=typeof a||!mN.has(a))throw Error(`Sampling message at index ${e} uses unsupported content type "${String(a)}". Supported types are text, image, and audio.`);if("text"===a&&"string"!=typeof r.text)throw Error(`Sampling message at index ${e} requires string text content.`);if(("image"===a||"audio"===a)&&("string"!=typeof r.data||"string"!=typeof r.mimeType))throw Error(`Sampling message at index ${e} requires base64 data and a mimeType.`)}(t,r);if("number"!=typeof e.maxTokens)throw Error("Sampling requires a numeric maxTokens.");return e}(t);try{return await e.mcpReq.requestSampling(a,r)}catch(e){if(e instanceof lH&&e.code===lF.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 e}})(n,e,t),inputResponses:n.mcpReq.inputResponses,requestState:n.mcpReq.requestState}));if(l instanceof Promise&&(l=await l),cY(l))return l;if(r&&fl(r)&&void 0!==l&&!fm(l)){if(await fp(l,r,a,"returned data that does not match outputSchema"),"string"==typeof l||"number"==typeof l)return{content:[{type:"text",text:`${l}`}],structuredContent:l};l={structuredContent:l}}if("string"==typeof l||"number"==typeof l){if(r&&!fl(r)){let e=Object.entries(r);if(1===e.length){let[t,r]=e[0];try{return r.parse(l),{content:[{type:"text",text:"number"==typeof l?`${l}`:l}],structuredContent:{[t]:l}}}catch{}}}return fh(t)?{content:[{type:"text",text:""}],structuredContent:{args:i},_meta:t}:{content:[{type:"text",text:"number"==typeof l?`${l}`:l}]}}if(r&&l&&"object"==typeof l&&!Array.isArray(l)&&!fm(l)&&(await fp(l,r,a,"returned data that does not match outputSchema"),l={structuredContent:l}),l&&"object"==typeof l&&"_meta"in l&&!("content"in l)&&!("structuredContent"in l)){let e=l._meta;if(fh(e))return{content:[{type:"text",text:""}],_meta:e}}if(!l||"object"!=typeof l){let e=null===l?"null":typeof l,t=void 0===l?"undefined":null===l?"null":"object"==typeof l?JSON.stringify(l,null,2):String(l);throw Error(`Tool handler must return a CallToolResult, string, or number. Got ${e}: ${t}
94
94
 
95
95
  Expected CallToolResult format:
96
96
  {
@@ -119,7 +119,7 @@ Or for widget metadata only:
119
119
  _meta: {
120
120
  "ui/...": ...
121
121
  }
122
- }`)}let c="content"in l&&Array.isArray(l.content),u="structuredContent"in l,d="isError"in l&&!0===l.isError;if(!c&&!u&&!d){let e=JSON.stringify(l,null,2);throw Error(`Tool handler must return at least 'content' or 'structuredContent'. Got: ${e}
122
+ }`)}let c="content"in l&&Array.isArray(l.content),u="structuredContent"in l&&void 0!==l.structuredContent,d="isError"in l&&!0===l.isError;if(!c&&!u&&!d){let e=JSON.stringify(l,null,2);throw Error(`Tool handler must return at least 'content' or 'structuredContent'. Got: ${e}
123
123
 
124
124
  Expected CallToolResult format:
125
125
  {
@@ -140,7 +140,7 @@ Or both for backwards compatibility:
140
140
  {
141
141
  content: [{ type: "text", text: "fallback" }],
142
142
  structuredContent: { your: "data" }
143
- }`)}if(d&&!c&&!u){let{isError:e,...t}=l,r=Object.keys(t).length>0?`Tool execution failed: ${JSON.stringify(t)}`:"Tool execution failed";l.content=[{type:"text",text:r}],c=!0}if(r&&u&&!d&&mN(l.structuredContent,r,a,"returned structuredContent that does not match outputSchema"),!c&&u&&(l.content=[{type:"text",text:JSON.stringify(l.structuredContent)}],c=!0),c)for(let e=0;e<l.content.length;e++){let t=l.content[e],r=mI(t);if(!r.valid)throw Error(`Invalid content item at index ${e}: ${r.error}
143
+ }`)}if(d&&!c&&!u){let{isError:e,...t}=l,r=Object.keys(t).length>0?`Tool execution failed: ${JSON.stringify(t)}`:"Tool execution failed";l.content=[{type:"text",text:r}],c=!0}if(r&&u&&!d&&await fp(l.structuredContent,r,a,"returned structuredContent that does not match outputSchema"),!c&&u&&(l.content=[{type:"text",text:JSON.stringify(l.structuredContent)}],c=!0),c)for(let e=0;e<l.content.length;e++){let t=l.content[e],r=mz(t);if(!r.valid)throw Error(`Invalid content item at index ${e}: ${r.error}
144
144
 
145
145
  Content item: ${JSON.stringify(t,null,2)}
146
146
 
@@ -149,15 +149,7 @@ Expected content formats:
149
149
  - Image: { type: "image", data: "base64data", mimeType: "image/jpeg" }
150
150
  - Audio: { type: "audio", data: "base64data", mimeType: "audio/mpeg" }
151
151
  - Resource: { type: "resource_link", name: "name", uri: "uri" }
152
- All content types support an optional "_meta" object property`)}if(u){let e=l.structuredContent;if(null===e||"object"!=typeof e||Array.isArray(e)){let t=Array.isArray(e)?"array":typeof e;throw Error(`'structuredContent' must be a plain object (not an array or primitive). Got ${t}: ${JSON.stringify(e,null,2)}
153
-
154
- Expected format:
155
- {
156
- structuredContent: {
157
- key: "value",
158
- nested: { data: "here" }
159
- }
160
- }`)}}return l}}(d,b,o,u.name);let S={title:u.annotations?.title,description:u.description,inputSchema:fu(f),outputSchema:o?fu(o,{strict:!0}):void 0,annotations:u.annotations,icons:u.icons,_meta:_};e.registerTool(u.name,S,(n={name:u.name,description:S.description,annotations:S.annotations,icons:S.icons,tags:u.tags,_meta:S._meta},l=mz(r),c=Object.freeze({metadata:function e(t,r=new WeakMap){if(null===t||"object"!=typeof t)return t;let a=Object.getPrototypeOf(t);if(!Array.isArray(t)&&a!==Object.prototype&&null!==a)return t;if(r.has(t))return r.get(t);let i=Array.isArray(t)?[]:Object.create(a);for(let[a,n]of(r.set(t,i),Object.entries(t)))Object.defineProperty(i,a,{value:e(n,r),enumerable:!0,configurable:!0,writable:!0});return Object.freeze(i)}(n)}),(e,t)=>l({method:"tools/call",params:{name:c.metadata.name,arguments:e},tool:c},t,()=>s(e,t))))})}(e,fy(t,l),o),fy(r,l).forEach((t,r)=>{let a=ff(r),i={name:a,title:a,description:"No description provided"},n={},{default:o,metadata:s,schema:l}=t;if("object"==typeof s&&null!==s&&Object.assign(i,s),!1===i.enabled)return;let c=function(e,t="assistant"){return async(r,a)=>{let i,n=e(r,a);if(n instanceof Promise&&(n=await n),Array.isArray(n)||null!==n&&"object"==typeof n&&"messages"in n){let e=Array.isArray(n)?{messages:n}:n,t=await uR.GetPromptResult["~standard"].validate(e);if(t.issues){let e=t.issues.map(e=>{let t=e.path?.map(e=>"object"==typeof e?e.key:e).join(".");return`${t||"result"}: ${e.message}`});throw Error(`Invalid prompt result: ${e.join("; ")}`)}return e}if("string"==typeof n||"number"==typeof n)i={type:"text",text:"number"==typeof n?`${n}`:n};else{let e=mI(n);if(e.valid)i=n;else{let t=null===n?"null":typeof n,r=void 0===n?"undefined":null===n?"null":"object"==typeof n?JSON.stringify(n,null,2):String(n);throw Error(`Prompt handler must return a PromptContent object, string, number, PromptMessage[], or GetPromptResult. Got ${t}: ${r}
152
+ All content types support an optional "_meta" object property`)}return l}}(d,b,o,u.name);let S={title:u.annotations?.title,description:u.description,inputSchema:fd(f),outputSchema:o?fd(o,{strict:!0}):void 0,annotations:u.annotations,icons:u.icons,_meta:_};e.registerTool(u.name,S,(n={name:u.name,description:S.description,annotations:S.annotations,icons:S.icons,tags:u.tags,_meta:S._meta},l=fg(r,!0),c=Object.freeze({metadata:fy(n)}),(e,t)=>l({method:"tools/call",params:{name:c.metadata.name,arguments:e},tool:c},t,()=>s(e,t))))})}(e,fx(t,c),o),fx(r,c).forEach((t,r)=>{let a=fR(r),i={name:a,title:a,description:"No description provided"},n={},{default:o,metadata:s,schema:l}=t;if("object"==typeof s&&null!==s&&Object.assign(i,s),!1===i.enabled)return;let c=function(e,t="assistant"){return async(r,a)=>{let i,n=e(r,a);if(n instanceof Promise&&(n=await n),Array.isArray(n)||null!==n&&"object"==typeof n&&"messages"in n){let e=Array.isArray(n)?{messages:n}:n,t=await uR.GetPromptResult["~standard"].validate(e);if(t.issues){let e=t.issues.map(e=>{let t=e.path?.map(e=>"object"==typeof e?e.key:e).join(".");return`${t||"result"}: ${e.message}`});throw Error(`Invalid prompt result: ${e.join("; ")}`)}return e}if("string"==typeof n||"number"==typeof n)i={type:"text",text:"number"==typeof n?`${n}`:n};else{let e=mz(n);if(e.valid)i=n;else{let t=null===n?"null":typeof n,r=void 0===n?"undefined":null===n?"null":"object"==typeof n?JSON.stringify(n,null,2):String(n);throw Error(`Prompt handler must return a PromptContent object, string, number, PromptMessage[], or GetPromptResult. Got ${t}: ${r}
161
153
 
162
154
  Validation error: ${e.error}
163
155
 
@@ -170,7 +162,7 @@ Expected formats:
170
162
  - Image content: { type: "image", data: "base64data", mimeType: "image/jpeg" }
171
163
  - Audio content: { type: "audio", data: "base64data", mimeType: "audio/mpeg" }
172
164
  - Resource link: { type: "resource_link", name: "resource name", uri: "resource://uri" }
173
- - All content types support an optional "_meta" object property`)}}if("user"!==t&&"assistant"!==t)throw Error(`Invalid role: ${t}`);return{messages:[{role:t,content:i}]}}}(o,i.role||"assistant");fh(l)?Object.assign(n,l):null!=l&&console.warn(`Invalid schema for prompt "${i.name}" at ${r}. Expected Record<string, z.ZodType>`),e.registerPrompt(i.name,{title:i.title,description:i.description,icons:i.icons,_meta:ml(i)._meta,argsSchema:fu(n)},c)}),n=fy(a,l),c=s?.registerResource,[...mc.getAll()].forEach(([t,r])=>{let a=r.mimeType||"text/html;profile=mcp-app",n=r?._meta?fd(r._meta):void 0,o={name:r.name,description:`Auto-generated resource for ${r.name} tool`,mimeType:r.mimeType,_meta:n};c?.(r.name,r.uri),e.registerResource(r.name,r.uri,o,async(e,t)=>{if(r.mimeType&&r.toolPath)try{var n;let e,t,o=(n=r.toolPath,IS_CLOUDFLARE?function(e){let{normalizedPath:t,baseName:r}=f$(e),a=5381;for(let e=0;e<t.length;e++)a=Math.imul(a,33)+t.charCodeAt(e)>>>0;let i=a.toString(16).slice(0,6).padStart(6,"0");return`${r}_${i}`}(n):function(e){let{normalizedPath:t,baseName:r}=f$(e),a=i(6982).createHash("md5").update(t).digest("hex").slice(0,6);return`${r}_${a}`}(n)),s=function(e){if(INJECTED_CLIENT_BUNDLES)return INJECTED_CLIENT_BUNDLES[e]||null;if(!IS_CLOUDFLARE)try{let t=i(9896),r=i(6928);for(let a of[r.join(process.cwd(),"dist","client"),r.join(process.cwd(),"client")]){let i=r.join(a,`${e}.bundle.js`),n=r.join(a,`${e}.bundle.css`);if(t.existsSync(i)){let e,r=t.readFileSync(i,"utf-8");return t.existsSync(n)&&(e=t.readFileSync(n,"utf-8")),{js:r,css:e}}}}catch{}return null}(o);if(!s)throw Error(`React client bundle not found for "${r.name}" (bundle: "${o}").
165
+ - All content types support an optional "_meta" object property`)}}if("user"!==t&&"assistant"!==t)throw Error(`Invalid role: ${t}`);return{messages:[{role:t,content:i}]}}}(o,i.role||"assistant");fw(l)?Object.assign(n,l):null!=l&&console.warn(`Invalid schema for prompt "${i.name}" at ${r}. Expected Record<string, z.ZodType>`),e.registerPrompt(i.name,{title:i.title,description:i.description,icons:i.icons,_meta:ml(i)._meta,argsSchema:fu(n)},c)}),s=fx(a,c),u=l?.registerResource,[...mc.getAll()].forEach(([t,r])=>{let a=r.mimeType||"text/html;profile=mcp-app",n=r?._meta?fb(r._meta):void 0,o={name:r.name,description:`Auto-generated resource for ${r.name} tool`,mimeType:r.mimeType,_meta:n};u?.(r.name,r.uri),e.registerResource(r.name,r.uri,o,async(e,t)=>{if(r.mimeType&&r.toolPath)try{var n;let e,t,o=(n=r.toolPath,IS_CLOUDFLARE?function(e){let{normalizedPath:t,baseName:r}=fC(e),a=5381;for(let e=0;e<t.length;e++)a=Math.imul(a,33)+t.charCodeAt(e)>>>0;let i=a.toString(16).slice(0,6).padStart(6,"0");return`${r}_${i}`}(n):function(e){let{normalizedPath:t,baseName:r}=fC(e),a=i(6982).createHash("md5").update(t).digest("hex").slice(0,6);return`${r}_${a}`}(n)),s=function(e){if(INJECTED_CLIENT_BUNDLES)return INJECTED_CLIENT_BUNDLES[e]||null;if(!IS_CLOUDFLARE)try{let t=i(9896),r=i(6928);for(let a of[r.join(process.cwd(),"dist","client"),r.join(process.cwd(),"client")]){let i=r.join(a,`${e}.bundle.js`),n=r.join(a,`${e}.bundle.css`);if(t.existsSync(i)){let e,r=t.readFileSync(i,"utf-8");return t.existsSync(n)&&(e=t.readFileSync(n,"utf-8")),{js:r,css:e}}}}catch{}return null}(o);if(!s)throw Error(`React client bundle not found for "${r.name}" (bundle: "${o}").
174
166
  React tool bundles are generated automatically when you run "xmcp build" (or "xmcp dev").
175
167
  Please re-run the build so the framework can regenerate the bundle.`);let l=s.js,c=s.css,u=(e=`
176
168
  <script type="module">
@@ -225,7 +217,7 @@ Please re-run the build so the framework can regenerate the bundle.`);let l=s.js
225
217
  <div id="root"></div>
226
218
  ${e}
227
219
  </body>
228
- </html>`);return{contents:[{uri:r.uri,text:u,mimeType:a,_meta:r._meta}]}}catch(e){throw console.error(`React failed for ${r.name}:`,e),e}let o=r.handler({},t);if(o instanceof Promise&&(o=await o),"string"==typeof o)return{contents:[{uri:r.uri,text:o,mimeType:a,_meta:r._meta}]};if(o&&"object"==typeof o&&"_meta"in o&&!("content"in o))return{contents:[{uri:r.uri,text:"",mimeType:a,_meta:r._meta}]};if(o&&"object"==typeof o&&"content"in o&&Array.isArray(o.content)){let e=o.content.find(e=>"text"===e.type);if(e&&"text"===e.type&&"string"==typeof e.text)return{contents:[{uri:r.uri,text:e.text,mimeType:a,_meta:r._meta}]}}return{contents:[{uri:r.uri,text:"",mimeType:a,_meta:r._meta}]}})}),n.forEach((t,r)=>{let a={name:ff(r),description:"No description provided"},{default:i,metadata:n,schema:o,complete:s}=t;if("object"==typeof n&&null!==n&&Object.assign(a,n),!1===a.enabled)return;let l={};fh(o)?l=o:null!=o&&console.warn(`Invalid schema for resource "${a.name}" at ${r}. Expected Record<string, z.ZodType>`);let u=fw(r);if(!u)return void console.warn(`Skipping resource "${a.name}" at ${r}: Invalid file path format`);let d=u.uriTemplate;a.mimeType&&a.mimeType.includes("html")&&(d=d.endsWith(".html")?d:`${d}.html`);let p=function(e,t,r={}){let a=fw(t);if(!a)throw Error(`Invalid resource file path: ${t}. Must follow (scheme)/path/[param] convention.`);return async(t,i)=>{let n=e(function(e,t,r){let a={},i={};if(0===t.parameters.length)return i;let n=t.uriTemplate.split("://")[1]||"",o=e.split("://")[1]||"",s=n.split("/"),l=o.split("/");for(let e=0;e<s.length&&e<l.length;e++){let t=s[e],r=l[e],i=t.match(/^\{(.+)\}$/);i&&(a[i[1]]=r)}for(let e of t.parameters){let t=a[e],n=r[e];if(void 0===t)throw Error(`Missing required parameter: ${e}`);if(!n){i[e]=t;continue}try{i[e]=n.parse(t)}catch(r){throw Error(`Invalid parameter "${e}": ${t}. Validation error: ${r instanceof Error?r.message:String(r)}`)}}return i}(t.href,a,r),i);if(n instanceof Promise&&(n=await n),cY(n))return n;if("string"==typeof n)return{contents:[{uri:t.href,text:n}]};if(!n||"object"!=typeof n||!Array.isArray(n.contents)){let e=null===n?"null":typeof n,t=void 0===n?"undefined":null===n?"null":"object"==typeof n?JSON.stringify(n,null,2):String(n);throw Error(`Resource handler must return a ReadResourceResult, InputRequiredResult, or string. Got ${e}: ${t}
220
+ </html>`);return{contents:[{uri:r.uri,text:u,mimeType:a,_meta:r._meta}]}}catch(e){throw console.error(`React failed for ${r.name}:`,e),e}let o=r.handler({},t);if(o instanceof Promise&&(o=await o),"string"==typeof o)return{contents:[{uri:r.uri,text:o,mimeType:a,_meta:r._meta}]};if(o&&"object"==typeof o&&"_meta"in o&&!("content"in o))return{contents:[{uri:r.uri,text:"",mimeType:a,_meta:r._meta}]};if(o&&"object"==typeof o&&"content"in o&&Array.isArray(o.content)){let e=o.content.find(e=>"text"===e.type);if(e&&"text"===e.type&&"string"==typeof e.text)return{contents:[{uri:r.uri,text:e.text,mimeType:a,_meta:r._meta}]}}return{contents:[{uri:r.uri,text:"",mimeType:a,_meta:r._meta}]}})}),s.forEach((t,r)=>{let a={name:fR(r),description:"No description provided"},{default:i,metadata:n,schema:o,complete:s}=t;if("object"==typeof n&&null!==n&&Object.assign(a,n),!1===a.enabled)return;let l={};fw(o)?l=o:null!=o&&console.warn(`Invalid schema for resource "${a.name}" at ${r}. Expected Record<string, z.ZodType>`);let c=fI(r);if(!c)return void console.warn(`Skipping resource "${a.name}" at ${r}: Invalid file path format`);let d=c.uriTemplate;a.mimeType&&a.mimeType.includes("html")&&(d=d.endsWith(".html")?d:`${d}.html`);let p=function(e,t,r={}){let a=fI(t);if(!a)throw Error(`Invalid resource file path: ${t}. Must follow (scheme)/path/[param] convention.`);return async(t,i)=>{let n=e(function(e,t,r){let a={},i={};if(0===t.parameters.length)return i;let n=t.uriTemplate.split("://")[1]||"",o=e.split("://")[1]||"",s=n.split("/"),l=o.split("/");for(let e=0;e<s.length&&e<l.length;e++){let t=s[e],r=l[e],i=t.match(/^\{(.+)\}$/);i&&(a[i[1]]=r)}for(let e of t.parameters){let t=a[e],n=r[e];if(void 0===t)throw Error(`Missing required parameter: ${e}`);if(!n){i[e]=t;continue}try{i[e]=n.parse(t)}catch(r){throw Error(`Invalid parameter "${e}": ${t}. Validation error: ${r instanceof Error?r.message:String(r)}`)}}return i}(t.href,a,r),i);if(n instanceof Promise&&(n=await n),cY(n))return n;if("string"==typeof n)return{contents:[{uri:t.href,text:n}]};if(!n||"object"!=typeof n||!Array.isArray(n.contents)){let e=null===n?"null":typeof n,t=void 0===n?"undefined":null===n?"null":"object"==typeof n?JSON.stringify(n,null,2):String(n);throw Error(`Resource handler must return a ReadResourceResult, InputRequiredResult, or string. Got ${e}: ${t}
229
221
 
230
222
  Expected ReadResourceResult format:
231
223
  {
@@ -234,4 +226,4 @@ Expected ReadResourceResult format:
234
226
  { uri: "resource://uri", mimeType: "application/json", text: "json content" },
235
227
  { uri: "resource://uri", blob: base64data }
236
228
  ]
237
- }`)}return n.contents.forEach(e=>{e.uri||(e.uri=t.href)}),n}}(i,r,l);if("direct"===u.type)c?.(a.name,d),e.registerResource(a.name,d,ml(a),p);else{let t=Object.create(null);for(let e of u.parameters)s&&Object.hasOwn(s,e)&&(t[e]=s[e]);let r=new pM(d,{list:void 0,complete:t});c?.(a.name,r),e.registerResource(a.name,r,ml(a),async(e,t,r)=>{let a={};for(let e of u.parameters){let r=t[e],i=l[e];if(void 0===r)throw Error(`Missing required parameter: ${e}. Available variables: ${Object.keys(t)}`);i?a[e]=i.parse(r):a[e]=r}let n=i(a,r);return n instanceof Promise&&(n=await n),"string"==typeof n?{contents:[{uri:e.href,text:n}]}:n})}}),function(e,t,r,a){let i=[...fy(new Map(t.map(e=>[e.uri,{metadata:{name:e.frontmatter.name},skill:e}])),r).values()].map(({skill:e})=>e);if(0===i.length)return;for(let{frontmatter:t,files:r}of i){let i=r[0].uri.slice(0,r[0].uri.lastIndexOf("/")+1);r.forEach(({uri:r,mimeType:n,text:o,blob:s},l)=>{let c=0===l?{mimeType:n,description:t.description}:{mimeType:n},u=0===l?t.name:`${t.name}/${decodeURIComponent(r.slice(i.length))}`,d=void 0!==o?{uri:r,mimeType:n,text:o}:{uri:r,mimeType:n,blob:s??""};a?.(u,r),e.registerResource(u,r,c,()=>({contents:[d]}))})}let n=i.map(fP),o=new Map(n.map(e=>[e.uri,e]));e.server.registerCapabilities({extensions:{"io.modelcontextprotocol/skills":{}}}),e.server.setRequestHandler("skills/list",{params:fk},e=>{let t=e?.cursor===void 0?0:function(e,t){let r=0/0;try{r=Number(atob(e))}catch{}if(!Number.isSafeInteger(r)||r<=0||r>=t)throw new cf(ch.InvalidParams,`Invalid cursor: ${e}`);return r}(e.cursor,n.length),r=t+50;return{skills:n.slice(t,r),...r<n.length?{nextCursor:btoa(String(r))}:{},...fR}}),e.server.setRequestHandler("skills/get",{params:fx},({uri:e})=>{let t=o.get(e);if(!t)throw new cf(ch.InvalidParams,`No skill is served at ${e}`);return{skill:t,...fR}})}(e,fI,l,s?.registerResource)}),e}(r,s,l,c)},{legacy:"stateless",maxSubscriptions:HTTP_CONFIG.maxSubscriptions});async function fA(e,t={}){let r="POST"===e.method?await e.clone().json().catch(()=>void 0):void 0;return ma({id:crypto.randomUUID(),headers:Object.fromEntries(e.headers.entries()),clientInfo:(e=>{for(let t of Array.isArray(e)?e:[e]){let e=mo(t);if(e)return e}})(r)},()=>fq.fetch(e,{parsedBody:r,authInfo:t.authInfo}))}})();var o=n.r;export{o as xmcpHandler};
229
+ }`)}return n.contents.forEach(e=>{e.uri||(e.uri=t.href)}),n}}(i,r,l);if("direct"===c.type)u?.(a.name,d),e.registerResource(a.name,d,ml(a),p);else{let t=Object.create(null);for(let e of c.parameters)s&&Object.hasOwn(s,e)&&(t[e]=s[e]);let r=new pM(d,{list:void 0,complete:t});u?.(a.name,r),e.registerResource(a.name,r,ml(a),async(e,t,r)=>{let a={};for(let e of c.parameters){let r=t[e],i=l[e];if(void 0===r)throw Error(`Missing required parameter: ${e}. Available variables: ${Object.keys(t)}`);i?a[e]=i.parse(r):a[e]=r}let n=i(a,r);return n instanceof Promise&&(n=await n),"string"==typeof n?{contents:[{uri:e.href,text:n}]}:n})}}),function(e,t,r,a,i){let n=[...fx(new Map(t.map(e=>[e.uri,{metadata:{name:e.frontmatter.name},skill:e}])),r).values()].map(({skill:e})=>e);if(0===n.length)return;for(let{frontmatter:t,files:r}of n){let i=r[0].uri.slice(0,r[0].uri.lastIndexOf("/")+1);r.forEach(({uri:r,mimeType:n,text:o,blob:s},l)=>{let c=0===l?{mimeType:n,description:t.description}:{mimeType:n},u=0===l?t.name:`${t.name}/${decodeURIComponent(r.slice(i.length))}`,d=void 0!==o?{uri:r,mimeType:n,text:o}:{uri:r,mimeType:n,blob:s??""};a?.(u,r),e.registerResource(u,r,c,()=>({contents:[d]}))})}let o=n.map(fz),s=new Map(o.map(e=>[e.uri,e]));e.server.registerCapabilities({extensions:{"io.modelcontextprotocol/skills":{}}}),e.server.setRequestHandler("skills/list",{params:fq},(e,t)=>mp(t,ff(t),async()=>{let t=Object.freeze({...md(),method:"skills/list",params:Object.freeze({...e})}),r=i?await Promise.all(o.map(e=>i(t,e.uri,"list"))):void 0,a=r?o.filter((e,t)=>r[t]):o,n=e?.cursor===void 0?0:function(e,t){let r=0/0;try{r=Number(atob(e))}catch{}if(!Number.isSafeInteger(r)||r<=0||r>=t)throw new cf(ch.InvalidParams,`Invalid cursor: ${e}`);return r}(e.cursor,a.length),s=n+50;return{skills:a.slice(n,s),...s<a.length?{nextCursor:btoa(String(s))}:{},...fN}})),e.server.setRequestHandler("skills/get",{params:fA},(e,t)=>mp(t,ff(t),async()=>{let{uri:t}=e,r=s.get(t),a=Object.freeze({...md(),method:"skills/get",params:Object.freeze({...e})});if(!r||i&&!await i(a,t,"read"))throw new cf(ch.InvalidParams,`No skill is served at ${t}`);return{skill:r,...fN}}))}(e,fV,c,l?.registerResource,n)},s),e}(e,n,o,s)},{legacy:"stateless",maxSubscriptions:HTTP_CONFIG.maxSubscriptions});async function fJ(e,t={}){let r="POST"===e.method?await e.clone().json().catch(()=>void 0):void 0;return ma({id:crypto.randomUUID(),headers:Object.fromEntries(e.headers.entries()),clientInfo:(e=>{for(let t of Array.isArray(e)?e:[e]){let e=mo(t);if(e)return e}})(r)},()=>fH.fetch(e,{parsedBody:r,authInfo:t.authInfo}))}})();var o=n.r;export{o as xmcpHandler};