xmcp 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- !function(t,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var a=r();for(var i in a)("object"==typeof exports?exports:t)[i]=a[i]}}(this,()=>(()=>{"use strict";var t={6982(t){t.exports=require("crypto")},9896(t){t.exports=require("fs")},6928(t){t.exports=require("path")}},r={};function a(i){var n=r[i];if(void 0!==n)return n.exports;var o=r[i]={exports:{}};return t[i](o,o.exports,a),o.exports}a.d=(t,r)=>{for(var i in r)a.o(r,i)&&!a.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:r[i]})},a.o=(t,r)=>Object.prototype.hasOwnProperty.call(t,r),a.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{let t,r,n,o,s,l,c,u,d,p,m,h,f,y,g,v,_,b,S,$,w;a.r(i),a.d(i,{xmcpHandler:()=>yo});let R=require("node:crypto");var k,x,P,E,T,j,O,C,I,N,q,A,M,z,L,Z,D=Object.create,U=Object.defineProperty,V=Object.getOwnPropertyDescriptor,F=Object.getOwnPropertyNames,H=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty,B=(t,r)=>()=>(r||t((r={exports:{}}).exports,r),r.exports),K=(t,r,a)=>(a=null!=t?D(H(t)):{},((t,r,a,i)=>{if(r&&"object"==typeof r||"function"==typeof r)for(var n,o=F(r),s=0,l=o.length;s<l;s++)n=o[s],J.call(t,n)||n===a||U(t,n,{get:(t=>r[t]).bind(null,n),enumerable:!(i=V(r,n))||i.enumerable});return t})(!r&&t&&t.__esModule?a:U(a,"default",{value:t,enumerable:!0}),t));let G=new Set(["https://json-schema.org/draft/2020-12/schema","http://json-schema.org/draft/2020-12/schema"]),W=new Set(["https://json-schema.org/draft/2019-09/schema","http://json-schema.org/draft/2019-09/schema"]),Y=new Set(["https://json-schema.org/draft-07/schema","http://json-schema.org/draft-07/schema"]),X=new Set(["https://json-schema.org/draft-06/schema","http://json-schema.org/draft-06/schema"]);function Q(t){let r=Object.values(t).filter(t=>"number"==typeof t);return Object.entries(t).filter(([t,a])=>-1===r.indexOf(+t)).map(([t,r])=>r)}function ee(t,r="|"){return t.map(t=>e$(t)).join(r)}function et(t,r){return"bigint"==typeof r?r.toString():r}class er{constructor(t){this._getter=t,this._value=void 0}get value(){let t=this._getter;return void 0!==t&&(this._value=t(),this._getter=void 0),this._value}}function ea(t){return new er(t)}function ei(t){let r=+!!t.startsWith("^"),a=t.endsWith("$")?t.length-1:t.length;return t.slice(r,a)}let en=Symbol("evaluating");function eo(t,r,a){Object.defineProperty(t,r,{value:a,writable:!0,enumerable:!0,configurable:!0})}function es(t){let r=Object.getOwnPropertyDescriptor(t,"shape");return r?.get?r.get.raw:r?.value}function el(t){return es(t._zod.def)??t._zod.def.shape}function ec(t,r,a){Object.defineProperty(t,r,{get(){let t=a();return eo(this,r,t),t},enumerable:!0,configurable:!0})}function eu(t,r,a){r in t?eo(t,r,a):t[r]=a}function ed(t,r,a,i){let n=el(r);for(let o of a){let a=Object.getOwnPropertyDescriptor(n,o);a.enumerable&&(a.get?ec(t,o,()=>{let t=r._zod.def.shape[o];return i?i(t,o):t}):eu(t,o,i?i(a.value,o):a.value))}}function ep(...t){let r={};for(let a of t)Object.assign(r,Object.getOwnPropertyDescriptors(a));return Object.defineProperties({},r)}let em="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function eh(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}let ef=ea(()=>{if(eK.jitless||"undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return Function(""),!0}catch(t){return!1}});function ey(t){if(!1===eh(t))return!1;let r=t.constructor;if(void 0===r||"function"!=typeof r)return!0;let a=r.prototype;return!1!==eh(a)&&!1!==Object.prototype.hasOwnProperty.call(a,"isPrototypeOf")}function eg(t){return ey(t)?{...t}:Array.isArray(t)?[...t]:t instanceof Map?new Map(t):t instanceof Set?new Set(t):t}let ev=new Set(["string","number","symbol"]);function e_(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function eb(t,r,a){let i=new t._zod.constr(r??t._zod.def);return(!r||a?.parent)&&(i._zod.parent=t),i}function eS(t){if(!t)return{};if("string"==typeof t)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return(delete t.message,"string"==typeof t.error)?{...t,error:()=>t.error}:t}function e$(t){return"bigint"==typeof t?t.toString()+"n":"string"==typeof t?`"${t}"`:`${t}`}let ew={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]},eR={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function ek(t,r){let a=el(t),i=[];for(let t of Reflect.ownKeys(r)){if(!Object.getOwnPropertyDescriptor(a,t)?.enumerable)throw Error(`Unrecognized key: "${String(t)}"`);r[t]&&i.push(t)}return i}function ex(t,r){let a={};ed(a,t,Reflect.ownKeys(el(t)));for(let t of Reflect.ownKeys(r)){let i=Object.getOwnPropertyDescriptor(r,t);i.enumerable&&(i.get?ec(a,t,()=>r[t]):eu(a,t,i.value))}return a}function eP(t,r,a,i="partial"){let n=r._zod.def.checks;if(n&&n.length>0)throw Error(`.${i}() cannot be used on object schemas containing refinements`);let o=a?new Set(ek(r,a)):void 0,s={};return ed(s,r,Reflect.ownKeys(el(r)),t&&((r,a)=>o&&!o.has(a)?r:new t({type:"optional",innerType:r}))),eb(r,ep(r._zod.def,{shape:s,checks:[]}))}function eE(t,r=0){if(!0===t.aborted)return!0;for(let a=r;a<t.issues.length;a++)if(t.issues[a]?.continue!==!0)return!0;return!1}function eT(t,r){return r.map(r=>(r.path??(r.path=[]),r.path.unshift(t),r))}function ej(t){return"string"==typeof t?t:t?.message}function eO(t,r,a){var i;for(let n=r;n<t.length;n++)(i=t[n]).schema??(i.schema=a)}function eC(t,r,a){let i=t.inst?._zod?.traits;i?.has("$ZodType")&&(i.has("$ZodCheck")?t.schema??(t.schema=t.inst):t.schema=t.inst);let n=t.schema!==t.inst?t.schema?._zod.def?.error:void 0,o=t.message?t.message:ej(t.inst?._zod.def?.error?.(t))??ej(n?.(t))??ej(r?.error?.(t))??ej(a.customError?.(t))??ej(a.localeError?.(t))??"Invalid input",s={};for(let r of Object.keys(t))"inst"!==r&&"schema"!==r&&"continue"!==r&&"input"!==r&&"__proto__"!==r&&(s[r]=t[r]);return s.path??(s.path=[]),s.message=o,r?.reportInput&&(s.input=t.input),s}let eI=/[\uD800-\uDBFF]/;function eN(t){let r=t.length;if(!eI.test(t))return r;let a=r;for(let i=0;i<r-1;i++)(64512&t.charCodeAt(i))==55296&&(64512&t.charCodeAt(i+1))==56320&&(a--,i++);return a}function eq(t){return Array.isArray(t)?"array":"string"==typeof t?"string":"unknown"}function eA(...t){let[r,a,i]=t;return"string"==typeof r?{message:r,code:"custom",input:a,inst:i}:{...r}}function eM(t,r,a,i=!0){return Object.defineProperty(t,r,{configurable:!0,writable:!0,enumerable:i,value:a}),a}function ez(t,r){for(let a in t){let i=t[a];Object.defineProperty(r,a,{configurable:!0,enumerable:!0,get(){return eM(this,a,i(this))},set(t){eM(this,a,t)}})}return r}let eL=!1,eZ={configurable:!0,get(){eL=!0}};function eD(r,a,i){let n=Object.getPrototypeOf(r._zod);if(a in n&&t!==r._zod){t=void 0;return}t=r._zod,Object.defineProperty(n,a,{configurable:!0,get(){Object.defineProperty(this,a,eZ);let t=eL;eL=!1;try{let r=i(this);return eL?delete this[a]:Object.defineProperty(this,a,{configurable:!0,writable:!0,value:r}),eL=eL||t,r}catch(r){throw delete this[a],eL=eL||t,r}},set(t){Object.defineProperty(this,a,{configurable:!0,writable:!0,value:t})}})}let eU=Object.freeze({status:"aborted"}),eV={value:void 0,enumerable:!1},eF="captureStackTrace"in Error?Error:null;function eH(t,r,a,i){function n(t){this.def=t,this.constr=u,this.traits=new Set}n.prototype={};let o=a&&new WeakSet;function s(i,s){if(i._zod){if(i._zod.traits.has(t))return}else{eV.value=new n(s);try{Object.defineProperty(i,"_zod",eV)}finally{eV.value=void 0}}if(i._zod.traits.add(t),r(i,s),o){let t=Object.getPrototypeOf(i),r=i._zod.constr.prototype,n=t;for(;n&&n!==r;)n=Object.getPrototypeOf(n);let s=n??t;if(!o.has(s)){o.add(s);for(let t in a){let r=Object.getOwnPropertyDescriptor(a,t);r.get?Object.defineProperty(s,t,{...r,enumerable:!1}):function(t,r,a){Object.defineProperty(t,r,{configurable:!0,get(){return this==null?a:eM(this,r,a.bind(this))},set(t){eM(this,r,t)}})}(s,t,r.value)}}}let l=u.prototype;for(let t in l)Object.prototype.hasOwnProperty.call(l,t)&&(t in i||(i[t]=l[t].bind(i)))}let l=i?.Parent??Object;class c extends l{}function u(t){let r=i?.Parent?function(t){let r=eF;if(r){let a=r.stackTraceLimit;if("number"==typeof a){try{r.stackTraceLimit=0}catch{return eF=null,new t}try{return new t}finally{r.stackTraceLimit=a}}}return new t}(c):this;s(r,t);let a=r._zod.deferred;if(a){for(let t of a)t();r._zod.deferred=void 0}let n=globalThis.__zod_globalConfig?.postProcessor;return n&&n(r),r}return Object.defineProperty(c,"name",{value:t}),Object.defineProperty(u,"init",{value:s}),Object.defineProperty(u,Symbol.hasInstance,{value:r=>!!i?.Parent&&r instanceof i.Parent||r?._zod?.traits?.has(t)}),Object.defineProperty(u,"name",{value:t}),u}class eJ extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class eB extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}(N=globalThis).__zod_globalConfig??(N.__zod_globalConfig={});let eK=globalThis.__zod_globalConfig;function eG(t){return t&&Object.assign(eK,t),eK}class eW extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform"),this.name="ZodCyclicError"}}let eY="~memo",eX=[];function eQ(t){return null!==t&&"object"==typeof t}function e0(t){return t.map(t=>t.path?{...t,path:t.path.slice()}:{...t})}let e1=new WeakMap,e2=[],e9={alloc(t,a,i){let n=r;if(!n)return i;r=void 0;let o={value:i,issues:null};return n.set(a.value,o),e2.push(o),i},guard(t){var r;(r=t._zod).deferred??(r.deferred=[]),t._zod.deferred.push(()=>{let r=t._zod.parse,a=(t,a)=>{var i,n;let o;if("backward"!==a.direction&&(i=a,n=t.value,void 0!==(o=i[eY]?.backEdges)&&eQ(n)&&o.has(n)))throw new eW;return r(t,a)};t._zod.parse=a,t._zod.run===r&&(t._zod.run=a)})},attach(t){var a;let i,n,o,s=!1;(a=t._zod).deferred??(a.deferred=[]),t._zod.deferred.push(()=>{let a=t._zod.parse,l=(c,u)=>{let d;if(void 0===i){let r=function t(r,a,i){var n,o;let s=e1.get(r);if(void 0!==s)return 2*!!s;if(a.has(r))return 2;a.add(r);let l=0,c=r=>{if(2!==l&&r?._zod){let n=t(r,a,i);n>l&&(l=n)}},u=t=>{t>l&&(l=t)},d=r._zod.def;switch(d.type){case"object":{let r=es(d);u(r?((r,n)=>{let o=0;for(let s of Reflect.ownKeys(r)){let l=Object.getOwnPropertyDescriptor(r,s);if(n&&!l.enumerable)continue;let c=l.get?1:l.value?._zod?t(l.value,a,i):0;c>o&&(o=c)}return o})(r,!0):1),c(d.catchall);break}case"array":c(d.element);break;case"tuple":for(let t of d.items)c(t);c(d.rest);break;case"record":case"map":c(d.keyType),c(d.valueType);break;case"set":c(d.valueType);break;case"union":for(let t of d.options)c(t);break;case"intersection":c(d.left),c(d.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":c(d.innerType);break;case"pipe":c(d.in),c(d.out);break;case"function":c(d.input),c(d.output);break;case"lazy":{let n=d._cachedInner??(i?r._zod.innerType:void 0);u(n?t(n,a,!1):1);break}case"template_literal":case"string":case"number":case"int":case"boolean":case"bigint":case"symbol":case"undefined":case"null":case"void":case"never":case"any":case"unknown":case"date":case"nan":case"enum":case"literal":case"file":case"transform":case"custom":break;default:for(let t in d){let r=Object.getOwnPropertyDescriptor(d,t);if(!r||r.get)continue;let a=r.value;if(a&&"object"==typeof a){if(a._zod)c(a);else if(Array.isArray(a))for(let t of a)c(t)}}}return a.delete(r),n=r,1!==(o=l)&&e1.set(n,2===o),o}(t,new Set,!1);if(0===r)return t._zod.parse=a,t._zod.run===l&&(t._zod.run=a),a(c,u);2===r||s?i=!0:s=!0}let p=c.value;if(!eQ(p))return a(c,u);let m=u[eY];if(m||(m={buckets:new WeakMap,backEdges:void 0},u[eY]=m),n===u)d=o;else{var h;let r;(r=(h=m).buckets.get(t))||(r=new WeakMap,h.buckets.set(t,r)),d=r,n=u,o=d}let f=d.get(p);if(f)return c.value=f.value,f.issues?f.issues.length&&c.issues.push(...e0(f.issues)):(c.memo=!0,m.backEdges??(m.backEdges=new WeakSet),m.backEdges.add(f.value)),c;r=d;let y=e2.length,g=a(c,u);r=void 0;let v=e2.length>y?e2.pop():void 0;return g instanceof Promise?g.then(t=>(v&&(v.issues=t.issues.length?e0(t.issues):eX),t)):(v&&(v.issues=g.issues.length?e0(g.issues):eX),g)};t._zod.parse=l,t._zod.run===a&&(t._zod.run=l)})}},e4=/^[cC][0-9a-z]{6,}$/,e3=/^[0-9a-z]+$/,e6=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,e5=/^[0-9a-vA-V]{20}$/,e8=/^[A-Za-z0-9]{27}$/,e7=/^[a-zA-Z0-9_-]{21}$/,te=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,tt=/^([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})$/,tr=t=>t?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,ta=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,ti=`^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`,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])$/,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}|:))$/,ts=/^((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])$/,tl=/^(([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])$/,tc=/^https?$/,tu=/^\+[1-9]\d{6,14}$/,td="(?:(?:\\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])))",tp=RegExp(`^${td}$`);function tm(t){let r="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof t.precision?-1===t.precision?`${r}`:0===t.precision?`${r}:[0-5]\\d`:`${r}:[0-5]\\d\\.\\d{${t.precision}}`:t.seconds?`${r}:[0-5]\\d(?:\\.\\d+)?`:`${r}(?::[0-5]\\d(?:\\.\\d+)?)?`}let th=/^[\s\S]{0,}$/,tf=/^-?\d+$/,ty=/^-?\d+(?:\.\d+)?$/,tg=/^(?:true|false)$/i,tv=/^null$/i,t_=/^[^A-Z]*$/,tb=/^[^a-z]*$/,tS=eH("$ZodCheck",(t,r)=>{var a;t._zod??(t._zod={}),t._zod.def=r,(a=t._zod).onattach??(a.onattach=[])}),t$=t=>{let r=t.value;return null!=r&&void 0!==r.length},tw={number:"number",bigint:"bigint",object:"date"},tR=eH("$ZodCheckLessThan",(t,r)=>{tS.init(t,r);let a=tw[typeof r.value];t._zod.check=i=>{(r.inclusive?i.value<=r.value:i.value<r.value)||i.issues.push({origin:tw[typeof i.value]??a,code:"too_big",maximum:"object"==typeof r.value?r.value.getTime():r.value,input:i.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),tk=eH("$ZodCheckGreaterThan",(t,r)=>{tS.init(t,r);let a=tw[typeof r.value];t._zod.check=i=>{(r.inclusive?i.value>=r.value:i.value>r.value)||i.issues.push({origin:tw[typeof i.value]??a,code:"too_small",minimum:"object"==typeof r.value?r.value.getTime():r.value,input:i.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),tx=eH("$ZodCheckMultipleOf",(t,r)=>{tS.init(t,r),t._zod.check=a=>{let i,n,o;if(typeof a.value!=typeof r.value)throw Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof a.value?r.value!==BigInt(0)&&a.value%r.value===BigInt(0):0==(n=Math.round(i=a.value/r.value),o=4*Number.EPSILON*Math.max(Math.abs(i),1),Math.abs(i-n)<o?0:i-n))||a.issues.push({origin:typeof a.value,code:"not_multiple_of",divisor:r.value,input:a.value,inst:t,continue:!r.abort})}}),tP=eH("$ZodCheckNumberFormat",(t,r)=>{tS.init(t,r),r.format=r.format||"float64";let a=r.format?.includes("int"),i=a?"int":"number",[n,o]=ew[r.format];t._zod.check=s=>{let l=s.value;if(a){if(!Number.isInteger(l))return void s.issues.push({expected:i,format:r.format,code:"invalid_type",continue:!1,input:l,inst:t});if(!Number.isSafeInteger(l))return void(l>0?s.issues.push({input:l,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:i,inclusive:!0,continue:!r.abort}):s.issues.push({input:l,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:i,inclusive:!0,continue:!r.abort}))}l<n&&s.issues.push({origin:"number",input:l,code:"too_small",minimum:n,inclusive:!0,inst:t,continue:!r.abort}),l>o&&s.issues.push({origin:"number",input:l,code:"too_big",maximum:o,inclusive:!0,inst:t,continue:!r.abort})}}),tE=eH("$ZodCheckMaxLength",(t,r)=>{var a;tS.init(t,r),(a=t._zod.def).when??(a.when=t$),t._zod.check=a=>{let i=a.value,n=i.length;if(("string"==typeof i&&n>r.maximum?eN(i):n)<=r.maximum)return;let o=eq(i);a.issues.push({origin:o,code:"too_big",maximum:r.maximum,inclusive:!0,input:i,inst:t,continue:!r.abort})}}),tT=eH("$ZodCheckMinLength",(t,r)=>{var a;tS.init(t,r),(a=t._zod.def).when??(a.when=t$),t._zod.check=a=>{let i=a.value,n=i.length;if(("string"==typeof i&&n>=r.minimum&&n<2*r.minimum?eN(i):n)>=r.minimum)return;let o=eq(i);a.issues.push({origin:o,code:"too_small",minimum:r.minimum,inclusive:!0,input:i,inst:t,continue:!r.abort})}}),tj=eH("$ZodCheckLengthEquals",(t,r)=>{var a;tS.init(t,r),(a=t._zod.def).when??(a.when=t$),t._zod.check=a=>{let i=a.value,n=i.length,o="string"==typeof i&&n>=r.length&&n<=2*r.length?eN(i):n;if(o===r.length)return;let s=eq(i),l=o>r.length;a.issues.push({origin:s,...l?{code:"too_big",maximum:r.length}:{code:"too_small",minimum:r.length},inclusive:!0,exact:!0,input:a.value,inst:t,continue:!r.abort})}}),tO=eH("$ZodCheckStringFormat",(t,r)=>{var a,i;tS.init(t,r),r.pattern?(a=t._zod).check??(a.check=a=>{r.pattern.lastIndex=0,r.pattern.test(a.value)||a.issues.push({origin:"string",code:"invalid_format",format:r.format,input:a.value,...r.pattern?{pattern:r.pattern.toString()}:{},inst:t,continue:!r.abort})}):(i=t._zod).check??(i.check=()=>{})}),tC=eH("$ZodCheckRegex",(t,r)=>{tO.init(t,r),t._zod.check=a=>{r.pattern.lastIndex=0,r.pattern.test(a.value)||a.issues.push({origin:"string",code:"invalid_format",format:"regex",input:a.value,pattern:r.pattern.toString(),inst:t,continue:!r.abort})}}),tI=eH("$ZodCheckLowerCase",(t,r)=>{r.pattern??(r.pattern=t_),tO.init(t,r)}),tN=eH("$ZodCheckUpperCase",(t,r)=>{r.pattern??(r.pattern=tb),tO.init(t,r)}),tq=eH("$ZodCheckIncludes",(t,r)=>{tS.init(t,r);let a=e_(r.includes),i=new RegExp("number"==typeof r.position?`^.{${r.position},}${a}`:a);r.pattern=i,t._zod.check=a=>{a.value.includes(r.includes,r.position)||a.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:r.includes,input:a.value,inst:t,continue:!r.abort})}}),tA=eH("$ZodCheckStartsWith",(t,r)=>{tS.init(t,r);let a=RegExp(`^${e_(r.prefix)}.*`);r.pattern??(r.pattern=a),t._zod.check=a=>{a.value.startsWith(r.prefix)||a.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:r.prefix,input:a.value,inst:t,continue:!r.abort})}}),tM=eH("$ZodCheckEndsWith",(t,r)=>{tS.init(t,r);let a=RegExp(`.*${e_(r.suffix)}$`);r.pattern??(r.pattern=a),t._zod.check=a=>{a.value.endsWith(r.suffix)||a.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:r.suffix,input:a.value,inst:t,continue:!r.abort})}}),tz=eH("$ZodCheckOverwrite",(t,r)=>{tS.init(t,r),t._zod.check=t=>{t.value=r.tx(t.value)}});class tL{constructor(t=[],r={}){this.content=[],this.indent=0,this.args=t,this.closed=r}indented(t){this.indent+=1;try{t(this)}finally{this.indent-=1}}write(t){if("function"==typeof t){t(this,{execution:"sync"}),t(this,{execution:"async"});return}let r=t.split("\n").filter(t=>t),a=Math.min(...r.map(t=>t.length-t.trimStart().length));for(let t of r.map(t=>t.slice(a)).map(t=>" ".repeat(2*this.indent)+t))this.content.push(t)}compile(){let t=Function,r=this?.content??[""];return new t(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
1
+ !function(t,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var a=r();for(var i in a)("object"==typeof exports?exports:t)[i]=a[i]}}(this,()=>(()=>{"use strict";var t={6982(t){t.exports=require("crypto")},9896(t){t.exports=require("fs")},6928(t){t.exports=require("path")}},r={};function a(i){var n=r[i];if(void 0!==n)return n.exports;var o=r[i]={exports:{}};return t[i](o,o.exports,a),o.exports}a.d=(t,r)=>{for(var i in r)a.o(r,i)&&!a.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:r[i]})},a.o=(t,r)=>Object.prototype.hasOwnProperty.call(t,r),a.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{let t,r,n,o,s,l,c,u,d,p,m,h,f,y,g,v,_,b,S,$,w;a.r(i),a.d(i,{xmcpHandler:()=>ym});let R=require("node:crypto");var k,x,P,E,T,j,O,C,I,N,q,A,M,z,L,Z,D=Object.create,U=Object.defineProperty,V=Object.getOwnPropertyDescriptor,F=Object.getOwnPropertyNames,H=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty,B=(t,r)=>()=>(r||t((r={exports:{}}).exports,r),r.exports),K=(t,r,a)=>(a=null!=t?D(H(t)):{},((t,r,a,i)=>{if(r&&"object"==typeof r||"function"==typeof r)for(var n,o=F(r),s=0,l=o.length;s<l;s++)n=o[s],J.call(t,n)||n===a||U(t,n,{get:(t=>r[t]).bind(null,n),enumerable:!(i=V(r,n))||i.enumerable});return t})(!r&&t&&t.__esModule?a:U(a,"default",{value:t,enumerable:!0}),t));let G=new Set(["https://json-schema.org/draft/2020-12/schema","http://json-schema.org/draft/2020-12/schema"]),W=new Set(["https://json-schema.org/draft/2019-09/schema","http://json-schema.org/draft/2019-09/schema"]),Y=new Set(["https://json-schema.org/draft-07/schema","http://json-schema.org/draft-07/schema"]),X=new Set(["https://json-schema.org/draft-06/schema","http://json-schema.org/draft-06/schema"]);function Q(t){let r=Object.values(t).filter(t=>"number"==typeof t);return Object.entries(t).filter(([t,a])=>-1===r.indexOf(+t)).map(([t,r])=>r)}function ee(t,r="|"){return t.map(t=>e$(t)).join(r)}function et(t,r){return"bigint"==typeof r?r.toString():r}class er{constructor(t){this._getter=t,this._value=void 0}get value(){let t=this._getter;return void 0!==t&&(this._value=t(),this._getter=void 0),this._value}}function ea(t){return new er(t)}function ei(t){let r=+!!t.startsWith("^"),a=t.endsWith("$")?t.length-1:t.length;return t.slice(r,a)}let en=Symbol("evaluating");function eo(t,r,a){Object.defineProperty(t,r,{value:a,writable:!0,enumerable:!0,configurable:!0})}function es(t){let r=Object.getOwnPropertyDescriptor(t,"shape");return r?.get?r.get.raw:r?.value}function el(t){return es(t._zod.def)??t._zod.def.shape}function ec(t,r,a){Object.defineProperty(t,r,{get(){let t=a();return eo(this,r,t),t},enumerable:!0,configurable:!0})}function eu(t,r,a){r in t?eo(t,r,a):t[r]=a}function ed(t,r,a,i){let n=el(r);for(let o of a){let a=Object.getOwnPropertyDescriptor(n,o);a.enumerable&&(a.get?ec(t,o,()=>{let t=r._zod.def.shape[o];return i?i(t,o):t}):eu(t,o,i?i(a.value,o):a.value))}}function ep(...t){let r={};for(let a of t)Object.assign(r,Object.getOwnPropertyDescriptors(a));return Object.defineProperties({},r)}let em="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function eh(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}let ef=ea(()=>{if(eK.jitless||"undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return Function(""),!0}catch(t){return!1}});function ey(t){if(!1===eh(t))return!1;let r=t.constructor;if(void 0===r||"function"!=typeof r)return!0;let a=r.prototype;return!1!==eh(a)&&!1!==Object.prototype.hasOwnProperty.call(a,"isPrototypeOf")}function eg(t){return ey(t)?{...t}:Array.isArray(t)?[...t]:t instanceof Map?new Map(t):t instanceof Set?new Set(t):t}let ev=new Set(["string","number","symbol"]);function e_(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function eb(t,r,a){let i=new t._zod.constr(r??t._zod.def);return(!r||a?.parent)&&(i._zod.parent=t),i}function eS(t){if(!t)return{};if("string"==typeof t)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return(delete t.message,"string"==typeof t.error)?{...t,error:()=>t.error}:t}function e$(t){return"bigint"==typeof t?t.toString()+"n":"string"==typeof t?`"${t}"`:`${t}`}let ew={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]},eR={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function ek(t,r){let a=el(t),i=[];for(let t of Reflect.ownKeys(r)){if(!Object.getOwnPropertyDescriptor(a,t)?.enumerable)throw Error(`Unrecognized key: "${String(t)}"`);r[t]&&i.push(t)}return i}function ex(t,r){let a={};ed(a,t,Reflect.ownKeys(el(t)));for(let t of Reflect.ownKeys(r)){let i=Object.getOwnPropertyDescriptor(r,t);i.enumerable&&(i.get?ec(a,t,()=>r[t]):eu(a,t,i.value))}return a}function eP(t,r,a,i="partial"){let n=r._zod.def.checks;if(n&&n.length>0)throw Error(`.${i}() cannot be used on object schemas containing refinements`);let o=a?new Set(ek(r,a)):void 0,s={};return ed(s,r,Reflect.ownKeys(el(r)),t&&((r,a)=>o&&!o.has(a)?r:new t({type:"optional",innerType:r}))),eb(r,ep(r._zod.def,{shape:s,checks:[]}))}function eE(t,r=0){if(!0===t.aborted)return!0;for(let a=r;a<t.issues.length;a++)if(t.issues[a]?.continue!==!0)return!0;return!1}function eT(t,r){return r.map(r=>(r.path??(r.path=[]),r.path.unshift(t),r))}function ej(t){return"string"==typeof t?t:t?.message}function eO(t,r,a){var i;for(let n=r;n<t.length;n++)(i=t[n]).schema??(i.schema=a)}function eC(t,r,a){let i=t.inst?._zod?.traits;i?.has("$ZodType")&&(i.has("$ZodCheck")?t.schema??(t.schema=t.inst):t.schema=t.inst);let n=t.schema!==t.inst?t.schema?._zod.def?.error:void 0,o=t.message?t.message:ej(t.inst?._zod.def?.error?.(t))??ej(n?.(t))??ej(r?.error?.(t))??ej(a.customError?.(t))??ej(a.localeError?.(t))??"Invalid input",s={};for(let r of Object.keys(t))"inst"!==r&&"schema"!==r&&"continue"!==r&&"input"!==r&&"__proto__"!==r&&(s[r]=t[r]);return s.path??(s.path=[]),s.message=o,r?.reportInput&&(s.input=t.input),s}let eI=/[\uD800-\uDBFF]/;function eN(t){let r=t.length;if(!eI.test(t))return r;let a=r;for(let i=0;i<r-1;i++)(64512&t.charCodeAt(i))==55296&&(64512&t.charCodeAt(i+1))==56320&&(a--,i++);return a}function eq(t){return Array.isArray(t)?"array":"string"==typeof t?"string":"unknown"}function eA(...t){let[r,a,i]=t;return"string"==typeof r?{message:r,code:"custom",input:a,inst:i}:{...r}}function eM(t,r,a,i=!0){return Object.defineProperty(t,r,{configurable:!0,writable:!0,enumerable:i,value:a}),a}function ez(t,r){for(let a in t){let i=t[a];Object.defineProperty(r,a,{configurable:!0,enumerable:!0,get(){return eM(this,a,i(this))},set(t){eM(this,a,t)}})}return r}let eL=!1,eZ={configurable:!0,get(){eL=!0}};function eD(r,a,i){let n=Object.getPrototypeOf(r._zod);if(a in n&&t!==r._zod){t=void 0;return}t=r._zod,Object.defineProperty(n,a,{configurable:!0,get(){Object.defineProperty(this,a,eZ);let t=eL;eL=!1;try{let r=i(this);return eL?delete this[a]:Object.defineProperty(this,a,{configurable:!0,writable:!0,value:r}),eL=eL||t,r}catch(r){throw delete this[a],eL=eL||t,r}},set(t){Object.defineProperty(this,a,{configurable:!0,writable:!0,value:t})}})}let eU=Object.freeze({status:"aborted"}),eV={value:void 0,enumerable:!1},eF="captureStackTrace"in Error?Error:null;function eH(t,r,a,i){function n(t){this.def=t,this.constr=u,this.traits=new Set}n.prototype={};let o=a&&new WeakSet;function s(i,s){if(i._zod){if(i._zod.traits.has(t))return}else{eV.value=new n(s);try{Object.defineProperty(i,"_zod",eV)}finally{eV.value=void 0}}if(i._zod.traits.add(t),r(i,s),o){let t=Object.getPrototypeOf(i),r=i._zod.constr.prototype,n=t;for(;n&&n!==r;)n=Object.getPrototypeOf(n);let s=n??t;if(!o.has(s)){o.add(s);for(let t in a){let r=Object.getOwnPropertyDescriptor(a,t);r.get?Object.defineProperty(s,t,{...r,enumerable:!1}):function(t,r,a){Object.defineProperty(t,r,{configurable:!0,get(){return this==null?a:eM(this,r,a.bind(this))},set(t){eM(this,r,t)}})}(s,t,r.value)}}}let l=u.prototype;for(let t in l)Object.prototype.hasOwnProperty.call(l,t)&&(t in i||(i[t]=l[t].bind(i)))}let l=i?.Parent??Object;class c extends l{}function u(t){let r=i?.Parent?function(t){let r=eF;if(r){let a=r.stackTraceLimit;if("number"==typeof a){try{r.stackTraceLimit=0}catch{return eF=null,new t}try{return new t}finally{r.stackTraceLimit=a}}}return new t}(c):this;s(r,t);let a=r._zod.deferred;if(a){for(let t of a)t();r._zod.deferred=void 0}let n=globalThis.__zod_globalConfig?.postProcessor;return n&&n(r),r}return Object.defineProperty(c,"name",{value:t}),Object.defineProperty(u,"init",{value:s}),Object.defineProperty(u,Symbol.hasInstance,{value:r=>!!i?.Parent&&r instanceof i.Parent||r?._zod?.traits?.has(t)}),Object.defineProperty(u,"name",{value:t}),u}class eJ extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class eB extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}(N=globalThis).__zod_globalConfig??(N.__zod_globalConfig={});let eK=globalThis.__zod_globalConfig;function eG(t){return t&&Object.assign(eK,t),eK}class eW extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform"),this.name="ZodCyclicError"}}let eY="~memo",eX=[];function eQ(t){return null!==t&&"object"==typeof t}function e0(t){return t.map(t=>t.path?{...t,path:t.path.slice()}:{...t})}let e1=new WeakMap,e2=[],e9={alloc(t,a,i){let n=r;if(!n)return i;r=void 0;let o={value:i,issues:null};return n.set(a.value,o),e2.push(o),i},guard(t){var r;(r=t._zod).deferred??(r.deferred=[]),t._zod.deferred.push(()=>{let r=t._zod.parse,a=(t,a)=>{var i,n;let o;if("backward"!==a.direction&&(i=a,n=t.value,void 0!==(o=i[eY]?.backEdges)&&eQ(n)&&o.has(n)))throw new eW;return r(t,a)};t._zod.parse=a,t._zod.run===r&&(t._zod.run=a)})},attach(t){var a;let i,n,o,s=!1;(a=t._zod).deferred??(a.deferred=[]),t._zod.deferred.push(()=>{let a=t._zod.parse,l=(c,u)=>{let d;if(void 0===i){let r=function t(r,a,i){var n,o;let s=e1.get(r);if(void 0!==s)return 2*!!s;if(a.has(r))return 2;a.add(r);let l=0,c=r=>{if(2!==l&&r?._zod){let n=t(r,a,i);n>l&&(l=n)}},u=t=>{t>l&&(l=t)},d=r._zod.def;switch(d.type){case"object":{let r=es(d);u(r?((r,n)=>{let o=0;for(let s of Reflect.ownKeys(r)){let l=Object.getOwnPropertyDescriptor(r,s);if(n&&!l.enumerable)continue;let c=l.get?1:l.value?._zod?t(l.value,a,i):0;c>o&&(o=c)}return o})(r,!0):1),c(d.catchall);break}case"array":c(d.element);break;case"tuple":for(let t of d.items)c(t);c(d.rest);break;case"record":case"map":c(d.keyType),c(d.valueType);break;case"set":c(d.valueType);break;case"union":for(let t of d.options)c(t);break;case"intersection":c(d.left),c(d.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":c(d.innerType);break;case"pipe":c(d.in),c(d.out);break;case"function":c(d.input),c(d.output);break;case"lazy":{let n=d._cachedInner??(i?r._zod.innerType:void 0);u(n?t(n,a,!1):1);break}case"template_literal":case"string":case"number":case"int":case"boolean":case"bigint":case"symbol":case"undefined":case"null":case"void":case"never":case"any":case"unknown":case"date":case"nan":case"enum":case"literal":case"file":case"transform":case"custom":break;default:for(let t in d){let r=Object.getOwnPropertyDescriptor(d,t);if(!r||r.get)continue;let a=r.value;if(a&&"object"==typeof a){if(a._zod)c(a);else if(Array.isArray(a))for(let t of a)c(t)}}}return a.delete(r),n=r,1!==(o=l)&&e1.set(n,2===o),o}(t,new Set,!1);if(0===r)return t._zod.parse=a,t._zod.run===l&&(t._zod.run=a),a(c,u);2===r||s?i=!0:s=!0}let p=c.value;if(!eQ(p))return a(c,u);let m=u[eY];if(m||(m={buckets:new WeakMap,backEdges:void 0},u[eY]=m),n===u)d=o;else{var h;let r;(r=(h=m).buckets.get(t))||(r=new WeakMap,h.buckets.set(t,r)),d=r,n=u,o=d}let f=d.get(p);if(f)return c.value=f.value,f.issues?f.issues.length&&c.issues.push(...e0(f.issues)):(c.memo=!0,m.backEdges??(m.backEdges=new WeakSet),m.backEdges.add(f.value)),c;r=d;let y=e2.length,g=a(c,u);r=void 0;let v=e2.length>y?e2.pop():void 0;return g instanceof Promise?g.then(t=>(v&&(v.issues=t.issues.length?e0(t.issues):eX),t)):(v&&(v.issues=g.issues.length?e0(g.issues):eX),g)};t._zod.parse=l,t._zod.run===a&&(t._zod.run=l)})}},e4=/^[cC][0-9a-z]{6,}$/,e3=/^[0-9a-z]+$/,e6=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,e5=/^[0-9a-vA-V]{20}$/,e8=/^[A-Za-z0-9]{27}$/,e7=/^[a-zA-Z0-9_-]{21}$/,te=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,tt=/^([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})$/,tr=t=>t?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,ta=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,ti=`^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`,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])$/,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}|:))$/,ts=/^((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])$/,tl=/^(([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])$/,tc=/^https?$/,tu=/^\+[1-9]\d{6,14}$/,td="(?:(?:\\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])))",tp=RegExp(`^${td}$`);function tm(t){let r="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof t.precision?-1===t.precision?`${r}`:0===t.precision?`${r}:[0-5]\\d`:`${r}:[0-5]\\d\\.\\d{${t.precision}}`:t.seconds?`${r}:[0-5]\\d(?:\\.\\d+)?`:`${r}(?::[0-5]\\d(?:\\.\\d+)?)?`}let th=/^[\s\S]{0,}$/,tf=/^-?\d+$/,ty=/^-?\d+(?:\.\d+)?$/,tg=/^(?:true|false)$/i,tv=/^null$/i,t_=/^[^A-Z]*$/,tb=/^[^a-z]*$/,tS=eH("$ZodCheck",(t,r)=>{var a;t._zod??(t._zod={}),t._zod.def=r,(a=t._zod).onattach??(a.onattach=[])}),t$=t=>{let r=t.value;return null!=r&&void 0!==r.length},tw={number:"number",bigint:"bigint",object:"date"},tR=eH("$ZodCheckLessThan",(t,r)=>{tS.init(t,r);let a=tw[typeof r.value];t._zod.check=i=>{(r.inclusive?i.value<=r.value:i.value<r.value)||i.issues.push({origin:tw[typeof i.value]??a,code:"too_big",maximum:"object"==typeof r.value?r.value.getTime():r.value,input:i.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),tk=eH("$ZodCheckGreaterThan",(t,r)=>{tS.init(t,r);let a=tw[typeof r.value];t._zod.check=i=>{(r.inclusive?i.value>=r.value:i.value>r.value)||i.issues.push({origin:tw[typeof i.value]??a,code:"too_small",minimum:"object"==typeof r.value?r.value.getTime():r.value,input:i.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),tx=eH("$ZodCheckMultipleOf",(t,r)=>{tS.init(t,r),t._zod.check=a=>{let i,n,o;if(typeof a.value!=typeof r.value)throw Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof a.value?r.value!==BigInt(0)&&a.value%r.value===BigInt(0):0==(n=Math.round(i=a.value/r.value),o=4*Number.EPSILON*Math.max(Math.abs(i),1),Math.abs(i-n)<o?0:i-n))||a.issues.push({origin:typeof a.value,code:"not_multiple_of",divisor:r.value,input:a.value,inst:t,continue:!r.abort})}}),tP=eH("$ZodCheckNumberFormat",(t,r)=>{tS.init(t,r),r.format=r.format||"float64";let a=r.format?.includes("int"),i=a?"int":"number",[n,o]=ew[r.format];t._zod.check=s=>{let l=s.value;if(a){if(!Number.isInteger(l))return void s.issues.push({expected:i,format:r.format,code:"invalid_type",continue:!1,input:l,inst:t});if(!Number.isSafeInteger(l))return void(l>0?s.issues.push({input:l,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:i,inclusive:!0,continue:!r.abort}):s.issues.push({input:l,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:i,inclusive:!0,continue:!r.abort}))}l<n&&s.issues.push({origin:"number",input:l,code:"too_small",minimum:n,inclusive:!0,inst:t,continue:!r.abort}),l>o&&s.issues.push({origin:"number",input:l,code:"too_big",maximum:o,inclusive:!0,inst:t,continue:!r.abort})}}),tE=eH("$ZodCheckMaxLength",(t,r)=>{var a;tS.init(t,r),(a=t._zod.def).when??(a.when=t$),t._zod.check=a=>{let i=a.value,n=i.length;if(("string"==typeof i&&n>r.maximum?eN(i):n)<=r.maximum)return;let o=eq(i);a.issues.push({origin:o,code:"too_big",maximum:r.maximum,inclusive:!0,input:i,inst:t,continue:!r.abort})}}),tT=eH("$ZodCheckMinLength",(t,r)=>{var a;tS.init(t,r),(a=t._zod.def).when??(a.when=t$),t._zod.check=a=>{let i=a.value,n=i.length;if(("string"==typeof i&&n>=r.minimum&&n<2*r.minimum?eN(i):n)>=r.minimum)return;let o=eq(i);a.issues.push({origin:o,code:"too_small",minimum:r.minimum,inclusive:!0,input:i,inst:t,continue:!r.abort})}}),tj=eH("$ZodCheckLengthEquals",(t,r)=>{var a;tS.init(t,r),(a=t._zod.def).when??(a.when=t$),t._zod.check=a=>{let i=a.value,n=i.length,o="string"==typeof i&&n>=r.length&&n<=2*r.length?eN(i):n;if(o===r.length)return;let s=eq(i),l=o>r.length;a.issues.push({origin:s,...l?{code:"too_big",maximum:r.length}:{code:"too_small",minimum:r.length},inclusive:!0,exact:!0,input:a.value,inst:t,continue:!r.abort})}}),tO=eH("$ZodCheckStringFormat",(t,r)=>{var a,i;tS.init(t,r),r.pattern?(a=t._zod).check??(a.check=a=>{r.pattern.lastIndex=0,r.pattern.test(a.value)||a.issues.push({origin:"string",code:"invalid_format",format:r.format,input:a.value,...r.pattern?{pattern:r.pattern.toString()}:{},inst:t,continue:!r.abort})}):(i=t._zod).check??(i.check=()=>{})}),tC=eH("$ZodCheckRegex",(t,r)=>{tO.init(t,r),t._zod.check=a=>{r.pattern.lastIndex=0,r.pattern.test(a.value)||a.issues.push({origin:"string",code:"invalid_format",format:"regex",input:a.value,pattern:r.pattern.toString(),inst:t,continue:!r.abort})}}),tI=eH("$ZodCheckLowerCase",(t,r)=>{r.pattern??(r.pattern=t_),tO.init(t,r)}),tN=eH("$ZodCheckUpperCase",(t,r)=>{r.pattern??(r.pattern=tb),tO.init(t,r)}),tq=eH("$ZodCheckIncludes",(t,r)=>{tS.init(t,r);let a=e_(r.includes),i=new RegExp("number"==typeof r.position?`^.{${r.position},}${a}`:a);r.pattern=i,t._zod.check=a=>{a.value.includes(r.includes,r.position)||a.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:r.includes,input:a.value,inst:t,continue:!r.abort})}}),tA=eH("$ZodCheckStartsWith",(t,r)=>{tS.init(t,r);let a=RegExp(`^${e_(r.prefix)}.*`);r.pattern??(r.pattern=a),t._zod.check=a=>{a.value.startsWith(r.prefix)||a.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:r.prefix,input:a.value,inst:t,continue:!r.abort})}}),tM=eH("$ZodCheckEndsWith",(t,r)=>{tS.init(t,r);let a=RegExp(`.*${e_(r.suffix)}$`);r.pattern??(r.pattern=a),t._zod.check=a=>{a.value.endsWith(r.suffix)||a.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:r.suffix,input:a.value,inst:t,continue:!r.abort})}}),tz=eH("$ZodCheckOverwrite",(t,r)=>{tS.init(t,r),t._zod.check=t=>{t.value=r.tx(t.value)}});class tL{constructor(t=[],r={}){this.content=[],this.indent=0,this.args=t,this.closed=r}indented(t){this.indent+=1;try{t(this)}finally{this.indent-=1}}write(t){if("function"==typeof t){t(this,{execution:"sync"}),t(this,{execution:"async"});return}let r=t.split("\n").filter(t=>t),a=Math.min(...r.map(t=>t.length-t.trimStart().length));for(let t of r.map(t=>t.slice(a)).map(t=>" ".repeat(2*this.indent)+t))this.content.push(t)}compile(){let t=Function,r=this?.content??[""];return new t(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
2
2
  ${r.join("\n")}
3
3
  };`)(...Object.values(this.closed))}}let tZ={major:4,minor:6,patch:5},tD=eH("$ZodType",(t,r)=>{var a;t??(t={}),t._zod.def=r,t._zod.bag=t._zod.bag||{},t._zod.version=tZ;let i=t._zod.def.checks,n=t._zod.traits.has("$ZodCheck")?[t,...i??[]]:i?.length?[...i]:[];for(let r of n)for(let a of r._zod.onattach)a(t);if(0===n.length)(a=t._zod).deferred??(a.deferred=[]),t._zod.deferred?.push(()=>{t._zod.run=t._zod.parse});else{let r=(r,a,i)=>{let n;if(r.memo)return r;let o=eE(r);for(let s of a){if(s._zod.def.when){if(function(t,r=0){if(!0===t.aborted)return!0;for(let a=r;a<t.issues.length;a++)if(t.issues[a]?.continue===!1)return!0;return!1}(r)||!s._zod.def.when(r))continue}else if(o)continue;let a=r.issues.length,l=s._zod.check(r);if(l instanceof Promise&&i?.async===!1)throw new eJ;if(n||l instanceof Promise)n=(n??Promise.resolve()).then(async()=>{await l,r.issues.length!==a&&(eO(r.issues,a,t),o||(o=eE(r,a)))});else{if(r.issues.length===a)continue;eO(r.issues,a,t),o||(o=eE(r,a))}}return n?n.then(()=>r):r},a=(a,i,o)=>{if(eE(a))return a.aborted=!0,a;let s=r(i,n,o);if(s instanceof Promise){if(!1===o.async)throw new eJ;return s.then(r=>t._zod.parse(r,o))}return t._zod.parse(s,o)};t._zod.run=(i,o)=>{if(o.skipChecks)return t._zod.parse(i,o);if("backward"===o.direction){let r=t._zod.parse({value:i.value,issues:[]},{...o,skipChecks:!0});return r instanceof Promise?r.then(t=>a(t,i,o)):a(r,i,o)}let s=t._zod.parse(i,o);if(s instanceof Promise){if(!1===o.async)throw new eJ;return s.then(t=>r(t,n,o))}return r(s,n,o)}}},{get"~standard"(){return eM(this,"~standard",tF(this),!1)},set"~standard"(value){eM(this,"~standard",value)}}),tU=(t,r)=>t.issues.length?{issues:t.issues.map(t=>eC(t,r,eG()))}:{value:t.value};async function tV(t,r){let a={async:!0};return tU(await t._zod.run({value:r,issues:[]},a),a)}function tF(t){return{validate:r=>{let a={async:!1};try{let i=t._zod.run({value:r,issues:[]},a);if(!(i instanceof Promise))return tU(i,a)}catch(t){}return tV(t,r)},vendor:"zod",version:1}}let tH=eH("$ZodString",(t,r)=>{tD.init(t,r),t._zod.pattern=r.pattern??th,t._zod.parse=(a,i)=>{if(r.coerce)try{a.value=String(a.value)}catch(t){}return"string"==typeof a.value||a.issues.push({expected:"string",code:"invalid_type",input:a.value,inst:t}),a}}),tJ=eH("$ZodStringFormat",(t,r)=>{tO.init(t,r),tH.init(t,r)}),tB=eH("$ZodGUID",(t,r)=>{r.pattern??(r.pattern=tt),tJ.init(t,r)}),tK=eH("$ZodUUID",(t,r)=>{if(r.version){let t={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[r.version];if(void 0===t)throw Error(`Invalid UUID version: "${r.version}"`);r.pattern??(r.pattern=tr(t))}else r.pattern??(r.pattern=tr());tJ.init(t,r)}),tG=eH("$ZodEmail",(t,r)=>{r.pattern??(r.pattern=ta),tJ.init(t,r)});function tW(t){try{if("undefined"!=typeof URL&&"function"==typeof URL.canParse)return URL.canParse(t);return new URL(t),!0}catch{return!1}}let tY=/[\t\n\r]/g;function tX(t){return t.replace(tY,"")}let tQ=eH("$ZodURL",(t,r)=>{tJ.init(t,r),t._zod.check=a=>{try{var i,n;let o=a.value.trim(),s="normalize"in r||"hostname"in r||"protocol"in r?function(t,r){if(!r.normalize&&r.protocol?.source===tc.source&&!/^https?:\/\//i.test(t))return 1;try{if("undefined"!=typeof URL){let r=URL;if("function"==typeof r.parse)return r.parse(t)??2}return new URL(t)}catch{return 2}}(o,r):tW(o)||2;if(1===s)return void a.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:a.value,inst:t,continue:!r.abort});if(2===s)return void a.issues.push({code:"invalid_format",format:"url",input:a.value,inst:t,continue:!r.abort});if(!0===s){a.value=tX(o);return}r.hostname&&((i=r.hostname).lastIndex=0,!i.test(s.hostname))&&a.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:r.hostname.source,input:a.value,inst:t,continue:!r.abort}),r.protocol&&((n=r.protocol).lastIndex=0,!n.test(s.protocol.endsWith(":")?s.protocol.slice(0,-1):s.protocol))&&a.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:r.protocol.source,input:a.value,inst:t,continue:!r.abort}),a.value=r.normalize?s.href:tX(o);return}catch(i){a.issues.push({code:"invalid_format",format:"url",input:a.value,inst:t,continue:!r.abort})}}}),t0=eH("$ZodEmoji",(t,r)=>{r.pattern??(r.pattern=RegExp(ti,"u")),tJ.init(t,r)}),t1=eH("$ZodNanoID",(t,r)=>{var a;if(void 0!==r.length&&(!Number.isInteger(r.length)||r.length<1))throw Error(`Invalid nanoid length: ${r.length}`);r.pattern??(r.pattern=void 0===r.length?e7:(a=r.length,RegExp(`^[a-zA-Z0-9_-]{${a}}$`))),tJ.init(t,r)}),t2=eH("$ZodCUID",(t,r)=>{r.pattern??(r.pattern=e4),tJ.init(t,r)}),t9=eH("$ZodCUID2",(t,r)=>{r.pattern??(r.pattern=e3),tJ.init(t,r)}),t4=eH("$ZodULID",(t,r)=>{r.pattern??(r.pattern=e6),tJ.init(t,r)}),t3=eH("$ZodXID",(t,r)=>{r.pattern??(r.pattern=e5),tJ.init(t,r)}),t6=eH("$ZodKSUID",(t,r)=>{r.pattern??(r.pattern=e8),tJ.init(t,r)}),t5=eH("$ZodISODateTime",(t,r)=>{let a,i,n;r.pattern??(a=["Z"],r.offset&&a.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)"),i=`${tm({precision:r.precision,seconds:!0})}(?:${a.join("|")})`,n=r.local?`${i}|${tm({precision:r.precision})}`:i,r.pattern=RegExp(`^${td}T(?:${n})$`)),tJ.init(t,r)}),t8=eH("$ZodISODate",(t,r)=>{r.pattern??(r.pattern=tp),tJ.init(t,r)}),t7=eH("$ZodISOTime",(t,r)=>{r.pattern??(r.pattern=RegExp(`^${tm(r)}$`)),tJ.init(t,r)}),re=eH("$ZodISODuration",(t,r)=>{r.pattern??(r.pattern=te),tJ.init(t,r)}),rt=eH("$ZodIPv4",(t,r)=>{r.pattern??(r.pattern=tn),tJ.init(t,r)}),rr=/^[0-9a-fA-F:.]+$/;function ra(t){return!!rr.test(t)&&tW(`http://[${t}]`)}let ri=eH("$ZodIPv6",(t,r)=>{r.pattern??(r.pattern=to),tJ.init(t,r),t._zod.check=a=>{ra(a.value)||a.issues.push({code:"invalid_format",format:"ipv6",input:a.value,inst:t,continue:!r.abort})}}),rn=eH("$ZodCIDRv4",(t,r)=>{r.pattern??(r.pattern=ts),tJ.init(t,r)}),ro=eH("$ZodCIDRv6",(t,r)=>{r.pattern??(r.pattern=tl),tJ.init(t,r),t._zod.check=a=>{!function(t){let r=t.split("/");if(2!==r.length)return!1;let[a,i]=r;if(!i)return!1;let n=Number(i);return`${n}`===i&&!(n<0)&&!(n>128)&&ra(a)}(a.value)&&a.issues.push({code:"invalid_format",format:"cidrv6",input:a.value,inst:t,continue:!r.abort})}});function rs(t){if(""===t)return!0;if(/\s/.test(t)||t.length%4!=0)return!1;try{return atob(t),!0}catch{return!1}}let rl=/^[0-9a-zA-Z+/]*={0,2}$/,rc=eH("$ZodBase64",(t,r)=>{r.pattern??(r.pattern=rl),tJ.init(t,r),t._zod.check=a=>{rs(a.value)||a.issues.push({code:"invalid_format",format:"base64",input:a.value,inst:t,continue:!r.abort})}}),ru=/^[A-Za-z0-9_-]*$/,rd=eH("$ZodBase64URL",(t,r)=>{r.pattern??(r.pattern=ru),tJ.init(t,r),t._zod.check=a=>{!function(t){if(!ru.test(t))return!1;let r=t.replace(/[-_]/g,t=>"-"===t?"+":"/");return rs(r.padEnd(4*Math.ceil(r.length/4),"="))}(a.value)&&a.issues.push({code:"invalid_format",format:"base64url",input:a.value,inst:t,continue:!r.abort})}}),rp=eH("$ZodE164",(t,r)=>{r.pattern??(r.pattern=tu),tJ.init(t,r)}),rm=eH("$ZodJWT",(t,r)=>{tJ.init(t,r),t._zod.check=a=>{!function(t,r=null){try{let a=t.split(".");if(3!==a.length)return!1;let[i]=a;if(!i)return!1;let n=JSON.parse(atob(i));if("typ"in n&&n?.typ!=="JWT"||!n.alg||r&&(!("alg"in n)||n.alg!==r))return!1;return!0}catch{return!1}}(a.value,r.alg)&&a.issues.push({code:"invalid_format",format:"jwt",input:a.value,inst:t,continue:!r.abort})}}),rh=eH("$ZodNumber",(t,r)=>{tD.init(t,r),t._zod.pattern=ty,t._zod.parse=(a,i)=>{if(r.coerce)try{a.value=Number(a.value)}catch(t){}let n=a.value;if("number"==typeof n&&!Number.isNaN(n)&&Number.isFinite(n))return a;let o="number"==typeof n?Number.isNaN(n)?"NaN":Number.isFinite(n)?void 0:String(n):void 0;return a.issues.push({expected:"number",code:"invalid_type",input:n,inst:t,...o?{received:o}:{}}),a}}),rf=eH("$ZodNumberFormat",(t,r)=>{tP.init(t,r),rh.init(t,r)}),ry=eH("$ZodBoolean",(t,r)=>{tD.init(t,r),t._zod.pattern=tg,t._zod.parse=(a,i)=>{if(r.coerce)try{a.value=!!a.value}catch(t){}let n=a.value;return"boolean"==typeof n||a.issues.push({expected:"boolean",code:"invalid_type",input:n,inst:t}),a}}),rg=eH("$ZodNull",(t,r)=>{tD.init(t,r),t._zod.pattern=tv,t._zod.values=new Set([null]),t._zod.parse=(r,a)=>{let i=r.value;return null===i||r.issues.push({expected:"null",code:"invalid_type",input:i,inst:t}),r}}),rv=eH("$ZodAny",(t,r)=>{tD.init(t,r),t._zod.parse=t=>t}),r_=eH("$ZodUnknown",(t,r)=>{tD.init(t,r),t._zod.parse=t=>t}),rb=eH("$ZodNever",(t,r)=>{tD.init(t,r),t._zod.parse=(r,a)=>(r.issues.push({expected:"never",code:"invalid_type",input:r.value,inst:t}),r)});function rS(t,r,a){t.issues.length&&r.issues.push(...eT(a,t.issues)),r.value[a]=t.value}let r$=eH("$ZodArray",(t,r)=>{tD.init(t,r);let a=eK.memoizer;a?.attach(t),t._zod.parse=(i,n)=>{let o=i.value;if(!Array.isArray(o))return i.issues.push({expected:"array",code:"invalid_type",input:o,inst:t}),i;i.value=a?a.alloc(t,i,Array(o.length),n):Array(o.length);let s=[],l=n?.abortEarly;for(let t=0;t<o.length;t++){let a=o[t],c=r.element._zod.run({value:a,issues:[]},n);if(c instanceof Promise)s.push(c.then(r=>rS(r,i,t)));else if(rS(c,i,t),l&&0!==c.issues.length&&eE(c))break}return s.length?Promise.all(s).then(()=>i):i}});function rw(t,r,a,i,n,o){let s=a in i,l="optional"===o;if(s||!l||"optional"!==n){if(t.issues.length){if(void 0!==n&&l&&!s)return;r.issues.push(...eT(a,t.issues))}if(!s&&void 0===n){t.issues.length||r.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[a]});return}void 0===t.value?(s||"defaulted"===n&&!l)&&(r.value[a]=void 0):r.value[a]=t.value}}let rR=[];function rk(t){var r;let a=Object.keys(t.shape),i=Object.getOwnPropertySymbols(t.shape),n=i.length?i:rR,o=n.length?[...a,...n]:a;for(let r of o)if(!t.shape?.[r]?._zod?.traits?.has("$ZodType"))throw Error(`Invalid element at key "${String(r)}": expected a Zod schema`);let s=Object.keys(r=t.shape).filter(t=>void 0!==r[t]._zod.optin&&"optional"===r[t]._zod.optout);return{...t,allKeys:o,symbolKeys:n,keySet:new Set(a),numKeys:a.length,optionalKeys:new Set(s)}}function rx(t,r,a,i,n,o,s){let l=[],c=n.keySet,u=n.catchall._zod,d=u.def.type,p=u.optin,m=u.optout,h=0;for(let n in r){if(s&&a.issues.length!==h){if(eE(a,h))break;h=a.issues.length}if(c.has(n))continue;if("__proto__"===n){"never"===d&&l.push(n);continue}if("never"===d){l.push(n);continue}let o=u.run({value:r[n],issues:[]},i);o instanceof Promise?t.push(o.then(t=>rw(t,a,n,r,p,m))):rw(o,a,n,r,p,m)}return(l.length&&a.issues.push({code:"unrecognized_keys",keys:l,input:r,inst:o,continue:!0}),t.length)?Promise.all(t).then(()=>a):a}let rP=eH("$ZodObject",(t,r)=>{let a;tD.init(t,r);let i=Object.getOwnPropertyDescriptor(r,"shape"),n=i?.get?i.get.raw:r.shape??{};if(n){let t=()=>{let a={...n};return Object.defineProperty(r,"shape",{value:a}),t.raw=a,a};t.raw=n,Object.defineProperty(r,"shape",{get:t})}let o=ea(()=>rk(r));eD(t,"propValues",t=>{let r=t.def.shape,a={};for(let t in r){let i=r[t]._zod;if(i.values){for(let r of(Object.prototype.hasOwnProperty.call(a,t)||eo(a,t,new Set),i.values))a[t].add(r);void 0!==i.optin&&a[t].add(void 0)}}return a});let s=r.catchall,l=eK.memoizer;l?.attach(t),t._zod.parse=(r,i)=>{a??(a=o.value);let n=r.value;if(!eh(n))return r.issues.push({expected:"object",code:"invalid_type",input:n,inst:t}),r;r.value=l?l.alloc(t,r,{},i):{};let c=[],u=a.shape,d=i?.abortEarly,p=r.issues.length;for(let t of a.allKeys){if(d&&r.issues.length!==p){if(eE(r,p))break;p=r.issues.length}if("__proto__"===t)continue;let a=u[t],o=a._zod.optin,s=a._zod.optout,l=a._zod.run({value:n[t],issues:[]},i);l instanceof Promise?c.push(l.then(a=>rw(a,r,t,n,o,s))):rw(l,r,t,n,o,s)}return s?rx(c,n,r,i,o.value,t,!0===d):c.length?Promise.all(c).then(()=>r):r}}),rE=eH("$ZodObjectJIT",(t,r)=>{let a,i;rP.init(t,r);let n=t._zod.parse,o=ea(()=>rk(r)),s=eK.memoizer,l=!eK.jitless,c=l&&ef.value,u=r.catchall;t._zod.parse=(d,p)=>{i??(i=o.value);let m=d.value;return eh(m)?l&&c&&p?.async===!1&&!0!==p.jitless?(a||(a=(r=>{let a=o.value,i=a.symbolKeys,n=new tL(["payload","ctx"],{shape:r,inst:t,memo:s,syms:i}),l=t=>`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`,c=(t,r)=>`
4
4
  let ${t}_ab = false;
@@ -74,17 +74,17 @@ data:
74
74
  `;return i&&(n+=`id: ${i}
75
75
  `),n+=`data: ${JSON.stringify(a)}
76
76
 
77
- `,t.enqueue(r.encode(n)),!0}catch(t){return this.onerror?.(t),!1}}handleUnsupportedRequest(){return this.onerror?.(Error("Method not allowed.")),Response.json({jsonrpc:"2.0",error:{code:-32e3,message:"Method not allowed."},id:null},{status:405,headers:{Allow:"GET, POST, DELETE","Content-Type":"application/json"}})}async handlePostRequest(t,r){try{let a,i,n,o,s,l=t.headers.get("accept");if(!l?.includes("application/json")||!l.includes("text/event-stream"))return this.onerror?.(Error("Not Acceptable: Client must accept both application/json and text/event-stream")),this.createJsonErrorResponse(406,-32e3,"Not Acceptable: Client must accept both application/json and text/event-stream");if(!uz(t.headers.get("content-type")))return this.onerror?.(Error("Unsupported Media Type: Content-Type must be application/json")),this.createJsonErrorResponse(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");if(r?.parsedBody===void 0)try{let r=await p2(t,this._maxRequestBodySize);if(r.tooLarge){let t=p0(this._maxRequestBodySize);return this.onerror?.(Error(t)),this.createJsonErrorResponse(413,-32e3,t)}a=JSON.parse(r.text)}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON")}else a=r.parsedBody;if(Array.isArray(a)&&a.length>100)return this.onerror?.(Error("Invalid Request: Batch must not exceed 100 messages")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Batch must not exceed 100 messages");try{i=Array.isArray(a)?a.map(t=>ou.parse(t)):[ou.parse(a)]}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON-RPC message")}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");let c=i.some(t=>ok.safeParse(t).success);if(c){if(this._initialized&&void 0!==this.sessionId)return this.onerror?.(Error("Invalid Request: Server already initialized")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Server already initialized");if(i.length>1)return this.onerror?.(Error("Invalid Request: Only one initialization request is allowed")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Only one initialization request is allowed");this.sessionId=this.sessionIdGenerator?.(),this._initialized=!0,this.sessionId&&this._onsessioninitialized&&await Promise.resolve(this._onsessioninitialized(this.sessionId))}if(!c){let r=this.validateSession(t);if(r)return r;let a=this.validateProtocolVersion(t);if(a)return a}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");try{n=await this._checkScopeChallenge(i,r?.authInfo)}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(500,-32603,"Internal server error")}if(n)return n;if(!i.some(t=>cW(t))){for(let a of i)this.onmessage?.(a,{authInfo:r?.authInfo,request:t});return new Response(null,{status:202})}let u=crypto.randomUUID(),d=i.find(t=>ok.safeParse(t).success),p=d?d.params.protocolVersion:t.headers.get("mcp-protocol-version")??"2025-03-26";if(this._enableJsonResponse)return new Promise(a=>{for(let t of(this._streamMapping.set(u,{resolveJson:a,cleanup:()=>{this._streamMapping.delete(u)}}),i))cW(t)&&this._requestToStreamMapping.set(t.id,u);for(let a of i)this.onmessage?.(a,{authInfo:r?.authInfo,request:t})});let m=new TextEncoder,h=new ReadableStream({start:t=>{o=t},cancel:()=>{void 0!==s&&clearInterval(s),this._streamMapping.get(u)?.controller===o&&this._streamMapping.delete(u)}}),f={"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"};for(let t of(void 0!==this.sessionId&&(f["mcp-session-id"]=this.sessionId),i))cW(t)&&(this._streamMapping.set(u,{controller:o,encoder:m,cleanup:()=>{void 0!==s&&clearInterval(s),this._streamMapping.delete(u);try{o.close()}catch{}}}),this._requestToStreamMapping.set(t.id,u));for(let a of(await this.writePrimingEvent(o,m,u,p),i)){let i,n;cW(a)&&this._eventStore&&this.supportsEmptySSEData(p)&&(i=()=>{this.closeSSEStream(a.id)},n=()=>{this.closeStandaloneSSEStream()}),this.onmessage?.(a,{authInfo:r?.authInfo,request:t,closeSSEStream:i,closeStandaloneSSEStream:n})}return this._streamMapping.get(u)?.controller===o&&(s=this.startKeepAlive(o,m)),new Response(h,{status:200,headers:f})}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error",{data:String(t)})}}async handleDeleteRequest(t){let r=this.validateSession(t);if(r)return r;let a=this.validateProtocolVersion(t);if(a)return a;try{return await Promise.resolve(this._onsessionclosed?.(this.sessionId)),new Response(null,{status:200})}finally{await this.close()}}validateSession(t){if(void 0===this.sessionIdGenerator)return;if(!this._initialized)return this.onerror?.(Error("Bad Request: Server not initialized")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Server not initialized");let r=t.headers.get("mcp-session-id");return r?r!==this.sessionId?(this.onerror?.(Error("Session not found")),this.createJsonErrorResponse(404,-32001,"Session not found")):void 0:(this.onerror?.(Error("Bad Request: Mcp-Session-Id header is required")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Mcp-Session-Id header is required"))}validateProtocolVersion(t){let r=t.headers.get("mcp-protocol-version");if(null!==r&&!this._supportedProtocolVersions.includes(r)){let t=`Bad Request: Unsupported protocol version: ${r} (supported versions: ${this._supportedProtocolVersions.join(", ")})`;return this.onerror?.(Error(t)),this.createJsonErrorResponse(400,-32e3,t)}}async close(){if(!this._closed){for(let{cleanup:t}of(this._closed=!0,this._streamMapping.values()))t();this._streamMapping.clear(),this._requestResponseMap.clear(),this.onclose?.()}}closeSSEStream(t){let r=this._requestToStreamMapping.get(t);if(!r)return;let a=this._streamMapping.get(r);a&&a.cleanup()}closeStandaloneSSEStream(){let t=this._streamMapping.get(this._standaloneSseStreamId);t&&t.cleanup()}async send(t,r){let a=r?.relatedRequestId;if((cX(t)||cQ(t))&&(a=t.id),void 0===a){let r;if(cX(t)||cQ(t))throw Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");this._eventStore&&(r=await this._eventStore.storeEvent(this._standaloneSseStreamId,t));let a=this._streamMapping.get(this._standaloneSseStreamId);if(void 0===a)return;a.controller&&a.encoder&&(void 0===r||!a.replayedEventIds?.has(r))&&this.writeSSEEvent(a.controller,a.encoder,t,r);return}let i=this._requestToStreamMapping.get(a);if(!i)throw Error(`No connection established for request ID: ${String(a)}`);let n=this._streamMapping.get(i);if(!this._enableJsonResponse){let r;this._eventStore&&(r=await this._eventStore.storeEvent(i,t),n=this._streamMapping.get(i)),n?.controller&&n?.encoder&&(void 0===r||!n.replayedEventIds?.has(r))&&this.writeSSEEvent(n.controller,n.encoder,t,r)}if(cX(t)||cQ(t)){this._requestResponseMap.set(a,t);let r=[...this._requestToStreamMapping.entries()].filter(([t,r])=>r===i).map(([t])=>t);if(r.every(t=>this._requestResponseMap.has(t))){if(!n){if(this._enableJsonResponse)throw Error(`No connection established for request ID: ${String(a)}`);if(!this._eventStore){for(let t of(this.onerror?.(Error(`Response for request ID ${String(a)} is undeliverable: per-request stream is disconnected and no eventStore is configured`)),r))this._requestResponseMap.delete(t),this._requestToStreamMapping.delete(t);return}for(let t of r)this._requestResponseMap.delete(t),this._requestToStreamMapping.delete(t);return}if(this._enableJsonResponse&&n.resolveJson){let t={"Content-Type":"application/json"};void 0!==this.sessionId&&(t["mcp-session-id"]=this.sessionId);let a=r.map(t=>this._requestResponseMap.get(t));1===a.length?n.resolveJson(Response.json(a[0],{status:200,headers:t})):n.resolveJson(Response.json(a,{status:200,headers:t})),n.cleanup()}else n.cleanup();for(let t of r)this._requestResponseMap.delete(t),this._requestToStreamMapping.delete(t)}}}};function p4(t){if(null===t||"object"!=typeof t||Array.isArray(t))return null;let{method:r,id:a}=t;return"string"!=typeof r?null:"string"==typeof a||"number"==typeof a?a:null}function p3(t,r,a,i,n=null){return Response.json({jsonrpc:"2.0",error:{code:r,message:a,...void 0!==i&&{data:i}},id:n},{status:t})}function p6(t,r=null){return p3(t.httpStatus,t.code,t.message,t.data,r)}function p5(t){return t instanceof Error?t:Error(String(t))}function p8(t=null){return p3(500,-32603,"Internal server error",void 0,t)}function p7(t){if(void 0!==t.transport)throw Error("The factory returned an instance that is still serving another request. Return a new instance for each request.")}function me(t){return{protocolVersionHeader:t.headers.get("mcp-protocol-version")??void 0,mcpMethodHeader:t.headers.get("mcp-method")??void 0,mcpNameHeader:t.headers.get("mcp-name")??void 0}}async function mt(t,r,a=!0,i=4194304){let n,o=t.method.toUpperCase(),s=r,l=t,c=!1;if("POST"===o){if(void 0===s){let r;a&&(l=t.clone());try{let a=await p2(t,i);if(a.tooLarge)return{step:"body-too-large"};r=a.text}catch{return{step:"unreadable-body"}}try{n=0===r.length?void 0:JSON.parse(r)}catch{c=!0}c||void 0===n||(s=n)}else n=s;if(c||void 0===n)return{step:"no-json-body",forwardRequest:l}}return{step:"classified",outcome:function(t){if("POST"!==(t={...t,...void 0!==t.protocolVersionHeader&&{protocolVersionHeader:us(t.protocolVersionHeader)},...void 0!==t.mcpMethodHeader&&{mcpMethodHeader:us(t.mcpMethodHeader)},...void 0!==t.mcpNameHeader&&{mcpNameHeader:us(t.mcpNameHeader)}}).httpMethod.toUpperCase())return{kind:"legacy",reason:"http-method"};let r=t.body;if(Array.isArray(r)){if(0===r.length)return ui("jsonrpc-shape","empty-batch",400,new cv(cg.InvalidRequest,"Bad Request: empty JSON-RPC batch"),!0);for(let t of r){if(cJ(ul(t)?t.params:void 0))return ui("jsonrpc-shape","batch-with-modern-element",400,new cv(cg.InvalidRequest,"Bad Request: JSON-RPC batches may not contain requests for protocol revision 2026-07-28 or later"),!0);if(!(cW(t)||cY(t)||cX(t)||cQ(t)))return ui("jsonrpc-shape","batch-with-invalid-element",400,new cv(cg.InvalidRequest,"Bad Request: JSON-RPC batch contains an invalid message"),!0)}return{kind:"legacy",reason:"batch"}}return cX(r)||cQ(r)?{kind:"legacy",reason:"response"}:ul(r)&&cW(r)?function(t,r){let a=r.params,i=r.method,n=t.protocolVersionHeader,o=void 0!==n&&n>=lX;if("initialize"===i&&!function(t){if(!cJ(t))return!1;let r=cB(t);if(void 0===r||!(r>=lX))return!1;let a=cH(t);return void 0!==a&&0===cK(a).length}(a)){if(o)return un("initialize-with-modern-header",n,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let t=ul(a)&&"string"==typeof a.protocolVersion?a.protocolVersion:void 0;return{kind:"legacy",reason:"initialize",...void 0!==t&&{requestedVersion:t}}}if(cJ(a)){let o=cH(a),s=(void 0===o?[]:cK(o))[0];if(void 0!==s)return ui("envelope","envelope-invalid",400,new cv(cg.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${s.key}: ${s.problem}`,{envelope:s}),!0);let l=cB(a);return void 0!==n&&void 0!==l&&n!==l?un("header-body-version-mismatch",n,`the body envelope names protocol version ${l} but the MCP-Protocol-Version header names ${n}`):void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==i?un("method-header-mismatch",t.mcpMethodHeader,`the body names method ${i} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"request",message:r,classification:uc(l)}}if(o){let t=cH(a),r=cK(t??{}).filter(t=>"missing"===t.problem).map(t=>t.key),i=void 0===t?["_meta"]:r.length>0?r:[nK];return ui("envelope","modern-header-without-claim",400,new cv(cg.InvalidParams,`Invalid params: the MCP-Protocol-Version header names protocol revision ${n}, but the request is missing the required per-request envelope key(s): ${i.join(", ")}`,{envelope:{missing:i}}),!0)}return{kind:"legacy",reason:"no-claim",...void 0!==n&&{requestedVersion:n}}}(t,r):ul(r)&&cY(r)?function(t,r){let a=r.params,i=r.method,n=t.protocolVersionHeader,o=void 0!==n&&n>=lX;if(cJ(a)){let o=cB(a);if(void 0===o){let t=cH(a),r=(void 0===t?[]:cK(t)).find(t=>t.key===nK)??{key:nK,problem:"expected a protocol version string"};return ui("envelope","notification-envelope-invalid",400,new cv(cg.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${r.key}: ${r.problem}`,{envelope:r}),!0)}if(void 0!==n&&n!==o)return un("notification-header-body-version-mismatch",n,`the notification envelope names protocol version ${o} but the MCP-Protocol-Version header names ${n}`);let s=uc(o);return"modern"===s.era&&void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==i?un("notification-method-header-mismatch",t.mcpMethodHeader,`the notification body names method ${i} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:r,classification:s}}return o?void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==i?un("notification-method-header-mismatch",t.mcpMethodHeader,`the notification body names method ${i} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:r,classification:{era:"modern",revision:n}}:{kind:"legacy",reason:"notification",...void 0!==n&&{requestedVersion:n}}}(t,r):ui("jsonrpc-shape","invalid-json-rpc-body",400,new cv(cg.InvalidRequest,"Bad Request: the request body is not a valid JSON-RPC message"),!0)}({httpMethod:o,...me(t),...void 0!==n&&{body:n}}),body:n,parsedBody:s,forwardRequest:l}}require("http"),require("http2");let mr=require("stream");var ma=a(6982),mi=global.Request,mn=class extends mi{constructor(t,r){"object"==typeof t&&ms in t&&(t=t[ms]()),void 0!==r?.body?.getReader&&(r.duplex??="half"),super(t,r)}},mo=Symbol("wrapBodyStream"),ms=Symbol("getRequestCache"),ml=Symbol("requestCache"),mc=Symbol("incomingKey"),mu=Symbol("urlKey"),md=Symbol("headersKey"),mp=Symbol("abortControllerKey"),mm=Symbol("getAbortController"),mh={get method(){return this[mc].method||"GET"},get url(){return this[mu]},get headers(){return this[md]||=(t=>{let r=[],a=t.rawHeaders;for(let t=0;t<a.length;t+=2){let{[t]:i,[t+1]:n}=a;58!==i.charCodeAt(0)&&r.push([i,n])}return new Headers(r)})(this[mc])},[mm](){return this[ms](),this[mp]},[ms](){return this[mp]||=new AbortController,this[ml]||=((t,r,a,i,n)=>{let o={method:t,headers:a,signal:n.signal};if("TRACE"===t){o.method="GET";let t=new mn(r,o);return Object.defineProperty(t,"method",{get:()=>"TRACE"}),t}if("GET"!==t&&"HEAD"!==t)if("rawBody"in i&&i.rawBody instanceof Buffer)o.body=new ReadableStream({start(t){t.enqueue(i.rawBody),t.close()}});else if(i[mo]){let t;o.body=new ReadableStream({async pull(r){try{t||=mr.Readable.toWeb(i).getReader();let{done:a,value:n}=await t.read();a?r.close():r.enqueue(n)}catch(t){r.error(t)}}})}else o.body=mr.Readable.toWeb(i);return new mn(r,o)})(this.method,this[mu],this.headers,this[mc],this[mp])}};["body","bodyUsed","cache","credentials","destination","integrity","mode","redirect","referrer","referrerPolicy","signal","keepalive"].forEach(t=>{Object.defineProperty(mh,t,{get(){return this[ms]()[t]}})}),["arrayBuffer","blob","clone","formData","json","text"].forEach(t=>{Object.defineProperty(mh,t,{value:function(){return this[ms]()[t]()}})}),Object.defineProperty(mh,Symbol.for("nodejs.util.inspect.custom"),{value:function(t,r,a){let i={method:this.method,url:this.url,headers:this.headers,nativeRequest:this[ml]};return`Request (lightweight) ${a(i,{...r,depth:null==t?null:t-1})}`}}),Object.setPrototypeOf(mh,mn.prototype);var mf=Symbol("responseCache"),my=Symbol("getResponseCache"),mg=Symbol("cache"),mv=global.Response,m_=class t{#e;#t;[my](){return delete this[mg],this[mf]||=new mv(this.#e,this.#t)}constructor(r,a){let i;if(this.#e=r,a instanceof t){const t=a[mf];if(t){this.#t=t,this[my]();return}this.#t=a.#t,i=new Headers(a.#t.headers)}else this.#t=a;("string"==typeof r||void 0!==r?.getReader||r instanceof Blob||r instanceof Uint8Array)&&(this[mg]=[a?.status||200,r,i||a?.headers])}get headers(){let t=this[mg];return t?(t[2]instanceof Headers||(t[2]=new Headers(t[2]||{"content-type":"text/plain; charset=UTF-8"})),t[2]):this[my]().headers}get status(){return this[mg]?.[0]??this[my]().status}get ok(){let t=this.status;return t>=200&&t<300}};function mb(t){return Array.isArray(t)?t[0]:t}async function mS(t,r,a){let i,n=(t.method??"GET").toUpperCase(),o=`http://${mb(t.headers.host)??mb(t.headers[":authority"])??"localhost"}${t.url??"/"}`,s=new Headers;for(let[r,a]of Object.entries(t.headers))if(!(void 0===a||r.startsWith(":")))if(Array.isArray(a))for(let t of a)s.append(r,t);else s.set(r,a);if("GET"!==n&&"HEAD"!==n)if(void 0===r){let r=new TextDecoder,a="";for await(let i of t)a+="string"==typeof i?i:r.decode(i,{stream:!0});(a+=r.decode()).length>0&&(i=a)}else{let t=JSON.stringify(r);s.delete("content-encoding"),s.delete("transfer-encoding"),void 0===t?s.delete("content-length"):(i=t,s.set("content-length",String(new TextEncoder().encode(t).byteLength)))}return new Request(o,{method:n,headers:s,...a?.signal!==void 0&&{signal:a.signal},...void 0!==i&&{body:i}})}["body","bodyUsed","redirected","statusText","trailers","type","url"].forEach(t=>{Object.defineProperty(m_.prototype,t,{get(){return this[my]()[t]}})}),["arrayBuffer","blob","clone","formData","json","text"].forEach(t=>{Object.defineProperty(m_.prototype,t,{value:function(){return this[my]()[t]()}})}),Object.defineProperty(m_.prototype,Symbol.for("nodejs.util.inspect.custom"),{value:function(t,r,a){let i={status:this.status,headers:this.headers,ok:this.ok,nativeResponse:this[mf]};return`Response (lightweight) ${a(i,{...r,depth:null==t?null:t-1})}`}}),Object.setPrototypeOf(m_,mv),Object.setPrototypeOf(m_.prototype,mv.prototype),void 0===global.crypto&&(global.crypto=ma),Symbol("outgoingEnded"),Symbol("incomingDraining");let m$=require("async_hooks"),mw=(t,r)=>{globalThis[t]=r},mR=t=>globalThis[t];function mk({name:t,fallback:r=!0}){let a=Symbol.for(`xmcp-context-${t}`),i=Symbol.for(`xmcp-context-${t}-fallback-store`);if(mR(a))return mR(a);let n=new m$.AsyncLocalStorage,o=globalThis[i]??{current:null};mw(i,o);let s={provider:(t,a)=>(r&&(o.current=t),n.run(t,a)),getContext:()=>{let a=n.getStore();if(a)return a;if(r&&o.current)return o.current;throw Error(`getContext() can only be used within the ${t} context.`)},setContext:a=>{let i=n.getStore()??(r?o.current:null);if(!i)throw Error(`setContext() can only be used within the ${t} context.`);Object.assign(i,a)}};return mw(a,s),s}let mx=mk({name:"http-request-context"});mx.setContext;let mP=mx.getContext,mE=mx.provider,mT=t=>"object"==typeof t&&null!==t&&!Array.isArray(t),mj=t=>{if(!mT(t)||"string"!=typeof t.name||"string"!=typeof t.version)return;let r={name:t.name,version:t.version};return"string"==typeof t.title&&(r.title=t.title),"string"==typeof t.websiteUrl&&(r.websiteUrl=t.websiteUrl),"string"==typeof t.description&&(r.description=t.description),r},mO=t=>{if(t&&"initialize"===t.method&&mT(t.params))return mj(t.params.clientInfo)},mC=(t,r)=>{let a=r.toLowerCase();for(let[r,i]of Object.entries(t)){if(r.toLowerCase()!==a)continue;let t=Array.isArray(i)?i[0]:i;if("string"!=typeof t)break;let n=t.trim();return n.length>0?n:void 0}};function mI(t){let{tags:r,enabled:a,...i}=t;return{...i,_meta:void 0===r?i._meta:{...i._meta,"xmcp/tags":r}}}let mN=new class{add(t,r){this.resources.set(t,r)}getAll(){return this.resources}clear(){this.resources.clear()}has(t){return this.resources.has(t)}constructor(){!function(t,r,a){r in t?Object.defineProperty(t,r,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[r]=a}(this,"resources",new Map)}},mq=mk({name:"request-context",fallback:!1}),mA=mk({name:"client-info-context"});mA.setContext;let mM=mA.getContext;mA.provider;let mz=new Set(["message","mode","requestedSchema"]),mL=new Set(["elicitationId","message","mode","url"]),mZ=new Set(["properties","required","type"]),mD=new Set(["default","description","format","maxLength","minLength","title","type"]),mU=new Set(["default","description","enum","enumNames","title","type"]),mV=new Set(["default","description","title","type"]),mF=new Set(["default","description","maximum","minimum","title","type"]),mH=new Set(["date","date-time","email","uri"]);async function mJ(t,r,a){let i=function(t){let r=t.mode??"form";if("url"===r)return function(t){let r;mK(t,"Elicitation request must be a plain object."),mB(t,mL,"URL elicitation"),mG(t.message,"URL elicitation requires a string message."),mW(t.elicitationId,"URL elicitation requires a non-empty elicitationId."),mW(t.url,"URL elicitation requires a non-empty URL.");try{r=new URL(t.url)}catch{throw Error("URL elicitation requires a valid http or https URL.")}if("http:"!==r.protocol&&"https:"!==r.protocol)throw Error("URL elicitation requires a valid http or https URL.")}(t),t;if("form"!==r)throw Error(`Unsupported elicitation mode "${String(t.mode)}". Expected "form" or "url".`);return function(t){mK(t,"Elicitation request must be a plain object."),mB(t,mz,"Form elicitation"),mG(t.message,"Form elicitation requires a string message.");let r=t.requestedSchema;if(mK(r,"Form elicitation requires a flat object schema."),mB(r,mZ,"Form elicitation schema"),"object"!==r.type)throw Error('Form elicitation schema must use type "object".');for(let[t,a]of(mK(r.properties,"Form elicitation schema requires a properties object."),Object.entries(r.properties)))!function(t,r){if(mK(r,`Form elicitation field "${t}" must be a plain object.`),mY(r.title,`Form elicitation field "${t}" title must be a string.`),mY(r.description,`Form elicitation field "${t}" description must be a string.`),"string"===r.type&&"enum"in r){var a,i;if(mB(r,mU,`Form elicitation field "${t}"`),mQ(r.enum,`Form elicitation field "${t}" enum values must be strings.`),a=r.enumNames,i=`Form elicitation field "${t}" enumNames must be strings.`,void 0!==a&&mQ(a,i),void 0!==r.enumNames&&r.enumNames.length!==r.enum.length)throw Error(`Form elicitation field "${t}" enumNames length must match enum length.`);if(mY(r.default,`Form elicitation field "${t}" default must be a string.`),void 0!==r.default&&!r.enum.includes(r.default))throw Error(`Form elicitation field "${t}" default must be one of its enum values.`);return}if("string"===r.type&&!("enum"in r)){mB(r,mD,`Form elicitation field "${t}"`),mX(r.minLength,`Form elicitation field "${t}" minLength must be a number.`),mX(r.maxLength,`Form elicitation field "${t}" maxLength must be a number.`),mY(r.default,`Form elicitation field "${t}" default must be a string.`);let a=r.format;if(mY(a,`Form elicitation field "${t}" format must be a string.`),void 0!==a&&!mH.has(a))throw Error(`Form elicitation field "${t}" format must be one of: ${Array.from(mH).join(", ")}.`);return}if("boolean"===r.type){if(mB(r,mV,`Form elicitation field "${t}"`),void 0!==r.default&&"boolean"!=typeof r.default)throw Error(`Form elicitation field "${t}" default must be a boolean.`);return}if("number"===r.type||"integer"===r.type){mB(r,mF,`Form elicitation field "${t}"`),mX(r.minimum,`Form elicitation field "${t}" minimum must be a number.`),mX(r.maximum,`Form elicitation field "${t}" maximum must be a number.`),mX(r.default,`Form elicitation field "${t}" default must be a number.`);return}throw Error(`Form elicitation field "${t}" uses unsupported type "${String(r.type)}". Supported types are string, boolean, number, integer, and string enums.`)}(t,a);if(void 0!==r.required){if(!Array.isArray(r.required)||r.required.some(t=>"string"!=typeof t))throw Error("Form elicitation schema required fields must be a string array.");for(let t of r.required)if(!(t in r.properties))throw Error(`Form elicitation schema required field "${t}" is not defined in properties.`)}}(t),{...t,mode:"form"}}(r);try{let r=await t.mcpReq.elicitInput(i,a);return{...r,content:r.content??void 0}}catch(t){if(t instanceof lK&&t.code===lB.MethodNotSupportedByProtocolVersion)throw Error("extra.elicit() is not available on protocol revision 2026-07-28: server-initiated elicitation was replaced by multi round-trip requests. Return inputRequired({ ... }) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw t}}function mB(t,r,a){let i=Object.keys(t).filter(t=>!r.has(t));if(0!==i.length)throw Error(`${a} includes unsupported key(s): ${i.join(", ")}.`)}function mK(t,r){if("object"!=typeof t||null===t||Array.isArray(t))throw Error(r)}function mG(t,r){if("string"!=typeof t)throw Error(r)}function mW(t,r){if("string"!=typeof t||0===t.trim().length)throw Error(r)}function mY(t,r){if(void 0!==t&&"string"!=typeof t)throw Error(r)}function mX(t,r){if(void 0!==t&&"number"!=typeof t)throw Error(r)}function mQ(t,r){if(!Array.isArray(t)||t.some(t=>"string"!=typeof t))throw Error(r)}let m0=new Set(["_meta","includeContext","maxTokens","messages","metadata","modelPreferences","stopSequences","systemPrompt","temperature"]),m1=new Set(["task","toolChoice","tools"]),m2=new Set(["text","image","audio"]);async function m9(t,r,a){let i=function(t){m4(t,"Sampling request must be a plain object.");let r=Object.keys(t),a=r.filter(t=>m1.has(t));if(a.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${a.join(", ")}.`);let i=r.filter(t=>!m0.has(t));if(i.length>0)throw Error(`Sampling request includes unsupported key(s): ${i.join(", ")}.`);if(!Array.isArray(t.messages)||0===t.messages.length)throw Error("Sampling requires at least one message.");for(let[r,a]of t.messages.entries())!function(t,r){if(m4(r,`Sampling message at index ${t} must be a plain object.`),"user"!==r.role&&"assistant"!==r.role)throw Error(`Sampling message at index ${t} requires role "user" or "assistant".`);let a=r.content;m4(a,`Sampling message at index ${t} requires a content object.`);let i=a.type;if("string"!=typeof i||!m2.has(i))throw Error(`Sampling message at index ${t} uses unsupported content type "${String(i)}". Supported types are text, image, and audio.`);if("text"===i&&"string"!=typeof a.text)throw Error(`Sampling message at index ${t} requires string text content.`);if(("image"===i||"audio"===i)&&("string"!=typeof a.data||"string"!=typeof a.mimeType))throw Error(`Sampling message at index ${t} requires base64 data and a mimeType.`)}(r,a);if("number"!=typeof t.maxTokens)throw Error("Sampling requires a numeric maxTokens.");return t}(r);try{return await t.mcpReq.requestSampling(i,a)}catch(t){if(t instanceof lK&&t.code===lB.MethodNotSupportedByProtocolVersion)throw Error("extra.sample() is not available on protocol revision 2026-07-28: server-initiated sampling was replaced by multi round-trip requests. Return inputRequired({ ... }) with inputRequired.createMessage(...) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw t}}function m4(t,r){if("object"!=typeof t||null===t||Array.isArray(t))throw Error(r)}let m3={text:t=>"string"!=typeof t.text?{valid:!1,error:'Text content must have a "text" property of type string'}:{valid:!0},image:t=>"string"!=typeof t.data?{valid:!1,error:'Image content must have a "data" property of type string (base64-encoded image)'}:"string"!=typeof t.mimeType?{valid:!1,error:'Image content must have a "mimeType" property of type string'}:{valid:!0},audio:t=>"string"!=typeof t.data?{valid:!1,error:'Audio content must have a "data" property of type string (base64-encoded audio)'}:"string"!=typeof t.mimeType?{valid:!1,error:'Audio content must have a "mimeType" property of type string'}:{valid:!0},resource_link:t=>"string"!=typeof t.name?{valid:!1,error:'Resource link content must have a "name" property of type string'}:"string"!=typeof t.uri?{valid:!1,error:'Resource link content must have a "uri" property of type string'}:void 0!==t.title&&"string"!=typeof t.title?{valid:!1,error:'Resource link "title" property must be a string if provided'}:void 0!==t.description&&"string"!=typeof t.description?{valid:!1,error:'Resource link "description" property must be a string if provided'}:void 0!==t.mimeType&&"string"!=typeof t.mimeType?{valid:!1,error:'Resource link "mimeType" property must be a string if provided'}:{valid:!0}};function m6(t){if(!t||"object"!=typeof t)return{valid:!1,error:"Content must be an object"};if("string"!=typeof t.type)return{valid:!1,error:'Content must have a "type" property of type string'};if(void 0!==t._meta&&(null===t._meta||"object"!=typeof t._meta))return{valid:!1,error:'Content "_meta" property must be an object if provided'};let r=m3[t.type];return r?r(t):{valid:!0}}function m5(t,r,a,i){if(null===t||"object"!=typeof t||Array.isArray(t))throw Error(`Tool "${a}" ${i}: expected a plain object.`);let n=new Set(Object.keys(r)),o=Object.keys(t).filter(t=>!n.has(t));if(o.length>0)throw Error(`Tool "${a}" ${i}: unrecognized key(s): ${o.join(", ")}`);for(let[n,o]of Object.entries(r))try{o.parse(t[n])}catch(t){throw Error(`Tool "${a}" ${i}: ${t?.message??`invalid field "${n}"`}`)}}function m8(t){return!!(t&&"object"==typeof t&&Object.keys(t).some(t=>t.startsWith("ui/")))}function m7(t){let r=t.mcpReq.envelope,a=mj(r?.[nG]);if(!a)try{let t,r=mP();a=r.clientInfo??(t=r.headers,mj({name:mC(t,"x-mcp-client-name"),version:mC(t,"x-mcp-client-version"),title:mC(t,"x-mcp-client-title"),websiteUrl:mC(t,"x-mcp-client-website-url"),description:mC(t,"x-mcp-client-description")}))}catch{}if(!a)try{a=mM().clientInfo}catch{}return a}function he(t){let r=[...t];return(t,a,i)=>(function(t,r,a){let i,n=new Map;if(t.http){let t=mP(),r=Object.fromEntries(Object.entries(t.headers).map(([t,r])=>[t,Array.isArray(r)?Object.freeze([...r]):r]));i=Object.freeze({id:t.id,headers:Object.freeze(r)})}return mq.provider(Object.freeze({clientInfo:r?Object.freeze({...r}):void 0,http:i,authInfo:t.http?.authInfo,signal:t.mcpReq.signal,set(t,r){n.set(t,r)},get:t=>n.get(t),async progress(r,a){let i=t.mcpReq._meta?.progressToken;void 0!==i&&await t.mcpReq.notify({method:"notifications/progress",params:{progressToken:i,progress:r,...void 0===a?{}:{total:a}}})},log:(r,a)=>t.mcpReq.log(r,a)}),a)})(a,m7(a),async()=>{if(0===r.length)return i();let a=Object.freeze({...function(){try{return mq.getContext()}catch{throw Error("getRequestContext() can only be used while handling an MCP request.")}}(),...t,params:Object.freeze({...t.params})}),n=-1,o=async t=>{if(t<=n)throw Error("MCP middleware next() can only be called once");n=t;let s=r[t];return s?s(a,()=>o(t+1)):i()};return o(0)})}let ht=new Set(["tools/list","prompts/get","prompts/list","resources/read","resources/list","resources/templates/list","completion/complete"]);function hr(t){return t.endsWith(".tsx")}let ha=Symbol("Let zodToJsonSchema decide on which parser to use"),hi={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=M||(M={})).assertEqual=t=>{},T.assertIs=function(t){},T.assertNever=function(t){throw Error()},T.arrayToEnum=t=>{let r={};for(let a of t)r[a]=a;return r},T.getValidEnumValues=t=>{let r=T.objectKeys(t).filter(r=>"number"!=typeof t[t[r]]),a={};for(let i of r)a[i]=t[i];return T.objectValues(a)},T.objectValues=t=>T.objectKeys(t).map(function(r){return t[r]}),T.objectKeys="function"==typeof Object.keys?t=>Object.keys(t):t=>{let r=[];for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&r.push(a);return r},T.find=(t,r)=>{for(let a of t)if(r(a))return a},T.isInteger="function"==typeof Number.isInteger?t=>Number.isInteger(t):t=>"number"==typeof t&&Number.isFinite(t)&&Math.floor(t)===t,T.joinValues=function(t,r=" | "){return t.map(t=>"string"==typeof t?`'${t}'`:t).join(r)},T.jsonStringifyReplacer=(t,r)=>"bigint"==typeof r?r.toString():r,(z||(z={})).mergeShapes=(t,r)=>({...t,...r});let hn=M.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),ho=t=>{switch(typeof t){case"undefined":return hn.undefined;case"string":return hn.string;case"number":return Number.isNaN(t)?hn.nan:hn.number;case"boolean":return hn.boolean;case"function":return hn.function;case"bigint":return hn.bigint;case"symbol":return hn.symbol;case"object":if(Array.isArray(t))return hn.array;if(null===t)return hn.null;if(t.then&&"function"==typeof t.then&&t.catch&&"function"==typeof t.catch)return hn.promise;if("undefined"!=typeof Map&&t instanceof Map)return hn.map;if("undefined"!=typeof Set&&t instanceof Set)return hn.set;if("undefined"!=typeof Date&&t instanceof Date)return hn.date;return hn.object;default:return hn.unknown}},hs=M.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 hl extends Error{get errors(){return this.issues}constructor(t){super(),this.issues=[],this.addIssue=t=>{this.issues=[...this.issues,t]},this.addIssues=(t=[])=>{this.issues=[...this.issues,...t]};const r=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,r):this.__proto__=r,this.name="ZodError",this.issues=t}format(t){let r=t||function(t){return t.message},a={_errors:[]},i=t=>{for(let n of t.issues)if("invalid_union"===n.code)n.unionErrors.map(i);else if("invalid_return_type"===n.code)i(n.returnTypeError);else if("invalid_arguments"===n.code)i(n.argumentsError);else if(0===n.path.length)a._errors.push(r(n));else{let t=a,i=0;for(;i<n.path.length;){let a=n.path[i],o=i===n.path.length-1;if("_errors"===a){o&&t._errors.push(r(n)),i++;continue}Object.prototype.hasOwnProperty.call(t,a)||("__proto__"===a?Object.defineProperty(t,a,{value:{_errors:[]},writable:!0,enumerable:!0,configurable:!0}):t[a]={_errors:[]}),t=t[a],o&&t._errors.push(r(n)),i++}}};return i(this),a}static assert(t){if(!(t instanceof hl))throw Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,M.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(t=t=>t.message){let r=Object.create(null),a=[];for(let i of this.issues)if(i.path.length>0){let a=i.path[0];r[a]=r[a]||[],r[a].push(t(i))}else a.push(t(i));return{formErrors:a,fieldErrors:r}}get formErrors(){return this.flatten()}}hl.create=t=>new hl(t);let hc=(t,r)=>{let a;switch(t.code){case hs.invalid_type:a=t.received===hn.undefined?"Required":`Expected ${t.expected}, received ${t.received}`;break;case hs.invalid_literal:a=`Invalid literal value, expected ${JSON.stringify(t.expected,M.jsonStringifyReplacer)}`;break;case hs.unrecognized_keys:a=`Unrecognized key(s) in object: ${M.joinValues(t.keys,", ")}`;break;case hs.invalid_union:a="Invalid input";break;case hs.invalid_union_discriminator:a=`Invalid discriminator value. Expected ${M.joinValues(t.options)}`;break;case hs.invalid_enum_value:a=`Invalid enum value. Expected ${M.joinValues(t.options)}, received '${t.received}'`;break;case hs.invalid_arguments:a="Invalid function arguments";break;case hs.invalid_return_type:a="Invalid function return type";break;case hs.invalid_date:a="Invalid date";break;case hs.invalid_string:"object"==typeof t.validation?"includes"in t.validation?(a=`Invalid input: must include "${t.validation.includes}"`,"number"==typeof t.validation.position&&(a=`${a} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?a=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?a=`Invalid input: must end with "${t.validation.endsWith}"`:M.assertNever(t.validation):a="regex"!==t.validation?`Invalid ${t.validation}`:"Invalid";break;case hs.too_small:a="array"===t.type?`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:"string"===t.type?`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:"number"===t.type||"bigint"===t.type?`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:"date"===t.type?`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:"Invalid input";break;case hs.too_big:a="array"===t.type?`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:"string"===t.type?`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:"number"===t.type?`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:"bigint"===t.type?`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:"date"===t.type?`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:"Invalid input";break;case hs.custom:a="Invalid input";break;case hs.invalid_intersection_types:a="Intersection results could not be merged";break;case hs.not_multiple_of:a=`Number must be a multiple of ${t.multipleOf}`;break;case hs.not_finite:a="Number must be finite";break;default:a=r.defaultError,M.assertNever(t)}return{message:a}};(j=L||(L={})).errToObj=t=>"string"==typeof t?{message:t}:t||{},j.toString=t=>"string"==typeof t?t:t?.message;let hu=t=>{let{data:r,path:a,errorMaps:i,issueData:n}=t,o=[...a,...n.path||[]],s={...n,path:o};if(void 0!==n.message)return{...n,path:o,message:n.message};let l="";for(let t of i.filter(t=>!!t).slice().reverse())l=t(s,{data:r,defaultError:l}).message;return{...n,path:o,message:l}};function hd(t,r){let a=hu({issueData:r,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,hc,void 0].filter(t=>!!t)});t.common.issues.push(a)}class hp{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(t,r){let a=[];for(let i of r){if("aborted"===i.status)return hm;"dirty"===i.status&&t.dirty(),a.push(i.value)}return{status:t.value,value:a}}static async mergeObjectAsync(t,r){let a=[];for(let t of r){let r=await t.key,i=await t.value;a.push({key:r,value:i})}return hp.mergeObjectSync(t,a)}static mergeObjectSync(t,r){let a={};for(let i of r){let{key:r,value:n}=i;if("aborted"===r.status||"aborted"===n.status)return hm;"dirty"===r.status&&t.dirty(),"dirty"===n.status&&t.dirty(),"__proto__"!==r.value&&(void 0!==n.value||i.alwaysSet)&&(a[r.value]=n.value)}return{status:t.value,value:a}}}let hm=Object.freeze({status:"aborted"}),hh=t=>({status:"dirty",value:t}),hf=t=>({status:"valid",value:t}),hy=t=>"undefined"!=typeof Promise&&t instanceof Promise;class hg{constructor(t,r,a,i){this._cachedPath=[],this.parent=t,this.data=r,this._path=a,this._key=i}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}let hv=(t,r)=>{if("valid"===r.status)return{success:!0,data:r.value};if(!t.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let r=new hl(t.common.issues);return this._error=r,this._error}}};function h_(t){if(!t)return{};let{errorMap:r,invalid_type_error:a,required_error:i,description:n}=t;if(r&&(a||i))throw Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');return r?{errorMap:r,description:n}:{errorMap:(r,n)=>{let{message:o}=t;return"invalid_enum_value"===r.code?{message:o??n.defaultError}:void 0===n.data?{message:o??i??n.defaultError}:"invalid_type"!==r.code?{message:n.defaultError}:{message:o??a??n.defaultError}},description:n}}class hb{get description(){return this._def.description}_getType(t){return ho(t.data)}_getOrReturnCtx(t,r){return r||{common:t.parent.common,data:t.data,parsedType:ho(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new hp,ctx:{common:t.parent.common,data:t.data,parsedType:ho(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){let r=this._parse(t);if(hy(r))throw Error("Synchronous parse encountered promise.");return r}_parseAsync(t){return Promise.resolve(this._parse(t))}parse(t,r){let a=this.safeParse(t,r);if(a.success)return a.data;throw a.error}safeParse(t,r){let a={common:{issues:[],async:r?.async??!1,contextualErrorMap:r?.errorMap},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:ho(t)},i=this._parseSync({data:t,path:a.path,parent:a});return hv(a,i)}"~validate"(t){let r={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:ho(t)};if(!this["~standard"].async)try{let a=this._parseSync({data:t,path:[],parent:r});return"valid"===a.status?{value:a.value}:{issues:r.common.issues}}catch(t){t?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),r.common={issues:[],async:!0}}return this._parseAsync({data:t,path:[],parent:r}).then(t=>"valid"===t.status?{value:t.value}:{issues:r.common.issues})}async parseAsync(t,r){let a=await this.safeParseAsync(t,r);if(a.success)return a.data;throw a.error}async safeParseAsync(t,r){let a={common:{issues:[],contextualErrorMap:r?.errorMap,async:!0},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:ho(t)},i=this._parse({data:t,path:a.path,parent:a});return hv(a,await (hy(i)?i:Promise.resolve(i)))}refine(t,r){return this._refinement((a,i)=>{let n=t(a),o=()=>i.addIssue({code:hs.custom,..."string"==typeof r||void 0===r?{message:r}:"function"==typeof r?r(a):r});return"undefined"!=typeof Promise&&n instanceof Promise?n.then(t=>!!t||(o(),!1)):!!n||(o(),!1)})}refinement(t,r){return this._refinement((a,i)=>!!t(a)||(i.addIssue("function"==typeof r?r(a,i):r),!1))}_refinement(t){return new fa({schema:this,typeName:Z.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}constructor(t){this.spa=this.safeParseAsync,this._def=t,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:t=>this["~validate"](t)}}optional(){return fi.create(this,this._def)}nullable(){return fn.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return hW.create(this)}promise(){return fr.create(this,this._def)}or(t){return hX.create([this,t],this._def)}and(t){return h1.create(this,t,this._def)}transform(t){return new fa({...h_(this._def),schema:this,typeName:Z.ZodEffects,effect:{type:"transform",transform:t}})}default(t){return new fo({...h_(this._def),innerType:this,defaultValue:"function"==typeof t?t:()=>t,typeName:Z.ZodDefault})}brand(){return new fc({typeName:Z.ZodBranded,type:this,...h_(this._def)})}catch(t){return new fs({...h_(this._def),innerType:this,catchValue:"function"==typeof t?t:()=>t,typeName:Z.ZodCatch})}describe(t){return new this.constructor({...this._def,description:t})}pipe(t){return fu.create(this,t)}readonly(){return fd.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}let hS=/^c[^\s-]{8,}$/i,h$=/^[0-9a-z]+$/,hw=/^[0-9A-HJKMNP-TV-Z]{26}$/i,hR=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,hk=/^[a-z0-9_-]{21}$/i,hx=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,hP=/^[-+]?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])$/,hj=/^(?:(?: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])$/,hO=/^(([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]))$/,hC=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,hI=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,hN=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,hq="((\\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])))",hA=RegExp(`^${hq}$`);function hM(t){let r="[0-5]\\d";t.precision?r=`${r}\\.\\d{${t.precision}}`:null==t.precision&&(r=`${r}(\\.\\d+)?`);let a=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${r})${a}`}class hz extends hb{_parse(t){var r,a,i,n;let o;if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==hn.string){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.string,received:r.parsedType}),hm}let s=new hp;for(let l of this._def.checks)if("min"===l.kind)t.data.length<l.value&&(hd(o=this._getOrReturnCtx(t,o),{code:hs.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),s.dirty());else if("max"===l.kind)t.data.length>l.value&&(hd(o=this._getOrReturnCtx(t,o),{code:hs.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),s.dirty());else if("length"===l.kind){let r=t.data.length>l.value,a=t.data.length<l.value;(r||a)&&(o=this._getOrReturnCtx(t,o),r?hd(o,{code:hs.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}):a&&hd(o,{code:hs.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}),s.dirty())}else if("email"===l.kind)hE.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"email",code:hs.invalid_string,message:l.message}),s.dirty());else if("emoji"===l.kind)h||(h=RegExp("^[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$","u")),h.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"emoji",code:hs.invalid_string,message:l.message}),s.dirty());else if("uuid"===l.kind)hR.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"uuid",code:hs.invalid_string,message:l.message}),s.dirty());else if("nanoid"===l.kind)hk.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"nanoid",code:hs.invalid_string,message:l.message}),s.dirty());else if("cuid"===l.kind)hS.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"cuid",code:hs.invalid_string,message:l.message}),s.dirty());else if("cuid2"===l.kind)h$.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"cuid2",code:hs.invalid_string,message:l.message}),s.dirty());else if("ulid"===l.kind)hw.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"ulid",code:hs.invalid_string,message:l.message}),s.dirty());else if("url"===l.kind)try{new URL(t.data)}catch{hd(o=this._getOrReturnCtx(t,o),{validation:"url",code:hs.invalid_string,message:l.message}),s.dirty()}else"regex"===l.kind?(l.regex.lastIndex=0,l.regex.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"regex",code:hs.invalid_string,message:l.message}),s.dirty())):"trim"===l.kind?t.data=t.data.trim():"includes"===l.kind?t.data.includes(l.value,l.position)||(hd(o=this._getOrReturnCtx(t,o),{code:hs.invalid_string,validation:{includes:l.value,position:l.position},message:l.message}),s.dirty()):"toLowerCase"===l.kind?t.data=t.data.toLowerCase():"toUpperCase"===l.kind?t.data=t.data.toUpperCase():"startsWith"===l.kind?t.data.startsWith(l.value)||(hd(o=this._getOrReturnCtx(t,o),{code:hs.invalid_string,validation:{startsWith:l.value},message:l.message}),s.dirty()):"endsWith"===l.kind?t.data.endsWith(l.value)||(hd(o=this._getOrReturnCtx(t,o),{code:hs.invalid_string,validation:{endsWith:l.value},message:l.message}),s.dirty()):"datetime"===l.kind?(function(t){let r=`${hq}T${hM(t)}`,a=[];return a.push(t.local?"Z?":"Z"),t.offset&&a.push("([+-]\\d{2}:?\\d{2})"),r=`${r}(${a.join("|")})`,RegExp(`^${r}$`)})(l).test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{code:hs.invalid_string,validation:"datetime",message:l.message}),s.dirty()):"date"===l.kind?hA.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{code:hs.invalid_string,validation:"date",message:l.message}),s.dirty()):"time"===l.kind?RegExp(`^${hM(l)}$`).test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{code:hs.invalid_string,validation:"time",message:l.message}),s.dirty()):"duration"===l.kind?hP.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"duration",code:hs.invalid_string,message:l.message}),s.dirty()):"ip"===l.kind?(r=t.data,!(("v4"===(a=l.version)||!a)&&hT.test(r)||("v6"===a||!a)&&hO.test(r))&&1&&(hd(o=this._getOrReturnCtx(t,o),{validation:"ip",code:hs.invalid_string,message:l.message}),s.dirty())):"jwt"===l.kind?!function(t,r){if(!hx.test(t))return!1;try{let[a]=t.split(".");if(!a)return!1;let i=a.replace(/-/g,"+").replace(/_/g,"/").padEnd(a.length+(4-a.length%4)%4,"="),n=JSON.parse(atob(i));if("object"!=typeof n||null===n||"typ"in n&&n?.typ!=="JWT"||!n.alg||r&&n.alg!==r)return!1;return!0}catch{return!1}}(t.data,l.alg)&&(hd(o=this._getOrReturnCtx(t,o),{validation:"jwt",code:hs.invalid_string,message:l.message}),s.dirty()):"cidr"===l.kind?(i=t.data,!(("v4"===(n=l.version)||!n)&&hj.test(i)||("v6"===n||!n)&&hC.test(i))&&1&&(hd(o=this._getOrReturnCtx(t,o),{validation:"cidr",code:hs.invalid_string,message:l.message}),s.dirty())):"base64"===l.kind?hI.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"base64",code:hs.invalid_string,message:l.message}),s.dirty()):"base64url"===l.kind?hN.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"base64url",code:hs.invalid_string,message:l.message}),s.dirty()):M.assertNever(l);return{status:s.value,value:t.data}}_regex(t,r,a){return this.refinement(r=>t.test(r),{validation:r,code:hs.invalid_string,...L.errToObj(a)})}_addCheck(t){return new hz({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...L.errToObj(t)})}url(t){return this._addCheck({kind:"url",...L.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...L.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...L.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...L.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...L.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...L.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...L.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...L.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...L.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...L.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...L.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...L.errToObj(t)})}datetime(t){return"string"==typeof t?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:t}):this._addCheck({kind:"datetime",precision:void 0===t?.precision?null:t?.precision,offset:t?.offset??!1,local:t?.local??!1,...L.errToObj(t?.message)})}date(t){return this._addCheck({kind:"date",message:t})}time(t){return"string"==typeof t?this._addCheck({kind:"time",precision:null,message:t}):this._addCheck({kind:"time",precision:void 0===t?.precision?null:t?.precision,...L.errToObj(t?.message)})}duration(t){return this._addCheck({kind:"duration",...L.errToObj(t)})}regex(t,r){return this._addCheck({kind:"regex",regex:t,...L.errToObj(r)})}includes(t,r){return this._addCheck({kind:"includes",value:t,position:r?.position,...L.errToObj(r?.message)})}startsWith(t,r){return this._addCheck({kind:"startsWith",value:t,...L.errToObj(r)})}endsWith(t,r){return this._addCheck({kind:"endsWith",value:t,...L.errToObj(r)})}min(t,r){return this._addCheck({kind:"min",value:t,...L.errToObj(r)})}max(t,r){return this._addCheck({kind:"max",value:t,...L.errToObj(r)})}length(t,r){return this._addCheck({kind:"length",value:t,...L.errToObj(r)})}nonempty(t){return this.min(1,L.errToObj(t))}trim(){return new hz({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new hz({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new hz({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(t=>"datetime"===t.kind)}get isDate(){return!!this._def.checks.find(t=>"date"===t.kind)}get isTime(){return!!this._def.checks.find(t=>"time"===t.kind)}get isDuration(){return!!this._def.checks.find(t=>"duration"===t.kind)}get isEmail(){return!!this._def.checks.find(t=>"email"===t.kind)}get isURL(){return!!this._def.checks.find(t=>"url"===t.kind)}get isEmoji(){return!!this._def.checks.find(t=>"emoji"===t.kind)}get isUUID(){return!!this._def.checks.find(t=>"uuid"===t.kind)}get isNANOID(){return!!this._def.checks.find(t=>"nanoid"===t.kind)}get isCUID(){return!!this._def.checks.find(t=>"cuid"===t.kind)}get isCUID2(){return!!this._def.checks.find(t=>"cuid2"===t.kind)}get isULID(){return!!this._def.checks.find(t=>"ulid"===t.kind)}get isIP(){return!!this._def.checks.find(t=>"ip"===t.kind)}get isCIDR(){return!!this._def.checks.find(t=>"cidr"===t.kind)}get isBase64(){return!!this._def.checks.find(t=>"base64"===t.kind)}get isBase64url(){return!!this._def.checks.find(t=>"base64url"===t.kind)}get minLength(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxLength(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}}hz.create=t=>new hz({checks:[],typeName:Z.ZodString,coerce:t?.coerce??!1,...h_(t)});class hL extends hb{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){let r;if(this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==hn.number){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.number,received:r.parsedType}),hm}let a=new hp;for(let i of this._def.checks)"int"===i.kind?M.isInteger(t.data)||(hd(r=this._getOrReturnCtx(t,r),{code:hs.invalid_type,expected:"integer",received:"float",message:i.message}),a.dirty()):"min"===i.kind?(i.inclusive?t.data<i.value:t.data<=i.value)&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),a.dirty()):"max"===i.kind?(i.inclusive?t.data>i.value:t.data>=i.value)&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),a.dirty()):"multipleOf"===i.kind?0!==function(t,r){let a=(t.toString().split(".")[1]||"").length,i=(r.toString().split(".")[1]||"").length,n=a>i?a:i;return Number.parseInt(t.toFixed(n).replace(".",""))%Number.parseInt(r.toFixed(n).replace(".",""))/10**n}(t.data,i.value)&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.not_multiple_of,multipleOf:i.value,message:i.message}),a.dirty()):"finite"===i.kind?Number.isFinite(t.data)||(hd(r=this._getOrReturnCtx(t,r),{code:hs.not_finite,message:i.message}),a.dirty()):M.assertNever(i);return{status:a.value,value:t.data}}gte(t,r){return this.setLimit("min",t,!0,L.toString(r))}gt(t,r){return this.setLimit("min",t,!1,L.toString(r))}lte(t,r){return this.setLimit("max",t,!0,L.toString(r))}lt(t,r){return this.setLimit("max",t,!1,L.toString(r))}setLimit(t,r,a,i){return new hL({...this._def,checks:[...this._def.checks,{kind:t,value:r,inclusive:a,message:L.toString(i)}]})}_addCheck(t){return new hL({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:L.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:L.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:L.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:L.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:L.toString(t)})}multipleOf(t,r){return this._addCheck({kind:"multipleOf",value:t,message:L.toString(r)})}finite(t){return this._addCheck({kind:"finite",message:L.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:L.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:L.toString(t)})}get minValue(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxValue(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}get isInt(){return!!this._def.checks.find(t=>"int"===t.kind||"multipleOf"===t.kind&&M.isInteger(t.value))}get isFinite(){let t=null,r=null;for(let a of this._def.checks)if("finite"===a.kind||"int"===a.kind||"multipleOf"===a.kind)return!0;else"min"===a.kind?(null===r||a.value>r)&&(r=a.value):"max"===a.kind&&(null===t||a.value<t)&&(t=a.value);return Number.isFinite(r)&&Number.isFinite(t)}}hL.create=t=>new hL({checks:[],typeName:Z.ZodNumber,coerce:t?.coerce||!1,...h_(t)});class hZ extends hb{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){let r;if(this._def.coerce)try{t.data=BigInt(t.data)}catch{return this._getInvalidInput(t)}if(this._getType(t)!==hn.bigint)return this._getInvalidInput(t);let a=new hp;for(let i of this._def.checks)"min"===i.kind?(i.inclusive?t.data<i.value:t.data<=i.value)&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),a.dirty()):"max"===i.kind?(i.inclusive?t.data>i.value:t.data>=i.value)&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),a.dirty()):"multipleOf"===i.kind?t.data%i.value!==BigInt(0)&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.not_multiple_of,multipleOf:i.value,message:i.message}),a.dirty()):M.assertNever(i);return{status:a.value,value:t.data}}_getInvalidInput(t){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.bigint,received:r.parsedType}),hm}gte(t,r){return this.setLimit("min",t,!0,L.toString(r))}gt(t,r){return this.setLimit("min",t,!1,L.toString(r))}lte(t,r){return this.setLimit("max",t,!0,L.toString(r))}lt(t,r){return this.setLimit("max",t,!1,L.toString(r))}setLimit(t,r,a,i){return new hZ({...this._def,checks:[...this._def.checks,{kind:t,value:r,inclusive:a,message:L.toString(i)}]})}_addCheck(t){return new hZ({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:L.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:L.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:L.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:L.toString(t)})}multipleOf(t,r){return this._addCheck({kind:"multipleOf",value:t,message:L.toString(r)})}get minValue(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxValue(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}}hZ.create=t=>new hZ({checks:[],typeName:Z.ZodBigInt,coerce:t?.coerce??!1,...h_(t)});class hD extends hb{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==hn.boolean){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.boolean,received:r.parsedType}),hm}return hf(t.data)}}hD.create=t=>new hD({typeName:Z.ZodBoolean,coerce:t?.coerce||!1,...h_(t)});class hU extends hb{_parse(t){let r;if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==hn.date){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.date,received:r.parsedType}),hm}if(Number.isNaN(t.data.getTime()))return hd(this._getOrReturnCtx(t),{code:hs.invalid_date}),hm;let a=new hp;for(let i of this._def.checks)"min"===i.kind?t.data.getTime()<i.value&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),a.dirty()):"max"===i.kind?t.data.getTime()>i.value&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),a.dirty()):M.assertNever(i);return{status:a.value,value:new Date(t.data.getTime())}}_addCheck(t){return new hU({...this._def,checks:[...this._def.checks,t]})}min(t,r){return this._addCheck({kind:"min",value:t.getTime(),message:L.toString(r)})}max(t,r){return this._addCheck({kind:"max",value:t.getTime(),message:L.toString(r)})}get minDate(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return null!=t?new Date(t):null}get maxDate(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return null!=t?new Date(t):null}}hU.create=t=>new hU({checks:[],coerce:t?.coerce||!1,typeName:Z.ZodDate,...h_(t)});class hV extends hb{_parse(t){if(this._getType(t)!==hn.symbol){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.symbol,received:r.parsedType}),hm}return hf(t.data)}}hV.create=t=>new hV({typeName:Z.ZodSymbol,...h_(t)});class hF extends hb{_parse(t){if(this._getType(t)!==hn.undefined){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.undefined,received:r.parsedType}),hm}return hf(t.data)}}hF.create=t=>new hF({typeName:Z.ZodUndefined,...h_(t)});class hH extends hb{_parse(t){if(this._getType(t)!==hn.null){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.null,received:r.parsedType}),hm}return hf(t.data)}}hH.create=t=>new hH({typeName:Z.ZodNull,...h_(t)});class hJ extends hb{constructor(){super(...arguments),this._any=!0}_parse(t){return hf(t.data)}}hJ.create=t=>new hJ({typeName:Z.ZodAny,...h_(t)});class hB extends hb{constructor(){super(...arguments),this._unknown=!0}_parse(t){return hf(t.data)}}hB.create=t=>new hB({typeName:Z.ZodUnknown,...h_(t)});class hK extends hb{_parse(t){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.never,received:r.parsedType}),hm}}hK.create=t=>new hK({typeName:Z.ZodNever,...h_(t)});class hG extends hb{_parse(t){if(this._getType(t)!==hn.undefined){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.void,received:r.parsedType}),hm}return hf(t.data)}}hG.create=t=>new hG({typeName:Z.ZodVoid,...h_(t)});class hW extends hb{_parse(t){let{ctx:r,status:a}=this._processInputParams(t),i=this._def;if(r.parsedType!==hn.array)return hd(r,{code:hs.invalid_type,expected:hn.array,received:r.parsedType}),hm;if(null!==i.exactLength){let t=r.data.length>i.exactLength.value,n=r.data.length<i.exactLength.value;(t||n)&&(hd(r,{code:t?hs.too_big:hs.too_small,minimum:n?i.exactLength.value:void 0,maximum:t?i.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:i.exactLength.message}),a.dirty())}if(null!==i.minLength&&r.data.length<i.minLength.value&&(hd(r,{code:hs.too_small,minimum:i.minLength.value,type:"array",inclusive:!0,exact:!1,message:i.minLength.message}),a.dirty()),null!==i.maxLength&&r.data.length>i.maxLength.value&&(hd(r,{code:hs.too_big,maximum:i.maxLength.value,type:"array",inclusive:!0,exact:!1,message:i.maxLength.message}),a.dirty()),r.common.async)return Promise.all([...r.data].map((t,a)=>i.type._parseAsync(new hg(r,t,r.path,a)))).then(t=>hp.mergeArray(a,t));let n=[...r.data].map((t,a)=>i.type._parseSync(new hg(r,t,r.path,a)));return hp.mergeArray(a,n)}get element(){return this._def.type}min(t,r){return new hW({...this._def,minLength:{value:t,message:L.toString(r)}})}max(t,r){return new hW({...this._def,maxLength:{value:t,message:L.toString(r)}})}length(t,r){return new hW({...this._def,exactLength:{value:t,message:L.toString(r)}})}nonempty(t){return this.min(1,t)}}hW.create=(t,r)=>new hW({type:t,minLength:null,maxLength:null,exactLength:null,typeName:Z.ZodArray,...h_(r)});class hY extends hb{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;let t=this._def.shape(),r=M.objectKeys(t);return this._cached={shape:t,keys:r},this._cached}_parse(t){if(this._getType(t)!==hn.object){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.object,received:r.parsedType}),hm}let{status:r,ctx:a}=this._processInputParams(t),{shape:i,keys:n}=this._getCached(),o=[];if(!(this._def.catchall instanceof hK&&"strip"===this._def.unknownKeys))for(let t in a.data)n.includes(t)||o.push(t);let s=[];for(let t of n){let r=i[t],n=a.data[t];s.push({key:{status:"valid",value:t},value:r._parse(new hg(a,n,a.path,t)),alwaysSet:t in a.data})}if(this._def.catchall instanceof hK){let t=this._def.unknownKeys;if("passthrough"===t)for(let t of o)s.push({key:{status:"valid",value:t},value:{status:"valid",value:a.data[t]}});else if("strict"===t)o.length>0&&(hd(a,{code:hs.unrecognized_keys,keys:o}),r.dirty());else if("strip"===t);else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let t=this._def.catchall;for(let r of o){let i=a.data[r];s.push({key:{status:"valid",value:r},value:t._parse(new hg(a,i,a.path,r)),alwaysSet:r in a.data})}}return a.common.async?Promise.resolve().then(async()=>{let t=[];for(let r of s){let a=await r.key,i=await r.value;t.push({key:a,value:i,alwaysSet:r.alwaysSet})}return t}).then(t=>hp.mergeObjectSync(r,t)):hp.mergeObjectSync(r,s)}get shape(){return this._def.shape()}strict(t){return L.errToObj,new hY({...this._def,unknownKeys:"strict",...void 0!==t?{errorMap:(r,a)=>{let i=this._def.errorMap?.(r,a).message??a.defaultError;return"unrecognized_keys"===r.code?{message:L.errToObj(t).message??i}:{message:i}}}:{}})}strip(){return new hY({...this._def,unknownKeys:"strip"})}passthrough(){return new hY({...this._def,unknownKeys:"passthrough"})}extend(t){return new hY({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new hY({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:Z.ZodObject})}setKey(t,r){return this.augment({[t]:r})}catchall(t){return new hY({...this._def,catchall:t})}pick(t){let r={};for(let a of M.objectKeys(t))t[a]&&this.shape[a]&&(r[a]=this.shape[a]);return new hY({...this._def,shape:()=>r})}omit(t){let r={};for(let a of M.objectKeys(this.shape))t[a]||(r[a]=this.shape[a]);return new hY({...this._def,shape:()=>r})}deepPartial(){return function t(r){if(r instanceof hY){let a={};for(let i in r.shape){let n=r.shape[i];a[i]=fi.create(t(n))}return new hY({...r._def,shape:()=>a})}if(r instanceof hW)return new hW({...r._def,type:t(r.element)});if(r instanceof fi)return fi.create(t(r.unwrap()));if(r instanceof fn)return fn.create(t(r.unwrap()));if(r instanceof h2)return h2.create(r.items.map(r=>t(r)));else return r}(this)}partial(t){let r={};for(let a of M.objectKeys(this.shape)){let i=this.shape[a];t&&!t[a]?r[a]=i:r[a]=i.optional()}return new hY({...this._def,shape:()=>r})}required(t){let r={};for(let a of M.objectKeys(this.shape))if(t&&!t[a])r[a]=this.shape[a];else{let t=this.shape[a];for(;t instanceof fi;)t=t._def.innerType;r[a]=t}return new hY({...this._def,shape:()=>r})}keyof(){return h7(M.objectKeys(this.shape))}}hY.create=(t,r)=>new hY({shape:()=>t,unknownKeys:"strip",catchall:hK.create(),typeName:Z.ZodObject,...h_(r)}),hY.strictCreate=(t,r)=>new hY({shape:()=>t,unknownKeys:"strict",catchall:hK.create(),typeName:Z.ZodObject,...h_(r)}),hY.lazycreate=(t,r)=>new hY({shape:t,unknownKeys:"strip",catchall:hK.create(),typeName:Z.ZodObject,...h_(r)});class hX extends hb{_parse(t){let{ctx:r}=this._processInputParams(t),a=this._def.options;if(r.common.async)return Promise.all(a.map(async t=>{let a={...r,common:{...r.common,issues:[]},parent:null};return{result:await t._parseAsync({data:r.data,path:r.path,parent:a}),ctx:a}})).then(function(t){for(let r of t)if("valid"===r.result.status)return r.result;for(let a of t)if("dirty"===a.result.status)return r.common.issues.push(...a.ctx.common.issues),a.result;let a=t.map(t=>new hl(t.ctx.common.issues));return hd(r,{code:hs.invalid_union,unionErrors:a}),hm});{let t,i=[];for(let n of a){let a={...r,common:{...r.common,issues:[]},parent:null},o=n._parseSync({data:r.data,path:r.path,parent:a});if("valid"===o.status)return o;"dirty"!==o.status||t||(t={result:o,ctx:a}),a.common.issues.length&&i.push(a.common.issues)}if(t)return r.common.issues.push(...t.ctx.common.issues),t.result;let n=i.map(t=>new hl(t));return hd(r,{code:hs.invalid_union,unionErrors:n}),hm}}get options(){return this._def.options}}hX.create=(t,r)=>new hX({options:t,typeName:Z.ZodUnion,...h_(r)});let hQ=t=>{if(t instanceof h5)return hQ(t.schema);if(t instanceof fa)return hQ(t.innerType());if(t instanceof h8)return[t.value];if(t instanceof fe)return t.options;if(t instanceof ft)return M.objectValues(t.enum);else if(t instanceof fo)return hQ(t._def.innerType);else if(t instanceof hF)return[void 0];else if(t instanceof hH)return[null];else if(t instanceof fi)return[void 0,...hQ(t.unwrap())];else if(t instanceof fn)return[null,...hQ(t.unwrap())];else if(t instanceof fc)return hQ(t.unwrap());else if(t instanceof fd)return hQ(t.unwrap());else if(t instanceof fs)return hQ(t._def.innerType);else return[]};class h0 extends hb{_parse(t){let{ctx:r}=this._processInputParams(t);if(r.parsedType!==hn.object)return hd(r,{code:hs.invalid_type,expected:hn.object,received:r.parsedType}),hm;let a=this.discriminator,i=r.data[a],n=this.optionsMap.get(i);return n?r.common.async?n._parseAsync({data:r.data,path:r.path,parent:r}):n._parseSync({data:r.data,path:r.path,parent:r}):(hd(r,{code:hs.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[a]}),hm)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,r,a){let i=new Map;for(let a of r){let r=hQ(a.shape[t]);if(!r.length)throw Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(let n of r){if(i.has(n))throw Error(`Discriminator property ${String(t)} has duplicate value ${String(n)}`);i.set(n,a)}}return new h0({typeName:Z.ZodDiscriminatedUnion,discriminator:t,options:r,optionsMap:i,...h_(a)})}}class h1 extends hb{_parse(t){let{status:r,ctx:a}=this._processInputParams(t),i=(t,i)=>{if("aborted"===t.status||"aborted"===i.status)return hm;let n=function t(r,a){let i=ho(r),n=ho(a);if(r===a)return{valid:!0,data:r};if(i===hn.object&&n===hn.object){let i=M.objectKeys(a),n=M.objectKeys(r).filter(t=>-1!==i.indexOf(t)),o={...r,...a};for(let i of(Object.prototype.hasOwnProperty.call(o,"__proto__")&&delete o.__proto__,n)){if("__proto__"===i)continue;let n=t(r[i],a[i]);if(!n.valid)return{valid:!1};o[i]=n.data}return{valid:!0,data:o}}if(i===hn.array&&n===hn.array){if(r.length!==a.length)return{valid:!1};let i=[];for(let n=0;n<r.length;n++){let o=t(r[n],a[n]);if(!o.valid)return{valid:!1};i.push(o.data)}return{valid:!0,data:i}}if(i===hn.date&&n===hn.date&&+r==+a)return{valid:!0,data:r};return{valid:!1}}(t.value,i.value);return n.valid?(("dirty"===t.status||"dirty"===i.status)&&r.dirty(),{status:r.value,value:n.data}):(hd(a,{code:hs.invalid_intersection_types}),hm)};return a.common.async?Promise.all([this._def.left._parseAsync({data:a.data,path:a.path,parent:a}),this._def.right._parseAsync({data:a.data,path:a.path,parent:a})]).then(([t,r])=>i(t,r)):i(this._def.left._parseSync({data:a.data,path:a.path,parent:a}),this._def.right._parseSync({data:a.data,path:a.path,parent:a}))}}h1.create=(t,r,a)=>new h1({left:t,right:r,typeName:Z.ZodIntersection,...h_(a)});class h2 extends hb{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==hn.array)return hd(a,{code:hs.invalid_type,expected:hn.array,received:a.parsedType}),hm;if(a.data.length<this._def.items.length)return hd(a,{code:hs.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),hm;!this._def.rest&&a.data.length>this._def.items.length&&(hd(a,{code:hs.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),r.dirty());let i=[...a.data].map((t,r)=>{let i=this._def.items[r]||this._def.rest;return i?i._parse(new hg(a,t,a.path,r)):null}).filter(t=>!!t);return a.common.async?Promise.all(i).then(t=>hp.mergeArray(r,t)):hp.mergeArray(r,i)}get items(){return this._def.items}rest(t){return new h2({...this._def,rest:t})}}h2.create=(t,r)=>{if(!Array.isArray(t))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new h2({items:t,typeName:Z.ZodTuple,rest:null,...h_(r)})};class h9 extends hb{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==hn.object)return hd(a,{code:hs.invalid_type,expected:hn.object,received:a.parsedType}),hm;let i=[],n=this._def.keyType,o=this._def.valueType;for(let t in a.data)i.push({key:n._parse(new hg(a,t,a.path,t)),value:o._parse(new hg(a,a.data[t],a.path,t)),alwaysSet:t in a.data});return a.common.async?hp.mergeObjectAsync(r,i):hp.mergeObjectSync(r,i)}get element(){return this._def.valueType}static create(t,r,a){return new h9(r instanceof hb?{keyType:t,valueType:r,typeName:Z.ZodRecord,...h_(a)}:{keyType:hz.create(),valueType:t,typeName:Z.ZodRecord,...h_(r)})}}class h4 extends hb{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==hn.map)return hd(a,{code:hs.invalid_type,expected:hn.map,received:a.parsedType}),hm;let i=this._def.keyType,n=this._def.valueType,o=[...a.data.entries()].map(([t,r],o)=>({key:i._parse(new hg(a,t,a.path,[o,"key"])),value:n._parse(new hg(a,r,a.path,[o,"value"]))}));if(a.common.async){let t=new Map;return Promise.resolve().then(async()=>{for(let a of o){let i=await a.key,n=await a.value;if("aborted"===i.status||"aborted"===n.status)return hm;("dirty"===i.status||"dirty"===n.status)&&r.dirty(),t.set(i.value,n.value)}return{status:r.value,value:t}})}{let t=new Map;for(let a of o){let i=a.key,n=a.value;if("aborted"===i.status||"aborted"===n.status)return hm;("dirty"===i.status||"dirty"===n.status)&&r.dirty(),t.set(i.value,n.value)}return{status:r.value,value:t}}}}h4.create=(t,r,a)=>new h4({valueType:r,keyType:t,typeName:Z.ZodMap,...h_(a)});class h3 extends hb{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==hn.set)return hd(a,{code:hs.invalid_type,expected:hn.set,received:a.parsedType}),hm;let i=this._def;null!==i.minSize&&a.data.size<i.minSize.value&&(hd(a,{code:hs.too_small,minimum:i.minSize.value,type:"set",inclusive:!0,exact:!1,message:i.minSize.message}),r.dirty()),null!==i.maxSize&&a.data.size>i.maxSize.value&&(hd(a,{code:hs.too_big,maximum:i.maxSize.value,type:"set",inclusive:!0,exact:!1,message:i.maxSize.message}),r.dirty());let n=this._def.valueType;function o(t){let a=new Set;for(let i of t){if("aborted"===i.status)return hm;"dirty"===i.status&&r.dirty(),a.add(i.value)}return{status:r.value,value:a}}let s=[...a.data.values()].map((t,r)=>n._parse(new hg(a,t,a.path,r)));return a.common.async?Promise.all(s).then(t=>o(t)):o(s)}min(t,r){return new h3({...this._def,minSize:{value:t,message:L.toString(r)}})}max(t,r){return new h3({...this._def,maxSize:{value:t,message:L.toString(r)}})}size(t,r){return this.min(t,r).max(t,r)}nonempty(t){return this.min(1,t)}}h3.create=(t,r)=>new h3({valueType:t,minSize:null,maxSize:null,typeName:Z.ZodSet,...h_(r)});class h6 extends hb{constructor(){super(...arguments),this.validate=this.implement}_parse(t){let{ctx:r}=this._processInputParams(t);if(r.parsedType!==hn.function)return hd(r,{code:hs.invalid_type,expected:hn.function,received:r.parsedType}),hm;function a(t,a){return hu({data:t,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,hc,hc].filter(t=>!!t),issueData:{code:hs.invalid_arguments,argumentsError:a}})}function i(t,a){return hu({data:t,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,hc,hc].filter(t=>!!t),issueData:{code:hs.invalid_return_type,returnTypeError:a}})}let n={errorMap:r.common.contextualErrorMap},o=r.data;if(this._def.returns instanceof fr){let t=this;return hf(async function(...r){let s=new hl([]),l=await t._def.args.parseAsync(r,n).catch(t=>{throw s.addIssue(a(r,t)),s}),c=await Reflect.apply(o,this,l);return await t._def.returns._def.type.parseAsync(c,n).catch(t=>{throw s.addIssue(i(c,t)),s})})}{let t=this;return hf(function(...r){let s=t._def.args.safeParse(r,n);if(!s.success)throw new hl([a(r,s.error)]);let l=Reflect.apply(o,this,s.data),c=t._def.returns.safeParse(l,n);if(!c.success)throw new hl([i(l,c.error)]);return c.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new h6({...this._def,args:h2.create(t).rest(hB.create())})}returns(t){return new h6({...this._def,returns:t})}implement(t){return this.parse(t)}strictImplement(t){return this.parse(t)}static create(t,r,a){return new h6({args:t||h2.create([]).rest(hB.create()),returns:r||hB.create(),typeName:Z.ZodFunction,...h_(a)})}}class h5 extends hb{get schema(){return this._def.getter()}_parse(t){let{ctx:r}=this._processInputParams(t);return this._def.getter()._parse({data:r.data,path:r.path,parent:r})}}h5.create=(t,r)=>new h5({getter:t,typeName:Z.ZodLazy,...h_(r)});class h8 extends hb{_parse(t){if(t.data!==this._def.value){let r=this._getOrReturnCtx(t);return hd(r,{received:r.data,code:hs.invalid_literal,expected:this._def.value}),hm}return{status:"valid",value:t.data}}get value(){return this._def.value}}function h7(t,r){return new fe({values:t,typeName:Z.ZodEnum,...h_(r)})}h8.create=(t,r)=>new h8({value:t,typeName:Z.ZodLiteral,...h_(r)});class fe extends hb{_parse(t){if("string"!=typeof t.data){let r=this._getOrReturnCtx(t),a=this._def.values;return hd(r,{expected:M.joinValues(a),received:r.parsedType,code:hs.invalid_type}),hm}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(t.data)){let r=this._getOrReturnCtx(t),a=this._def.values;return hd(r,{received:r.data,code:hs.invalid_enum_value,options:a}),hm}return hf(t.data)}get options(){return this._def.values}get enum(){let t={};for(let r of this._def.values)t[r]=r;return t}get Values(){let t={};for(let r of this._def.values)t[r]=r;return t}get Enum(){let t={};for(let r of this._def.values)t[r]=r;return t}extract(t,r=this._def){return fe.create(t,{...this._def,...r})}exclude(t,r=this._def){return fe.create(this.options.filter(r=>!t.includes(r)),{...this._def,...r})}}fe.create=h7;class ft extends hb{_parse(t){let r=M.getValidEnumValues(this._def.values),a=this._getOrReturnCtx(t);if(a.parsedType!==hn.string&&a.parsedType!==hn.number){let t=M.objectValues(r);return hd(a,{expected:M.joinValues(t),received:a.parsedType,code:hs.invalid_type}),hm}if(this._cache||(this._cache=new Set(M.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){let t=M.objectValues(r);return hd(a,{received:a.data,code:hs.invalid_enum_value,options:t}),hm}return hf(t.data)}get enum(){return this._def.values}}ft.create=(t,r)=>new ft({values:t,typeName:Z.ZodNativeEnum,...h_(r)});class fr extends hb{unwrap(){return this._def.type}_parse(t){let{ctx:r}=this._processInputParams(t);return r.parsedType!==hn.promise&&!1===r.common.async?(hd(r,{code:hs.invalid_type,expected:hn.promise,received:r.parsedType}),hm):hf((r.parsedType===hn.promise?r.data:Promise.resolve(r.data)).then(t=>this._def.type.parseAsync(t,{path:r.path,errorMap:r.common.contextualErrorMap})))}}fr.create=(t,r)=>new fr({type:t,typeName:Z.ZodPromise,...h_(r)});class fa extends hb{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===Z.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){let{status:r,ctx:a}=this._processInputParams(t),i=this._def.effect||null,n={addIssue:t=>{hd(a,t),t.fatal?r.abort():r.dirty()},get path(){return a.path}};if(n.addIssue=n.addIssue.bind(n),"preprocess"===i.type){let t=i.transform(a.data,n);if(a.common.async)return Promise.resolve(t).then(async t=>{if("aborted"===r.value)return hm;let i=await this._def.schema._parseAsync({data:t,path:a.path,parent:a});return"aborted"===i.status?hm:"dirty"===i.status||"dirty"===r.value?hh(i.value):i});{if("aborted"===r.value)return hm;let i=this._def.schema._parseSync({data:t,path:a.path,parent:a});return"aborted"===i.status?hm:"dirty"===i.status||"dirty"===r.value?hh(i.value):i}}if("refinement"===i.type){let t=t=>{let r=i.refinement(t,n);if(a.common.async)return Promise.resolve(r);if(r instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return t};if(!1!==a.common.async)return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then(a=>"aborted"===a.status?hm:("dirty"===a.status&&r.dirty(),t(a.value).then(()=>({status:r.value,value:a.value}))));{let i=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});return"aborted"===i.status?hm:("dirty"===i.status&&r.dirty(),t(i.value),{status:r.value,value:i.value})}}if("transform"===i.type)if(!1!==a.common.async)return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then(t=>"valid"!==t.status?hm:Promise.resolve(i.transform(t.value,n)).then(t=>({status:r.value,value:t})));else{let t=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});if("valid"!==t.status)return hm;let o=i.transform(t.value,n);if(o instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:o}}M.assertNever(i)}}fa.create=(t,r,a)=>new fa({schema:t,typeName:Z.ZodEffects,effect:r,...h_(a)}),fa.createWithPreprocess=(t,r,a)=>new fa({schema:r,effect:{type:"preprocess",transform:t},typeName:Z.ZodEffects,...h_(a)});class fi extends hb{_parse(t){return this._getType(t)===hn.undefined?hf(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}fi.create=(t,r)=>new fi({innerType:t,typeName:Z.ZodOptional,...h_(r)});class fn extends hb{_parse(t){return this._getType(t)===hn.null?hf(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}fn.create=(t,r)=>new fn({innerType:t,typeName:Z.ZodNullable,...h_(r)});class fo extends hb{_parse(t){let{ctx:r}=this._processInputParams(t),a=r.data;return r.parsedType===hn.undefined&&(a=this._def.defaultValue()),this._def.innerType._parse({data:a,path:r.path,parent:r})}removeDefault(){return this._def.innerType}}fo.create=(t,r)=>new fo({innerType:t,typeName:Z.ZodDefault,defaultValue:"function"==typeof r.default?r.default:()=>r.default,...h_(r)});class fs extends hb{_parse(t){let{ctx:r}=this._processInputParams(t),a={...r,common:{...r.common,issues:[]}},i=this._def.innerType._parse({data:a.data,path:a.path,parent:{...a}});return hy(i)?i.then(t=>({status:"valid",value:"valid"===t.status?t.value:this._def.catchValue({get error(){return new hl(a.common.issues)},input:a.data})})):{status:"valid",value:"valid"===i.status?i.value:this._def.catchValue({get error(){return new hl(a.common.issues)},input:a.data})}}removeCatch(){return this._def.innerType}}fs.create=(t,r)=>new fs({innerType:t,typeName:Z.ZodCatch,catchValue:"function"==typeof r.catch?r.catch:()=>r.catch,...h_(r)});class fl extends hb{_parse(t){if(this._getType(t)!==hn.nan){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.nan,received:r.parsedType}),hm}return{status:"valid",value:t.data}}}fl.create=t=>new fl({typeName:Z.ZodNaN,...h_(t)}),Symbol("zod_brand");class fc extends hb{_parse(t){let{ctx:r}=this._processInputParams(t),a=r.data;return this._def.type._parse({data:a,path:r.path,parent:r})}unwrap(){return this._def.type}}class fu extends hb{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.common.async)return(async()=>{let t=await this._def.in._parseAsync({data:a.data,path:a.path,parent:a});return"aborted"===t.status?hm:"dirty"===t.status?(r.dirty(),hh(t.value)):this._def.out._parseAsync({data:t.value,path:a.path,parent:a})})();{let t=this._def.in._parseSync({data:a.data,path:a.path,parent:a});return"aborted"===t.status?hm:"dirty"===t.status?(r.dirty(),{status:"dirty",value:t.value}):this._def.out._parseSync({data:t.value,path:a.path,parent:a})}}static create(t,r){return new fu({in:t,out:r,typeName:Z.ZodPipeline})}}class fd extends hb{_parse(t){let r=this._def.innerType._parse(t),a=t=>("valid"===t.status&&(t.value=Object.freeze(t.value)),t);return hy(r)?r.then(t=>a(t)):a(r)}unwrap(){return this._def.innerType}}fd.create=(t,r)=>new fd({innerType:t,typeName:Z.ZodReadonly,...h_(r)}),hY.lazycreate,(O=Z||(Z={})).ZodString="ZodString",O.ZodNumber="ZodNumber",O.ZodNaN="ZodNaN",O.ZodBigInt="ZodBigInt",O.ZodBoolean="ZodBoolean",O.ZodDate="ZodDate",O.ZodSymbol="ZodSymbol",O.ZodUndefined="ZodUndefined",O.ZodNull="ZodNull",O.ZodAny="ZodAny",O.ZodUnknown="ZodUnknown",O.ZodNever="ZodNever",O.ZodVoid="ZodVoid",O.ZodArray="ZodArray",O.ZodObject="ZodObject",O.ZodUnion="ZodUnion",O.ZodDiscriminatedUnion="ZodDiscriminatedUnion",O.ZodIntersection="ZodIntersection",O.ZodTuple="ZodTuple",O.ZodRecord="ZodRecord",O.ZodMap="ZodMap",O.ZodSet="ZodSet",O.ZodFunction="ZodFunction",O.ZodLazy="ZodLazy",O.ZodLiteral="ZodLiteral",O.ZodEnum="ZodEnum",O.ZodEffects="ZodEffects",O.ZodNativeEnum="ZodNativeEnum",O.ZodOptional="ZodOptional",O.ZodNullable="ZodNullable",O.ZodDefault="ZodDefault",O.ZodCatch="ZodCatch",O.ZodPromise="ZodPromise",O.ZodBranded="ZodBranded",O.ZodPipeline="ZodPipeline",O.ZodReadonly="ZodReadonly",hz.create,hL.create,fl.create,hZ.create,hD.create,hU.create,hV.create,hF.create,hH.create,hJ.create,hB.create,hK.create,hG.create,hW.create,hY.create,hY.strictCreate,hX.create,h0.create,h1.create,h2.create,h9.create,h4.create,h3.create,h6.create,h5.create,h8.create,fe.create,ft.create,fr.create,fa.create,fi.create,fn.create,fa.createWithPreprocess,fu.create;let fp=(t,r)=>{let a=0;for(;a<t.length&&a<r.length&&t[a]===r[a];a++);return[(t.length-a).toString(),...r.slice(a)].join("/")};function fm(t){if("openAi"!==t.target)return{};let r=[...t.basePath,t.definitionPath,t.openAiAnyTypeName];return t.flags.hasReferencedOpenAiAnyType=!0,{$ref:"relative"===t.$refStrategy?fp(r,t.currentPath):r.join("/")}}function fh(t,r,a,i){i?.errorMessages&&a&&(t.errorMessage={...t.errorMessage,[r]:a})}function ff(t,r,a,i,n){t[r]=a,fh(t,r,i,n)}function fy(t,r){return fM(t.type._def,r)}let fg=/^[cC][^\s-]{8,}$/,fv=/^[0-9a-z]+$/,f_=/^[0-9A-HJKMNP-TV-Z]{26}$/,fb=/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,fS=()=>(void 0===w&&(w=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),w),f$=/^(?:(?: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])$/,fw=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,fR=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,fk=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,fx=/^[a-zA-Z0-9_-]{21}$/,fP=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;function fE(t,r){let a={type:"string"};if(t.checks)for(let i of t.checks)switch(i.kind){case"min":ff(a,"minLength","number"==typeof a.minLength?Math.max(a.minLength,i.value):i.value,i.message,r);break;case"max":ff(a,"maxLength","number"==typeof a.maxLength?Math.min(a.maxLength,i.value):i.value,i.message,r);break;case"email":switch(r.emailStrategy){case"format:email":fO(a,"email",i.message,r);break;case"format:idn-email":fO(a,"idn-email",i.message,r);break;case"pattern:zod":fC(a,fb,i.message,r)}break;case"url":fO(a,"uri",i.message,r);break;case"uuid":fO(a,"uuid",i.message,r);break;case"regex":fC(a,i.regex,i.message,r);break;case"cuid":fC(a,fg,i.message,r);break;case"cuid2":fC(a,fv,i.message,r);break;case"startsWith":fC(a,RegExp(`^${fT(i.value,r)}`),i.message,r);break;case"endsWith":fC(a,RegExp(`${fT(i.value,r)}$`),i.message,r);break;case"datetime":fO(a,"date-time",i.message,r);break;case"date":fO(a,"date",i.message,r);break;case"time":fO(a,"time",i.message,r);break;case"duration":fO(a,"duration",i.message,r);break;case"length":ff(a,"minLength","number"==typeof a.minLength?Math.max(a.minLength,i.value):i.value,i.message,r),ff(a,"maxLength","number"==typeof a.maxLength?Math.min(a.maxLength,i.value):i.value,i.message,r);break;case"includes":fC(a,RegExp(fT(i.value,r)),i.message,r);break;case"ip":"v6"!==i.version&&fO(a,"ipv4",i.message,r),"v4"!==i.version&&fO(a,"ipv6",i.message,r);break;case"base64url":fC(a,fk,i.message,r);break;case"jwt":fC(a,fP,i.message,r);break;case"cidr":"v6"!==i.version&&fC(a,f$,i.message,r),"v4"!==i.version&&fC(a,fw,i.message,r);break;case"emoji":fC(a,fS(),i.message,r);break;case"ulid":fC(a,f_,i.message,r);break;case"base64":switch(r.base64Strategy){case"format:binary":fO(a,"binary",i.message,r);break;case"contentEncoding:base64":ff(a,"contentEncoding","base64",i.message,r);break;case"pattern:zod":fC(a,fR,i.message,r)}break;case"nanoid":fC(a,fx,i.message,r)}return a}function fT(t,r){return"escape"===r.patternStrategy?function(t){let r="";for(let a=0;a<t.length;a++)fj.has(t[a])||(r+="\\"),r+=t[a];return r}(t):t}let fj=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function fO(t,r,a,i){t.format||t.anyOf?.some(t=>t.format)?(t.anyOf||(t.anyOf=[]),t.format&&(t.anyOf.push({format:t.format,...t.errorMessage&&i.errorMessages&&{errorMessage:{format:t.errorMessage.format}}}),delete t.format,t.errorMessage&&(delete t.errorMessage.format,0===Object.keys(t.errorMessage).length&&delete t.errorMessage)),t.anyOf.push({format:r,...a&&i.errorMessages&&{errorMessage:{format:a}}})):ff(t,"format",r,a,i)}function fC(t,r,a,i){t.pattern||t.allOf?.some(t=>t.pattern)?(t.allOf||(t.allOf=[]),t.pattern&&(t.allOf.push({pattern:t.pattern,...t.errorMessage&&i.errorMessages&&{errorMessage:{pattern:t.errorMessage.pattern}}}),delete t.pattern,t.errorMessage&&(delete t.errorMessage.pattern,0===Object.keys(t.errorMessage).length&&delete t.errorMessage)),t.allOf.push({pattern:fI(r,i),...a&&i.errorMessages&&{errorMessage:{pattern:a}}})):ff(t,"pattern",fI(r,i),a,i)}function fI(t,r){if(!r.applyRegexFlags||!t.flags)return t.source;let a={i:t.flags.includes("i"),m:t.flags.includes("m"),s:t.flags.includes("s")},i=a.i?t.source.toLowerCase():t.source,n="",o=!1,s=!1,l=!1;for(let t=0;t<i.length;t++){if(o){n+=i[t],o=!1;continue}if(a.i){if(s){if(i[t].match(/[a-z]/)){l?(n+=i[t],n+=`${i[t-2]}-${i[t]}`.toUpperCase(),l=!1):"-"===i[t+1]&&i[t+2]?.match(/[a-z]/)?(n+=i[t],l=!0):n+=`${i[t]}${i[t].toUpperCase()}`;continue}}else if(i[t].match(/[a-z]/)){n+=`[${i[t]}${i[t].toUpperCase()}]`;continue}}if(a.m){if("^"===i[t]){n+=`(^|(?<=[\r
77
+ `,t.enqueue(r.encode(n)),!0}catch(t){return this.onerror?.(t),!1}}handleUnsupportedRequest(){return this.onerror?.(Error("Method not allowed.")),Response.json({jsonrpc:"2.0",error:{code:-32e3,message:"Method not allowed."},id:null},{status:405,headers:{Allow:"GET, POST, DELETE","Content-Type":"application/json"}})}async handlePostRequest(t,r){try{let a,i,n,o,s,l=t.headers.get("accept");if(!l?.includes("application/json")||!l.includes("text/event-stream"))return this.onerror?.(Error("Not Acceptable: Client must accept both application/json and text/event-stream")),this.createJsonErrorResponse(406,-32e3,"Not Acceptable: Client must accept both application/json and text/event-stream");if(!uz(t.headers.get("content-type")))return this.onerror?.(Error("Unsupported Media Type: Content-Type must be application/json")),this.createJsonErrorResponse(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");if(r?.parsedBody===void 0)try{let r=await p2(t,this._maxRequestBodySize);if(r.tooLarge){let t=p0(this._maxRequestBodySize);return this.onerror?.(Error(t)),this.createJsonErrorResponse(413,-32e3,t)}a=JSON.parse(r.text)}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON")}else a=r.parsedBody;if(Array.isArray(a)&&a.length>100)return this.onerror?.(Error("Invalid Request: Batch must not exceed 100 messages")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Batch must not exceed 100 messages");try{i=Array.isArray(a)?a.map(t=>ou.parse(t)):[ou.parse(a)]}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON-RPC message")}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");let c=i.some(t=>ok.safeParse(t).success);if(c){if(this._initialized&&void 0!==this.sessionId)return this.onerror?.(Error("Invalid Request: Server already initialized")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Server already initialized");if(i.length>1)return this.onerror?.(Error("Invalid Request: Only one initialization request is allowed")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Only one initialization request is allowed");this.sessionId=this.sessionIdGenerator?.(),this._initialized=!0,this.sessionId&&this._onsessioninitialized&&await Promise.resolve(this._onsessioninitialized(this.sessionId))}if(!c){let r=this.validateSession(t);if(r)return r;let a=this.validateProtocolVersion(t);if(a)return a}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");try{n=await this._checkScopeChallenge(i,r?.authInfo)}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(500,-32603,"Internal server error")}if(n)return n;if(!i.some(t=>cW(t))){for(let a of i)this.onmessage?.(a,{authInfo:r?.authInfo,request:t});return new Response(null,{status:202})}let u=crypto.randomUUID(),d=i.find(t=>ok.safeParse(t).success),p=d?d.params.protocolVersion:t.headers.get("mcp-protocol-version")??"2025-03-26";if(this._enableJsonResponse)return new Promise(a=>{for(let t of(this._streamMapping.set(u,{resolveJson:a,cleanup:()=>{this._streamMapping.delete(u)}}),i))cW(t)&&this._requestToStreamMapping.set(t.id,u);for(let a of i)this.onmessage?.(a,{authInfo:r?.authInfo,request:t})});let m=new TextEncoder,h=new ReadableStream({start:t=>{o=t},cancel:()=>{void 0!==s&&clearInterval(s),this._streamMapping.get(u)?.controller===o&&this._streamMapping.delete(u)}}),f={"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"};for(let t of(void 0!==this.sessionId&&(f["mcp-session-id"]=this.sessionId),i))cW(t)&&(this._streamMapping.set(u,{controller:o,encoder:m,cleanup:()=>{void 0!==s&&clearInterval(s),this._streamMapping.delete(u);try{o.close()}catch{}}}),this._requestToStreamMapping.set(t.id,u));for(let a of(await this.writePrimingEvent(o,m,u,p),i)){let i,n;cW(a)&&this._eventStore&&this.supportsEmptySSEData(p)&&(i=()=>{this.closeSSEStream(a.id)},n=()=>{this.closeStandaloneSSEStream()}),this.onmessage?.(a,{authInfo:r?.authInfo,request:t,closeSSEStream:i,closeStandaloneSSEStream:n})}return this._streamMapping.get(u)?.controller===o&&(s=this.startKeepAlive(o,m)),new Response(h,{status:200,headers:f})}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error",{data:String(t)})}}async handleDeleteRequest(t){let r=this.validateSession(t);if(r)return r;let a=this.validateProtocolVersion(t);if(a)return a;try{return await Promise.resolve(this._onsessionclosed?.(this.sessionId)),new Response(null,{status:200})}finally{await this.close()}}validateSession(t){if(void 0===this.sessionIdGenerator)return;if(!this._initialized)return this.onerror?.(Error("Bad Request: Server not initialized")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Server not initialized");let r=t.headers.get("mcp-session-id");return r?r!==this.sessionId?(this.onerror?.(Error("Session not found")),this.createJsonErrorResponse(404,-32001,"Session not found")):void 0:(this.onerror?.(Error("Bad Request: Mcp-Session-Id header is required")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Mcp-Session-Id header is required"))}validateProtocolVersion(t){let r=t.headers.get("mcp-protocol-version");if(null!==r&&!this._supportedProtocolVersions.includes(r)){let t=`Bad Request: Unsupported protocol version: ${r} (supported versions: ${this._supportedProtocolVersions.join(", ")})`;return this.onerror?.(Error(t)),this.createJsonErrorResponse(400,-32e3,t)}}async close(){if(!this._closed){for(let{cleanup:t}of(this._closed=!0,this._streamMapping.values()))t();this._streamMapping.clear(),this._requestResponseMap.clear(),this.onclose?.()}}closeSSEStream(t){let r=this._requestToStreamMapping.get(t);if(!r)return;let a=this._streamMapping.get(r);a&&a.cleanup()}closeStandaloneSSEStream(){let t=this._streamMapping.get(this._standaloneSseStreamId);t&&t.cleanup()}async send(t,r){let a=r?.relatedRequestId;if((cX(t)||cQ(t))&&(a=t.id),void 0===a){let r;if(cX(t)||cQ(t))throw Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");this._eventStore&&(r=await this._eventStore.storeEvent(this._standaloneSseStreamId,t));let a=this._streamMapping.get(this._standaloneSseStreamId);if(void 0===a)return;a.controller&&a.encoder&&(void 0===r||!a.replayedEventIds?.has(r))&&this.writeSSEEvent(a.controller,a.encoder,t,r);return}let i=this._requestToStreamMapping.get(a);if(!i)throw Error(`No connection established for request ID: ${String(a)}`);let n=this._streamMapping.get(i);if(!this._enableJsonResponse){let r;this._eventStore&&(r=await this._eventStore.storeEvent(i,t),n=this._streamMapping.get(i)),n?.controller&&n?.encoder&&(void 0===r||!n.replayedEventIds?.has(r))&&this.writeSSEEvent(n.controller,n.encoder,t,r)}if(cX(t)||cQ(t)){this._requestResponseMap.set(a,t);let r=[...this._requestToStreamMapping.entries()].filter(([t,r])=>r===i).map(([t])=>t);if(r.every(t=>this._requestResponseMap.has(t))){if(!n){if(this._enableJsonResponse)throw Error(`No connection established for request ID: ${String(a)}`);if(!this._eventStore){for(let t of(this.onerror?.(Error(`Response for request ID ${String(a)} is undeliverable: per-request stream is disconnected and no eventStore is configured`)),r))this._requestResponseMap.delete(t),this._requestToStreamMapping.delete(t);return}for(let t of r)this._requestResponseMap.delete(t),this._requestToStreamMapping.delete(t);return}if(this._enableJsonResponse&&n.resolveJson){let t={"Content-Type":"application/json"};void 0!==this.sessionId&&(t["mcp-session-id"]=this.sessionId);let a=r.map(t=>this._requestResponseMap.get(t));1===a.length?n.resolveJson(Response.json(a[0],{status:200,headers:t})):n.resolveJson(Response.json(a,{status:200,headers:t})),n.cleanup()}else n.cleanup();for(let t of r)this._requestResponseMap.delete(t),this._requestToStreamMapping.delete(t)}}}};function p4(t){if(null===t||"object"!=typeof t||Array.isArray(t))return null;let{method:r,id:a}=t;return"string"!=typeof r?null:"string"==typeof a||"number"==typeof a?a:null}function p3(t,r,a,i,n=null){return Response.json({jsonrpc:"2.0",error:{code:r,message:a,...void 0!==i&&{data:i}},id:n},{status:t})}function p6(t,r=null){return p3(t.httpStatus,t.code,t.message,t.data,r)}function p5(t){return t instanceof Error?t:Error(String(t))}function p8(t=null){return p3(500,-32603,"Internal server error",void 0,t)}function p7(t){if(void 0!==t.transport)throw Error("The factory returned an instance that is still serving another request. Return a new instance for each request.")}function me(t){return{protocolVersionHeader:t.headers.get("mcp-protocol-version")??void 0,mcpMethodHeader:t.headers.get("mcp-method")??void 0,mcpNameHeader:t.headers.get("mcp-name")??void 0}}async function mt(t,r,a=!0,i=4194304){let n,o=t.method.toUpperCase(),s=r,l=t,c=!1;if("POST"===o){if(void 0===s){let r;a&&(l=t.clone());try{let a=await p2(t,i);if(a.tooLarge)return{step:"body-too-large"};r=a.text}catch{return{step:"unreadable-body"}}try{n=0===r.length?void 0:JSON.parse(r)}catch{c=!0}c||void 0===n||(s=n)}else n=s;if(c||void 0===n)return{step:"no-json-body",forwardRequest:l}}return{step:"classified",outcome:function(t){if("POST"!==(t={...t,...void 0!==t.protocolVersionHeader&&{protocolVersionHeader:us(t.protocolVersionHeader)},...void 0!==t.mcpMethodHeader&&{mcpMethodHeader:us(t.mcpMethodHeader)},...void 0!==t.mcpNameHeader&&{mcpNameHeader:us(t.mcpNameHeader)}}).httpMethod.toUpperCase())return{kind:"legacy",reason:"http-method"};let r=t.body;if(Array.isArray(r)){if(0===r.length)return ui("jsonrpc-shape","empty-batch",400,new cv(cg.InvalidRequest,"Bad Request: empty JSON-RPC batch"),!0);for(let t of r){if(cJ(ul(t)?t.params:void 0))return ui("jsonrpc-shape","batch-with-modern-element",400,new cv(cg.InvalidRequest,"Bad Request: JSON-RPC batches may not contain requests for protocol revision 2026-07-28 or later"),!0);if(!(cW(t)||cY(t)||cX(t)||cQ(t)))return ui("jsonrpc-shape","batch-with-invalid-element",400,new cv(cg.InvalidRequest,"Bad Request: JSON-RPC batch contains an invalid message"),!0)}return{kind:"legacy",reason:"batch"}}return cX(r)||cQ(r)?{kind:"legacy",reason:"response"}:ul(r)&&cW(r)?function(t,r){let a=r.params,i=r.method,n=t.protocolVersionHeader,o=void 0!==n&&n>=lX;if("initialize"===i&&!function(t){if(!cJ(t))return!1;let r=cB(t);if(void 0===r||!(r>=lX))return!1;let a=cH(t);return void 0!==a&&0===cK(a).length}(a)){if(o)return un("initialize-with-modern-header",n,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let t=ul(a)&&"string"==typeof a.protocolVersion?a.protocolVersion:void 0;return{kind:"legacy",reason:"initialize",...void 0!==t&&{requestedVersion:t}}}if(cJ(a)){let o=cH(a),s=(void 0===o?[]:cK(o))[0];if(void 0!==s)return ui("envelope","envelope-invalid",400,new cv(cg.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${s.key}: ${s.problem}`,{envelope:s}),!0);let l=cB(a);return void 0!==n&&void 0!==l&&n!==l?un("header-body-version-mismatch",n,`the body envelope names protocol version ${l} but the MCP-Protocol-Version header names ${n}`):void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==i?un("method-header-mismatch",t.mcpMethodHeader,`the body names method ${i} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"request",message:r,classification:uc(l)}}if(o){let t=cH(a),r=cK(t??{}).filter(t=>"missing"===t.problem).map(t=>t.key),i=void 0===t?["_meta"]:r.length>0?r:[nK];return ui("envelope","modern-header-without-claim",400,new cv(cg.InvalidParams,`Invalid params: the MCP-Protocol-Version header names protocol revision ${n}, but the request is missing the required per-request envelope key(s): ${i.join(", ")}`,{envelope:{missing:i}}),!0)}return{kind:"legacy",reason:"no-claim",...void 0!==n&&{requestedVersion:n}}}(t,r):ul(r)&&cY(r)?function(t,r){let a=r.params,i=r.method,n=t.protocolVersionHeader,o=void 0!==n&&n>=lX;if(cJ(a)){let o=cB(a);if(void 0===o){let t=cH(a),r=(void 0===t?[]:cK(t)).find(t=>t.key===nK)??{key:nK,problem:"expected a protocol version string"};return ui("envelope","notification-envelope-invalid",400,new cv(cg.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${r.key}: ${r.problem}`,{envelope:r}),!0)}if(void 0!==n&&n!==o)return un("notification-header-body-version-mismatch",n,`the notification envelope names protocol version ${o} but the MCP-Protocol-Version header names ${n}`);let s=uc(o);return"modern"===s.era&&void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==i?un("notification-method-header-mismatch",t.mcpMethodHeader,`the notification body names method ${i} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:r,classification:s}}return o?void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==i?un("notification-method-header-mismatch",t.mcpMethodHeader,`the notification body names method ${i} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:r,classification:{era:"modern",revision:n}}:{kind:"legacy",reason:"notification",...void 0!==n&&{requestedVersion:n}}}(t,r):ui("jsonrpc-shape","invalid-json-rpc-body",400,new cv(cg.InvalidRequest,"Bad Request: the request body is not a valid JSON-RPC message"),!0)}({httpMethod:o,...me(t),...void 0!==n&&{body:n}}),body:n,parsedBody:s,forwardRequest:l}}require("http"),require("http2");let mr=require("stream");var ma=a(6982),mi=global.Request,mn=class extends mi{constructor(t,r){"object"==typeof t&&ms in t&&(t=t[ms]()),void 0!==r?.body?.getReader&&(r.duplex??="half"),super(t,r)}},mo=Symbol("wrapBodyStream"),ms=Symbol("getRequestCache"),ml=Symbol("requestCache"),mc=Symbol("incomingKey"),mu=Symbol("urlKey"),md=Symbol("headersKey"),mp=Symbol("abortControllerKey"),mm=Symbol("getAbortController"),mh={get method(){return this[mc].method||"GET"},get url(){return this[mu]},get headers(){return this[md]||=(t=>{let r=[],a=t.rawHeaders;for(let t=0;t<a.length;t+=2){let{[t]:i,[t+1]:n}=a;58!==i.charCodeAt(0)&&r.push([i,n])}return new Headers(r)})(this[mc])},[mm](){return this[ms](),this[mp]},[ms](){return this[mp]||=new AbortController,this[ml]||=((t,r,a,i,n)=>{let o={method:t,headers:a,signal:n.signal};if("TRACE"===t){o.method="GET";let t=new mn(r,o);return Object.defineProperty(t,"method",{get:()=>"TRACE"}),t}if("GET"!==t&&"HEAD"!==t)if("rawBody"in i&&i.rawBody instanceof Buffer)o.body=new ReadableStream({start(t){t.enqueue(i.rawBody),t.close()}});else if(i[mo]){let t;o.body=new ReadableStream({async pull(r){try{t||=mr.Readable.toWeb(i).getReader();let{done:a,value:n}=await t.read();a?r.close():r.enqueue(n)}catch(t){r.error(t)}}})}else o.body=mr.Readable.toWeb(i);return new mn(r,o)})(this.method,this[mu],this.headers,this[mc],this[mp])}};["body","bodyUsed","cache","credentials","destination","integrity","mode","redirect","referrer","referrerPolicy","signal","keepalive"].forEach(t=>{Object.defineProperty(mh,t,{get(){return this[ms]()[t]}})}),["arrayBuffer","blob","clone","formData","json","text"].forEach(t=>{Object.defineProperty(mh,t,{value:function(){return this[ms]()[t]()}})}),Object.defineProperty(mh,Symbol.for("nodejs.util.inspect.custom"),{value:function(t,r,a){let i={method:this.method,url:this.url,headers:this.headers,nativeRequest:this[ml]};return`Request (lightweight) ${a(i,{...r,depth:null==t?null:t-1})}`}}),Object.setPrototypeOf(mh,mn.prototype);var mf=Symbol("responseCache"),my=Symbol("getResponseCache"),mg=Symbol("cache"),mv=global.Response,m_=class t{#e;#t;[my](){return delete this[mg],this[mf]||=new mv(this.#e,this.#t)}constructor(r,a){let i;if(this.#e=r,a instanceof t){const t=a[mf];if(t){this.#t=t,this[my]();return}this.#t=a.#t,i=new Headers(a.#t.headers)}else this.#t=a;("string"==typeof r||void 0!==r?.getReader||r instanceof Blob||r instanceof Uint8Array)&&(this[mg]=[a?.status||200,r,i||a?.headers])}get headers(){let t=this[mg];return t?(t[2]instanceof Headers||(t[2]=new Headers(t[2]||{"content-type":"text/plain; charset=UTF-8"})),t[2]):this[my]().headers}get status(){return this[mg]?.[0]??this[my]().status}get ok(){let t=this.status;return t>=200&&t<300}};function mb(t){return Array.isArray(t)?t[0]:t}async function mS(t,r,a){let i,n=(t.method??"GET").toUpperCase(),o=`http://${mb(t.headers.host)??mb(t.headers[":authority"])??"localhost"}${t.url??"/"}`,s=new Headers;for(let[r,a]of Object.entries(t.headers))if(!(void 0===a||r.startsWith(":")))if(Array.isArray(a))for(let t of a)s.append(r,t);else s.set(r,a);if("GET"!==n&&"HEAD"!==n)if(void 0===r){let r=new TextDecoder,a="";for await(let i of t)a+="string"==typeof i?i:r.decode(i,{stream:!0});(a+=r.decode()).length>0&&(i=a)}else{let t=JSON.stringify(r);s.delete("content-encoding"),s.delete("transfer-encoding"),void 0===t?s.delete("content-length"):(i=t,s.set("content-length",String(new TextEncoder().encode(t).byteLength)))}return new Request(o,{method:n,headers:s,...a?.signal!==void 0&&{signal:a.signal},...void 0!==i&&{body:i}})}["body","bodyUsed","redirected","statusText","trailers","type","url"].forEach(t=>{Object.defineProperty(m_.prototype,t,{get(){return this[my]()[t]}})}),["arrayBuffer","blob","clone","formData","json","text"].forEach(t=>{Object.defineProperty(m_.prototype,t,{value:function(){return this[my]()[t]()}})}),Object.defineProperty(m_.prototype,Symbol.for("nodejs.util.inspect.custom"),{value:function(t,r,a){let i={status:this.status,headers:this.headers,ok:this.ok,nativeResponse:this[mf]};return`Response (lightweight) ${a(i,{...r,depth:null==t?null:t-1})}`}}),Object.setPrototypeOf(m_,mv),Object.setPrototypeOf(m_.prototype,mv.prototype),void 0===global.crypto&&(global.crypto=ma),Symbol("outgoingEnded"),Symbol("incomingDraining");let m$=require("async_hooks"),mw=(t,r)=>{globalThis[t]=r},mR=t=>globalThis[t];function mk({name:t,fallback:r=!0}){let a=Symbol.for(`xmcp-context-${t}`),i=Symbol.for(`xmcp-context-${t}-fallback-store`);if(mR(a))return mR(a);let n=new m$.AsyncLocalStorage,o=globalThis[i]??{current:null};mw(i,o);let s={provider:(t,a)=>(r&&(o.current=t),n.run(t,a)),getContext:()=>{let a=n.getStore();if(a)return a;if(r&&o.current)return o.current;throw Error(`getContext() can only be used within the ${t} context.`)},setContext:a=>{let i=n.getStore()??(r?o.current:null);if(!i)throw Error(`setContext() can only be used within the ${t} context.`);Object.assign(i,a)}};return mw(a,s),s}let mx=mk({name:"http-request-context"});mx.setContext;let mP=mx.getContext,mE=mx.provider,mT=t=>"object"==typeof t&&null!==t&&!Array.isArray(t),mj=t=>{if(!mT(t)||"string"!=typeof t.name||"string"!=typeof t.version)return;let r={name:t.name,version:t.version};return"string"==typeof t.title&&(r.title=t.title),"string"==typeof t.websiteUrl&&(r.websiteUrl=t.websiteUrl),"string"==typeof t.description&&(r.description=t.description),r},mO=t=>{if(t&&"initialize"===t.method&&mT(t.params))return mj(t.params.clientInfo)},mC=(t,r)=>{let a=r.toLowerCase();for(let[r,i]of Object.entries(t)){if(r.toLowerCase()!==a)continue;let t=Array.isArray(i)?i[0]:i;if("string"!=typeof t)break;let n=t.trim();return n.length>0?n:void 0}};function mI(t){let{tags:r,enabled:a,...i}=t;return{...i,_meta:void 0===r?i._meta:{...i._meta,"xmcp/tags":r}}}let mN=new class{add(t,r){this.resources.set(t,r)}getAll(){return this.resources}clear(){this.resources.clear()}has(t){return this.resources.has(t)}constructor(){!function(t,r,a){r in t?Object.defineProperty(t,r,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[r]=a}(this,"resources",new Map)}},mq=mk({name:"request-context",fallback:!1}),mA=mk({name:"client-info-context"});mA.setContext;let mM=mA.getContext;mA.provider;let mz=new Set(["message","mode","requestedSchema"]),mL=new Set(["elicitationId","message","mode","url"]),mZ=new Set(["properties","required","type"]),mD=new Set(["default","description","format","maxLength","minLength","title","type"]),mU=new Set(["default","description","enum","enumNames","title","type"]),mV=new Set(["default","description","title","type"]),mF=new Set(["default","description","maximum","minimum","title","type"]),mH=new Set(["date","date-time","email","uri"]);async function mJ(t,r,a){let i=function(t){let r=t.mode??"form";if("url"===r)return function(t){let r;mK(t,"Elicitation request must be a plain object."),mB(t,mL,"URL elicitation"),mG(t.message,"URL elicitation requires a string message."),mW(t.elicitationId,"URL elicitation requires a non-empty elicitationId."),mW(t.url,"URL elicitation requires a non-empty URL.");try{r=new URL(t.url)}catch{throw Error("URL elicitation requires a valid http or https URL.")}if("http:"!==r.protocol&&"https:"!==r.protocol)throw Error("URL elicitation requires a valid http or https URL.")}(t),t;if("form"!==r)throw Error(`Unsupported elicitation mode "${String(t.mode)}". Expected "form" or "url".`);return function(t){mK(t,"Elicitation request must be a plain object."),mB(t,mz,"Form elicitation"),mG(t.message,"Form elicitation requires a string message.");let r=t.requestedSchema;if(mK(r,"Form elicitation requires a flat object schema."),mB(r,mZ,"Form elicitation schema"),"object"!==r.type)throw Error('Form elicitation schema must use type "object".');for(let[t,a]of(mK(r.properties,"Form elicitation schema requires a properties object."),Object.entries(r.properties)))!function(t,r){if(mK(r,`Form elicitation field "${t}" must be a plain object.`),mY(r.title,`Form elicitation field "${t}" title must be a string.`),mY(r.description,`Form elicitation field "${t}" description must be a string.`),"string"===r.type&&"enum"in r){var a,i;if(mB(r,mU,`Form elicitation field "${t}"`),mQ(r.enum,`Form elicitation field "${t}" enum values must be strings.`),a=r.enumNames,i=`Form elicitation field "${t}" enumNames must be strings.`,void 0!==a&&mQ(a,i),void 0!==r.enumNames&&r.enumNames.length!==r.enum.length)throw Error(`Form elicitation field "${t}" enumNames length must match enum length.`);if(mY(r.default,`Form elicitation field "${t}" default must be a string.`),void 0!==r.default&&!r.enum.includes(r.default))throw Error(`Form elicitation field "${t}" default must be one of its enum values.`);return}if("string"===r.type&&!("enum"in r)){mB(r,mD,`Form elicitation field "${t}"`),mX(r.minLength,`Form elicitation field "${t}" minLength must be a number.`),mX(r.maxLength,`Form elicitation field "${t}" maxLength must be a number.`),mY(r.default,`Form elicitation field "${t}" default must be a string.`);let a=r.format;if(mY(a,`Form elicitation field "${t}" format must be a string.`),void 0!==a&&!mH.has(a))throw Error(`Form elicitation field "${t}" format must be one of: ${Array.from(mH).join(", ")}.`);return}if("boolean"===r.type){if(mB(r,mV,`Form elicitation field "${t}"`),void 0!==r.default&&"boolean"!=typeof r.default)throw Error(`Form elicitation field "${t}" default must be a boolean.`);return}if("number"===r.type||"integer"===r.type){mB(r,mF,`Form elicitation field "${t}"`),mX(r.minimum,`Form elicitation field "${t}" minimum must be a number.`),mX(r.maximum,`Form elicitation field "${t}" maximum must be a number.`),mX(r.default,`Form elicitation field "${t}" default must be a number.`);return}throw Error(`Form elicitation field "${t}" uses unsupported type "${String(r.type)}". Supported types are string, boolean, number, integer, and string enums.`)}(t,a);if(void 0!==r.required){if(!Array.isArray(r.required)||r.required.some(t=>"string"!=typeof t))throw Error("Form elicitation schema required fields must be a string array.");for(let t of r.required)if(!(t in r.properties))throw Error(`Form elicitation schema required field "${t}" is not defined in properties.`)}}(t),{...t,mode:"form"}}(r);try{let r=await t.mcpReq.elicitInput(i,a);return{...r,content:r.content??void 0}}catch(t){if(t instanceof lK&&t.code===lB.MethodNotSupportedByProtocolVersion)throw Error("extra.elicit() is not available on protocol revision 2026-07-28: server-initiated elicitation was replaced by multi round-trip requests. Return inputRequired({ ... }) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw t}}function mB(t,r,a){let i=Object.keys(t).filter(t=>!r.has(t));if(0!==i.length)throw Error(`${a} includes unsupported key(s): ${i.join(", ")}.`)}function mK(t,r){if("object"!=typeof t||null===t||Array.isArray(t))throw Error(r)}function mG(t,r){if("string"!=typeof t)throw Error(r)}function mW(t,r){if("string"!=typeof t||0===t.trim().length)throw Error(r)}function mY(t,r){if(void 0!==t&&"string"!=typeof t)throw Error(r)}function mX(t,r){if(void 0!==t&&"number"!=typeof t)throw Error(r)}function mQ(t,r){if(!Array.isArray(t)||t.some(t=>"string"!=typeof t))throw Error(r)}let m0=new Set(["_meta","includeContext","maxTokens","messages","metadata","modelPreferences","stopSequences","systemPrompt","temperature"]),m1=new Set(["task","toolChoice","tools"]),m2=new Set(["text","image","audio"]);async function m9(t,r,a){let i=function(t){m4(t,"Sampling request must be a plain object.");let r=Object.keys(t),a=r.filter(t=>m1.has(t));if(a.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${a.join(", ")}.`);let i=r.filter(t=>!m0.has(t));if(i.length>0)throw Error(`Sampling request includes unsupported key(s): ${i.join(", ")}.`);if(!Array.isArray(t.messages)||0===t.messages.length)throw Error("Sampling requires at least one message.");for(let[r,a]of t.messages.entries())!function(t,r){if(m4(r,`Sampling message at index ${t} must be a plain object.`),"user"!==r.role&&"assistant"!==r.role)throw Error(`Sampling message at index ${t} requires role "user" or "assistant".`);let a=r.content;m4(a,`Sampling message at index ${t} requires a content object.`);let i=a.type;if("string"!=typeof i||!m2.has(i))throw Error(`Sampling message at index ${t} uses unsupported content type "${String(i)}". Supported types are text, image, and audio.`);if("text"===i&&"string"!=typeof a.text)throw Error(`Sampling message at index ${t} requires string text content.`);if(("image"===i||"audio"===i)&&("string"!=typeof a.data||"string"!=typeof a.mimeType))throw Error(`Sampling message at index ${t} requires base64 data and a mimeType.`)}(r,a);if("number"!=typeof t.maxTokens)throw Error("Sampling requires a numeric maxTokens.");return t}(r);try{return await t.mcpReq.requestSampling(i,a)}catch(t){if(t instanceof lK&&t.code===lB.MethodNotSupportedByProtocolVersion)throw Error("extra.sample() is not available on protocol revision 2026-07-28: server-initiated sampling was replaced by multi round-trip requests. Return inputRequired({ ... }) with inputRequired.createMessage(...) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw t}}function m4(t,r){if("object"!=typeof t||null===t||Array.isArray(t))throw Error(r)}let m3={text:t=>"string"!=typeof t.text?{valid:!1,error:'Text content must have a "text" property of type string'}:{valid:!0},image:t=>"string"!=typeof t.data?{valid:!1,error:'Image content must have a "data" property of type string (base64-encoded image)'}:"string"!=typeof t.mimeType?{valid:!1,error:'Image content must have a "mimeType" property of type string'}:{valid:!0},audio:t=>"string"!=typeof t.data?{valid:!1,error:'Audio content must have a "data" property of type string (base64-encoded audio)'}:"string"!=typeof t.mimeType?{valid:!1,error:'Audio content must have a "mimeType" property of type string'}:{valid:!0},resource_link:t=>"string"!=typeof t.name?{valid:!1,error:'Resource link content must have a "name" property of type string'}:"string"!=typeof t.uri?{valid:!1,error:'Resource link content must have a "uri" property of type string'}:void 0!==t.title&&"string"!=typeof t.title?{valid:!1,error:'Resource link "title" property must be a string if provided'}:void 0!==t.description&&"string"!=typeof t.description?{valid:!1,error:'Resource link "description" property must be a string if provided'}:void 0!==t.mimeType&&"string"!=typeof t.mimeType?{valid:!1,error:'Resource link "mimeType" property must be a string if provided'}:{valid:!0}};function m6(t){if(!t||"object"!=typeof t)return{valid:!1,error:"Content must be an object"};if("string"!=typeof t.type)return{valid:!1,error:'Content must have a "type" property of type string'};if(void 0!==t._meta&&(null===t._meta||"object"!=typeof t._meta))return{valid:!1,error:'Content "_meta" property must be an object if provided'};let r=m3[t.type];return r?r(t):{valid:!0}}function m5(t,r,a,i){if(null===t||"object"!=typeof t||Array.isArray(t))throw Error(`Tool "${a}" ${i}: expected a plain object.`);let n=new Set(Object.keys(r)),o=Object.keys(t).filter(t=>!n.has(t));if(o.length>0)throw Error(`Tool "${a}" ${i}: unrecognized key(s): ${o.join(", ")}`);for(let[n,o]of Object.entries(r))try{o.parse(t[n])}catch(t){throw Error(`Tool "${a}" ${i}: ${t?.message??`invalid field "${n}"`}`)}}function m8(t){return!!(t&&"object"==typeof t&&Object.keys(t).some(t=>t.startsWith("ui/")))}function m7(t){let r=t.mcpReq.envelope,a=mj(r?.[nG]);if(!a)try{let t,r=mP();a=r.clientInfo??(t=r.headers,mj({name:mC(t,"x-mcp-client-name"),version:mC(t,"x-mcp-client-version"),title:mC(t,"x-mcp-client-title"),websiteUrl:mC(t,"x-mcp-client-website-url"),description:mC(t,"x-mcp-client-description")}))}catch{}if(!a)try{a=mM().clientInfo}catch{}return a}function he(t){let r=[...t];return(t,a,i)=>(function(t,r,a){let i,n=new Map;if(t.http){let t=mP(),r=Object.fromEntries(Object.entries(t.headers).map(([t,r])=>[t,Array.isArray(r)?Object.freeze([...r]):r]));i=Object.freeze({id:t.id,headers:Object.freeze(r)})}return mq.provider(Object.freeze({clientInfo:r?Object.freeze({...r}):void 0,http:i,authInfo:t.http?.authInfo,signal:t.mcpReq.signal,set(t,r){n.set(t,r)},get:t=>n.get(t),async progress(r,a){let i=t.mcpReq._meta?.progressToken;void 0!==i&&await t.mcpReq.notify({method:"notifications/progress",params:{progressToken:i,progress:r,...void 0===a?{}:{total:a}}})},log:(r,a)=>t.mcpReq.log(r,a)}),a)})(a,m7(a),async()=>{if(0===r.length)return i();let a=Object.freeze({...function(){try{return mq.getContext()}catch{throw Error("getRequestContext() can only be used while handling an MCP request.")}}(),...t,params:Object.freeze({...t.params})}),n=-1,o=async t=>{if(t<=n)throw Error("MCP middleware next() can only be called once");n=t;let s=r[t];return s?s(a,()=>o(t+1)):i()};return o(0)})}let ht=new Set(["tools/list","prompts/get","prompts/list","resources/read","resources/list","resources/templates/list","completion/complete"]);function hr(t){return t.endsWith(".tsx")}let ha=Symbol("Let zodToJsonSchema decide on which parser to use"),hi={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=M||(M={})).assertEqual=t=>{},T.assertIs=function(t){},T.assertNever=function(t){throw Error()},T.arrayToEnum=t=>{let r={};for(let a of t)r[a]=a;return r},T.getValidEnumValues=t=>{let r=T.objectKeys(t).filter(r=>"number"!=typeof t[t[r]]),a={};for(let i of r)a[i]=t[i];return T.objectValues(a)},T.objectValues=t=>T.objectKeys(t).map(function(r){return t[r]}),T.objectKeys="function"==typeof Object.keys?t=>Object.keys(t):t=>{let r=[];for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&r.push(a);return r},T.find=(t,r)=>{for(let a of t)if(r(a))return a},T.isInteger="function"==typeof Number.isInteger?t=>Number.isInteger(t):t=>"number"==typeof t&&Number.isFinite(t)&&Math.floor(t)===t,T.joinValues=function(t,r=" | "){return t.map(t=>"string"==typeof t?`'${t}'`:t).join(r)},T.jsonStringifyReplacer=(t,r)=>"bigint"==typeof r?r.toString():r,(z||(z={})).mergeShapes=(t,r)=>({...t,...r});let hn=M.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),ho=t=>{switch(typeof t){case"undefined":return hn.undefined;case"string":return hn.string;case"number":return Number.isNaN(t)?hn.nan:hn.number;case"boolean":return hn.boolean;case"function":return hn.function;case"bigint":return hn.bigint;case"symbol":return hn.symbol;case"object":if(Array.isArray(t))return hn.array;if(null===t)return hn.null;if(t.then&&"function"==typeof t.then&&t.catch&&"function"==typeof t.catch)return hn.promise;if("undefined"!=typeof Map&&t instanceof Map)return hn.map;if("undefined"!=typeof Set&&t instanceof Set)return hn.set;if("undefined"!=typeof Date&&t instanceof Date)return hn.date;return hn.object;default:return hn.unknown}},hs=M.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 hl extends Error{get errors(){return this.issues}constructor(t){super(),this.issues=[],this.addIssue=t=>{this.issues=[...this.issues,t]},this.addIssues=(t=[])=>{this.issues=[...this.issues,...t]};const r=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,r):this.__proto__=r,this.name="ZodError",this.issues=t}format(t){let r=t||function(t){return t.message},a={_errors:[]},i=t=>{for(let n of t.issues)if("invalid_union"===n.code)n.unionErrors.map(i);else if("invalid_return_type"===n.code)i(n.returnTypeError);else if("invalid_arguments"===n.code)i(n.argumentsError);else if(0===n.path.length)a._errors.push(r(n));else{let t=a,i=0;for(;i<n.path.length;){let a=n.path[i],o=i===n.path.length-1;if("_errors"===a){o&&t._errors.push(r(n)),i++;continue}Object.prototype.hasOwnProperty.call(t,a)||("__proto__"===a?Object.defineProperty(t,a,{value:{_errors:[]},writable:!0,enumerable:!0,configurable:!0}):t[a]={_errors:[]}),t=t[a],o&&t._errors.push(r(n)),i++}}};return i(this),a}static assert(t){if(!(t instanceof hl))throw Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,M.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(t=t=>t.message){let r=Object.create(null),a=[];for(let i of this.issues)if(i.path.length>0){let a=i.path[0];r[a]=r[a]||[],r[a].push(t(i))}else a.push(t(i));return{formErrors:a,fieldErrors:r}}get formErrors(){return this.flatten()}}hl.create=t=>new hl(t);let hc=(t,r)=>{let a;switch(t.code){case hs.invalid_type:a=t.received===hn.undefined?"Required":`Expected ${t.expected}, received ${t.received}`;break;case hs.invalid_literal:a=`Invalid literal value, expected ${JSON.stringify(t.expected,M.jsonStringifyReplacer)}`;break;case hs.unrecognized_keys:a=`Unrecognized key(s) in object: ${M.joinValues(t.keys,", ")}`;break;case hs.invalid_union:a="Invalid input";break;case hs.invalid_union_discriminator:a=`Invalid discriminator value. Expected ${M.joinValues(t.options)}`;break;case hs.invalid_enum_value:a=`Invalid enum value. Expected ${M.joinValues(t.options)}, received '${t.received}'`;break;case hs.invalid_arguments:a="Invalid function arguments";break;case hs.invalid_return_type:a="Invalid function return type";break;case hs.invalid_date:a="Invalid date";break;case hs.invalid_string:"object"==typeof t.validation?"includes"in t.validation?(a=`Invalid input: must include "${t.validation.includes}"`,"number"==typeof t.validation.position&&(a=`${a} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?a=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?a=`Invalid input: must end with "${t.validation.endsWith}"`:M.assertNever(t.validation):a="regex"!==t.validation?`Invalid ${t.validation}`:"Invalid";break;case hs.too_small:a="array"===t.type?`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:"string"===t.type?`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:"number"===t.type||"bigint"===t.type?`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:"date"===t.type?`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:"Invalid input";break;case hs.too_big:a="array"===t.type?`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:"string"===t.type?`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:"number"===t.type?`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:"bigint"===t.type?`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:"date"===t.type?`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:"Invalid input";break;case hs.custom:a="Invalid input";break;case hs.invalid_intersection_types:a="Intersection results could not be merged";break;case hs.not_multiple_of:a=`Number must be a multiple of ${t.multipleOf}`;break;case hs.not_finite:a="Number must be finite";break;default:a=r.defaultError,M.assertNever(t)}return{message:a}};(j=L||(L={})).errToObj=t=>"string"==typeof t?{message:t}:t||{},j.toString=t=>"string"==typeof t?t:t?.message;let hu=t=>{let{data:r,path:a,errorMaps:i,issueData:n}=t,o=[...a,...n.path||[]],s={...n,path:o};if(void 0!==n.message)return{...n,path:o,message:n.message};let l="";for(let t of i.filter(t=>!!t).slice().reverse())l=t(s,{data:r,defaultError:l}).message;return{...n,path:o,message:l}};function hd(t,r){let a=hu({issueData:r,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,hc,void 0].filter(t=>!!t)});t.common.issues.push(a)}class hp{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(t,r){let a=[];for(let i of r){if("aborted"===i.status)return hm;"dirty"===i.status&&t.dirty(),a.push(i.value)}return{status:t.value,value:a}}static async mergeObjectAsync(t,r){let a=[];for(let t of r){let r=await t.key,i=await t.value;a.push({key:r,value:i})}return hp.mergeObjectSync(t,a)}static mergeObjectSync(t,r){let a={};for(let i of r){let{key:r,value:n}=i;if("aborted"===r.status||"aborted"===n.status)return hm;"dirty"===r.status&&t.dirty(),"dirty"===n.status&&t.dirty(),"__proto__"!==r.value&&(void 0!==n.value||i.alwaysSet)&&(a[r.value]=n.value)}return{status:t.value,value:a}}}let hm=Object.freeze({status:"aborted"}),hh=t=>({status:"dirty",value:t}),hf=t=>({status:"valid",value:t}),hy=t=>"undefined"!=typeof Promise&&t instanceof Promise;class hg{constructor(t,r,a,i){this._cachedPath=[],this.parent=t,this.data=r,this._path=a,this._key=i}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}let hv=(t,r)=>{if("valid"===r.status)return{success:!0,data:r.value};if(!t.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let r=new hl(t.common.issues);return this._error=r,this._error}}};function h_(t){if(!t)return{};let{errorMap:r,invalid_type_error:a,required_error:i,description:n}=t;if(r&&(a||i))throw Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');return r?{errorMap:r,description:n}:{errorMap:(r,n)=>{let{message:o}=t;return"invalid_enum_value"===r.code?{message:o??n.defaultError}:void 0===n.data?{message:o??i??n.defaultError}:"invalid_type"!==r.code?{message:n.defaultError}:{message:o??a??n.defaultError}},description:n}}class hb{get description(){return this._def.description}_getType(t){return ho(t.data)}_getOrReturnCtx(t,r){return r||{common:t.parent.common,data:t.data,parsedType:ho(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new hp,ctx:{common:t.parent.common,data:t.data,parsedType:ho(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){let r=this._parse(t);if(hy(r))throw Error("Synchronous parse encountered promise.");return r}_parseAsync(t){return Promise.resolve(this._parse(t))}parse(t,r){let a=this.safeParse(t,r);if(a.success)return a.data;throw a.error}safeParse(t,r){let a={common:{issues:[],async:r?.async??!1,contextualErrorMap:r?.errorMap},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:ho(t)},i=this._parseSync({data:t,path:a.path,parent:a});return hv(a,i)}"~validate"(t){let r={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:ho(t)};if(!this["~standard"].async)try{let a=this._parseSync({data:t,path:[],parent:r});return"valid"===a.status?{value:a.value}:{issues:r.common.issues}}catch(t){t?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),r.common={issues:[],async:!0}}return this._parseAsync({data:t,path:[],parent:r}).then(t=>"valid"===t.status?{value:t.value}:{issues:r.common.issues})}async parseAsync(t,r){let a=await this.safeParseAsync(t,r);if(a.success)return a.data;throw a.error}async safeParseAsync(t,r){let a={common:{issues:[],contextualErrorMap:r?.errorMap,async:!0},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:ho(t)},i=this._parse({data:t,path:a.path,parent:a});return hv(a,await (hy(i)?i:Promise.resolve(i)))}refine(t,r){return this._refinement((a,i)=>{let n=t(a),o=()=>i.addIssue({code:hs.custom,..."string"==typeof r||void 0===r?{message:r}:"function"==typeof r?r(a):r});return"undefined"!=typeof Promise&&n instanceof Promise?n.then(t=>!!t||(o(),!1)):!!n||(o(),!1)})}refinement(t,r){return this._refinement((a,i)=>!!t(a)||(i.addIssue("function"==typeof r?r(a,i):r),!1))}_refinement(t){return new fa({schema:this,typeName:Z.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}constructor(t){this.spa=this.safeParseAsync,this._def=t,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:t=>this["~validate"](t)}}optional(){return fi.create(this,this._def)}nullable(){return fn.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return hW.create(this)}promise(){return fr.create(this,this._def)}or(t){return hX.create([this,t],this._def)}and(t){return h1.create(this,t,this._def)}transform(t){return new fa({...h_(this._def),schema:this,typeName:Z.ZodEffects,effect:{type:"transform",transform:t}})}default(t){return new fo({...h_(this._def),innerType:this,defaultValue:"function"==typeof t?t:()=>t,typeName:Z.ZodDefault})}brand(){return new fc({typeName:Z.ZodBranded,type:this,...h_(this._def)})}catch(t){return new fs({...h_(this._def),innerType:this,catchValue:"function"==typeof t?t:()=>t,typeName:Z.ZodCatch})}describe(t){return new this.constructor({...this._def,description:t})}pipe(t){return fu.create(this,t)}readonly(){return fd.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}let hS=/^c[^\s-]{8,}$/i,h$=/^[0-9a-z]+$/,hw=/^[0-9A-HJKMNP-TV-Z]{26}$/i,hR=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,hk=/^[a-z0-9_-]{21}$/i,hx=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,hP=/^[-+]?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])$/,hj=/^(?:(?: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])$/,hO=/^(([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]))$/,hC=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,hI=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,hN=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,hq="((\\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])))",hA=RegExp(`^${hq}$`);function hM(t){let r="[0-5]\\d";t.precision?r=`${r}\\.\\d{${t.precision}}`:null==t.precision&&(r=`${r}(\\.\\d+)?`);let a=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${r})${a}`}class hz extends hb{_parse(t){var r,a,i,n;let o;if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==hn.string){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.string,received:r.parsedType}),hm}let s=new hp;for(let l of this._def.checks)if("min"===l.kind)t.data.length<l.value&&(hd(o=this._getOrReturnCtx(t,o),{code:hs.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),s.dirty());else if("max"===l.kind)t.data.length>l.value&&(hd(o=this._getOrReturnCtx(t,o),{code:hs.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),s.dirty());else if("length"===l.kind){let r=t.data.length>l.value,a=t.data.length<l.value;(r||a)&&(o=this._getOrReturnCtx(t,o),r?hd(o,{code:hs.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}):a&&hd(o,{code:hs.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}),s.dirty())}else if("email"===l.kind)hE.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"email",code:hs.invalid_string,message:l.message}),s.dirty());else if("emoji"===l.kind)h||(h=RegExp("^[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$","u")),h.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"emoji",code:hs.invalid_string,message:l.message}),s.dirty());else if("uuid"===l.kind)hR.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"uuid",code:hs.invalid_string,message:l.message}),s.dirty());else if("nanoid"===l.kind)hk.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"nanoid",code:hs.invalid_string,message:l.message}),s.dirty());else if("cuid"===l.kind)hS.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"cuid",code:hs.invalid_string,message:l.message}),s.dirty());else if("cuid2"===l.kind)h$.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"cuid2",code:hs.invalid_string,message:l.message}),s.dirty());else if("ulid"===l.kind)hw.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"ulid",code:hs.invalid_string,message:l.message}),s.dirty());else if("url"===l.kind)try{new URL(t.data)}catch{hd(o=this._getOrReturnCtx(t,o),{validation:"url",code:hs.invalid_string,message:l.message}),s.dirty()}else"regex"===l.kind?(l.regex.lastIndex=0,l.regex.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"regex",code:hs.invalid_string,message:l.message}),s.dirty())):"trim"===l.kind?t.data=t.data.trim():"includes"===l.kind?t.data.includes(l.value,l.position)||(hd(o=this._getOrReturnCtx(t,o),{code:hs.invalid_string,validation:{includes:l.value,position:l.position},message:l.message}),s.dirty()):"toLowerCase"===l.kind?t.data=t.data.toLowerCase():"toUpperCase"===l.kind?t.data=t.data.toUpperCase():"startsWith"===l.kind?t.data.startsWith(l.value)||(hd(o=this._getOrReturnCtx(t,o),{code:hs.invalid_string,validation:{startsWith:l.value},message:l.message}),s.dirty()):"endsWith"===l.kind?t.data.endsWith(l.value)||(hd(o=this._getOrReturnCtx(t,o),{code:hs.invalid_string,validation:{endsWith:l.value},message:l.message}),s.dirty()):"datetime"===l.kind?(function(t){let r=`${hq}T${hM(t)}`,a=[];return a.push(t.local?"Z?":"Z"),t.offset&&a.push("([+-]\\d{2}:?\\d{2})"),r=`${r}(${a.join("|")})`,RegExp(`^${r}$`)})(l).test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{code:hs.invalid_string,validation:"datetime",message:l.message}),s.dirty()):"date"===l.kind?hA.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{code:hs.invalid_string,validation:"date",message:l.message}),s.dirty()):"time"===l.kind?RegExp(`^${hM(l)}$`).test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{code:hs.invalid_string,validation:"time",message:l.message}),s.dirty()):"duration"===l.kind?hP.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"duration",code:hs.invalid_string,message:l.message}),s.dirty()):"ip"===l.kind?(r=t.data,!(("v4"===(a=l.version)||!a)&&hT.test(r)||("v6"===a||!a)&&hO.test(r))&&1&&(hd(o=this._getOrReturnCtx(t,o),{validation:"ip",code:hs.invalid_string,message:l.message}),s.dirty())):"jwt"===l.kind?!function(t,r){if(!hx.test(t))return!1;try{let[a]=t.split(".");if(!a)return!1;let i=a.replace(/-/g,"+").replace(/_/g,"/").padEnd(a.length+(4-a.length%4)%4,"="),n=JSON.parse(atob(i));if("object"!=typeof n||null===n||"typ"in n&&n?.typ!=="JWT"||!n.alg||r&&n.alg!==r)return!1;return!0}catch{return!1}}(t.data,l.alg)&&(hd(o=this._getOrReturnCtx(t,o),{validation:"jwt",code:hs.invalid_string,message:l.message}),s.dirty()):"cidr"===l.kind?(i=t.data,!(("v4"===(n=l.version)||!n)&&hj.test(i)||("v6"===n||!n)&&hC.test(i))&&1&&(hd(o=this._getOrReturnCtx(t,o),{validation:"cidr",code:hs.invalid_string,message:l.message}),s.dirty())):"base64"===l.kind?hI.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"base64",code:hs.invalid_string,message:l.message}),s.dirty()):"base64url"===l.kind?hN.test(t.data)||(hd(o=this._getOrReturnCtx(t,o),{validation:"base64url",code:hs.invalid_string,message:l.message}),s.dirty()):M.assertNever(l);return{status:s.value,value:t.data}}_regex(t,r,a){return this.refinement(r=>t.test(r),{validation:r,code:hs.invalid_string,...L.errToObj(a)})}_addCheck(t){return new hz({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...L.errToObj(t)})}url(t){return this._addCheck({kind:"url",...L.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...L.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...L.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...L.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...L.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...L.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...L.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...L.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...L.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...L.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...L.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...L.errToObj(t)})}datetime(t){return"string"==typeof t?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:t}):this._addCheck({kind:"datetime",precision:void 0===t?.precision?null:t?.precision,offset:t?.offset??!1,local:t?.local??!1,...L.errToObj(t?.message)})}date(t){return this._addCheck({kind:"date",message:t})}time(t){return"string"==typeof t?this._addCheck({kind:"time",precision:null,message:t}):this._addCheck({kind:"time",precision:void 0===t?.precision?null:t?.precision,...L.errToObj(t?.message)})}duration(t){return this._addCheck({kind:"duration",...L.errToObj(t)})}regex(t,r){return this._addCheck({kind:"regex",regex:t,...L.errToObj(r)})}includes(t,r){return this._addCheck({kind:"includes",value:t,position:r?.position,...L.errToObj(r?.message)})}startsWith(t,r){return this._addCheck({kind:"startsWith",value:t,...L.errToObj(r)})}endsWith(t,r){return this._addCheck({kind:"endsWith",value:t,...L.errToObj(r)})}min(t,r){return this._addCheck({kind:"min",value:t,...L.errToObj(r)})}max(t,r){return this._addCheck({kind:"max",value:t,...L.errToObj(r)})}length(t,r){return this._addCheck({kind:"length",value:t,...L.errToObj(r)})}nonempty(t){return this.min(1,L.errToObj(t))}trim(){return new hz({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new hz({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new hz({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(t=>"datetime"===t.kind)}get isDate(){return!!this._def.checks.find(t=>"date"===t.kind)}get isTime(){return!!this._def.checks.find(t=>"time"===t.kind)}get isDuration(){return!!this._def.checks.find(t=>"duration"===t.kind)}get isEmail(){return!!this._def.checks.find(t=>"email"===t.kind)}get isURL(){return!!this._def.checks.find(t=>"url"===t.kind)}get isEmoji(){return!!this._def.checks.find(t=>"emoji"===t.kind)}get isUUID(){return!!this._def.checks.find(t=>"uuid"===t.kind)}get isNANOID(){return!!this._def.checks.find(t=>"nanoid"===t.kind)}get isCUID(){return!!this._def.checks.find(t=>"cuid"===t.kind)}get isCUID2(){return!!this._def.checks.find(t=>"cuid2"===t.kind)}get isULID(){return!!this._def.checks.find(t=>"ulid"===t.kind)}get isIP(){return!!this._def.checks.find(t=>"ip"===t.kind)}get isCIDR(){return!!this._def.checks.find(t=>"cidr"===t.kind)}get isBase64(){return!!this._def.checks.find(t=>"base64"===t.kind)}get isBase64url(){return!!this._def.checks.find(t=>"base64url"===t.kind)}get minLength(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxLength(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}}hz.create=t=>new hz({checks:[],typeName:Z.ZodString,coerce:t?.coerce??!1,...h_(t)});class hL extends hb{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){let r;if(this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==hn.number){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.number,received:r.parsedType}),hm}let a=new hp;for(let i of this._def.checks)"int"===i.kind?M.isInteger(t.data)||(hd(r=this._getOrReturnCtx(t,r),{code:hs.invalid_type,expected:"integer",received:"float",message:i.message}),a.dirty()):"min"===i.kind?(i.inclusive?t.data<i.value:t.data<=i.value)&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),a.dirty()):"max"===i.kind?(i.inclusive?t.data>i.value:t.data>=i.value)&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),a.dirty()):"multipleOf"===i.kind?0!==function(t,r){let a=(t.toString().split(".")[1]||"").length,i=(r.toString().split(".")[1]||"").length,n=a>i?a:i;return Number.parseInt(t.toFixed(n).replace(".",""))%Number.parseInt(r.toFixed(n).replace(".",""))/10**n}(t.data,i.value)&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.not_multiple_of,multipleOf:i.value,message:i.message}),a.dirty()):"finite"===i.kind?Number.isFinite(t.data)||(hd(r=this._getOrReturnCtx(t,r),{code:hs.not_finite,message:i.message}),a.dirty()):M.assertNever(i);return{status:a.value,value:t.data}}gte(t,r){return this.setLimit("min",t,!0,L.toString(r))}gt(t,r){return this.setLimit("min",t,!1,L.toString(r))}lte(t,r){return this.setLimit("max",t,!0,L.toString(r))}lt(t,r){return this.setLimit("max",t,!1,L.toString(r))}setLimit(t,r,a,i){return new hL({...this._def,checks:[...this._def.checks,{kind:t,value:r,inclusive:a,message:L.toString(i)}]})}_addCheck(t){return new hL({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:L.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:L.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:L.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:L.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:L.toString(t)})}multipleOf(t,r){return this._addCheck({kind:"multipleOf",value:t,message:L.toString(r)})}finite(t){return this._addCheck({kind:"finite",message:L.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:L.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:L.toString(t)})}get minValue(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxValue(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}get isInt(){return!!this._def.checks.find(t=>"int"===t.kind||"multipleOf"===t.kind&&M.isInteger(t.value))}get isFinite(){let t=null,r=null;for(let a of this._def.checks)if("finite"===a.kind||"int"===a.kind||"multipleOf"===a.kind)return!0;else"min"===a.kind?(null===r||a.value>r)&&(r=a.value):"max"===a.kind&&(null===t||a.value<t)&&(t=a.value);return Number.isFinite(r)&&Number.isFinite(t)}}hL.create=t=>new hL({checks:[],typeName:Z.ZodNumber,coerce:t?.coerce||!1,...h_(t)});class hZ extends hb{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){let r;if(this._def.coerce)try{t.data=BigInt(t.data)}catch{return this._getInvalidInput(t)}if(this._getType(t)!==hn.bigint)return this._getInvalidInput(t);let a=new hp;for(let i of this._def.checks)"min"===i.kind?(i.inclusive?t.data<i.value:t.data<=i.value)&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),a.dirty()):"max"===i.kind?(i.inclusive?t.data>i.value:t.data>=i.value)&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),a.dirty()):"multipleOf"===i.kind?t.data%i.value!==BigInt(0)&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.not_multiple_of,multipleOf:i.value,message:i.message}),a.dirty()):M.assertNever(i);return{status:a.value,value:t.data}}_getInvalidInput(t){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.bigint,received:r.parsedType}),hm}gte(t,r){return this.setLimit("min",t,!0,L.toString(r))}gt(t,r){return this.setLimit("min",t,!1,L.toString(r))}lte(t,r){return this.setLimit("max",t,!0,L.toString(r))}lt(t,r){return this.setLimit("max",t,!1,L.toString(r))}setLimit(t,r,a,i){return new hZ({...this._def,checks:[...this._def.checks,{kind:t,value:r,inclusive:a,message:L.toString(i)}]})}_addCheck(t){return new hZ({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:L.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:L.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:L.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:L.toString(t)})}multipleOf(t,r){return this._addCheck({kind:"multipleOf",value:t,message:L.toString(r)})}get minValue(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxValue(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}}hZ.create=t=>new hZ({checks:[],typeName:Z.ZodBigInt,coerce:t?.coerce??!1,...h_(t)});class hD extends hb{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==hn.boolean){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.boolean,received:r.parsedType}),hm}return hf(t.data)}}hD.create=t=>new hD({typeName:Z.ZodBoolean,coerce:t?.coerce||!1,...h_(t)});class hU extends hb{_parse(t){let r;if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==hn.date){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.date,received:r.parsedType}),hm}if(Number.isNaN(t.data.getTime()))return hd(this._getOrReturnCtx(t),{code:hs.invalid_date}),hm;let a=new hp;for(let i of this._def.checks)"min"===i.kind?t.data.getTime()<i.value&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),a.dirty()):"max"===i.kind?t.data.getTime()>i.value&&(hd(r=this._getOrReturnCtx(t,r),{code:hs.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),a.dirty()):M.assertNever(i);return{status:a.value,value:new Date(t.data.getTime())}}_addCheck(t){return new hU({...this._def,checks:[...this._def.checks,t]})}min(t,r){return this._addCheck({kind:"min",value:t.getTime(),message:L.toString(r)})}max(t,r){return this._addCheck({kind:"max",value:t.getTime(),message:L.toString(r)})}get minDate(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return null!=t?new Date(t):null}get maxDate(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return null!=t?new Date(t):null}}hU.create=t=>new hU({checks:[],coerce:t?.coerce||!1,typeName:Z.ZodDate,...h_(t)});class hV extends hb{_parse(t){if(this._getType(t)!==hn.symbol){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.symbol,received:r.parsedType}),hm}return hf(t.data)}}hV.create=t=>new hV({typeName:Z.ZodSymbol,...h_(t)});class hF extends hb{_parse(t){if(this._getType(t)!==hn.undefined){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.undefined,received:r.parsedType}),hm}return hf(t.data)}}hF.create=t=>new hF({typeName:Z.ZodUndefined,...h_(t)});class hH extends hb{_parse(t){if(this._getType(t)!==hn.null){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.null,received:r.parsedType}),hm}return hf(t.data)}}hH.create=t=>new hH({typeName:Z.ZodNull,...h_(t)});class hJ extends hb{constructor(){super(...arguments),this._any=!0}_parse(t){return hf(t.data)}}hJ.create=t=>new hJ({typeName:Z.ZodAny,...h_(t)});class hB extends hb{constructor(){super(...arguments),this._unknown=!0}_parse(t){return hf(t.data)}}hB.create=t=>new hB({typeName:Z.ZodUnknown,...h_(t)});class hK extends hb{_parse(t){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.never,received:r.parsedType}),hm}}hK.create=t=>new hK({typeName:Z.ZodNever,...h_(t)});class hG extends hb{_parse(t){if(this._getType(t)!==hn.undefined){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.void,received:r.parsedType}),hm}return hf(t.data)}}hG.create=t=>new hG({typeName:Z.ZodVoid,...h_(t)});class hW extends hb{_parse(t){let{ctx:r,status:a}=this._processInputParams(t),i=this._def;if(r.parsedType!==hn.array)return hd(r,{code:hs.invalid_type,expected:hn.array,received:r.parsedType}),hm;if(null!==i.exactLength){let t=r.data.length>i.exactLength.value,n=r.data.length<i.exactLength.value;(t||n)&&(hd(r,{code:t?hs.too_big:hs.too_small,minimum:n?i.exactLength.value:void 0,maximum:t?i.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:i.exactLength.message}),a.dirty())}if(null!==i.minLength&&r.data.length<i.minLength.value&&(hd(r,{code:hs.too_small,minimum:i.minLength.value,type:"array",inclusive:!0,exact:!1,message:i.minLength.message}),a.dirty()),null!==i.maxLength&&r.data.length>i.maxLength.value&&(hd(r,{code:hs.too_big,maximum:i.maxLength.value,type:"array",inclusive:!0,exact:!1,message:i.maxLength.message}),a.dirty()),r.common.async)return Promise.all([...r.data].map((t,a)=>i.type._parseAsync(new hg(r,t,r.path,a)))).then(t=>hp.mergeArray(a,t));let n=[...r.data].map((t,a)=>i.type._parseSync(new hg(r,t,r.path,a)));return hp.mergeArray(a,n)}get element(){return this._def.type}min(t,r){return new hW({...this._def,minLength:{value:t,message:L.toString(r)}})}max(t,r){return new hW({...this._def,maxLength:{value:t,message:L.toString(r)}})}length(t,r){return new hW({...this._def,exactLength:{value:t,message:L.toString(r)}})}nonempty(t){return this.min(1,t)}}hW.create=(t,r)=>new hW({type:t,minLength:null,maxLength:null,exactLength:null,typeName:Z.ZodArray,...h_(r)});class hY extends hb{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;let t=this._def.shape(),r=M.objectKeys(t);return this._cached={shape:t,keys:r},this._cached}_parse(t){if(this._getType(t)!==hn.object){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.object,received:r.parsedType}),hm}let{status:r,ctx:a}=this._processInputParams(t),{shape:i,keys:n}=this._getCached(),o=[];if(!(this._def.catchall instanceof hK&&"strip"===this._def.unknownKeys))for(let t in a.data)n.includes(t)||o.push(t);let s=[];for(let t of n){let r=i[t],n=a.data[t];s.push({key:{status:"valid",value:t},value:r._parse(new hg(a,n,a.path,t)),alwaysSet:t in a.data})}if(this._def.catchall instanceof hK){let t=this._def.unknownKeys;if("passthrough"===t)for(let t of o)s.push({key:{status:"valid",value:t},value:{status:"valid",value:a.data[t]}});else if("strict"===t)o.length>0&&(hd(a,{code:hs.unrecognized_keys,keys:o}),r.dirty());else if("strip"===t);else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let t=this._def.catchall;for(let r of o){let i=a.data[r];s.push({key:{status:"valid",value:r},value:t._parse(new hg(a,i,a.path,r)),alwaysSet:r in a.data})}}return a.common.async?Promise.resolve().then(async()=>{let t=[];for(let r of s){let a=await r.key,i=await r.value;t.push({key:a,value:i,alwaysSet:r.alwaysSet})}return t}).then(t=>hp.mergeObjectSync(r,t)):hp.mergeObjectSync(r,s)}get shape(){return this._def.shape()}strict(t){return L.errToObj,new hY({...this._def,unknownKeys:"strict",...void 0!==t?{errorMap:(r,a)=>{let i=this._def.errorMap?.(r,a).message??a.defaultError;return"unrecognized_keys"===r.code?{message:L.errToObj(t).message??i}:{message:i}}}:{}})}strip(){return new hY({...this._def,unknownKeys:"strip"})}passthrough(){return new hY({...this._def,unknownKeys:"passthrough"})}extend(t){return new hY({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new hY({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:Z.ZodObject})}setKey(t,r){return this.augment({[t]:r})}catchall(t){return new hY({...this._def,catchall:t})}pick(t){let r={};for(let a of M.objectKeys(t))t[a]&&this.shape[a]&&(r[a]=this.shape[a]);return new hY({...this._def,shape:()=>r})}omit(t){let r={};for(let a of M.objectKeys(this.shape))t[a]||(r[a]=this.shape[a]);return new hY({...this._def,shape:()=>r})}deepPartial(){return function t(r){if(r instanceof hY){let a={};for(let i in r.shape){let n=r.shape[i];a[i]=fi.create(t(n))}return new hY({...r._def,shape:()=>a})}if(r instanceof hW)return new hW({...r._def,type:t(r.element)});if(r instanceof fi)return fi.create(t(r.unwrap()));if(r instanceof fn)return fn.create(t(r.unwrap()));if(r instanceof h2)return h2.create(r.items.map(r=>t(r)));else return r}(this)}partial(t){let r={};for(let a of M.objectKeys(this.shape)){let i=this.shape[a];t&&!t[a]?r[a]=i:r[a]=i.optional()}return new hY({...this._def,shape:()=>r})}required(t){let r={};for(let a of M.objectKeys(this.shape))if(t&&!t[a])r[a]=this.shape[a];else{let t=this.shape[a];for(;t instanceof fi;)t=t._def.innerType;r[a]=t}return new hY({...this._def,shape:()=>r})}keyof(){return h7(M.objectKeys(this.shape))}}hY.create=(t,r)=>new hY({shape:()=>t,unknownKeys:"strip",catchall:hK.create(),typeName:Z.ZodObject,...h_(r)}),hY.strictCreate=(t,r)=>new hY({shape:()=>t,unknownKeys:"strict",catchall:hK.create(),typeName:Z.ZodObject,...h_(r)}),hY.lazycreate=(t,r)=>new hY({shape:t,unknownKeys:"strip",catchall:hK.create(),typeName:Z.ZodObject,...h_(r)});class hX extends hb{_parse(t){let{ctx:r}=this._processInputParams(t),a=this._def.options;if(r.common.async)return Promise.all(a.map(async t=>{let a={...r,common:{...r.common,issues:[]},parent:null};return{result:await t._parseAsync({data:r.data,path:r.path,parent:a}),ctx:a}})).then(function(t){for(let r of t)if("valid"===r.result.status)return r.result;for(let a of t)if("dirty"===a.result.status)return r.common.issues.push(...a.ctx.common.issues),a.result;let a=t.map(t=>new hl(t.ctx.common.issues));return hd(r,{code:hs.invalid_union,unionErrors:a}),hm});{let t,i=[];for(let n of a){let a={...r,common:{...r.common,issues:[]},parent:null},o=n._parseSync({data:r.data,path:r.path,parent:a});if("valid"===o.status)return o;"dirty"!==o.status||t||(t={result:o,ctx:a}),a.common.issues.length&&i.push(a.common.issues)}if(t)return r.common.issues.push(...t.ctx.common.issues),t.result;let n=i.map(t=>new hl(t));return hd(r,{code:hs.invalid_union,unionErrors:n}),hm}}get options(){return this._def.options}}hX.create=(t,r)=>new hX({options:t,typeName:Z.ZodUnion,...h_(r)});let hQ=t=>{if(t instanceof h5)return hQ(t.schema);if(t instanceof fa)return hQ(t.innerType());if(t instanceof h8)return[t.value];if(t instanceof fe)return t.options;if(t instanceof ft)return M.objectValues(t.enum);else if(t instanceof fo)return hQ(t._def.innerType);else if(t instanceof hF)return[void 0];else if(t instanceof hH)return[null];else if(t instanceof fi)return[void 0,...hQ(t.unwrap())];else if(t instanceof fn)return[null,...hQ(t.unwrap())];else if(t instanceof fc)return hQ(t.unwrap());else if(t instanceof fd)return hQ(t.unwrap());else if(t instanceof fs)return hQ(t._def.innerType);else return[]};class h0 extends hb{_parse(t){let{ctx:r}=this._processInputParams(t);if(r.parsedType!==hn.object)return hd(r,{code:hs.invalid_type,expected:hn.object,received:r.parsedType}),hm;let a=this.discriminator,i=r.data[a],n=this.optionsMap.get(i);return n?r.common.async?n._parseAsync({data:r.data,path:r.path,parent:r}):n._parseSync({data:r.data,path:r.path,parent:r}):(hd(r,{code:hs.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[a]}),hm)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,r,a){let i=new Map;for(let a of r){let r=hQ(a.shape[t]);if(!r.length)throw Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(let n of r){if(i.has(n))throw Error(`Discriminator property ${String(t)} has duplicate value ${String(n)}`);i.set(n,a)}}return new h0({typeName:Z.ZodDiscriminatedUnion,discriminator:t,options:r,optionsMap:i,...h_(a)})}}class h1 extends hb{_parse(t){let{status:r,ctx:a}=this._processInputParams(t),i=(t,i)=>{if("aborted"===t.status||"aborted"===i.status)return hm;let n=function t(r,a){let i=ho(r),n=ho(a);if(r===a)return{valid:!0,data:r};if(i===hn.object&&n===hn.object){let i=M.objectKeys(a),n=M.objectKeys(r).filter(t=>-1!==i.indexOf(t)),o={...r,...a};for(let i of(Object.prototype.hasOwnProperty.call(o,"__proto__")&&delete o.__proto__,n)){if("__proto__"===i)continue;let n=t(r[i],a[i]);if(!n.valid)return{valid:!1};o[i]=n.data}return{valid:!0,data:o}}if(i===hn.array&&n===hn.array){if(r.length!==a.length)return{valid:!1};let i=[];for(let n=0;n<r.length;n++){let o=t(r[n],a[n]);if(!o.valid)return{valid:!1};i.push(o.data)}return{valid:!0,data:i}}if(i===hn.date&&n===hn.date&&+r==+a)return{valid:!0,data:r};return{valid:!1}}(t.value,i.value);return n.valid?(("dirty"===t.status||"dirty"===i.status)&&r.dirty(),{status:r.value,value:n.data}):(hd(a,{code:hs.invalid_intersection_types}),hm)};return a.common.async?Promise.all([this._def.left._parseAsync({data:a.data,path:a.path,parent:a}),this._def.right._parseAsync({data:a.data,path:a.path,parent:a})]).then(([t,r])=>i(t,r)):i(this._def.left._parseSync({data:a.data,path:a.path,parent:a}),this._def.right._parseSync({data:a.data,path:a.path,parent:a}))}}h1.create=(t,r,a)=>new h1({left:t,right:r,typeName:Z.ZodIntersection,...h_(a)});class h2 extends hb{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==hn.array)return hd(a,{code:hs.invalid_type,expected:hn.array,received:a.parsedType}),hm;if(a.data.length<this._def.items.length)return hd(a,{code:hs.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),hm;!this._def.rest&&a.data.length>this._def.items.length&&(hd(a,{code:hs.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),r.dirty());let i=[...a.data].map((t,r)=>{let i=this._def.items[r]||this._def.rest;return i?i._parse(new hg(a,t,a.path,r)):null}).filter(t=>!!t);return a.common.async?Promise.all(i).then(t=>hp.mergeArray(r,t)):hp.mergeArray(r,i)}get items(){return this._def.items}rest(t){return new h2({...this._def,rest:t})}}h2.create=(t,r)=>{if(!Array.isArray(t))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new h2({items:t,typeName:Z.ZodTuple,rest:null,...h_(r)})};class h9 extends hb{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==hn.object)return hd(a,{code:hs.invalid_type,expected:hn.object,received:a.parsedType}),hm;let i=[],n=this._def.keyType,o=this._def.valueType;for(let t in a.data)i.push({key:n._parse(new hg(a,t,a.path,t)),value:o._parse(new hg(a,a.data[t],a.path,t)),alwaysSet:t in a.data});return a.common.async?hp.mergeObjectAsync(r,i):hp.mergeObjectSync(r,i)}get element(){return this._def.valueType}static create(t,r,a){return new h9(r instanceof hb?{keyType:t,valueType:r,typeName:Z.ZodRecord,...h_(a)}:{keyType:hz.create(),valueType:t,typeName:Z.ZodRecord,...h_(r)})}}class h4 extends hb{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==hn.map)return hd(a,{code:hs.invalid_type,expected:hn.map,received:a.parsedType}),hm;let i=this._def.keyType,n=this._def.valueType,o=[...a.data.entries()].map(([t,r],o)=>({key:i._parse(new hg(a,t,a.path,[o,"key"])),value:n._parse(new hg(a,r,a.path,[o,"value"]))}));if(a.common.async){let t=new Map;return Promise.resolve().then(async()=>{for(let a of o){let i=await a.key,n=await a.value;if("aborted"===i.status||"aborted"===n.status)return hm;("dirty"===i.status||"dirty"===n.status)&&r.dirty(),t.set(i.value,n.value)}return{status:r.value,value:t}})}{let t=new Map;for(let a of o){let i=a.key,n=a.value;if("aborted"===i.status||"aborted"===n.status)return hm;("dirty"===i.status||"dirty"===n.status)&&r.dirty(),t.set(i.value,n.value)}return{status:r.value,value:t}}}}h4.create=(t,r,a)=>new h4({valueType:r,keyType:t,typeName:Z.ZodMap,...h_(a)});class h3 extends hb{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==hn.set)return hd(a,{code:hs.invalid_type,expected:hn.set,received:a.parsedType}),hm;let i=this._def;null!==i.minSize&&a.data.size<i.minSize.value&&(hd(a,{code:hs.too_small,minimum:i.minSize.value,type:"set",inclusive:!0,exact:!1,message:i.minSize.message}),r.dirty()),null!==i.maxSize&&a.data.size>i.maxSize.value&&(hd(a,{code:hs.too_big,maximum:i.maxSize.value,type:"set",inclusive:!0,exact:!1,message:i.maxSize.message}),r.dirty());let n=this._def.valueType;function o(t){let a=new Set;for(let i of t){if("aborted"===i.status)return hm;"dirty"===i.status&&r.dirty(),a.add(i.value)}return{status:r.value,value:a}}let s=[...a.data.values()].map((t,r)=>n._parse(new hg(a,t,a.path,r)));return a.common.async?Promise.all(s).then(t=>o(t)):o(s)}min(t,r){return new h3({...this._def,minSize:{value:t,message:L.toString(r)}})}max(t,r){return new h3({...this._def,maxSize:{value:t,message:L.toString(r)}})}size(t,r){return this.min(t,r).max(t,r)}nonempty(t){return this.min(1,t)}}h3.create=(t,r)=>new h3({valueType:t,minSize:null,maxSize:null,typeName:Z.ZodSet,...h_(r)});class h6 extends hb{constructor(){super(...arguments),this.validate=this.implement}_parse(t){let{ctx:r}=this._processInputParams(t);if(r.parsedType!==hn.function)return hd(r,{code:hs.invalid_type,expected:hn.function,received:r.parsedType}),hm;function a(t,a){return hu({data:t,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,hc,hc].filter(t=>!!t),issueData:{code:hs.invalid_arguments,argumentsError:a}})}function i(t,a){return hu({data:t,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,hc,hc].filter(t=>!!t),issueData:{code:hs.invalid_return_type,returnTypeError:a}})}let n={errorMap:r.common.contextualErrorMap},o=r.data;if(this._def.returns instanceof fr){let t=this;return hf(async function(...r){let s=new hl([]),l=await t._def.args.parseAsync(r,n).catch(t=>{throw s.addIssue(a(r,t)),s}),c=await Reflect.apply(o,this,l);return await t._def.returns._def.type.parseAsync(c,n).catch(t=>{throw s.addIssue(i(c,t)),s})})}{let t=this;return hf(function(...r){let s=t._def.args.safeParse(r,n);if(!s.success)throw new hl([a(r,s.error)]);let l=Reflect.apply(o,this,s.data),c=t._def.returns.safeParse(l,n);if(!c.success)throw new hl([i(l,c.error)]);return c.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new h6({...this._def,args:h2.create(t).rest(hB.create())})}returns(t){return new h6({...this._def,returns:t})}implement(t){return this.parse(t)}strictImplement(t){return this.parse(t)}static create(t,r,a){return new h6({args:t||h2.create([]).rest(hB.create()),returns:r||hB.create(),typeName:Z.ZodFunction,...h_(a)})}}class h5 extends hb{get schema(){return this._def.getter()}_parse(t){let{ctx:r}=this._processInputParams(t);return this._def.getter()._parse({data:r.data,path:r.path,parent:r})}}h5.create=(t,r)=>new h5({getter:t,typeName:Z.ZodLazy,...h_(r)});class h8 extends hb{_parse(t){if(t.data!==this._def.value){let r=this._getOrReturnCtx(t);return hd(r,{received:r.data,code:hs.invalid_literal,expected:this._def.value}),hm}return{status:"valid",value:t.data}}get value(){return this._def.value}}function h7(t,r){return new fe({values:t,typeName:Z.ZodEnum,...h_(r)})}h8.create=(t,r)=>new h8({value:t,typeName:Z.ZodLiteral,...h_(r)});class fe extends hb{_parse(t){if("string"!=typeof t.data){let r=this._getOrReturnCtx(t),a=this._def.values;return hd(r,{expected:M.joinValues(a),received:r.parsedType,code:hs.invalid_type}),hm}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(t.data)){let r=this._getOrReturnCtx(t),a=this._def.values;return hd(r,{received:r.data,code:hs.invalid_enum_value,options:a}),hm}return hf(t.data)}get options(){return this._def.values}get enum(){let t={};for(let r of this._def.values)t[r]=r;return t}get Values(){let t={};for(let r of this._def.values)t[r]=r;return t}get Enum(){let t={};for(let r of this._def.values)t[r]=r;return t}extract(t,r=this._def){return fe.create(t,{...this._def,...r})}exclude(t,r=this._def){return fe.create(this.options.filter(r=>!t.includes(r)),{...this._def,...r})}}fe.create=h7;class ft extends hb{_parse(t){let r=M.getValidEnumValues(this._def.values),a=this._getOrReturnCtx(t);if(a.parsedType!==hn.string&&a.parsedType!==hn.number){let t=M.objectValues(r);return hd(a,{expected:M.joinValues(t),received:a.parsedType,code:hs.invalid_type}),hm}if(this._cache||(this._cache=new Set(M.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){let t=M.objectValues(r);return hd(a,{received:a.data,code:hs.invalid_enum_value,options:t}),hm}return hf(t.data)}get enum(){return this._def.values}}ft.create=(t,r)=>new ft({values:t,typeName:Z.ZodNativeEnum,...h_(r)});class fr extends hb{unwrap(){return this._def.type}_parse(t){let{ctx:r}=this._processInputParams(t);return r.parsedType!==hn.promise&&!1===r.common.async?(hd(r,{code:hs.invalid_type,expected:hn.promise,received:r.parsedType}),hm):hf((r.parsedType===hn.promise?r.data:Promise.resolve(r.data)).then(t=>this._def.type.parseAsync(t,{path:r.path,errorMap:r.common.contextualErrorMap})))}}fr.create=(t,r)=>new fr({type:t,typeName:Z.ZodPromise,...h_(r)});class fa extends hb{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===Z.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){let{status:r,ctx:a}=this._processInputParams(t),i=this._def.effect||null,n={addIssue:t=>{hd(a,t),t.fatal?r.abort():r.dirty()},get path(){return a.path}};if(n.addIssue=n.addIssue.bind(n),"preprocess"===i.type){let t=i.transform(a.data,n);if(a.common.async)return Promise.resolve(t).then(async t=>{if("aborted"===r.value)return hm;let i=await this._def.schema._parseAsync({data:t,path:a.path,parent:a});return"aborted"===i.status?hm:"dirty"===i.status||"dirty"===r.value?hh(i.value):i});{if("aborted"===r.value)return hm;let i=this._def.schema._parseSync({data:t,path:a.path,parent:a});return"aborted"===i.status?hm:"dirty"===i.status||"dirty"===r.value?hh(i.value):i}}if("refinement"===i.type){let t=t=>{let r=i.refinement(t,n);if(a.common.async)return Promise.resolve(r);if(r instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return t};if(!1!==a.common.async)return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then(a=>"aborted"===a.status?hm:("dirty"===a.status&&r.dirty(),t(a.value).then(()=>({status:r.value,value:a.value}))));{let i=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});return"aborted"===i.status?hm:("dirty"===i.status&&r.dirty(),t(i.value),{status:r.value,value:i.value})}}if("transform"===i.type)if(!1!==a.common.async)return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then(t=>"valid"!==t.status?hm:Promise.resolve(i.transform(t.value,n)).then(t=>({status:r.value,value:t})));else{let t=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});if("valid"!==t.status)return hm;let o=i.transform(t.value,n);if(o instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:o}}M.assertNever(i)}}fa.create=(t,r,a)=>new fa({schema:t,typeName:Z.ZodEffects,effect:r,...h_(a)}),fa.createWithPreprocess=(t,r,a)=>new fa({schema:r,effect:{type:"preprocess",transform:t},typeName:Z.ZodEffects,...h_(a)});class fi extends hb{_parse(t){return this._getType(t)===hn.undefined?hf(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}fi.create=(t,r)=>new fi({innerType:t,typeName:Z.ZodOptional,...h_(r)});class fn extends hb{_parse(t){return this._getType(t)===hn.null?hf(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}fn.create=(t,r)=>new fn({innerType:t,typeName:Z.ZodNullable,...h_(r)});class fo extends hb{_parse(t){let{ctx:r}=this._processInputParams(t),a=r.data;return r.parsedType===hn.undefined&&(a=this._def.defaultValue()),this._def.innerType._parse({data:a,path:r.path,parent:r})}removeDefault(){return this._def.innerType}}fo.create=(t,r)=>new fo({innerType:t,typeName:Z.ZodDefault,defaultValue:"function"==typeof r.default?r.default:()=>r.default,...h_(r)});class fs extends hb{_parse(t){let{ctx:r}=this._processInputParams(t),a={...r,common:{...r.common,issues:[]}},i=this._def.innerType._parse({data:a.data,path:a.path,parent:{...a}});return hy(i)?i.then(t=>({status:"valid",value:"valid"===t.status?t.value:this._def.catchValue({get error(){return new hl(a.common.issues)},input:a.data})})):{status:"valid",value:"valid"===i.status?i.value:this._def.catchValue({get error(){return new hl(a.common.issues)},input:a.data})}}removeCatch(){return this._def.innerType}}fs.create=(t,r)=>new fs({innerType:t,typeName:Z.ZodCatch,catchValue:"function"==typeof r.catch?r.catch:()=>r.catch,...h_(r)});class fl extends hb{_parse(t){if(this._getType(t)!==hn.nan){let r=this._getOrReturnCtx(t);return hd(r,{code:hs.invalid_type,expected:hn.nan,received:r.parsedType}),hm}return{status:"valid",value:t.data}}}fl.create=t=>new fl({typeName:Z.ZodNaN,...h_(t)}),Symbol("zod_brand");class fc extends hb{_parse(t){let{ctx:r}=this._processInputParams(t),a=r.data;return this._def.type._parse({data:a,path:r.path,parent:r})}unwrap(){return this._def.type}}class fu extends hb{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.common.async)return(async()=>{let t=await this._def.in._parseAsync({data:a.data,path:a.path,parent:a});return"aborted"===t.status?hm:"dirty"===t.status?(r.dirty(),hh(t.value)):this._def.out._parseAsync({data:t.value,path:a.path,parent:a})})();{let t=this._def.in._parseSync({data:a.data,path:a.path,parent:a});return"aborted"===t.status?hm:"dirty"===t.status?(r.dirty(),{status:"dirty",value:t.value}):this._def.out._parseSync({data:t.value,path:a.path,parent:a})}}static create(t,r){return new fu({in:t,out:r,typeName:Z.ZodPipeline})}}class fd extends hb{_parse(t){let r=this._def.innerType._parse(t),a=t=>("valid"===t.status&&(t.value=Object.freeze(t.value)),t);return hy(r)?r.then(t=>a(t)):a(r)}unwrap(){return this._def.innerType}}fd.create=(t,r)=>new fd({innerType:t,typeName:Z.ZodReadonly,...h_(r)}),hY.lazycreate,(O=Z||(Z={})).ZodString="ZodString",O.ZodNumber="ZodNumber",O.ZodNaN="ZodNaN",O.ZodBigInt="ZodBigInt",O.ZodBoolean="ZodBoolean",O.ZodDate="ZodDate",O.ZodSymbol="ZodSymbol",O.ZodUndefined="ZodUndefined",O.ZodNull="ZodNull",O.ZodAny="ZodAny",O.ZodUnknown="ZodUnknown",O.ZodNever="ZodNever",O.ZodVoid="ZodVoid",O.ZodArray="ZodArray",O.ZodObject="ZodObject",O.ZodUnion="ZodUnion",O.ZodDiscriminatedUnion="ZodDiscriminatedUnion",O.ZodIntersection="ZodIntersection",O.ZodTuple="ZodTuple",O.ZodRecord="ZodRecord",O.ZodMap="ZodMap",O.ZodSet="ZodSet",O.ZodFunction="ZodFunction",O.ZodLazy="ZodLazy",O.ZodLiteral="ZodLiteral",O.ZodEnum="ZodEnum",O.ZodEffects="ZodEffects",O.ZodNativeEnum="ZodNativeEnum",O.ZodOptional="ZodOptional",O.ZodNullable="ZodNullable",O.ZodDefault="ZodDefault",O.ZodCatch="ZodCatch",O.ZodPromise="ZodPromise",O.ZodBranded="ZodBranded",O.ZodPipeline="ZodPipeline",O.ZodReadonly="ZodReadonly";let fp=hz.create;hL.create,fl.create,hZ.create,hD.create,hU.create,hV.create,hF.create,hH.create,hJ.create,hB.create,hK.create,hG.create,hW.create;let fm=hY.create;hY.strictCreate,hX.create,h0.create,h1.create,h2.create,h9.create,h4.create,h3.create,h6.create,h5.create,h8.create,fe.create,ft.create,fr.create,fa.create,fi.create,fn.create,fa.createWithPreprocess,fu.create;let fh=(t,r)=>{let a=0;for(;a<t.length&&a<r.length&&t[a]===r[a];a++);return[(t.length-a).toString(),...r.slice(a)].join("/")};function ff(t){if("openAi"!==t.target)return{};let r=[...t.basePath,t.definitionPath,t.openAiAnyTypeName];return t.flags.hasReferencedOpenAiAnyType=!0,{$ref:"relative"===t.$refStrategy?fh(r,t.currentPath):r.join("/")}}function fy(t,r,a,i){i?.errorMessages&&a&&(t.errorMessage={...t.errorMessage,[r]:a})}function fg(t,r,a,i,n){t[r]=a,fy(t,r,i,n)}function fv(t,r){return fL(t.type._def,r)}let f_=/^[cC][^\s-]{8,}$/,fb=/^[0-9a-z]+$/,fS=/^[0-9A-HJKMNP-TV-Z]{26}$/,f$=/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,fw=()=>(void 0===w&&(w=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),w),fR=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,fk=/^(([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])$/,fx=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,fP=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,fE=/^[a-zA-Z0-9_-]{21}$/,fT=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;function fj(t,r){let a={type:"string"};if(t.checks)for(let i of t.checks)switch(i.kind){case"min":fg(a,"minLength","number"==typeof a.minLength?Math.max(a.minLength,i.value):i.value,i.message,r);break;case"max":fg(a,"maxLength","number"==typeof a.maxLength?Math.min(a.maxLength,i.value):i.value,i.message,r);break;case"email":switch(r.emailStrategy){case"format:email":fI(a,"email",i.message,r);break;case"format:idn-email":fI(a,"idn-email",i.message,r);break;case"pattern:zod":fN(a,f$,i.message,r)}break;case"url":fI(a,"uri",i.message,r);break;case"uuid":fI(a,"uuid",i.message,r);break;case"regex":fN(a,i.regex,i.message,r);break;case"cuid":fN(a,f_,i.message,r);break;case"cuid2":fN(a,fb,i.message,r);break;case"startsWith":fN(a,RegExp(`^${fO(i.value,r)}`),i.message,r);break;case"endsWith":fN(a,RegExp(`${fO(i.value,r)}$`),i.message,r);break;case"datetime":fI(a,"date-time",i.message,r);break;case"date":fI(a,"date",i.message,r);break;case"time":fI(a,"time",i.message,r);break;case"duration":fI(a,"duration",i.message,r);break;case"length":fg(a,"minLength","number"==typeof a.minLength?Math.max(a.minLength,i.value):i.value,i.message,r),fg(a,"maxLength","number"==typeof a.maxLength?Math.min(a.maxLength,i.value):i.value,i.message,r);break;case"includes":fN(a,RegExp(fO(i.value,r)),i.message,r);break;case"ip":"v6"!==i.version&&fI(a,"ipv4",i.message,r),"v4"!==i.version&&fI(a,"ipv6",i.message,r);break;case"base64url":fN(a,fP,i.message,r);break;case"jwt":fN(a,fT,i.message,r);break;case"cidr":"v6"!==i.version&&fN(a,fR,i.message,r),"v4"!==i.version&&fN(a,fk,i.message,r);break;case"emoji":fN(a,fw(),i.message,r);break;case"ulid":fN(a,fS,i.message,r);break;case"base64":switch(r.base64Strategy){case"format:binary":fI(a,"binary",i.message,r);break;case"contentEncoding:base64":fg(a,"contentEncoding","base64",i.message,r);break;case"pattern:zod":fN(a,fx,i.message,r)}break;case"nanoid":fN(a,fE,i.message,r)}return a}function fO(t,r){return"escape"===r.patternStrategy?function(t){let r="";for(let a=0;a<t.length;a++)fC.has(t[a])||(r+="\\"),r+=t[a];return r}(t):t}let fC=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function fI(t,r,a,i){t.format||t.anyOf?.some(t=>t.format)?(t.anyOf||(t.anyOf=[]),t.format&&(t.anyOf.push({format:t.format,...t.errorMessage&&i.errorMessages&&{errorMessage:{format:t.errorMessage.format}}}),delete t.format,t.errorMessage&&(delete t.errorMessage.format,0===Object.keys(t.errorMessage).length&&delete t.errorMessage)),t.anyOf.push({format:r,...a&&i.errorMessages&&{errorMessage:{format:a}}})):fg(t,"format",r,a,i)}function fN(t,r,a,i){t.pattern||t.allOf?.some(t=>t.pattern)?(t.allOf||(t.allOf=[]),t.pattern&&(t.allOf.push({pattern:t.pattern,...t.errorMessage&&i.errorMessages&&{errorMessage:{pattern:t.errorMessage.pattern}}}),delete t.pattern,t.errorMessage&&(delete t.errorMessage.pattern,0===Object.keys(t.errorMessage).length&&delete t.errorMessage)),t.allOf.push({pattern:fq(r,i),...a&&i.errorMessages&&{errorMessage:{pattern:a}}})):fg(t,"pattern",fq(r,i),a,i)}function fq(t,r){if(!r.applyRegexFlags||!t.flags)return t.source;let a={i:t.flags.includes("i"),m:t.flags.includes("m"),s:t.flags.includes("s")},i=a.i?t.source.toLowerCase():t.source,n="",o=!1,s=!1,l=!1;for(let t=0;t<i.length;t++){if(o){n+=i[t],o=!1;continue}if(a.i){if(s){if(i[t].match(/[a-z]/)){l?(n+=i[t],n+=`${i[t-2]}-${i[t]}`.toUpperCase(),l=!1):"-"===i[t+1]&&i[t+2]?.match(/[a-z]/)?(n+=i[t],l=!0):n+=`${i[t]}${i[t].toUpperCase()}`;continue}}else if(i[t].match(/[a-z]/)){n+=`[${i[t]}${i[t].toUpperCase()}]`;continue}}if(a.m){if("^"===i[t]){n+=`(^|(?<=[\r
78
78
  ]))`;continue}else if("$"===i[t]){n+=`($|(?=[\r
79
79
  ]))`;continue}}if(a.s&&"."===i[t]){n+=s?`${i[t]}\r
80
80
  `:`[${i[t]}\r
81
- ]`;continue}n+=i[t],"\\"===i[t]?o=!0:s&&"]"===i[t]?s=!1:s||"["!==i[t]||(s=!0)}try{new RegExp(n)}catch{return console.warn(`Could not convert regex pattern at ${r.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),t.source}return n}function fN(t,r){if("openAi"===r.target&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),"openApi3"===r.target&&t.keyType?._def.typeName===Z.ZodEnum)return{type:"object",required:t.keyType._def.values,properties:t.keyType._def.values.reduce((a,i)=>({...a,[i]:fM(t.valueType._def,{...r,currentPath:[...r.currentPath,"properties",i]})??fm(r)}),{}),additionalProperties:r.rejectedAdditionalProperties};let a={type:"object",additionalProperties:fM(t.valueType._def,{...r,currentPath:[...r.currentPath,"additionalProperties"]})??r.allowedAdditionalProperties};if("openApi3"===r.target)return a;if(t.keyType?._def.typeName===Z.ZodString&&t.keyType._def.checks?.length){let{type:i,...n}=fE(t.keyType._def,r);return{...a,propertyNames:n}}if(t.keyType?._def.typeName===Z.ZodEnum)return{...a,propertyNames:{enum:t.keyType._def.values}};if(t.keyType?._def.typeName===Z.ZodBranded&&t.keyType._def.type._def.typeName===Z.ZodString&&t.keyType._def.type._def.checks?.length){let{type:i,...n}=fy(t.keyType._def,r);return{...a,propertyNames:n}}return a}let fq={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"},fA=(t,r)=>{let a=(t.options instanceof Map?Array.from(t.options.values()):t.options).map((t,a)=>fM(t._def,{...r,currentPath:[...r.currentPath,"anyOf",`${a}`]})).filter(t=>!!t&&(!r.strictUnions||"object"==typeof t&&Object.keys(t).length>0));return a.length?{anyOf:a}:void 0};function fM(t,r,a=!1){let i=r.seen.get(t);if(r.override){let n=r.override?.(t,r,i,a);if(n!==ha)return n}if(i&&!a){let t=fz(i,r);if(void 0!==t)return t}let n={def:t,path:r.currentPath,jsonSchema:void 0};r.seen.set(t,n);let o=((t,r,a)=>{switch(r){case Z.ZodString:return fE(t,a);case Z.ZodNumber:let i={type:"number"};if(!t.checks)return i;for(let r of t.checks)switch(r.kind){case"int":i.type="integer",fh(i,"type",r.message,a);break;case"min":"jsonSchema7"===a.target?r.inclusive?ff(i,"minimum",r.value,r.message,a):ff(i,"exclusiveMinimum",r.value,r.message,a):(r.inclusive||(i.exclusiveMinimum=!0),ff(i,"minimum",r.value,r.message,a));break;case"max":"jsonSchema7"===a.target?r.inclusive?ff(i,"maximum",r.value,r.message,a):ff(i,"exclusiveMaximum",r.value,r.message,a):(r.inclusive||(i.exclusiveMaximum=!0),ff(i,"maximum",r.value,r.message,a));break;case"multipleOf":ff(i,"multipleOf",r.value,r.message,a)}return i;case Z.ZodObject:return function(t,r){let a="openAi"===r.target,i={type:"object",properties:{}},n=[],o=t.shape();for(let t in o){let s=o[t];if(void 0===s||void 0===s._def)continue;let l=function(t){try{return t.isOptional()}catch{return!0}}(s);l&&a&&("ZodOptional"===s._def.typeName&&(s=s._def.innerType),s.isNullable()||(s=s.nullable()),l=!1);let c=fM(s._def,{...r,currentPath:[...r.currentPath,"properties",t],propertyPath:[...r.currentPath,"properties",t]});void 0!==c&&(i.properties[t]=c,l||n.push(t))}n.length&&(i.required=n);let s=function(t,r){if("ZodNever"!==t.catchall._def.typeName)return fM(t.catchall._def,{...r,currentPath:[...r.currentPath,"additionalProperties"]});switch(t.unknownKeys){case"passthrough":return r.allowedAdditionalProperties;case"strict":return r.rejectedAdditionalProperties;case"strip":return"strict"===r.removeAdditionalStrategy?r.allowedAdditionalProperties:r.rejectedAdditionalProperties}}(t,r);return void 0!==s&&(i.additionalProperties=s),i}(t,a);case Z.ZodBigInt:let n={type:"integer",format:"int64"};if(!t.checks)return n;for(let r of t.checks)switch(r.kind){case"min":"jsonSchema7"===a.target?r.inclusive?ff(n,"minimum",r.value,r.message,a):ff(n,"exclusiveMinimum",r.value,r.message,a):(r.inclusive||(n.exclusiveMinimum=!0),ff(n,"minimum",r.value,r.message,a));break;case"max":"jsonSchema7"===a.target?r.inclusive?ff(n,"maximum",r.value,r.message,a):ff(n,"exclusiveMaximum",r.value,r.message,a):(r.inclusive||(n.exclusiveMaximum=!0),ff(n,"maximum",r.value,r.message,a));break;case"multipleOf":ff(n,"multipleOf",r.value,r.message,a)}return n;case Z.ZodBoolean:return{type:"boolean"};case Z.ZodDate:return function t(r,a,i){let n=i??a.dateStrategy;if(Array.isArray(n))return{anyOf:n.map((i,n)=>t(r,a,i))};switch(n){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":var o=r,s=a;let l={type:"integer",format:"unix-time"};if("openApi3"===s.target)return l;for(let t of o.checks)switch(t.kind){case"min":ff(l,"minimum",t.value,t.message,s);break;case"max":ff(l,"maximum",t.value,t.message,s)}return l}}(t,a);case Z.ZodUndefined:return{not:fm(a)};case Z.ZodNull:return"openApi3"===a.target?{enum:["null"],nullable:!0}:{type:"null"};case Z.ZodArray:let o;return o={type:"array"},t.type?._def&&t.type?._def?.typeName!==Z.ZodAny&&(o.items=fM(t.type._def,{...a,currentPath:[...a.currentPath,"items"]})),t.minLength&&ff(o,"minItems",t.minLength.value,t.minLength.message,a),t.maxLength&&ff(o,"maxItems",t.maxLength.value,t.maxLength.message,a),t.exactLength&&(ff(o,"minItems",t.exactLength.value,t.exactLength.message,a),ff(o,"maxItems",t.exactLength.value,t.exactLength.message,a)),o;case Z.ZodUnion:case Z.ZodDiscriminatedUnion:if("openApi3"===a.target)return fA(t,a);let s=t.options instanceof Map?Array.from(t.options.values()):t.options;if(s.every(t=>t._def.typeName in fq&&(!t._def.checks||!t._def.checks.length))){let t=s.reduce((t,r)=>{let a=fq[r._def.typeName];return a&&!t.includes(a)?[...t,a]:t},[]);return{type:t.length>1?t:t[0]}}if(s.every(t=>"ZodLiteral"===t._def.typeName&&!t.description)){let t=s.reduce((t,r)=>{let a=typeof r._def.value;switch(a){case"string":case"number":case"boolean":return[...t,a];case"bigint":return[...t,"integer"];case"object":if(null===r._def.value)return[...t,"null"];default:return t}},[]);if(t.length===s.length){let r=t.filter((t,r,a)=>a.indexOf(t)===r);return{type:r.length>1?r:r[0],enum:s.reduce((t,r)=>t.includes(r._def.value)?t:[...t,r._def.value],[])}}}else if(s.every(t=>"ZodEnum"===t._def.typeName))return{type:"string",enum:s.reduce((t,r)=>[...t,...r._def.values.filter(r=>!t.includes(r))],[])};return fA(t,a);case Z.ZodIntersection:let l,c,u;return l=[fM(t.left._def,{...a,currentPath:[...a.currentPath,"allOf","0"]}),fM(t.right._def,{...a,currentPath:[...a.currentPath,"allOf","1"]})].filter(t=>!!t),c="jsonSchema2019-09"===a.target?{unevaluatedProperties:!1}:void 0,u=[],l.forEach(t=>{if((!("type"in t)||"string"!==t.type)&&"allOf"in t)u.push(...t.allOf),void 0===t.unevaluatedProperties&&(c=void 0);else{let r=t;if("additionalProperties"in t&&!1===t.additionalProperties){let{additionalProperties:a,...i}=t;r=i}else c=void 0;u.push(r)}}),u.length?{allOf:u,...c}:void 0;case Z.ZodTuple:return t.rest?{type:"array",minItems:t.items.length,items:t.items.map((t,r)=>fM(t._def,{...a,currentPath:[...a.currentPath,"items",`${r}`]})).reduce((t,r)=>void 0===r?t:[...t,r],[]),additionalItems:fM(t.rest._def,{...a,currentPath:[...a.currentPath,"additionalItems"]})}:{type:"array",minItems:t.items.length,maxItems:t.items.length,items:t.items.map((t,r)=>fM(t._def,{...a,currentPath:[...a.currentPath,"items",`${r}`]})).reduce((t,r)=>void 0===r?t:[...t,r],[])};case Z.ZodRecord:return fN(t,a);case Z.ZodLiteral:let d;return"bigint"!=(d=typeof t.value)&&"number"!==d&&"boolean"!==d&&"string"!==d?{type:Array.isArray(t.value)?"array":"object"}:"openApi3"===a.target?{type:"bigint"===d?"integer":d,enum:[t.value]}:{type:"bigint"===d?"integer":d,const:t.value};case Z.ZodEnum:return{type:"string",enum:Array.from(t.values)};case Z.ZodNativeEnum:let p,m,h;return p=t.values,{type:1===(h=Array.from(new Set((m=Object.keys(t.values).filter(t=>"number"!=typeof p[p[t]]).map(t=>p[t])).map(t=>typeof t)))).length?"string"===h[0]?"string":"number":["string","number"],enum:m};case Z.ZodNullable:if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(t.innerType._def.typeName)&&(!t.innerType._def.checks||!t.innerType._def.checks.length))return"openApi3"===a.target?{type:fq[t.innerType._def.typeName],nullable:!0}:{type:[fq[t.innerType._def.typeName],"null"]};if("openApi3"===a.target){let r=fM(t.innerType._def,{...a,currentPath:[...a.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}let f=fM(t.innerType._def,{...a,currentPath:[...a.currentPath,"anyOf","0"]});return f&&{anyOf:[f,{type:"null"}]};case Z.ZodOptional:if(a.currentPath.toString()===a.propertyPath?.toString())return fM(t.innerType._def,a);let y=fM(t.innerType._def,{...a,currentPath:[...a.currentPath,"anyOf","1"]});return y?{anyOf:[{not:fm(a)},y]}:fm(a);case Z.ZodMap:if("record"===a.mapStrategy)return fN(t,a);return{type:"array",maxItems:125,items:{type:"array",items:[fM(t.keyType._def,{...a,currentPath:[...a.currentPath,"items","items","0"]})||fm(a),fM(t.valueType._def,{...a,currentPath:[...a.currentPath,"items","items","1"]})||fm(a)],minItems:2,maxItems:2}};case Z.ZodSet:let g;return g={type:"array",uniqueItems:!0,items:fM(t.valueType._def,{...a,currentPath:[...a.currentPath,"items"]})},t.minSize&&ff(g,"minItems",t.minSize.value,t.minSize.message,a),t.maxSize&&ff(g,"maxItems",t.maxSize.value,t.maxSize.message,a),g;case Z.ZodLazy:return()=>t.getter()._def;case Z.ZodPromise:return fM(t.type._def,a);case Z.ZodNaN:case Z.ZodNever:return"openAi"===a.target?void 0:{not:fm({...a,currentPath:[...a.currentPath,"not"]})};case Z.ZodEffects:return"input"===a.effectStrategy?fM(t.schema._def,a):fm(a);case Z.ZodAny:case Z.ZodUnknown:return fm(a);case Z.ZodDefault:return{...fM(t.innerType._def,a),default:t.defaultValue()};case Z.ZodBranded:return fy(t,a);case Z.ZodReadonly:case Z.ZodCatch:return fM(t.innerType._def,a);case Z.ZodPipeline:if("input"===a.pipeStrategy)return fM(t.in._def,a);if("output"===a.pipeStrategy)return fM(t.out._def,a);let v=fM(t.in._def,{...a,currentPath:[...a.currentPath,"allOf","0"]}),_=fM(t.out._def,{...a,currentPath:[...a.currentPath,"allOf",v?"1":"0"]});return{allOf:[v,_].filter(t=>void 0!==t)};case Z.ZodFunction:case Z.ZodVoid:case Z.ZodSymbol:default:return}})(t,t.typeName,r),s="function"==typeof o?fM(o(),r):o;if(s&&fL(t,r,s),r.postProcess){let a=r.postProcess(s,t,r);return n.jsonSchema=s,a}return n.jsonSchema=s,s}let fz=(t,r)=>{switch(r.$refStrategy){case"root":return{$ref:t.path.join("/")};case"relative":return{$ref:fp(r.currentPath,t.path)};case"none":case"seen":if(t.path.length<r.currentPath.length&&t.path.every((t,a)=>r.currentPath[a]===t))return console.warn(`Recursive reference detected at ${r.currentPath.join("/")}! Defaulting to any`),fm(r);return"seen"===r.$refStrategy?fm(r):void 0}},fL=(t,r,a)=>(t.description&&(a.description=t.description,r.markdownDescription&&(a.markdownDescription=t.description)),a);function fZ(t,r={}){let{strict:a=!1}=r,i=Object.entries(t),n=t=>({target:r})=>{let n={},o=[];for(let[a,s]of i)n[a]=function(t,r,a){let i=t["~standard"];if(i.jsonSchema)return i.jsonSchema[a]({target:r});if("zod"===t["~standard"].vendor&&!("_zod"in t)&&"_def"in t){let a=((t,r)=>{let a,i,n=(i=void 0!==(a="string"==typeof r?{...hi,name:r}:{...hi,...r}).name?[...a.basePath,a.definitionPath,a.name]:a.basePath,{...a,flags:{hasReferencedOpenAiAnyType:!1},currentPath:i,propertyPath:void 0,seen:new Map(Object.entries(a.definitions).map(([t,r])=>[r._def,{def:r._def,path:[...a.basePath,a.definitionPath,t],jsonSchema:void 0}]))}),o="object"==typeof r&&r.definitions?Object.entries(r.definitions).reduce((t,[r,a])=>({...t,[r]:fM(a._def,{...n,currentPath:[...n.basePath,n.definitionPath,r]},!0)??fm(n)}),{}):void 0,s="string"==typeof r?r:r?.nameStrategy==="title"?void 0:r?.name,l=fM(t._def,void 0===s?n:{...n,currentPath:[...n.basePath,n.definitionPath,s]},!1)??fm(n),c="object"==typeof r&&void 0!==r.name&&"title"===r.nameStrategy?r.name:void 0;void 0!==c&&(l.title=c),n.flags.hasReferencedOpenAiAnyType&&(o||(o={}),o[n.openAiAnyTypeName]||(o[n.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:"relative"===n.$refStrategy?"1":[...n.basePath,n.definitionPath,n.openAiAnyTypeName].join("/")}}));let u=void 0===s?o?{...l,[n.definitionPath]:o}:l:{$ref:[..."relative"===n.$refStrategy?[]:n.basePath,n.definitionPath,s].join("/"),[n.definitionPath]:{...o,[s]:l}};return"jsonSchema7"===n.target?u.$schema="http://json-schema.org/draft-07/schema#":("jsonSchema2019-09"===n.target||"openAi"===n.target)&&(u.$schema="https://json-schema.org/draft/2019-09/schema#"),"openAi"===n.target&&("anyOf"in u||"oneOf"in u||"allOf"in u||"type"in u&&Array.isArray(u.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),u})(t,{$refStrategy:"none",target:"openapi-3.0"===r?"openApi3":"jsonSchema7"});return delete a.$schema,a}if("zod"===i.vendor&&"_zod"in t)try{let r=it(t);return delete r.$schema,r}catch(t){throw Error(`Failed to convert a zod schema to JSON Schema (zod v4 without "~standard.jsonSchema"). Upgrade to zod >= 4.2.0. Original error: ${t instanceof Error?t.message:String(t)}`)}throw Error(`Schema library "${i.vendor}" cannot be converted to JSON Schema. Use zod v3 (>= 3.25.76), zod >= 4.2.0, or a Standard Schema library implementing "~standard.jsonSchema".`)}(s,r,t),!function(t,r){if("function"!=typeof t.safeParse)return!1;try{let a=t.safeParse(void 0);return a.success&&("input"===r||void 0===a.data)}catch{return!1}}(s,t)&&o.push(a);let s={type:"object",properties:n};return o.length>0&&(s.required=o),a&&(s.additionalProperties=!1),s},o=async r=>{if("object"!=typeof r||null===r||Array.isArray(r))return{issues:[{message:"Expected an object."}]};let n={},o=[];for(let[t,a]of i){let i=await a["~standard"].validate(r[t]);if(i.issues)for(let r of i.issues)o.push({message:r.message,path:[t,...r.path??[]]});else(t in r||void 0!==i.value)&&(n[t]=i.value)}if(a)for(let a of Object.keys(r))a in t||o.push({message:`Unrecognized key: "${a}"`,path:[a]});return o.length>0?{issues:o}:{value:n}};return{shape:t,"~standard":{version:1,vendor:"xmcp",validate:o,jsonSchema:{input:n("input"),output:n("output")}}}}function fD(t){let r={};return!function t(a,i=""){if(a&&"object"==typeof a)for(let[n,o]of Object.entries(a)){let a=i?`${i}/${n}`:n;!o||"object"!=typeof o||Array.isArray(o)||o instanceof Date||o instanceof RegExp?r[a]=o:t(o,a)}}(t),r}let fU=["ui/resourceUri","resourceUri","visibility"],fV=["prefersBorder","domain","csp","permissions","connectDomains","resourceDomains","frameDomains","baseUriDomains"];function fF(t){return"object"==typeof t&&null!==t&&Object.entries(t).every(([t,r])=>"string"==typeof t&&"object"==typeof r&&null!==r&&"parse"in r&&"function"==typeof r.parse)}function fH(t){return(t.split("/").pop()||t).replace(/\.[^/.]+$/,"")}function fJ(t,r,a){return t.names?.includes(r)===!0||t.tags?.some(t=>a.includes(t))===!0}function fB(t,r){return r?new Map([...t].filter(([t,{metadata:a}])=>{if(a?.enabled===!1)return!1;let i=a?.name??fH(t),n=a?.tags??[];return(!r.include||fJ(r.include,i,n))&&(!r.exclude||!fJ(r.exclude,i,n))})):t}function fK(t){return Error(`[xmcp] Invalid prompt file: ${t}
82
- -> Default export must be a prompt handler function.`)}async function fG(t){let r=new Map,a=[];for(let i of(await Promise.all(Object.entries(t).map(async([t,r])=>{let a=await r(),i=function(t,r){if("object"!=typeof t||null===t)throw fK(r);let a=Object.keys(t),i=t.default,n=a.filter(t=>"__esModule"!==t);if(0===a.length||1===n.length&&"default"===n[0]&&"object"==typeof i&&null!==i&&0===Object.keys(i).length)return"empty";if(!("default"in t)||void 0===t.default)return"missing-default";if("function"!=typeof t.default)throw fK(r);return"valid"}(a,t);return"empty"===i?{skipped:!0,issue:{path:t,message:"File is empty."}}:"missing-default"===i?{skipped:!0,issue:{path:t,message:"File does not export a default prompt handler."}}:{skipped:!1,path:t,promptModule:a}})))){if(i.skipped){a.push(i.issue);continue}r.set(i.path,i.promptModule)}return{promptModules:r,skippedPrompts:a}}let fW=function(t=console){let r="";return a=>{let i=a.map(({path:t,message:r})=>`${t}:${r}`).sort().join("|");if(i===r||(r=i,0===a.length))return;a.forEach(({path:r,message:a})=>{t.warn(`[xmcp] Failed to load prompt file: ${r}
83
- -> ${a}`)});let n=a.length;t.warn(`[xmcp] ${n} prompt${1===n?"":"s"} skipped due to empty files or missing default exports`)}}();function fY(t){return Error(`[xmcp] Invalid resource file: ${t}
84
- -> Default export must be a resource handler function.`)}async function fX(t){let r=new Map,a=[];for(let i of(await Promise.all(Object.entries(t).map(async([t,r])=>{let a=await r(),i=function(t,r){if("object"!=typeof t||null===t)throw fY(r);let a=Object.keys(t),i=t.default,n=a.filter(t=>"__esModule"!==t);if(0===a.length||1===n.length&&"default"===n[0]&&"object"==typeof i&&null!==i&&0===Object.keys(i).length)return"empty";if(!("default"in t)||void 0===t.default)return"missing-default";if("function"!=typeof t.default)throw fY(r);return"valid"}(a,t);return"empty"===i?{skipped:!0,issue:{path:t,message:"File is empty."}}:"missing-default"===i?{skipped:!0,issue:{path:t,message:"File does not export a default resource handler."}}:{skipped:!1,path:t,resourceModule:a}})))){if(i.skipped){a.push(i.issue);continue}r.set(i.path,i.resourceModule)}return{resourceModules:r,skippedResources:a}}let fQ=function(t=console){let r="";return a=>{let i=a.map(({path:t,message:r})=>`${t}:${r}`).sort().join("|");if(i===r||(r=i,0===a.length))return;a.forEach(({path:r,message:a})=>{t.warn(`[xmcp] Failed to load resource file: ${r}
85
- -> ${a}`)});let n=a.length;t.warn(`[xmcp] ${n} resource${1===n?"":"s"} skipped due to empty files or missing default exports`)}}();function f0(t){let r=t.replace(/\\/g,"/");if(!r)throw Error("Invalid tool path: path is empty");let a=r.replace(/\.[^/.]+$/,"").replace(/\//g,"_");return{normalizedPath:r,baseName:a}}function f1(t){let r=t.split("/").filter(t=>""!==t),a=r.findIndex(t=>t.match(/^\(.+\)$/));if(-1===a)return null;let i=r[r.length-1];if(i&&i.match(/^\[.+\]\.ts$/))return null;let n=r[a].slice(1,-1),o=r.slice(a+1),s=o[o.length-1];if(s&&s.includes(".")){let t=s.split(".")[0];"index"!==t?o[o.length-1]=t:o.pop()}let l=[],c=[],u=o.map(t=>{if(!t.match(/^\[.+\]$/))return c.push(t),t;{let r=t.slice(1,-1);return l.push(r),`{${r}}`}}),d=`${n}://${u.join("/")}`,p=l.length>0?"template":"direct";return{filePath:t,uriTemplate:d,scheme:n,parameters:l,pathSegments:c,type:p}}function f2(t){return Error(`[xmcp] Invalid tool file: ${t}
86
- -> Default export must be a tool handler function.`)}async function f9(t){let r=new Map,a=[];for(let i of(await Promise.all(Object.entries(t).map(async([t,r])=>{let a=await r(),i=function(t,r){if("object"!=typeof t||null===t)throw f2(r);let a=Object.keys(t),i=t.default,n=a.filter(t=>"__esModule"!==t);if(0===a.length||1===n.length&&"default"===n[0]&&"object"==typeof i&&null!==i&&0===Object.keys(i).length)return"empty";if(!("default"in t)||void 0===t.default)return"missing-default";if("function"!=typeof t.default)throw f2(r);return"valid"}(a,t);return"empty"===i?{skipped:!0,issue:{path:t,message:"File is empty."}}:"missing-default"===i?{skipped:!0,issue:{path:t,message:"File does not export a default tool handler."}}:{skipped:!1,path:t,toolModule:a}})))){if(i.skipped){a.push(i.issue);continue}r.set(i.path,i.toolModule)}return{toolModules:r,skippedTools:a}}let f4=function(t=console){let r="";return a=>{let i=a.map(({path:t,message:r})=>`${t}:${r}`).sort().join("|");if(i===r||(r=i,0===a.length))return;a.forEach(({path:r,message:a})=>{t.warn(`[xmcp] Failed to load tool file: ${r}
87
- -> ${a}`)});let n=a.length;t.warn(`[xmcp] ${n} tool${1===n?"":"s"} skipped due to empty files or missing default exports`)}}(),f3=INJECTED_TOOLS,f6=INJECTED_PROMPTS,f5=INJECTED_RESOURCES,f8=SERVER_INFO;async function f7(t,r,i,n){let o=await INJECTED_MIDDLEWARE?.(),s=function(t){if(void 0===t)return[];let r=Array.isArray(t)?[...t]:[t];if(!r.every(t=>"function"==typeof t))throw Error("src/middleware.ts must export mcp as a function or an array of functions");return r}(o?.mcp),l="undefined"!=typeof OBSERVABILITY_CONFIG&&OBSERVABILITY_CONFIG.enabled?function(t=t=>console.error(t)){let r=new Map,a=[];function i(r){try{t(JSON.stringify({"@timestamp":new Date().toISOString(),...r}))}catch{}}return{middleware:async(t,n)=>{let o,s,l;if("tools/call"!==t.method&&"prompts/get"!==t.method&&"resources/read"!==t.method)return n();try{s=performance.now(),o={log:{level:"info"},...function(t){let r=t.http?.headers.traceparent;if("string"!=typeof r)return{};let a=/^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/.exec(r);return!a||"ff"===a[1]||/^0+$/.test(a[2])||/^0+$/.test(a[3])||"00"===a[1]&&void 0!==a[5]?{}:{trace:{id:a[2]},parent:{id:a[3]}}}(t),transaction:{id:crypto.randomUUID()},...t.http?{http:{request:{id:t.http.id}}}:{},xmcp:{method:t.method,component:"resources/read"===t.method?function(t){try{let i=new URL(t).href;return r.get(i)??a.find(({template:t})=>t.uriTemplate.match(i))?.name??"unknown"}catch{return"unknown"}}(t.params.uri):t.params.name}}}catch{return n()}i({...o,event:{kind:"event",category:["api"],type:["start"],action:"execution.start"}});let c="unknown";try{let r=await n();try{c=t.signal.aborted?"cancelled":c0(r)?"input_required":"isError"in r&&!0===r.isError?"failure":"success","failure"===c&&(l={message:"Operation returned an error result"})}catch{}return r}catch(r){throw l={message:"cancelled"==(c=t.signal.aborted?"cancelled":"failure")?"Operation cancelled":"Operation threw an exception"},r}finally{try{i({...o,log:{level:"failure"===c?"error":"info"},event:{kind:"event",category:["api"],type:["end"],action:"execution.end",duration:Math.round((performance.now()-s)*1e6),outcome:"success"===c?"success":"failure"===c?"failure":"unknown"},xmcp:{...o.xmcp,status:c},...l?{error:l}:{}})}catch{}}},registerResource(t,i){try{"string"==typeof i?r.set(new URL(i).href,t):a.push({name:t,template:i})}catch{}}}}():void 0;l&&s.unshift(l.middleware),mN.clear();let c="undefined"==typeof COMPONENTS_CONFIG?void 0:COMPONENTS_CONFIG;return!function(t,r,a){let i=t.server,n=i.setRequestHandler,o=he(r);i.setRequestHandler=(t,...r)=>{if(ht.has(t)&&1===r.length&&"function"==typeof r[0]){let t=r[0];r[0]=(r,a)=>o({method:r.method,params:r.params??{}},a,()=>t(r,a))}Reflect.apply(n,i,[t,...r])};try{a()}finally{i.setRequestHandler=n}}(t,s,()=>{var o,u;!function(t,r,a=[]){r.forEach((r,i)=>{var n,o;let s,l,c,u,d={name:fH(i),description:"No description provided"},{default:p,metadata:m,schema:h,outputSchema:f}=r;if("object"==typeof m&&null!==m&&Object.assign(d,m),!1===d.enabled)return;if("function"==typeof p&&"__x402"in p){let t=global.__XMCP_X402_REGISTRY;t&&t.set(d.name,p.__x402)}let y={};if(fF(h)?y=h:null!=h&&console.warn(`Invalid schema for tool "${d.name}" at ${i}. Expected Record<string, z.ZodType>`),null!=f)if(fF(f))s=f;else throw Error(`Invalid outputSchema for tool "${d.name}" at ${i}. Expected Record<string, z.ZodType>`);d.annotations={...d.annotations??{}},void 0===d.annotations.title&&(d.annotations.title=d.name),d._meta={...mI(d)._meta};let g=hr(i),v=!!(n=d._meta)&&"object"==typeof n&&"ui"in n&&"object"==typeof n.ui||g,_=d._meta;if(v){let t=`ui://app/${d.name}.html`;d._meta.ui||(d._meta.ui={}),d._meta.ui.resourceUri||(d._meta.ui.resourceUri=t);let r=function(t){let r={},a={};if(t.ui&&"object"==typeof t.ui){let i=t.ui,n={},o={};for(let[t,r]of Object.entries(i))fU.includes(t)?n[t]=r:fV.includes(t)?o[t]=r:n[t]=r;Object.keys(n).length>0&&(r.ui=n),Object.keys(o).length>0&&(a.ui=o)}for(let[a,i]of Object.entries(t))"ui"!==a&&(r[a]=i);return{toolMeta:r,resourceMeta:a}}(_);_=r.toolMeta;let a=r.resourceMeta;a.ui=a.ui||{},a.ui.csp=a.ui.csp||{},a.ui.csp.resourceDomains=a.ui.csp.resourceDomains||[],a.ui.csp.resourceDomains.includes("https://esm.sh")||a.ui.csp.resourceDomains.push("https://esm.sh"),mN.add(d.name,{name:d.name,uri:t,handler:p,mimeType:"text/html;profile=mcp-app",_meta:a,toolPath:g?i:void 0})}let b=fD(_),S=v?b:void 0;l=hr(i)&&v?async(t,r)=>({content:[{type:"text",text:""}],_meta:S,structuredContent:{args:t}}):function(t,r,a,i="unknown-tool"){return async(n,o)=>{let s,l,c=t(n,(s=m7(o),l=function(t){if(!t)return;let r={};return t.headers.forEach((t,a)=>{r[a]=t}),r}(o.http?.req),{signal:o.mcpReq.signal,authInfo:o.http?.authInfo,sessionId:o.sessionId,_meta:o.mcpReq._meta,requestId:o.mcpReq.id,requestInfo:l?{headers:l}:void 0,clientInfo:s,sendNotification:t=>o.mcpReq.notify(t),sendRequest:(t,r,a)=>o.mcpReq.send(t,r,a),elicit:(t,r)=>mJ(o,t,r),sample:(t,r)=>m9(o,t,r),inputResponses:o.mcpReq.inputResponses,requestState:o.mcpReq.requestState}));if(c instanceof Promise&&(c=await c),c0(c))return c;if("string"==typeof c||"number"==typeof c){if(a){let t=Object.entries(a);if(1===t.length){let[r,a]=t[0];try{return a.parse(c),{content:[{type:"text",text:"number"==typeof c?`${c}`:c}],structuredContent:{[r]:c}}}catch{}}}return m8(r)?{content:[{type:"text",text:""}],structuredContent:{args:n},_meta:r}:{content:[{type:"text",text:"number"==typeof c?`${c}`:c}]}}if(!a||!c||"object"!=typeof c||Array.isArray(c)||"structuredContent"in c||"content"in c&&Array.isArray(c.content)||"_meta"in c||"isError"in c||(m5(c,a,i,"returned data that does not match outputSchema"),c={structuredContent:c}),c&&"object"==typeof c&&"_meta"in c&&!("content"in c)&&!("structuredContent"in c)){let t=c._meta;if(m8(t))return{content:[{type:"text",text:""}],_meta:t}}if(!c||"object"!=typeof c){let t=null===c?"null":typeof c,r=void 0===c?"undefined":null===c?"null":"object"==typeof c?JSON.stringify(c,null,2):String(c);throw Error(`Tool handler must return a CallToolResult, string, or number. Got ${t}: ${r}
81
+ ]`;continue}n+=i[t],"\\"===i[t]?o=!0:s&&"]"===i[t]?s=!1:s||"["!==i[t]||(s=!0)}try{new RegExp(n)}catch{return console.warn(`Could not convert regex pattern at ${r.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),t.source}return n}function fA(t,r){if("openAi"===r.target&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),"openApi3"===r.target&&t.keyType?._def.typeName===Z.ZodEnum)return{type:"object",required:t.keyType._def.values,properties:t.keyType._def.values.reduce((a,i)=>({...a,[i]:fL(t.valueType._def,{...r,currentPath:[...r.currentPath,"properties",i]})??ff(r)}),{}),additionalProperties:r.rejectedAdditionalProperties};let a={type:"object",additionalProperties:fL(t.valueType._def,{...r,currentPath:[...r.currentPath,"additionalProperties"]})??r.allowedAdditionalProperties};if("openApi3"===r.target)return a;if(t.keyType?._def.typeName===Z.ZodString&&t.keyType._def.checks?.length){let{type:i,...n}=fj(t.keyType._def,r);return{...a,propertyNames:n}}if(t.keyType?._def.typeName===Z.ZodEnum)return{...a,propertyNames:{enum:t.keyType._def.values}};if(t.keyType?._def.typeName===Z.ZodBranded&&t.keyType._def.type._def.typeName===Z.ZodString&&t.keyType._def.type._def.checks?.length){let{type:i,...n}=fv(t.keyType._def,r);return{...a,propertyNames:n}}return a}let fM={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"},fz=(t,r)=>{let a=(t.options instanceof Map?Array.from(t.options.values()):t.options).map((t,a)=>fL(t._def,{...r,currentPath:[...r.currentPath,"anyOf",`${a}`]})).filter(t=>!!t&&(!r.strictUnions||"object"==typeof t&&Object.keys(t).length>0));return a.length?{anyOf:a}:void 0};function fL(t,r,a=!1){let i=r.seen.get(t);if(r.override){let n=r.override?.(t,r,i,a);if(n!==ha)return n}if(i&&!a){let t=fZ(i,r);if(void 0!==t)return t}let n={def:t,path:r.currentPath,jsonSchema:void 0};r.seen.set(t,n);let o=((t,r,a)=>{switch(r){case Z.ZodString:return fj(t,a);case Z.ZodNumber:let i={type:"number"};if(!t.checks)return i;for(let r of t.checks)switch(r.kind){case"int":i.type="integer",fy(i,"type",r.message,a);break;case"min":"jsonSchema7"===a.target?r.inclusive?fg(i,"minimum",r.value,r.message,a):fg(i,"exclusiveMinimum",r.value,r.message,a):(r.inclusive||(i.exclusiveMinimum=!0),fg(i,"minimum",r.value,r.message,a));break;case"max":"jsonSchema7"===a.target?r.inclusive?fg(i,"maximum",r.value,r.message,a):fg(i,"exclusiveMaximum",r.value,r.message,a):(r.inclusive||(i.exclusiveMaximum=!0),fg(i,"maximum",r.value,r.message,a));break;case"multipleOf":fg(i,"multipleOf",r.value,r.message,a)}return i;case Z.ZodObject:return function(t,r){let a="openAi"===r.target,i={type:"object",properties:{}},n=[],o=t.shape();for(let t in o){let s=o[t];if(void 0===s||void 0===s._def)continue;let l=function(t){try{return t.isOptional()}catch{return!0}}(s);l&&a&&("ZodOptional"===s._def.typeName&&(s=s._def.innerType),s.isNullable()||(s=s.nullable()),l=!1);let c=fL(s._def,{...r,currentPath:[...r.currentPath,"properties",t],propertyPath:[...r.currentPath,"properties",t]});void 0!==c&&(i.properties[t]=c,l||n.push(t))}n.length&&(i.required=n);let s=function(t,r){if("ZodNever"!==t.catchall._def.typeName)return fL(t.catchall._def,{...r,currentPath:[...r.currentPath,"additionalProperties"]});switch(t.unknownKeys){case"passthrough":return r.allowedAdditionalProperties;case"strict":return r.rejectedAdditionalProperties;case"strip":return"strict"===r.removeAdditionalStrategy?r.allowedAdditionalProperties:r.rejectedAdditionalProperties}}(t,r);return void 0!==s&&(i.additionalProperties=s),i}(t,a);case Z.ZodBigInt:let n={type:"integer",format:"int64"};if(!t.checks)return n;for(let r of t.checks)switch(r.kind){case"min":"jsonSchema7"===a.target?r.inclusive?fg(n,"minimum",r.value,r.message,a):fg(n,"exclusiveMinimum",r.value,r.message,a):(r.inclusive||(n.exclusiveMinimum=!0),fg(n,"minimum",r.value,r.message,a));break;case"max":"jsonSchema7"===a.target?r.inclusive?fg(n,"maximum",r.value,r.message,a):fg(n,"exclusiveMaximum",r.value,r.message,a):(r.inclusive||(n.exclusiveMaximum=!0),fg(n,"maximum",r.value,r.message,a));break;case"multipleOf":fg(n,"multipleOf",r.value,r.message,a)}return n;case Z.ZodBoolean:return{type:"boolean"};case Z.ZodDate:return function t(r,a,i){let n=i??a.dateStrategy;if(Array.isArray(n))return{anyOf:n.map((i,n)=>t(r,a,i))};switch(n){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":var o=r,s=a;let l={type:"integer",format:"unix-time"};if("openApi3"===s.target)return l;for(let t of o.checks)switch(t.kind){case"min":fg(l,"minimum",t.value,t.message,s);break;case"max":fg(l,"maximum",t.value,t.message,s)}return l}}(t,a);case Z.ZodUndefined:return{not:ff(a)};case Z.ZodNull:return"openApi3"===a.target?{enum:["null"],nullable:!0}:{type:"null"};case Z.ZodArray:let o;return o={type:"array"},t.type?._def&&t.type?._def?.typeName!==Z.ZodAny&&(o.items=fL(t.type._def,{...a,currentPath:[...a.currentPath,"items"]})),t.minLength&&fg(o,"minItems",t.minLength.value,t.minLength.message,a),t.maxLength&&fg(o,"maxItems",t.maxLength.value,t.maxLength.message,a),t.exactLength&&(fg(o,"minItems",t.exactLength.value,t.exactLength.message,a),fg(o,"maxItems",t.exactLength.value,t.exactLength.message,a)),o;case Z.ZodUnion:case Z.ZodDiscriminatedUnion:if("openApi3"===a.target)return fz(t,a);let s=t.options instanceof Map?Array.from(t.options.values()):t.options;if(s.every(t=>t._def.typeName in fM&&(!t._def.checks||!t._def.checks.length))){let t=s.reduce((t,r)=>{let a=fM[r._def.typeName];return a&&!t.includes(a)?[...t,a]:t},[]);return{type:t.length>1?t:t[0]}}if(s.every(t=>"ZodLiteral"===t._def.typeName&&!t.description)){let t=s.reduce((t,r)=>{let a=typeof r._def.value;switch(a){case"string":case"number":case"boolean":return[...t,a];case"bigint":return[...t,"integer"];case"object":if(null===r._def.value)return[...t,"null"];default:return t}},[]);if(t.length===s.length){let r=t.filter((t,r,a)=>a.indexOf(t)===r);return{type:r.length>1?r:r[0],enum:s.reduce((t,r)=>t.includes(r._def.value)?t:[...t,r._def.value],[])}}}else if(s.every(t=>"ZodEnum"===t._def.typeName))return{type:"string",enum:s.reduce((t,r)=>[...t,...r._def.values.filter(r=>!t.includes(r))],[])};return fz(t,a);case Z.ZodIntersection:let l,c,u;return l=[fL(t.left._def,{...a,currentPath:[...a.currentPath,"allOf","0"]}),fL(t.right._def,{...a,currentPath:[...a.currentPath,"allOf","1"]})].filter(t=>!!t),c="jsonSchema2019-09"===a.target?{unevaluatedProperties:!1}:void 0,u=[],l.forEach(t=>{if((!("type"in t)||"string"!==t.type)&&"allOf"in t)u.push(...t.allOf),void 0===t.unevaluatedProperties&&(c=void 0);else{let r=t;if("additionalProperties"in t&&!1===t.additionalProperties){let{additionalProperties:a,...i}=t;r=i}else c=void 0;u.push(r)}}),u.length?{allOf:u,...c}:void 0;case Z.ZodTuple:return t.rest?{type:"array",minItems:t.items.length,items:t.items.map((t,r)=>fL(t._def,{...a,currentPath:[...a.currentPath,"items",`${r}`]})).reduce((t,r)=>void 0===r?t:[...t,r],[]),additionalItems:fL(t.rest._def,{...a,currentPath:[...a.currentPath,"additionalItems"]})}:{type:"array",minItems:t.items.length,maxItems:t.items.length,items:t.items.map((t,r)=>fL(t._def,{...a,currentPath:[...a.currentPath,"items",`${r}`]})).reduce((t,r)=>void 0===r?t:[...t,r],[])};case Z.ZodRecord:return fA(t,a);case Z.ZodLiteral:let d;return"bigint"!=(d=typeof t.value)&&"number"!==d&&"boolean"!==d&&"string"!==d?{type:Array.isArray(t.value)?"array":"object"}:"openApi3"===a.target?{type:"bigint"===d?"integer":d,enum:[t.value]}:{type:"bigint"===d?"integer":d,const:t.value};case Z.ZodEnum:return{type:"string",enum:Array.from(t.values)};case Z.ZodNativeEnum:let p,m,h;return p=t.values,{type:1===(h=Array.from(new Set((m=Object.keys(t.values).filter(t=>"number"!=typeof p[p[t]]).map(t=>p[t])).map(t=>typeof t)))).length?"string"===h[0]?"string":"number":["string","number"],enum:m};case Z.ZodNullable:if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(t.innerType._def.typeName)&&(!t.innerType._def.checks||!t.innerType._def.checks.length))return"openApi3"===a.target?{type:fM[t.innerType._def.typeName],nullable:!0}:{type:[fM[t.innerType._def.typeName],"null"]};if("openApi3"===a.target){let r=fL(t.innerType._def,{...a,currentPath:[...a.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}let f=fL(t.innerType._def,{...a,currentPath:[...a.currentPath,"anyOf","0"]});return f&&{anyOf:[f,{type:"null"}]};case Z.ZodOptional:if(a.currentPath.toString()===a.propertyPath?.toString())return fL(t.innerType._def,a);let y=fL(t.innerType._def,{...a,currentPath:[...a.currentPath,"anyOf","1"]});return y?{anyOf:[{not:ff(a)},y]}:ff(a);case Z.ZodMap:if("record"===a.mapStrategy)return fA(t,a);return{type:"array",maxItems:125,items:{type:"array",items:[fL(t.keyType._def,{...a,currentPath:[...a.currentPath,"items","items","0"]})||ff(a),fL(t.valueType._def,{...a,currentPath:[...a.currentPath,"items","items","1"]})||ff(a)],minItems:2,maxItems:2}};case Z.ZodSet:let g;return g={type:"array",uniqueItems:!0,items:fL(t.valueType._def,{...a,currentPath:[...a.currentPath,"items"]})},t.minSize&&fg(g,"minItems",t.minSize.value,t.minSize.message,a),t.maxSize&&fg(g,"maxItems",t.maxSize.value,t.maxSize.message,a),g;case Z.ZodLazy:return()=>t.getter()._def;case Z.ZodPromise:return fL(t.type._def,a);case Z.ZodNaN:case Z.ZodNever:return"openAi"===a.target?void 0:{not:ff({...a,currentPath:[...a.currentPath,"not"]})};case Z.ZodEffects:return"input"===a.effectStrategy?fL(t.schema._def,a):ff(a);case Z.ZodAny:case Z.ZodUnknown:return ff(a);case Z.ZodDefault:return{...fL(t.innerType._def,a),default:t.defaultValue()};case Z.ZodBranded:return fv(t,a);case Z.ZodReadonly:case Z.ZodCatch:return fL(t.innerType._def,a);case Z.ZodPipeline:if("input"===a.pipeStrategy)return fL(t.in._def,a);if("output"===a.pipeStrategy)return fL(t.out._def,a);let v=fL(t.in._def,{...a,currentPath:[...a.currentPath,"allOf","0"]}),_=fL(t.out._def,{...a,currentPath:[...a.currentPath,"allOf",v?"1":"0"]});return{allOf:[v,_].filter(t=>void 0!==t)};case Z.ZodFunction:case Z.ZodVoid:case Z.ZodSymbol:default:return}})(t,t.typeName,r),s="function"==typeof o?fL(o(),r):o;if(s&&fD(t,r,s),r.postProcess){let a=r.postProcess(s,t,r);return n.jsonSchema=s,a}return n.jsonSchema=s,s}let fZ=(t,r)=>{switch(r.$refStrategy){case"root":return{$ref:t.path.join("/")};case"relative":return{$ref:fh(r.currentPath,t.path)};case"none":case"seen":if(t.path.length<r.currentPath.length&&t.path.every((t,a)=>r.currentPath[a]===t))return console.warn(`Recursive reference detected at ${r.currentPath.join("/")}! Defaulting to any`),ff(r);return"seen"===r.$refStrategy?ff(r):void 0}},fD=(t,r,a)=>(t.description&&(a.description=t.description,r.markdownDescription&&(a.markdownDescription=t.description)),a);function fU(t,r={}){let{strict:a=!1}=r,i=Object.entries(t),n=t=>({target:r})=>{let n={},o=[];for(let[a,s]of i)n[a]=function(t,r,a){let i=t["~standard"];if(i.jsonSchema)return i.jsonSchema[a]({target:r});if("zod"===t["~standard"].vendor&&!("_zod"in t)&&"_def"in t){let a=((t,r)=>{let a,i,n=(i=void 0!==(a="string"==typeof r?{...hi,name:r}:{...hi,...r}).name?[...a.basePath,a.definitionPath,a.name]:a.basePath,{...a,flags:{hasReferencedOpenAiAnyType:!1},currentPath:i,propertyPath:void 0,seen:new Map(Object.entries(a.definitions).map(([t,r])=>[r._def,{def:r._def,path:[...a.basePath,a.definitionPath,t],jsonSchema:void 0}]))}),o="object"==typeof r&&r.definitions?Object.entries(r.definitions).reduce((t,[r,a])=>({...t,[r]:fL(a._def,{...n,currentPath:[...n.basePath,n.definitionPath,r]},!0)??ff(n)}),{}):void 0,s="string"==typeof r?r:r?.nameStrategy==="title"?void 0:r?.name,l=fL(t._def,void 0===s?n:{...n,currentPath:[...n.basePath,n.definitionPath,s]},!1)??ff(n),c="object"==typeof r&&void 0!==r.name&&"title"===r.nameStrategy?r.name:void 0;void 0!==c&&(l.title=c),n.flags.hasReferencedOpenAiAnyType&&(o||(o={}),o[n.openAiAnyTypeName]||(o[n.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:"relative"===n.$refStrategy?"1":[...n.basePath,n.definitionPath,n.openAiAnyTypeName].join("/")}}));let u=void 0===s?o?{...l,[n.definitionPath]:o}:l:{$ref:[..."relative"===n.$refStrategy?[]:n.basePath,n.definitionPath,s].join("/"),[n.definitionPath]:{...o,[s]:l}};return"jsonSchema7"===n.target?u.$schema="http://json-schema.org/draft-07/schema#":("jsonSchema2019-09"===n.target||"openAi"===n.target)&&(u.$schema="https://json-schema.org/draft/2019-09/schema#"),"openAi"===n.target&&("anyOf"in u||"oneOf"in u||"allOf"in u||"type"in u&&Array.isArray(u.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),u})(t,{$refStrategy:"none",target:"openapi-3.0"===r?"openApi3":"jsonSchema7"});return delete a.$schema,a}if("zod"===i.vendor&&"_zod"in t)try{let r=it(t);return delete r.$schema,r}catch(t){throw Error(`Failed to convert a zod schema to JSON Schema (zod v4 without "~standard.jsonSchema"). Upgrade to zod >= 4.2.0. Original error: ${t instanceof Error?t.message:String(t)}`)}throw Error(`Schema library "${i.vendor}" cannot be converted to JSON Schema. Use zod v3 (>= 3.25.76), zod >= 4.2.0, or a Standard Schema library implementing "~standard.jsonSchema".`)}(s,r,t),!function(t,r){if("function"!=typeof t.safeParse)return!1;try{let a=t.safeParse(void 0);return a.success&&("input"===r||void 0===a.data)}catch{return!1}}(s,t)&&o.push(a);let s={type:"object",properties:n};return o.length>0&&(s.required=o),a&&(s.additionalProperties=!1),s},o=async r=>{if("object"!=typeof r||null===r||Array.isArray(r))return{issues:[{message:"Expected an object."}]};let n={},o=[];for(let[t,a]of i){let i=await a["~standard"].validate(r[t]);if(i.issues)for(let r of i.issues)o.push({message:r.message,path:[t,...r.path??[]]});else(t in r||void 0!==i.value)&&(n[t]=i.value)}if(a)for(let a of Object.keys(r))a in t||o.push({message:`Unrecognized key: "${a}"`,path:[a]});return o.length>0?{issues:o}:{value:n}};return{shape:t,"~standard":{version:1,vendor:"xmcp",validate:o,jsonSchema:{input:n("input"),output:n("output")}}}}function fV(t){let r={};return!function t(a,i=""){if(a&&"object"==typeof a)for(let[n,o]of Object.entries(a)){let a=i?`${i}/${n}`:n;!o||"object"!=typeof o||Array.isArray(o)||o instanceof Date||o instanceof RegExp?r[a]=o:t(o,a)}}(t),r}let fF=["ui/resourceUri","resourceUri","visibility"],fH=["prefersBorder","domain","csp","permissions","connectDomains","resourceDomains","frameDomains","baseUriDomains"];function fJ(t){return"object"==typeof t&&null!==t&&Object.entries(t).every(([t,r])=>"string"==typeof t&&"object"==typeof r&&null!==r&&"parse"in r&&"function"==typeof r.parse)}function fB(t){return(t.split("/").pop()||t).replace(/\.[^/.]+$/,"")}function fK(t,r,a){return t.names?.includes(r)===!0||t.tags?.some(t=>a.includes(t))===!0}function fG(t,r){return r?new Map([...t].filter(([t,{metadata:a}])=>{if(a?.enabled===!1)return!1;let i=a?.name??fB(t),n=a?.tags??[];return(!r.include||fK(r.include,i,n))&&(!r.exclude||!fK(r.exclude,i,n))})):t}function fW(t){return Error(`[xmcp] Invalid prompt file: ${t}
82
+ -> Default export must be a prompt handler function.`)}async function fY(t){let r=new Map,a=[];for(let i of(await Promise.all(Object.entries(t).map(async([t,r])=>{let a=await r(),i=function(t,r){if("object"!=typeof t||null===t)throw fW(r);let a=Object.keys(t),i=t.default,n=a.filter(t=>"__esModule"!==t);if(0===a.length||1===n.length&&"default"===n[0]&&"object"==typeof i&&null!==i&&0===Object.keys(i).length)return"empty";if(!("default"in t)||void 0===t.default)return"missing-default";if("function"!=typeof t.default)throw fW(r);return"valid"}(a,t);return"empty"===i?{skipped:!0,issue:{path:t,message:"File is empty."}}:"missing-default"===i?{skipped:!0,issue:{path:t,message:"File does not export a default prompt handler."}}:{skipped:!1,path:t,promptModule:a}})))){if(i.skipped){a.push(i.issue);continue}r.set(i.path,i.promptModule)}return{promptModules:r,skippedPrompts:a}}let fX=function(t=console){let r="";return a=>{let i=a.map(({path:t,message:r})=>`${t}:${r}`).sort().join("|");if(i===r||(r=i,0===a.length))return;a.forEach(({path:r,message:a})=>{t.warn(`[xmcp] Failed to load prompt file: ${r}
83
+ -> ${a}`)});let n=a.length;t.warn(`[xmcp] ${n} prompt${1===n?"":"s"} skipped due to empty files or missing default exports`)}}();function fQ(t){return Error(`[xmcp] Invalid resource file: ${t}
84
+ -> Default export must be a resource handler function.`)}async function f0(t){let r=new Map,a=[];for(let i of(await Promise.all(Object.entries(t).map(async([t,r])=>{let a=await r(),i=function(t,r){if("object"!=typeof t||null===t)throw fQ(r);let a=Object.keys(t),i=t.default,n=a.filter(t=>"__esModule"!==t);if(0===a.length||1===n.length&&"default"===n[0]&&"object"==typeof i&&null!==i&&0===Object.keys(i).length)return"empty";if(!("default"in t)||void 0===t.default)return"missing-default";if("function"!=typeof t.default)throw fQ(r);return"valid"}(a,t);return"empty"===i?{skipped:!0,issue:{path:t,message:"File is empty."}}:"missing-default"===i?{skipped:!0,issue:{path:t,message:"File does not export a default resource handler."}}:{skipped:!1,path:t,resourceModule:a}})))){if(i.skipped){a.push(i.issue);continue}r.set(i.path,i.resourceModule)}return{resourceModules:r,skippedResources:a}}let f1=function(t=console){let r="";return a=>{let i=a.map(({path:t,message:r})=>`${t}:${r}`).sort().join("|");if(i===r||(r=i,0===a.length))return;a.forEach(({path:r,message:a})=>{t.warn(`[xmcp] Failed to load resource file: ${r}
85
+ -> ${a}`)});let n=a.length;t.warn(`[xmcp] ${n} resource${1===n?"":"s"} skipped due to empty files or missing default exports`)}}();function f2(t){let r=t.replace(/\\/g,"/");if(!r)throw Error("Invalid tool path: path is empty");let a=r.replace(/\.[^/.]+$/,"").replace(/\//g,"_");return{normalizedPath:r,baseName:a}}function f9(t){let r=t.split("/").filter(t=>""!==t),a=r.findIndex(t=>t.match(/^\(.+\)$/));if(-1===a)return null;let i=r[r.length-1];if(i&&i.match(/^\[.+\]\.ts$/))return null;let n=r[a].slice(1,-1),o=r.slice(a+1),s=o[o.length-1];if(s&&s.includes(".")){let t=s.split(".")[0];"index"!==t?o[o.length-1]=t:o.pop()}let l=[],c=[],u=o.map(t=>{if(!t.match(/^\[.+\]$/))return c.push(t),t;{let r=t.slice(1,-1);return l.push(r),`{${r}}`}}),d=`${n}://${u.join("/")}`,p=l.length>0?"template":"direct";return{filePath:t,uriTemplate:d,scheme:n,parameters:l,pathSegments:c,type:p}}let f4={ttlMs:0,cacheScope:"private"},f3=fm({cursor:fp().optional()}).passthrough().optional(),f6=fm({uri:fp()}).passthrough();function f5({uri:t,frontmatter:r,files:a}){return{uri:t,frontmatter:r,resources:a.map(({uri:t,digest:r,size:a})=>({uri:t,digest:r,size:a}))}}function f8(t){return Error(`[xmcp] Invalid tool file: ${t}
86
+ -> Default export must be a tool handler function.`)}async function f7(t){let r=new Map,a=[];for(let i of(await Promise.all(Object.entries(t).map(async([t,r])=>{let a=await r(),i=function(t,r){if("object"!=typeof t||null===t)throw f8(r);let a=Object.keys(t),i=t.default,n=a.filter(t=>"__esModule"!==t);if(0===a.length||1===n.length&&"default"===n[0]&&"object"==typeof i&&null!==i&&0===Object.keys(i).length)return"empty";if(!("default"in t)||void 0===t.default)return"missing-default";if("function"!=typeof t.default)throw f8(r);return"valid"}(a,t);return"empty"===i?{skipped:!0,issue:{path:t,message:"File is empty."}}:"missing-default"===i?{skipped:!0,issue:{path:t,message:"File does not export a default tool handler."}}:{skipped:!1,path:t,toolModule:a}})))){if(i.skipped){a.push(i.issue);continue}r.set(i.path,i.toolModule)}return{toolModules:r,skippedTools:a}}let ye=function(t=console){let r="";return a=>{let i=a.map(({path:t,message:r})=>`${t}:${r}`).sort().join("|");if(i===r||(r=i,0===a.length))return;a.forEach(({path:r,message:a})=>{t.warn(`[xmcp] Failed to load tool file: ${r}
87
+ -> ${a}`)});let n=a.length;t.warn(`[xmcp] ${n} tool${1===n?"":"s"} skipped due to empty files or missing default exports`)}}(),yt=INJECTED_TOOLS,yr=INJECTED_PROMPTS,ya=INJECTED_RESOURCES,yi="undefined"==typeof INJECTED_SKILLS?[]:INJECTED_SKILLS??[],yn=SERVER_INFO;async function yo(t,r,i,n){let o=await INJECTED_MIDDLEWARE?.(),s=function(t){if(void 0===t)return[];let r=Array.isArray(t)?[...t]:[t];if(!r.every(t=>"function"==typeof t))throw Error("src/middleware.ts must export mcp as a function or an array of functions");return r}(o?.mcp),l="undefined"!=typeof OBSERVABILITY_CONFIG&&OBSERVABILITY_CONFIG.enabled?function(t=t=>console.error(t)){let r=new Map,a=[];function i(r){try{t(JSON.stringify({"@timestamp":new Date().toISOString(),...r}))}catch{}}return{middleware:async(t,n)=>{let o,s,l;if("tools/call"!==t.method&&"prompts/get"!==t.method&&"resources/read"!==t.method)return n();try{s=performance.now(),o={log:{level:"info"},...function(t){let r=t.http?.headers.traceparent;if("string"!=typeof r)return{};let a=/^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/.exec(r);return!a||"ff"===a[1]||/^0+$/.test(a[2])||/^0+$/.test(a[3])||"00"===a[1]&&void 0!==a[5]?{}:{trace:{id:a[2]},parent:{id:a[3]}}}(t),transaction:{id:crypto.randomUUID()},...t.http?{http:{request:{id:t.http.id}}}:{},xmcp:{method:t.method,component:"resources/read"===t.method?function(t){try{let i=new URL(t).href;return r.get(i)??a.find(({template:t})=>t.uriTemplate.match(i))?.name??"unknown"}catch{return"unknown"}}(t.params.uri):t.params.name}}}catch{return n()}i({...o,event:{kind:"event",category:["api"],type:["start"],action:"execution.start"}});let c="unknown";try{let r=await n();try{c=t.signal.aborted?"cancelled":c0(r)?"input_required":"isError"in r&&!0===r.isError?"failure":"success","failure"===c&&(l={message:"Operation returned an error result"})}catch{}return r}catch(r){throw l={message:"cancelled"==(c=t.signal.aborted?"cancelled":"failure")?"Operation cancelled":"Operation threw an exception"},r}finally{try{i({...o,log:{level:"failure"===c?"error":"info"},event:{kind:"event",category:["api"],type:["end"],action:"execution.end",duration:Math.round((performance.now()-s)*1e6),outcome:"success"===c?"success":"failure"===c?"failure":"unknown"},xmcp:{...o.xmcp,status:c},...l?{error:l}:{}})}catch{}}},registerResource(t,i){try{"string"==typeof i?r.set(new URL(i).href,t):a.push({name:t,template:i})}catch{}}}}():void 0;l&&s.unshift(l.middleware),mN.clear();let c="undefined"==typeof COMPONENTS_CONFIG?void 0:COMPONENTS_CONFIG;return!function(t,r,a){let i=t.server,n=i.setRequestHandler,o=he(r);i.setRequestHandler=(t,...r)=>{if(ht.has(t)&&1===r.length&&"function"==typeof r[0]){let t=r[0];r[0]=(r,a)=>o({method:r.method,params:r.params??{}},a,()=>t(r,a))}Reflect.apply(n,i,[t,...r])};try{a()}finally{i.setRequestHandler=n}}(t,s,()=>{var o,u;!function(t,r,a=[]){r.forEach((r,i)=>{var n,o;let s,l,c,u,d={name:fB(i),description:"No description provided"},{default:p,metadata:m,schema:h,outputSchema:f}=r;if("object"==typeof m&&null!==m&&Object.assign(d,m),!1===d.enabled)return;if("function"==typeof p&&"__x402"in p){let t=global.__XMCP_X402_REGISTRY;t&&t.set(d.name,p.__x402)}let y={};if(fJ(h)?y=h:null!=h&&console.warn(`Invalid schema for tool "${d.name}" at ${i}. Expected Record<string, z.ZodType>`),null!=f)if(fJ(f))s=f;else throw Error(`Invalid outputSchema for tool "${d.name}" at ${i}. Expected Record<string, z.ZodType>`);d.annotations={...d.annotations??{}},void 0===d.annotations.title&&(d.annotations.title=d.name),d._meta={...mI(d)._meta};let g=hr(i),v=!!(n=d._meta)&&"object"==typeof n&&"ui"in n&&"object"==typeof n.ui||g,_=d._meta;if(v){let t=`ui://app/${d.name}.html`;d._meta.ui||(d._meta.ui={}),d._meta.ui.resourceUri||(d._meta.ui.resourceUri=t);let r=function(t){let r={},a={};if(t.ui&&"object"==typeof t.ui){let i=t.ui,n={},o={};for(let[t,r]of Object.entries(i))fF.includes(t)?n[t]=r:fH.includes(t)?o[t]=r:n[t]=r;Object.keys(n).length>0&&(r.ui=n),Object.keys(o).length>0&&(a.ui=o)}for(let[a,i]of Object.entries(t))"ui"!==a&&(r[a]=i);return{toolMeta:r,resourceMeta:a}}(_);_=r.toolMeta;let a=r.resourceMeta;a.ui=a.ui||{},a.ui.csp=a.ui.csp||{},a.ui.csp.resourceDomains=a.ui.csp.resourceDomains||[],a.ui.csp.resourceDomains.includes("https://esm.sh")||a.ui.csp.resourceDomains.push("https://esm.sh"),mN.add(d.name,{name:d.name,uri:t,handler:p,mimeType:"text/html;profile=mcp-app",_meta:a,toolPath:g?i:void 0})}let b=fV(_),S=v?b:void 0;l=hr(i)&&v?async(t,r)=>({content:[{type:"text",text:""}],_meta:S,structuredContent:{args:t}}):function(t,r,a,i="unknown-tool"){return async(n,o)=>{let s,l,c=t(n,(s=m7(o),l=function(t){if(!t)return;let r={};return t.headers.forEach((t,a)=>{r[a]=t}),r}(o.http?.req),{signal:o.mcpReq.signal,authInfo:o.http?.authInfo,sessionId:o.sessionId,_meta:o.mcpReq._meta,requestId:o.mcpReq.id,requestInfo:l?{headers:l}:void 0,clientInfo:s,sendNotification:t=>o.mcpReq.notify(t),sendRequest:(t,r,a)=>o.mcpReq.send(t,r,a),elicit:(t,r)=>mJ(o,t,r),sample:(t,r)=>m9(o,t,r),inputResponses:o.mcpReq.inputResponses,requestState:o.mcpReq.requestState}));if(c instanceof Promise&&(c=await c),c0(c))return c;if("string"==typeof c||"number"==typeof c){if(a){let t=Object.entries(a);if(1===t.length){let[r,a]=t[0];try{return a.parse(c),{content:[{type:"text",text:"number"==typeof c?`${c}`:c}],structuredContent:{[r]:c}}}catch{}}}return m8(r)?{content:[{type:"text",text:""}],structuredContent:{args:n},_meta:r}:{content:[{type:"text",text:"number"==typeof c?`${c}`:c}]}}if(!a||!c||"object"!=typeof c||Array.isArray(c)||"structuredContent"in c||"content"in c&&Array.isArray(c.content)||"_meta"in c||"isError"in c||(m5(c,a,i,"returned data that does not match outputSchema"),c={structuredContent:c}),c&&"object"==typeof c&&"_meta"in c&&!("content"in c)&&!("structuredContent"in c)){let t=c._meta;if(m8(t))return{content:[{type:"text",text:""}],_meta:t}}if(!c||"object"!=typeof c){let t=null===c?"null":typeof c,r=void 0===c?"undefined":null===c?"null":"object"==typeof c?JSON.stringify(c,null,2):String(c);throw Error(`Tool handler must return a CallToolResult, string, or number. Got ${t}: ${r}
88
88
 
89
89
  Expected CallToolResult format:
90
90
  {
@@ -151,7 +151,7 @@ Expected format:
151
151
  key: "value",
152
152
  nested: { data: "here" }
153
153
  }
154
- }`)}}return c}}(p,S,s,d.name);let $={title:d.annotations?.title,description:d.description,inputSchema:fZ(y),outputSchema:s?fZ(s,{strict:!0}):void 0,annotations:d.annotations,icons:d.icons,_meta:b};t.registerTool(d.name,$,(o={name:d.name,description:$.description,annotations:$.annotations,icons:$.icons,tags:d.tags,_meta:$._meta},c=he(a),u=Object.freeze({metadata:function t(r,a=new WeakMap){if(null===r||"object"!=typeof r)return r;let i=Object.getPrototypeOf(r);if(!Array.isArray(r)&&i!==Object.prototype&&null!==i)return r;if(a.has(r))return a.get(r);let n=Array.isArray(r)?[]:Object.create(i);for(let[i,o]of(a.set(r,n),Object.entries(r)))Object.defineProperty(n,i,{value:t(o,a),enumerable:!0,configurable:!0,writable:!0});return Object.freeze(n)}(o)}),(t,r)=>c({method:"tools/call",params:{name:u.metadata.name,arguments:t},tool:u},r,()=>l(t,r))))})}(t,fB(r,c),s),fB(i,c).forEach((r,a)=>{let i=fH(a),n={name:i,title:i,description:"No description provided"},o={},{default:s,metadata:l,schema:c}=r;if("object"==typeof l&&null!==l&&Object.assign(n,l),!1===n.enabled)return;let u=function(t,r="assistant"){return async(a,i)=>{let n,o=t(a,i);if(o instanceof Promise&&(o=await o),Array.isArray(o)||null!==o&&"object"==typeof o&&"messages"in o){let t=Array.isArray(o)?{messages:o}:o,r=await ux.GetPromptResult["~standard"].validate(t);if(r.issues){let t=r.issues.map(t=>{let r=t.path?.map(t=>"object"==typeof t?t.key:t).join(".");return`${r||"result"}: ${t.message}`});throw Error(`Invalid prompt result: ${t.join("; ")}`)}return t}if("string"==typeof o||"number"==typeof o)n={type:"text",text:"number"==typeof o?`${o}`:o};else{let t=m6(o);if(t.valid)n=o;else{let r=null===o?"null":typeof o,a=void 0===o?"undefined":null===o?"null":"object"==typeof o?JSON.stringify(o,null,2):String(o);throw Error(`Prompt handler must return a PromptContent object, string, number, PromptMessage[], or GetPromptResult. Got ${r}: ${a}
154
+ }`)}}return c}}(p,S,s,d.name);let $={title:d.annotations?.title,description:d.description,inputSchema:fU(y),outputSchema:s?fU(s,{strict:!0}):void 0,annotations:d.annotations,icons:d.icons,_meta:b};t.registerTool(d.name,$,(o={name:d.name,description:$.description,annotations:$.annotations,icons:$.icons,tags:d.tags,_meta:$._meta},c=he(a),u=Object.freeze({metadata:function t(r,a=new WeakMap){if(null===r||"object"!=typeof r)return r;let i=Object.getPrototypeOf(r);if(!Array.isArray(r)&&i!==Object.prototype&&null!==i)return r;if(a.has(r))return a.get(r);let n=Array.isArray(r)?[]:Object.create(i);for(let[i,o]of(a.set(r,n),Object.entries(r)))Object.defineProperty(n,i,{value:t(o,a),enumerable:!0,configurable:!0,writable:!0});return Object.freeze(n)}(o)}),(t,r)=>c({method:"tools/call",params:{name:u.metadata.name,arguments:t},tool:u},r,()=>l(t,r))))})}(t,fG(r,c),s),fG(i,c).forEach((r,a)=>{let i=fB(a),n={name:i,title:i,description:"No description provided"},o={},{default:s,metadata:l,schema:c}=r;if("object"==typeof l&&null!==l&&Object.assign(n,l),!1===n.enabled)return;let u=function(t,r="assistant"){return async(a,i)=>{let n,o=t(a,i);if(o instanceof Promise&&(o=await o),Array.isArray(o)||null!==o&&"object"==typeof o&&"messages"in o){let t=Array.isArray(o)?{messages:o}:o,r=await ux.GetPromptResult["~standard"].validate(t);if(r.issues){let t=r.issues.map(t=>{let r=t.path?.map(t=>"object"==typeof t?t.key:t).join(".");return`${r||"result"}: ${t.message}`});throw Error(`Invalid prompt result: ${t.join("; ")}`)}return t}if("string"==typeof o||"number"==typeof o)n={type:"text",text:"number"==typeof o?`${o}`:o};else{let t=m6(o);if(t.valid)n=o;else{let r=null===o?"null":typeof o,a=void 0===o?"undefined":null===o?"null":"object"==typeof o?JSON.stringify(o,null,2):String(o);throw Error(`Prompt handler must return a PromptContent object, string, number, PromptMessage[], or GetPromptResult. Got ${r}: ${a}
155
155
 
156
156
  Validation error: ${t.error}
157
157
 
@@ -164,7 +164,7 @@ Expected formats:
164
164
  - Image content: { type: "image", data: "base64data", mimeType: "image/jpeg" }
165
165
  - Audio content: { type: "audio", data: "base64data", mimeType: "audio/mpeg" }
166
166
  - Resource link: { type: "resource_link", name: "resource name", uri: "resource://uri" }
167
- - All content types support an optional "_meta" object property`)}}if("user"!==r&&"assistant"!==r)throw Error(`Invalid role: ${r}`);return{messages:[{role:r,content:n}]}}}(s,n.role||"assistant");fF(c)?Object.assign(o,c):null!=c&&console.warn(`Invalid schema for prompt "${n.name}" at ${a}. Expected Record<string, z.ZodType>`),t.registerPrompt(n.name,{title:n.title,description:n.description,icons:n.icons,_meta:mI(n)._meta,argsSchema:fZ(o)},u)}),o=fB(n,c),u=l?.registerResource,[...mN.getAll()].forEach(([r,i])=>{let n=i.mimeType||"text/html;profile=mcp-app",o=i?._meta?fD(i._meta):void 0,s={name:i.name,description:`Auto-generated resource for ${i.name} tool`,mimeType:i.mimeType,_meta:o},l=async(t,r)=>{if(i.mimeType&&i.toolPath)try{var o;let t,r,s=(o=i.toolPath,IS_CLOUDFLARE?function(t){let{normalizedPath:r,baseName:a}=f0(t),i=5381;for(let t=0;t<r.length;t++)i=Math.imul(i,33)+r.charCodeAt(t)>>>0;let n=i.toString(16).slice(0,6).padStart(6,"0");return`${a}_${n}`}(o):function(t){let{normalizedPath:r,baseName:i}=f0(t),n=a(6982).createHash("md5").update(r).digest("hex").slice(0,6);return`${i}_${n}`}(o)),l=function(t){if(INJECTED_CLIENT_BUNDLES)return INJECTED_CLIENT_BUNDLES[t]||null;if(!IS_CLOUDFLARE)try{let r=a(9896),i=a(6928);for(let a of[i.join(process.cwd(),"dist","client"),i.join(process.cwd(),"client")]){let n=i.join(a,`${t}.bundle.js`),o=i.join(a,`${t}.bundle.css`);if(r.existsSync(n)){let t,a=r.readFileSync(n,"utf-8");return r.existsSync(o)&&(t=r.readFileSync(o,"utf-8")),{js:a,css:t}}}}catch{}return null}(s);if(!l)throw Error(`React client bundle not found for "${i.name}" (bundle: "${s}").
167
+ - All content types support an optional "_meta" object property`)}}if("user"!==r&&"assistant"!==r)throw Error(`Invalid role: ${r}`);return{messages:[{role:r,content:n}]}}}(s,n.role||"assistant");fJ(c)?Object.assign(o,c):null!=c&&console.warn(`Invalid schema for prompt "${n.name}" at ${a}. Expected Record<string, z.ZodType>`),t.registerPrompt(n.name,{title:n.title,description:n.description,icons:n.icons,_meta:mI(n)._meta,argsSchema:fU(o)},u)}),o=fG(n,c),u=l?.registerResource,[...mN.getAll()].forEach(([r,i])=>{let n=i.mimeType||"text/html;profile=mcp-app",o=i?._meta?fV(i._meta):void 0,s={name:i.name,description:`Auto-generated resource for ${i.name} tool`,mimeType:i.mimeType,_meta:o},l=async(t,r)=>{if(i.mimeType&&i.toolPath)try{var o;let t,r,s=(o=i.toolPath,IS_CLOUDFLARE?function(t){let{normalizedPath:r,baseName:a}=f2(t),i=5381;for(let t=0;t<r.length;t++)i=Math.imul(i,33)+r.charCodeAt(t)>>>0;let n=i.toString(16).slice(0,6).padStart(6,"0");return`${a}_${n}`}(o):function(t){let{normalizedPath:r,baseName:i}=f2(t),n=a(6982).createHash("md5").update(r).digest("hex").slice(0,6);return`${i}_${n}`}(o)),l=function(t){if(INJECTED_CLIENT_BUNDLES)return INJECTED_CLIENT_BUNDLES[t]||null;if(!IS_CLOUDFLARE)try{let r=a(9896),i=a(6928);for(let a of[i.join(process.cwd(),"dist","client"),i.join(process.cwd(),"client")]){let n=i.join(a,`${t}.bundle.js`),o=i.join(a,`${t}.bundle.css`);if(r.existsSync(n)){let t,a=r.readFileSync(n,"utf-8");return r.existsSync(o)&&(t=r.readFileSync(o,"utf-8")),{js:a,css:t}}}}catch{}return null}(s);if(!l)throw Error(`React client bundle not found for "${i.name}" (bundle: "${s}").
168
168
  React tool bundles are generated automatically when you run "xmcp build" (or "xmcp dev").
169
169
  Please re-run the build so the framework can regenerate the bundle.`);let c=l.js,u=l.css,d=(t=`
170
170
  <script type="module">
@@ -219,7 +219,7 @@ Please re-run the build so the framework can regenerate the bundle.`);let c=l.js
219
219
  <div id="root"></div>
220
220
  ${t}
221
221
  </body>
222
- </html>`);return{contents:[{uri:i.uri,text:d,mimeType:n,_meta:i._meta}]}}catch(t){throw console.error(`React failed for ${i.name}:`,t),t}let s=i.handler({},r);if(s instanceof Promise&&(s=await s),"string"==typeof s)return{contents:[{uri:i.uri,text:s,mimeType:n,_meta:i._meta}]};if(s&&"object"==typeof s&&"_meta"in s&&!("content"in s))return{contents:[{uri:i.uri,text:"",mimeType:n,_meta:i._meta}]};if(s&&"object"==typeof s&&"content"in s&&Array.isArray(s.content)){let t=s.content.find(t=>"text"===t.type);if(t&&"text"===t.type&&"string"==typeof t.text)return{contents:[{uri:i.uri,text:t.text,mimeType:n,_meta:i._meta}]}}return{contents:[{uri:i.uri,text:"",mimeType:n,_meta:i._meta}]}};u?.(i.name,i.uri),t.registerResource(i.name,i.uri,s,l)}),o.forEach((r,a)=>{let i={name:fH(a),description:"No description provided"},{default:n,metadata:o,schema:s,complete:l}=r;if("object"==typeof o&&null!==o&&Object.assign(i,o),!1===i.enabled)return;let c={};fF(s)?c=s:null!=s&&console.warn(`Invalid schema for resource "${i.name}" at ${a}. Expected Record<string, z.ZodType>`);let d=f1(a);if(!d)return void console.warn(`Skipping resource "${i.name}" at ${a}: Invalid file path format`);let p=d.uriTemplate;i.mimeType&&i.mimeType.includes("html")&&(p=p.endsWith(".html")?p:`${p}.html`);let m=function(t,r,a={}){let i=f1(r);if(!i)throw Error(`Invalid resource file path: ${r}. Must follow (scheme)/path/[param] convention.`);return async(r,n)=>{let o=t(function(t,r,a){let i={},n={};if(0===r.parameters.length)return n;let o=r.uriTemplate.split("://")[1]||"",s=t.split("://")[1]||"",l=o.split("/"),c=s.split("/");for(let t=0;t<l.length&&t<c.length;t++){let r=l[t],a=c[t],n=r.match(/^\{(.+)\}$/);n&&(i[n[1]]=a)}for(let t of r.parameters){let r=i[t],o=a[t];if(void 0===r)throw Error(`Missing required parameter: ${t}`);if(!o){n[t]=r;continue}try{n[t]=o.parse(r)}catch(a){throw Error(`Invalid parameter "${t}": ${r}. Validation error: ${a instanceof Error?a.message:String(a)}`)}}return n}(r.href,i,a),n);if(o instanceof Promise&&(o=await o),c0(o))return o;if("string"==typeof o)return{contents:[{uri:r.href,text:o}]};if(!o||"object"!=typeof o||!Array.isArray(o.contents)){let t=null===o?"null":typeof o,r=void 0===o?"undefined":null===o?"null":"object"==typeof o?JSON.stringify(o,null,2):String(o);throw Error(`Resource handler must return a ReadResourceResult, InputRequiredResult, or string. Got ${t}: ${r}
222
+ </html>`);return{contents:[{uri:i.uri,text:d,mimeType:n,_meta:i._meta}]}}catch(t){throw console.error(`React failed for ${i.name}:`,t),t}let s=i.handler({},r);if(s instanceof Promise&&(s=await s),"string"==typeof s)return{contents:[{uri:i.uri,text:s,mimeType:n,_meta:i._meta}]};if(s&&"object"==typeof s&&"_meta"in s&&!("content"in s))return{contents:[{uri:i.uri,text:"",mimeType:n,_meta:i._meta}]};if(s&&"object"==typeof s&&"content"in s&&Array.isArray(s.content)){let t=s.content.find(t=>"text"===t.type);if(t&&"text"===t.type&&"string"==typeof t.text)return{contents:[{uri:i.uri,text:t.text,mimeType:n,_meta:i._meta}]}}return{contents:[{uri:i.uri,text:"",mimeType:n,_meta:i._meta}]}};u?.(i.name,i.uri),t.registerResource(i.name,i.uri,s,l)}),o.forEach((r,a)=>{let i={name:fB(a),description:"No description provided"},{default:n,metadata:o,schema:s,complete:l}=r;if("object"==typeof o&&null!==o&&Object.assign(i,o),!1===i.enabled)return;let c={};fJ(s)?c=s:null!=s&&console.warn(`Invalid schema for resource "${i.name}" at ${a}. Expected Record<string, z.ZodType>`);let d=f9(a);if(!d)return void console.warn(`Skipping resource "${i.name}" at ${a}: Invalid file path format`);let p=d.uriTemplate;i.mimeType&&i.mimeType.includes("html")&&(p=p.endsWith(".html")?p:`${p}.html`);let m=function(t,r,a={}){let i=f9(r);if(!i)throw Error(`Invalid resource file path: ${r}. Must follow (scheme)/path/[param] convention.`);return async(r,n)=>{let o=t(function(t,r,a){let i={},n={};if(0===r.parameters.length)return n;let o=r.uriTemplate.split("://")[1]||"",s=t.split("://")[1]||"",l=o.split("/"),c=s.split("/");for(let t=0;t<l.length&&t<c.length;t++){let r=l[t],a=c[t],n=r.match(/^\{(.+)\}$/);n&&(i[n[1]]=a)}for(let t of r.parameters){let r=i[t],o=a[t];if(void 0===r)throw Error(`Missing required parameter: ${t}`);if(!o){n[t]=r;continue}try{n[t]=o.parse(r)}catch(a){throw Error(`Invalid parameter "${t}": ${r}. Validation error: ${a instanceof Error?a.message:String(a)}`)}}return n}(r.href,i,a),n);if(o instanceof Promise&&(o=await o),c0(o))return o;if("string"==typeof o)return{contents:[{uri:r.href,text:o}]};if(!o||"object"!=typeof o||!Array.isArray(o.contents)){let t=null===o?"null":typeof o,r=void 0===o?"undefined":null===o?"null":"object"==typeof o?JSON.stringify(o,null,2):String(o);throw Error(`Resource handler must return a ReadResourceResult, InputRequiredResult, or string. Got ${t}: ${r}
223
223
 
224
224
  Expected ReadResourceResult format:
225
225
  {
@@ -228,10 +228,10 @@ Expected ReadResourceResult format:
228
228
  { uri: "resource://uri", mimeType: "application/json", text: "json content" },
229
229
  { uri: "resource://uri", blob: base64data }
230
230
  ]
231
- }`)}return o.contents.forEach(t=>{t.uri||(t.uri=r.href)}),o}}(n,a,c);if("direct"===d.type)u?.(i.name,p),t.registerResource(i.name,p,mI(i),m);else{let r=Object.create(null);for(let t of d.parameters)l&&Object.hasOwn(l,t)&&(r[t]=l[t]);let a=new pV(p,{list:void 0,complete:r}),o=async(t,r,a)=>{let i={};for(let t of d.parameters){let a=r[t],n=c[t];if(void 0===a)throw Error(`Missing required parameter: ${t}. Available variables: ${Object.keys(r)}`);n?i[t]=n.parse(a):i[t]=a}let o=n(i,a);return o instanceof Promise&&(o=await o),"string"==typeof o?{contents:[{uri:t.href,text:o}]}:o};u?.(i.name,a),t.registerResource(i.name,a,mI(i),o)}})}),t}async function ye(){let{toolModules:t,skippedTools:r}=await f9(f3);return f4(r),t}async function yt(){let{promptModules:t,skippedPrompts:r}=await fG(f6);return fW(r),t}async function yr(){let{resourceModules:t,skippedResources:r}=await fX(f5);return fQ(r),t}let ya=HTTP_CONFIG,yi=HTTP_CORS_CONFIG,yn=(C=function(t,r={}){var a;let{legacy:i,onerror:n,responseMode:o}=r,s=p1(r.maxRequestBodySize);if("function"==typeof i)throw TypeError("The 'legacy' option only accepts 'stateless' or 'reject', not a handler function. To serve 2025-era traffic with your own handler, route in user land with the exported isLegacyRequest(request) predicate in front of a strict (legacy: 'reject') handler.");let l=new Set,c=!1,h=t=>{try{n?.(t)}catch{}},f=r.bus??new pT(h),y={toolsChanged:()=>f.publish({kind:"tools_list_changed"}),promptsChanged:()=>f.publish({kind:"prompts_list_changed"}),resourcesChanged:()=>f.publish({kind:"resources_list_changed"}),resourceUpdated:t=>f.publish({kind:"resource_updated",uri:t})},g=function(t){let{bus:r,onerror:a}=t,i=t.maxSubscriptions??1024,n=t.keepAliveMs??15e3,o=new Set;return{serve:function(t,s,l,c){var u,d,p;let m,h,f,y,g,v,_;if(o.size>=i)return a?.(Error(`subscriptions/listen refused: subscription limit reached (${i})`)),pj(t.id,-32603,"Subscription limit reached");let b=(u=t,(g=cz(cM).validateRequest("subscriptions/listen",u)).ok?g.value.params?.notifications:void 0);if(void 0===b)return pj(t.id,-32602,"Invalid params: 'notifications' is required and must be a valid SubscriptionFilter");let S=(d=b,p=l,v={},_=t=>void 0===p||!0===t,!0===d.toolsListChanged&&_(p?.tools?.listChanged)&&(v.toolsListChanged=!0),!0===d.promptsListChanged&&_(p?.prompts?.listChanged)&&(v.promptsListChanged=!0),!0===d.resourcesListChanged&&_(p?.resources?.listChanged)&&(v.resourcesListChanged=!0),void 0!==d.resourceSubscriptions&&d.resourceSubscriptions.length>0&&_(p?.resources?.subscribe)&&(v.resourceSubscriptions=[...d.resourceSubscriptions]),v),$=t.id,w=new TextEncoder,R=!1,k=t=>{if(!R)try{m.enqueue(w.encode(t))}catch(t){a?.(t instanceof Error?t:Error(String(t)))}},x=(t,r)=>{k(`event: message
231
+ }`)}return o.contents.forEach(t=>{t.uri||(t.uri=r.href)}),o}}(n,a,c);if("direct"===d.type)u?.(i.name,p),t.registerResource(i.name,p,mI(i),m);else{let r=Object.create(null);for(let t of d.parameters)l&&Object.hasOwn(l,t)&&(r[t]=l[t]);let a=new pV(p,{list:void 0,complete:r}),o=async(t,r,a)=>{let i={};for(let t of d.parameters){let a=r[t],n=c[t];if(void 0===a)throw Error(`Missing required parameter: ${t}. Available variables: ${Object.keys(r)}`);n?i[t]=n.parse(a):i[t]=a}let o=n(i,a);return o instanceof Promise&&(o=await o),"string"==typeof o?{contents:[{uri:t.href,text:o}]}:o};u?.(i.name,a),t.registerResource(i.name,a,mI(i),o)}}),function(t,r,a,i){let n=[...fG(new Map(r.map(t=>[t.uri,{metadata:{name:t.frontmatter.name},skill:t}])),a).values()].map(({skill:t})=>t);if(0===n.length)return;for(let{frontmatter:r,files:a}of n){let n=a[0].uri.slice(0,a[0].uri.lastIndexOf("/")+1);a.forEach(({uri:a,mimeType:o,text:s,blob:l},c)=>{let u=0===c?{mimeType:o,description:r.description}:{mimeType:o},d=0===c?r.name:`${r.name}/${decodeURIComponent(a.slice(n.length))}`,p=void 0!==s?{uri:a,mimeType:o,text:s}:{uri:a,mimeType:o,blob:l??""};i?.(d,a),t.registerResource(d,a,u,()=>({contents:[p]}))})}let o=n.map(f5),s=new Map(o.map(t=>[t.uri,t]));t.server.registerCapabilities({extensions:{"io.modelcontextprotocol/skills":{}}}),t.server.setRequestHandler("skills/list",{params:f3},t=>{let r=t?.cursor===void 0?0:function(t,r){let a=NaN;try{a=Number(atob(t))}catch{}if(!Number.isSafeInteger(a)||a<=0||a>=r)throw new cv(cg.InvalidParams,`Invalid cursor: ${t}`);return a}(t.cursor,o.length),a=r+50;return{skills:o.slice(r,a),...a<o.length?{nextCursor:btoa(String(a))}:{},...f4}}),t.server.setRequestHandler("skills/get",{params:f6},({uri:t})=>{let r=s.get(t);if(!r)throw new cv(cg.InvalidParams,`No skill is served at ${t}`);return{skill:r,...f4}})}(t,yi,c,l?.registerResource)}),t}async function ys(){let{toolModules:t,skippedTools:r}=await f7(yt);return ye(r),t}async function yl(){let{promptModules:t,skippedPrompts:r}=await fY(yr);return fX(r),t}async function yc(){let{resourceModules:t,skippedResources:r}=await f0(ya);return f1(r),t}let yu=HTTP_CONFIG,yd=HTTP_CORS_CONFIG,yp=(C=function(t,r={}){var a;let{legacy:i,onerror:n,responseMode:o}=r,s=p1(r.maxRequestBodySize);if("function"==typeof i)throw TypeError("The 'legacy' option only accepts 'stateless' or 'reject', not a handler function. To serve 2025-era traffic with your own handler, route in user land with the exported isLegacyRequest(request) predicate in front of a strict (legacy: 'reject') handler.");let l=new Set,c=!1,h=t=>{try{n?.(t)}catch{}},f=r.bus??new pT(h),y={toolsChanged:()=>f.publish({kind:"tools_list_changed"}),promptsChanged:()=>f.publish({kind:"prompts_list_changed"}),resourcesChanged:()=>f.publish({kind:"resources_list_changed"}),resourceUpdated:t=>f.publish({kind:"resource_updated",uri:t})},g=function(t){let{bus:r,onerror:a}=t,i=t.maxSubscriptions??1024,n=t.keepAliveMs??15e3,o=new Set;return{serve:function(t,s,l,c){var u,d,p;let m,h,f,y,g,v,_;if(o.size>=i)return a?.(Error(`subscriptions/listen refused: subscription limit reached (${i})`)),pj(t.id,-32603,"Subscription limit reached");let b=(u=t,(g=cz(cM).validateRequest("subscriptions/listen",u)).ok?g.value.params?.notifications:void 0);if(void 0===b)return pj(t.id,-32602,"Invalid params: 'notifications' is required and must be a valid SubscriptionFilter");let S=(d=b,p=l,v={},_=t=>void 0===p||!0===t,!0===d.toolsListChanged&&_(p?.tools?.listChanged)&&(v.toolsListChanged=!0),!0===d.promptsListChanged&&_(p?.prompts?.listChanged)&&(v.promptsListChanged=!0),!0===d.resourcesListChanged&&_(p?.resources?.listChanged)&&(v.resourcesListChanged=!0),void 0!==d.resourceSubscriptions&&d.resourceSubscriptions.length>0&&_(p?.resources?.subscribe)&&(v.resourceSubscriptions=[...d.resourceSubscriptions]),v),$=t.id,w=new TextEncoder,R=!1,k=t=>{if(!R)try{m.enqueue(w.encode(t))}catch(t){a?.(t instanceof Error?t:Error(String(t)))}},x=(t,r)=>{k(`event: message
232
232
  data: ${JSON.stringify({jsonrpc:"2.0",method:t,params:r})}
233
233
 
234
234
  `)},P=t=>{if(!R){t&&k(`event: message
235
235
  data: ${JSON.stringify({jsonrpc:"2.0",id:$,result:{resultType:"complete",_meta:{[nX]:$,[nW]:c}}})}
236
236
 
237
- `),R=!0;try{h?.()}catch(t){a?.(t instanceof Error?t:Error(String(t)))}void 0!==f&&clearInterval(f),y?.(),o.delete(P);try{m.close()}catch{}}},E=new ReadableStream({start(t){m=t;let a=pO({method:"notifications/subscriptions/acknowledged",params:{notifications:S}},$);(x(a.method,a.params),0===Object.keys(S).length)?P(!0):(h=r.subscribe(t=>{if(R||!function(t,r){switch(r.kind){case"tools_list_changed":return!0===t.toolsListChanged;case"prompts_list_changed":return!0===t.promptsListChanged;case"resources_list_changed":return!0===t.resourcesListChanged;case"resource_updated":return void 0!==t.resourceSubscriptions&&t.resourceSubscriptions.includes(r.uri)}}(S,t))return;let r=pO(function(t){switch(t.kind){case"tools_list_changed":return{method:"notifications/tools/list_changed"};case"prompts_list_changed":return{method:"notifications/prompts/list_changed"};case"resources_list_changed":return{method:"notifications/resources/list_changed"};case"resource_updated":return{method:"notifications/resources/updated",params:{uri:t.uri}}}}(t),$);x(r.method,r.params)}),f=pE(n,()=>k(": keepalive\n\n")),o.add(P))},cancel(){P(!1)}});if(void 0!==s)if(s.aborted)P(!1);else{let t=()=>P(!1);s.addEventListener("abort",t,{once:!0}),y=()=>s.removeEventListener("abort",t)}return new Response(E,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"}})},closeAll(){for(let t of o)t(!0)},get openCount(){return o.size}}}({bus:f,maxSubscriptions:r.maxSubscriptions??1024,keepAliveMs:r.keepAliveMs??15e3,onerror:h});"json"===o&&console.warn("responseMode: 'json' drops mid-call notifications. subscriptions/listen streams are always served over SSE regardless; other notifications emitted before a result are dropped.");let v="reject"===i?void 0:(a=r.keepAliveMs,async(r,i)=>{if("POST"!==r.method.toUpperCase())return p3(405,-32e3,"Method not allowed.");try{let n=await t({era:"legacy",...i?.authInfo!==void 0&&{authInfo:i.authInfo},requestInfo:r}),o=new p9({sessionIdGenerator:void 0,...void 0!==a&&{keepAliveMs:a},...void 0!==s&&{maxRequestBodySize:s}});await n.connect(o);let l=()=>{o.close().catch(()=>{}),n.close().catch(()=>{})};r.signal?.addEventListener("abort",l,{once:!0});let c=await o.handleRequest(r,{...i?.authInfo!==void 0&&{authInfo:i.authInfo},...i?.parsedBody!==void 0&&{parsedBody:i.parsedBody}});if(null===c.body||"text/event-stream"!==uM(c.headers.get("content-type")))return l(),c;let u=c.body.getReader(),d=!1,p=()=>{d||(d=!0,l())},m=new ReadableStream({pull:async t=>{try{let{done:r,value:a}=await u.read();if(r){p(),t.close();return}void 0!==a&&t.enqueue(a)}catch(r){p(),t.error(r)}},cancel:t=>(p(),u.cancel(t).catch(()=>{}))});return new Response(m,{status:c.status,statusText:c.statusText,headers:c.headers})}catch(t){try{h?.(p5(t))}catch{}return p8(p4(i?.parsedBody))}});async function _(a,i,n){var s,c;let f=a.classification.revision;if(void 0===f||!lQ.includes(f)){let t=new cS({supported:[...lQ],requested:f??"unknown"});return h(t),p3(400,t.code,t.message,t.data,p4(a.message))}let y=function(t,r){if("request"!==r.messageKind)return;let a=r.message.method;if(void 0===t.protocolVersionHeader){let t=r.classification.revision;return un("version-header-missing","(missing)",void 0===t?"the body carries a modern per-request envelope but the required MCP-Protocol-Version header is absent":`the body envelope names protocol version ${t} but the required MCP-Protocol-Version header is absent`,"standard-header-validation")}if(void 0===t.mcpMethodHeader)return un("method-header-missing","(missing)",`the body names method ${a} but the required Mcp-Method header is absent`,"standard-header-validation");let i=function(t,r){let a=Object.hasOwn(uo,t)?uo[t]:void 0;if(void 0===a)return;let i=ul(r)?r[a]:void 0;return{field:a,value:"string"==typeof i?i:void 0}}(a,r.message.params);if(void 0===i)return;let{field:n,value:o}=i;if(void 0===t.mcpNameHeader){if(void 0===o)return;return un("name-header-missing","(missing)",`the body carries params.${n}="${o}" but the required Mcp-Name header is absent`,"standard-header-validation")}let s=us(t.mcpNameHeader),l=ue(s);return void 0===l?un("name-header-invalid-encoding",s,"the Mcp-Name header carries an invalid Base64 sentinel value","standard-header-validation"):void 0!==o&&l!==o?un("name-header-mismatch",s,`the body carries params.${n}="${o}" but the Mcp-Name header names "${l}"`,"standard-header-validation"):void 0}({httpMethod:i.method,...me(i)},a);if(void 0!==y)return h(Error(`Rejected inbound request (${y.cell}): ${y.message}`)),p6(y,p4(a.message));let v="request"===a.messageKind?cH(a.message.params):void 0,_=v?.[nY];if("request"===a.messageKind){let t=Object.hasOwn(lG,s=a.message.method)?lG[s]:void 0;if(void 0!==t){let r=lY(t,_);if(void 0!==r){let t=new c$({requiredCapabilities:r});return h(t),p3(ua[t.code]??400,t.code,t.message,t.data,a.message.id)}}}let b=await t({era:"modern",...void 0!==n&&{authInfo:n},requestInfo:i}),S=b instanceof pU?b.server:b;if(p7(S),"request"===a.messageKind&&"subscriptions/listen"===a.message.method){let t=S.getCapabilities(),r=m(S);return b.close().catch(h),g.serve(a.message,i.signal,t,r)}if("request"===a.messageKind&&"tools/call"===a.message.method&&b instanceof pU){let t=a.message.params,r="string"==typeof t?.name?t.name:void 0,n=void 0===r?void 0:b.toolInputSchemaJson(r);if(void 0!==n){let r=c4(n);if(r.valid&&r.declarations.length>0){let n=function(t,r,a){for(let i of t){let t=`Mcp-Param-${i.headerName}`,n=a.get(t),o=function(t,r){let a=t;for(let t of r){if(null===a||"object"!=typeof a)return;a=a[t]}return a}(r,i.path);if(null==o)continue;let s=function(t){if("string"==typeof t)return t;if("boolean"==typeof t)return t?"true":"false";if("number"==typeof t){if(!Number.isFinite(t)||Number.isInteger(t)&&!Number.isSafeInteger(t))return;return String(t)}}(o);if(void 0===s)continue;if(null===n)return ut("param-header-missing",t,`the body carries ${c5(i.path)}=${JSON.stringify(o)} but the ${t} header is absent`);let l=ue(n);if(void 0===l)return ut("param-header-invalid-encoding",t,`the ${t} header carries an invalid Base64 sentinel value`);if(!(("integer"===i.type||"number"===i.type)&&c7.test(l)&&"number"==typeof o?Number(l)===o:l===s))return ut("param-header-mismatch",t,`the ${t} header decodes to ${JSON.stringify(l)} but the body carries ${c5(i.path)}=${JSON.stringify(o)}`)}}(r.declarations,t?.arguments,i.headers);if(void 0!==n)return b.close().catch(h),h(Error(`Rejected inbound request (${n.cell}): ${n.message}`)),p6(n,a.message.id)}}}if("request"===a.messageKind&&b instanceof pU)try{let t=await pN([a.message],n,t=>b.resolveScopeChallenge(t));if(void 0!==t)return b.close().catch(h),pA(t,pq(n))}catch(t){return b.close().catch(h),h(p5(t)),p8(a.message.id)}p7(S),u(S,f),p(S,lQ),void 0!==v&&(c={clientInfo:v[nG],clientCapabilities:_},d(S,c));let $=S.onclose;l.add(S);let w=()=>{l.delete(S),S.onclose===w&&(S.onclose=$),$?.()};S.onclose=w;try{let t=await pQ(b,a.message,{classification:a.classification,request:i,...void 0!==n&&{authInfo:n},...void 0!==o&&{responseMode:o},...void 0!==r.keepAliveMs&&{keepAliveMs:r.keepAliveMs}});return"notification"===a.messageKind&&queueMicrotask(()=>void S.close().catch(()=>{})),t}catch(t){if(t instanceof lK&&t.code===lB.ConnectionClosed)return new Response(null,{status:499});return await S.close().catch(()=>{}),l.delete(S),h(p5(t)),p8(p4(a.message))}}async function b(t,r,a,i){if(void 0!==v)return v(r,{...void 0!==a&&{authInfo:a},...void 0!==i&&{parsedBody:i}});let n=function(t,r){switch(t.reason){case"http-method":return ui("http-method","modern-only-method-not-allowed",405,new cv(-32e3,"Method not allowed."),!0);case"batch":return ui("jsonrpc-shape","modern-only-batch-not-supported",400,new cv(cg.InvalidRequest,"Bad Request: JSON-RPC batches are not supported by this endpoint"),!0);case"response":return ui("jsonrpc-shape","modern-only-response-post",400,new cv(cg.InvalidRequest,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"),!0);case"notification":return;case"initialize":case"no-claim":{let a=t.requestedVersion;return ui("era-classification","modern-only-missing-envelope",400,void 0===a?new cv(cg.UnsupportedProtocolVersion,"Unsupported protocol version: the request did not name a protocol version",{supported:[...r]}):new cS({supported:[...r],requested:a}),!0)}}}(t,lQ);return void 0===n?new Response(null,{status:202}):(h(Error(`Rejected 2025-era request on a modern-only endpoint (${n.cell}): ${n.message}`)),p6(n,p4(i)))}async function S(t,r){let a=r?.authInfo;if("POST"===t.method.toUpperCase()&&!uz(t.headers.get("content-type")))return h(Error("Unsupported Media Type: Content-Type must be application/json")),p3(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");let i=await mt(t,r?.parsedBody,!0,s);if("unreadable-body"===i.step)return p3(400,-32700,"Parse error: the request body could not be read");if("body-too-large"===i.step)return p3(413,-32e3,p0(s));if("no-json-body"===i.step)return void 0!==v?v(i.forwardRequest,{...void 0!==a&&{authInfo:a}}):p3(400,-32700,"Parse error: the request body is not valid JSON");let{outcome:n,body:o,parsedBody:l,forwardRequest:c}=i;try{switch(n.kind){case"reject":return h(Error(`Rejected inbound request (${n.cell}): ${n.message}`)),p6(n,p4(o));case"modern":return await _(n,t,a);case"legacy":return await b(n,c,a,l)}}catch(t){return h(p5(t)),p8(p4(o))}}return{fetch:async(t,r)=>{if(c)throw Error("This MCP handler has been closed");try{return await S(t,r)}catch(t){return h(p5(t)),p8(p4(r?.parsedBody))}},notify:y,bus:f,close:async()=>{c=!0,g.closeAll();let t=[...l].map(t=>t.close().catch(()=>{}));l.clear(),await Promise.all(t)}}}(async function(){let{instructions:t,...r}=f8,a=new pU(r,{instructions:t}),i=ye(),n=yt(),o=yr(),[s,l,c]=await Promise.all([i,n,o]);return f7(a,s,l,c)},{legacy:"stateless",maxSubscriptions:ya.maxSubscriptions,onerror:ya.debug?t=>console.error("[HTTP-server] MCP handler error:",t):void 0}),I={onerror:t=>console.error("[HTTP-server] Error handling MCP request:",t)},async(t,r,a)=>{let i,n;"function"==typeof a&&(a=void 0);let o=!1,s=new AbortController;r.on("close",()=>{o||s.abort()}),!0===r.destroyed&&s.abort();try{let r=await mS(t,a,{signal:s.signal});i=await C.fetch(r,{...void 0!==t.auth&&{authInfo:t.auth},...void 0!==a&&{parsedBody:a}})}catch(t){var l;try{I?.onerror?.(t instanceof Error?t:Error(String(t)))}catch{}l=function(t){if(null===t||"object"!=typeof t||Array.isArray(t))return null;let{method:r,id:a}=t;return"string"!=typeof r?null:"string"==typeof a||"number"==typeof a?a:null}(a),i=Response.json({jsonrpc:"2.0",error:{code:-32603,message:"Internal server error"},id:l},{status:500})}let c={};for(let[t,r]of i.headers)c[t]=r;if(r.writeHead(i.status,c),null===i.body){o=!0,r.end();return}r.on("drain",()=>{n?.(),n=void 0});let u=new Promise(t=>{s.signal.addEventListener("abort",()=>t(),{once:!0})});try{for await(let t of i.body){if(s.signal.aborted)break;!1===r.write(t)&&await Promise.race([new Promise(t=>{n=t}),u])}}catch{}o=!0,r.end()});async function yo(t,r){let a=(0,R.randomUUID)(),i=(t=>{for(let r of Array.isArray(t)?t:[t]){let t=mO(r);if(t)return t}})(t.body);await mE({id:a,headers:t.headers,clientInfo:i},async()=>{for(let[a,i]of Object.entries(function(t,r){let a={};if(void 0!==t.origin){if(!0===t.origin)r&&(a["Access-Control-Allow-Origin"]=r);else if(!1!==t.origin)if(Array.isArray(t.origin)){let i=r&&t.origin.includes(r)?r:t.origin[0]||"*";a["Access-Control-Allow-Origin"]=i}else a["Access-Control-Allow-Origin"]=String(t.origin)}return void 0!==t.methods&&(a["Access-Control-Allow-Methods"]=Array.isArray(t.methods)?t.methods.join(","):String(t.methods)),void 0!==t.allowedHeaders&&(a["Access-Control-Allow-Headers"]=Array.isArray(t.allowedHeaders)?t.allowedHeaders.join(","):String(t.allowedHeaders)),void 0!==t.exposedHeaders&&(a["Access-Control-Expose-Headers"]=Array.isArray(t.exposedHeaders)?t.exposedHeaders.join(","):String(t.exposedHeaders)),"boolean"==typeof t.credentials&&(a["Access-Control-Allow-Credentials"]=String(t.credentials)),"number"==typeof t.maxAge&&(a["Access-Control-Max-Age"]=String(t.maxAge)),a}(yi,t.headers.origin)))r.setHeader(a,i);await yn(t,r,t.body)})}})(),i})());
237
+ `),R=!0;try{h?.()}catch(t){a?.(t instanceof Error?t:Error(String(t)))}void 0!==f&&clearInterval(f),y?.(),o.delete(P);try{m.close()}catch{}}},E=new ReadableStream({start(t){m=t;let a=pO({method:"notifications/subscriptions/acknowledged",params:{notifications:S}},$);(x(a.method,a.params),0===Object.keys(S).length)?P(!0):(h=r.subscribe(t=>{if(R||!function(t,r){switch(r.kind){case"tools_list_changed":return!0===t.toolsListChanged;case"prompts_list_changed":return!0===t.promptsListChanged;case"resources_list_changed":return!0===t.resourcesListChanged;case"resource_updated":return void 0!==t.resourceSubscriptions&&t.resourceSubscriptions.includes(r.uri)}}(S,t))return;let r=pO(function(t){switch(t.kind){case"tools_list_changed":return{method:"notifications/tools/list_changed"};case"prompts_list_changed":return{method:"notifications/prompts/list_changed"};case"resources_list_changed":return{method:"notifications/resources/list_changed"};case"resource_updated":return{method:"notifications/resources/updated",params:{uri:t.uri}}}}(t),$);x(r.method,r.params)}),f=pE(n,()=>k(": keepalive\n\n")),o.add(P))},cancel(){P(!1)}});if(void 0!==s)if(s.aborted)P(!1);else{let t=()=>P(!1);s.addEventListener("abort",t,{once:!0}),y=()=>s.removeEventListener("abort",t)}return new Response(E,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"}})},closeAll(){for(let t of o)t(!0)},get openCount(){return o.size}}}({bus:f,maxSubscriptions:r.maxSubscriptions??1024,keepAliveMs:r.keepAliveMs??15e3,onerror:h});"json"===o&&console.warn("responseMode: 'json' drops mid-call notifications. subscriptions/listen streams are always served over SSE regardless; other notifications emitted before a result are dropped.");let v="reject"===i?void 0:(a=r.keepAliveMs,async(r,i)=>{if("POST"!==r.method.toUpperCase())return p3(405,-32e3,"Method not allowed.");try{let n=await t({era:"legacy",...i?.authInfo!==void 0&&{authInfo:i.authInfo},requestInfo:r}),o=new p9({sessionIdGenerator:void 0,...void 0!==a&&{keepAliveMs:a},...void 0!==s&&{maxRequestBodySize:s}});await n.connect(o);let l=()=>{o.close().catch(()=>{}),n.close().catch(()=>{})};r.signal?.addEventListener("abort",l,{once:!0});let c=await o.handleRequest(r,{...i?.authInfo!==void 0&&{authInfo:i.authInfo},...i?.parsedBody!==void 0&&{parsedBody:i.parsedBody}});if(null===c.body||"text/event-stream"!==uM(c.headers.get("content-type")))return l(),c;let u=c.body.getReader(),d=!1,p=()=>{d||(d=!0,l())},m=new ReadableStream({pull:async t=>{try{let{done:r,value:a}=await u.read();if(r){p(),t.close();return}void 0!==a&&t.enqueue(a)}catch(r){p(),t.error(r)}},cancel:t=>(p(),u.cancel(t).catch(()=>{}))});return new Response(m,{status:c.status,statusText:c.statusText,headers:c.headers})}catch(t){try{h?.(p5(t))}catch{}return p8(p4(i?.parsedBody))}});async function _(a,i,n){var s,c;let f=a.classification.revision;if(void 0===f||!lQ.includes(f)){let t=new cS({supported:[...lQ],requested:f??"unknown"});return h(t),p3(400,t.code,t.message,t.data,p4(a.message))}let y=function(t,r){if("request"!==r.messageKind)return;let a=r.message.method;if(void 0===t.protocolVersionHeader){let t=r.classification.revision;return un("version-header-missing","(missing)",void 0===t?"the body carries a modern per-request envelope but the required MCP-Protocol-Version header is absent":`the body envelope names protocol version ${t} but the required MCP-Protocol-Version header is absent`,"standard-header-validation")}if(void 0===t.mcpMethodHeader)return un("method-header-missing","(missing)",`the body names method ${a} but the required Mcp-Method header is absent`,"standard-header-validation");let i=function(t,r){let a=Object.hasOwn(uo,t)?uo[t]:void 0;if(void 0===a)return;let i=ul(r)?r[a]:void 0;return{field:a,value:"string"==typeof i?i:void 0}}(a,r.message.params);if(void 0===i)return;let{field:n,value:o}=i;if(void 0===t.mcpNameHeader){if(void 0===o)return;return un("name-header-missing","(missing)",`the body carries params.${n}="${o}" but the required Mcp-Name header is absent`,"standard-header-validation")}let s=us(t.mcpNameHeader),l=ue(s);return void 0===l?un("name-header-invalid-encoding",s,"the Mcp-Name header carries an invalid Base64 sentinel value","standard-header-validation"):void 0!==o&&l!==o?un("name-header-mismatch",s,`the body carries params.${n}="${o}" but the Mcp-Name header names "${l}"`,"standard-header-validation"):void 0}({httpMethod:i.method,...me(i)},a);if(void 0!==y)return h(Error(`Rejected inbound request (${y.cell}): ${y.message}`)),p6(y,p4(a.message));let v="request"===a.messageKind?cH(a.message.params):void 0,_=v?.[nY];if("request"===a.messageKind){let t=Object.hasOwn(lG,s=a.message.method)?lG[s]:void 0;if(void 0!==t){let r=lY(t,_);if(void 0!==r){let t=new c$({requiredCapabilities:r});return h(t),p3(ua[t.code]??400,t.code,t.message,t.data,a.message.id)}}}let b=await t({era:"modern",...void 0!==n&&{authInfo:n},requestInfo:i}),S=b instanceof pU?b.server:b;if(p7(S),"request"===a.messageKind&&"subscriptions/listen"===a.message.method){let t=S.getCapabilities(),r=m(S);return b.close().catch(h),g.serve(a.message,i.signal,t,r)}if("request"===a.messageKind&&"tools/call"===a.message.method&&b instanceof pU){let t=a.message.params,r="string"==typeof t?.name?t.name:void 0,n=void 0===r?void 0:b.toolInputSchemaJson(r);if(void 0!==n){let r=c4(n);if(r.valid&&r.declarations.length>0){let n=function(t,r,a){for(let i of t){let t=`Mcp-Param-${i.headerName}`,n=a.get(t),o=function(t,r){let a=t;for(let t of r){if(null===a||"object"!=typeof a)return;a=a[t]}return a}(r,i.path);if(null==o)continue;let s=function(t){if("string"==typeof t)return t;if("boolean"==typeof t)return t?"true":"false";if("number"==typeof t){if(!Number.isFinite(t)||Number.isInteger(t)&&!Number.isSafeInteger(t))return;return String(t)}}(o);if(void 0===s)continue;if(null===n)return ut("param-header-missing",t,`the body carries ${c5(i.path)}=${JSON.stringify(o)} but the ${t} header is absent`);let l=ue(n);if(void 0===l)return ut("param-header-invalid-encoding",t,`the ${t} header carries an invalid Base64 sentinel value`);if(!(("integer"===i.type||"number"===i.type)&&c7.test(l)&&"number"==typeof o?Number(l)===o:l===s))return ut("param-header-mismatch",t,`the ${t} header decodes to ${JSON.stringify(l)} but the body carries ${c5(i.path)}=${JSON.stringify(o)}`)}}(r.declarations,t?.arguments,i.headers);if(void 0!==n)return b.close().catch(h),h(Error(`Rejected inbound request (${n.cell}): ${n.message}`)),p6(n,a.message.id)}}}if("request"===a.messageKind&&b instanceof pU)try{let t=await pN([a.message],n,t=>b.resolveScopeChallenge(t));if(void 0!==t)return b.close().catch(h),pA(t,pq(n))}catch(t){return b.close().catch(h),h(p5(t)),p8(a.message.id)}p7(S),u(S,f),p(S,lQ),void 0!==v&&(c={clientInfo:v[nG],clientCapabilities:_},d(S,c));let $=S.onclose;l.add(S);let w=()=>{l.delete(S),S.onclose===w&&(S.onclose=$),$?.()};S.onclose=w;try{let t=await pQ(b,a.message,{classification:a.classification,request:i,...void 0!==n&&{authInfo:n},...void 0!==o&&{responseMode:o},...void 0!==r.keepAliveMs&&{keepAliveMs:r.keepAliveMs}});return"notification"===a.messageKind&&queueMicrotask(()=>void S.close().catch(()=>{})),t}catch(t){if(t instanceof lK&&t.code===lB.ConnectionClosed)return new Response(null,{status:499});return await S.close().catch(()=>{}),l.delete(S),h(p5(t)),p8(p4(a.message))}}async function b(t,r,a,i){if(void 0!==v)return v(r,{...void 0!==a&&{authInfo:a},...void 0!==i&&{parsedBody:i}});let n=function(t,r){switch(t.reason){case"http-method":return ui("http-method","modern-only-method-not-allowed",405,new cv(-32e3,"Method not allowed."),!0);case"batch":return ui("jsonrpc-shape","modern-only-batch-not-supported",400,new cv(cg.InvalidRequest,"Bad Request: JSON-RPC batches are not supported by this endpoint"),!0);case"response":return ui("jsonrpc-shape","modern-only-response-post",400,new cv(cg.InvalidRequest,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"),!0);case"notification":return;case"initialize":case"no-claim":{let a=t.requestedVersion;return ui("era-classification","modern-only-missing-envelope",400,void 0===a?new cv(cg.UnsupportedProtocolVersion,"Unsupported protocol version: the request did not name a protocol version",{supported:[...r]}):new cS({supported:[...r],requested:a}),!0)}}}(t,lQ);return void 0===n?new Response(null,{status:202}):(h(Error(`Rejected 2025-era request on a modern-only endpoint (${n.cell}): ${n.message}`)),p6(n,p4(i)))}async function S(t,r){let a=r?.authInfo;if("POST"===t.method.toUpperCase()&&!uz(t.headers.get("content-type")))return h(Error("Unsupported Media Type: Content-Type must be application/json")),p3(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");let i=await mt(t,r?.parsedBody,!0,s);if("unreadable-body"===i.step)return p3(400,-32700,"Parse error: the request body could not be read");if("body-too-large"===i.step)return p3(413,-32e3,p0(s));if("no-json-body"===i.step)return void 0!==v?v(i.forwardRequest,{...void 0!==a&&{authInfo:a}}):p3(400,-32700,"Parse error: the request body is not valid JSON");let{outcome:n,body:o,parsedBody:l,forwardRequest:c}=i;try{switch(n.kind){case"reject":return h(Error(`Rejected inbound request (${n.cell}): ${n.message}`)),p6(n,p4(o));case"modern":return await _(n,t,a);case"legacy":return await b(n,c,a,l)}}catch(t){return h(p5(t)),p8(p4(o))}}return{fetch:async(t,r)=>{if(c)throw Error("This MCP handler has been closed");try{return await S(t,r)}catch(t){return h(p5(t)),p8(p4(r?.parsedBody))}},notify:y,bus:f,close:async()=>{c=!0,g.closeAll();let t=[...l].map(t=>t.close().catch(()=>{}));l.clear(),await Promise.all(t)}}}(async function(){let{instructions:t,...r}=yn,a=new pU(r,{instructions:t}),i=ys(),n=yl(),o=yc(),[s,l,c]=await Promise.all([i,n,o]);return yo(a,s,l,c)},{legacy:"stateless",maxSubscriptions:yu.maxSubscriptions,onerror:yu.debug?t=>console.error("[HTTP-server] MCP handler error:",t):void 0}),I={onerror:t=>console.error("[HTTP-server] Error handling MCP request:",t)},async(t,r,a)=>{let i,n;"function"==typeof a&&(a=void 0);let o=!1,s=new AbortController;r.on("close",()=>{o||s.abort()}),!0===r.destroyed&&s.abort();try{let r=await mS(t,a,{signal:s.signal});i=await C.fetch(r,{...void 0!==t.auth&&{authInfo:t.auth},...void 0!==a&&{parsedBody:a}})}catch(t){var l;try{I?.onerror?.(t instanceof Error?t:Error(String(t)))}catch{}l=function(t){if(null===t||"object"!=typeof t||Array.isArray(t))return null;let{method:r,id:a}=t;return"string"!=typeof r?null:"string"==typeof a||"number"==typeof a?a:null}(a),i=Response.json({jsonrpc:"2.0",error:{code:-32603,message:"Internal server error"},id:l},{status:500})}let c={};for(let[t,r]of i.headers)c[t]=r;if(r.writeHead(i.status,c),null===i.body){o=!0,r.end();return}r.on("drain",()=>{n?.(),n=void 0});let u=new Promise(t=>{s.signal.addEventListener("abort",()=>t(),{once:!0})});try{for await(let t of i.body){if(s.signal.aborted)break;!1===r.write(t)&&await Promise.race([new Promise(t=>{n=t}),u])}}catch{}o=!0,r.end()});async function ym(t,r){let a=(0,R.randomUUID)(),i=(t=>{for(let r of Array.isArray(t)?t:[t]){let t=mO(r);if(t)return t}})(t.body);await mE({id:a,headers:t.headers,clientInfo:i},async()=>{for(let[a,i]of Object.entries(function(t,r){let a={};if(void 0!==t.origin){if(!0===t.origin)r&&(a["Access-Control-Allow-Origin"]=r);else if(!1!==t.origin)if(Array.isArray(t.origin)){let i=r&&t.origin.includes(r)?r:t.origin[0]||"*";a["Access-Control-Allow-Origin"]=i}else a["Access-Control-Allow-Origin"]=String(t.origin)}return void 0!==t.methods&&(a["Access-Control-Allow-Methods"]=Array.isArray(t.methods)?t.methods.join(","):String(t.methods)),void 0!==t.allowedHeaders&&(a["Access-Control-Allow-Headers"]=Array.isArray(t.allowedHeaders)?t.allowedHeaders.join(","):String(t.allowedHeaders)),void 0!==t.exposedHeaders&&(a["Access-Control-Expose-Headers"]=Array.isArray(t.exposedHeaders)?t.exposedHeaders.join(","):String(t.exposedHeaders)),"boolean"==typeof t.credentials&&(a["Access-Control-Allow-Credentials"]=String(t.credentials)),"number"==typeof t.maxAge&&(a["Access-Control-Max-Age"]=String(t.maxAge)),a}(yd,t.headers.origin)))r.setHeader(a,i);await yp(t,r,t.body)})}})(),i})());